Add functionality to limit a pathbrowser to a specific root

This commit is contained in:
Henrik Rydgård committed 2024-05-03 17:54:57 +02:00
1 parent 0ae0c9bbe9
commit ae1ee41eb0
8 files changed
+44 -12

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,
+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);
+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;
+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;