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