Skip to content

Commit

Permalink
Merge pull request #13902 from unknownbrackets/ui-cleanup
Browse files Browse the repository at this point in the history
UI: Cleanup Windows header in MainScreen.cpp
  • Loading branch information
hrydgard authored Jan 9, 2021
2 parents f6fcb52 + eee529c commit 291f9fd
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 56 deletions.
5 changes: 5 additions & 0 deletions Common/Net/HTTPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@
#include "Common/StringUtils.h"

#ifndef _WIN32
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netdb.h>
#include <unistd.h>
#define closesocket close
#else
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <winsock2.h>
#include <ws2tcpip.h>
#include <io.h>
Expand Down
13 changes: 0 additions & 13 deletions Common/Net/HTTPClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,6 @@

#include "Common/Net/Resolve.h"

#ifdef _WIN32
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <winsock2.h>
#include <ws2tcpip.h>
#else
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netdb.h>
#endif

#include "Common/Buffer.h"

namespace net {
Expand Down
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
3 changes: 3 additions & 0 deletions Core/Util/GameManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
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 291f9fd

Please sign in to comment.