diff --git a/Core/CwCheat.cpp b/Core/CwCheat.cpp index 38b6b2b095..4d82886c99 100644 --- a/Core/CwCheat.cpp +++ b/Core/CwCheat.cpp @@ -29,8 +29,8 @@ static void __CheatStart() { gameTitle = g_paramSFO.GetValueString("DISC_ID"); - activeCheatFile = g_Config.memCardDirectory + "PSP/Cheats/" + gameTitle + ".ini"; - File::CreateFullPath(g_Config.memCardDirectory + "PSP/Cheats"); + activeCheatFile = GetSysDirectory(DIRECTORY_CHEATS) + gameTitle + ".ini"; + File::CreateFullPath(GetSysDirectory(DIRECTORY_CHEATS)); if (!File::Exists(activeCheatFile)) { File::CreateEmptyFile(activeCheatFile); diff --git a/Core/HLE/sceIo.cpp b/Core/HLE/sceIo.cpp index a5ceedb0a1..2146ad01c7 100644 --- a/Core/HLE/sceIo.cpp +++ b/Core/HLE/sceIo.cpp @@ -448,15 +448,11 @@ void __IoInit() { asyncNotifyEvent = CoreTiming::RegisterEvent("IoAsyncNotify", __IoAsyncNotify); syncNotifyEvent = CoreTiming::RegisterEvent("IoSyncNotify", __IoSyncNotify); - std::string memstickpath; - std::string flash0path; - GetSysDirectories(memstickpath, flash0path); - - memstickSystem = new DirectoryFileSystem(&pspFileSystem, memstickpath); + memstickSystem = new DirectoryFileSystem(&pspFileSystem, g_Config.memCardDirectory); #ifdef ANDROID flash0System = new VFSFileSystem(&pspFileSystem, "flash0"); #else - flash0System = new DirectoryFileSystem(&pspFileSystem, flash0path); + flash0System = new DirectoryFileSystem(&pspFileSystem, g_Config.flash0Directory); #endif pspFileSystem.Mount("ms0:", memstickSystem); pspFileSystem.Mount("fatms0:", memstickSystem); diff --git a/Core/System.cpp b/Core/System.cpp index 61eba4a2cd..0588e50728 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -360,17 +360,42 @@ CoreParameter &PSP_CoreParameter() { return coreParameter; } +std::string GetSysDirectory(PSPDirectories directoryType) { + switch (directoryType) { + case DIRECTORY_CHEATS: + return g_Config.memCardDirectory + "PSP/Cheats/"; + case DIRECTORY_GAME: + return g_Config.memCardDirectory + "PSP/GAME/"; + case DIRECTORY_SAVEDATA: + return g_Config.memCardDirectory + "PSP/SAVEDATA/"; + case DIRECTORY_SCREENSHOT: + return g_Config.memCardDirectory + "PSP/SCREENSHOT/"; + case DIRECTORY_SYSTEM: + return g_Config.memCardDirectory + "PSP/SYSTEM/"; + case DIRECTORY_PAUTH: + return g_Config.memCardDirectory + "PAUTH/"; + // Just return the memory stick root if we run into some sort of problem. + default: + ERROR_LOG(FILESYS, "Unknown directory type."); + return g_Config.memCardDirectory; + } +} -void GetSysDirectories(std::string &memstickpath, std::string &flash0path) { #ifdef _WIN32 +// Run this at startup time. Please use GetSysDirectory if you need to query where folders are. +void InitSysDirectories() { + if (!g_Config.memCardDirectory.empty() && !g_Config.flash0Directory.empty()) + return; + const std::string path = ConvertWStringToUTF8(File::GetExeDirectory()); // Mount a filesystem - flash0path = path + "/flash0/"; + g_Config.flash0Directory = path + "/flash0/"; // Detect the "My Documents"(XP) or "Documents"(on Vista/7/8) folder. wchar_t myDocumentsPath[MAX_PATH]; const HRESULT result = SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, myDocumentsPath); + const std::string myDocsPath = ConvertWStringToUTF8(myDocumentsPath) + "/PPSSPP/"; const std::string installedFile = path + "/installed.txt"; const bool installed = File::Exists(installedFile); @@ -388,41 +413,41 @@ void GetSysDirectories(std::string &memstickpath, std::string &flash0path) { if (tempString.substr(0, 3) == "\xEF\xBB\xBF") tempString = tempString.substr(3); - memstickpath = tempString; + g_Config.memCardDirectory = tempString; } inputFile.close(); // Check if the file is empty first, before appending the slash. - if (memstickpath.empty()) - memstickpath = ConvertWStringToUTF8(myDocumentsPath) + "/PPSSPP/"; + if (g_Config.memCardDirectory.empty()) + g_Config.memCardDirectory = myDocsPath; - size_t lastSlash = memstickpath.find_last_of("/"); - if (lastSlash != (memstickpath.length() - 1)) - memstickpath.append("/"); + size_t lastSlash = g_Config.memCardDirectory.find_last_of("/"); + if (lastSlash != (g_Config.memCardDirectory.length() - 1)) + g_Config.memCardDirectory.append("/"); } else { - memstickpath = path + "/memstick/"; + g_Config.memCardDirectory = path + "/memstick/"; } // Create the memstickpath before trying to write to it, and fall back on Documents yet again // if we can't make it. - if (!File::Exists(memstickpath)) { - if(!File::CreateDir(memstickpath)) - memstickpath = ConvertWStringToUTF8(myDocumentsPath) + "/PPSSPP/"; + if (!File::Exists(g_Config.memCardDirectory)) { + if (!File::CreateDir(g_Config.memCardDirectory)) + g_Config.memCardDirectory = myDocsPath; } const std::string testFile = "/_writable_test.$$$"; // If any directory is read-only, fall back to the Documents directory. // We're screwed anyway if we can't write to Documents, or can't detect it. - if (!File::CreateEmptyFile(memstickpath + testFile)) - memstickpath = ConvertWStringToUTF8(myDocumentsPath) + "/PPSSPP/"; + if (!File::CreateEmptyFile(g_Config.memCardDirectory + testFile)) + g_Config.memCardDirectory = myDocsPath; // Clean up our mess. - if (File::Exists(memstickpath + testFile)) - File::Delete(memstickpath + testFile); -#else - // TODO - memstickpath = g_Config.memCardDirectory; - flash0path = g_Config.flash0Directory; -#endif + if (File::Exists(g_Config.memCardDirectory + testFile)) + File::Delete(g_Config.memCardDirectory + testFile); + + if (g_Config.currentDirectory.empty()) { + g_Config.currentDirectory = GetSysDirectory(DIRECTORY_GAME); + } } +#endif diff --git a/Core/System.h b/Core/System.h index 0c7db24b4e..300c8d03c7 100644 --- a/Core/System.h +++ b/Core/System.h @@ -36,6 +36,15 @@ enum GlobalUIState { UISTATE_EXIT, }; +// Use these in conjunction with GetSysDirectory. +enum PSPDirectories { + DIRECTORY_CHEATS, + DIRECTORY_SCREENSHOT, + DIRECTORY_SYSTEM, + DIRECTORY_GAME, + DIRECTORY_SAVEDATA, + DIRECTORY_PAUTH, +}; extern GlobalUIState globalUIState; @@ -58,7 +67,10 @@ void Audio_Init(); bool IsOnSeparateCPUThread(); bool IsAudioInitialised(); -void GetSysDirectories(std::string &memstickpath, std::string &flash0path); +std::string GetSysDirectory(PSPDirectories directoryType); +#ifdef _WIN32 +void InitSysDirectories(); +#endif // RUNNING must be at 0, NEXTFRAME must be at 1. enum CoreState diff --git a/UI/CwCheatScreen.cpp b/UI/CwCheatScreen.cpp index 04c997b68f..00137d7c20 100644 --- a/UI/CwCheatScreen.cpp +++ b/UI/CwCheatScreen.cpp @@ -153,12 +153,10 @@ UI::EventReturn CwCheatScreen::OnImportCheat(UI::EventParams ¶ms) std::vector title; bool finished = false, skip = false; std::vector newList; -#if defined(ANDROID) || defined(__SYMBIAN32__) || defined(BLACKBERRY) || defined(_WIN32) - std::string cheatDir = g_Config.memCardDirectory + "PSP/Cheats/cheat.db"; + + std::string cheatDir = GetSysDirectory(DIRECTORY_CHEATS) + "cheat.db"; is.open(cheatDir.c_str()); -#else - is.open("cheats/cheat.db"); -#endif + while (is.good()) { getline(is, line); // get line from file diff --git a/UI/GameInfoCache.cpp b/UI/GameInfoCache.cpp index 5a90236ae0..c3afe08b80 100644 --- a/UI/GameInfoCache.cpp +++ b/UI/GameInfoCache.cpp @@ -71,11 +71,10 @@ u64 GameInfo::GetGameSizeInBytes() { } std::vector GameInfo::GetSaveDataDirectories() { - std::string memc, flash; - GetSysDirectories(memc, flash); + std::string memc = GetSysDirectory(DIRECTORY_SAVEDATA); std::vector dirs; - getFilesInDir((memc + "PSP/SAVEDATA/").c_str(), &dirs); + getFilesInDir(memc.c_str(), &dirs); std::vector directories; for (size_t i = 0; i < dirs.size(); i++) { diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index a194fdb8a4..b3d7d6de4a 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -301,12 +301,6 @@ void PathBrowser::Navigate(const std::string &path) { } } -static std::string GetMemCardDirectory() { - std::string memCardDirectory, ignore; - GetSysDirectories(memCardDirectory, ignore); - return memCardDirectory; -} - class GameBrowser : public UI::LinearLayout { public: GameBrowser(std::string path, bool allowBrowsing, bool *gridStyle_, std::string lastText, std::string lastLink, UI::LayoutParams *layoutParams = 0); @@ -350,7 +344,7 @@ UI::EventReturn GameBrowser::LastClick(UI::EventParams &e) { } UI::EventReturn GameBrowser::HomeClick(UI::EventParams &e) { - path_.SetPath(GetMemCardDirectory()); + path_.SetPath(g_Config.memCardDirectory); g_Config.currentDirectory = path_.GetPath(); Refresh(); return UI::EVENT_DONE; @@ -497,7 +491,7 @@ void MainScreen::CreateViews() { GameBrowser *tabAllGames = new GameBrowser(g_Config.currentDirectory, true, &g_Config.bGridView2, m->T("How to get games"), "http://www.ppsspp.org/getgames.html", new LinearLayoutParams(FILL_PARENT, FILL_PARENT)); - GameBrowser *tabHomebrew = new GameBrowser(GetMemCardDirectory() + "PSP/GAME/", false, &g_Config.bGridView3, + GameBrowser *tabHomebrew = new GameBrowser(GetSysDirectory(DIRECTORY_GAME), false, &g_Config.bGridView3, m->T("How to get homebrew & demos"), "http://www.ppsspp.org/gethomebrew.html", new LinearLayoutParams(FILL_PARENT, FILL_PARENT)); diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index ed6e30b8cb..4b0cca2435 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -367,12 +367,6 @@ void NativeInit(int argc, const char *argv[], if (!gfxLog) logman->SetLogLevel(LogTypes::G3D, LogTypes::LERROR); INFO_LOG(BOOT, "Logger inited."); -#else - if (g_Config.currentDirectory.empty()) { - g_Config.currentDirectory = ConvertWStringToUTF8(File::GetExeDirectory()); - } - // TODO: Is this even needed, when PPSSPP uses GetSysDirectories in multiple other places? - g_Config.memCardDirectory = "memstick/"; #endif i18nrepo.LoadIni(g_Config.sLanguageIni); diff --git a/Windows/EmuThread.cpp b/Windows/EmuThread.cpp index 88b9d2c3b3..6cf9103f7f 100644 --- a/Windows/EmuThread.cpp +++ b/Windows/EmuThread.cpp @@ -86,15 +86,12 @@ unsigned int WINAPI TheThread(void *) setCurrentThreadName("EmuThread"); - std::string memstick, flash0; - GetSysDirectories(memstick, flash0); - // Native overwrites host. Can't allow that. Host *oldHost = host; UpdateScreenScale(); - NativeInit(__argc, (const char **)__argv, memstick.c_str(), memstick.c_str(), "1234"); + NativeInit(__argc, (const char **)__argv, "1234", "1234", "1234"); Host *nativeHost = host; host = oldHost; diff --git a/Windows/WndMainWindow.cpp b/Windows/WndMainWindow.cpp index 0c4db2be0d..6e4ae2d1b8 100644 --- a/Windows/WndMainWindow.cpp +++ b/Windows/WndMainWindow.cpp @@ -1127,20 +1127,11 @@ namespace MainWindow break; case ID_FILE_LOAD_MEMSTICK: - { - std::string memStickDir, flash0dir; - GetSysDirectories(memStickDir, flash0dir); - memStickDir += "PSP\\GAME\\"; - BrowseAndBoot(memStickDir); - } + BrowseAndBoot(GetSysDirectory(DIRECTORY_GAME)); break; case ID_FILE_MEMSTICK: - { - std::string memStickDir, flash0dir; - GetSysDirectories(memStickDir, flash0dir); - ShellExecuteA(NULL, "open", memStickDir.c_str(), 0, 0, SW_SHOW); - } + ShellExecute(NULL, L"open", ConvertUTF8ToWString(g_Config.memCardDirectory).c_str(), 0, 0, SW_SHOW); break; case ID_TOGGLE_PAUSE: diff --git a/Windows/main.cpp b/Windows/main.cpp index 16a527b857..5c1398f00f 100644 --- a/Windows/main.cpp +++ b/Windows/main.cpp @@ -217,14 +217,15 @@ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLin } } - std::string memstickpath, flash0path; - GetSysDirectories(memstickpath, flash0path); + // On Win32 it makes more sense to initialize the system directories here + // because the next place it was called was in the EmuThread, and it's too late by then. + InitSysDirectories(); // Load config up here, because those changes below would be overwritten // if it's not loaded here first. g_Config.AddSearchPath(""); - g_Config.AddSearchPath(memstickpath + "PSP/SYSTEM/"); - g_Config.SetDefaultPath(memstickpath + "PSP/SYSTEM/"); + g_Config.AddSearchPath(GetSysDirectory(DIRECTORY_SYSTEM)); + g_Config.SetDefaultPath(GetSysDirectory(DIRECTORY_SYSTEM)); g_Config.Load(configFilename, controlsConfigFilename); // The rest is handled in NativeInit().