Skip to content

Commit

Permalink
UI: Cleanup Windows header in MainScreen.cpp.
Browse files Browse the repository at this point in the history
Better to have this come from System, probably.  It's mainly for Windows
anyway, to alert people their save data isn't permanent.
  • Loading branch information
unknownbrackets committed Jan 9, 2021
1 parent b60074f commit eee529c
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 43 deletions.
1 change: 1 addition & 0 deletions Common/System/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 11 additions & 1 deletion Qt/QtMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
13 changes: 12 additions & 1 deletion SDL/SDLMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
49 changes: 10 additions & 39 deletions UI/MainScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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) {
Expand All @@ -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] != '\\')
Expand All @@ -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;
}
Expand Down
24 changes: 23 additions & 1 deletion UWP/PPSSPP_UWPMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
24 changes: 23 additions & 1 deletion Windows/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
2 changes: 2 additions & 0 deletions android/jni/app-android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
}
Expand Down
1 change: 1 addition & 0 deletions ios/main.mm
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ kern_return_t catch_exception_raise(mach_port_t exception_port,

std::vector<std::string> System_GetPropertyStringVec(SystemProperty prop) {
switch (prop) {
case SYSPROP_TEMP_DIRS:
default:
return std::vector<std::string>();
}
Expand Down

0 comments on commit eee529c

Please sign in to comment.