Skip to content

Commit 8c7a7a7

Browse files
author
Martin Robinson
committed
Fixes for recent OS X installer changes.
Show the progress dialog even if this is a application update. [#289]
1 parent 4421681 commit 8c7a7a7

File tree

3 files changed

+126
-133
lines changed

3 files changed

+126
-133
lines changed

installation/net_installer/osx/Controller.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ SharedApplication app;
5454
NSString *temporaryDirectory;
5555
NSString *installDirectory;
5656
NSString *updateFile;
57-
BOOL quiet;
57+
BOOL skipIntroDialog;
5858
}
5959

6060
-(IBAction)cancelProgress:(id)sender;

installation/net_installer/osx/Controller.mm

Lines changed: 123 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,25 @@ -(int)totalJobs;
9393

9494
@implementation Controller
9595

96+
-(void)dealloc
97+
{
98+
[jobs release];
99+
[installDirectory release];
100+
101+
if (temporaryDirectory)
102+
{
103+
[[NSFileManager defaultManager]
104+
removeFileAtPath:temporaryDirectory handler:nil];
105+
[temporaryDirectory release];
106+
}
107+
108+
if (updateFile)
109+
[updateFile release];
110+
111+
[super dealloc];
112+
}
113+
114+
96115
-(NSProgressIndicator*)progressBar
97116
{
98117
return progressBar;
@@ -117,7 +136,7 @@ -(NSString*)installDirectory
117136
-(void)bailWithMessage:(NSString*)errorString;
118137
{
119138
NSLog(@"Bailing with error: %@", errorString);
120-
NSRunCriticalAlertPanel(nil, errorString, @"Cancel", nil, nil);
139+
NSRunCriticalAlertPanel(@"Error", errorString, @"Cancel", nil, nil);
121140
exit(1);
122141
}
123142

@@ -288,6 +307,7 @@ -(void)install:(Job*)job
288307

289308
-(void)downloadAndInstall:(Controller*)controller
290309
{
310+
printf("downloading jobs: %i\n", [jobs count]);
291311
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
292312

293313
// Download only those jobs which actually need to be downloaded
@@ -326,26 +346,14 @@ -(void)downloadAndInstall:(Controller*)controller
326346
[NSApp terminate:self];
327347
}
328348

329-
- (BOOL)isVolumeReadOnly
330-
{
331-
struct statfs statfs_info;
332-
statfs([[[NSBundle mainBundle] bundlePath] fileSystemRepresentation], &statfs_info);
333-
return (statfs_info.f_flags & MNT_RDONLY);
334-
}
335-
336349
-(void)finishInstallation
337350
{
338351
// Write the .installed file
339-
NSFileManager *fm = [NSFileManager defaultManager];
340-
NSString* ifile = [NSString stringWithUTF8String:app->GetDataPath().c_str()];
341-
ifile = [ifile stringByAppendingPathComponent:@".installed"];
342-
[fm createFileAtPath:ifile contents:[NSData data] attributes:nil];
343-
344-
// Remove the update file if it exists
345-
if (updateFile != nil)
346-
{
347-
[fm removeFileAtPath:updateFile handler:nil];
348-
}
352+
std::string filePath(FileUtils::Join(app->GetDataPath().c_str(), ".installed", 0));
353+
[[NSFileManager defaultManager]
354+
createFileAtPath:[NSString stringWithUTF8String:filePath.c_str()]
355+
contents:[NSData data]
356+
attributes:nil];
349357
}
350358

351359
-(void)downloadJob:(Job*)job atIndex:(int)index
@@ -386,27 +394,6 @@ -(void)downloadJob:(Job*)job atIndex:(int)index
386394
}
387395
}
388396

