Merge tag '1.13.0' into develop

# Conflicts:
#	Sparkle/Autoupdate/Autoupdate.m
#	Sparkle/SUBasicUpdateDriver.m
#	Sparkle/SUErrors.h
#	Sparkle/SUUIBasedUpdateDriver.m
#	Sparkle/SUUpdateDriver.h
#	Sparkle/SUUpdateDriver.m
#	Sparkle/Sparkle.h
This commit is contained in:
Dmytro Tretiakov committed 2016-01-29 17:17:19 +02:00
commit b01c8ab023
121 files changed
+6861 -4098

No files matched your search

+22 -14
View File
@@ -8,6 +8,8 @@
#import "SUTestApplicationDelegate.h"
#import "SUUpdateSettingsWindowController.h"
#import "SUFileManager.h"
#import "SUTestWebServer.h"
#define MACROSTRING(x) #x
#define NSSTRING_MACRO(x) @MACROSTRING(x)
@@ -19,14 +21,14 @@
@interface SUTestApplicationDelegate ()
@property (nonatomic) SUUpdateSettingsWindowController *updateSettingsWindowController;
@property (nonatomic) NSTask *serverTask;
@property (nonatomic) SUTestWebServer *webServer;
@end
@implementation SUTestApplicationDelegate
@synthesize updateSettingsWindowController = _updateSettingsWindowController;
@synthesize serverTask = _serverTask;
@synthesize webServer = _webServer;
static NSString * const UPDATED_VERSION = @"2.0";
static NSString * const CODE_SIGN_ID = NSSTRING_MACRO(CODE_SIGN_IDENTITY);
@@ -45,11 +47,11 @@ static NSString * const CODE_SIGN_ID = NSSTRING_MACRO(CODE_SIGN_IDENTITY);
[[NSApplication sharedApplication] terminate:nil];
}
NSFileManager *fileManager = [NSFileManager defaultManager];
SUFileManager *fileManager = [SUFileManager fileManagerAllowingAuthorization:NO];
// Locate user's cache directory
NSError *cacheError = nil;
NSURL *cacheDirectoryURL = [fileManager URLForDirectory:NSCachesDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:&cacheError];
NSURL *cacheDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSCachesDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:&cacheError];
if (cacheDirectoryURL == nil) {
NSLog(@"Failed to locate cache directory with error: %@", cacheError);
@@ -61,7 +63,7 @@ static NSString * const CODE_SIGN_ID = NSSTRING_MACRO(CODE_SIGN_IDENTITY);
// Create a directory that'll be used for our web server listing
NSURL *serverDirectoryURL = [cacheDirectoryURL URLByAppendingPathComponent:bundleIdentifier];
if ([fileManager fileExistsAtPath:serverDirectoryURL.path]) {
if ([serverDirectoryURL checkResourceIsReachableAndReturnError:nil]) {
NSError *removeServerDirectoryError = nil;
if (![fileManager removeItemAtURL:serverDirectoryURL error:&removeServerDirectoryError]) {
@@ -70,7 +72,7 @@ static NSString * const CODE_SIGN_ID = NSSTRING_MACRO(CODE_SIGN_IDENTITY);
}
NSError *createDirectoryError = nil;
if (![fileManager createDirectoryAtURL:serverDirectoryURL withIntermediateDirectories:YES attributes:nil error:&createDirectoryError]) {
if (![[NSFileManager defaultManager] createDirectoryAtURL:serverDirectoryURL withIntermediateDirectories:YES attributes:nil error:&createDirectoryError]) {
NSLog(@"Failed creating directory at %@ with error %@", serverDirectoryURL.path, createDirectoryError);
assert(NO);
}
@@ -89,7 +91,7 @@ static NSString * const CODE_SIGN_ID = NSSTRING_MACRO(CODE_SIGN_IDENTITY);
// Update bundle's version keys to latest version
NSURL *infoURL = [[destinationBundleURL URLByAppendingPathComponent:@"Contents"] URLByAppendingPathComponent:@"Info.plist"];
BOOL infoFileExists = [fileManager fileExistsAtPath:infoURL.path];
BOOL infoFileExists = [infoURL checkResourceIsReachableAndReturnError:nil];
assert(infoFileExists);
NSMutableDictionary *infoDictionary = [[NSMutableDictionary alloc] initWithContentsOfURL:infoURL];
@@ -111,20 +113,21 @@ static NSString * const CODE_SIGN_ID = NSSTRING_MACRO(CODE_SIGN_IDENTITY);
}
// Change current working directory so web server knows where to list files
BOOL changedCurrentWorkingDirectory = [fileManager changeCurrentDirectoryPath:serverDirectoryURL.path];
assert(changedCurrentWorkingDirectory);
NSString *serverDirectoryPath = serverDirectoryURL.path;
assert(serverDirectoryPath != nil);
// Create the archive for our update
NSString *zipName = @"Sparkle_Test_App.zip";
NSTask *dittoTask = [[NSTask alloc] init];
dittoTask.launchPath = @"/usr/bin/ditto";
dittoTask.arguments = @[@"-c", @"-k", @"--sequesterRsrc", @"--keepParent", destinationBundleURL.lastPathComponent, zipName];
dittoTask.currentDirectoryPath = serverDirectoryPath;
[dittoTask launch];
[dittoTask waitUntilExit];
assert(dittoTask.terminationStatus == 0);
[[NSFileManager defaultManager] removeItemAtURL:destinationBundleURL error:NULL];
[fileManager removeItemAtURL:destinationBundleURL error:NULL];
// Don't ever do this at home, kids (seriously)
// (that is, including the private key inside of your application)
@@ -138,7 +141,7 @@ static NSString * const CODE_SIGN_ID = NSSTRING_MACRO(CODE_SIGN_IDENTITY);
signUpdateTask.launchPath = signUpdatePath;
NSURL *archiveURL = [serverDirectoryURL URLByAppendingPathComponent:zipName];
signUpdateTask.arguments = @[archiveURL, privateKeyPath];
signUpdateTask.arguments = @[archiveURL.path, privateKeyPath];
NSPipe *outputPipe = [NSPipe pipe];
signUpdateTask.standardOutput = outputPipe;
@@ -155,7 +158,7 @@ static NSString * const CODE_SIGN_ID = NSSTRING_MACRO(CODE_SIGN_IDENTITY);
// Obtain the file attributes to get the file size of our update later
NSError *fileAttributesError = nil;
NSDictionary *archiveFileAttributes = [fileManager attributesOfItemAtPath:archiveURL.path error:&fileAttributesError];
NSDictionary *archiveFileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:archiveURL.path error:&fileAttributesError];
if (archiveFileAttributes == nil) {
NSLog(@"Failed to retrieve file attributes from archive with error %@", fileAttributesError);
assert(NO);
@@ -194,7 +197,12 @@ static NSString * const CODE_SIGN_ID = NSSTRING_MACRO(CODE_SIGN_IDENTITY);
}
// Finally start the server
self.serverTask = [NSTask launchedTaskWithLaunchPath:@"/usr/bin/python" arguments:@[@"-m", @"SimpleHTTPServer", @"1337"]];
SUTestWebServer *webServer = [[SUTestWebServer alloc] initWithPort:1337 workingDirectory:serverDirectoryPath];
if (!webServer) {
NSLog(@"Failed to create the web server");
assert(NO);
}
self.webServer = webServer;
// Show the Settings window
self.updateSettingsWindowController = [[SUUpdateSettingsWindowController alloc] init];
@@ -203,7 +211,7 @@ static NSString * const CODE_SIGN_ID = NSSTRING_MACRO(CODE_SIGN_IDENTITY);
- (void)applicationWillTerminate:(NSNotification * __unused)notification
{
[self.serverTask terminate];
[self.webServer close];
}
@end