ample/Ample/AppDelegate.m
Kelvin Sherlock 1b7faf3ac4 Updates to work with 10.11 (El Capitan) and newer.
There are still a couple minor UI degradations

eg: mame cheat sheet, recent disk images window, auto complete window.

Squashed commit of the following:

commit fb115024f805da38b747fd1905573fabb7bff24e
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Sun May 30 18:00:13 2021 -0400

    ?

commit 8405f4df95ae8f5bc5dc33598dc0b3f8972b32cd
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Sun May 30 17:59:43 2021 -0400

    tintColor not present before 10.14

commit 86a6102cee4f30cac2972259ef55fda3c32b8f9a
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Sun May 30 17:59:19 2021 -0400

    [menu setItemArray:] apparently has problems before 10.14

commit 65227a00743fbf143c623af8a76698d57bdc4573
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Sun May 30 17:58:15 2021 -0400

    NSCache doesn't like null objects.

commit 8a4c3a4662647d5ee0b609bde9f3aaa5c0d99776
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Sun May 30 16:00:05 2021 -0400

    organize copy bundle resources.

    multiple-sized png images are converted to a single tiff (with multiple sizes).
    This is fine BUT EL capitan grabs the first image so if the @3x image is first, it will be used.

commit 44b94cdfd47117864b6529214b1c91a0c2e41327
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Sun May 30 15:57:37 2021 -0400

    add NewSlotViewController.m to Ample Lite.

commit 2fa1b7418783e48ca625ab3490e43cbff9e5619a
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Sun May 30 13:57:19 2021 -0400

    Ample Lite was missing reference to New Slot View nib.

commit 65f268e77a65f8c57019702d8f0c2b66577c5ee7
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Sun May 30 13:56:04 2021 -0400

    based on testing, 10.11 still has public.file-url, which is kUTTypeFileURL.  10.13 added NSURLPBoardType as a synonym.

commit cde123b16eb336b7695b444931b9e9bb9802d772
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Sun May 30 13:54:02 2021 -0400

    set everything to 10.11

commit e7a670efd3
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Sat May 29 23:33:31 2021 -0400

    script to download SDL2.Framework

commit 9f38f2972a
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Sat May 29 22:15:32 2021 -0400

    WKWebView apparently has a bug prior to 10.12 so it can't be created via a nib.

commit e18aea7249
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Sat May 29 22:14:38 2021 -0400

    version checks for features not present in 10.11

commit 07dcf30f52
Author: Kelvin Sherlock <ksherlock@gmail.com>
Date:   Fri May 28 21:30:53 2021 -0400

    lower target to 10.11
2021-05-30 18:00:34 -04:00

227 lines
5.9 KiB
Objective-C

//
// AppDelegate.m
// Ample
//
// 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"
#import "DownloadWindowController.h"
#import "DiskImagesWindowController.h"
#import "CheatSheetWindowController.h"
#import "Transformers.h"
#import "LogWindowController.h"
@interface AppDelegate ()
@property (weak) IBOutlet NSWindow *installWindow;
@end
@implementation AppDelegate {
NSWindowController *_prefs;
NSWindowController *_launcher;
NSWindowController *_downloader;
NSWindowController *_diskImages;
NSWindowController *_cheatSheet;
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
NSBundle *bundle = [NSBundle mainBundle];
NSString *path;
NSDictionary *dict;
RegisterTransformers();
path = [bundle pathForResource: @"Defaults" ofType: @"plist"];
dict = [NSDictionary dictionaryWithContentsOfFile: path];
if (dict)
{
[[NSUserDefaults standardUserDefaults] registerDefaults: dict];
}
_diskImages = [DiskImagesWindowController sharedInstance]; //[DiskImagesWindowController 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
];
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){
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];
[self displayROMS: nil];
});
}];
[task launch];
return NO;
}
- (void)applicationWillTerminate:(NSNotification *)aNotification {
// Insert code here to tear down your application
}
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender {
return YES;
}
-(BOOL)application:(NSApplication *)sender openFile:(NSString *)filename {
NSString *ext = [[filename pathExtension] lowercaseString];
if ([ext isEqualToString: @"vgm"] || [ext isEqualToString: @"vgz"]) {
// run mame...
NSArray *args = @[ @"vgmplay", @"-window", @"-nomax", @"-skip_gameinfo", @"-quik", filename ];
[LogWindowController controllerForArgs: args];
}
return NO;
}
#pragma mark - IBActions
- (IBAction)displayPreferences:(id)sender {
if (!_prefs) {
_prefs = [PreferencesWindowController new];
}
[_prefs showWindow: sender];
}
- (IBAction)displayROMS:(id)sender {
if (!_downloader) {
_downloader = [DownloadWindowController sharedInstance];
}
[_downloader showWindow: sender];
}
- (IBAction)displayRecentDiskImages:(id)sender {
if (!_diskImages) {
_diskImages = [DiskImagesWindowController sharedInstance];
}
[_diskImages showWindow: sender];
}
- (IBAction)displayCheatSheet:(id)sender {
if (!_cheatSheet) {
_cheatSheet = [CheatSheetWindowController new];
}
[_cheatSheet showWindow: sender];
}
- (IBAction)displaySupportDirectory:(id)sender {
NSURL *url = SupportDirectory();
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
[ws openURL: url];
}
- (IBAction)mameDocumentation:(id)sender {
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
NSURL *url = [NSURL URLWithString: @"https://docs.mamedev.org"];
[ws openURL: url];
}
- (IBAction)mameAppleWiki:(id)sender {
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
NSURL *url = [NSURL URLWithString: @"https://wiki.mamedev.org/index.php/Driver:Apple_II"];
[ws openURL: url];
}
- (IBAction)mameMac68kWiki:(id)sender {
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
NSURL *url = [NSURL URLWithString: @"https://wiki.mamedev.org/index.php/Driver:Mac_68K"];
[ws openURL: url];
}
@end