This repository was archived by the owner on Aug 12, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 84
Fixing version comparison & adding support for build comparisons #69
Open
pudquick
wants to merge
1
commit into
google:master
Choose a base branch
from
pudquick:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,9 +39,20 @@ @implementation DNAppDelegate | |
|
|
||
| - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { | ||
| NSString *expectedVersion = NSLocalizedString(@"expectedVersion", @""); | ||
| NSString *expectedBuildsStr = NSLocalizedString(@"expectedBuilds", @""); | ||
| NSArray *expectedBuilds; | ||
|
|
||
| if ([expectedBuildsStr isEqualToString:@"expectedBuilds"]) { | ||
| // Apparently NSLocalizedStringWithDefaultValue will act exactly like NSLocalizedString | ||
| // if you attempt to use a default value of nil or empty string. Ugh. | ||
| expectedBuildsStr = @""; | ||
| } else { | ||
| expectedBuilds = [expectedBuildsStr componentsSeparatedByString:@","]; | ||
| } | ||
| NSDictionary *systemVersionDictionary = [NSDictionary dictionaryWithContentsOfFile: | ||
| @"/System/Library/CoreServices/SystemVersion.plist"]; | ||
| NSString *systemVersion = systemVersionDictionary[@"ProductVersion"]; | ||
| NSString *systemBuild = systemVersionDictionary[@"ProductBuildVersion"]; | ||
|
|
||
| NSArray *systemVersionArray = [systemVersion componentsSeparatedByString:@"."]; | ||
| if (systemVersionArray.count == 2) { | ||
|
|
@@ -53,15 +64,38 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { | |
| expectedVersionArray = [expectedVersionArray arrayByAddingObject:@"0"]; | ||
| } | ||
|
|
||
|
|
||
| NSLog(@"Info: System version: %@ %@", systemVersion, systemBuild); | ||
| NSLog(@"Info: Expected version: %@ %@", expectedVersion, expectedBuildsStr); | ||
| if (systemVersionArray.count < 3 || expectedVersionArray.count < 3) { | ||
| NSLog(@"Exiting: Error, unable to properly determine system version or expected version"); | ||
| [NSApp terminate:nil]; | ||
| } else if ([expectedVersionArray[0] intValue] < [systemVersionArray[0] intValue]) { | ||
| NSLog(@"Exiting: OS is already %@ or greater", expectedVersion); | ||
| [NSApp terminate:nil]; | ||
| } else if (([expectedVersionArray[0] intValue] <= [systemVersionArray[0] intValue]) && | ||
| ([expectedVersionArray[1] intValue] < [systemVersionArray[1] intValue])) { | ||
| NSLog(@"Exiting: OS is already %@ or greater", expectedVersion); | ||
| [NSApp terminate:nil]; | ||
| } else if (([expectedVersionArray[0] intValue] <= [systemVersionArray[0] intValue]) && | ||
| ([expectedVersionArray[1] intValue] <= [systemVersionArray[1] intValue]) && | ||
| ([expectedVersionArray[2] intValue] <= [systemVersionArray[2] intValue])) { | ||
| ([expectedVersionArray[2] intValue] < [systemVersionArray[2] intValue])) { | ||
| NSLog(@"Exiting: OS is already %@ or greater", expectedVersion); | ||
| [NSApp terminate:nil]; | ||
| } else if (([expectedVersionArray[0] intValue] == [systemVersionArray[0] intValue]) && | ||
| ([expectedVersionArray[1] intValue] == [systemVersionArray[1] intValue]) && | ||
| ([expectedVersionArray[2] intValue] == [systemVersionArray[2] intValue])) { | ||
| NSLog(@"Checking: OS is equal to %@, checking build version", expectedVersion); | ||
| if (expectedBuilds == nil) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use
tburgin marked this conversation as resolved.
|
||
| NSLog(@"Exiting: No preferred build, so considered equal to %@", expectedVersion); | ||
| [NSApp terminate:nil]; | ||
| } else { | ||
| if ([expectedBuilds containsObject:systemBuild]) { | ||
| NSLog(@"Exiting: OS build is one of the expected builds [ %@ ]", expectedBuildsStr); | ||
| [NSApp terminate:nil]; | ||
| } else { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As the last line of the first condition exits, there's no need for the else, might as well remove it and reduce the indentation. |
||
| NSLog(@"Checking: OS build not found in expected builds [ %@ ]", expectedBuildsStr); | ||
| } | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic, while correct, is a bit more difficult to read as it's quite repetitive. Could we flip it around? if ([expectedVersionArray isEqualToArray:systemVersionArray]) {
NSLog(@"Checking: running OS is equal to %@, checking build version", expectedVersion);
if (!expectedBuilds.count) {
NSLog(@"Exiting: No preferred build, so considered equal");
[NSApp terminate:nil];
}
if ([expectedBuilds containsObject:systemBuild]) {
NSLog(@"Exiting: OS build is one of the expected builds %@", expectedBuilds);
[NSApp terminate:nil];
}
NSLog(@"Checking: OS build not found in expected builds %@", expectedBuilds);
} else if ([systemVersionArray[0] intValue] < [expectedVersionArray[0] intValue] ||
[systemVersionArray[1] intValue] < [expectedVersionArray[1] intValue] ||
[systemVersionArray[2] intValue] < [expectedVersionArray[2] intValue]) {
NSLog(@"Checking: OS build is lower than required");
} else {
NSLog(@"Exiting: OS build is greater than required");
[NSapp terminate:nil];
} |
||
| } | ||
|
|
||
| [[NSUserDefaults standardUserDefaults] synchronize]; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: For large expectedBuilds builds list, a set theoretically has faster lookups.