Read/Write settings.ini; use this to select the game to start.
This commit is contained in:
@@ -18,9 +18,13 @@
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
|
||||
@class Settings;
|
||||
@interface Controller : NSObject {
|
||||
// Main Window
|
||||
NSDictionary *modButtonMappings;
|
||||
Settings *settings;
|
||||
|
||||
// Package Downloader
|
||||
NSString *localDownloadPath;
|
||||
NSString *packageDirectory;
|
||||
NSURLDownload *currentDownload;
|
||||
|
||||
@@ -17,12 +17,28 @@
|
||||
*/
|
||||
|
||||
#import "Controller.h"
|
||||
|
||||
#import "Settings.h"
|
||||
|
||||
@implementation Controller
|
||||
|
||||
- (void)awakeFromNib
|
||||
{
|
||||
NSURL *settingsFile = [NSURL fileURLWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"launcher.ini"]];
|
||||
settings = [[Settings alloc] init];
|
||||
|
||||
[settings loadSettingsFile:settingsFile];
|
||||
|
||||
modButtonMappings = [[NSDictionary dictionaryWithObjectsAndKeys:
|
||||
@"cnc",@"C&C",
|
||||
@"ra",@"Red Alert",
|
||||
nil] retain];
|
||||
}
|
||||
|
||||
-(IBAction)launchApp:(id)sender
|
||||
{
|
||||
[settings setValue:[modButtonMappings objectForKey:[sender title]] forSetting:@"InitialMods"];
|
||||
[settings save];
|
||||
|
||||
[[NSWorkspace sharedWorkspace] launchApplication:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"OpenRA.app"]];
|
||||
[NSApp terminate: nil];
|
||||
}
|
||||
@@ -140,4 +156,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[modButtonMappings release];
|
||||
[settings release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
</object>
|
||||
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<integer value="569"/>
|
||||
<integer value="29"/>
|
||||
<integer value="569"/>
|
||||
<integer value="372"/>
|
||||
</object>
|
||||
<object class="NSArray" key="IBDocument.PluginDependencies">
|
||||
@@ -925,6 +925,7 @@
|
||||
<reference ref="926167763"/>
|
||||
</object>
|
||||
<reference key="parent" ref="439893737"/>
|
||||
<string key="objectName">cnc</string>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">534</int>
|
||||
@@ -944,6 +945,7 @@
|
||||
<reference ref="1057175677"/>
|
||||
</object>
|
||||
<reference key="parent" ref="439893737"/>
|
||||
<string key="objectName">ra</string>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">549</int>
|
||||
@@ -1215,7 +1217,7 @@
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<integer value="1"/>
|
||||
<string>{{525, 802}, {197, 73}}</string>
|
||||
<string>{{226, 941}, {221, 20}}</string>
|
||||
<string>{{226, 836}, {221, 20}}</string>
|
||||
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
|
||||
<integer value="1"/>
|
||||
<string>{74, 862}</string>
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; };
|
||||
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
|
||||
DA1241101151F194002EFE2B /* OpenRa.icns in Resources */ = {isa = PBXBuildFile; fileRef = DA12410F1151F194002EFE2B /* OpenRa.icns */; };
|
||||
DAAB5C7911536D6500DCCB80 /* Settings.m in Sources */ = {isa = PBXBuildFile; fileRef = DAAB5C7811536D6500DCCB80 /* Settings.m */; };
|
||||
DAFD657B11520799001F4C97 /* launcher.ini in Resources */ = {isa = PBXBuildFile; fileRef = DAFD657A11520799001F4C97 /* launcher.ini */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
@@ -30,6 +31,8 @@
|
||||
8D1107310486CEB800E47090 /* OpenRA-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "OpenRA-Info.plist"; sourceTree = "<group>"; };
|
||||
8D1107320486CEB800E47090 /* OpenRA.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = OpenRA.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
DA12410F1151F194002EFE2B /* OpenRa.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = OpenRa.icns; sourceTree = "<group>"; };
|
||||
DAAB5C7711536D6500DCCB80 /* Settings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Settings.h; sourceTree = "<group>"; };
|
||||
DAAB5C7811536D6500DCCB80 /* Settings.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Settings.m; sourceTree = "<group>"; };
|
||||
DAFD657A11520799001F4C97 /* launcher.ini */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = launcher.ini; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
@@ -50,6 +53,8 @@
|
||||
children = (
|
||||
8990E7AD1151C0F20089C198 /* Controller.h */,
|
||||
8990E7AE1151C0F20089C198 /* Controller.m */,
|
||||
DAAB5C7711536D6500DCCB80 /* Settings.h */,
|
||||
DAAB5C7811536D6500DCCB80 /* Settings.m */,
|
||||
);
|
||||
name = Classes;
|
||||
sourceTree = "<group>";
|
||||
@@ -200,6 +205,7 @@
|
||||
files = (
|
||||
8D11072D0486CEB800E47090 /* main.m in Sources */,
|
||||
8990E7AF1151C0F20089C198 /* Controller.m in Sources */,
|
||||
DAAB5C7911536D6500DCCB80 /* Settings.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
||||
33
packaging/osx/launcher/Settings.h
Normal file
33
packaging/osx/launcher/Settings.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
||||
* This file is part of OpenRA.
|
||||
*
|
||||
* OpenRA is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* OpenRA is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
|
||||
@interface Settings : NSObject {
|
||||
NSMutableDictionary *settings;
|
||||
NSURL *filePath;
|
||||
}
|
||||
|
||||
|
||||
- (NSString *)valueForSetting:(NSString *)key;
|
||||
- (void)setValue:(NSString *)value forSetting:(NSString *)key;
|
||||
- (void)loadSettingsFile:(NSURL *)filePath;
|
||||
- (void)save;
|
||||
- (void)saveToFile:(NSURL *)filePath;
|
||||
@end
|
||||
92
packaging/osx/launcher/Settings.m
Normal file
92
packaging/osx/launcher/Settings.m
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
||||
* This file is part of OpenRA.
|
||||
*
|
||||
* OpenRA is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* OpenRA is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#import "Settings.h"
|
||||
|
||||
|
||||
@implementation Settings
|
||||
|
||||
- (id)init
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil)
|
||||
{
|
||||
settings = [[NSMutableDictionary alloc] init];
|
||||
filePath = nil;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSString *)valueForSetting:(NSString *)key
|
||||
{
|
||||
return [settings valueForKey:key];
|
||||
}
|
||||
|
||||
- (void)setValue:(NSString *)value forSetting:(NSString *)key
|
||||
{
|
||||
[settings setValue:value forKey:key];
|
||||
}
|
||||
|
||||
- (void)loadSettingsFile:(NSURL *)file
|
||||
{
|
||||
[filePath autorelease];
|
||||
filePath = file;
|
||||
[filePath retain];
|
||||
|
||||
NSError *error;
|
||||
NSString *data = [NSString stringWithContentsOfURL:filePath encoding:NSUTF8StringEncoding error:&error];
|
||||
NSArray *lines = [data componentsSeparatedByString:@"\n"];
|
||||
|
||||
for (id line in lines)
|
||||
{
|
||||
NSArray *cmp = [line componentsSeparatedByString:@"="];
|
||||
if ([cmp count] != 2)
|
||||
continue;
|
||||
|
||||
NSString *key = [[cmp objectAtIndex:0] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
|
||||
NSString *value = [[cmp objectAtIndex:1] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
|
||||
|
||||
[settings setObject:value forKey:key];
|
||||
}
|
||||
NSLog(@"Loaded settings: %@",settings);
|
||||
}
|
||||
|
||||
- (void)save
|
||||
{
|
||||
[self saveToFile:filePath];
|
||||
}
|
||||
|
||||
- (void)saveToFile:(NSURL *)file
|
||||
{
|
||||
NSMutableString *data = [NSMutableString stringWithString:@"[Settings]\n"];
|
||||
for (id key in settings)
|
||||
{
|
||||
[data appendFormat:@"%@=%@\n",key, [settings valueForKey:key]];
|
||||
}
|
||||
NSError *error;
|
||||
[data writeToURL:file atomically:YES encoding:NSUTF8StringEncoding error:&error];
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[settings release]; settings = nil;
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user