Fixing bug that would require users to restart MenuTunes when they enter
[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
36 - (id)init
37 {
38     if ( ( self = [super init] ) ) {
39         checkDone = 0;
40     }
41     return self;
42 }
43
44
45 - (void)showPanel
46 {
47     if ( ! window ) {
48         window = [MTShizzleWindow sharedWindowForSender:self];
49     }
50
51     [window center];
52     [window makeKeyAndOrderFront:nil];
53 //  [window setLevel:NSStatusWindowLevel];
54 }
55
56 - (void)showPanelIfNeeded
57 {
58     if ( ! (checkDone == 2475) ) {
59         if ( ! ([self checkKeyFile] == 7465) ) {
60             [self showPanel];
61         } else {
62             checkDone = 2475;
63         }
64     }
65 }
66
67 - (void)goToTheStore:(id)sender
68 {
69     [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://store.eSellerate.net/s.asp?s=STR090894476"]];
70 }
71
72 - (void)registerLater:(id)sender
73 {
74     [window orderOut:self];
75 }
76
77 - (void)verifyKey:(id)sender
78 {
79     NSString *o = [window owner];
80     NSString *k = [window key];
81
82     MTeSerialNumber *s = [[[MTeSerialNumber alloc] initWithSerialNumber:k
83                                                                    name:o
84                                                                   extra:nil
85                                                               publisher:@"04611"] autorelease];
86     if ( ([s isValid] == ITeSerialNumberIsValid) && ( [[[s infoDictionary] objectForKey:@"appIdentifier"] isEqualToString:@"MT"] ) ) {
87     
88         NSFileManager *fm = [NSFileManager defaultManager];
89         
90         if ( ! [fm fileExistsAtPath:APP_SUPPORT_PATH_STRING] ) {
91             [fm createDirectoryAtPath:APP_SUPPORT_PATH_STRING attributes:nil];
92         }
93         
94         [[NSDictionary dictionaryWithObjectsAndKeys:
95             o, @"Owner",
96             k, @"Key",
97             nil] writeToFile:LICENSE_PATH_STRING atomically:YES];
98
99         checkDone = 2475;
100
101         NSBeginInformationalAlertSheet(NSLocalizedString(@"validated_title", @"Validated Title"),
102                                        @"Thank You!", nil, nil,
103                                        window,
104                                        self,
105                                        @selector(finishValidSheet:returnCode:contextInfo:),
106                                        nil,
107                                        nil,
108                                        NSLocalizedString(@"validated_msg", @"Validated Message"));
109
110     } else {
111     
112         NSBeginAlertSheet(NSLocalizedString(@"failed_title", @"Failed Title"),
113                           @"Try Again", nil, nil,
114                           window,
115                           self,
116                           nil, nil, nil,
117                           NSLocalizedString(@"failed_msg", @"Failed Message"));
118     }
119     [[MainController sharedController] blingTime];
120 }
121
122 - (int)checkKeyFile
123 {
124     NSString        *p = LICENSE_PATH_STRING;
125     MTeSerialNumber *k = [[[MTeSerialNumber alloc] initWithContentsOfFile:p
126                                                                     extra:@""
127                                                                 publisher:@"04611"] autorelease];
128     if ( k && ([k isValid] == ITeSerialNumberIsValid) && ( [[[k infoDictionary] objectForKey:@"appIdentifier"] isEqualToString:@"MT"] )) {
129         return 7465;
130     } else {
131         [[NSFileManager defaultManager] removeFileAtPath:p handler:nil];
132         return 0;
133     }
134
135 }
136
137 - (int)checkDone
138 {
139     if ( ! (checkDone == 2475) ) {
140         if ( ! ([self checkKeyFile] == 7465) ) {
141             checkDone = 0;
142         } else {
143             checkDone = 2475;
144         }
145     }
146     return checkDone;
147 }
148
149 - (void)finishValidSheet:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
150 {
151     [window orderOut:self];
152 }
153
154 @end