389-
-(void)dealloc
390-
{
391-
392-
[jobs release];
393-
[installDirectory release];
394-
395-
if (temporaryDirectory != nil)
396-
{
397-
NSFileManager *fm = [NSFileManager defaultManager];
398-
[fm removeFileAtPath:temporaryDirectory handler:nil];
399-
[temporaryDirectory release];
400-
}
401-
402-
if (updateFile != nil)
403-
{
404-
[updateFile release];
405-
}
406-
407-
[super dealloc];
408-
}
409-
410397
-(void)createInstallerMenu: (NSString*)applicationName
411398
{
412399
NSString* menuAppName = [NSString stringWithFormat:@"%@ Installer", applicationName];
@@ -525,87 +512,6 @@ -(void)createInstallerMenu: (NSString*)applicationName
525512
-(void)awakeFromNib
526513
{
527514
[NSApp setDelegate:self];
528-
529-
quiet = NO;;
530-
updateFile = nil;
531-
NSString *appPath = nil;
532-
jobs = [[NSMutableArray alloc] init];
533-
534-
NSArray* args = [[NSProcessInfo processInfo] arguments];
535-
int count = [args count];
536-
for (int i = 1; i < count; i++)
537-
{
538-
NSString* arg = [args objectAtIndex:i];
539-
if ([arg isEqual:@"-appPath"] && count > i+1)
540-
{
541-
appPath = [args objectAtIndex:i+1];
542-
i++;
543-
}
544-
else if ([arg isEqual:@"-updateFile"] && count > i+1)
545-
{
546-
updateFile = [args objectAtIndex:i+1];
547-
[updateFile retain];
548-
i++;
549-
}
550-
else if ([arg isEqual:@"-quiet"])
551-
{
552-
quiet = YES;
553-
}
554-
else
555-
{
556-
[jobs addObject:[[Job alloc] init:arg]];
557-
}
558-
}
559-
560-
if (appPath == nil)
561-
{
562-
[self bailWithMessage:@"Sorry, but the installer was not given enough information to continue."];
563-
}
564-
565-
if (updateFile == nil)
566-
{
567-
app = Application::NewApplication([appPath UTF8String]);
568-
}
569-
else
570-
{
571-
app = Application::NewApplication([updateFile UTF8String], [appPath UTF8String]);
572-
NSString* updateURL = [NSString stringWithUTF8String:app->GetUpdateURL().c_str()];
573-
[jobs addObject:[[Job alloc] initUpdate:updateURL]];
574-
}
575-
576-
std::string tempDir = FileUtils::GetTempDirectory();
577-
temporaryDirectory = [NSString stringWithUTF8String:tempDir.c_str()];
578-
[self createDirectory: temporaryDirectory];
579-
[temporaryDirectory retain];
580-
581-
// Check to see if we can write to the system install location -- if so install there
582-
std::string systemRuntimeHome = FileUtils::GetSystemRuntimeHomeDirectory();
583-
std::string userRuntimeHome = FileUtils::GetUserRuntimeHomeDirectory();
584-
585-
installDirectory = [NSString stringWithUTF8String:systemRuntimeHome.c_str()];
586-
if ((!FileUtils::IsDirectory(systemRuntimeHome) &&
587-
[[NSFileManager defaultManager] isWritableFileAtPath:[installDirectory stringByDeletingLastPathComponent]]) ||
588-
[[NSFileManager defaultManager] isWritableFileAtPath:installDirectory])
589-
{
590-
installDirectory = [NSString stringWithUTF8String:systemRuntimeHome.c_str()];
591-
}
592-
else
593-
{
594-
// Cannot write to system-wide install location -- install to user directory
595-
installDirectory = [NSString stringWithUTF8String:userRuntimeHome.c_str()];
596-
}
597-
[installDirectory retain];
598-
599-
600-
if (quiet)
601-
{
602-
[self continueIntro:self];
603-
return;
604-
}
605-
else
606-
{
607-
[self showIntroDialog:app];
608-
}
609515
}
610516

611517
-(void)showIntroDialog:(SharedApplication)app
@@ -683,7 +589,11 @@ -(void)showIntroDialog:(SharedApplication)app
683589
[introWindow setShowsResizeIndicator:NO];
684590
[introWindow setFrame:frame display:YES];
685591
}
686-
[NSApp arrangeInFront:introWindow];
592+
593+
// Hide the progress Window.
594+
[progressWindow orderOut:self];
595+
[introWindow center];
596+
[introWindow makeKeyAndOrderFront:self];
687597
}
688598

689599
- (BOOL)canBecomeKeyWindow
@@ -698,11 +608,92 @@ - (BOOL)canBecomeMainWindow
698608

