From 5afdc4f20ee9686f377f8c308f6c7961e12af957 Mon Sep 17 00:00:00 2001 From: Jake Petroules Date: Sun, 27 Sep 2015 15:41:12 -0700 Subject: [PATCH 1/2] Implement isOperatingSystemAtLeastVersion: --- Sparkle/SUHost.h | 1 + Sparkle/SUHost.m | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/Sparkle/SUHost.h b/Sparkle/SUHost.h index 732eae28..127f2d99 100644 --- a/Sparkle/SUHost.h +++ b/Sparkle/SUHost.h @@ -24,6 +24,7 @@ typedef struct { @property (strong, readonly) NSBundle *bundle; + (NSOperatingSystemVersion)operatingSystemVersion; ++ (BOOL)isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion)version; + (NSString *)systemVersionString; - (instancetype)initWithBundle:(NSBundle *)aBundle; diff --git a/Sparkle/SUHost.m b/Sparkle/SUHost.m index 6ce40fbb..aa95b3bd 100644 --- a/Sparkle/SUHost.m +++ b/Sparkle/SUHost.m @@ -305,6 +305,18 @@ return [[NSProcessInfo processInfo] operatingSystemVersion]; } ++ (BOOL)isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion)version +{ + const NSOperatingSystemVersion systemVersion = self.operatingSystemVersion; + if (systemVersion.majorVersion == version.majorVersion) { + if (systemVersion.minorVersion == version.minorVersion) { + return systemVersion.patchVersion >= version.patchVersion; + } + return systemVersion.minorVersion >= version.minorVersion; + } + return systemVersion.majorVersion >= version.majorVersion; +} + + (NSString *)systemVersionString { NSOperatingSystemVersion version = self.operatingSystemVersion; From b943af3b595216c42888e11384168b60b3b2aa86 Mon Sep 17 00:00:00 2001 From: Jake Petroules Date: Sun, 27 Sep 2015 15:42:51 -0700 Subject: [PATCH 2/2] Use proper version checking. --- Sparkle/SUFileManager.m | 7 ++++--- Sparkle/SUHost.m | 2 +- Sparkle/SUUIBasedUpdateDriver.m | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Sparkle/SUFileManager.m b/Sparkle/SUFileManager.m index f2739f40..d34333ea 100644 --- a/Sparkle/SUFileManager.m +++ b/Sparkle/SUFileManager.m @@ -7,6 +7,7 @@ // #import "SUFileManager.h" +#import "SUHost.h" #include #include @@ -699,8 +700,8 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza NSURL *trashURL = nil; BOOL canUseNewTrashAPI = YES; -#if __MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_8 - canUseNewTrashAPI = [_fileManager respondsToSelector:@selector(trashItemAtURL:resultingItemURL:error:)]; +#if __MAC_OS_X_VERSION_MIN_REQUIRED < 1080 + canUseNewTrashAPI = [SUHost isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){10, 8, 0}]; if (!canUseNewTrashAPI) { FSRef trashRef; if (FSFindFolder(kUserDomain, kTrashFolderType, kDontCreateFolder, &trashRef) == noErr) { @@ -747,7 +748,7 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza // If we get here, we should be able to trash the item normally without authentication BOOL success = NO; -#if __MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_8 +#if __MAC_OS_X_VERSION_MIN_REQUIRED < 1080 if (!canUseNewTrashAPI) { NSString *tempParentPath = tempItemURL.URLByDeletingLastPathComponent.path; success = [[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:tempParentPath destination:@"" files:@[tempItemURL.lastPathComponent] tag:NULL]; diff --git a/Sparkle/SUHost.m b/Sparkle/SUHost.m index aa95b3bd..57bd8f25 100644 --- a/Sparkle/SUHost.m +++ b/Sparkle/SUHost.m @@ -286,7 +286,7 @@ + (NSOperatingSystemVersion)operatingSystemVersion { -#if __MAC_OS_X_VERSION_MIN_REQUIRED < 1090 // Present in 10.9 despite NS_AVAILABLE's claims +#if __MAC_OS_X_VERSION_MIN_REQUIRED < 101000 #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wselector" // Xcode 5.1.1: operatingSystemVersion is clearly declared, must warn due to a compiler bug? diff --git a/Sparkle/SUUIBasedUpdateDriver.m b/Sparkle/SUUIBasedUpdateDriver.m index 869dc0de..4e7f7ec8 100644 --- a/Sparkle/SUUIBasedUpdateDriver.m +++ b/Sparkle/SUUIBasedUpdateDriver.m @@ -128,7 +128,7 @@ - (NSString *)localizedStringFromByteCount:(long long)value { - if (SUHost.operatingSystemVersion.minorVersion < 8) { + if (![SUHost isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){10, 8, 0}]) { if (value < 1000) { return [NSString stringWithFormat:@"%.0lf %@", value / 1.0, SULocalizedString(@"B", @"the unit for bytes")];