Upped the timeout for the albums and artist method to 600.
[MenuTunes.git] / MTBlingController.m
1 //
2 //  MTBlingController.m
3 //  MenuTunes
4 //
5 //  Created by Matthew L. Judy on Tue Aug 19 2003.
6 //  Copyright (c) 2003 iThink Software. All rights reserved.
7 //
8
9 #import "MTBlingController.h"
10 #import "MTeSerialNumber.h"
11 #import "MainController.h"
12
13 #define APP_SUPPORT_PATH_STRING [@"~/Library/Application Support/MenuTunes/" stringByExpandingTildeInPath]
14 #define LICENSE_PATH_STRING [APP_SUPPORT_PATH_STRING stringByAppendingString:@"/.license"]
15
16
17 @interface MTBlingController (Private)
18 - (void)showPanel;
19 @end
20
21
22 @implementation MTBlingController
23
24
25 - (void)_HEY {}
26 - (void)_SUCKA {}
27 - (void)_QUIT {}
28 - (void)_HACKING {}
29 - (void)_AND {}
30 - (void)_GO {}
31 - (void)_BUY {}
32 - (void)_IT {}
33 - (void)_YOU {}
34 - (void)_TIGHTWAD {}
35 - (void)_HAHAHA {}
36 - (void)_LOLOL {}
37 - (void)_FIVERSKATES {}
38
39 - (id)init
40 {
41     if ( ( self = [super init] ) ) {
42         checkDone = 0;
43     }
44     return self;
45 }
46
47
48 - (void)showPanel
49 {
50     if ( ! window ) {
51         window = [MTShizzleWindow sharedWindowForSender:self];
52     }
53     [NSApp activateIgnoringOtherApps:YES];
54     [window center];
55     [window orderFrontRegardless];
56     [window makeKeyWindow];
57 //  [window setLevel:NSStatusWindowLevel];
58 }
59
60 - (void)showPanelIfNeeded
61 {
62     if ( ! (checkDone == 2475) ) {
63         if ( ! ([self checkKeyFile] == 7465) ) {
64             [self showPanel];
65         } else {
66             checkDone = 2475;
67         }
68     }
69 }
70
71 - (void)goToTheStore:(id)sender
72 {
73     [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://store.eSellerate.net/s.asp?s=STR090894476"]];
74 }
75
76 - (void)registerLater:(id)sender
77 {
78     [window orderOut:self];
79         if ([[NSDate date] timeIntervalSinceDate:[[MainController sharedController] getBlingTime]] >= 604800) {
80                 [NSApp terminate:nil];
81         }
82 }
83
84 - (void)verifyKey:(id)sender
85 {
86     NSString *o = [window owner];
87     NSString *k = [window key];
88
89     MTeSerialNumber *s = [[[MTeSerialNumber alloc] initWithSerialNumber:k
90                                                                    name:o
91                                                                   extra:nil
92                                                               publisher:@"04611"] autorelease];
93     if ( ([s isValid] == ITeSerialNumberIsValid) && ( [[[s infoDictionary] objectForKey:@"appIdentifier"] isEqualToString:@"MT"] ) ) {
94     
95         NSFileManager *fm = [NSFileManager defaultManager];
96         
97         if ( ! [fm fileExistsAtPath:APP_SUPPORT_PATH_STRING] ) {
98             [fm createDirectoryAtPath:APP_SUPPORT_PATH_STRING attributes:nil];
99         }
100         
101         [[NSDictionary dictionaryWithObjectsAndKeys:
102             o, @"Owner",
103             k, @"Key",
104             nil] writeToFile:LICENSE_PATH_STRING atomically:YES];
105
106         checkDone = 2475;
107
108         NSBeginInformationalAlertSheet(NSLocalizedString(@"validated_title", @"Validated Title"),
109                                        @"Thank You!", nil, nil,
110                                        window,
111                                        self,
112                                        @selector(finishValidSheet:returnCode:contextInfo:),
113                                        nil,
114                                        nil,
115                                        NSLocalizedString(@"validated_msg", @"Validated Message"));
116
117     } else {
118     
119         NSBeginAlertSheet(NSLocalizedString(@"failed_title", @"Failed Title"),
120                           @"Try Again", nil, nil,
121                           window,
122                           self,
123                           nil, nil, nil,
124                           NSLocalizedString(@"failed_msg", @"Failed Message"));
125     }
126     [[MainController sharedController] blingTime];
127 }
128
129 - (int)checkKeyFile
130 {
131     NSString        *p = LICENSE_PATH_STRING;
132     MTeSerialNumber *k = [[[MTeSerialNumber alloc] initWithContentsOfFile:p
133                                                                     extra:@""
134                                                                 publisher:@"04611"] autorelease];
135     if ( k && ([k isValid] == ITeSerialNumberIsValid) && ( [[[k infoDictionary] objectForKey:@"appIdentifier"] isEqualToString:@"MT"] )) {
136         return 7465;
137     } else {
138         [[NSFileManager defaultManager] removeFileAtPath:p handler:nil];
139         return 0;
140     }
141
142 }
143
144 - (int)checkDone
145 {
146     if ( ! (checkDone == 2475) ) {
147         if ( ! ([self checkKeyFile] == 7465) ) {
148             checkDone = 0;
149         } else {
150             checkDone = 2475;
151         }
152     }
153     return checkDone;
154 }
155
156 - (void)finishValidSheet:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
157 {
158     [window orderOut:self];
159 }
160
161 @end