ref: bf8974e63b988ae1b5d2fdb0492dfe0bb3613680
parent: 47f828ea9faf6fbb695fe2b901be466195b2a168
author: Simon Howard <fraggle@gmail.com>
date: Sat Jan 23 18:06:45 EST 2010
Add menu item to launcher to open a terminal window that can be used to start the game. Add missing 'edit' menu. Set svn:ignore property for osx directory. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1824
--- a/pkg/osx/.gitignore
+++ b/pkg/osx/.gitignore
@@ -1,5 +1,7 @@
Info.plist
+Info-gnustep.plist
launcher
*.o
*.d
+*.dmg
staging
--- a/pkg/osx/Execute.h
+++ b/pkg/osx/Execute.h
@@ -25,6 +25,7 @@
void SetProgramLocation(const char *path);
void ExecuteProgram(const char *executable, const char *iwad, const char *args);
+void OpenTerminalWindow(const char *doomwadpath);
#endif /* #ifndef LAUNCHER_EXECUTE_H */
--- a/pkg/osx/Execute.m
+++ b/pkg/osx/Execute.m
@@ -24,10 +24,16 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include <AppKit/AppKit.h>
+
+#include "config.h"
+
#define RESPONSE_FILE "/tmp/launcher.rsp"
+#define TEMP_SCRIPT "/tmp/tempscript.sh"
static char *executable_path;
@@ -107,5 +113,85 @@
{
signal(SIGCHLD, SIG_IGN);
}
+}
+
+// Write a sequence of commands that will display the specified message
+// via shell commands.
+
+static void WriteMessage(FILE *script, char *msg)
+{
+ char *p;
+
+ fprintf(script, "echo \"");
+
+ for (p=msg; *p != '\0'; ++p)
+ {
+ // Start new line?
+
+ if (*p == '\n')
+ {
+ fprintf(script, "\"\necho \"");
+ continue;
+ }
+
+ // Escaped character?
+
+ if (*p == '\\' || *p == '\"')
+ {
+ fprintf(script, "\\");
+ }
+
+ fprintf(script, "%c", *p);
+ }
+
+ fprintf(script, "\"\n");
+}
+
+// Open a terminal window with the PATH set appropriately, and DOOMWADPATH
+// set to the specified value.
+
+void OpenTerminalWindow(const char *doomwadpath)
+{
+ FILE *stream;
+
+ // Generate a shell script that sets the PATH to include the location
+ // where the Doom binaries are, and DOOMWADPATH to include the
+ // IWAD files that have been configured in the launcher interface.
+ // The script then deletes itself and starts a shell.
+
+ stream = fopen(TEMP_SCRIPT, "w");
+
+ fprintf(stream, "#!/bin/sh\n");
+ //fprintf(stream, "set -x\n");
+ fprintf(stream, "PATH=\"%s:$PATH\"\n", executable_path);
+ fprintf(stream, "DOOMWADPATH=\"%s\"\n", doomwadpath);
+ fprintf(stream, "export DOOMWADPATH\n");
+ fprintf(stream, "rm -f \"%s\"\n", TEMP_SCRIPT);
+
+ // Display a useful message:
+
+ fprintf(stream, "clear\n");
+ WriteMessage(stream,
+ "\n"
+ "This command line has the PATH variable configured so that you may\n"
+ "launch the game with whatever parameters you desire.\n"
+ "\n"
+ "For example:\n"
+ "\n"
+ " " PACKAGE_TARNAME " -iwad doom2.wad -file sid.wad -warp 1\n"
+ "\n"
+ "Type 'exit' to exit.\n");
+
+ fprintf(stream, "exec $SHELL\n");
+ fprintf(stream, "\n");
+
+ fclose(stream);
+
+ chmod(TEMP_SCRIPT, 0755);
+
+ // Tell the terminal to open a window to run the script.
+
+ [[NSWorkspace sharedWorkspace] openFile: @TEMP_SCRIPT
+ withApplication: @"Terminal"];
}
--- a/pkg/osx/IWADController.h
+++ b/pkg/osx/IWADController.h
@@ -45,6 +45,7 @@
- (BOOL) setDropdownList;
- (void) setDropdownSelection;
- (void) saveConfig;
+- (char *) doomWadPath;
- (void) setEnvironment;
@end
--- a/pkg/osx/IWADController.m
+++ b/pkg/osx/IWADController.m
@@ -264,10 +264,10 @@
}
}
-// Set the DOOMWADPATH environment variable to contain the path to each
-// of the configured IWAD files.
+// Generate a value to set for the DOOMWADPATH environment variable
+// that contains each of the configured IWAD files.
-- (void) setEnvironment
+- (char *) doomWadPath
{
IWADLocation *iwadList[NUM_IWAD_TYPES];
NSString *location;
@@ -280,7 +280,7 @@
// Calculate length of environment string.
- len = 30;
+ len = 0;
for (i=0; i<NUM_IWAD_TYPES; ++i)
{
@@ -295,7 +295,7 @@
// Build string.
env = malloc(len);
- strcpy(env, "DOOMWADPATH=");
+ strcpy(env, "");
first = YES;
@@ -314,6 +314,27 @@
first = NO;
}
}
+
+ return env;
+}
+
+// Set the DOOMWADPATH environment variable to contain the path to each
+// of the configured IWAD files.
+
+- (void) setEnvironment
+{
+ char *doomwadpath;
+ char *env;
+
+ // Get the value for the path.
+
+ doomwadpath = [self doomWadPath];
+
+ env = malloc(strlen(doomwadpath) + 15);
+
+ sprintf(env, "DOOMWADPATH=%s", doomwadpath);
+
+ free(doomwadpath);
// Load into environment:
--- a/pkg/osx/LauncherManager.h
+++ b/pkg/osx/LauncherManager.h
@@ -43,7 +43,7 @@
- (void) clearCommandLine;
- (void) addFileToCommandLine: (NSString *) fileName
forArgument: (NSString *) args;
-
+- (void) openTerminal: (id) sender;
@end
--- a/pkg/osx/LauncherManager.m
+++ b/pkg/osx/LauncherManager.m
@@ -299,6 +299,8 @@
[NSApp terminate:sender];
}
+// Invoked when the "Setup Tool" button is clicked, to run the setup tool:
+
- (void) runSetup: (id)sender
{
[self saveConfig];
@@ -305,6 +307,22 @@
[self->iwadController setEnvironment];
ExecuteProgram("chocolate-setup", NULL, NULL);
+}
+
+// Invoked when the "Terminal" option is selected from the menu, to open
+// a terminal window.
+
+- (void) openTerminal: (id) sender
+{
+ char *doomwadpath;
+
+ [self saveConfig];
+
+ doomwadpath = [self->iwadController doomWadPath];
+
+ OpenTerminalWindow(doomwadpath);
+
+ free(doomwadpath);
}
- (void) awakeFromNib
--- a/pkg/osx/Resources/launcher.nib/classes.nib
+++ b/pkg/osx/Resources/launcher.nib/classes.nib
@@ -30,7 +30,7 @@
SUPERCLASS = NSObject;
},
{
- ACTIONS = {launch = id; runSetup = id; };
+ ACTIONS = {launch = id; openTerminal = id; runSetup = id; };
CLASS = LauncherManager;
LANGUAGE = ObjC;
OUTLETS = {
--- a/pkg/osx/Resources/launcher.nib/info.nib
+++ b/pkg/osx/Resources/launcher.nib/info.nib
@@ -3,18 +3,18 @@
<plist version="1.0">
<dict>
<key>IBDocumentLocation</key>
- <string>170 140 612 260 0 0 1440 878 </string>
+ <string>484 105 612 260 0 0 1440 878 </string>
<key>IBEditorPositions</key>
<dict>
<key>29</key>
- <string>108 337 163 44 0 0 1440 878 </string>
+ <string>221 322 205 44 0 0 1440 878 </string>
</dict>
<key>IBFramework Version</key>
<string>446.1</string>
<key>IBOpenObjects</key>
<array>
- <integer>21</integer>
<integer>29</integer>
+ <integer>21</integer>
<integer>227</integer>
</array>
<key>IBSystem Version</key>
binary files a/pkg/osx/Resources/launcher.nib/keyedobjects.nib b/pkg/osx/Resources/launcher.nib/keyedobjects.nib differ