From aa2f102a0acd3d85fef4bf89fdd8a9d13791b80a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 20 Dec 2020 01:00:07 +0100 Subject: [PATCH] PathBrowser: Show simplified version of paths under the memstick dir. --- Common/File/PathBrowser.cpp | 26 ++++++++++++++++++++++++++ Common/File/PathBrowser.h | 14 +------------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/Common/File/PathBrowser.cpp b/Common/File/PathBrowser.cpp index 7cbfa0aa32..8f39e12a56 100644 --- a/Common/File/PathBrowser.cpp +++ b/Common/File/PathBrowser.cpp @@ -2,6 +2,8 @@ #include #include +#include "ppsspp_config.h" + #include "Common/Net/HTTPClient.h" #include "Common/Net/URL.h" @@ -11,6 +13,8 @@ #include "Common/Log.h" #include "Common/Thread/ThreadUtil.h" +#include "Core/System.h" + bool LoadRemoteFileList(const std::string &url, bool *cancel, std::vector &files) { http::Client http; Buffer result; @@ -201,6 +205,28 @@ bool PathBrowser::IsListingReady() { return ready_; } +std::string PathBrowser::GetFriendlyPath() const { + std::string str = GetPath(); + // Show relative to memstick root if there. + std::string root = GetSysDirectory(DIRECTORY_MEMSTICK_ROOT); + for (size_t i = 0; i < root.size(); i++) { + if (root[i] == '\\') + root[i] = '/'; + } + + if (startsWith(str, root)) { + return std::string("ms:/") + str.substr(root.size()); + } + +#if 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)); + } +#endif + return str; +} + bool PathBrowser::GetListing(std::vector &fileInfo, const char *filter, bool *cancel) { std::unique_lock guard(pendingLock_); while (!IsListingReady() && (!cancel || !*cancel)) { diff --git a/Common/File/PathBrowser.h b/Common/File/PathBrowser.h index 3f4f21fc3e..43625536db 100644 --- a/Common/File/PathBrowser.h +++ b/Common/File/PathBrowser.h @@ -32,19 +32,7 @@ public: else return ""; } - std::string GetFriendlyPath() const { - std::string str = GetPath(); -#if defined(__ANDROID__) - // Do nothing -#elif defined(__linux) - char *home = getenv("HOME"); - if (home != nullptr && !strncmp(str.c_str(), home, strlen(home))) { - str = str.substr(strlen(home)); - str.insert(0, 1, '~'); - } -#endif - return str; - } + std::string GetFriendlyPath() const; private: void HandlePath();