diff --git a/Core/Config.cpp b/Core/Config.cpp index 02a8f3e094..324d9a4cfc 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -19,6 +19,7 @@ #include "base/NativeApp.h" #include "Common/KeyMap.h" #include "Common/FileUtil.h" +#include "Common/StringUtils.h" #include "Config.h" #include "file/ini_file.h" #include "i18n/i18n.h" @@ -36,9 +37,8 @@ Config::~Config() { } void Config::Load(const char *iniFileName, const char *controllerIniFilename) { - iniFilename_ = iniFileName != NULL ? iniFileName : "ppsspp.ini"; - - controllerIniFilename_ = controllerIniFilename != NULL ? controllerIniFilename : "controls.ini"; + iniFilename_ = FindConfigFile(iniFileName != NULL ? iniFileName : "ppsspp.ini"); + controllerIniFilename_ = FindConfigFile(controllerIniFilename != NULL ? controllerIniFilename : "controls.ini"); INFO_LOG(LOADER, "Loading config: %s", iniFilename_.c_str()); bSaveSettings = true; @@ -462,7 +462,38 @@ void Config::CleanRecent() { recentIsos = cleanedRecent; } +void Config::SetDefaultPath(const std::string &defaultPath) { + defaultPath_ = defaultPath; +} + +void Config::AddSearchPath(const std::string &path) { + searchPath_.push_back(path); +} + +const std::string Config::FindConfigFile(const std::string &baseFilename) { + // Don't search for an absolute path. + if (baseFilename.size() > 1 && baseFilename[0] == '/') { + return baseFilename; + } + + for (size_t i = 0; i < searchPath_.size(); ++i) { + std::string filename = searchPath_[i] + baseFilename; + if (File::Exists(filename)) { + return filename; + } + } + + const std::string filename = defaultPath_.empty() ? baseFilename : defaultPath_ + baseFilename; + if (!File::Exists(filename)) { + std::string path; + SplitPath(filename, &path, NULL, NULL); + File::CreateFullPath(path); + } + return filename; +} + void Config::RestoreDefaults() { + // TODO: This should probably use the correct path? if(File::Exists("ppsspp.ini")) File::Delete("ppsspp.ini"); recentIsos.clear(); diff --git a/Core/Config.h b/Core/Config.h index 60ce073412..d37e20594c 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -180,6 +180,12 @@ public: void Save(); void RestoreDefaults(); + // Used when the file is not found in the search path. Trailing slash. + void SetDefaultPath(const std::string &defaultPath); + // Use a trailing slash. + void AddSearchPath(const std::string &path); + const std::string FindConfigFile(const std::string &baseFilename); + // Utility functions for "recent" management void AddRecent(const std::string &file); void CleanRecent(); @@ -187,6 +193,8 @@ public: private: std::string iniFilename_; std::string controllerIniFilename_; + std::vector searchPath_; + std::string defaultPath_; }; extern Config g_Config; diff --git a/Qt/QtHost.cpp b/Qt/QtHost.cpp index 650a4ddc55..6f6d3b780b 100644 --- a/Qt/QtHost.cpp +++ b/Qt/QtHost.cpp @@ -29,7 +29,6 @@ Texture *uiTexture; UIContext *uiContext; ScreenManager *screenManager; -std::string config_filename; std::string game_title; event m_hGPUStepEvent; @@ -228,18 +227,19 @@ void QtHost::NextGPUStep() void NativeInit(int argc, const char *argv[], const char *savegame_directory, const char *external_directory, const char *installID) { - std::string config_filename; Common::EnableCrashingOnCrashes(); isMessagePending = false; std::string user_data_path = savegame_directory; + std::string memcard_path = QDir::homePath().toStdString() + "/.ppsspp/"; VFSRegister("", new DirectoryAssetReader("assets/")); VFSRegister("", new DirectoryAssetReader(user_data_path.c_str())); - config_filename = user_data_path + "ppsspp.ini"; - - g_Config.Load(config_filename.c_str()); + g_Config.AddSearchPath(user_data_path); + g_Config.AddSearchPath(memcard_path + "PSP/SYSTEM/"); + g_Config.SetDefaultPath(g_Config.memCardDirectory + "PSP/SYSTEM/"); + g_Config.Load(); const char *fileToLog = 0; diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 68db3042d7..938e10e8b5 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -246,6 +246,22 @@ void NativeInit(int argc, const char *argv[], host = new NativeHost(); +#if defined(ANDROID) + g_Config.internalDataDirectory = savegame_directory; + // Maybe there should be an option to use internal memory instead, but I think + // that for most people, using external memory (SDCard/USB Storage) makes the + // most sense. + g_Config.memCardDirectory = std::string(external_directory) + "/"; + g_Config.flashDirectory = std::string(external_directory) + "/flash0/"; +#elif defined(BLACKBERRY) || defined(__SYMBIAN32__) || defined(MEEGO_EDITION_HARMATTAN) || defined(IOS) + g_Config.memCardDirectory = user_data_path; + g_Config.flashDirectory = std::string(external_directory) + "/flash0/"; +#elif !defined(_WIN32) + // Linux, Mac. Does this path really make sense? + g_Config.memCardDirectory = std::string(getenv("HOME")) + "/.ppsspp/"; + g_Config.flashDirectory = g_Config.memCardDirectory + "/flash0/"; +#endif + #ifndef _WIN32 logger = new AndroidLogger(); @@ -253,19 +269,20 @@ void NativeInit(int argc, const char *argv[], LogManager *logman = LogManager::GetInstance(); ILOG("Logman: %p", logman); - config_filename = user_data_path + "/ppsspp.ini"; - std::string controls_filename = user_data_path + "/controls.ini"; - g_Config.Load(config_filename.c_str(), controls_filename.c_str()); + g_Config.AddSearchPath(user_data_path); + g_Config.AddSearchPath(g_Config.memCardDirectory + "PSP/SYSTEM/"); + g_Config.SetDefaultPath(g_Config.memCardDirectory + "PSP/SYSTEM/"); + g_Config.Load(); g_Config.externalDirectory = external_directory; #endif #ifdef ANDROID // On Android, create a PSP directory tree in the external_directory, // to hopefully reduce confusion a bit. - ILOG("Creating %s", (g_Config.externalDirectory + "/PSP").c_str()); - mkDir((g_Config.externalDirectory + "/PSP").c_str()); - mkDir((g_Config.externalDirectory + "/PSP/SAVEDATA").c_str()); - mkDir((g_Config.externalDirectory + "/PSP/GAME").c_str()); + ILOG("Creating %s", (g_Config.memCardDirectory + "PSP").c_str()); + mkDir((g_Config.memCardDirectory + "PSP").c_str()); + mkDir((g_Config.memCardDirectory + "PSP/SAVEDATA").c_str()); + mkDir((g_Config.memCardDirectory + "PSP/GAME").c_str()); #endif const char *fileToLog = 0; @@ -331,21 +348,6 @@ void NativeInit(int argc, const char *argv[], #endif } -#if defined(ANDROID) - g_Config.internalDataDirectory = savegame_directory; - // Maybe there should be an option to use internal memory instead, but I think - // that for most people, using external memory (SDCard/USB Storage) makes the - // most sense. - g_Config.memCardDirectory = std::string(external_directory) + "/"; - g_Config.flashDirectory = std::string(external_directory)+"/flash0/"; -#elif defined(BLACKBERRY) || defined(__SYMBIAN32__) || defined(MEEGO_EDITION_HARMATTAN) || defined(IOS) || defined(_WIN32) - g_Config.memCardDirectory = user_data_path; - g_Config.flashDirectory = std::string(external_directory)+"flash0/"; -#else - g_Config.memCardDirectory = std::string(getenv("HOME"))+"/.ppsspp/"; - g_Config.flashDirectory = g_Config.memCardDirectory+"/flash0/"; -#endif - for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; i++) { LogTypes::LOG_TYPE type = (LogTypes::LOG_TYPE)i; diff --git a/Windows/OpenGLBase.cpp b/Windows/OpenGLBase.cpp index aaa9b5dedc..814c048d0a 100644 --- a/Windows/OpenGLBase.cpp +++ b/Windows/OpenGLBase.cpp @@ -18,8 +18,6 @@ static int xres, yres; // TODO: Make config? static bool enableGLDebug = false; -#pragma optimize("", off) - void GL_Resized() { if (!hWnd) return; diff --git a/Windows/main.cpp b/Windows/main.cpp index 296c6ce41e..39bff5597e 100644 --- a/Windows/main.cpp +++ b/Windows/main.cpp @@ -195,10 +195,10 @@ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLin osName = GetWindowsVersion() + " " + GetWindowsSystemArchitecture(); - std::string configFilename; + const char *configFilename = NULL; const char *configOption = "--config="; - std::string controlsConfigFilename; + const char *controlsConfigFilename = NULL; const char *controlsOption = "--controlconfig="; for (int i = 1; i < __argc; ++i) @@ -216,15 +216,15 @@ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLin } } - if(configFilename.empty()) - configFilename = "ppsspp.ini"; - - if(controlsConfigFilename.empty()) - controlsConfigFilename = "controls.ini"; + std::string memstickpath, flash0path; + GetSysDirectories(memstickpath, flash0path); // Load config up here, because those changes below would be overwritten // if it's not loaded here first. - g_Config.Load(configFilename.c_str(), controlsConfigFilename.c_str()); + g_Config.AddSearchPath(""); + g_Config.AddSearchPath(memstickpath + "PSP/SYSTEM/"); + g_Config.SetDefaultPath(memstickpath + "PSP/SYSTEM/"); + g_Config.Load(configFilename, controlsConfigFilename); // The rest is handled in NativeInit(). for (int i = 1; i < __argc; ++i)