Merge pull request #19104 from hrydgard/path-browser-root

Add ability to limit PathBrowser to a specific root folder
This commit is contained in:
Henrik Rydgård authored and GitHub committed 2024-05-03 19:13:33 +01:00
commit 60ffd07116
11 files changed
+67 -27

No files matched your search

+3
View File
@@ -240,6 +240,9 @@ bool Path::FilePathContainsNoCase(std::string_view needle) const {
}
bool Path::StartsWith(const Path &other) const {
if (other.empty()) {
return true;
}
if (type_ != other.type_) {
// Bad
return false;
+19 -1
View File
@@ -124,9 +124,15 @@ PathBrowser::~PathBrowser() {
void PathBrowser::SetPath(const Path &path) {
path_ = path;
ApplyRestriction();
HandlePath();
}
void PathBrowser::RestrictToRoot(const Path &root) {
INFO_LOG(SYSTEM, "Restricting to root: %s", root.c_str());
restrictedRoot_ = root;
}
void PathBrowser::HandlePath() {
if (!path_.empty() && path_.ToString()[0] == '!') {
if (pendingActive_)
@@ -203,7 +209,7 @@ bool PathBrowser::IsListingReady() {
std::string PathBrowser::GetFriendlyPath() const {
std::string str = GetPath().ToVisualString();
// Show relative to memstick root if there.
if (startsWith(str, aliasMatch_)) {
if (path_.StartsWith(aliasMatch_)) {
return aliasDisplay_ + str.substr(aliasMatch_.size());
}
@@ -229,12 +235,24 @@ bool PathBrowser::GetListing(std::vector<File::FileInfo> &fileInfo, const char *
return true;
}
void PathBrowser::ApplyRestriction() {
if (!path_.StartsWith(restrictedRoot_) && !startsWith(path_.ToString(), "!")) {
WARN_LOG(SYSTEM, "Applying path restriction: %s (%s didn't match)", restrictedRoot_.c_str(), path_.c_str());
path_ = restrictedRoot_;
}
}
bool PathBrowser::CanNavigateUp() {
if (path_ == restrictedRoot_) {
return false;
}
return path_.CanNavigateUp();
}
void PathBrowser::NavigateUp() {
_dbg_assert_(CanNavigateUp());
path_ = path_.NavigateUp();
ApplyRestriction();
}
// TODO: Support paths like "../../hello"
+6 -6
View File
@@ -8,7 +8,6 @@
#include <vector>
#include <cstdlib>
#include "Common/File/DirListing.h"
#include "Common/File/Path.h"
@@ -18,7 +17,6 @@
class PathBrowser {
public:
PathBrowser() {}
PathBrowser(const Path &path) { SetPath(path); }
~PathBrowser();
void SetPath(const Path &path);
@@ -41,11 +39,11 @@ public:
void SetUserAgent(const std::string &s) {
userAgent_ = s;
}
void SetRootAlias(const std::string &alias, const std::string &longValue) {
void SetRootAlias(const std::string &alias, const Path &rootPath) {
aliasDisplay_ = alias;
aliasMatch_ = longValue;
aliasMatch_ = rootPath;
}
void RestrictToRoot(const Path &root);
bool empty() const {
return path_.empty();
}
@@ -53,12 +51,14 @@ public:
private:
void HandlePath();
void ResetPending();
void ApplyRestriction();
Path path_;
Path pendingPath_;
Path restrictedRoot_;
std::string userAgent_;
std::string aliasDisplay_;
std::string aliasMatch_;
Path aliasMatch_;
std::vector<File::FileInfo> pendingFiles_;
std::condition_variable pendingCond_;
std::mutex pendingLock_;
+4
View File
@@ -193,6 +193,10 @@ enum SystemProperty {
SYSPROP_USER_DOCUMENTS_DIR,
// iOS app store limitation: The documents directory should be the only browsable directory.
// We'll not return true for this in non-app-store builds.
SYSPROP_LIMITED_FILE_BROWSING,
SYSPROP_OK_BUTTON_LEFT,
SYSPROP_MAIN_WINDOW_HANDLE,
+7
View File
@@ -1227,6 +1227,13 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) {
ResetControlLayout();
}
// Force JIT setting to a valid value for the current system configuration.
if (!System_GetPropertyBool(SYSPROP_CAN_JIT)) {
if (g_Config.iCpuCore == (int)CPUCore::JIT || g_Config.iCpuCore == (int)CPUCore::JIT_IR) {
g_Config.iCpuCore = (int)CPUCore::IR_INTERPRETER;
}
}
const char *gitVer = PPSSPP_GIT_VERSION;
Version installed(gitVer);
Version upgrade(upgradeVersion);
+1 -1
View File
@@ -352,7 +352,7 @@ void SetDefaultKeyMap(DefaultMaps dmap, bool replace) {
switch (dmap) {
case DEFAULT_MAPPING_KEYBOARD:
{
int keyboardLayout = System_GetPropertyInt(SYSPROP_KEYBOARD_LAYOUT);
int keyboardLayout = (int)System_GetPropertyInt(SYSPROP_KEYBOARD_LAYOUT);
switch (keyboardLayout) {
case KEYBOARD_LAYOUT_QWERTZ:
SetDefaultKeyMap(DEVICE_ID_KEYBOARD, defaultQwertzKeyboardKeyMap, ARRAY_SIZE(defaultQwertzKeyboardKeyMap), replace);
+1 -1
View File
@@ -1755,7 +1755,7 @@ void DeveloperToolsScreen::CreateViews() {
list->Add(new ItemHeader(sy->T("General")));
bool canUseJit = true;
bool canUseJit = System_GetPropertyBool(SYSPROP_CAN_JIT);
// iOS can now use JIT on all modes, apparently.
// The bool may come in handy for future non-jit platforms though (UWP XB1?)
+6 -2
View File
@@ -510,10 +510,14 @@ void DirButton::Draw(UIContext &dc) {
}
GameBrowser::GameBrowser(int token, const Path &path, BrowseFlags browseFlags, bool *gridStyle, ScreenManager *screenManager, std::string_view lastText, std::string_view lastLink, UI::LayoutParams *layoutParams)
: LinearLayout(UI::ORIENT_VERTICAL, layoutParams), path_(path), gridStyle_(gridStyle), browseFlags_(browseFlags), lastText_(lastText), lastLink_(lastLink), screenManager_(screenManager), token_(token) {
: LinearLayout(UI::ORIENT_VERTICAL, layoutParams), gridStyle_(gridStyle), browseFlags_(browseFlags), lastText_(lastText), lastLink_(lastLink), screenManager_(screenManager), token_(token) {
using namespace UI;
path_.SetUserAgent(StringFromFormat("PPSSPP/%s", PPSSPP_GIT_VERSION));
path_.SetRootAlias("ms:", GetSysDirectory(DIRECTORY_MEMSTICK_ROOT).ToVisualString() + "/");
path_.SetRootAlias("ms:", GetSysDirectory(DIRECTORY_MEMSTICK_ROOT));
if (System_GetPropertyBool(SYSPROP_LIMITED_FILE_BROWSING)) {
path_.RestrictToRoot(GetSysDirectory(DIRECTORY_MEMSTICK_ROOT));
}
path_.SetPath(path);
Refresh();
}
+3 -2
View File
@@ -253,10 +253,11 @@ bool RemoteISOConnectScreen::FindServer(std::string &resultHost, int &resultPort
}
static bool LoadGameList(const Path &url, std::vector<Path> &games) {
PathBrowser browser(url);
PathBrowser browser;
browser.SetPath(url);
std::vector<File::FileInfo> files;
browser.SetUserAgent(StringFromFormat("PPSSPP/%s", PPSSPP_GIT_VERSION));
browser.SetRootAlias("ms:", GetSysDirectory(DIRECTORY_MEMSTICK_ROOT).ToVisualString() + "/");
browser.SetRootAlias("ms:", GetSysDirectory(DIRECTORY_MEMSTICK_ROOT));
browser.GetListing(files, "iso:cso:chd:pbp:elf:prx:ppdmp:", &scanCancelled);
if (scanCancelled) {
return false;
+15 -14
View File
@@ -269,23 +269,23 @@ extern WindowsAudioBackend *winAudioBackend;
#ifdef _WIN32
#if PPSSPP_PLATFORM(UWP)
static int ScreenDPI() {
return 96; // TODO UWP
static float ScreenDPI() {
return 96.0f; // TODO UWP
}
#else
static int ScreenDPI() {
static float ScreenDPI() {
HDC screenDC = GetDC(nullptr);
int dotsPerInch = GetDeviceCaps(screenDC, LOGPIXELSY);
ReleaseDC(nullptr, screenDC);
return dotsPerInch ? dotsPerInch : 96;
return dotsPerInch ? (float)dotsPerInch : 96.0f;
}
#endif
#endif
static int ScreenRefreshRateHz() {
static int rate = 0;
static float ScreenRefreshRateHz() {
static float rate = 0.0f;
static double lastCheck = 0.0;
double now = time_now_d();
const double now = time_now_d();
if (!rate || lastCheck < now - 10.0) {
lastCheck = now;
DEVMODE lpDevMode{};
@@ -295,12 +295,12 @@ static int ScreenRefreshRateHz() {
// TODO: Use QueryDisplayConfig instead (Win7+) so we can get fractional refresh rates correctly.
if (EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &lpDevMode) == 0) {
rate = 60; // default value
rate = 60.0f; // default value
} else {
if (lpDevMode.dmFields & DM_DISPLAYFREQUENCY) {
rate = lpDevMode.dmDisplayFrequency > 60 ? lpDevMode.dmDisplayFrequency : 60;
rate = (float)(lpDevMode.dmDisplayFrequency > 60 ? lpDevMode.dmDisplayFrequency : 60);
} else {
rate = 60;
rate = 60.0f;
}
}
}
@@ -340,9 +340,9 @@ int64_t System_GetPropertyInt(SystemProperty prop) {
float System_GetPropertyFloat(SystemProperty prop) {
switch (prop) {
case SYSPROP_DISPLAY_REFRESH_RATE:
return (float)ScreenRefreshRateHz();
return ScreenRefreshRateHz();
case SYSPROP_DISPLAY_DPI:
return (float)ScreenDPI();
return ScreenDPI();
case SYSPROP_DISPLAY_SAFE_INSET_LEFT:
case SYSPROP_DISPLAY_SAFE_INSET_RIGHT:
case SYSPROP_DISPLAY_SAFE_INSET_TOP:
@@ -480,7 +480,7 @@ void System_Notify(SystemNotification notification) {
}
}
std::wstring MakeFilter(std::wstring filter) {
static std::wstring MakeFilter(std::wstring filter) {
for (size_t i = 0; i < filter.length(); i++) {
if (filter[i] == '|')
filter[i] = '\0';
@@ -651,7 +651,8 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string
void System_AskForPermission(SystemPermission permission) {}
PermissionStatus System_GetPermissionStatus(SystemPermission permission) { return PERMISSION_STATUS_GRANTED; }
void EnableCrashingOnCrashes() {
// Don't swallow exceptions.
static void EnableCrashingOnCrashes() {
typedef BOOL (WINAPI *tGetPolicy)(LPDWORD lpFlags);
typedef BOOL (WINAPI *tSetPolicy)(DWORD dwFlags);
const DWORD EXCEPTION_SWALLOWING = 0x1;
+2
View File
@@ -349,6 +349,8 @@ bool System_GetPropertyBool(SystemProperty prop) {
#endif
case SYSPROP_CAN_JIT:
return g_jitAvailable;
case SYSPROP_LIMITED_FILE_BROWSING:
return false; // But will return true in app store builds.
#ifndef HTTPS_NOT_AVAILABLE
case SYSPROP_SUPPORTS_HTTPS:
return true;