2020-08-16 16:53:17 +00:00
|
|
|
//
|
|
|
|
// AppDelegate.m
|
2020-08-30 03:24:49 +00:00
|
|
|
// Ample
|
2020-08-16 16:53:17 +00:00
|
|
|
//
|
|
|
|
// Created by Kelvin Sherlock on 8/16/2020.
|
|
|
|
// Copyright © 2020 Kelvin Sherlock. All rights reserved.
|
|
|
|
//
|
2020-09-02 23:12:17 +00:00
|
|
|
#import "Ample.h"
|
2020-08-16 16:53:17 +00:00
|
|
|
#import "AppDelegate.h"
|
2020-08-29 19:42:06 +00:00
|
|
|
#import "LaunchWindowController.h"
|
2020-08-31 21:14:05 +00:00
|
|
|
#import "PreferencesWindowController.h"
|
2020-09-03 04:15:50 +00:00
|
|
|
#import "DownloadWindowController.h"
|
2020-09-14 02:48:55 +00:00
|
|
|
#import "DiskImagesWindowController.h"
|
2021-01-17 05:47:05 +00:00
|
|
|
#import "CheatSheetWindowController.h"
|
2022-02-24 01:56:21 +00:00
|
|
|
#import "BookmarkWindowController.h"
|
|
|
|
|
2020-09-14 02:48:55 +00:00
|
|
|
#import "Transformers.h"
|
2021-06-07 04:34:26 +00:00
|
|
|
#import "BookmarkManager.h"
|
2020-08-16 20:23:51 +00:00
|
|
|
|
2020-09-30 23:15:37 +00:00
|
|
|
#import "LogWindowController.h"
|
|
|
|
|
2020-08-16 16:53:17 +00:00
|
|
|
@interface AppDelegate ()
|
2020-09-02 23:12:17 +00:00
|
|
|
@property (weak) IBOutlet NSWindow *installWindow;
|
2020-08-16 16:53:17 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
2020-08-29 18:40:34 +00:00
|
|
|
@implementation AppDelegate {
|
|
|
|
NSWindowController *_prefs;
|
2020-08-29 19:42:06 +00:00
|
|
|
NSWindowController *_launcher;
|
2020-09-03 04:15:50 +00:00
|
|
|
NSWindowController *_downloader;
|
2020-09-14 02:48:55 +00:00
|
|
|
NSWindowController *_diskImages;
|
2021-01-17 05:47:05 +00:00
|
|
|
NSWindowController *_cheatSheet;
|
2022-02-24 01:56:21 +00:00
|
|
|
NSWindowController *_bookmarks;
|
|
|
|
|
2020-08-29 18:40:34 +00:00
|
|
|
}
|
2020-08-16 16:53:17 +00:00
|
|
|
|
2020-08-16 20:23:51 +00:00
|
|
|
|
2020-08-16 16:53:17 +00:00
|
|
|
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
|
|
|
|
// Insert code here to initialize your application
|
2020-08-16 20:23:51 +00:00
|
|
|
|
2020-08-29 18:40:34 +00:00
|
|
|
NSBundle *bundle = [NSBundle mainBundle];
|
|
|
|
NSString *path;
|
|
|
|
NSDictionary *dict;
|
|
|
|
|
|
|
|
|
2020-09-14 02:48:55 +00:00
|
|
|
RegisterTransformers();
|
|
|
|
|
2022-02-24 01:56:21 +00:00
|
|
|
//BookmarkManager *bm = [BookmarkManager sharedManager];
|
2021-06-07 04:34:26 +00:00
|
|
|
|
2020-08-29 18:40:34 +00:00
|
|
|
path = [bundle pathForResource: @"Defaults" ofType: @"plist"];
|
|
|
|
dict = [NSDictionary dictionaryWithContentsOfFile: path];
|
|
|
|
|
|
|
|
if (dict)
|
|
|
|
{
|
|
|
|
[[NSUserDefaults standardUserDefaults] registerDefaults: dict];
|
|
|
|
}
|
|
|
|
|
2020-09-26 00:46:25 +00:00
|
|
|
_diskImages = [DiskImagesWindowController sharedInstance]; //[DiskImagesWindowController new];
|
|
|
|
|
2020-09-02 23:12:17 +00:00
|
|
|
if ([self installMameComponents]) {
|
2020-09-26 00:46:25 +00:00
|
|
|
|
2020-09-02 23:12:17 +00:00
|
|
|
[self displayLaunchWindow];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-24 01:56:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2020-09-02 23:12:17 +00:00
|
|
|
-(void)displayLaunchWindow {
|
|
|
|
|
|
|
|
if (!_launcher) {
|
|
|
|
_launcher = [LaunchWindowController new];
|
|
|
|
}
|
2020-08-29 19:42:06 +00:00
|
|
|
[_launcher showWindow: nil];
|
2020-08-16 16:53:17 +00:00
|
|
|
}
|
|
|
|
|
2020-09-02 23:12:17 +00:00
|
|
|
-(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
|
|
|
|
];
|
2021-05-30 22:00:34 +00:00
|
|
|
if (@available(macOS 10.13, *)) {
|
|
|
|
[task setExecutableURL: [NSURL fileURLWithPath: @"/usr/bin/tar"]];
|
|
|
|
[task setCurrentDirectoryURL: sd];
|
|
|
|
} else {
|
|
|
|
[task setLaunchPath: @"/usr/bin/tar"];
|
|
|
|
[task setCurrentDirectoryPath: SupportDirectoryPath()];
|
|
|
|
}
|
2020-09-02 23:12:17 +00:00
|
|
|
[task setArguments: argv];
|
2021-05-30 22:00:34 +00:00
|
|
|
|
2020-09-02 23:12:17 +00:00
|
|
|
|
|
|
|
dispatch_time_t when = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC));
|
|
|
|
[task setTerminationHandler: ^(NSTask *task){
|
2022-04-30 14:17:57 +00:00
|
|
|
|
|
|
|
int st = [task terminationStatus];
|
|
|
|
// delay so the install window is visible, I think
|
2020-09-02 23:12:17 +00:00
|
|
|
dispatch_after(when, 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];
|
|
|
|
[self displayLaunchWindow];
|
2020-09-26 00:46:25 +00:00
|
|
|
[self displayROMS: nil];
|
2020-09-02 23:12:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
}];
|
|
|
|
[task launch];
|
|
|
|
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2020-08-16 16:53:17 +00:00
|
|
|
|
|
|
|
- (void)applicationWillTerminate:(NSNotification *)aNotification {
|
|
|
|
// Insert code here to tear down your application
|
2022-02-24 01:56:21 +00:00
|
|
|
|
2020-08-16 16:53:17 +00:00
|
|
|
}
|
|
|
|
|
2020-08-17 01:22:45 +00:00
|
|
|
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender {
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2020-08-16 16:53:17 +00:00
|
|
|
|
2020-09-30 23:15:37 +00:00
|
|
|
-(BOOL)application:(NSApplication *)sender openFile:(NSString *)filename {
|
|
|
|
|
|
|
|
NSString *ext = [[filename pathExtension] lowercaseString];
|
|
|
|
|
|
|
|
if ([ext isEqualToString: @"vgm"] || [ext isEqualToString: @"vgz"]) {
|
|
|
|
// run mame...
|
2020-10-01 03:06:44 +00:00
|
|
|
NSArray *args = @[ @"vgmplay", @"-window", @"-nomax", @"-skip_gameinfo", @"-quik", filename ];
|
2020-09-30 23:15:37 +00:00
|
|
|
|
|
|
|
[LogWindowController controllerForArgs: args];
|
|
|
|
}
|
|
|
|
return NO;
|
|
|
|
}
|
2020-08-16 20:23:51 +00:00
|
|
|
|
|
|
|
|
2020-08-26 03:22:08 +00:00
|
|
|
#pragma mark - IBActions
|
|
|
|
|
|
|
|
|
2020-08-29 18:40:34 +00:00
|
|
|
- (IBAction)displayPreferences:(id)sender {
|
|
|
|
if (!_prefs) {
|
2020-08-31 21:14:05 +00:00
|
|
|
_prefs = [PreferencesWindowController new];
|
2020-08-29 18:40:34 +00:00
|
|
|
}
|
|
|
|
[_prefs showWindow: sender];
|
|
|
|
}
|
2020-08-16 20:23:51 +00:00
|
|
|
|
2020-08-20 00:26:44 +00:00
|
|
|
|
2020-09-14 02:48:55 +00:00
|
|
|
- (IBAction)displayROMS:(id)sender {
|
2020-09-03 04:15:50 +00:00
|
|
|
if (!_downloader) {
|
2020-09-26 00:46:25 +00:00
|
|
|
_downloader = [DownloadWindowController sharedInstance];
|
2020-09-03 04:15:50 +00:00
|
|
|
}
|
|
|
|
[_downloader showWindow: sender];
|
|
|
|
}
|
|
|
|
|
2020-09-14 02:48:55 +00:00
|
|
|
- (IBAction)displayRecentDiskImages:(id)sender {
|
|
|
|
if (!_diskImages) {
|
2020-09-26 00:46:25 +00:00
|
|
|
_diskImages = [DiskImagesWindowController sharedInstance];
|
2020-09-14 02:48:55 +00:00
|
|
|
}
|
|
|
|
[_diskImages showWindow: sender];
|
|
|
|
}
|
2021-01-17 05:47:05 +00:00
|
|
|
|
|
|
|
- (IBAction)displayCheatSheet:(id)sender {
|
|
|
|
if (!_cheatSheet) {
|
|
|
|
_cheatSheet = [CheatSheetWindowController new];
|
|
|
|
}
|
|
|
|
[_cheatSheet showWindow: sender];
|
|
|
|
}
|
|
|
|
|
2020-10-03 16:46:19 +00:00
|
|
|
- (IBAction)displaySupportDirectory:(id)sender {
|
|
|
|
NSURL *url = SupportDirectory();
|
|
|
|
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
|
|
|
|
[ws openURL: url];
|
|
|
|
}
|
2020-10-04 18:53:20 +00:00
|
|
|
- (IBAction)mameDocumentation:(id)sender {
|
|
|
|
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
|
|
|
|
|
|
|
|
NSURL *url = [NSURL URLWithString: @"https://docs.mamedev.org"];
|
|
|
|
[ws openURL: url];
|
|
|
|
}
|
2020-09-26 00:46:25 +00:00
|
|
|
|
2020-12-29 23:04:02 +00:00
|
|
|
- (IBAction)mameAppleWiki:(id)sender {
|
|
|
|
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
|
|
|
|
|
|
|
|
NSURL *url = [NSURL URLWithString: @"https://wiki.mamedev.org/index.php/Driver:Apple_II"];
|
|
|
|
[ws openURL: url];
|
|
|
|
}
|
|
|
|
|
2021-05-18 21:51:53 +00:00
|
|
|
- (IBAction)mameMac68kWiki:(id)sender {
|
|
|
|
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
|
|
|
|
|
|
|
|
NSURL *url = [NSURL URLWithString: @"https://wiki.mamedev.org/index.php/Driver:Mac_68K"];
|
|
|
|
[ws openURL: url];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-24 01:56:21 +00:00
|
|
|
- (IBAction)manageBookmarks: (id)sender {
|
|
|
|
|
|
|
|
if (!_bookmarks) {
|
|
|
|
_bookmarks = [BookmarkWindowController new];
|
|
|
|
}
|
|
|
|
[_bookmarks showWindow: sender];
|
|
|
|
}
|
2021-05-18 21:51:53 +00:00
|
|
|
|
2020-12-29 23:04:02 +00:00
|
|
|
|
2022-04-30 14:17:57 +00:00
|
|
|
-(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];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-08-16 16:53:17 +00:00
|
|
|
@end
|