699609
-(void)applicationDidFinishLaunching:(NSNotification *) notif
700610
{
701-
if (updateFile == nil && quiet == NO)
611+
jobs = [[NSMutableArray alloc] init];
612+
skipIntroDialog = NO;;
613+
updateFile = nil;
614+
NSString *appPath = nil;
615+
616+
NSArray* args = [[NSProcessInfo processInfo] arguments];
617+
int count = [args count];
618+
for (int i = 1; i < count; i++)
702619
{
703-
[introWindow center];
704-
[progressWindow orderOut:self];
705-
[introWindow makeKeyAndOrderFront:self];
620+
NSString* arg = [args objectAtIndex:i];
621+
if ([arg isEqual:@"-appPath"] && count > i+1)
622+
{
623+
appPath = [args objectAtIndex:i+1];
624+
i++;
625+
}
626+
else if ([arg isEqual:@"-updateFile"] && count > i+1)
627+
{
628+
updateFile = [args objectAtIndex:i+1];
629+
[updateFile retain];
630+
i++;
631+
}
632+
else if ([arg isEqual:@"-quiet"])
633+
{
634+
skipIntroDialog = YES;
635+
}
636+
else
637+
{
638+
[jobs addObject:[[Job alloc] init:arg]];
639+
}
640+
}
641+
642+
if (!appPath)
643+
[self bailWithMessage:@"Sorry, but the installer was not given the application path."];
644+
645+
if (!updateFile)
646+
{
647+
app = Application::NewApplication([appPath UTF8String]);
648+
}
649+
else
650+
{
651+
if (!FileUtils::IsFile([updateFile UTF8String]))
652+
[self bailWithMessage:@"Could not find specified update file."];
653+
654+
skipIntroDialog = YES;
655+
app = Application::NewApplication([updateFile UTF8String], [appPath UTF8String]);
656+
[jobs addObject:[[Job alloc]
657+
initUpdate:[NSString stringWithUTF8String:app->GetUpdateURL().c_str()]]];
658+
659+
// Remove the update file as soon as possible, so that if the installation
660+
// fails the application will still start. We can always fetch the update
661+
// later.
662+
[[NSFileManager defaultManager] removeFileAtPath:updateFile handler:nil];
663+
}
664+
665+
std::string tempDir = FileUtils::GetTempDirectory();
666+
temporaryDirectory = [NSString stringWithUTF8String:tempDir.c_str()];
667+
[self createDirectory: temporaryDirectory];
668+
[temporaryDirectory retain];
669+
670+
// Check to see if we can write to the system install location -- if so install there
671+
std::string systemRuntimeHome = FileUtils::GetSystemRuntimeHomeDirectory();
672+
std::string userRuntimeHome = FileUtils::GetUserRuntimeHomeDirectory();
673+
674+
installDirectory = [NSString stringWithUTF8String:systemRuntimeHome.c_str()];
675+
if ((!FileUtils::IsDirectory(systemRuntimeHome) &&
676+
[[NSFileManager defaultManager] isWritableFileAtPath:[installDirectory stringByDeletingLastPathComponent]]) ||
677+
[[NSFileManager defaultManager] isWritableFileAtPath:installDirectory])
678+
{
679+
installDirectory = [NSString stringWithUTF8String:systemRuntimeHome.c_str()];
680+
}
681+
else
682+
{
683+
// Cannot write to system-wide install location -- install to user directory
684+
installDirectory = [NSString stringWithUTF8String:userRuntimeHome.c_str()];
685+
}
686+
[installDirectory retain];
687+
688+
689+
if (skipIntroDialog)
690+
{
691+
[self continueIntro:self];
692+
return;
693+
}
694+
else
695+
{
696+
[self showIntroDialog:app];
706697
}
707698
}
708699

@@ -721,11 +712,12 @@ -(IBAction)cancelIntro:(id)sender
721712

722713
-(IBAction)continueIntro:(id)sender;
723714
{
724-
if (!quiet)
715+
if (!skipIntroDialog)
725716
[introWindow orderOut:self];
726717

727-
// Always show the progress view, even if we are in quiet mode. Otherwise
728-
// the user won't know what is going on and won't be able to cancel.
718+
// Always show the progress view, even if we skip the intro dialog.
719+
// Otherwise the user won't know what is going on or be able to cancel
720+
// the download.
729721
[progressText setStringValue:@"Connecting to download site..."];
730722
[progressBar setUsesThreadedAnimation:NO];
731723
[progressBar setIndeterminate:NO];
@@ -740,7 +732,9 @@ -(IBAction)continueIntro:(id)sender;
740732
[NSApp activateIgnoringOtherApps:YES];
741733
}
742734

743-
[NSThread detachNewThreadSelector:@selector(downloadAndInstall:) toTarget:self withObject:self];
735+
[NSThread detachNewThreadSelector:@selector(downloadAndInstall:)
736+
toTarget:self
737+
withObject:self];
744738
}
745739

746740
@end

installation/net_installer/osx/SConscript

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ Env = build.env.Clone()
88
Env.Append(FRAMEWORKS=['Cocoa'])
99
sources = Glob('*.m') + Glob('*.mm')
1010

11-
# Turn off debugging for the installer to try to save space
12-
ccflags = Env['CCFLAGS']
13-
if '-g' in ccflags: ccflags.remove('-g')
11+
# Optimize the installer for size.
12+
ccflags = list(Env['CCFLAGS'])
1413
ccflags.append('-Oz')
1514
Env['CCFLAGS'] = ccflags
1615

0 commit comments

Comments
 (0)