Incomplete - started adding support for "Reinstall MAME components" menu item.

The main holdup is that the software list is loaded from those installed MAME components and reinstalling them would invalidate and require a reload.
This commit is contained in:
Kelvin Sherlock 2022-04-30 10:17:57 -04:00
parent 23a05d5414
commit 4a0caa2e78
4 changed files with 81 additions and 4 deletions

View File

@ -115,11 +115,11 @@
dispatch_time_t when = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC));
[task setTerminationHandler: ^(NSTask *task){
int st = [task terminationStatus];
// delay so the install window is visible, I think
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"];
@ -238,4 +238,70 @@
}
-(IBAction)installMameComponents:(id)sender {
/* 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;
NSString *path = [bundle pathForResource: @"mame-data" ofType: @"tgz"];
if (!path) return; // Ample Lite?
NSWindow *win = _installWindow;
[win makeKeyAndOrderFront: nil];
NSTask *task = [NSTask new];
NSArray *argv = @[
@"xfz",
path
];
if (@available(macOS 10.13, *)) {
[task setExecutableURL: [NSURL fileURLWithPath: @"/usr/bin/tar"]];
[task setCurrentDirectoryURL: sd];
} else {
[task setLaunchPath: @"/usr/bin/tar"];
[task setCurrentDirectoryPath: SupportDirectoryPath()];
}
[task setArguments: argv];
//dispatch_time_t when = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC));
[task setTerminationHandler: ^(NSTask *task){
int st = [task terminationStatus];
dispatch_async(dispatch_get_main_queue(), ^{
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];
// need to reload the software list data.
});
}];
[task launch];
}
@end

View File

@ -45,6 +45,9 @@
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="VOq-y0-SEH"/>
<menuItem title="Reinstall MAME components" hidden="YES" id="c3P-WT-eUP">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem title="Preferences…" keyEquivalent="," id="BOF-NM-1cW">
<connections>
<action selector="displayPreferences:" target="Voe-Tx-rLC" id="Hsm-pX-sUc"/>

View File

@ -39,6 +39,8 @@
@interface SoftwareSet : NSObject <NSFastEnumeration, AutoCompleteDelegate>
+(instancetype)softwareSetForMachine: (NSString *)machine;
+(void)invalidate;
-(BOOL)nameIsUnique: (NSString *)name;
-(NSString *)nameForSoftware: (Software *)software;

View File

@ -512,9 +512,15 @@ NSArray<SoftwareList *> *SoftwareListForMachine(NSString *machine) {
}
static NSCache *cache;
+(void)invalidate {
// called after mame components are updated. clears the cache.
cache = nil;
}
+(instancetype)softwareSetForMachine:(NSString *)machine {
static NSCache *cache;
if (!cache)
cache = [NSCache new];