1
0
mirror of synced 2025-02-28 06:30:23 +01:00

Merge pull request #43 from Caviar-X/master

Add config path sepcification
This commit is contained in:
Bobby Dilley 2025-01-08 17:12:46 +00:00 committed by GitHub
commit 3bf76eba5f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 39 additions and 8 deletions

View File

@ -1297,7 +1297,7 @@ KeyMapping getDefaultKeymap()
return defaultKeyMapping; return defaultKeyMapping;
} }
int initConfig() int initConfig(const char* configPath)
{ {
config.emulateRideboard = 0; config.emulateRideboard = 0;
config.emulateDriveboard = 0; config.emulateDriveboard = 0;
@ -1348,15 +1348,20 @@ int initConfig()
} }
config.inputMode = 0; // Default to all inputs config.inputMode = 0; // Default to all inputs
char* configFilePath = CONFIG_PATH;
if (configPath != NULL)
strcpy(configFilePath, configPath);
configFile = fopen(CONFIG_PATH, "r"); configFile = fopen(configFilePath, "r");
if (configFile == NULL) if (configFile == NULL)
{ {
printf("Warning: Cannot open %s, using default values.\n", CONFIG_PATH); printf("Warning: Cannot open %s, using default config values.\n", configFilePath);
return 1; return 1;
} }
readConfig(configFile, &config); readConfig(configFile, &config);
fclose(configFile); fclose(configFile);

View File

@ -264,7 +264,7 @@ typedef struct
} EmulatorConfig; } EmulatorConfig;
KeyMapping getDefaultKeymap(); KeyMapping getDefaultKeymap();
int initConfig(); int initConfig(const char* configPath);
EmulatorConfig *getConfig(); EmulatorConfig *getConfig();
char *getGameName(); char *getGameName();
char *getDVPName(); char *getDVPName();

View File

@ -49,7 +49,6 @@
#include "evdevinput.h" #include "evdevinput.h"
#define HOOK_FILE_NAME "/dev/zero" #define HOOK_FILE_NAME "/dev/zero"
#define BASEBOARD 0 #define BASEBOARD 0
#define EEPROM 1 #define EEPROM 1
#define SERIAL0 2 #define SERIAL0 2
@ -171,8 +170,11 @@ void __attribute__((constructor)) hook_init()
act.sa_sigaction = handleSegfault; act.sa_sigaction = handleSegfault;
act.sa_flags = SA_SIGINFO; act.sa_flags = SA_SIGINFO;
sigaction(SIGSEGV, &act, NULL); sigaction(SIGSEGV, &act, NULL);
// use unmodified version of getenv
char *(*_getenv)(const char *name) = dlsym(RTLD_NEXT, "getenv");
char* envPath = _getenv("LINDBERGH_CONFIG_PATH");
initConfig(); initConfig(envPath);
if (getConfig()->fpsLimiter == 1) if (getConfig()->fpsLimiter == 1)
{ {

View File

@ -3,11 +3,13 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdint.h> #include <stdint.h>
#include <limits.h>
#include "evdevinput.h" #include "evdevinput.h"
#include "version.h" #include "version.h"
#define LD_LIBRARY_PATH "LD_LIBRARY_PATH" #define LD_LIBRARY_PATH "LD_LIBRARY_PATH"
#define LINDBERGH_CONFIG_PATH "LINDBERGH_CONFIG_PATH"
#define LD_PRELOAD "LD_PRELOAD" #define LD_PRELOAD "LD_PRELOAD"
#define PRELOAD_FILE_NAME "lindbergh.so" #define PRELOAD_FILE_NAME "lindbergh.so"
#define TEAM "bobbydilley, retrofan, dkeruza-neo, doozer, francesco, rolel, caviar-x" #define TEAM "bobbydilley, retrofan, dkeruza-neo, doozer, francesco, rolel, caviar-x"
@ -118,6 +120,7 @@ void printUsage(char *argv[])
printf(" --list-controllers Lists available controllers and inputs\n"); printf(" --list-controllers Lists available controllers and inputs\n");
printf(" --version Displays the version of the loader and team's names\n"); printf(" --version Displays the version of the loader and team's names\n");
printf(" --help Displays this usage text\n"); printf(" --help Displays this usage text\n");
printf(" --config | -c Specifies configuration path\n");
} }
/** /**
@ -247,8 +250,10 @@ int main(int argc, char *argv[])
int gdb = 0; int gdb = 0;
int forceGame = 0; int forceGame = 0;
int segaboot = 0; int segaboot = 0;
int extConfig = 0;
char envConfigPath[PATH_MAX] = {0};
char forceGamePath[128] = {0}; char forceGamePath[128] = {0};
for (int i = 1; i < argc; i++) for (int i = 1; i < argc; i++)
{ {
if (strcmp(argv[i], "-t") == 0 || strcmp(argv[i], "--test") == 0) if (strcmp(argv[i], "-t") == 0 || strcmp(argv[i], "--test") == 0)
@ -268,12 +273,31 @@ int main(int argc, char *argv[])
gdb = 1; gdb = 1;
continue; continue;
} }
if (strcmp(argv[i], "--config") == 0 || strcmp(argv[i], "-c") == 0)
{
// prevent wild pointer
if (i+1 >= argc)
{
printf("Unable to read config file because it's the end of argument list\n");
break;
}
extConfig = 1;
strcpy(envConfigPath, argv[i+1]);
// skip the next argument
i += 1;
continue;
}
// Treat the argument as the game name // Treat the argument as the game name
strcpy(forceGamePath, argv[i]); strcpy(forceGamePath, argv[i]);
forceGame = 1; forceGame = 1;
} }
if (extConfig)
{
// always override the old environment
setenv(LINDBERGH_CONFIG_PATH, envConfigPath, 1);
}
char command[128] = {0}; char command[128] = {0};
strcpy(command, "./"); strcpy(command, "./");
if (forceGame) if (forceGame)