UI: Cleanup Windows header in MainScreen.cpp.

Better to have this come from System, probably.  It's mainly for Windows
anyway, to alert people their save data isn't permanent.
This commit is contained in:
Unknown W. Brackets 2021-01-09 14:45:49 -08:00
parent b60074f697
commit eee529c6c9
8 changed files with 83 additions and 43 deletions

View File

@ -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,

View File

@ -150,9 +150,19 @@ std::string System_GetProperty(SystemProperty prop) {
}
std::vector<std::string> System_GetPropertyStringVec(SystemProperty prop) {
std::vector<std::string> 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<std::string>();
return result;
}
}

View File

@ -326,9 +326,20 @@ std::string System_GetProperty(SystemProperty prop) {
}
std::vector<std::string> System_GetPropertyStringVec(SystemProperty prop) {
std::vector<std::string> 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<std::string>();
return result;
}
}

View File

@ -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 <cmath>
#include <algorithm>
#include <cmath>
#include <sstream>
#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 <sstream>
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<std::string> 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;
}

View File

@ -357,9 +357,31 @@ std::string System_GetProperty(SystemProperty prop) {
}
std::vector<std::string> System_GetPropertyStringVec(SystemProperty prop) {
std::vector<std::string> 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<std::string>();
return result;
}
}

View File

@ -217,9 +217,31 @@ std::string System_GetProperty(SystemProperty prop) {
}
std::vector<std::string> System_GetPropertyStringVec(SystemProperty prop) {
std::vector<std::string> 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<std::string>();
return result;
}
}

View File

@ -372,6 +372,8 @@ std::vector<std::string> System_GetPropertyStringVec(SystemProperty prop) {
switch (prop) {
case SYSPROP_ADDITIONAL_STORAGE_DIRS:
return g_additionalStorageDirs;
case SYSPROP_TEMP_DIRS:
default:
return std::vector<std::string>();
}

View File

@ -66,6 +66,7 @@ std::string System_GetProperty(SystemProperty prop) {
std::vector<std::string> System_GetPropertyStringVec(SystemProperty prop) {
switch (prop) {
case SYSPROP_TEMP_DIRS:
default:
return std::vector<std::string>();
}