(OSX) Add command line support; only arguments passed after an -- argument are passed to retroarch (eg retroarch -- /path/to/game)

This commit is contained in:
meancoot 2013-08-27 12:07:59 -04:00
parent 6372e755c4
commit 851a56195a
3 changed files with 49 additions and 20 deletions

View File

@ -85,7 +85,7 @@
apple_display_alert(@"No libretro cores were found.\nSelect \"Go->Cores Directory\" from the menu and place libretro dylib files there.", @"RetroArch");
// Run RGUI if needed
if (!_wantReload)
if (!_wantReload || apple_argv)
apple_run_core(nil, 0);
else
[self chooseCore];
@ -270,6 +270,23 @@
int main(int argc, char *argv[])
{
uint32_t current_argc = 0;
for (int i = 0; i != argc; i ++)
{
if (strcmp(argv[i], "--") == 0)
{
current_argc = 1;
apple_argv = malloc(sizeof(char*) * (argc + 1));
memset(apple_argv, 0, sizeof(char*) * (argc + 1));
apple_argv[0] = argv[0];
}
else if (current_argc)
{
apple_argv[current_argc ++] = argv[i];
}
}
return NSApplicationMain(argc, (const char **) argv);
}

View File

@ -38,6 +38,7 @@
#import "../OSX/platform.h"
#endif
extern char** apple_argv;
extern bool apple_is_paused;
extern bool apple_is_running;
extern bool apple_use_tv_mode;

View File

@ -23,6 +23,8 @@
#include "file.h"
char** apple_argv;
//#define HAVE_DEBUG_FILELOG
id<RetroArch_Platform> apple_platform;
@ -125,37 +127,46 @@ void apple_run_core(RAModuleInfo* core, const char* file)
apple_core = core;
apple_is_running = true;
static char config_path[PATH_MAX];
static char core_path[PATH_MAX];
static char file_path[PATH_MAX];
static const char* argv[] = { "retroarch", "-c", config_path, "-L", core_path, file_path, 0 };
if (apple_core)
strlcpy(config_path, apple_core.configPath.UTF8String, sizeof(config_path));
else
strlcpy(config_path, RAModuleInfo.globalConfigPath.UTF8String, sizeof(config_path));
if (!apple_argv)
{
static const char* argv[] = { "retroarch", "-c", config_path, "-L", core_path, file_path, 0 };
if (apple_core)
strlcpy(config_path, apple_core.configPath.UTF8String, sizeof(config_path));
else
strlcpy(config_path, RAModuleInfo.globalConfigPath.UTF8String, sizeof(config_path));
if (file && core)
{
argv[3] = "-L";
argv[4] = core_path;
strlcpy(core_path, apple_core.path.UTF8String, sizeof(core_path));
strlcpy(file_path, file, sizeof(file_path));
}
else
{
argv[3] = "--menu";
argv[4] = 0;
if (file && core)
{
argv[3] = "-L";
argv[4] = core_path;
strlcpy(core_path, apple_core.path.UTF8String, sizeof(core_path));
strlcpy(file_path, file, sizeof(file_path));
}
else
{
argv[3] = "--menu";
argv[4] = 0;
}
apple_argv = (char**)argv;
}
if (pthread_create(&apple_retro_thread, 0, rarch_main_spring, argv))
if (pthread_create(&apple_retro_thread, 0, rarch_main_spring, apple_argv))
{
apple_argv = 0;
apple_rarch_exited((void*)1);
return;
}
apple_argv = 0;
pthread_detach(apple_retro_thread);
}
}