diff --git a/.gitignore b/.gitignore index 6401c32..46fcb47 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ dist embedded/mame64 embedded/SDL2.framework build +embedded/mame-data.tgz diff --git a/Ample.xcodeproj/project.pbxproj b/Ample.xcodeproj/project.pbxproj index 3e1983f..2fc4096 100644 --- a/Ample.xcodeproj/project.pbxproj +++ b/Ample.xcodeproj/project.pbxproj @@ -59,6 +59,7 @@ B6109A4324F5F377005CB652 /* agat7.plist in Resources */ = {isa = PBXBuildFile; fileRef = B6109A1624F5F376005CB652 /* agat7.plist */; }; B63C1B8B24FF4BF700511A71 /* Ample.m in Sources */ = {isa = PBXBuildFile; fileRef = B63C1B8A24FF4BF700511A71 /* Ample.m */; }; B63C1B8C24FF4BF700511A71 /* Ample.m in Sources */ = {isa = PBXBuildFile; fileRef = B63C1B8A24FF4BF700511A71 /* Ample.m */; }; + B63C1B8E25004C6D00511A71 /* mame-data.tgz in Resources */ = {isa = PBXBuildFile; fileRef = B63C1B8D25004C6D00511A71 /* mame-data.tgz */; }; B64979C224EF6703008ABD20 /* MediaViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B64979C124EF6703008ABD20 /* MediaViewController.m */; }; B64E15A924EA1D5300E8AD3D /* MachineViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B64E15A824EA1D5300E8AD3D /* MachineViewController.m */; }; B65593B124ECB61800722E0C /* SlotViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B65593B024ECB61800722E0C /* SlotViewController.m */; }; @@ -229,6 +230,7 @@ B6109A1624F5F376005CB652 /* agat7.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = agat7.plist; sourceTree = ""; }; B63C1B8924FF4B7100511A71 /* Ample.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Ample.h; sourceTree = ""; }; B63C1B8A24FF4BF700511A71 /* Ample.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Ample.m; sourceTree = ""; }; + B63C1B8D25004C6D00511A71 /* mame-data.tgz */ = {isa = PBXFileReference; lastKnownFileType = file; name = "mame-data.tgz"; path = "embedded/mame-data.tgz"; sourceTree = ""; }; B64979C024EF6703008ABD20 /* MediaViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MediaViewController.h; sourceTree = ""; }; B64979C124EF6703008ABD20 /* MediaViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MediaViewController.m; sourceTree = ""; }; B64E15A724EA1D5300E8AD3D /* MachineViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MachineViewController.h; sourceTree = ""; }; @@ -348,6 +350,7 @@ B66236BD24FDA7EA006CABD7 /* Embedded Content */ = { isa = PBXGroup; children = ( + B63C1B8D25004C6D00511A71 /* mame-data.tgz */, B66236B824FDA698006CABD7 /* mame64 */, B66236B224FDA522006CABD7 /* SDL2.framework */, ); @@ -535,6 +538,7 @@ B6109A3224F5F377005CB652 /* basis108.plist in Resources */, B6109A4324F5F377005CB652 /* agat7.plist in Resources */, B6109A2B24F5F377005CB652 /* elppa.plist in Resources */, + B63C1B8E25004C6D00511A71 /* mame-data.tgz in Resources */, B6109A3B24F5F377005CB652 /* apple2gsr1.plist in Resources */, B6D6DE3B24FACF4F00661A5F /* Defaults.plist in Resources */, B6109A2224F5F377005CB652 /* models.plist in Resources */, diff --git a/Ample/Ample.h b/Ample/Ample.h index d091a4c..2c62288 100644 --- a/Ample/Ample.h +++ b/Ample/Ample.h @@ -17,5 +17,6 @@ NSURL *SupportDirectory(void); extern NSString *kUseCustomMame; extern NSString *kMamePath; extern NSString *kAutoCloseLogWindow; +extern NSString *kMameComponentsDate; #endif /* Ample_h */ diff --git a/Ample/Ample.m b/Ample/Ample.m index 4c75000..db766b0 100644 --- a/Ample/Ample.m +++ b/Ample/Ample.m @@ -27,3 +27,4 @@ NSURL *SupportDirectory(void) { NSString *kUseCustomMame = @"UseCustomMame"; NSString *kMamePath = @"MamePath"; NSString *kAutoCloseLogWindow = @"AutoCloseLogWindow"; +NSString *kMameComponentsDate = @"MameComponentsDate"; diff --git a/Ample/AppDelegate.m b/Ample/AppDelegate.m index adb7586..265f239 100644 --- a/Ample/AppDelegate.m +++ b/Ample/AppDelegate.m @@ -5,12 +5,13 @@ // Created by Kelvin Sherlock on 8/16/2020. // Copyright © 2020 Kelvin Sherlock. All rights reserved. // - +#import "Ample.h" #import "AppDelegate.h" #import "LaunchWindowController.h" #import "PreferencesWindowController.h" @interface AppDelegate () +@property (weak) IBOutlet NSWindow *installWindow; @end @@ -36,10 +37,87 @@ [[NSUserDefaults standardUserDefaults] registerDefaults: dict]; } - _launcher = [LaunchWindowController new]; + + + if ([self installMameComponents]) { + [self displayLaunchWindow]; + } + +} + +-(void)displayLaunchWindow { + + if (!_launcher) { + _launcher = [LaunchWindowController new]; + } [_launcher showWindow: nil]; } +-(BOOL)installMameComponents { + + /* install the mame data components. */ + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + NSBundle *bundle = [NSBundle mainBundle]; + NSURL *sd = SupportDirectory(); + + NSURL *ample_url = [sd URLByAppendingPathComponent: @"Ample.plist"]; + NSMutableDictionary *d = [NSMutableDictionary dictionaryWithContentsOfURL: ample_url]; + + NSDate *oldDate = [d objectForKey: kMameComponentsDate]; + NSDate *newDate = [defaults objectForKey: kMameComponentsDate]; + if (![newDate isKindOfClass: [NSDate class]]) + newDate = nil; + + if (!newDate) return YES; //???? + if (oldDate && [oldDate compare: newDate] >= 0) return YES; + + NSString *path = [bundle pathForResource: @"mame-data" ofType: @"tgz"]; + if (!path) return YES; // Ample Lite? + + + NSWindow *win = _installWindow; + [win makeKeyAndOrderFront: nil]; + NSTask *task = [NSTask new]; + NSArray *argv = @[ + @"xfz", + path + ]; + [task setExecutableURL: [NSURL fileURLWithPath: @"/usr/bin/tar"]]; + [task setArguments: argv]; + [task setCurrentDirectoryURL: sd]; + + + dispatch_time_t when = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)); + [task setTerminationHandler: ^(NSTask *task){ + + dispatch_after(when, dispatch_get_main_queue(), ^{ + + int st = [task terminationStatus]; + + if (st) { + NSAlert *alert = [NSAlert new]; + [alert setMessageText: @"An error occurred extracting MAME components"]; + [alert runModal]; + [win close]; + return; + } + + if (d) { + [d setObject: newDate forKey: kMameComponentsDate]; + [d writeToURL: ample_url atomically: YES]; + } else { + [@{ kMameComponentsDate: newDate } writeToURL: ample_url atomically: YES]; + } + [win close]; + [self displayLaunchWindow]; + }); + + }]; + [task launch]; + + return NO; +} + - (void)applicationWillTerminate:(NSNotification *)aNotification { // Insert code here to tear down your application diff --git a/Ample/Base.lproj/MainMenu.xib b/Ample/Base.lproj/MainMenu.xib index cd873bf..df0dea5 100644 --- a/Ample/Base.lproj/MainMenu.xib +++ b/Ample/Base.lproj/MainMenu.xib @@ -3,6 +3,7 @@ + @@ -12,7 +13,11 @@ - + + + + + @@ -680,5 +685,25 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/Ample/Defaults.plist b/Ample/Defaults.plist index 472d948..3a4e96d 100644 --- a/Ample/Defaults.plist +++ b/Ample/Defaults.plist @@ -2,6 +2,8 @@ + MameComponentsDate + 2020-09-02T16:00:00Z UseCustomMame AutoCloseLogWindow