use constants for default keys.

This commit is contained in:
Kelvin Sherlock 2020-09-01 23:52:11 -04:00
parent 90be56f96d
commit e512fb982a
7 changed files with 75 additions and 9 deletions

View File

@ -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 = "<group>"; };
B6109A1524F5F376005CB652 /* apple2p.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = apple2p.plist; sourceTree = "<group>"; };
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>"; };
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>"; };
@ -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 */,

View File

@ -4,6 +4,11 @@
<dict>
<key>SchemeUserState</key>
<dict>
<key>Ample Lite.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
</dict>
<key>Ample copy.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>

21
Ample/Ample.h Normal file
View File

@ -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 <Cocoa/Cocoa.h>
NSURL *SupportDirectory(void);
/* NSUserDefaults keys */
extern NSString *kUseCustomMame;
extern NSString *kMamePath;
extern NSString *kAutoCloseLogWindow;
#endif /* Ample_h */

29
Ample/Ample.m Normal file
View File

@ -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";

View File

@ -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) {

View File

@ -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.

View File

@ -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]];
}