Launch game or setup program when launch/setup buttons are pressed.

Subversion-branch: /launcher
Subversion-revision: 1762
This commit is contained in:
Simon Howard 2009-12-26 17:38:30 +00:00
parent d74fb3d055
commit 72d11e43eb
7 changed files with 158 additions and 6 deletions

30
Execute.h Normal file
View file

@ -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 */

109
Execute.m Normal file
View file

@ -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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#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);
}
}

View file

@ -20,8 +20,7 @@ chocolate-launcher_RESOURCE_FILES = \
Resources/launcher.gorm \ Resources/launcher.gorm \
Resources/Main.gsmarkup \ Resources/Main.gsmarkup \
Resources/MainMenu-GNUstep.gsmarkup \ Resources/MainMenu-GNUstep.gsmarkup \
Resources/MainMenu-OSX.gsmarkup \ Resources/MainMenu-OSX.gsmarkup
Resources/48x48.png
# #
@ -29,6 +28,7 @@ Resources/48x48.png
# #
chocolate-launcher_HEADER_FILES = \ chocolate-launcher_HEADER_FILES = \
AppController.h \ AppController.h \
Execute.h \
IWADController.h \ IWADController.h \
IWADLocation.h \ IWADLocation.h \
LauncherManager.h LauncherManager.h
@ -38,6 +38,7 @@ LauncherManager.h
# #
chocolate-launcher_OBJC_FILES = \ chocolate-launcher_OBJC_FILES = \
AppController.m \ AppController.m \
Execute.m \
IWADController.m \ IWADController.m \
IWADLocation.m \ IWADLocation.m \
LauncherManager.m LauncherManager.m

View file

@ -21,6 +21,7 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#include <AppKit/AppKit.h> #include <AppKit/AppKit.h>
#include "Execute.h"
#include "LauncherManager.h" #include "LauncherManager.h"
#include "config.h" #include "config.h"
@ -72,13 +73,17 @@
if (iwad != nil) 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 - (void) runSetup: (id)sender
{ {
[self saveConfig]; [self saveConfig];
ExecuteProgram("chocolate-setup", NULL, NULL);
} }
- (void) awakeFromNib - (void) awakeFromNib

View file

@ -1,11 +1,12 @@
{ {
APPLICATIONICON = "48x48.png"; APPLICATIONICON = 48x48.png;
APP_DOCUMENT_BASED = NO; APP_DOCUMENT_BASED = NO;
APP_TYPE = GORM; APP_TYPE = GORM;
BUILDER_ARGS = ( BUILDER_ARGS = (
); );
CLASS_FILES = ( CLASS_FILES = (
AppController.m, AppController.m,
Execute.m,
IWADController.m, IWADController.m,
IWADLocation.m, IWADLocation.m,
LauncherManager.m LauncherManager.m
@ -19,6 +20,7 @@
); );
HEADER_FILES = ( HEADER_FILES = (
AppController.h, AppController.h,
Execute.h,
IWADController.h, IWADController.h,
IWADLocation.h, IWADLocation.h,
LauncherManager.h LauncherManager.h
@ -33,7 +35,7 @@
"MainMenu-OSX.gsmarkup" "MainMenu-OSX.gsmarkup"
); );
LANGUAGE = English; LANGUAGE = English;
LAST_EDITING = "2009-12-25 00:36:37 +0000"; LAST_EDITING = "2009-12-26 02:46:42 +0000";
LIBRARIES = ( LIBRARIES = (
"gnustep-base", "gnustep-base",
"gnustep-gui" "gnustep-gui"

View file

@ -1,11 +1,13 @@
{ {
ApplicationDescription = "No description avaliable!"; ApplicationDescription = "No description avaliable!";
ApplicationIcon = 48x48.png;
ApplicationName = "chocolate-launcher"; ApplicationName = "chocolate-launcher";
ApplicationRelease = 0.1; ApplicationRelease = 0.1;
Copyright = "Copyright (C) 200x"; Copyright = "Copyright (C) 2009";
CopyrightDescription = "Released under ..."; CopyrightDescription = "Released under ...";
FullVersionID = 0.1; FullVersionID = 0.1;
NSExecutable = "chocolate-launcher"; NSExecutable = "chocolate-launcher";
NSIcon = 48x48.png;
NSMainNibFile = launcher.gorm; NSMainNibFile = launcher.gorm;
NSPrincipalClass = NSApplication; NSPrincipalClass = NSApplication;
NSRole = Application; NSRole = Application;

3
main.m
View file

@ -21,9 +21,12 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#include <AppKit/AppKit.h> #include <AppKit/AppKit.h>
#include "Execute.h"
int main(int argc, const char *argv[]) int main(int argc, const char *argv[])
{ {
SetProgramLocation(argv[0]);
return NSApplicationMain (argc, argv); return NSApplicationMain (argc, argv);
} }