mirror of
https://github.com/libretro/ppsspp.git
synced 2024-12-12 10:56:45 +00:00
Add command-line argument to allow a path to be specified for configuration files and control mapping files. Also fix a possible crash when loading ini files.
This commit is contained in:
parent
bcf3d534b0
commit
5cdfb6c4f9
@ -36,14 +36,16 @@ Config::~Config() { }
|
||||
|
||||
void Config::Load(const char *iniFileName, const char *controllerIniFilename)
|
||||
{
|
||||
iniFilename_ = iniFileName;
|
||||
controllerIniFilename_ = controllerIniFilename;
|
||||
INFO_LOG(LOADER, "Loading config: %s", iniFileName);
|
||||
iniFilename_ = iniFileName != NULL ? iniFileName : "ppsspp.ini";
|
||||
|
||||
controllerIniFilename_ = controllerIniFilename != NULL ? controllerIniFilename : "controls.ini";
|
||||
|
||||
INFO_LOG(LOADER, "Loading config: %s", iniFilename_);
|
||||
bSaveSettings = true;
|
||||
|
||||
IniFile iniFile;
|
||||
if (!iniFile.Load(iniFileName)) {
|
||||
ERROR_LOG(LOADER, "Failed to read %s. Setting config to default.", iniFileName);
|
||||
if (!iniFile.Load(iniFilename_)) {
|
||||
ERROR_LOG(LOADER, "Failed to read %s. Setting config to default.", iniFilename_);
|
||||
// Continue anyway to initialize the config.
|
||||
}
|
||||
|
||||
@ -229,12 +231,12 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename)
|
||||
IniFile::Section *gleshacks = iniFile.GetOrCreateSection("GLESHacks");
|
||||
gleshacks->Get("PrescaleUV", &bPrescaleUV, false);
|
||||
|
||||
INFO_LOG(LOADER, "Loading controller config: %s", controllerIniFilename);
|
||||
INFO_LOG(LOADER, "Loading controller config: %s", controllerIniFilename_);
|
||||
bSaveSettings = true;
|
||||
|
||||
IniFile controllerIniFile;
|
||||
if (!controllerIniFile.Load(controllerIniFilename)) {
|
||||
ERROR_LOG(LOADER, "Failed to read %s. Setting controller config to default.", controllerIniFilename);
|
||||
if (!controllerIniFile.Load(controllerIniFilename_)) {
|
||||
ERROR_LOG(LOADER, "Failed to read %s. Setting controller config to default.", controllerIniFilename_);
|
||||
KeyMap::RestoreDefault();
|
||||
} else {
|
||||
// Continue anyway to initialize the config. It will just restore the defaults.
|
||||
|
@ -106,9 +106,36 @@ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLin
|
||||
langRegion = "en_US";
|
||||
}
|
||||
|
||||
std::string configFilename;
|
||||
const char *configOption = "--config=";
|
||||
|
||||
std::string controlsConfigFilename;
|
||||
const char *controlsOption = "--controlconfig=";
|
||||
|
||||
for (int i = 1; i < __argc; ++i)
|
||||
{
|
||||
if (__argv[i][0] == '\0')
|
||||
continue;
|
||||
if (__argv[i][0] == '-')
|
||||
{
|
||||
if (!strncmp(__argv[i], controlsOption, strlen(controlsOption)) && strlen(__argv[i]) > strlen(controlsOption)) {
|
||||
configFilename = __argv[i] + strlen(controlsOption);
|
||||
}
|
||||
if (!strncmp(__argv[i], controlsOption, strlen(controlsOption)) && strlen(__argv[i]) > strlen(controlsOption)) {
|
||||
controlsConfigFilename = __argv[i] + strlen(controlsOption);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(configFilename.empty())
|
||||
configFilename = "ppsspp.ini";
|
||||
|
||||
if(controlsConfigFilename.empty())
|
||||
controlsConfigFilename = "controls.ini";
|
||||
|
||||
// Load config up here, because those changes below would be overwritten
|
||||
// if it's not loaded here first.
|
||||
g_Config.Load();
|
||||
g_Config.Load(configFilename, controlsConfigFilename);
|
||||
|
||||
// The rest is handled in NativeInit().
|
||||
for (int i = 1; i < __argc; ++i)
|
||||
|
Loading…
Reference in New Issue
Block a user