support change config file, resource file path
parent
fa06e917de
commit
2a2ec1b45f
|
@ -6,5 +6,7 @@
|
|||
<true/>
|
||||
<key>com.apple.security.files.user-selected.read-only</key>
|
||||
<true/>
|
||||
<key>com.apple.security.files.bookmarks.app-scope</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
|
|
|
@ -27,7 +27,7 @@ class CelestiaCore;
|
|||
-(int)toCelestiaModifiers:(unsigned int)modifiers buttons:(unsigned int)buttons;
|
||||
-(void)archive;
|
||||
+(CelestiaAppCore *)sharedAppCore;
|
||||
-(BOOL)initSimulation;
|
||||
-(BOOL)initSimulationWithConfigPath:(NSString *)configPath extraPath:(NSString *)extraPath;
|
||||
-(BOOL)initRenderer;
|
||||
-(void)start:(NSDate *)date;
|
||||
-(void)charEntered:(char)c withModifiers:(int)modifiers;
|
||||
|
|
|
@ -339,70 +339,22 @@ CelestiaCore *appCore;
|
|||
[super dealloc];
|
||||
}
|
||||
|
||||
-(BOOL)initSimulation
|
||||
-(BOOL)initSimulationWithConfigPath:(NSString *)configPath extraPath:(NSString *)extraPath
|
||||
{
|
||||
BOOL result = NO;
|
||||
appCore = new CelestiaCore();
|
||||
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
|
||||
NSString *confFileSetting;
|
||||
std::string confFile;
|
||||
NSArray *existingResourceDirsSetting;
|
||||
NSArray *extrasDirsSetting;
|
||||
std::string confFile = [configPath UTF8String];
|
||||
std::vector<std::string> extrasDirs;
|
||||
NSString *extrasDir = nil;
|
||||
MacOSXSplashProgressNotifier progressNotifier;
|
||||
|
||||
if ((confFileSetting = [prefs stringForKey:@"conf"]))
|
||||
if (extraPath)
|
||||
{
|
||||
confFile = [confFileSetting stdString];
|
||||
}
|
||||
|
||||
if ((existingResourceDirsSetting = [prefs stringArrayForKey:@"existingResourceDirs"]))
|
||||
{
|
||||
NSFileManager *fm = [NSFileManager defaultManager];
|
||||
BOOL isFolder = NO;
|
||||
NSEnumerator *resouceDirEnum = [existingResourceDirsSetting objectEnumerator];
|
||||
NSString *resourceDir = nil;
|
||||
NSString *existingConfFile = nil;
|
||||
while ((resourceDir = [resouceDirEnum nextObject]))
|
||||
{
|
||||
existingConfFile = [resourceDir stringByAppendingPathComponent:@"celestia.cfg"];
|
||||
CelestiaConfig *config = ReadCelestiaConfig([existingConfFile stdString], NULL);
|
||||
if (config)
|
||||
{
|
||||
for (vector<string>::const_iterator iter = config->extrasDirs.begin();
|
||||
iter != config->extrasDirs.end(); iter++)
|
||||
{
|
||||
if (*iter != "")
|
||||
{
|
||||
extrasDir = [NSString stringWithStdString: (*iter)];
|
||||
if (([fm fileExistsAtPath: extrasDir = [extrasDir stringByStandardizingPath] isDirectory: &isFolder] && isFolder) ||
|
||||
[fm fileExistsAtPath: extrasDir = [resourceDir stringByAppendingPathComponent:extrasDir] isDirectory: &isFolder] && isFolder)
|
||||
{
|
||||
extrasDirs.push_back([extrasDir stdString]);
|
||||
}
|
||||
}
|
||||
}
|
||||
delete config;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ([fm fileExistsAtPath: extrasDir = [resourceDir stringByAppendingPathComponent: @"extras"] isDirectory: &isFolder] && isFolder)
|
||||
extrasDirs.push_back([extrasDir stdString]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if ((extrasDirsSetting = [prefs stringArrayForKey:@"extrasDirs"]))
|
||||
{
|
||||
NSEnumerator *iter = [extrasDirsSetting objectEnumerator];
|
||||
while ((extrasDir = [iter nextObject]))
|
||||
extrasDirs.push_back([extrasDir stdString]);
|
||||
extrasDirs.push_back([extraPath UTF8String]);
|
||||
}
|
||||
|
||||
appCore->setAlerter(new MacOSXAlerter());
|
||||
appCore->setCursorHandler(new MacOSXCursorHandler());
|
||||
result = appCore->initSimulation(!confFile.empty() ? &confFile : nil,
|
||||
result = appCore->initSimulation(&confFile,
|
||||
&extrasDirs,
|
||||
&progressNotifier);
|
||||
if (result)
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
@class SplashWindowController;
|
||||
@class EclipseFinderController;
|
||||
@class ScriptsController;
|
||||
@class ConfigSelectionWindowController;
|
||||
|
||||
@interface CelestiaController : NSWindowController
|
||||
{
|
||||
|
@ -28,6 +29,7 @@
|
|||
BOOL ready;
|
||||
BOOL isDirty;
|
||||
BOOL isFullScreen;
|
||||
BOOL needsRelaunch;
|
||||
IBOutlet SplashWindowController *splashWindowController;
|
||||
IBOutlet NSTextView *glInfo;
|
||||
IBOutlet NSPanel *glInfoPanel;
|
||||
|
@ -39,6 +41,7 @@
|
|||
BrowserWindowController *browserWindowController;
|
||||
EclipseFinderController *eclipseFinderController;
|
||||
NSWindowController *helpWindowController;
|
||||
ConfigSelectionWindowController *configSelectionWindowController;
|
||||
NSTimer* timer;
|
||||
|
||||
NSConditionLock* startupCondition;
|
||||
|
@ -47,6 +50,7 @@
|
|||
NSString *pendingScript;
|
||||
NSString *pendingUrl;
|
||||
}
|
||||
-(void)setNeedsRelaunch:(BOOL)needsRelaunch;
|
||||
-(BOOL)applicationShouldTerminate:(id)sender;
|
||||
-(BOOL)windowShouldClose:(id)sender;
|
||||
-(IBAction)back:(id)sender;
|
||||
|
|
|
@ -18,12 +18,16 @@
|
|||
#import <Carbon/Carbon.h>
|
||||
#import <OpenGL/gl.h>
|
||||
#import "CGLInfo.h"
|
||||
#import "ConfigSelectionWindowController.h"
|
||||
|
||||
#include <float.h>
|
||||
|
||||
|
||||
@implementation CelestiaController
|
||||
|
||||
static NSURL *configFilePath = nil;
|
||||
static NSURL *dataDirPath = nil;
|
||||
static NSURL *extraDataDirPath = nil;
|
||||
|
||||
static CelestiaController* firstInstance;
|
||||
|
||||
+(CelestiaController*) shared
|
||||
|
@ -44,6 +48,30 @@ NSString* fatalErrorMessage;
|
|||
}
|
||||
|
||||
if (firstInstance == nil ) firstInstance = self;
|
||||
|
||||
// read config file/data dir from saved
|
||||
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
|
||||
NSData *configFileData = [prefs objectForKey:configFilePathPrefKey];
|
||||
NSData *dataDirData = [prefs objectForKey:configFilePathPrefKey];
|
||||
|
||||
if (configFileData != nil && dataDirData != nil) {
|
||||
// read saved sandbox bookmark
|
||||
NSError *error = nil;
|
||||
configFilePath = [NSURL URLByResolvingBookmarkData:configFileData options:NSURLBookmarkResolutionWithSecurityScope relativeToURL:nil bookmarkDataIsStale:nil error:&error];
|
||||
dataDirPath = [NSURL URLByResolvingBookmarkData:dataDirData options:NSURLBookmarkResolutionWithSecurityScope relativeToURL:nil bookmarkDataIsStale:nil error:&error];
|
||||
}
|
||||
|
||||
if (configFilePath == nil || dataDirPath == nil)
|
||||
{
|
||||
// use the default location
|
||||
configFilePath = [[[NSBundle mainBundle] URLForResource:[NSString stringWithFormat:@"%@/celestia.cfg", CELESTIA_RESOURCES_FOLDER] withExtension:nil] retain];
|
||||
dataDirPath = [[[NSBundle mainBundle] URLForResource:[NSString stringWithFormat:@"%@", CELESTIA_RESOURCES_FOLDER] withExtension:nil] retain];
|
||||
}
|
||||
|
||||
// add the edit configuration menu item
|
||||
NSMenu *appMenu = [[[[NSApp mainMenu] itemArray] objectAtIndex:0] submenu];
|
||||
[appMenu insertItem:[[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Change Configuration File", "") action:@selector(changeConfigFileLocation) keyEquivalent:@""] atIndex:[[appMenu itemArray] count] - 1];
|
||||
|
||||
int cpuCount = 0;
|
||||
size_t cpuCountSize = sizeof cpuCount;
|
||||
if (0 == sysctlbyname("hw.ncpu", &cpuCount, &cpuCountSize, NULL, 0))
|
||||
|
@ -53,12 +81,13 @@ NSString* fatalErrorMessage;
|
|||
ready = NO;
|
||||
isDirty = YES;
|
||||
isFullScreen = NO;
|
||||
needsRelaunch = NO;
|
||||
appCore = nil;
|
||||
fatalErrorMessage = nil;
|
||||
lastScript = nil;
|
||||
|
||||
[self setupResourceDirectory];
|
||||
[scriptsController buildScriptMenu];
|
||||
[scriptsController buildScriptMenuWithScriptDir:extraDataDirPath.path];
|
||||
|
||||
// hide main window until ready
|
||||
[[glView window] setAlphaValue: 0.0f]; // not [[glView window] orderOut: nil];
|
||||
|
@ -94,72 +123,48 @@ NSString* fatalErrorMessage;
|
|||
}
|
||||
}
|
||||
|
||||
- (void)setNeedsRelaunch:(BOOL)newValue {
|
||||
needsRelaunch = newValue;
|
||||
}
|
||||
|
||||
- (void)changeConfigFileLocation {
|
||||
if (configSelectionWindowController == nil) {
|
||||
configSelectionWindowController = [[ConfigSelectionWindowController alloc] initWithWindowNibName:@"ConfigSelectionWindow"];
|
||||
configSelectionWindowController->dataDirPath = [dataDirPath retain];
|
||||
configSelectionWindowController->configFilePath = [configFilePath retain];
|
||||
}
|
||||
[configSelectionWindowController showWindow:self];
|
||||
}
|
||||
|
||||
- (void) setupResourceDirectory
|
||||
{
|
||||
NSBundle* mainBundle = [NSBundle mainBundle];
|
||||
// Change directory to resource dir so Celestia can find cfg files and textures
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
NSString* path;
|
||||
NSMutableArray *resourceDirs = [NSMutableArray array];
|
||||
BOOL isFolder = NO;
|
||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||
[fileManager changeCurrentDirectoryPath:[dataDirPath path]];
|
||||
|
||||
if ( [ fileManager fileExistsAtPath: path = [[ mainBundle resourcePath ] stringByAppendingPathComponent: CELESTIA_RESOURCES_FOLDER ] isDirectory: &isFolder ] && isFolder )
|
||||
{
|
||||
[resourceDirs addObject: path];
|
||||
}
|
||||
if ( [ fileManager fileExistsAtPath: path = [[[ mainBundle bundlePath ] stringByDeletingLastPathComponent] stringByAppendingPathComponent: CELESTIA_RESOURCES_FOLDER ] isDirectory: &isFolder ] && isFolder )
|
||||
{
|
||||
[resourceDirs addObject: path];
|
||||
}
|
||||
FSRef folder;
|
||||
CFURLRef url;
|
||||
static short domains[] = { kUserDomain, kLocalDomain, kNetworkDomain };
|
||||
unsigned i;
|
||||
path = nil;
|
||||
// extra/script resources are located in application support folder, not sandboxed
|
||||
NSString *supportPath = [NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) firstObject];
|
||||
NSString *extraDataDir = [supportPath stringByAppendingPathComponent:CELESTIA_RESOURCES_FOLDER];
|
||||
NSString *extraDir = [extraDataDir stringByAppendingPathComponent:@"extras"];
|
||||
NSString *scriptDir = [extraDataDir stringByAppendingPathComponent:CEL_SCRIPTS_FOLDER];
|
||||
BOOL isDirectory;
|
||||
BOOL exists = [fileManager fileExistsAtPath:extraDataDir isDirectory:&isDirectory];
|
||||
|
||||
for (i = 0; i < (sizeof domains / sizeof(short)); ++i)
|
||||
if (exists && !isDirectory) // should be a directory but not
|
||||
return;
|
||||
|
||||
if (!exists)
|
||||
{
|
||||
if (FSFindFolder(domains[i], kApplicationSupportFolderType, FALSE, &folder) == noErr)
|
||||
// create directory and subdirectories
|
||||
if ([fileManager createDirectoryAtPath:extraDataDir withIntermediateDirectories:YES attributes:nil error:nil])
|
||||
{
|
||||
url = CFURLCreateFromFSRef(nil, &folder);
|
||||
path = [(NSURL *)url path];
|
||||
CFRelease(url);
|
||||
|
||||
if (path)
|
||||
{
|
||||
if (![fileManager fileExistsAtPath: path = [path stringByAppendingPathComponent: CELESTIA_RESOURCES_FOLDER]] &&
|
||||
kUserDomain==domains[i])
|
||||
{
|
||||
if ([fileManager createDirectoryAtPath:path attributes:nil])
|
||||
{
|
||||
[fileManager createDirectoryAtPath:[path stringByAppendingPathComponent:@"extras"] attributes:nil];
|
||||
[fileManager createDirectoryAtPath:[path stringByAppendingPathComponent:CEL_SCRIPTS_FOLDER] attributes:nil];
|
||||
}
|
||||
}
|
||||
if ([fileManager fileExistsAtPath:path isDirectory:&isFolder] && isFolder)
|
||||
{
|
||||
[resourceDirs addObject: path];
|
||||
}
|
||||
}
|
||||
|
||||
path = nil;
|
||||
[fileManager createDirectoryAtPath:extraDir withIntermediateDirectories:YES attributes:nil error:nil];
|
||||
[fileManager createDirectoryAtPath:scriptDir withIntermediateDirectories:YES attributes:nil error:nil];
|
||||
}
|
||||
}
|
||||
|
||||
if ([resourceDirs count] > 0)
|
||||
{
|
||||
[fileManager changeCurrentDirectoryPath: [resourceDirs objectAtIndex: 0]];
|
||||
[resourceDirs removeObjectAtIndex: 0];
|
||||
if ([resourceDirs count] > 0) {
|
||||
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
|
||||
[prefs registerDefaults:[NSDictionary dictionaryWithObject:[NSArray arrayWithObject:[resourceDirs objectAtIndex:0]] forKey:@"existingResourceDirs"]];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
[self fatalError: NSLocalizedString(@"It appears that the \"CelestiaResources\" directory has not been properly installed in the correct location as indicated in the installation instructions. \n\nPlease correct this and try again.",@"")];
|
||||
[self fatalError: nil];
|
||||
if ([fileManager fileExistsAtPath:extraDataDir isDirectory:&isDirectory] && isDirectory) {
|
||||
extraDataDirPath = [NSURL fileURLWithPath:extraDataDir];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -171,7 +176,7 @@ NSString* fatalErrorMessage;
|
|||
#ifdef DEBUG
|
||||
NSDate *t = [NSDate date];
|
||||
#endif
|
||||
if (![appCore initSimulation])
|
||||
if (![appCore initSimulationWithConfigPath:configFilePath.path extraPath:extraDataDirPath.path])
|
||||
{
|
||||
[startupCondition lock];
|
||||
[startupCondition unlockWithCondition: 99];
|
||||
|
@ -464,14 +469,17 @@ NSString* fatalErrorMessage;
|
|||
|
||||
-(BOOL)applicationShouldTerminate:(id)sender
|
||||
{
|
||||
if ( NSRunAlertPanel(NSLocalizedString(@"Quit Celestia?",@""),
|
||||
NSLocalizedString(@"Are you sure you want to quit Celestia?",@""),
|
||||
NSLocalizedString(@"Quit",@""),
|
||||
NSLocalizedString(@"Cancel",@""),
|
||||
nil) != NSAlertDefaultReturn )
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
if (needsRelaunch)
|
||||
return YES;
|
||||
|
||||
if ( NSRunAlertPanel(NSLocalizedString(@"Quit Celestia?",@""),
|
||||
NSLocalizedString(@"Are you sure you want to quit Celestia?",@""),
|
||||
NSLocalizedString(@"Quit",@""),
|
||||
NSLocalizedString(@"Cancel",@""),
|
||||
nil) != NSAlertDefaultReturn )
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (timer != nil) {
|
||||
[timer invalidate];
|
||||
|
@ -495,6 +503,11 @@ NSString* fatalErrorMessage;
|
|||
[appCore release];
|
||||
appCore = nil;
|
||||
}
|
||||
|
||||
if (needsRelaunch)
|
||||
{
|
||||
[[NSWorkspace sharedWorkspace] launchAppWithBundleIdentifier:[[NSBundle mainBundle] bundleIdentifier] options:NSWorkspaceLaunchAsync additionalEventParamDescriptor:nil launchIdentifier:nil];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,102 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
||||
<dependencies>
|
||||
<deployment identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14490.70"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<customObject id="-2" userLabel="File's Owner" customClass="ConfigSelectionWindowController">
|
||||
<connections>
|
||||
<outlet property="configFilePathControl" destination="Rsa-NG-CKd" id="zuh-8R-j4m"/>
|
||||
<outlet property="dataDirPathControl" destination="28L-dp-ArL" id="vJR-Xg-VZd"/>
|
||||
<outlet property="window" destination="RKC-D9-XqT" id="wIx-7S-quQ"/>
|
||||
</connections>
|
||||
</customObject>
|
||||
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
|
||||
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
|
||||
<window title="Configuration File Selection" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" restorable="NO" frameAutosaveName="" animationBehavior="default" id="RKC-D9-XqT">
|
||||
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
|
||||
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
|
||||
<rect key="contentRect" x="131" y="158" width="393" height="111"/>
|
||||
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="877"/>
|
||||
<value key="minSize" type="size" width="393" height="111"/>
|
||||
<value key="maxSize" type="size" width="393" height="111"/>
|
||||
<view key="contentView" id="OOK-Xk-qXu">
|
||||
<rect key="frame" x="0.0" y="0.0" width="393" height="111"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<pathControl verticalHuggingPriority="750" fixedFrame="YES" allowsExpansionToolTips="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Rsa-NG-CKd">
|
||||
<rect key="frame" x="133" y="73" width="204" height="22"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<pathCell key="cell" controlSize="small" selectable="YES" editable="YES" alignment="left" pathStyle="popUp" id="e39-KY-FwS">
|
||||
<font key="font" metaFont="controlContent" size="11"/>
|
||||
<url key="url" string="file://localhost/Applications/"/>
|
||||
<allowedTypes>
|
||||
<string>cfg</string>
|
||||
</allowedTypes>
|
||||
</pathCell>
|
||||
</pathControl>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="RPi-Te-S7L">
|
||||
<rect key="frame" x="18" y="77" width="97" height="14"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<textFieldCell key="cell" controlSize="small" lineBreakMode="clipping" title="Configuration File" id="mm9-vf-wMR">
|
||||
<font key="font" metaFont="controlContent" size="11"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="wHC-tW-1gU">
|
||||
<rect key="frame" x="18" y="55" width="80" height="14"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<textFieldCell key="cell" controlSize="small" lineBreakMode="clipping" title="Data Directory" id="UVE-HK-9If">
|
||||
<font key="font" metaFont="controlContent" size="11"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<pathControl verticalHuggingPriority="750" fixedFrame="YES" allowsExpansionToolTips="YES" translatesAutoresizingMaskIntoConstraints="NO" id="28L-dp-ArL">
|
||||
<rect key="frame" x="133" y="51" width="204" height="22"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<pathCell key="cell" controlSize="small" selectable="YES" editable="YES" alignment="left" pathStyle="popUp" id="mzg-f0-1Fg">
|
||||
<font key="font" metaFont="controlContent" size="11"/>
|
||||
<url key="url" string="file://localhost/Applications/"/>
|
||||
<allowedTypes>
|
||||
<string>public.folder</string>
|
||||
</allowedTypes>
|
||||
</pathCell>
|
||||
</pathControl>
|
||||
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="ff6-C3-vKK">
|
||||
<rect key="frame" x="148" y="14" width="79" height="27"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<buttonCell key="cell" type="push" title="Cancel" bezelStyle="rounded" alignment="center" controlSize="small" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="nal-G6-jSo">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="controlContent" size="11"/>
|
||||
<string key="keyEquivalent" base64-UTF8="YES">
|
||||
Gw
|
||||
</string>
|
||||
</buttonCell>
|
||||
<connections>
|
||||
<action selector="performClose:" target="RKC-D9-XqT" id="rhQ-aJ-hns"/>
|
||||
</connections>
|
||||
</button>
|
||||
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="niS-ko-H04">
|
||||
<rect key="frame" x="236" y="14" width="142" height="27"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<buttonCell key="cell" type="push" title="Confirm and Relaunch" bezelStyle="rounded" alignment="center" controlSize="small" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="bzF-c1-7D5">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="controlContent" size="11"/>
|
||||
<string key="keyEquivalent" base64-UTF8="YES">
|
||||
DQ
|
||||
</string>
|
||||
</buttonCell>
|
||||
<connections>
|
||||
<action selector="confirmSelection:" target="-2" id="fHd-Fv-LIW"/>
|
||||
</connections>
|
||||
</button>
|
||||
</subviews>
|
||||
</view>
|
||||
<point key="canvasLocation" x="31.5" y="90.5"/>
|
||||
</window>
|
||||
</objects>
|
||||
</document>
|
|
@ -0,0 +1,22 @@
|
|||
//
|
||||
// ConfigSelectionWindowController.h
|
||||
// Celestia
|
||||
//
|
||||
// Created by 李林峰 on 2019/9/8.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
extern NSString *const configFilePathPrefKey;
|
||||
extern NSString *const dataDirPathPrefKey;
|
||||
|
||||
@interface ConfigSelectionWindowController : NSWindowController {
|
||||
@public
|
||||
NSURL *configFilePath;
|
||||
NSURL *dataDirPath;
|
||||
@private
|
||||
IBOutlet NSPathControl *configFilePathControl;
|
||||
IBOutlet NSPathControl *dataDirPathControl;
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,49 @@
|
|||
//
|
||||
// ConfigSelectionWindowController.m
|
||||
// Celestia
|
||||
//
|
||||
// Created by 李林峰 on 2019/9/8.
|
||||
//
|
||||
|
||||
#import "ConfigSelectionWindowController.h"
|
||||
#import "CelestiaController.h"
|
||||
|
||||
NSString *const configFilePathPrefKey = @"configFilePath";
|
||||
NSString *const dataDirPathPrefKey = @"dataDirPath";
|
||||
|
||||
@implementation ConfigSelectionWindowController
|
||||
|
||||
- (void)awakeFromNib {
|
||||
[super awakeFromNib];
|
||||
|
||||
[configFilePathControl setURL:configFilePath];
|
||||
[dataDirPathControl setURL:dataDirPath];
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[configFilePath release];
|
||||
[dataDirPath release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (IBAction)confirmSelection:(id)sender {
|
||||
// save the selection, since we are running in a sandboxed environment, save bookmark
|
||||
NSError *error = nil;
|
||||
NSData *configFilePathData = [[configFilePathControl URL] bookmarkDataWithOptions:NSURLBookmarkCreationSecurityScopeAllowOnlyReadAccess includingResourceValuesForKeys:nil relativeToURL:nil error:&error];
|
||||
NSData *dataDirPathData = [[dataDirPathControl URL] bookmarkDataWithOptions:NSURLBookmarkCreationSecurityScopeAllowOnlyReadAccess includingResourceValuesForKeys:nil relativeToURL:nil error:&error];
|
||||
if (error != nil) {
|
||||
// failed
|
||||
[[NSAlert alertWithError:error] runModal];
|
||||
return;
|
||||
}
|
||||
|
||||
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
|
||||
|
||||
[prefs setValue:configFilePathData forKey:configFilePathPrefKey];
|
||||
[prefs setValue:dataDirPathData forKey:dataDirPathPrefKey];
|
||||
[prefs synchronize];
|
||||
[[CelestiaController shared] setNeedsRelaunch:YES];
|
||||
[NSApp terminate:nil];
|
||||
}
|
||||
|
||||
@end
|
|
@ -14,5 +14,5 @@
|
|||
{
|
||||
IBOutlet NSMenu *scriptMenu;
|
||||
}
|
||||
- (void)buildScriptMenu;
|
||||
- (void)buildScriptMenuWithScriptDir:(NSString *)scriptDir;
|
||||
@end
|
||||
|
|
|
@ -82,39 +82,29 @@
|
|||
return [itemDict count] > 0 ? itemDict : nil;
|
||||
}
|
||||
|
||||
- (void)buildScriptMenu
|
||||
- (void)buildScriptMenuWithScriptDir:(NSString *)scriptDir
|
||||
{
|
||||
NSDictionary *itemDict = nil;
|
||||
NSArray *existingResourceDirsSetting = nil;
|
||||
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
|
||||
BOOL addSeparator = NO;
|
||||
|
||||
int count = [scriptMenu numberOfItems];
|
||||
while (count-- > 0)
|
||||
[scriptMenu removeItemAtIndex: 0];
|
||||
|
||||
if (itemDict = [ScriptsController scriptsForFolderRoot: @""])
|
||||
if ((itemDict = [ScriptsController scriptsForFolderRoot:@""]) != nil)
|
||||
{
|
||||
[self addItems:itemDict toMenu:scriptMenu];
|
||||
addSeparator = YES;
|
||||
}
|
||||
|
||||
if ((existingResourceDirsSetting = [prefs stringArrayForKey:@"existingResourceDirs"]))
|
||||
if ((itemDict = [ScriptsController scriptsForFolderRoot:scriptDir]) != nil)
|
||||
{
|
||||
NSEnumerator *iter = [existingResourceDirsSetting objectEnumerator];
|
||||
NSString *dir = nil;
|
||||
while ((dir = [iter nextObject]))
|
||||
if (addSeparator)
|
||||
{
|
||||
if (itemDict = [ScriptsController scriptsForFolderRoot: dir])
|
||||
{
|
||||
if (addSeparator)
|
||||
{
|
||||
[scriptMenu addItem: [NSMenuItem separatorItem]];
|
||||
addSeparator = NO;
|
||||
}
|
||||
[self addItems:[NSDictionary dictionaryWithObject:itemDict forKey:[dir stringByAbbreviatingWithTildeInPath]] toMenu:scriptMenu];
|
||||
}
|
||||
[scriptMenu addItem: [NSMenuItem separatorItem]];
|
||||
addSeparator = NO;
|
||||
}
|
||||
[self addItems:[NSDictionary dictionaryWithObject:itemDict forKey:[scriptDir stringByAbbreviatingWithTildeInPath]] toMenu:scriptMenu];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,6 +45,8 @@
|
|||
88654A260DB29585007C8027 /* celx_rotation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 88654A130DB29585007C8027 /* celx_rotation.cpp */; };
|
||||
88654A280DB29585007C8027 /* celx_vector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 88654A150DB29585007C8027 /* celx_vector.cpp */; };
|
||||
9708E6A92312A8BB0015C9F4 /* libjpeg.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 9708E6A72312A8B00015C9F4 /* libjpeg.a */; };
|
||||
978EBA922324D0740025C9D5 /* ConfigSelectionWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 978EBA912324D0740025C9D5 /* ConfigSelectionWindow.xib */; };
|
||||
9798FB522324D2BE007F92B8 /* ConfigSelectionWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9798FB502324D2BE007F92B8 /* ConfigSelectionWindowController.m */; };
|
||||
97E4018123101501002013C7 /* cspice.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CE4EEA6D0F50144A003341A2 /* cspice.a */; };
|
||||
97E4018323101501002013C7 /* libpng.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 97E4018223101501002013C7 /* libpng.a */; };
|
||||
97E401852310150F002013C7 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 97E401842310150F002013C7 /* libz.tbd */; };
|
||||
|
@ -536,6 +538,9 @@
|
|||
9708E6A22312A8310015C9F4 /* jconfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = jconfig.h; path = include/jconfig.h; sourceTree = "<group>"; };
|
||||
9708E6A72312A8B00015C9F4 /* libjpeg.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libjpeg.a; path = lib/libjpeg.a; sourceTree = "<group>"; };
|
||||
9726813A231D0D930014C8D7 /* Celestia.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Celestia.entitlements; sourceTree = "<group>"; };
|
||||
978EBA912324D0740025C9D5 /* ConfigSelectionWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ConfigSelectionWindow.xib; sourceTree = "<group>"; };
|
||||
9798FB4F2324D2BE007F92B8 /* ConfigSelectionWindowController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ConfigSelectionWindowController.h; sourceTree = "<group>"; };
|
||||
9798FB502324D2BE007F92B8 /* ConfigSelectionWindowController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ConfigSelectionWindowController.m; sourceTree = "<group>"; };
|
||||
97E4018223101501002013C7 /* libpng.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libpng.a; path = lib/libpng.a; sourceTree = "<group>"; };
|
||||
97E401842310150F002013C7 /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; };
|
||||
97E40188231015AD002013C7 /* liblua5.1.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = liblua5.1.a; path = lib/liblua5.1.a; sourceTree = "<group>"; };
|
||||
|
@ -1089,6 +1094,7 @@
|
|||
E5E365AB095C11B500B14224 /* SplashScreen.m */,
|
||||
E5D956DF096651DF00CB02B2 /* SplashWindowController.m */,
|
||||
E5E2BDD50C24F7E6000D6E83 /* TextWindowController.m */,
|
||||
9798FB502324D2BE007F92B8 /* ConfigSelectionWindowController.m */,
|
||||
F5040B0E02A484DA014901DC /* CelestiaController.h */,
|
||||
F5231C7202C2997601000006 /* CelestiaFavorites.h */,
|
||||
F5274ED202AE88260100020A /* CelestiaOpenGLView.h */,
|
||||
|
@ -1106,6 +1112,7 @@
|
|||
E5E365AA095C11B500B14224 /* SplashScreen.h */,
|
||||
E5D956DE096651DF00CB02B2 /* SplashWindowController.h */,
|
||||
E5E2BDD40C24F7E6000D6E83 /* TextWindowController.h */,
|
||||
9798FB4F2324D2BE007F92B8 /* ConfigSelectionWindowController.h */,
|
||||
F578B79D02B3E2AD0100020A /* Cocoa Extensions */,
|
||||
F55A246702B2D4FF0100020A /* Wrappers */,
|
||||
E5CC203109AA832000CFFF2C /* POConverter */,
|
||||
|
@ -1191,6 +1198,7 @@
|
|||
E50CCA530C065F0100E9C76A /* EclipseFinder.nib */,
|
||||
E5D7660E0982B1860099DBBD /* HelpWindow.nib */,
|
||||
E5E2BDD00C24F7B6000D6E83 /* TextWindow.nib */,
|
||||
978EBA912324D0740025C9D5 /* ConfigSelectionWindow.xib */,
|
||||
089C165CFE840E0CC02AAC07 /* InfoPlist.strings */,
|
||||
E5CC204509AA843300CFFF2C /* Localizable.strings */,
|
||||
);
|
||||
|
@ -1920,6 +1928,7 @@
|
|||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
978EBA922324D0740025C9D5 /* ConfigSelectionWindow.xib in Resources */,
|
||||
E56430BB07769C9000E2C4A3 /* MainMenu.nib in Resources */,
|
||||
E56430BC07769C9000E2C4A3 /* InfoPlist.strings in Resources */,
|
||||
E5B615070777307F001BB2BF /* celestia.icns in Resources */,
|
||||
|
@ -2131,6 +2140,7 @@
|
|||
E532F4F50933331800D7D5B3 /* dsooctree.cpp in Sources */,
|
||||
E532F4F80933331800D7D5B3 /* staroctree.cpp in Sources */,
|
||||
E5E365AD095C11B500B14224 /* SplashScreen.m in Sources */,
|
||||
9798FB522324D2BE007F92B8 /* ConfigSelectionWindowController.m in Sources */,
|
||||
E5D956E00966520700CB02B2 /* SplashWindowController.m in Sources */,
|
||||
E56B96570AAB22AA0097DDFE /* renderglsl.cpp in Sources */,
|
||||
E56457520AF8FD6A00F2D9FA /* samporient.cpp in Sources */,
|
||||
|
|
Loading…
Reference in New Issue