diff --git a/Execute.h b/Execute.h new file mode 100644 index 0000000..e92d3a1 --- /dev/null +++ b/Execute.h @@ -0,0 +1,30 @@ +/* ... */ +//----------------------------------------------------------------------------- +// +// Copyright(C) 2009 Simon Howard +// +// This program 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 2 +// of the License, or (at your option) any later version. +// +// This program 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 this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +// 02111-1307, USA. +// +//----------------------------------------------------------------------------- + +#ifndef LAUNCHER_EXECUTE_H +#define LAUNCHER_EXECUTE_H + +void SetProgramLocation(const char *path); +void ExecuteProgram(const char *executable, const char *iwad, const char *args); + +#endif /* #ifndef LAUNCHER_EXECUTE_H */ + diff --git a/Execute.m b/Execute.m new file mode 100644 index 0000000..4d44c1c --- /dev/null +++ b/Execute.m @@ -0,0 +1,109 @@ +/* ... */ +//----------------------------------------------------------------------------- +// +// Copyright(C) 2009 Simon Howard +// +// This program 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 2 +// of the License, or (at your option) any later version. +// +// This program 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 this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +// 02111-1307, USA. +// +//----------------------------------------------------------------------------- + +#include +#include +#include +#include +#include +#include + +#define RESPONSE_FILE "/tmp/launcher.rsp" + +static char *executable_path; + +// Called on startup to save the location of the launcher program +// (within a package, other executables should be in the same directory) + +void SetProgramLocation(const char *path) +{ + char *p; + + executable_path = strdup(path); + + p = strrchr(executable_path, '/'); + *p = '\0'; +} + +// Write out the response file containing command line arguments. + +static void WriteResponseFile(const char *iwad, const char *args) +{ + FILE *fstream; + + fstream = fopen(RESPONSE_FILE, "w"); + + if (iwad != NULL) + { + fprintf(fstream, "-iwad \"%s\"", iwad); + } + + if (args != NULL) + { + fprintf(fstream, "%s", args); + } + + fclose(fstream); +} + +static void DoExec(const char *executable, const char *iwad, const char *args) +{ + char *argv[3]; + + argv[0] = malloc(strlen(executable_path) + strlen(executable) + 3); + sprintf(argv[0], "%s/%s", executable_path, executable); + + if (iwad != NULL || args != NULL) + { + WriteResponseFile(iwad, args); + + argv[1] = "@" RESPONSE_FILE; + argv[2] = NULL; + } + else + { + argv[1] = NULL; + } + + execv(argv[0], argv); + exit(-1); +} + +// Execute the specified executable contained in the same directory +// as the launcher, with the specified arguments. + +void ExecuteProgram(const char *executable, const char *iwad, const char *args) +{ + pid_t childpid; + + childpid = fork(); + + if (childpid == 0) + { + DoExec(executable, iwad, args); + } + else + { + signal(SIGCHLD, SIG_IGN); + } +} + diff --git a/GNUmakefile b/GNUmakefile index e5a8cd6..aa5bd87 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -20,8 +20,7 @@ chocolate-launcher_RESOURCE_FILES = \ Resources/launcher.gorm \ Resources/Main.gsmarkup \ Resources/MainMenu-GNUstep.gsmarkup \ -Resources/MainMenu-OSX.gsmarkup \ -Resources/48x48.png +Resources/MainMenu-OSX.gsmarkup # @@ -29,6 +28,7 @@ Resources/48x48.png # chocolate-launcher_HEADER_FILES = \ AppController.h \ +Execute.h \ IWADController.h \ IWADLocation.h \ LauncherManager.h @@ -38,6 +38,7 @@ LauncherManager.h # chocolate-launcher_OBJC_FILES = \ AppController.m \ +Execute.m \ IWADController.m \ IWADLocation.m \ LauncherManager.m diff --git a/LauncherManager.m b/LauncherManager.m index 3f112f1..f2b5734 100644 --- a/LauncherManager.m +++ b/LauncherManager.m @@ -21,6 +21,7 @@ //----------------------------------------------------------------------------- #include +#include "Execute.h" #include "LauncherManager.h" #include "config.h" @@ -72,13 +73,17 @@ if (iwad != nil) { - printf("Command line: %s %s\n", [iwad UTF8String], [args UTF8String]); + ExecuteProgram(PACKAGE_TARNAME, [iwad UTF8String], + [args UTF8String]); + [NSApp terminate:sender]; } } - (void) runSetup: (id)sender { [self saveConfig]; + + ExecuteProgram("chocolate-setup", NULL, NULL); } - (void) awakeFromNib diff --git a/PC.project b/PC.project index f388fe2..58afb31 100644 --- a/PC.project +++ b/PC.project @@ -1,11 +1,12 @@ { - APPLICATIONICON = "48x48.png"; + APPLICATIONICON = 48x48.png; APP_DOCUMENT_BASED = NO; APP_TYPE = GORM; BUILDER_ARGS = ( ); CLASS_FILES = ( AppController.m, + Execute.m, IWADController.m, IWADLocation.m, LauncherManager.m @@ -19,6 +20,7 @@ ); HEADER_FILES = ( AppController.h, + Execute.h, IWADController.h, IWADLocation.h, LauncherManager.h @@ -33,7 +35,7 @@ "MainMenu-OSX.gsmarkup" ); LANGUAGE = English; - LAST_EDITING = "2009-12-25 00:36:37 +0000"; + LAST_EDITING = "2009-12-26 02:46:42 +0000"; LIBRARIES = ( "gnustep-base", "gnustep-gui" diff --git a/chocolate-launcherInfo.plist b/chocolate-launcherInfo.plist index 95d3ff6..4c4ce90 100644 --- a/chocolate-launcherInfo.plist +++ b/chocolate-launcherInfo.plist @@ -1,11 +1,13 @@ { ApplicationDescription = "No description avaliable!"; + ApplicationIcon = 48x48.png; ApplicationName = "chocolate-launcher"; ApplicationRelease = 0.1; - Copyright = "Copyright (C) 200x"; + Copyright = "Copyright (C) 2009"; CopyrightDescription = "Released under ..."; FullVersionID = 0.1; NSExecutable = "chocolate-launcher"; + NSIcon = 48x48.png; NSMainNibFile = launcher.gorm; NSPrincipalClass = NSApplication; NSRole = Application; diff --git a/main.m b/main.m index 3d4707f..e3c70dc 100644 --- a/main.m +++ b/main.m @@ -21,9 +21,12 @@ //----------------------------------------------------------------------------- #include +#include "Execute.h" int main(int argc, const char *argv[]) { + SetProgramLocation(argv[0]); + return NSApplicationMain (argc, argv); }