Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(399)

Side by Side Diff: Source/EmUpAppController.m

Issue 824050: Allow latest app version to be dependent on current system version Base URL: http://google-email-uploader-mac.googlecode.com/svn/trunk/
Patch Set: Created 15 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Copyright (c) 2009 Google Inc. 1 /* Copyright (c) 2009 Google Inc.
2 * 2 *
3 * Licensed under the Apache License, Version 2.0 (the "License"); 3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. 4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at 5 * You may obtain a copy of the License at
6 * 6 *
7 * http://www.apache.org/licenses/LICENSE-2.0 7 * http://www.apache.org/licenses/LICENSE-2.0
8 * 8 *
9 * Unless required by applicable law or agreed to in writing, software 9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS, 10 * distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 NSURLRequest *request = [NSURLRequest requestWithURL:plistURL]; 132 NSURLRequest *request = [NSURLRequest requestWithURL:plistURL];
133 GDataHTTPFetcher *fetcher = [GDataHTTPFetcher httpFetcherWithRequest:request]; 133 GDataHTTPFetcher *fetcher = [GDataHTTPFetcher httpFetcherWithRequest:request];
134 134
135 [fetcher beginFetchWithDelegate:self 135 [fetcher beginFetchWithDelegate:self
136 didFinishSelector:@selector(plistFetcher:finishedWithData:) 136 didFinishSelector:@selector(plistFetcher:finishedWithData:)
137 didFailSelector:@selector(plistFetcher:failedWithError:)]; 137 didFailSelector:@selector(plistFetcher:failedWithError:)];
138 138
139 [fetcher setUserData:[NSNumber numberWithBool:shouldForceUpdate]]; 139 [fetcher setUserData:[NSNumber numberWithBool:shouldForceUpdate]];
140 } 140 }
141 141
142 - (NSString *)appVersionForCurrentSystemVersionWithMap:(NSDictionary *)versionMa p {
143 // using a dictionary mapping system version ranges to app versions, like
144 // -10.4.11 : 1.1.2
145 // 10.5-10.5.8 : 1.1.3
146 // 10.6- : 1.1.4
147 // find the latest app version for the current system
148 //
149 // note: the system ranges should have no holes or overlapping system
150 // versions, and should not be order-dependent
151
152 SInt32 systemMajor = 0, systemMinor = 0, systemRelease = 0;
153 (void) Gestalt(gestaltSystemVersionMajor, &systemMajor);
154 (void) Gestalt(gestaltSystemVersionMinor, &systemMinor);
155 (void) Gestalt(gestaltSystemVersionBugFix, &systemRelease);
156
157 NSString *systemVersion = [NSString stringWithFormat:@"%d.%d.%d",
158 (int)systemMajor, (int)systemMinor, (int)systemRele ase];
159 NSString *versionRange;
160 GDATA_FOREACH_KEY(versionRange, versionMap) {
161
162 NSString *lowSystemVersion = nil;
163 NSString *dash = nil;
164 NSString *highSystemVersion = nil;
165 NSComparisonResult comp1, comp2;
166
167 // parse "low", "low-", "low-high", or "-high"
168 NSScanner *scanner = [NSScanner scannerWithString:versionRange];
169 [scanner scanUpToString:@"-" intoString:&lowSystemVersion];
170 [scanner scanString:@"-" intoString:&dash];
171 [scanner scanUpToString:@"\r" intoString:&highSystemVersion];
172
173 BOOL doesMatchLow = YES;
174 BOOL doesMatchHigh = YES;
TVL 2010/04/15 11:23:03 "match" isn't really right here, but I'm not comin
175
176 if (lowSystemVersion) {
177 comp1 = [GDataUtilities compareVersion:lowSystemVersion
178 toVersion:systemVersion];
179 doesMatchLow = (comp1 == NSOrderedSame
180 || (dash != nil && comp1 == NSOrderedAscending));
181 }
182
183 if (highSystemVersion) {
184 comp2 = [GDataUtilities compareVersion:highSystemVersion
185 toVersion:systemVersion];
186 doesMatchHigh = (comp2 == NSOrderedSame
187 || (dash != nil && comp2 == NSOrderedDescending));
188 }
189
190 if (doesMatchLow && doesMatchHigh) {
191 NSString *result = [versionMap objectForKey:versionRange];
192 return result;
193 }
194 }
195
196 return nil;
197 }
198
142 - (void)plistFetcher:(GDataHTTPFetcher *)fetcher finishedWithData:(NSData *)data { 199 - (void)plistFetcher:(GDataHTTPFetcher *)fetcher finishedWithData:(NSData *)data {
143 // convert the returns data to a plist dictionary 200 // convert the returns data to a plist dictionary
144 NSString *errorStr = nil; 201 NSString *errorStr = nil;
145 NSDictionary *plist; 202 NSDictionary *plist;
146 203
147 plist = [NSPropertyListSerialization propertyListFromData:data 204 plist = [NSPropertyListSerialization propertyListFromData:data
148 mutabilityOption:NSPropertyListImmuta ble 205 mutabilityOption:NSPropertyListImmuta ble
149 format:NULL 206 format:NULL
150 errorDescription:&errorStr]; 207 errorDescription:&errorStr];
151 208
152 if ([plist isKindOfClass:[NSDictionary class]]) { 209 if ([plist isKindOfClass:[NSDictionary class]]) {
153 // compare the plist's short version string with the one in this bundle 210
154 NSString *latestVersion = [plist objectForKey:@"CFBundleShortVersionString"] ; 211 // get the map of system versions to app versions, and step through the
212 // system version ranges to find the latest app version for this system
213 NSString *latestVersion;
214 NSDictionary *versionMap = [plist objectForKey:@"SystemToVersionMap"];
215 if (versionMap) {
216 // new, with the map
217 latestVersion = [self appVersionForCurrentSystemVersionWithMap:versionMap] ;
218 } else {
219 // old, without the map
220 latestVersion = [plist objectForKey:@"CFBundleShortVersionString"];
221 }
222
223 // compare the short version string in this bundle to the one from the
224 // map
155 NSString *thisVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@" CFBundleShortVersionString"]; 225 NSString *thisVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@" CFBundleShortVersionString"];
156 226
157 NSComparisonResult result = [GDataUtilities compareVersion:thisVersion 227 NSComparisonResult result = [GDataUtilities compareVersion:thisVersion
158 toVersion:latestVersion]; 228 toVersion:latestVersion];
159 229
160 BOOL shouldForceUpdate = [[fetcher userData] boolValue]; 230 BOOL shouldForceUpdate = [[fetcher userData] boolValue];
161 231
162 if (result != NSOrderedAscending && !shouldForceUpdate) { 232 if (result != NSOrderedAscending && !shouldForceUpdate) {
163 // we're current; do nothing 233 // we're current; do nothing
164 } else { 234 } else {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:urlStr]]; 266 [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:urlStr]];
197 } 267 }
198 } 268 }
199 269
200 - (void)plistFetcher:(GDataHTTPFetcher *)fetcher failedWithError:(NSError *)erro r { 270 - (void)plistFetcher:(GDataHTTPFetcher *)fetcher failedWithError:(NSError *)erro r {
201 // nothing to do but report this on the console 271 // nothing to do but report this on the console
202 NSLog(@"unable to fetch plist at %@, %@", [[fetcher request] URL], error); 272 NSLog(@"unable to fetch plist at %@, %@", [[fetcher request] URL], error);
203 } 273 }
204 274
205 @end 275 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b