ref: 160ff32f2fb8ba7112938790044684c61a0b07b1
parent: 550b95f79cf8022acc5b335f6ef948b32cd2c615
author: Simon Howard <[email protected]>
date: Mon Jan 11 14:10:42 EST 2010
Insert new files into the command line at the correct location, allowing multiple files to be opened at once. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1803
--- a/pkg/osx/AppController.h
+++ b/pkg/osx/AppController.h
@@ -30,6 +30,7 @@
@interface AppController : NSObject
{
LauncherManager *launcherManager;
+ BOOL filesAdded;
}
+ (void)initialize;
--- a/pkg/osx/AppController.m
+++ b/pkg/osx/AppController.m
@@ -46,6 +46,8 @@
{
}
+ self->filesAdded = NO;
+
return self;
}
@@ -79,6 +81,17 @@
{
NSString *extension;
+ // If this is the first file added, clear out the existing
+ // command line. This allows us to select multiple files
+ // in the finder and open them all together (for TCs, etc).
+
+ if (!self->filesAdded)
+ {
+ [self->launcherManager clearCommandLine];
+ }
+
+ // Add file with appropriate command line option based on extension:
+
extension = [fileName pathExtension];
if (![extension caseInsensitiveCompare: @"wad"])
@@ -95,6 +108,8 @@
{
return NO;
}
+
+ self->filesAdded = YES;
return YES;
}
--- a/pkg/osx/LauncherManager.h
+++ b/pkg/osx/LauncherManager.h
@@ -40,6 +40,7 @@
- (void) launch: (id)sender;
- (void) runSetup: (id)sender;
- (void) awakeFromNib;
+- (void) clearCommandLine;
- (void) addFileToCommandLine: (NSString *) fileName
forArgument: (NSString *) args;
--- a/pkg/osx/LauncherManager.m
+++ b/pkg/osx/LauncherManager.m
@@ -79,6 +79,7 @@
if (*pos >= [commandLine length])
{
+ *arg_pos = *pos;
return nil;
}
@@ -193,6 +194,42 @@
return arg_pos;
}
+// Given the specified string, append a filename, quoted if necessary.
+
+static NSString *AppendQuotedFilename(NSString *str, NSString *fileName)
+{
+ int i;
+
+ // Search the filename for spaces, and quote if necessary.
+
+ for (i=0; i<[fileName length]; ++i)
+ {
+ if (isspace([fileName characterAtIndex: i]))
+ {
+ str = [str stringByAppendingString: @" \""];
+ str = [str stringByAppendingString: fileName];
+ str = [str stringByAppendingString: @"\" "];
+
+ return str;
+ }
+ }
+
+ str = [str stringByAppendingString: @" "];
+ str = [str stringByAppendingString: fileName];
+
+ return str;
+}
+
+// Clear out the existing command line options.
+// Invoked before the first file is added.
+
+- (void) clearCommandLine
+{
+ [self->commandLineArguments setStringValue: @""];
+}
+
+// Add a file to the command line to load with the game.
+
- (void) addFileToCommandLine: (NSString *) fileName
forArgument: (NSString *) arg
{
@@ -215,10 +252,7 @@
{
commandLine = [commandLine stringByAppendingString: @" "];
commandLine = [commandLine stringByAppendingString: arg];
-
- commandLine = [commandLine stringByAppendingString: @" \""];
- commandLine = [commandLine stringByAppendingString: fileName];
- commandLine = [commandLine stringByAppendingString: @"\""];
+ commandLine = AppendQuotedFilename(commandLine, fileName);
}
else
{
@@ -232,9 +266,8 @@
// Construct new command line:
- commandLine = [start stringByAppendingString: @" \""];
- commandLine = [commandLine stringByAppendingString: fileName];
- commandLine = [commandLine stringByAppendingString: @"\" "];
+ commandLine = AppendQuotedFilename(start, fileName);
+ commandLine = [commandLine stringByAppendingString: @" "];
commandLine = [commandLine stringByAppendingString: end];
}