From 3956a27bd06fa9dfbd054faa71d616b13cbce1b7 Mon Sep 17 00:00:00 2001 From: Dmytro Tretiakov Date: Wed, 30 Jul 2014 16:26:11 +0300 Subject: [PATCH] Add ability to skip install in finish_installation tool. --- SUBasicUpdateDriver.m | 12 +++++------- finish_installation.m | 14 ++++++++------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/SUBasicUpdateDriver.m b/SUBasicUpdateDriver.m index c84b66b7..df9dfca2 100644 --- a/SUBasicUpdateDriver.m +++ b/SUBasicUpdateDriver.m @@ -376,12 +376,10 @@ NSArray *SUGetAllDevMateURLHosts(void) if ([[updater delegate] respondsToSelector:@selector(updater:willInstallUpdate:)]) [[updater delegate] updater:updater willInstallUpdate:updateItem]; + BOOL isAlreadyInstalled = NO; if ([[updater delegate] respondsToSelector:@selector(updater:overrideInstallUpdate:downloadPath:)]) { - if ([[updater delegate] updater:updater overrideInstallUpdate:updateItem downloadPath:tempDir]) - { - return; - } + isAlreadyInstalled = [[updater delegate] updater:updater overrideInstallUpdate:updateItem downloadPath:tempDir] } // Copy the relauncher into a temporary directory so we can get to it after the new version's installed. @@ -405,10 +403,10 @@ NSArray *SUGetAllDevMateURLHosts(void) { copiedRelaunchTool = [SUPlainInstaller copyPathWithAuthentication:relaunchPathToCopy overPath:targetPath temporaryName:nil error:&error]; } - [self finishRelaunchAfterSuccessfulCopying:copiedRelaunchTool fromPath:relaunchPathToCopy toPath:targetPath relaunch:relaunch]; + [self finishRelaunchAfterSuccessfulCopying:copiedRelaunchTool fromPath:relaunchPathToCopy toPath:targetPath isInstalled:isAlreadyInstalled relaunch:relaunch]; } -- (void)finishRelaunchAfterSuccessfulCopying:(BOOL)copiedRelaunchTool fromPath:(NSString *)relaunchPathToCopy toPath:(NSString *)targetPath relaunch:(BOOL)relaunch +- (void)finishRelaunchAfterSuccessfulCopying:(BOOL)copiedRelaunchTool fromPath:(NSString *)relaunchPathToCopy toPath:(NSString *)targetPath isInstalled:(BOOL)isInstalled relaunch:(BOOL)relaunch { NSError *error = nil; @@ -433,7 +431,7 @@ NSArray *SUGetAllDevMateURLHosts(void) if ([[updater delegate] respondsToSelector:@selector(pathToRelaunchForUpdater:)]) pathToRelaunch = [[updater delegate] pathToRelaunchForUpdater:updater]; NSString *relaunchToolPath = [relaunchPath stringByAppendingPathComponent: @"/Contents/MacOS/finish_installation"]; - NSArray *arguments = [NSArray arrayWithObjects:[host bundlePath], pathToRelaunch, [NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]], tempDir, relaunch ? @"1" : @"0", nil]; + NSArray *arguments = [NSArray arrayWithObjects:[host bundlePath], pathToRelaunch, [NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]], tempDir, relaunch ? @"1" : @"0", isInstalled ? @"1" : @"0" nil]; if (SUShouldUseXPCInstaller()) { [SUXPCInstaller launchTaskWithLaunchPath:relaunchToolPath arguments:arguments completionHandler:^{ diff --git a/finish_installation.m b/finish_installation.m index 740de4b4..216fd8cb 100644 --- a/finish_installation.m +++ b/finish_installation.m @@ -24,6 +24,7 @@ NSTimer *longInstallationTimer; SUHost *host; BOOL shouldRelaunch; + BOOL alreadyInstalled; } - (void) parentHasQuit; @@ -39,17 +40,17 @@ @implementation TerminationListener - (id) initWithHostPath:(const char *)inhostpath executablePath:(const char *)execpath parentProcessId:(pid_t)ppid folderPath: (const char*)infolderpath shouldRelaunch:(BOOL)relaunch - selfPath: (NSString*)inSelfPath +selfPath: (NSString*)inSelfPath alreadyInstalled:(BOOL)inalreadyInstalled { if( !(self = [super init]) ) return nil; - hostpath = inhostpath; executablepath = execpath; parentprocessid = ppid; folderpath = infolderpath; selfPath = [inSelfPath retain]; shouldRelaunch = relaunch; + alreadyInstalled = inalreadyInstalled; BOOL alreadyTerminated = (getppid() == 1); // ppid is launchd (1) => parent terminated already @@ -90,7 +91,7 @@ target: self selector: @selector(showAppIconInDock:) userInfo:nil repeats:NO] retain]; - if( folderpath ) + if( folderpath && !alreadyInstalled ) [self install]; else [self relaunch]; @@ -177,7 +178,7 @@ int main (int argc, const char * argv[]) { - if( argc < 5 || argc > 6 ) + if( argc < 5 || argc > 7 ) return EXIT_FAILURE; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; @@ -198,14 +199,15 @@ int main (int argc, const char * argv[]) #else NSString* selfPath = [[NSBundle mainBundle] bundlePath]; #endif - + [NSApplication sharedApplication]; [[[TerminationListener alloc] initWithHostPath: (argc > 1) ? argv[1] : NULL executablePath: (argc > 2) ? argv[2] : NULL parentProcessId: (argc > 3) ? atoi(argv[3]) : 0 folderPath: (argc > 4) ? argv[4] : NULL shouldRelaunch: (argc > 5) ? atoi(argv[5]) : 1 - selfPath: selfPath] autorelease]; + selfPath: selfPath + alreadyInstalled: (argc > 6) ? atoi(argv[6]) : 0] autorelease]; [[NSApplication sharedApplication] run]; [pool drain];