diff --git a/Common/Net/HTTPClient.cpp b/Common/Net/HTTPClient.cpp index 7193582fa599..1c13d95f901f 100644 --- a/Common/Net/HTTPClient.cpp +++ b/Common/Net/HTTPClient.cpp @@ -4,13 +4,18 @@ #include "Common/StringUtils.h" #ifndef _WIN32 +#include #include #include #include #include +#include #include #define closesocket close #else +#ifndef NOMINMAX +#define NOMINMAX +#endif #include #include #include diff --git a/Common/Net/HTTPClient.h b/Common/Net/HTTPClient.h index 731ff75dd543..d76e57d1b9a4 100644 --- a/Common/Net/HTTPClient.h +++ b/Common/Net/HTTPClient.h @@ -7,19 +7,6 @@ #include "Common/Net/Resolve.h" -#ifdef _WIN32 -#ifndef NOMINMAX -#define NOMINMAX -#endif -#include -#include -#else -#include -#include -#include -#include -#endif - #include "Common/Buffer.h" namespace net { 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/Core/Util/GameManager.cpp b/Core/Util/GameManager.cpp index 17b2e75751b7..3e0c618b0e77 100644 --- a/Core/Util/GameManager.cpp +++ b/Core/Util/GameManager.cpp @@ -28,6 +28,9 @@ #else #include "ext/libzip/zip.h" #endif +#ifdef _WIN32 +#include "Common/CommonWindows.h" +#endif #include "Common/Data/Encoding/Utf8.h" #include "Common/Data/Format/IniFile.h" #include "Common/Log.h" 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 20d5970ee7d6..517f1c6f5c76 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 9887f8821bac..fcff1d71830d 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(); }