Fixing blingBling :)
[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
12 #define APP_SUPPORT_PATH_STRING [@"~/Library/Application Support/MenuTunes/" stringByExpandingTildeInPath]
13 #define LICENSE_PATH_STRING [APP_SUPPORT_PATH_STRING stringByAppendingString:@"/.license"]
14
15
16 @interface MTBlingController (Private)
17 - (void)showPanel;
18 @end
19
20
21 @implementation MTBlingController
22
23
24 - (void)_HEY {}
25 - (void)_SUCKA {}
26 - (void)_QUIT {}
27 - (void)_HACKING {}
28 - (void)_AND {}
29 - (void)_GO {}
30 - (void)_BUY {}
31 - (void)_IT {}
32 - (void)_YOU {}
33 - (void)_TIGHTWAD {}
34
35 - (id)init
36 {
37     if ( ( self = [super init] ) ) {
38         checkDone = 0;
39     }
40     return self;
41 }
42
43
44 - (void)showPanel
45 {
46     if ( ! window ) {
47         window = [MTShizzleWindow sharedWindowForSender:self];
48     }
49
50     [window center];
51     [window makeKeyAndOrderFront:nil];
52 //  [window setLevel:NSStatusWindowLevel];
53 }
54
55 - (void)showPanelIfNeeded
56 {
57     if ( ! (checkDone == 2475) ) {
58         if ( ! ([self checkKeyFile] == 7465) ) {
59             [self showPanel];
60         } else {
61             checkDone = 2475;
62         }
63     }
64 }
65
66 - (void)goToTheStore:(id)sender
67 {
68     [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://store.eSellerate.net/s.asp?s=STR090894476"]];
69 }
70
71 - (void)registerLater:(id)sender
72 {
73     [window orderOut:self];
74 }
75
76 - (void)verifyKey:(id)sender
77 {
78     NSString *o = [window owner];
79     NSString *k = [window key];
80
81     MTeSerialNumber *s = [[[MTeSerialNumber alloc] initWithSerialNumber:k
82                                                                    name:o
83                                                                   extra:nil
84                                                               publisher:@"04611"] autorelease];
85     if ( ([s isValid] == ITeSerialNumberIsValid) && ( [[[s infoDictionary] objectForKey:@"appIdentifier"] isEqualToString:@"MT"] ) ) {
86     
87         NSFileManager *fm = [NSFileManager defaultManager];
88         
89         if ( ! [fm fileExistsAtPath:APP_SUPPORT_PATH_STRING] ) {
90             [fm createDirectoryAtPath:APP_SUPPORT_PATH_STRING attributes:nil];
91         }
92         
93         [[NSDictionary dictionaryWithObjectsAndKeys:
94             o, @"Owner",
95             k, @"Key",
96             nil] writeToFile:LICENSE_PATH_STRING atomically:YES];
97
98         checkDone = 2475;
99
100         NSBeginInformationalAlertSheet(NSLocalizedString(@"validated_title", @"Validated Title"),
101                                        @"Thank You!", nil, nil,
102                                        window,
103                                        self,
104                                        @selector(finishValidSheet:returnCode:contextInfo:),
105                                        nil,
106                                        nil,
107                                        NSLocalizedString(@"validated_msg", @"Validated Message"));
108
109     } else {
110     
111         NSBeginAlertSheet(NSLocalizedString(@"failed_title", @"Failed Title"),
112                           @"Try Again", nil, nil,
113                           window,
114                           self,
115                           nil, nil, nil,
116                           NSLocalizedString(@"failed_msg", @"Failed Message"));
117     }
118     
119 }
120
121 - (int)checkKeyFile
122 {
123     NSString        *p = LICENSE_PATH_STRING;
124     MTeSerialNumber *k = [[[MTeSerialNumber alloc] initWithContentsOfFile:p
125                                                                     extra:@""
126                                                                 publisher:@"04611"] autorelease];
127     if ( k && ([k isValid] == ITeSerialNumberIsValid) && ( [[[k infoDictionary] objectForKey:@"appIdentifier"] isEqualToString:@"MT"] )) {
128         return 7465;
129     } else {
130         [[NSFileManager defaultManager] removeFileAtPath:p handler:nil];
131         return 0;
132     }
133
134 }
135
136 - (int)checkDone
137 {
138     if ( ! (checkDone == 2475) ) {
139         if ( ! ([self checkKeyFile] == 7465) ) {
140             return 0
141         } else {
142             return 2475;
143         }
144     }
145 }
146
147 - (void)finishValidSheet:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
148 {
149     [window orderOut:self];
150 }
151
152 @end