shithub: choc

Download patch

ref: 351c1be33154d12b55e658cfb8f3101858fba63c
parent: 6e9294e05572d46d3897744d78f4604b412ceb65
author: Simon Howard <[email protected]>
date: Sun May 8 14:29:46 EDT 2011

Allow IWAD files to be double-clicked in the finder to set the IWAD
configuration.

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 2334

--- a/pkg/osx/AppController.m
+++ b/pkg/osx/AppController.m
@@ -83,6 +83,14 @@
 {
     NSString *extension;
 
+    // This may be an IWAD.  If so, add it to the IWAD configuration;
+    // don't add it like a PWAD.
+
+    if ([self->launcherManager addIWADPath: fileName])
+    {
+        return YES;
+    }
+
     // 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).
--- a/pkg/osx/IWADController.h
+++ b/pkg/osx/IWADController.h
@@ -47,6 +47,7 @@
 - (void) saveConfig;
 - (char *) doomWadPath;
 - (void) setEnvironment;
+- (BOOL) addIWADPath: (NSString *) path;
 
 @end
 
--- a/pkg/osx/IWADController.m
+++ b/pkg/osx/IWADController.m
@@ -343,5 +343,44 @@
     //free(env);
 }
 
+// Examine a path to a WAD and determine whether it is an IWAD file.
+// If so, it is added to the IWAD configuration, and true is returned.
+
+- (BOOL) addIWADPath: (NSString *) path
+{
+    IWADLocation *iwadList[NUM_IWAD_TYPES];
+    NSArray *pathComponents;
+    NSString *filename;
+    unsigned int i;
+
+    [self getIWADList: iwadList];
+
+    // Find an IWAD file that matches the filename in the path that we
+    // have been given.
+
+    pathComponents = [path pathComponents];
+    filename = [pathComponents objectAtIndex: [pathComponents count] - 1];
+
+    for (i = 0; i < NUM_IWAD_TYPES; ++i)
+    {
+        if ([filename caseInsensitiveCompare: IWADFilenames[i]] == 0)
+        {
+            // Configure this IWAD.
+
+            [iwadList[i] setLocation: path];
+
+            // Rebuild dropdown list and select the new IWAD.
+
+            [self setDropdownList];
+            [self->iwadSelector selectItemWithTitle:IWADLabels[i]];
+            return YES;
+        }
+    }
+
+    // No IWAD found with this name.
+
+    return NO;
+}
+
 @end
 
--- a/pkg/osx/LauncherManager.h
+++ b/pkg/osx/LauncherManager.h
@@ -41,6 +41,7 @@
 - (void) runSetup: (id)sender;
 - (void) awakeFromNib;
 - (void) clearCommandLine;
+- (BOOL) addIWADPath: (NSString *) path;
 - (void) addFileToCommandLine: (NSString *) fileName
          forArgument: (NSString *) args;
 - (void) openTerminal: (id) sender;
--- a/pkg/osx/LauncherManager.m
+++ b/pkg/osx/LauncherManager.m
@@ -358,5 +358,10 @@
     [self setConfig];
 }
 
+- (BOOL) addIWADPath: (NSString *) path
+{
+    return [self->iwadController addIWADPath: path];
+}
+
 @end