Rewrite GetFriendlyPath to not crash and work in more situations

This commit is contained in:
Henrik Rydgård 2024-05-31 20:41:03 +02:00
parent a431d53da3
commit b85890c37b
2 changed files with 20 additions and 6 deletions

View file

@ -209,19 +209,28 @@ bool PathBrowser::IsListingReady() {
}
std::string PathBrowser::GetFriendlyPath() const {
std::string str = GetPath().ToVisualString();
// Show relative to memstick root if there.
if (path_.StartsWith(aliasMatch_)) {
return aliasDisplay_ + str.substr(aliasMatch_.size());
std::string p;
if (aliasMatch_.ComputePathTo(path_, p)) {
return aliasDisplay_ + p;
}
std::string str = path_.ToString();
if (aliasMatch_.size() < str.length()) {
return aliasDisplay_ + str.substr(aliasMatch_.size());
} else {
return aliasDisplay_;
}
}
#if PPSSPP_PLATFORM(LINUX) || PPSSPP_PLATFORM(MAC)
std::string str = path_.ToString();
#if !PPSSPP_PLATFORM(ANDROID) && (PPSSPP_PLATFORM(LINUX) || PPSSPP_PLATFORM(MAC))
char *home = getenv("HOME");
if (home != nullptr && !strncmp(str.c_str(), home, strlen(home))) {
str = std::string("~") + str.substr(strlen(home));
return std::string("~") + str.substr(strlen(home));
}
#endif
return str;
return path_.ToVisualString();
}
bool PathBrowser::GetListing(std::vector<File::FileInfo> &fileInfo, const char *filter, bool *cancel) {

View file

@ -513,7 +513,12 @@ GameBrowser::GameBrowser(int token, const Path &path, BrowseFlags browseFlags, b
: 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));
Path memstickRoot = GetSysDirectory(DIRECTORY_MEMSTICK_ROOT);
if (memstickRoot == GetSysDirectory(DIRECTORY_PSP)) {
path_.SetRootAlias("ms:/PSP/", memstickRoot);
} else {
path_.SetRootAlias("ms:/", memstickRoot);
}
if (System_GetPropertyBool(SYSPROP_LIMITED_FILE_BROWSING)) {
path_.RestrictToRoot(GetSysDirectory(DIRECTORY_MEMSTICK_ROOT));
}