From bf8974e63b988ae1b5d2fdb0492dfe0bb3613680 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sat, 23 Jan 2010 23:06:45 +0000 Subject: 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 --- pkg/osx/.gitignore | 2 + pkg/osx/Execute.h | 1 + pkg/osx/Execute.m | 86 ++++++++++++++++++++++++ pkg/osx/IWADController.h | 1 + pkg/osx/IWADController.m | 31 +++++++-- pkg/osx/LauncherManager.h | 2 +- pkg/osx/LauncherManager.m | 18 +++++ pkg/osx/Resources/launcher.nib/classes.nib | 2 +- pkg/osx/Resources/launcher.nib/info.nib | 6 +- pkg/osx/Resources/launcher.nib/keyedobjects.nib | Bin 17541 -> 19494 bytes 10 files changed, 139 insertions(+), 10 deletions(-) (limited to 'pkg/osx') diff --git a/pkg/osx/.gitignore b/pkg/osx/.gitignore index 5b7a16ef..ca1a7908 100644 --- a/pkg/osx/.gitignore +++ b/pkg/osx/.gitignore @@ -1,5 +1,7 @@ Info.plist +Info-gnustep.plist launcher *.o *.d +*.dmg staging diff --git a/pkg/osx/Execute.h b/pkg/osx/Execute.h index e92d3a11..2098be8a 100644 --- 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 */ diff --git a/pkg/osx/Execute.m b/pkg/osx/Execute.m index 1afcab1f..bb4eed45 100644 --- a/pkg/osx/Execute.m +++ b/pkg/osx/Execute.m @@ -24,10 +24,16 @@ #include #include #include +#include #include #include +#include + +#include "config.h" + #define RESPONSE_FILE "/tmp/launcher.rsp" +#define TEMP_SCRIPT "/tmp/tempscript.sh" static char *executable_path; @@ -109,3 +115,83 @@ void ExecuteProgram(const char *executable, const char *iwad, const char *args) } } +// 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"]; +} + diff --git a/pkg/osx/IWADController.h b/pkg/osx/IWADController.h index 8bdd0d55..90f44667 100644 --- 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 diff --git a/pkg/osx/IWADController.m b/pkg/osx/IWADController.m index a7730cc7..3c596850 100644 --- a/pkg/osx/IWADController.m +++ b/pkg/osx/IWADController.m @@ -264,10 +264,10 @@ static NSString *IWADFilenames[NUM_IWAD_TYPES + 1] = } } -// 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 @@ static NSString *IWADFilenames[NUM_IWAD_TYPES + 1] = // Calculate length of environment string. - len = 30; + len = 0; for (i=0; iiwadController doomWadPath]; + + OpenTerminalWindow(doomwadpath); + + free(doomwadpath); +} + - (void) awakeFromNib { [self->packageLabel setStringValue: @PACKAGE_STRING]; diff --git a/pkg/osx/Resources/launcher.nib/classes.nib b/pkg/osx/Resources/launcher.nib/classes.nib index 3ff47e71..236f6b67 100644 --- 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 = { diff --git a/pkg/osx/Resources/launcher.nib/info.nib b/pkg/osx/Resources/launcher.nib/info.nib index aecf812a..32b331f5 100644 --- a/pkg/osx/Resources/launcher.nib/info.nib +++ b/pkg/osx/Resources/launcher.nib/info.nib @@ -3,18 +3,18 @@ IBDocumentLocation - 170 140 612 260 0 0 1440 878 + 484 105 612 260 0 0 1440 878 IBEditorPositions 29 - 108 337 163 44 0 0 1440 878 + 221 322 205 44 0 0 1440 878 IBFramework Version 446.1 IBOpenObjects - 21 29 + 21 227 IBSystem Version diff --git a/pkg/osx/Resources/launcher.nib/keyedobjects.nib b/pkg/osx/Resources/launcher.nib/keyedobjects.nib index 12cf6aa5..4f078d7c 100644 Binary files a/pkg/osx/Resources/launcher.nib/keyedobjects.nib and b/pkg/osx/Resources/launcher.nib/keyedobjects.nib differ -- cgit v1.2.3