@@ -93,6 +93,25 @@ -(int)totalJobs;
93
93
94
94
@implementation Controller
95
95
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
+
96
115
-(NSProgressIndicator *)progressBar
97
116
{
98
117
return progressBar;
@@ -117,7 +136,7 @@ -(NSString*)installDirectory
117
136
-(void )bailWithMessage : (NSString *)errorString ;
118
137
{
119
138
NSLog (@" Bailing with error: %@ " , errorString);
120
- NSRunCriticalAlertPanel (nil , errorString, @" Cancel" , nil , nil );
139
+ NSRunCriticalAlertPanel (@" Error " , errorString, @" Cancel" , nil , nil );
121
140
exit (1 );
122
141
}
123
142
@@ -288,6 +307,7 @@ -(void)install:(Job*)job
288
307
289
308
-(void )downloadAndInstall : (Controller*)controller
290
309
{
310
+ printf (" downloading jobs: %i\n " , [jobs count ]);
291
311
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc ] init ];
292
312
293
313
// Download only those jobs which actually need to be downloaded
@@ -326,26 +346,14 @@ -(void)downloadAndInstall:(Controller*)controller
326
346
[NSApp terminate: self ];
327
347
}
328
348
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
-
336
349
-(void )finishInstallation
337
350
{
338
351
// 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 ];
349
357
}
350
358
351
359
-(void )downloadJob : (Job*)job atIndex : (int )index
@@ -386,27 +394,6 @@ -(void)downloadJob:(Job*)job atIndex:(int)index
386
394
}
387
395
}
388
396
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
-
410
397
-(void )createInstallerMenu : (NSString *)applicationName
411
398
{
412
399
NSString * menuAppName = [NSString stringWithFormat: @" %@ Installer" , applicationName];
@@ -525,87 +512,6 @@ -(void)createInstallerMenu: (NSString*)applicationName
525
512
-(void )awakeFromNib
526
513
{
527
514
[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
- }
609
515
}
610
516
611
517
-(void )showIntroDialog : (SharedApplication)app
@@ -683,7 +589,11 @@ -(void)showIntroDialog:(SharedApplication)app
683
589
[introWindow setShowsResizeIndicator: NO ];
684
590
[introWindow setFrame: frame display: YES ];
685
591
}
686
- [NSApp arrangeInFront: introWindow];
592
+
593
+ // Hide the progress Window.
594
+ [progressWindow orderOut: self ];
595
+ [introWindow center ];
596
+ [introWindow makeKeyAndOrderFront: self ];
687
597
}
688
598
689
599
- (BOOL )canBecomeKeyWindow
@@ -698,11 +608,92 @@ - (BOOL)canBecomeMainWindow
698
608
699
609
-(void )applicationDidFinishLaunching : (NSNotification *) notif
700
610
{
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++)
702
619
{
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];
706
697
}
707
698
}
708
699
@@ -721,11 +712,12 @@ -(IBAction)cancelIntro:(id)sender
721
712
722
713
-(IBAction )continueIntro : (id )sender ;
723
714
{
724
- if (!quiet )
715
+ if (!skipIntroDialog )
725
716
[introWindow orderOut: self ];
726
717
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.
729
721
[progressText setStringValue: @" Connecting to download site..." ];
730
722
[progressBar setUsesThreadedAnimation: NO ];
731
723
[progressBar setIndeterminate: NO ];
@@ -740,7 +732,9 @@ -(IBAction)continueIntro:(id)sender;
740
732
[NSApp activateIgnoringOtherApps: YES ];
741
733
}
742
734
743
- [NSThread detachNewThreadSelector: @selector (downloadAndInstall: ) toTarget: self withObject: self ];
735
+ [NSThread detachNewThreadSelector: @selector (downloadAndInstall: )
736
+ toTarget: self
737
+ withObject: self ];
744
738
}
745
739
746
740
@end
0 commit comments