mirror of
https://github.com/ksherlock/ample.git
synced 2025-01-24 06:29:47 +00:00
untar mame-data.tgz to the application support directory.
This just uses NSTask to launch tar in the background.
This commit is contained in:
parent
cfe0e950c4
commit
8264aa1515
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@ dist
|
||||
embedded/mame64
|
||||
embedded/SDL2.framework
|
||||
build
|
||||
embedded/mame-data.tgz
|
||||
|
@ -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 = "<group>"; };
|
||||
B63C1B8924FF4B7100511A71 /* Ample.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Ample.h; sourceTree = "<group>"; };
|
||||
B63C1B8A24FF4BF700511A71 /* Ample.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Ample.m; sourceTree = "<group>"; };
|
||||
B63C1B8D25004C6D00511A71 /* mame-data.tgz */ = {isa = PBXFileReference; lastKnownFileType = file; name = "mame-data.tgz"; path = "embedded/mame-data.tgz"; sourceTree = "<group>"; };
|
||||
B64979C024EF6703008ABD20 /* MediaViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MediaViewController.h; sourceTree = "<group>"; };
|
||||
B64979C124EF6703008ABD20 /* MediaViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MediaViewController.m; sourceTree = "<group>"; };
|
||||
B64E15A724EA1D5300E8AD3D /* MachineViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MachineViewController.h; sourceTree = "<group>"; };
|
||||
@ -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 */,
|
||||
|
@ -17,5 +17,6 @@ NSURL *SupportDirectory(void);
|
||||
extern NSString *kUseCustomMame;
|
||||
extern NSString *kMamePath;
|
||||
extern NSString *kAutoCloseLogWindow;
|
||||
extern NSString *kMameComponentsDate;
|
||||
|
||||
#endif /* Ample_h */
|
||||
|
@ -27,3 +27,4 @@ NSURL *SupportDirectory(void) {
|
||||
NSString *kUseCustomMame = @"UseCustomMame";
|
||||
NSString *kMamePath = @"MamePath";
|
||||
NSString *kAutoCloseLogWindow = @"AutoCloseLogWindow";
|
||||
NSString *kMameComponentsDate = @"MameComponentsDate";
|
||||
|
@ -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
|
||||
|
@ -3,6 +3,7 @@
|
||||
<dependencies>
|
||||
<deployment identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="15705"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
|
||||
@ -12,7 +13,11 @@
|
||||
</customObject>
|
||||
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
|
||||
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
|
||||
<customObject id="Voe-Tx-rLC" customClass="AppDelegate"/>
|
||||
<customObject id="Voe-Tx-rLC" customClass="AppDelegate">
|
||||
<connections>
|
||||
<outlet property="installWindow" destination="jWX-pY-Zpb" id="xAj-Vj-Vxn"/>
|
||||
</connections>
|
||||
</customObject>
|
||||
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>
|
||||
<menu title="Main Menu" systemMenu="main" id="AYu-sK-qS6">
|
||||
<items>
|
||||
@ -680,5 +685,25 @@
|
||||
</items>
|
||||
<point key="canvasLocation" x="132" y="154"/>
|
||||
</menu>
|
||||
<window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" restorable="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" frameAutosaveName="" animationBehavior="default" id="jWX-pY-Zpb">
|
||||
<rect key="contentRect" x="283" y="305" width="226" height="56"/>
|
||||
<rect key="screenRect" x="0.0" y="0.0" width="2560" height="1417"/>
|
||||
<view key="contentView" id="L7W-DF-UXe">
|
||||
<rect key="frame" x="0.0" y="0.0" width="226" height="56"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="iC1-A6-a6T">
|
||||
<rect key="frame" x="18" y="20" width="190" height="16"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<textFieldCell key="cell" lineBreakMode="clipping" title="Installing MAME components…" id="ura-rh-zmZ">
|
||||
<font key="font" usesAppearanceFont="YES"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
</subviews>
|
||||
</view>
|
||||
<point key="canvasLocation" x="13" y="-182"/>
|
||||
</window>
|
||||
</objects>
|
||||
</document>
|
||||
|
@ -2,6 +2,8 @@
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>MameComponentsDate</key>
|
||||
<date>2020-09-02T16:00:00Z</date>
|
||||
<key>UseCustomMame</key>
|
||||
<false/>
|
||||
<key>AutoCloseLogWindow</key>
|
||||
|
Loading…
x
Reference in New Issue
Block a user