diff --git a/Sparkle/Autoupdate/AppInstaller.m b/Sparkle/Autoupdate/AppInstaller.m index c4fcb248..7ea0318c 100644 --- a/Sparkle/Autoupdate/AppInstaller.m +++ b/Sparkle/Autoupdate/AppInstaller.m @@ -355,7 +355,7 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.5; dispatch_async(self.installerQueue, ^{ NSError *installerError = nil; - id installer = [SUInstaller installerForHost:self.host updateDirectory:self.installationData.updateDirectoryPath versionComparator:[SUStandardVersionComparator defaultComparator] error:&installerError]; + id installer = [SUInstaller installerForHost:self.host installationPath:[self installationPath] updateDirectory:self.installationData.updateDirectoryPath versionComparator:[SUStandardVersionComparator defaultComparator] error:&installerError]; if (installer == nil) { SULog(@"Error: Failed to create installer instance with error: %@", installerError); @@ -395,6 +395,22 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.5; }); } +- (NSString *)installationPath +{ + NSBundle *bundle = self.host.bundle; + assert(bundle != nil); + + if (SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME) { + // We'll install to "#{CFBundleName}.app", but only if that path doesn't already exist. If we're "Foo 4.2.app," and there's a "Foo.app" in this directory, we don't want to overwrite it! But if there's no "Foo.app," we'll take that name. + NSString *normalizedAppPath = [[[bundle bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.%@", [bundle objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleNameKey], [[bundle bundlePath] pathExtension]]]; + + if (![[NSFileManager defaultManager] fileExistsAtPath:normalizedAppPath]) { + return normalizedAppPath; + } + } + return [bundle bundlePath]; +} + - (void)performStage2InstallationIfNeeded { #warning this test should be async? @@ -406,7 +422,7 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.5; // Predict if an admin prompt is needed // If it is, we should activate our app so that the auth prompt will be active // (Note it's more efficient/simpler to predict rather than trying, seeing if we fail, notifying, and re-trying) - NSString *installationPath = self.host.installationPath; + NSString *installationPath = [self installationPath]; if (![[NSFileManager defaultManager] isWritableFileAtPath:installationPath]) { [[NSApplication sharedApplication] activateIgnoringOtherApps:YES]; } @@ -476,7 +492,7 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.5; } dispatch_async(dispatch_get_main_queue(), ^{ - NSString *installationPath = [self.host.installationPath copy]; + NSString *installationPath = [self installationPath]; if (self.shouldRelaunch) { NSString *pathToRelaunch = nil; diff --git a/Sparkle/SUHost.h b/Sparkle/SUHost.h index 927b354d..c317baf5 100644 --- a/Sparkle/SUHost.h +++ b/Sparkle/SUHost.h @@ -13,7 +13,6 @@ - (instancetype)initWithBundle:(NSBundle *)aBundle; @property (readonly, copy) NSString *bundlePath; -@property (readonly, copy) NSString *installationPath; @property (readonly, copy) NSString *name; @property (readonly, copy) NSString *version; @property (readonly, copy) NSString *displayVersion; diff --git a/Sparkle/SUHost.m b/Sparkle/SUHost.m index 31d66395..aefb32d7 100644 --- a/Sparkle/SUHost.m +++ b/Sparkle/SUHost.m @@ -60,26 +60,13 @@ } -- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@, %@>", [self class], [self bundlePath], [self installationPath]]; } +- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@>", [self class], [self bundlePath]]; } - (NSString *)bundlePath { return [self.bundle bundlePath]; } -- (NSString *)installationPath -{ - if (SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME) { - // We'll install to "#{CFBundleName}.app", but only if that path doesn't already exist. If we're "Foo 4.2.app," and there's a "Foo.app" in this directory, we don't want to overwrite it! But if there's no "Foo.app," we'll take that name. - NSString *normalizedAppPath = [[[self.bundle bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.%@", [self.bundle objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleNameKey], [[self.bundle bundlePath] pathExtension]]]; - - if (![[NSFileManager defaultManager] fileExistsAtPath:normalizedAppPath]) { - return normalizedAppPath; - } - } - return [self.bundle bundlePath]; -} - - (NSString *__nonnull)name { NSString *name; diff --git a/Sparkle/SUInstaller.h b/Sparkle/SUInstaller.h index bd179b1a..43facc32 100644 --- a/Sparkle/SUInstaller.h +++ b/Sparkle/SUInstaller.h @@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN @interface SUInstaller : NSObject -+ (nullable id)installerForHost:(SUHost *)host updateDirectory:(NSString *)updateDirectory versionComparator:(id )comparator error:(NSError **)error; ++ (nullable id)installerForHost:(SUHost *)host installationPath:(NSString *)installationPath updateDirectory:(NSString *)updateDirectory versionComparator:(id )comparator error:(NSError **)error; + (NSString *)installSourcePathInUpdateFolder:(NSString *)inUpdateFolder forHost:(SUHost *)host isPackage:(BOOL *)isPackagePtr isGuided:(nullable BOOL *)isGuidedPtr; diff --git a/Sparkle/SUInstaller.m b/Sparkle/SUInstaller.m index 4f2a63c8..ce1a51d9 100644 --- a/Sparkle/SUInstaller.m +++ b/Sparkle/SUInstaller.m @@ -109,7 +109,7 @@ return newAppDownloadPath; } -+ (nullable id)installerForHost:(SUHost *)host updateDirectory:(NSString *)updateDirectory versionComparator:(id )comparator error:(NSError * __autoreleasing *)error ++ (nullable id)installerForHost:(SUHost *)host installationPath:(NSString *)installationPath updateDirectory:(NSString *)updateDirectory versionComparator:(id )comparator error:(NSError * __autoreleasing *)error { BOOL isPackage = NO; BOOL isGuided = NO; @@ -128,7 +128,7 @@ } else if (isPackage) { installer = [[SUPackageInstaller alloc] initWithPackagePath:newDownloadPath]; } else { - installer = [[SUPlainInstaller alloc] initWithHost:host applicationPath:newDownloadPath installationPath:host.installationPath versionComparator:comparator]; + installer = [[SUPlainInstaller alloc] initWithHost:host applicationPath:newDownloadPath installationPath:installationPath versionComparator:comparator]; } return installer; } diff --git a/Sparkle/SUStatusController.m b/Sparkle/SUStatusController.m index b60a9783..271e90d5 100644 --- a/Sparkle/SUStatusController.m +++ b/Sparkle/SUStatusController.m @@ -40,7 +40,7 @@ return self; } -- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@, %@>", [self class], [self.host bundlePath], [self.host installationPath]]; } +- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@>", [self class], [self.host bundlePath]]; } - (void)windowDidLoad { diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index 5969156e..b5f65317 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -119,7 +119,7 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification #endif } -- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@, %@>", [self class], [self.host bundlePath], [self.host installationPath]]; } +- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@>", [self class], [self.host bundlePath]]; } - (void)startUpdateCycle {