mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-25 04:47:55 +00:00
Remove duplicated Sparkle Cache directory code
This commit is contained in:
1 parent
1392190d47
commit
1aedf2f9ed
5 files changed
+66
-38
No files matched your search
@@ -8,6 +8,7 @@
|
||||
|
||||
#import "SUPersistentDownloader.h"
|
||||
#import "SUPersistentDownloaderDelegate.h"
|
||||
#import "SULocalCacheDirectory.h"
|
||||
#import "SUURLRequest.h"
|
||||
#import "SUErrors.h"
|
||||
|
||||
@@ -47,7 +48,7 @@ static NSString *SUPersistentDownloadingReason = @"Downloading persistent file";
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// Remove our old caches path so we don't start accumulating files in there
|
||||
NSString *cachePath = [[self class] sparkleCachePathForBundleIdentifier:bundleIdentifier];
|
||||
NSString *cachePath = [SULocalCacheDirectory cachePathForBundleIdentifier:bundleIdentifier];
|
||||
if ([[NSFileManager defaultManager] fileExistsAtPath:cachePath]) {
|
||||
[[NSFileManager defaultManager] removeItemAtPath:cachePath error:NULL];
|
||||
}
|
||||
@@ -86,21 +87,11 @@ static NSString *SUPersistentDownloadingReason = @"Downloading persistent file";
|
||||
});
|
||||
}
|
||||
|
||||
// If we support sandboxing this component in the future, it is important to note this may return a different path
|
||||
// For this reason, this method should not be a part of SUHost because its behavior depends on what kind of process it's being invoked from
|
||||
+ (NSString *)sparkleCachePathForBundleIdentifier:(NSString *)bundleIdentifier
|
||||
{
|
||||
NSURL *cacheURL = [[NSFileManager defaultManager] URLForDirectory:NSCachesDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:NULL];
|
||||
|
||||
assert(cacheURL != nil);
|
||||
return [[[cacheURL URLByAppendingPathComponent:bundleIdentifier] URLByAppendingPathComponent:@SPARKLE_BUNDLE_IDENTIFIER] path];
|
||||
}
|
||||
|
||||
- (void)download:(NSURLDownload *)__unused d decideDestinationWithSuggestedFilename:(NSString *)name
|
||||
{
|
||||
NSString *downloadFileName = self.desiredFilename;
|
||||
|
||||
NSString *cachePath = [[self class] sparkleCachePathForBundleIdentifier:self.bundleIdentifier];
|
||||
NSString *cachePath = [SULocalCacheDirectory cachePathForBundleIdentifier:self.bundleIdentifier];
|
||||
|
||||
NSString *tempDir = [cachePath stringByAppendingPathComponent:downloadFileName];
|
||||
int count = 1;
|
||||
|
||||
@@ -137,6 +137,9 @@
|
||||
721BC2031D17A4FC002BC71E /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 61B5F8F609C4CEB300B25A18 /* Security.framework */; };
|
||||
721BC2041D17A51B002BC71E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0867D69BFE84028FC02AAC07 /* Foundation.framework */; };
|
||||
721BC20B1D17A5AD002BC71E /* CoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 721BC20A1D17A5AD002BC71E /* CoreServices.framework */; };
|
||||
721BC20E1D1CDE55002BC71E /* SULocalCacheDirectory.h in Headers */ = {isa = PBXBuildFile; fileRef = 721BC20C1D1CDE55002BC71E /* SULocalCacheDirectory.h */; };
|
||||
721BC20F1D1CDE55002BC71E /* SULocalCacheDirectory.m in Sources */ = {isa = PBXBuildFile; fileRef = 721BC20D1D1CDE55002BC71E /* SULocalCacheDirectory.m */; };
|
||||
721BC2101D1CDE55002BC71E /* SULocalCacheDirectory.m in Sources */ = {isa = PBXBuildFile; fileRef = 721BC20D1D1CDE55002BC71E /* SULocalCacheDirectory.m */; };
|
||||
721C245A1CB75756005440CB /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 525A278F133D6AE900FD8D70 /* Cocoa.framework */; };
|
||||
721C245B1CB75765005440CB /* SURemoteMessagePort.m in Sources */ = {isa = PBXBuildFile; fileRef = 729746441C91212400FC134E /* SURemoteMessagePort.m */; };
|
||||
721C245C1CB7576E005440CB /* SUStatusController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6196CFE409C71ADE000DC222 /* SUStatusController.m */; };
|
||||
@@ -858,6 +861,8 @@
|
||||
721BC2061D17A532002BC71E /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = System/Library/Frameworks/CoreFoundation.framework; sourceTree = SDKROOT; };
|
||||
721BC2081D17A553002BC71E /* Carbon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Carbon.framework; path = System/Library/Frameworks/Carbon.framework; sourceTree = SDKROOT; };
|
||||
721BC20A1D17A5AD002BC71E /* CoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreServices.framework; path = System/Library/Frameworks/CoreServices.framework; sourceTree = SDKROOT; };
|
||||
721BC20C1D1CDE55002BC71E /* SULocalCacheDirectory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SULocalCacheDirectory.h; sourceTree = "<group>"; };
|
||||
721BC20D1D1CDE55002BC71E /* SULocalCacheDirectory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SULocalCacheDirectory.m; sourceTree = "<group>"; };
|
||||
721C24451CB753E6005440CB /* Updater.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Updater.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
721C24571CB754E8005440CB /* ConfigInstallerProgress.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigInstallerProgress.xcconfig; sourceTree = "<group>"; };
|
||||
721C24581CB7567D005440CB /* InstallerProgress-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "InstallerProgress-Info.plist"; path = "Sparkle/InstallerProgress/InstallerProgress-Info.plist"; sourceTree = SOURCE_ROOT; };
|
||||
@@ -1506,6 +1511,8 @@
|
||||
14652F8319A9759F00959E44 /* SUExport.h */,
|
||||
61EF67580E25C5B400F754E0 /* SUHost.h */,
|
||||
61EF67550E25B58D00F754E0 /* SUHost.m */,
|
||||
721BC20C1D1CDE55002BC71E /* SULocalCacheDirectory.h */,
|
||||
721BC20D1D1CDE55002BC71E /* SULocalCacheDirectory.m */,
|
||||
55C14F04136EF6DB00649790 /* SULog.h */,
|
||||
55C14F05136EF6DB00649790 /* SULog.m */,
|
||||
726F2CE31BC9C33D001971A4 /* SUOperatingSystem.h */,
|
||||
@@ -1856,6 +1863,7 @@
|
||||
726E4A0E1C86881600C57C6A /* SUStandardUserDriverUIDelegate.h in Headers */,
|
||||
725F97A81C8B42D700265BE4 /* SUStandardUserDriverProtocol.h in Headers */,
|
||||
726E4A101C86B5A200C57C6A /* SUStandardUserDriverRemoteDelegate.h in Headers */,
|
||||
721BC20E1D1CDE55002BC71E /* SULocalCacheDirectory.h in Headers */,
|
||||
72B767DA1C9CD2E400A07552 /* SUUIBasedUpdateDriver.h in Headers */,
|
||||
725CB95A1C7121830064365A /* SUStandardUserDriver.h in Headers */,
|
||||
725CB9571C7120410064365A /* SUUserDriver.h in Headers */,
|
||||
@@ -2773,6 +2781,7 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
7293A1B11CEE9B9F00B957A7 /* SUURLRequest.m in Sources */,
|
||||
721BC2101D1CDE55002BC71E /* SULocalCacheDirectory.m in Sources */,
|
||||
723B5DA71CF7AB0100365F95 /* main.m in Sources */,
|
||||
728638ED1CAF50CE00783084 /* SUConstants.m in Sources */,
|
||||
723B5DA91CF7AB0100365F95 /* SUPersistentDownloader.m in Sources */,
|
||||
@@ -2834,6 +2843,7 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
72E641AC1D090F7F000404CA /* SUFileOperationConstants.m in Sources */,
|
||||
721BC20F1D1CDE55002BC71E /* SULocalCacheDirectory.m in Sources */,
|
||||
724A0A3E1CF7AF0E00D8C3D5 /* SUTemporaryDownloader.m in Sources */,
|
||||
723B5DAA1CF7AB6A00365F95 /* SUPersistentDownloader.m in Sources */,
|
||||
72F94F5A1CC450DE002DEE68 /* SUInstallerLauncher.m in Sources */,
|
||||
|
||||
Vendored
+4
-26
@@ -12,6 +12,7 @@
|
||||
#import "SUBasicUpdateDriver.h"
|
||||
#import "SUInstallerDriver.h"
|
||||
#import "SUDownloadDriver.h"
|
||||
#import "SULocalCacheDirectory.h"
|
||||
#import "SULog.h"
|
||||
|
||||
#ifdef _APPKITDEFINES_H
|
||||
@@ -47,38 +48,15 @@
|
||||
@synthesize updaterDelegate = _updaterDelegate;
|
||||
@synthesize userAgent = _userAgent;
|
||||
|
||||
// If we support sandboxing this component in the future, it is important to note this may return a different path
|
||||
// For this reason, this method should not be a part of SUHost because its behavior depends on what kind of process it's being invoked from
|
||||
#warning kind of duplicated code from SUPersistentDownloader ??
|
||||
+ (NSString *)sparkleCachePathForHost:(SUHost *)host
|
||||
{
|
||||
NSArray *cachePaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
||||
NSString *cachePath = nil;
|
||||
if ([cachePaths count]) {
|
||||
cachePath = [cachePaths objectAtIndex:0];
|
||||
}
|
||||
if (!cachePath) {
|
||||
SULog(@"Failed to find user's cache directory! Using system default");
|
||||
cachePath = NSTemporaryDirectory();
|
||||
}
|
||||
|
||||
NSString *name = [host.bundle bundleIdentifier];
|
||||
if (!name) {
|
||||
name = [host name];
|
||||
}
|
||||
|
||||
cachePath = [cachePath stringByAppendingPathComponent:name];
|
||||
cachePath = [cachePath stringByAppendingPathComponent:@SPARKLE_BUNDLE_IDENTIFIER];
|
||||
return cachePath;
|
||||
}
|
||||
|
||||
- (instancetype)initWithHost:(SUHost *)host sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater updaterDelegate:(nullable id <SUUpdaterDelegate>)updaterDelegate delegate:(id<SUCoreBasedUpdateDriverDelegate>)delegate
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_delegate = delegate;
|
||||
|
||||
NSString *cachePath = [[self class] sparkleCachePathForHost:host];
|
||||
NSString *bundleIdentifier = host.bundle.bundleIdentifier;
|
||||
assert(bundleIdentifier != nil);
|
||||
NSString *cachePath = [SULocalCacheDirectory cachePathForBundleIdentifier:bundleIdentifier];
|
||||
|
||||
_basicDriver = [[SUBasicUpdateDriver alloc] initWithHost:host updater:updater updaterDelegate:updaterDelegate delegate:self];
|
||||
_installerDriver = [[SUInstallerDriver alloc] initWithHost:host cachePath:cachePath sparkleBundle:sparkleBundle updater:updater updaterDelegate:updaterDelegate delegate:self];
|
||||
|
||||
Vendored
+23
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// SULocalCacheDirectory.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 6/23/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface SULocalCacheDirectory : NSObject
|
||||
|
||||
// Returns a path to a suitable cache directory to create specifically for Sparkle
|
||||
// Intermediate directories to this path may not exist yet
|
||||
// This path may depend on the type of running process,
|
||||
// such that sandboxed vs non-sandboxed processes could yield different paths
|
||||
+ (NSString *)cachePathForBundleIdentifier:(NSString *)bundleIdentifier;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
Vendored
+26
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// SULocalCacheDirectory.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 6/23/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SULocalCacheDirectory.h"
|
||||
|
||||
@implementation SULocalCacheDirectory
|
||||
|
||||
// If we support sandboxing this component in the future, it is important to note this may return a different path
|
||||
// For this reason, this method should not be a part of SUHost because its behavior depends on what kind of process it's being invoked from
|
||||
+ (NSString *)cachePathForBundleIdentifier:(NSString *)bundleIdentifier
|
||||
{
|
||||
NSURL *cacheURL = [[NSFileManager defaultManager] URLForDirectory:NSCachesDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:NULL];
|
||||
assert(cacheURL != nil);
|
||||
|
||||
NSString *resultPath = [[[cacheURL URLByAppendingPathComponent:bundleIdentifier] URLByAppendingPathComponent:@SPARKLE_BUNDLE_IDENTIFIER] path];
|
||||
assert(resultPath != nil);
|
||||
|
||||
return resultPath;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user