From 343d6866c42b06352bf512fae2cf7982d5c7278b Mon Sep 17 00:00:00 2001 From: Uli Kusterer Date: Fri, 4 Dec 2009 09:20:21 +0100 Subject: [PATCH] - finish_installation is now a real bundled app, so it can be localized. - It contains its own copy of Sparkle.strings and SUUpdateStatus.nib so it can show its progress prettier - We call TransformProcessType() before our first call to [NSApplication sharedApplication], so we can be launched as a command line tool and get a proper window server connection, and so our progress bars animate. - We still support the old "relaunch"-style mode of operation, just by not passing the folder to install. This is useful for other relaunch occasions, like setting one's own dock icon flag. - To do: Make sample app use the new finish_installation. --- Elgato/BuildSparkleFinishInstallTool.command | 10 + SUBasicUpdateDriver.m | 5 +- Sparkle.xcodeproj/project.pbxproj | 182 ++++++++++++++++++- finish_installation-Info.plist | 30 +++ finish_installation.m | 84 +++++---- finish_installation.pch | 16 ++ 6 files changed, 288 insertions(+), 39 deletions(-) create mode 100755 Elgato/BuildSparkleFinishInstallTool.command create mode 100644 finish_installation-Info.plist create mode 100644 finish_installation.pch diff --git a/Elgato/BuildSparkleFinishInstallTool.command b/Elgato/BuildSparkleFinishInstallTool.command new file mode 100755 index 00000000..f98a4b26 --- /dev/null +++ b/Elgato/BuildSparkleFinishInstallTool.command @@ -0,0 +1,10 @@ +#/bin/bash + +MY_PATH="`dirname $0`" +cd "$MY_PATH/../" + +xcodebuild -project Sparkle.xcodeproj -target finish_installation -configuration Release build + +cd "$MY_PATH/../build/Release/" + +/usr/bin/tar -czf "$MY_PATH/finish_installation.app.tar.gz" "finish_installation.app" \ No newline at end of file diff --git a/SUBasicUpdateDriver.m b/SUBasicUpdateDriver.m index b23eaa8e..86b623fc 100644 --- a/SUBasicUpdateDriver.m +++ b/SUBasicUpdateDriver.m @@ -233,7 +233,7 @@ if ([[updater delegate] respondsToSelector:@selector(updater:willInstallUpdate:)]) [[updater delegate] updater:updater willInstallUpdate:updateItem]; // Copy the relauncher into a temporary directory so we can get to it after the new version's installed. - NSString *relaunchPathToCopy = [[NSBundle bundleForClass:[self class]] pathForResource:@"finish_installation" ofType:@""]; + NSString *relaunchPathToCopy = [[NSBundle bundleForClass:[self class]] pathForResource:@"finish_installation" ofType:@"app"]; NSString *appSupportFolder = [[@"~/Library/Application Support/" stringByExpandingTildeInPath] stringByAppendingPathComponent: [host name]]; NSString *targetPath = [appSupportFolder stringByAppendingPathComponent:[relaunchPathToCopy lastPathComponent]]; #if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 @@ -291,7 +291,8 @@ NSString *pathToRelaunch = [host bundlePath]; if ([[updater delegate] respondsToSelector:@selector(pathToRelaunchForUpdater:)]) pathToRelaunch = [[updater delegate] pathToRelaunchForUpdater:updater]; - [NSTask launchedTaskWithLaunchPath:relaunchPath arguments:[NSArray arrayWithObjects:pathToRelaunch, [NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]], [downloadPath stringByDeletingLastPathComponent], nil]]; + NSString *relaunchToolPath = [relaunchPath stringByAppendingPathComponent: @"/Contents/MacOS/finish_installation"]; + [NSTask launchedTaskWithLaunchPath: relaunchToolPath arguments:[NSArray arrayWithObjects:pathToRelaunch, [NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]], [downloadPath stringByDeletingLastPathComponent], nil]]; [NSApp terminate:self]; } diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 4036b4b8..e7a7f6fe 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -21,6 +21,24 @@ 55D8F80B10C58B210011E7FA /* SULog.h in Headers */ = {isa = PBXBuildFile; fileRef = 55D8F80710C58B210011E7FA /* SULog.h */; }; 55D8F80C10C58B210011E7FA /* SULog.m in Sources */ = {isa = PBXBuildFile; fileRef = 55D8F80810C58B210011E7FA /* SULog.m */; }; 55D8F80D10C58B210011E7FA /* SULog.m in Sources */ = {isa = PBXBuildFile; fileRef = 55D8F80810C58B210011E7FA /* SULog.m */; }; + 55F9B62E10C6BD590099848A /* finish_installation.m in Sources */ = {isa = PBXBuildFile; fileRef = 613242130CD06CEF00106AA4 /* finish_installation.m */; }; + 55F9B62F10C6BD610099848A /* SUHost.m in Sources */ = {isa = PBXBuildFile; fileRef = 61EF67550E25B58D00F754E0 /* SUHost.m */; }; + 55F9B63010C6BD650099848A /* SUConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 61299A5F09CA6EB100B7442F /* SUConstants.m */; }; + 55F9B63510C6BE900099848A /* SUInstaller.m in Sources */ = {isa = PBXBuildFile; fileRef = 618FA5000DAE88B40026945C /* SUInstaller.m */; }; + 55F9B63610C6BE940099848A /* SUPlainInstaller.m in Sources */ = {isa = PBXBuildFile; fileRef = 618FA5040DAE8AB80026945C /* SUPlainInstaller.m */; }; + 55F9B63710C6BE970099848A /* SUPlainInstallerInternals.m in Sources */ = {isa = PBXBuildFile; fileRef = 61B5F8E509C4CE3C00B25A18 /* SUPlainInstallerInternals.m */; }; + 55F9B63810C6BE9A0099848A /* SUPackageInstaller.m in Sources */ = {isa = PBXBuildFile; fileRef = 618FA5210DAE8E8A0026945C /* SUPackageInstaller.m */; }; + 55F9B63910C6BE9F0099848A /* SUStandardVersionComparator.m in Sources */ = {isa = PBXBuildFile; fileRef = 61A225A30D1C4AC000430CCD /* SUStandardVersionComparator.m */; }; + 55F9B63A10C6BEA50099848A /* SUSystemProfiler.m in Sources */ = {isa = PBXBuildFile; fileRef = 61A2279B0D1CEE7600430CCD /* SUSystemProfiler.m */; }; + 55F9B63D10C6BEC00099848A /* SULog.m in Sources */ = {isa = PBXBuildFile; fileRef = 55D8F80810C58B210011E7FA /* SULog.m */; }; + 55F9B67F10C6BED60099848A /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 61B5F8F609C4CEB300B25A18 /* Security.framework */; }; + 55F9B73810C6BEDC0099848A /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0867D6A5FE840307C02AAC07 /* AppKit.framework */; }; + 55F9B7B810C6BEE20099848A /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0867D69BFE84028FC02AAC07 /* Foundation.framework */; }; + 55F9B7D010C6DDD60099848A /* Sparkle.icns in Resources */ = {isa = PBXBuildFile; fileRef = 61BBDF810A49220C00378739 /* Sparkle.icns */; }; + 55F9B7D110C6DDE50099848A /* Sparkle.strings in Resources */ = {isa = PBXBuildFile; fileRef = 61AAE8220A321A7F00D8810D /* Sparkle.strings */; }; + 55F9B7D710C6E2FF0099848A /* SUStatusController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6196CFE409C71ADE000DC222 /* SUStatusController.m */; }; + 55F9B7D810C6E3020099848A /* SUWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 61180BC90D64138900B4E0D1 /* SUWindowController.m */; }; + 55F9B7F410C6E8B50099848A /* SUStatus.nib in Resources */ = {isa = PBXBuildFile; fileRef = 610D5A740A1670A4004AAD9C /* SUStatus.nib */; }; 610134730DD250470049ACDF /* SUUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 610134710DD250470049ACDF /* SUUpdateDriver.h */; settings = {ATTRIBUTES = (); }; }; 610134740DD250470049ACDF /* SUUpdateDriver.m in Sources */ = {isa = PBXBuildFile; fileRef = 610134720DD250470049ACDF /* SUUpdateDriver.m */; }; 6101347B0DD2541A0049ACDF /* SUProbingUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 610134790DD2541A0049ACDF /* SUProbingUpdateDriver.h */; settings = {ATTRIBUTES = (); }; }; @@ -162,6 +180,10 @@ 55D8F80410C589F40011E7FA /* ThreadSafePreferences.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ThreadSafePreferences.h; path = Elgato/ThreadSafePreferences.h; sourceTree = ""; }; 55D8F80710C58B210011E7FA /* SULog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SULog.h; sourceTree = ""; }; 55D8F80810C58B210011E7FA /* SULog.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SULog.m; sourceTree = ""; }; + 55F9B5E410C68F890099848A /* finish_installation.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = finish_installation.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 55F9B5E610C68F890099848A /* finish_installation-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "finish_installation-Info.plist"; sourceTree = ""; }; + 55F9B7C310C6C1740099848A /* finish_installation-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "finish_installation-Info.plist"; sourceTree = ""; }; + 55F9B7E010C6E4A00099848A /* finish_installation.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = finish_installation.pch; sourceTree = ""; }; 610134710DD250470049ACDF /* SUUpdateDriver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUpdateDriver.h; sourceTree = ""; }; 610134720DD250470049ACDF /* SUUpdateDriver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUUpdateDriver.m; sourceTree = ""; }; 610134790DD2541A0049ACDF /* SUProbingUpdateDriver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUProbingUpdateDriver.h; sourceTree = ""; }; @@ -325,6 +347,16 @@ /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ + 55F9B5E210C68F890099848A /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 55F9B73810C6BEDC0099848A /* AppKit.framework in Frameworks */, + 55F9B67F10C6BED60099848A /* Security.framework in Frameworks */, + 55F9B7B810C6BEE20099848A /* Foundation.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 612279D60DB5470200AB99EA /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -375,6 +407,7 @@ 61B5F90209C4CEE200B25A18 /* Sparkle Test App.app */, DAAEFC960DA571DF0051E0D0 /* finish_installation */, 612279D90DB5470200AB99EA /* Sparkle Unit Tests.octest */, + 55F9B5E410C68F890099848A /* finish_installation.app */, ); name = Products; sourceTree = ""; @@ -391,12 +424,15 @@ 6101354A0DD25B7F0049ACDF /* Unarchiving */, 61299B3A09CB056100B7442F /* User Interface */, 61B5F8F309C4CE5900B25A18 /* Other Sources */, + 6101355D0DD25BB70049ACDF /* finish_installation Sources */, + 55F9B7C210C6C0DC0099848A /* finish_installation Resources */, 089C1665FE841158C02AAC07 /* Framework Resources */, 61227A100DB5484000AB99EA /* Tests */, 61B5F91D09C4CF7F00B25A18 /* Test Application Sources */, 0867D69AFE84028FC02AAC07 /* Apple Frameworks and Libraries */, FA1941C40D94A6EA00DD942E /* Configurations */, 034768DFFF38A50411DB9C8B /* Products */, + 55F9B5E610C68F890099848A /* finish_installation-Info.plist */, ); name = Sparkle; sourceTree = ""; @@ -428,6 +464,14 @@ name = "Framework Resources"; sourceTree = ""; }; + 55F9B7C210C6C0DC0099848A /* finish_installation Resources */ = { + isa = PBXGroup; + children = ( + 55F9B7C310C6C1740099848A /* finish_installation-Info.plist */, + ); + name = "finish_installation Resources"; + sourceTree = ""; + }; 6101354A0DD25B7F0049ACDF /* Unarchiving */ = { isa = PBXGroup; children = ( @@ -445,12 +489,13 @@ name = Unarchiving; sourceTree = ""; }; - 6101355D0DD25BB70049ACDF /* Support */ = { + 6101355D0DD25BB70049ACDF /* finish_installation Sources */ = { isa = PBXGroup; children = ( + 55F9B7E010C6E4A00099848A /* finish_installation.pch */, 613242130CD06CEF00106AA4 /* finish_installation.m */, ); - name = Support; + name = "finish_installation Sources"; sourceTree = ""; }; 61227A100DB5484000AB99EA /* Tests */ = { @@ -507,7 +552,6 @@ 61B5F8E509C4CE3C00B25A18 /* SUPlainInstallerInternals.m */, 618FA5200DAE8E8A0026945C /* SUPackageInstaller.h */, 618FA5210DAE8E8A0026945C /* SUPackageInstaller.m */, - 6101355D0DD25BB70049ACDF /* Support */, ); name = Installation; sourceTree = ""; @@ -648,6 +692,23 @@ /* End PBXHeadersBuildPhase section */ /* Begin PBXNativeTarget section */ + 55F9B5E310C68F890099848A /* finish_installation */ = { + isa = PBXNativeTarget; + buildConfigurationList = 55F9B5EB10C68F8A0099848A /* Build configuration list for PBXNativeTarget "finish_installation" */; + buildPhases = ( + 55F9B5E110C68F890099848A /* Sources */, + 55F9B5E010C68F890099848A /* Resources */, + 55F9B5E210C68F890099848A /* Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = finish_installation; + productName = finish_installation; + productReference = 55F9B5E410C68F890099848A /* finish_installation.app */; + productType = "com.apple.product-type.application"; + }; 612279D80DB5470200AB99EA /* Sparkle Unit Tests */ = { isa = PBXNativeTarget; buildConfigurationList = 612279DD0DB5470300AB99EA /* Build configuration list for PBXNativeTarget "Sparkle Unit Tests" */; @@ -778,11 +839,22 @@ 61B5F90109C4CEE200B25A18 /* Sparkle Test App */, DAAEFC950DA571DF0051E0D0 /* finish_installation tool */, 612279D80DB5470200AB99EA /* Sparkle Unit Tests */, + 55F9B5E310C68F890099848A /* finish_installation */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ + 55F9B5E010C68F890099848A /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 55F9B7D110C6DDE50099848A /* Sparkle.strings in Resources */, + 55F9B7D010C6DDD60099848A /* Sparkle.icns in Resources */, + 55F9B7F410C6E8B50099848A /* SUStatus.nib in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 612279D40DB5470200AB99EA /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -879,6 +951,25 @@ /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ + 55F9B5E110C68F890099848A /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 55F9B62E10C6BD590099848A /* finish_installation.m in Sources */, + 55F9B62F10C6BD610099848A /* SUHost.m in Sources */, + 55F9B63010C6BD650099848A /* SUConstants.m in Sources */, + 55F9B63510C6BE900099848A /* SUInstaller.m in Sources */, + 55F9B63610C6BE940099848A /* SUPlainInstaller.m in Sources */, + 55F9B63710C6BE970099848A /* SUPlainInstallerInternals.m in Sources */, + 55F9B63810C6BE9A0099848A /* SUPackageInstaller.m in Sources */, + 55F9B63910C6BE9F0099848A /* SUStandardVersionComparator.m in Sources */, + 55F9B63A10C6BEA50099848A /* SUSystemProfiler.m in Sources */, + 55F9B63D10C6BEC00099848A /* SULog.m in Sources */, + 55F9B7D710C6E2FF0099848A /* SUStatusController.m in Sources */, + 55F9B7D810C6E3020099848A /* SUWindowController.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 612279D50DB5470200AB99EA /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -1106,6 +1197,8 @@ 1DEB91B208733DA50010E9CD /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + GCC_VERSION = 4.0; + SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.4u.sdk"; WARNING_CFLAGS = "-Wundeclared-selector"; }; name = Debug; @@ -1113,13 +1206,86 @@ 1DEB91B308733DA50010E9CD /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + GCC_VERSION = 4.0; + SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.4u.sdk"; WARNING_CFLAGS = "-Wundeclared-selector"; }; name = Release; }; + 55F9B5E810C68F8A0099848A /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + COPY_PHASE_STRIP = NO; + GCC_DYNAMIC_NO_PIC = NO; + GCC_ENABLE_FIX_AND_CONTINUE = YES; + GCC_MODEL_TUNING = G5; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = finish_installation.pch; + INFOPLIST_FILE = "finish_installation-Info.plist"; + INSTALL_PATH = "$(HOME)/Applications"; + OTHER_LDFLAGS = ( + "-framework", + Foundation, + "-framework", + AppKit, + ); + PREBINDING = NO; + PRODUCT_NAME = finish_installation; + }; + name = Debug; + }; + 55F9B5E910C68F8A0099848A /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + COPY_PHASE_STRIP = YES; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + GCC_ENABLE_FIX_AND_CONTINUE = NO; + GCC_MODEL_TUNING = G5; + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = finish_installation.pch; + INFOPLIST_FILE = "finish_installation-Info.plist"; + INSTALL_PATH = "$(HOME)/Applications"; + OTHER_LDFLAGS = ( + "-framework", + Foundation, + "-framework", + AppKit, + ); + PREBINDING = NO; + PRODUCT_NAME = finish_installation; + ZERO_LINK = NO; + }; + name = Release; + }; + 55F9B5EA10C68F8A0099848A /* Release (GC dual-mode; 10.5-only) */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + GCC_ENABLE_FIX_AND_CONTINUE = YES; + GCC_MODEL_TUNING = G5; + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = finish_installation.pch; + INFOPLIST_FILE = "finish_installation-Info.plist"; + INSTALL_PATH = "$(HOME)/Applications"; + OTHER_LDFLAGS = ( + "-framework", + Foundation, + "-framework", + AppKit, + ); + PREBINDING = NO; + PRODUCT_NAME = finish_installation; + }; + name = "Release (GC dual-mode; 10.5-only)"; + }; 61072EAD0DF263BD008FE88B /* Release (GC dual-mode; 10.5-only) */ = { isa = XCBuildConfiguration; buildSettings = { + GCC_VERSION = 4.0; + SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.4u.sdk"; WARNING_CFLAGS = "-Wundeclared-selector"; }; name = "Release (GC dual-mode; 10.5-only)"; @@ -1289,6 +1455,16 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + 55F9B5EB10C68F8A0099848A /* Build configuration list for PBXNativeTarget "finish_installation" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 55F9B5E810C68F8A0099848A /* Debug */, + 55F9B5E910C68F8A0099848A /* Release */, + 55F9B5EA10C68F8A0099848A /* Release (GC dual-mode; 10.5-only) */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; 612279DD0DB5470300AB99EA /* Build configuration list for PBXNativeTarget "Sparkle Unit Tests" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/finish_installation-Info.plist b/finish_installation-Info.plist new file mode 100644 index 00000000..875efd5b --- /dev/null +++ b/finish_installation-Info.plist @@ -0,0 +1,30 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIconFile + Sparkle + CFBundleIdentifier + org.andymatuschak.${PRODUCT_NAME:rfc1034identifier} + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + LSMinimumSystemVersion + ${MACOSX_DEPLOYMENT_TARGET} + NSMainNibFile + MainMenu + NSPrincipalClass + NSApplication + + diff --git a/finish_installation.m b/finish_installation.m index 263127b2..43e0fc87 100644 --- a/finish_installation.m +++ b/finish_installation.m @@ -3,6 +3,7 @@ #import "SUInstaller.h" #import "SUHost.h" #import "SUStandardVersionComparator.h" +#import "SUStatusController.h" #include @@ -12,10 +13,15 @@ pid_t parentProcessId; const char *folderPath; NSString *selfPath; + NSTimer *watchdogTimer; } -- (void) relaunch; -- (void) install; +- (void) parentHasQuit; + +- (void) relaunch; +- (void) install; + +- (void) watchdog:(NSTimer *)timer; @end @@ -27,17 +33,16 @@ self = [super init]; if (self != nil) { - ProcessSerialNumber psn = { 0, kCurrentProcess }; - TransformProcessType( &psn, kProcessTransformToForegroundApplication ); - [[NSApplication sharedApplication] activateIgnoringOtherApps: YES]; - executablePath = execPath; parentProcessId = ppid; folderPath = inFolderPath; selfPath = [inSelfPath retain]; - if (getppid() == 1) // ppid is launchd (1) => parent terminated already - [self install]; - [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(watchdog:) userInfo:nil repeats:YES]; + BOOL alreadyTerminated = (getppid() == 1); // ppid is launchd (1) => parent terminated already + + if( alreadyTerminated ) + [self parentHasQuit]; + else + watchdogTimer = [[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(watchdog:) userInfo:nil repeats:YES] retain]; } return self; } @@ -47,16 +52,29 @@ { [selfPath release]; selfPath = nil; + [watchdogTimer release]; + watchdogTimer = nil; [super dealloc]; } +-(void) parentHasQuit +{ + [watchdogTimer invalidate]; + + if( folderPath ) + [self install]; + else + [self relaunch]; +} + + - (void)watchdog:(NSTimer *)timer { ProcessSerialNumber psn; if (GetProcessForPID(parentProcessId, &psn) == procNotFound) - [self install]; + [self parentHasQuit]; } - (void) relaunch @@ -78,29 +96,15 @@ NSBundle *theBundle = [NSBundle bundleWithPath: [NSString stringWithUTF8String: executablePath]]; SUHost *theHost = [[[SUHost alloc] initWithBundle: theBundle] autorelease]; - NSRect wdBox = NSMakeRect( 100, 100, 300, 70 ); - NSWindow *statusWindowHack = [[NSWindow alloc] initWithContentRect: wdBox - styleMask: NSTitledWindowMask backing: NSBackingStoreBuffered defer: NO]; // +++ LEAK, but app closes when this finishes anyway. - NSTextField *progressMessageField = [[[NSTextField alloc] initWithFrame: NSMakeRect( 12, 40, wdBox.size.width -24, 18 )] autorelease]; - [progressMessageField setStringValue: [[NSFileManager defaultManager] displayNameAtPath: [theHost bundlePath]]]; - [progressMessageField setDrawsBackground: NO]; - [progressMessageField setBordered: NO]; - [progressMessageField setBezeled: NO]; - [progressMessageField setEditable: NO]; - [[statusWindowHack contentView] addSubview: progressMessageField]; - - NSProgressIndicator *progressView = [[[NSProgressIndicator alloc] initWithFrame: NSMakeRect( 12, 16, wdBox.size.width -24, 16 )] autorelease]; - [progressView setStyle: NSProgressIndicatorBarStyle]; - [progressView setIndeterminate: YES]; - [[statusWindowHack contentView] addSubview: progressView]; - [statusWindowHack center]; - [[NSApplication sharedApplication] activateIgnoringOtherApps: YES]; - [statusWindowHack makeKeyAndOrderFront: nil]; - [progressView startAnimation: self]; + SUStatusController* statusCtl = [[SUStatusController alloc] initWithHost: theHost]; // We quit anyway after we've installed, so leak this for now. + [statusCtl setButtonTitle: SULocalizedString(@"Cancel Update",@"") target: nil action: Nil isDefault: NO]; + [statusCtl beginActionWithTitle: SULocalizedString(@"Installing update...",@"") + maxProgressValue: 0 statusText: @""]; + [statusCtl showWindow: self]; [SUInstaller installFromUpdateFolder: [NSString stringWithUTF8String: folderPath] overHost: theHost - delegate: self synchronously: YES + delegate: self synchronously: NO versionComparator: [SUStandardVersionComparator defaultComparator]]; } @@ -119,8 +123,16 @@ int main (int argc, const char * argv[]) { - if (argc != 4) return EXIT_FAILURE; + if( argc < 3 || argc > 4 ) + return EXIT_FAILURE; + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + + ProcessSerialNumber psn = { 0, kCurrentProcess }; + TransformProcessType( &psn, kProcessTransformToForegroundApplication ); + [[NSApplication sharedApplication] activateIgnoringOtherApps: YES]; + + #if 0 // Cmdline tool NSString* selfPath = nil; if( argv[0][0] == '/' ) selfPath = [NSString stringWithUTF8String: argv[0]]; @@ -129,11 +141,15 @@ int main (int argc, const char * argv[]) selfPath = [[NSFileManager defaultManager] currentDirectoryPath]; selfPath = [selfPath stringByAppendingPathComponent: [NSString stringWithUTF8String: argv[0]]]; } - - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + #else + NSString* selfPath = [[NSBundle mainBundle] bundlePath]; + #endif [NSApplication sharedApplication]; - [[[TerminationListener alloc] initWithExecutablePath: argv[1] parentProcessId: atoi(argv[2]) folderPath: argv[3] selfPath: selfPath] autorelease]; + [[[TerminationListener alloc] initWithExecutablePath: (argc > 1) ? argv[1] : NULL + parentProcessId: (argc > 2) ? atoi(argv[2]) : 0 + folderPath: (argc > 3) ? argv[3] : NULL + selfPath: selfPath] autorelease]; [[NSApplication sharedApplication] run]; [pool drain]; diff --git a/finish_installation.pch b/finish_installation.pch new file mode 100644 index 00000000..f29230f1 --- /dev/null +++ b/finish_installation.pch @@ -0,0 +1,16 @@ +// +// Sparkle.pch +// Sparkle +// +// Created by Andy Matuschak on 7/23/08. +// Copyright 2008 Andy Matuschak. All rights reserved. +// + +#define SPARKLE_BUNDLE [NSBundle mainBundle] +#define SULocalizedString(key,comment) NSLocalizedStringFromTableInBundle(key, @"Sparkle", SPARKLE_BUNDLE, comment) +#define SUAbstractFail() NSAssert2(nil, @"Can't call %@ on an instance of %@; this is an abstract method!", __PRETTY_FUNCTION__, [self class]); + +#ifdef __OBJC__ +#import +#import "SUConstants.h" +#endif