From e512fb982a1e89fc1455b210171f87e22df1e2e0 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Tue, 1 Sep 2020 23:52:11 -0400 Subject: [PATCH] use constants for default keys. --- Ample.xcodeproj/project.pbxproj | 8 +++++ .../xcschemes/xcschememanagement.plist | 5 ++++ Ample/Ample.h | 21 ++++++++++++++ Ample/Ample.m | 29 +++++++++++++++++++ Ample/LaunchWindowController.m | 15 +++++----- Ample/LogWindowController.m | 3 +- Ample/PreferencesWindowController.m | 3 +- 7 files changed, 75 insertions(+), 9 deletions(-) create mode 100644 Ample/Ample.h create mode 100644 Ample/Ample.m diff --git a/Ample.xcodeproj/project.pbxproj b/Ample.xcodeproj/project.pbxproj index 0faffd9..3e1983f 100644 --- a/Ample.xcodeproj/project.pbxproj +++ b/Ample.xcodeproj/project.pbxproj @@ -57,6 +57,8 @@ B6109A4124F5F377005CB652 /* apple2cp.plist in Resources */ = {isa = PBXBuildFile; fileRef = B6109A1424F5F376005CB652 /* apple2cp.plist */; }; B6109A4224F5F377005CB652 /* apple2p.plist in Resources */ = {isa = PBXBuildFile; fileRef = B6109A1524F5F376005CB652 /* apple2p.plist */; }; 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 */; }; 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 */; }; @@ -225,6 +227,8 @@ B6109A1424F5F376005CB652 /* apple2cp.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = apple2cp.plist; sourceTree = ""; }; B6109A1524F5F376005CB652 /* apple2p.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = apple2p.plist; sourceTree = ""; }; 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 = ""; }; 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 = ""; }; @@ -375,6 +379,8 @@ children = ( B6BA257E24E99BE9005FB8FF /* AppDelegate.h */, B6BA257F24E99BE9005FB8FF /* AppDelegate.m */, + B63C1B8924FF4B7100511A71 /* Ample.h */, + B63C1B8A24FF4BF700511A71 /* Ample.m */, B6D6DE3F24FADFAC00661A5F /* LaunchWindowController.h */, B6D6DE4024FADFAC00661A5F /* LaunchWindowController.m */, B65593B024ECB61800722E0C /* SlotViewController.m */, @@ -618,6 +624,7 @@ buildActionMask = 2147483647; files = ( B6BA258824E99BEB005FB8FF /* main.m in Sources */, + B63C1B8B24FF4BF700511A71 /* Ample.m in Sources */, B6D6DE4124FADFAC00661A5F /* LaunchWindowController.m in Sources */, B64E15A924EA1D5300E8AD3D /* MachineViewController.m in Sources */, B64979C224EF6703008ABD20 /* MediaViewController.m in Sources */, @@ -634,6 +641,7 @@ buildActionMask = 2147483647; files = ( B6E4B5B024FDE2670094A35C /* main.m in Sources */, + B63C1B8C24FF4BF700511A71 /* Ample.m in Sources */, B6E4B5B124FDE2670094A35C /* LaunchWindowController.m in Sources */, B6E4B5B224FDE2670094A35C /* MachineViewController.m in Sources */, B6E4B5B324FDE2670094A35C /* MediaViewController.m in Sources */, diff --git a/Ample.xcodeproj/xcuserdata/kelvin.xcuserdatad/xcschemes/xcschememanagement.plist b/Ample.xcodeproj/xcuserdata/kelvin.xcuserdatad/xcschemes/xcschememanagement.plist index bc391e3..e3ca695 100644 --- a/Ample.xcodeproj/xcuserdata/kelvin.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/Ample.xcodeproj/xcuserdata/kelvin.xcuserdatad/xcschemes/xcschememanagement.plist @@ -4,6 +4,11 @@ SchemeUserState + Ample Lite.xcscheme_^#shared#^_ + + orderHint + 1 + Ample copy.xcscheme_^#shared#^_ orderHint diff --git a/Ample/Ample.h b/Ample/Ample.h new file mode 100644 index 0000000..d091a4c --- /dev/null +++ b/Ample/Ample.h @@ -0,0 +1,21 @@ +// +// Ample.h +// Ample +// +// Created by Kelvin Sherlock on 9/1/2020. +// Copyright © 2020 Kelvin Sherlock. All rights reserved. +// + +#ifndef Ample_h +#define Ample_h + +#import + +NSURL *SupportDirectory(void); + +/* NSUserDefaults keys */ +extern NSString *kUseCustomMame; +extern NSString *kMamePath; +extern NSString *kAutoCloseLogWindow; + +#endif /* Ample_h */ diff --git a/Ample/Ample.m b/Ample/Ample.m new file mode 100644 index 0000000..4c75000 --- /dev/null +++ b/Ample/Ample.m @@ -0,0 +1,29 @@ +// +// Ample.m +// Ample +// +// Created by Kelvin Sherlock on 9/1/2020. +// Copyright © 2020 Kelvin Sherlock. All rights reserved. +// + +#include "Ample.h" + +NSURL *SupportDirectory(void) { + static NSURL *cached = nil; + + if (!cached) { + NSFileManager *fm = [NSFileManager defaultManager]; + NSError *error = nil; + + NSURL *url = [fm URLForDirectory: NSApplicationSupportDirectory inDomain: NSUserDomainMask appropriateForURL: nil create: YES error: &error]; + cached = [url URLByAppendingPathComponent: @"Ample"]; + + [fm createDirectoryAtURL: cached withIntermediateDirectories: YES attributes: nil error: &error]; + } + return cached; +} + + +NSString *kUseCustomMame = @"UseCustomMame"; +NSString *kMamePath = @"MamePath"; +NSString *kAutoCloseLogWindow = @"AutoCloseLogWindow"; diff --git a/Ample/LaunchWindowController.m b/Ample/LaunchWindowController.m index 9cf73fc..22c5306 100644 --- a/Ample/LaunchWindowController.m +++ b/Ample/LaunchWindowController.m @@ -6,6 +6,7 @@ // Copyright © 2020 Kelvin Sherlock. All rights reserved. // +#import "Ample.h" #import "LaunchWindowController.h" #import "MediaViewController.h" #import "SlotViewController.h" @@ -97,8 +98,8 @@ static NSURL *MameURL(void) { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSBundle *bundle = [NSBundle mainBundle]; - if ([defaults boolForKey: @"UseSystemMame"]) { - NSString *path = [defaults stringForKey: @"MamePath"]; + if ([defaults boolForKey: kUseCustomMame]) { + NSString *path = [defaults stringForKey: kMamePath]; if (![path length]) return [NSURL fileURLWithPath: path]; } @@ -114,8 +115,8 @@ static NSString *MamePath(void) { NSString *path; - if ([defaults boolForKey: @"UseCustomMame"]) { - path = [defaults stringForKey: @"MamePath"]; + if ([defaults boolForKey: kUseCustomMame]) { + path = [defaults stringForKey: kMamePath]; if ([path length]) return path; } path = [bundle pathForAuxiliaryExecutable: @"mame64"]; @@ -197,7 +198,6 @@ static NSString * JoinArguments(NSArray *argv) { -(void)buildCommandLine { - if (!_mameMachine) { [self setCommandLine: @""]; return; @@ -252,7 +252,7 @@ static NSString * JoinArguments(NSArray *argv) { if (_mameNoThrottle) [argv addObject: @"-nothrottle"]; - [self setCommandLine: JoinArguments(argv)]; //[argv componentsJoinedByString:@" "]]; + [self setCommandLine: JoinArguments(argv)]; [self setArgs: argv]; } @@ -264,7 +264,8 @@ static NSString * JoinArguments(NSArray *argv) { - (IBAction)launchAction:(id)sender { if (![_args count]) return; - + + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSURL *url = MameURL(); if (!url) { diff --git a/Ample/LogWindowController.m b/Ample/LogWindowController.m index 31e0f70..ff201f5 100644 --- a/Ample/LogWindowController.m +++ b/Ample/LogWindowController.m @@ -6,6 +6,7 @@ // Copyright © 2020 Kelvin Sherlock. All rights reserved. // +#import "Ample.h" #import "LogWindowController.h" static NSMutableSet *LogWindows; @@ -148,7 +149,7 @@ static NSMutableSet *LogWindows; [[self window] setDocumentEdited: NO]; - if (ok && [[NSUserDefaults standardUserDefaults] boolForKey: @"AutoCloseLogWindow"]) { + if (ok && [[NSUserDefaults standardUserDefaults] boolForKey: kAutoCloseLogWindow]) { [[self window] close]; //[LogWindows removeObject: self]; // close sends WindowWillClose notification. diff --git a/Ample/PreferencesWindowController.m b/Ample/PreferencesWindowController.m index eb97fce..d01b109 100644 --- a/Ample/PreferencesWindowController.m +++ b/Ample/PreferencesWindowController.m @@ -6,6 +6,7 @@ // Copyright © 2020 Kelvin Sherlock. All rights reserved. // +#import "Ample.h" #import "PreferencesWindowController.h" @interface PreferencesWindowController () @@ -25,7 +26,7 @@ // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file. - [self validateMamePath: [defaults stringForKey: @"MamePath"]]; + [self validateMamePath: [defaults stringForKey: kMamePath]]; }