|
10 | 10 | #import <EasyNSURLConnection/EasyNSURLConnection.h>
|
11 | 11 | #import <CocoaOniguruma/OnigRegexp.h>
|
12 | 12 | #import <CocoaOniguruma/OnigRegexpUtility.h>
|
| 13 | +#ifdef oss |
| 14 | +#else |
| 15 | +#import <DonationCheck_KeyOnly/DonationKeyVerify.h> |
| 16 | +#endif |
13 | 17 |
|
14 | 18 | @implementation Utility
|
15 | 19 | + (int)checkMatch:(NSString *)title
|
@@ -85,32 +89,35 @@ + (NSString *)urlEncodeString:(NSString *)string{
|
85 | 89 | }
|
86 | 90 | + (void)donateCheck:(MAL_Updater_OS_XAppDelegate*)delegate{
|
87 | 91 | if ([NSUserDefaults.standardUserDefaults boolForKey:@"MacAppStoreMigrated"]) {
|
| 92 | + [[NSUserDefaults standardUserDefaults] setObject:@NO forKey:@"donated"]; |
| 93 | + [[NSUserDefaults standardUserDefaults] setObject:@NO forKey:@"MacAppStoreMigrated"]; |
88 | 94 | return;
|
89 | 95 | }
|
90 | 96 | if (![[NSUserDefaults standardUserDefaults] objectForKey:@"donatereminderdate"]) {
|
91 | 97 | [Utility setReminderDate];
|
92 | 98 | }
|
93 |
| - if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"donatereminderdate"] timeIntervalSinceNow] < 0) { |
94 |
| - if (((NSNumber *)[[NSUserDefaults standardUserDefaults] objectForKey:@"donated"]).boolValue) { |
95 |
| - int validkey = [Utility checkDonationKey:[[NSUserDefaults standardUserDefaults] objectForKey:@"donatekey"] name:[[NSUserDefaults standardUserDefaults] objectForKey:@"donor"]]; |
96 |
| - if (validkey == 1) { |
97 |
| - //Reset check |
98 |
| - [Utility setReminderDate]; |
99 |
| - } |
100 |
| - else if (validkey == 2) { |
101 |
| - //Try again when there is internet access |
102 |
| - } |
103 |
| - else { |
104 |
| - //Invalid Key |
105 |
| - [Utility showsheetmessage:@"Donation Key Error" explaination:@"This key has been revoked. Please contact the author of this program or enter a valid key." window:nil]; |
106 |
| - [Utility showDonateReminder:delegate]; |
107 |
| - [[NSUserDefaults standardUserDefaults] setObject:@NO forKey:@"donated"]; |
108 |
| - } |
| 99 | + if (((NSNumber *)[[NSUserDefaults standardUserDefaults] objectForKey:@"donated"]).boolValue) { |
| 100 | + int validkey = [Utility checkDonationKey:[[NSUserDefaults standardUserDefaults] objectForKey:@"donatekey"] name:[[NSUserDefaults standardUserDefaults] objectForKey:@"donor"]]; |
| 101 | + if (validkey == 1) { |
| 102 | + //Reset check |
| 103 | + [Utility setReminderDate]; |
| 104 | + return; |
| 105 | + } |
| 106 | + else if (validkey == 2) { |
| 107 | + //Try again when there is internet access |
| 108 | + return; |
109 | 109 | }
|
110 | 110 | else {
|
| 111 | + //Invalid Key |
| 112 | + [Utility showsheetmessage:@"Donation Key Error" explaination:@"This key has been revoked. Please contact the author of this program or enter a valid key." window:nil]; |
111 | 113 | [Utility showDonateReminder:delegate];
|
| 114 | + [[NSUserDefaults standardUserDefaults] setObject:@NO forKey:@"donated"]; |
| 115 | + return; |
112 | 116 | }
|
113 | 117 | }
|
| 118 | + if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"donatereminderdate"] timeIntervalSinceNow] < 0) { |
| 119 | + [Utility showDonateReminder:delegate]; |
| 120 | + } |
114 | 121 | }
|
115 | 122 | + (void)showDonateReminder:(MAL_Updater_OS_XAppDelegate*)delegate{
|
116 | 123 | // Shows Donation Reminder
|
@@ -147,23 +154,34 @@ + (void)setReminderDate{
|
147 | 154 | [[NSUserDefaults standardUserDefaults] setObject:reminderdate forKey:@"donatereminderdate"];
|
148 | 155 | }
|
149 | 156 | + (int)checkDonationKey:(NSString *)key name:(NSString *)name{
|
150 |
| - //Set Search API |
151 |
| - NSURL *url = [NSURL URLWithString:@"https://licensing.malupdaterosx.moe/keycheck.php"]; |
152 |
| - EasyNSURLConnection *request = [[EasyNSURLConnection alloc] initWithURL:url]; |
153 |
| - [request addFormData:name forKey:@"name"]; |
154 |
| - [request addFormData:key forKey:@"key"]; |
155 |
| - //Ignore Cookies |
156 |
| - [request setUseCookies:NO]; |
157 |
| - //Perform Search |
158 |
| - [request startJSONFormRequest:EasyNSURLConnectionJsonType]; |
159 |
| - // Get Status Code |
160 |
| - long statusCode = [request getStatusCode]; |
| 157 | + // Check Cocoafob Keys |
| 158 | + bool valid = [DonationKeyVerify checkMALULicense:name withDonationKey:key]; |
| 159 | + if (valid) { |
| 160 | + return 1; |
| 161 | + } |
| 162 | + // Checks Donation Key validatity |
| 163 | + NSURL *url = [NSURL URLWithString:@"https://licensing.malupdaterosx.moe/keycheck.php"]; |
| 164 | + EasyNSURLConnection *request = [[EasyNSURLConnection alloc] initWithURL:url]; |
| 165 | + [request addFormData:name forKey:@"name"]; |
| 166 | + [request addFormData:key forKey:@"key"]; |
| 167 | + //Ignore Cookies |
| 168 | + [request setUseCookies:NO]; |
| 169 | + //Perform Search |
| 170 | + [request startJSONFormRequest:EasyNSURLConnectionJsonType]; |
| 171 | + // Get Status Code |
| 172 | + long statusCode = [request getStatusCode]; |
161 | 173 | if (statusCode == 200) {
|
162 | 174 | NSError* jerror;
|
163 | 175 | NSDictionary *d = [NSJSONSerialization JSONObjectWithData:request.response.responsedata options:nil error:&jerror];
|
164 | 176 | int valid = ((NSNumber *)d[@"valid"]).intValue;
|
165 | 177 | if (valid == 1) {
|
166 | 178 | // Valid Key
|
| 179 | + if (d[@"newlicense"]) { |
| 180 | + [[NSUserDefaults standardUserDefaults] setObject:d[@"newlicense"] forKey:@"donatekey"]; |
| 181 | + } |
| 182 | + else { |
| 183 | + [[NSUserDefaults standardUserDefaults] setObject:key forKey:@"donatekey"]; |
| 184 | + } |
167 | 185 | return 1;
|
168 | 186 | }
|
169 | 187 | else {
|
|
0 commit comments