From 83fe6adcbaaa9397f2d22a7be7e5957c9ef280b0 Mon Sep 17 00:00:00 2001 From: Zorg Date: Thu, 19 May 2016 19:29:47 -0400 Subject: [PATCH] Make sure XPC versions are synced with the framework version --- Configurations/ConfigCommon.xcconfig | 2 +- Sparkle/SUUpdater.m | 14 +++----------- Sparkle/SUXPCServiceInfo.h | 2 +- Sparkle/SUXPCServiceInfo.m | 21 +++++++++++++++++---- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/Configurations/ConfigCommon.xcconfig b/Configurations/ConfigCommon.xcconfig index cc57e75f..ac7b37fb 100644 --- a/Configurations/ConfigCommon.xcconfig +++ b/Configurations/ConfigCommon.xcconfig @@ -44,7 +44,7 @@ APPCAST_DOWNLOADER_BUNDLE_ID = org.sparkle-project.${APPCAST_DOWNLOADER_PRODUCT_ UPDATE_DOWNLOADER_BUNDLE_ID = org.sparkle-project.${UPDATE_DOWNLOADER_PRODUCT_NAME} REMOTE_MESSAGE_PORT_BUNDLE_ID = org.sparkle-project.${REMOTE_MESSAGE_PORT_PRODUCT_NAME} -GCC_PREPROCESSOR_DEFINITIONS_COMMON = SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME=$(SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME) SPARKLE_AUTOMATED_DOWNGRADES=$(SPARKLE_AUTOMATED_DOWNGRADES) SPARKLE_APPEND_VERSION_NUMBER=$(SPARKLE_APPEND_VERSION_NUMBER) SPARKLE_BUNDLE_IDENTIFIER=\"$(SPARKLE_BUNDLE_IDENTIFIER)\" SPARKLE_RELAUNCH_TOOL_NAME=\"$(SPARKLE_RELAUNCH_TOOL_NAME)\" SPARKLE_INSTALLER_PROGRESS_TOOL_NAME=\"$(SPARKLE_INSTALLER_PROGRESS_TOOL_NAME)\" SPARKLE_ICON_NAME=\"$(SPARKLE_ICON_NAME)\" INSTALLER_LAUNCHER_BUNDLE_ID=\"${INSTALLER_LAUNCHER_BUNDLE_ID}\" APPCAST_DOWNLOADER_BUNDLE_ID=\"${APPCAST_DOWNLOADER_BUNDLE_ID}\" UPDATE_DOWNLOADER_BUNDLE_ID=\"${UPDATE_DOWNLOADER_BUNDLE_ID}\" REMOTE_MESSAGE_PORT_BUNDLE_ID=\"${REMOTE_MESSAGE_PORT_BUNDLE_ID}\" INSTALLER_LAUNCHER_PRODUCT_NAME=\"${INSTALLER_LAUNCHER_PRODUCT_NAME}\" APPCAST_DOWNLOADER_PRODUCT_NAME=\"${APPCAST_DOWNLOADER_PRODUCT_NAME}\" UPDATE_DOWNLOADER_PRODUCT_NAME=\"${UPDATE_DOWNLOADER_PRODUCT_NAME}\" REMOTE_MESSAGE_PORT_PRODUCT_NAME=\"${REMOTE_MESSAGE_PORT_PRODUCT_NAME}\" +GCC_PREPROCESSOR_DEFINITIONS_COMMON = SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME=$(SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME) SPARKLE_AUTOMATED_DOWNGRADES=$(SPARKLE_AUTOMATED_DOWNGRADES) SPARKLE_APPEND_VERSION_NUMBER=$(SPARKLE_APPEND_VERSION_NUMBER) SPARKLE_BUNDLE_IDENTIFIER=\"$(SPARKLE_BUNDLE_IDENTIFIER)\" CURRENT_PROJECT_VERSION=\"$(CURRENT_PROJECT_VERSION)\" SPARKLE_RELAUNCH_TOOL_NAME=\"$(SPARKLE_RELAUNCH_TOOL_NAME)\" SPARKLE_INSTALLER_PROGRESS_TOOL_NAME=\"$(SPARKLE_INSTALLER_PROGRESS_TOOL_NAME)\" SPARKLE_ICON_NAME=\"$(SPARKLE_ICON_NAME)\" INSTALLER_LAUNCHER_BUNDLE_ID=\"${INSTALLER_LAUNCHER_BUNDLE_ID}\" APPCAST_DOWNLOADER_BUNDLE_ID=\"${APPCAST_DOWNLOADER_BUNDLE_ID}\" UPDATE_DOWNLOADER_BUNDLE_ID=\"${UPDATE_DOWNLOADER_BUNDLE_ID}\" REMOTE_MESSAGE_PORT_BUNDLE_ID=\"${REMOTE_MESSAGE_PORT_BUNDLE_ID}\" INSTALLER_LAUNCHER_PRODUCT_NAME=\"${INSTALLER_LAUNCHER_PRODUCT_NAME}\" APPCAST_DOWNLOADER_PRODUCT_NAME=\"${APPCAST_DOWNLOADER_PRODUCT_NAME}\" UPDATE_DOWNLOADER_PRODUCT_NAME=\"${UPDATE_DOWNLOADER_PRODUCT_NAME}\" REMOTE_MESSAGE_PORT_PRODUCT_NAME=\"${REMOTE_MESSAGE_PORT_PRODUCT_NAME}\" CLANG_ENABLE_OBJC_ARC = YES GCC_ENABLE_PASCAL_STRINGS = NO diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index 3493c948..572e9d42 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -119,16 +119,8 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification return YES; } -- (BOOL)checkATSIssueForBundleURL:(NSURL *)bundleURL getBundleExists:(BOOL *)bundleExists +- (BOOL)checkATSIssueForBundle:(NSBundle * _Nullable)bundle getBundleExists:(BOOL *)bundleExists { - if (bundleURL == nil) { - if (bundleExists != NULL) { - *bundleExists = NO; - } - return NO; - } - - NSBundle *bundle = [NSBundle bundleWithURL:bundleURL]; if (bundleExists != NULL) { *bundleExists = (bundle != nil); } @@ -179,12 +171,12 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification BOOL servingOverHttps = [[[feedURL scheme] lowercaseString] isEqualToString:@"https"]; if (!servingOverHttps) { BOOL foundXPCAppcastDownloaderService = NO; - BOOL foundATSAppcastIssue = [self checkATSIssueForBundleURL:SUXPCServiceURL(@APPCAST_DOWNLOADER_PRODUCT_NAME) getBundleExists:&foundXPCAppcastDownloaderService]; + BOOL foundATSAppcastIssue = [self checkATSIssueForBundle:SUXPCServiceBundle(@APPCAST_DOWNLOADER_PRODUCT_NAME) getBundleExists:&foundXPCAppcastDownloaderService]; BOOL foundXPCUpdateDownloaderService = NO; BOOL foundATSUpdateIssue = NO; if (!foundATSAppcastIssue) { - foundATSUpdateIssue = [self checkATSIssueForBundleURL:SUXPCServiceURL(@UPDATE_DOWNLOADER_PRODUCT_NAME) getBundleExists:&foundXPCUpdateDownloaderService]; + foundATSUpdateIssue = [self checkATSIssueForBundle:SUXPCServiceBundle(@UPDATE_DOWNLOADER_PRODUCT_NAME) getBundleExists:&foundXPCUpdateDownloaderService]; } NSBundle *mainBundle = [NSBundle mainBundle]; diff --git a/Sparkle/SUXPCServiceInfo.h b/Sparkle/SUXPCServiceInfo.h index f3c4451f..ac660494 100644 --- a/Sparkle/SUXPCServiceInfo.h +++ b/Sparkle/SUXPCServiceInfo.h @@ -12,6 +12,6 @@ NS_ASSUME_NONNULL_BEGIN BOOL SUXPCServiceExists(NSString *bundleName); -NSURL * _Nullable SUXPCServiceURL(NSString *bundleName); +NSBundle * _Nullable SUXPCServiceBundle(NSString *bundleName); NS_ASSUME_NONNULL_END diff --git a/Sparkle/SUXPCServiceInfo.m b/Sparkle/SUXPCServiceInfo.m index f1b4dab0..535d7f13 100644 --- a/Sparkle/SUXPCServiceInfo.m +++ b/Sparkle/SUXPCServiceInfo.m @@ -10,11 +10,24 @@ BOOL SUXPCServiceExists(NSString *bundleName) { - NSURL *xpcBundleURL = SUXPCServiceURL(bundleName); - return (xpcBundleURL != nil && [xpcBundleURL checkResourceIsReachableAndReturnError:NULL]); + NSBundle *xpcBundle = SUXPCServiceBundle(bundleName); + if (xpcBundle == nil) { + return NO; + } + + NSString *version = [xpcBundle objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey]; + NSString *projectVersion = @""CURRENT_PROJECT_VERSION; + if (version == nil || ![version isEqualToString:projectVersion]) { + // Use NSLog instead of SULog here because this is a developer configuration error... + NSLog(@"Error: XPC Version mismatch. Framework version is %@ but XPC Service (%@) version is %@", projectVersion, xpcBundle.bundlePath, version); + NSLog(@"Not using XPC Service..."); + return NO; + } + + return YES; } -NSURL * _Nullable SUXPCServiceURL(NSString *bundleName) +NSBundle * _Nullable SUXPCServiceBundle(NSString *bundleName) { NSBundle *mainBundle = [NSBundle mainBundle]; NSURL *executableURL = mainBundle.executableURL; @@ -24,5 +37,5 @@ NSURL * _Nullable SUXPCServiceURL(NSString *bundleName) NSURL *xpcBundleURL = [[[executableURL.URLByDeletingLastPathComponent.URLByDeletingLastPathComponent URLByAppendingPathComponent:@"XPCServices"] URLByAppendingPathComponent:bundleName] URLByAppendingPathExtension:@"xpc"]; - return xpcBundleURL; + return [NSBundle bundleWithURL:xpcBundleURL]; }