mirror of
https://github.com/chocolate-doom/launcher.git
synced 2024-11-21 12:10:59 +00:00
Launch game or setup program when launch/setup buttons are pressed.
Subversion-branch: /launcher Subversion-revision: 1762
This commit is contained in:
parent
d74fb3d055
commit
72d11e43eb
7 changed files with 158 additions and 6 deletions
30
Execute.h
Normal file
30
Execute.h
Normal 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
109
Execute.m
Normal 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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include <AppKit/AppKit.h>
|
||||
#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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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;
|
||||
|
|
3
main.m
3
main.m
|
@ -21,9 +21,12 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include <AppKit/AppKit.h>
|
||||
#include "Execute.h"
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
SetProgramLocation(argv[0]);
|
||||
|
||||
return NSApplicationMain (argc, argv);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue