From d771dca3dad90e8a07daa9b6becdf63437a304a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 20 Dec 2020 00:41:28 +0100 Subject: [PATCH] Fix navigation upwards from a pinned game streaming folder. Fixes #13224. --- Common/File/PathBrowser.cpp | 28 +++++++++++++++++++--------- Common/File/PathBrowser.h | 2 ++ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/Common/File/PathBrowser.cpp b/Common/File/PathBrowser.cpp index 712e5a95e6..7cbfa0aa32 100644 --- a/Common/File/PathBrowser.cpp +++ b/Common/File/PathBrowser.cpp @@ -238,20 +238,30 @@ bool PathBrowser::GetListing(std::vector &fileInfo, const char *filter } } +void PathBrowser::NavigateUp() { + // Upwards. + // Check for windows drives. + if (path_.size() == 3 && path_[1] == ':') { + path_ = "/"; + } else if (startsWith(path_, "http://") || startsWith(path_, "https://")) { + // You can actually pin "remote disc streaming" (which I didn't even realize until recently). + // This prevents you from getting the path browser into very weird states: + path_ = "/"; + // It's ok to just go directly to root without more checking since remote disc streaming + // does not yet support folders. + } else { + size_t slash = path_.rfind('/', path_.size() - 2); + if (slash != std::string::npos) + path_ = path_.substr(0, slash + 1); + } +} + // TODO: Support paths like "../../hello" void PathBrowser::Navigate(const std::string &path) { if (path == ".") return; if (path == "..") { - // Upwards. - // Check for windows drives. - if (path_.size() == 3 && path_[1] == ':') { - path_ = "/"; - } else { - size_t slash = path_.rfind('/', path_.size() - 2); - if (slash != std::string::npos) - path_ = path_.substr(0, slash + 1); - } + NavigateUp(); } else { if (path.size() > 2 && path[1] == ':' && path_ == "/") path_ = path; diff --git a/Common/File/PathBrowser.h b/Common/File/PathBrowser.h index 01da52e89f..3f4f21fc3e 100644 --- a/Common/File/PathBrowser.h +++ b/Common/File/PathBrowser.h @@ -22,6 +22,8 @@ public: void SetPath(const std::string &path); bool IsListingReady(); bool GetListing(std::vector &fileInfo, const char *filter = nullptr, bool *cancel = nullptr); + + void NavigateUp(); void Navigate(const std::string &path); std::string GetPath() const {