Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 159 lines (125 sloc) 4.295 kb
b2eab97 Made the relaunching process much snazzier, courtesy of Cedric Luthi. No...
andym authored
1
2 #import <AppKit/AppKit.h>
bbcfe7e Uli Kusterer - More WIP creating finish_installation that waits
uliwitness authored
3 #import "SUInstaller.h"
4 #import "SUHost.h"
5 #import "SUStandardVersionComparator.h"
343d686 Uli Kusterer - finish_installation is now a real bundled app, so it can be localized.
uliwitness authored
6 #import "SUStatusController.h"
b2eab97 Made the relaunching process much snazzier, courtesy of Cedric Luthi. No...
andym authored
7
fbcdba4 Fixes several warnings
Stuart Morgan authored
8 #include <unistd.h>
9
b2eab97 Made the relaunching process much snazzier, courtesy of Cedric Luthi. No...
andym authored
10 @interface TerminationListener : NSObject
11 {
bbcfe7e Uli Kusterer - More WIP creating finish_installation that waits
uliwitness authored
12 const char *executablePath;
13 pid_t parentProcessId;
14 const char *folderPath;
15 NSString *selfPath;
343d686 Uli Kusterer - finish_installation is now a real bundled app, so it can be localized.
uliwitness authored
16 NSTimer *watchdogTimer;
b2eab97 Made the relaunching process much snazzier, courtesy of Cedric Luthi. No...
andym authored
17 }
18
343d686 Uli Kusterer - finish_installation is now a real bundled app, so it can be localized.
uliwitness authored
19 - (void) parentHasQuit;
20
21 - (void) relaunch;
22 - (void) install;
23
24 - (void) watchdog:(NSTimer *)timer;
b2eab97 Made the relaunching process much snazzier, courtesy of Cedric Luthi. No...
andym authored
25
26 @end
27
28 @implementation TerminationListener
29
bbcfe7e Uli Kusterer - More WIP creating finish_installation that waits
uliwitness authored
30 - (id) initWithExecutablePath:(const char *)execPath parentProcessId:(pid_t)ppid folderPath: (const char*)inFolderPath
31 selfPath: (NSString*)inSelfPath
b2eab97 Made the relaunching process much snazzier, courtesy of Cedric Luthi. No...
andym authored
32 {
33 self = [super init];
4b74af2 Andy Matuschak Fixes 240385
andymatuschak authored
34 if (self != nil)
35 {
b2eab97 Made the relaunching process much snazzier, courtesy of Cedric Luthi. No...
andym authored
36 executablePath = execPath;
37 parentProcessId = ppid;
bbcfe7e Uli Kusterer - More WIP creating finish_installation that waits
uliwitness authored
38 folderPath = inFolderPath;
39 selfPath = [inSelfPath retain];
343d686 Uli Kusterer - finish_installation is now a real bundled app, so it can be localized.
uliwitness authored
40 BOOL alreadyTerminated = (getppid() == 1); // ppid is launchd (1) => parent terminated already
41
42 if( alreadyTerminated )
43 [self parentHasQuit];
44 else
45 watchdogTimer = [[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(watchdog:) userInfo:nil repeats:YES] retain];
b2eab97 Made the relaunching process much snazzier, courtesy of Cedric Luthi. No...
andym authored
46 }
47 return self;
48 }
49
bbcfe7e Uli Kusterer - More WIP creating finish_installation that waits
uliwitness authored
50
51 -(void) dealloc
52 {
53 [selfPath release];
54 selfPath = nil;
343d686 Uli Kusterer - finish_installation is now a real bundled app, so it can be localized.
uliwitness authored
55 [watchdogTimer release];
56 watchdogTimer = nil;
bbcfe7e Uli Kusterer - More WIP creating finish_installation that waits
uliwitness authored
57
58 [super dealloc];
59 }
60
61
343d686 Uli Kusterer - finish_installation is now a real bundled app, so it can be localized.
uliwitness authored
62 -(void) parentHasQuit
63 {
64 [watchdogTimer invalidate];
65
66 if( folderPath )
67 [self install];
68 else
69 [self relaunch];
70 }
71
72
4b74af2 Andy Matuschak Fixes 240385
andymatuschak authored
73 - (void)watchdog:(NSTimer *)timer
b2eab97 Made the relaunching process much snazzier, courtesy of Cedric Luthi. No...
andym authored
74 {
4b74af2 Andy Matuschak Fixes 240385
andymatuschak authored
75 ProcessSerialNumber psn;
76 if (GetProcessForPID(parentProcessId, &psn) == procNotFound)
343d686 Uli Kusterer - finish_installation is now a real bundled app, so it can be localized.
uliwitness authored
77 [self parentHasQuit];
b2eab97 Made the relaunching process much snazzier, courtesy of Cedric Luthi. No...
andym authored
78 }
79
80 - (void) relaunch
81 {
eac4134 Andy Matuschak Replaced UTF8String with fileSystemRepresentation and [NSString initWith...
andymatuschak authored
82 [[NSWorkspace sharedWorkspace] openFile:[[NSFileManager defaultManager] stringWithFileSystemRepresentation:executablePath length:strlen(executablePath)]];
4fad530 Change availability checks so that they build on 10.4
Stuart Morgan authored
83 #if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
43a0a7d Uli Kusterer Merge of changes from SVN repository:
uliwitness authored
84 [[NSFileManager defaultManager] removeFileAtPath: [SUInstaller updateFolder] handler: nil];
bbcfe7e Uli Kusterer - More WIP creating finish_installation that waits
uliwitness authored
85 [[NSFileManager defaultManager] removeFileAtPath: selfPath handler: nil];
54299d7 added #ifdef's for Tiger support
August Joki authored
86 #else
43a0a7d Uli Kusterer Merge of changes from SVN repository:
uliwitness authored
87 [[NSFileManager defaultManager] removeItemAtPath: [SUInstaller updateFolder] error: NULL];
bbcfe7e Uli Kusterer - More WIP creating finish_installation that waits
uliwitness authored
88 [[NSFileManager defaultManager] removeItemAtPath: selfPath error: NULL];
54299d7 added #ifdef's for Tiger support
August Joki authored
89 #endif
bbcfe7e Uli Kusterer - More WIP creating finish_installation that waits
uliwitness authored
90 exit(EXIT_SUCCESS);
91 }
92
93
94 -(void) install
95 {
43a0a7d Uli Kusterer Merge of changes from SVN repository:
uliwitness authored
96 NSBundle *theBundle = [NSBundle bundleWithPath: [NSString stringWithUTF8String: executablePath]];
97 SUHost *theHost = [[[SUHost alloc] initWithBundle: theBundle] autorelease];
98
343d686 Uli Kusterer - finish_installation is now a real bundled app, so it can be localized.
uliwitness authored
99 SUStatusController* statusCtl = [[SUStatusController alloc] initWithHost: theHost]; // We quit anyway after we've installed, so leak this for now.
100 [statusCtl setButtonTitle: SULocalizedString(@"Cancel Update",@"") target: nil action: Nil isDefault: NO];
101 [statusCtl beginActionWithTitle: SULocalizedString(@"Installing update...",@"")
102 maxProgressValue: 0 statusText: @""];
103 [statusCtl showWindow: self];
bbcfe7e Uli Kusterer - More WIP creating finish_installation that waits
uliwitness authored
104
105 [SUInstaller installFromUpdateFolder: [NSString stringWithUTF8String: folderPath]
106 overHost: theHost
343d686 Uli Kusterer - finish_installation is now a real bundled app, so it can be localized.
uliwitness authored
107 delegate: self synchronously: NO
bbcfe7e Uli Kusterer - More WIP creating finish_installation that waits
uliwitness authored
108 versionComparator: [SUStandardVersionComparator defaultComparator]];
109 }
110
111 - (void)installerFinishedForHost:(SUHost *)aHost
112 {
113 [self relaunch];
114 }
115
116 - (void)installerForHost:(SUHost *)host failedWithError:(NSError *)error
117 {
118 NSRunAlertPanel( @"", @"%@", @"OK", @"", @"", error );
119 exit(EXIT_FAILURE);
b2eab97 Made the relaunching process much snazzier, courtesy of Cedric Luthi. No...
andym authored
120 }
121
122 @end
123
124 int main (int argc, const char * argv[])
125 {
343d686 Uli Kusterer - finish_installation is now a real bundled app, so it can be localized.
uliwitness authored
126 if( argc < 3 || argc > 4 )
127 return EXIT_FAILURE;
128
129 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
bbcfe7e Uli Kusterer - More WIP creating finish_installation that waits
uliwitness authored
130
343d686 Uli Kusterer - finish_installation is now a real bundled app, so it can be localized.
uliwitness authored
131 ProcessSerialNumber psn = { 0, kCurrentProcess };
132 TransformProcessType( &psn, kProcessTransformToForegroundApplication );
133 [[NSApplication sharedApplication] activateIgnoringOtherApps: YES];
134
135 #if 0 // Cmdline tool
bbcfe7e Uli Kusterer - More WIP creating finish_installation that waits
uliwitness authored
136 NSString* selfPath = nil;
137 if( argv[0][0] == '/' )
138 selfPath = [NSString stringWithUTF8String: argv[0]];
139 else
140 {
141 selfPath = [[NSFileManager defaultManager] currentDirectoryPath];
142 selfPath = [selfPath stringByAppendingPathComponent: [NSString stringWithUTF8String: argv[0]]];
143 }
343d686 Uli Kusterer - finish_installation is now a real bundled app, so it can be localized.
uliwitness authored
144 #else
145 NSString* selfPath = [[NSBundle mainBundle] bundlePath];
146 #endif
b2eab97 Made the relaunching process much snazzier, courtesy of Cedric Luthi. No...
andym authored
147
254cf85 add [NSApplication sharedApplication] to be sure relaucher stay alive an...
catlan authored
148 [NSApplication sharedApplication];
343d686 Uli Kusterer - finish_installation is now a real bundled app, so it can be localized.
uliwitness authored
149 [[[TerminationListener alloc] initWithExecutablePath: (argc > 1) ? argv[1] : NULL
150 parentProcessId: (argc > 2) ? atoi(argv[2]) : 0
151 folderPath: (argc > 3) ? argv[3] : NULL
152 selfPath: selfPath] autorelease];
690f04e Fixed the relaunch tool to have Leoaprd compatibility (thanks, Cedric Lu...
andym authored
153 [[NSApplication sharedApplication] run];
b2eab97 Made the relaunching process much snazzier, courtesy of Cedric Luthi. No...
andym authored
154
d4291d6 Andy Matuschak Fixes 239512
andymatuschak authored
155 [pool drain];
b2eab97 Made the relaunching process much snazzier, courtesy of Cedric Luthi. No...
andym authored
156
157 return EXIT_SUCCESS;
87f2893 Fixed warnings for missing newlines at the end of the file.
andym authored
158 }
Something went wrong with that request. Please try again.