diff --git a/Sparkle/SUBasicUpdateDriver.m b/Sparkle/SUBasicUpdateDriver.m index c426849b..2591288d 100644 --- a/Sparkle/SUBasicUpdateDriver.m +++ b/Sparkle/SUBasicUpdateDriver.m @@ -200,11 +200,11 @@ NSString *downloadFileName = [NSString stringWithFormat:@"%@ %@", [self.host name], [self.updateItem versionString]]; - self.tempDir = [[self.host appSupportPath] stringByAppendingPathComponent:downloadFileName]; + self.tempDir = [self.host.appCachePath stringByAppendingPathComponent:downloadFileName]; int cnt = 1; while ([[NSFileManager defaultManager] fileExistsAtPath:self.tempDir] && cnt <= 999) { - self.tempDir = [[self.host appSupportPath] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@ %d", downloadFileName, cnt++]]; + self.tempDir = [self.host.appCachePath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@ %d", downloadFileName, cnt++]]; } // Create the temporary directory if necessary. @@ -358,7 +358,7 @@ NSString *const relaunchPathToCopy = [sparkleBundle pathForResource:[[sparkleBundle infoDictionary] objectForKey:SURelaunchToolNameKey] ofType:@"app"]; if (relaunchPathToCopy != nil) { - NSString *targetPath = [[self.host appSupportPath] stringByAppendingPathComponent:[relaunchPathToCopy lastPathComponent]]; + NSString *targetPath = [self.host.appCachePath stringByAppendingPathComponent:[relaunchPathToCopy lastPathComponent]]; // Only the paranoid survive: if there's already a stray copy of relaunch there, we would have problems. NSError *error = nil; [[NSFileManager defaultManager] createDirectoryAtPath:[targetPath stringByDeletingLastPathComponent] withIntermediateDirectories:YES attributes:@{} error:&error]; diff --git a/Sparkle/SUHost.h b/Sparkle/SUHost.h index 6e4e49f9..4ec13286 100644 --- a/Sparkle/SUHost.h +++ b/Sparkle/SUHost.h @@ -18,7 +18,7 @@ - (instancetype)initWithBundle:(NSBundle *)aBundle; @property (readonly, copy) NSString *bundlePath; -@property (readonly, copy) NSString *appSupportPath; +@property (readonly, copy) NSString *appCachePath; @property (readonly, copy) NSString *installationPath; @property (readonly, copy) NSString *name; @property (readonly, copy) NSString *version; diff --git a/Sparkle/SUHost.m b/Sparkle/SUHost.m index 58c53651..20a8791e 100644 --- a/Sparkle/SUHost.m +++ b/Sparkle/SUHost.m @@ -66,21 +66,26 @@ typedef struct { return [self.bundle bundlePath]; } -- (NSString *)appSupportPath +- (NSString *)appCachePath { - NSArray *appSupportPaths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES); - NSString *appSupportPath = nil; - if (!appSupportPaths || [appSupportPaths count] == 0) - { - SULog(@"Failed to find app support directory! Using ~/Library/Application Support..."); - appSupportPath = [@"~/Library/Application Support" stringByExpandingTildeInPath]; + NSArray *cachePaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); + NSString *cachePath = nil; + if ([cachePaths count]) { + cachePath = cachePaths[0]; } - else { - appSupportPath = appSupportPaths[0]; + if (!cachePath) { + SULog(@"Failed to find user's cache directory! Using system default"); + cachePath = NSTemporaryDirectory(); } - appSupportPath = [appSupportPath stringByAppendingPathComponent:[self name]]; - appSupportPath = [appSupportPath stringByAppendingPathComponent:@".Sparkle"]; - return appSupportPath; + + NSString *name = [self.bundle bundleIdentifier]; + if (!name) { + name = [self name]; + } + + cachePath = [cachePath stringByAppendingPathComponent:name]; + cachePath = [cachePath stringByAppendingPathComponent:@"Sparkle"]; + return cachePath; } - (NSString *)installationPath