From d8a0adf50c08d8dc43084bdb6aae7a618a891795 Mon Sep 17 00:00:00 2001 From: The Dax Date: Sun, 13 Oct 2013 17:17:48 -0400 Subject: [PATCH] If installed.txt has a path in it, use that instead of the detected Documents directory. --- Core/System.cpp | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/Core/System.cpp b/Core/System.cpp index 1190ff7604..9eab10e745 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -18,6 +18,8 @@ #ifdef _WIN32 #include "Common/CommonWindows.h" #include +#include +#include #endif #include "native/thread/thread.h" @@ -379,17 +381,38 @@ void GetSysDirectories(std::string &memstickpath, std::string &flash0path) { wchar_t myDocumentsPath[MAX_PATH]; HRESULT result = SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, myDocumentsPath); - bool installed = File::Exists(g_Config.currentDirectory + "/installed.txt"); + std::string installedFile = g_Config.currentDirectory + "/installed.txt"; + bool installed = File::Exists(installedFile); std::string testFile = g_Config.currentDirectory + "/_writable_test.$$$"; - // If installed.txt exists(and we can determine the Documents directory) or directory is read-only - if ((installed && result == S_OK) || !File::CreateEmptyFile(testFile)) { - memstickpath = ConvertWStringToUTF8(myDocumentsPath) + "/PPSSPP/"; + // If installed.txt exists(and we can determine the Documents directory) + if ((installed && result == S_OK) ) { + std::ifstream inputFile; + inputFile.open(installedFile); + if (!inputFile.fail()) { + while (!inputFile.eof()) { + std::getline(inputFile, memstickpath); + } + } + + // If the path doesn't end with a slash, add one. + size_t lastSlash = memstickpath.find_last_of("/"); + if (lastSlash != (memstickpath.length() - 1)) + memstickpath.append("/"); + + inputFile.close(); } else { sprintf(memstickpath_buf, "%s%smemstick\\", drive, dir); memstickpath = memstickpath_buf; } + bool currentDirIsReadOnly = !File::CreateEmptyFile(testFile); + + // Use the documents directory if the installedFile is blank or if we can't create a file + // in the current directory. + if (currentDirIsReadOnly || memstickpath.empty()) + memstickpath = ConvertWStringToUTF8(myDocumentsPath) + "/PPSSPP/"; + File::Delete(testFile); g_Config.currentDirectory = previousCurrentDir;