PathBrowser: Show simplified version of paths under the memstick dir.

This commit is contained in:
Henrik Rydgård committed 2020-12-20 01:00:07 +01:00
1 parent d771dca3da
commit aa2f102a0a
2 files changed
+27 -13

No files matched your search

+26
View File
@@ -2,6 +2,8 @@
#include <cstring>
#include <set>
#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<FileInfo> &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> &fileInfo, const char *filter, bool *cancel) {
std::unique_lock<std::mutex> guard(pendingLock_);
while (!IsListingReady() && (!cancel || !*cancel)) {
+1 -13
View File
@@ -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();