diff --git a/Common/System/System.h b/Common/System/System.h index 7bfe71828fa3..a713616a1095 100644 --- a/Common/System/System.h +++ b/Common/System/System.h @@ -59,6 +59,7 @@ enum SystemProperty { // Need hacky solutions to get at this. SYSPROP_HAS_ADDITIONAL_STORAGE, SYSPROP_ADDITIONAL_STORAGE_DIRS, + SYSPROP_TEMP_DIRS, SYSPROP_HAS_FILE_BROWSER, SYSPROP_HAS_FOLDER_BROWSER, diff --git a/Qt/QtMain.cpp b/Qt/QtMain.cpp index 32ae76e6c614..5ed1349ddae6 100644 --- a/Qt/QtMain.cpp +++ b/Qt/QtMain.cpp @@ -150,9 +150,19 @@ std::string System_GetProperty(SystemProperty prop) { } std::vector System_GetPropertyStringVec(SystemProperty prop) { + std::vector result; switch (prop) { + case SYSPROP_TEMP_DIRS: + if (getenv("TMPDIR") && strlen(getenv("TMPDIR")) != 0) + result.push_back(getenv("TMPDIR")); + if (getenv("TMPDIR") && strlen(getenv("TMP")) != 0) + result.push_back(getenv("TMP")); + if (getenv("TMPDIR") && strlen(getenv("TEMP")) != 0) + result.push_back(getenv("TEMP")); + return result; + default: - return std::vector(); + return result; } } diff --git a/SDL/SDLMain.cpp b/SDL/SDLMain.cpp index c65f583fc6b9..e04edae1e4bc 100644 --- a/SDL/SDLMain.cpp +++ b/SDL/SDLMain.cpp @@ -326,9 +326,20 @@ std::string System_GetProperty(SystemProperty prop) { } std::vector System_GetPropertyStringVec(SystemProperty prop) { + std::vector result; + switch (prop) { + case SYSPROP_TEMP_DIRS: + if (getenv("TMPDIR") && strlen(getenv("TMPDIR")) != 0) + result.push_back(getenv("TMPDIR")); + if (getenv("TMPDIR") && strlen(getenv("TMP")) != 0) + result.push_back(getenv("TMP")); + if (getenv("TMPDIR") && strlen(getenv("TEMP")) != 0) + result.push_back(getenv("TEMP")); + return result; + default: - return std::vector(); + return result; } } diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 375d09a39eb9..ca870ab8ff27 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -15,8 +15,9 @@ // Official git repository and contact information can be found at // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. -#include #include +#include +#include #include "ppsspp_config.h" @@ -64,13 +65,6 @@ #include "Core/HLE/sceDisplay.h" #include "Core/HLE/sceUmd.h" -#ifdef _WIN32 -// Unfortunate, for undef DrawText... -#include "Common/CommonWindows.h" -#endif - -#include - bool MainScreen::showHomebrewTab = false; bool LaunchFile(ScreenManager *screenManager, std::string path) { @@ -97,8 +91,13 @@ bool LaunchFile(ScreenManager *screenManager, std::string path) { static bool IsTempPath(const std::string &str) { std::string item = str; +#ifdef _WIN32 + // Normalize slashes. + item = ReplaceAll(str, "/", "\\"); +#endif - const auto testPath = [&](std::string temp) { + std::vector tempPaths = System_GetPropertyStringVec(SYSPROP_TEMP_DIRS); + for (auto temp : tempPaths) { #ifdef _WIN32 temp = ReplaceAll(temp, "/", "\\"); if (!temp.empty() && temp[temp.size() - 1] != '\\') @@ -107,37 +106,9 @@ static bool IsTempPath(const std::string &str) { if (!temp.empty() && temp[temp.size() - 1] != '/') temp += "/"; #endif - return startsWith(item, temp); - }; - - const auto testCPath = [&](const char *temp) { - if (temp && temp[0]) - return testPath(temp); - return false; - }; - -#ifdef _WIN32 - // Normalize slashes. - item = ReplaceAll(str, "/", "\\"); - - std::wstring tempPath(MAX_PATH, '\0'); - size_t sz = GetTempPath((DWORD)tempPath.size(), &tempPath[0]); - if (sz >= tempPath.size()) { - tempPath.resize(sz); - sz = GetTempPath((DWORD)tempPath.size(), &tempPath[0]); + if (startsWith(item, temp)) + return true; } - // Need to resize off the null terminator either way. - tempPath.resize(sz); - if (testPath(ConvertWStringToUTF8(tempPath))) - return true; -#endif - - if (testCPath(getenv("TMPDIR"))) - return true; - if (testCPath(getenv("TMP"))) - return true; - if (testCPath(getenv("TEMP"))) - return true; return false; } diff --git a/UWP/PPSSPP_UWPMain.cpp b/UWP/PPSSPP_UWPMain.cpp index 60a73f86952a..6b4404e5f581 100644 --- a/UWP/PPSSPP_UWPMain.cpp +++ b/UWP/PPSSPP_UWPMain.cpp @@ -357,9 +357,31 @@ std::string System_GetProperty(SystemProperty prop) { } std::vector System_GetPropertyStringVec(SystemProperty prop) { + std::vector result; switch (prop) { + case SYSPROP_TEMP_DIRS: + { + std::wstring tempPath(MAX_PATH, '\0'); + size_t sz = GetTempPath((DWORD)tempPath.size(), &tempPath[0]); + if (sz >= tempPath.size()) { + tempPath.resize(sz); + sz = GetTempPath((DWORD)tempPath.size(), &tempPath[0]); + } + // Need to resize off the null terminator either way. + tempPath.resize(sz); + result.push_back(ConvertWStringToUTF8(tempPath)); + + if (getenv("TMPDIR") && strlen(getenv("TMPDIR")) != 0) + result.push_back(getenv("TMPDIR")); + if (getenv("TMPDIR") && strlen(getenv("TMP")) != 0) + result.push_back(getenv("TMP")); + if (getenv("TMPDIR") && strlen(getenv("TEMP")) != 0) + result.push_back(getenv("TEMP")); + return result; + } + default: - return std::vector(); + return result; } } diff --git a/Windows/main.cpp b/Windows/main.cpp index c7e9dc9fd678..21bfe67f1adf 100644 --- a/Windows/main.cpp +++ b/Windows/main.cpp @@ -217,9 +217,31 @@ std::string System_GetProperty(SystemProperty prop) { } std::vector System_GetPropertyStringVec(SystemProperty prop) { + std::vector result; switch (prop) { + case SYSPROP_TEMP_DIRS: + { + std::wstring tempPath(MAX_PATH, '\0'); + size_t sz = GetTempPath((DWORD)tempPath.size(), &tempPath[0]); + if (sz >= tempPath.size()) { + tempPath.resize(sz); + sz = GetTempPath((DWORD)tempPath.size(), &tempPath[0]); + } + // Need to resize off the null terminator either way. + tempPath.resize(sz); + result.push_back(ConvertWStringToUTF8(tempPath)); + + if (getenv("TMPDIR") && strlen(getenv("TMPDIR")) != 0) + result.push_back(getenv("TMPDIR")); + if (getenv("TMPDIR") && strlen(getenv("TMP")) != 0) + result.push_back(getenv("TMP")); + if (getenv("TMPDIR") && strlen(getenv("TEMP")) != 0) + result.push_back(getenv("TEMP")); + return result; + } + default: - return std::vector(); + return result; } } diff --git a/android/jni/app-android.cpp b/android/jni/app-android.cpp index 90070eedd102..a5a172432597 100644 --- a/android/jni/app-android.cpp +++ b/android/jni/app-android.cpp @@ -372,6 +372,8 @@ std::vector System_GetPropertyStringVec(SystemProperty prop) { switch (prop) { case SYSPROP_ADDITIONAL_STORAGE_DIRS: return g_additionalStorageDirs; + + case SYSPROP_TEMP_DIRS: default: return std::vector(); } diff --git a/ios/main.mm b/ios/main.mm index 80825849334c..4b3e768d5cf7 100644 --- a/ios/main.mm +++ b/ios/main.mm @@ -66,6 +66,7 @@ kern_return_t catch_exception_raise(mach_port_t exception_port, std::vector System_GetPropertyStringVec(SystemProperty prop) { switch (prop) { + case SYSPROP_TEMP_DIRS: default: return std::vector(); }