diff --git a/Core/CwCheat.cpp b/Core/CwCheat.cpp index 02c3bd4cc..74b94bf1c 100644 --- a/Core/CwCheat.cpp +++ b/Core/CwCheat.cpp @@ -17,7 +17,7 @@ void trim2(std::string& str); void __CheatInit() { gameTitle = g_paramSFO.GetValueString("DISC_ID"); -#if defined(ANDROID) || defined(__SYMBIAN32__) +#if defined(ANDROID) || defined(__SYMBIAN32__) || defined(_WIN32) activeCheatFile = g_Config.memCardDirectory + "PSP/Cheats/" + gameTitle + ".ini"; #else activeCheatFile = CHEATS_DIR + "/" + gameTitle + ".ini"; diff --git a/Core/System.cpp b/Core/System.cpp index e58a7a198..1190ff760 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -17,6 +17,7 @@ #ifdef _WIN32 #include "Common/CommonWindows.h" +#include #endif #include "native/thread/thread.h" @@ -364,18 +365,37 @@ void GetSysDirectories(std::string &memstickpath, std::string &flash0path) { char drive[_MAX_DRIVE] ,dir[_MAX_DIR], file[_MAX_FNAME], ext[_MAX_EXT]; char memstickpath_buf[_MAX_PATH]; char flash0path_buf[_MAX_PATH]; - GetModuleFileName(NULL, path_buffer, ARRAY_SIZE(path_buffer)); std::string path = ConvertWStringToUTF8(path_buffer); _splitpath_s(path.c_str(), drive, dir, file, ext ); - // Mount a couple of filesystems - sprintf(memstickpath_buf, "%s%smemstick\\", drive, dir); - sprintf(flash0path_buf, "%s%sflash0\\", drive, dir); + std::string previousCurrentDir = g_Config.currentDirectory; - memstickpath = memstickpath_buf; + g_Config.currentDirectory = File::GetExeDirectory(); + + // Detect the "My Documents"(XP) or "Documents"(on Vista/7/8) folder. + 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 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/"; + } else { + sprintf(memstickpath_buf, "%s%smemstick\\", drive, dir); + memstickpath = memstickpath_buf; + } + + File::Delete(testFile); + + g_Config.currentDirectory = previousCurrentDir; + + // Mount a filesystem + sprintf(flash0path_buf, "%s%sflash0\\", drive, dir); flash0path = flash0path_buf; #else // TODO diff --git a/UI/CwCheatScreen.cpp b/UI/CwCheatScreen.cpp index d3d11f2d1..04c997b68 100644 --- a/UI/CwCheatScreen.cpp +++ b/UI/CwCheatScreen.cpp @@ -153,7 +153,7 @@ 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) +#if defined(ANDROID) || defined(__SYMBIAN32__) || defined(BLACKBERRY) || defined(_WIN32) std::string cheatDir = g_Config.memCardDirectory + "PSP/Cheats/cheat.db"; is.open(cheatDir.c_str()); #else