From 9c1fd06c2fa92c96b8cb84ea226b5637d005b12f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 29 Dec 2023 21:34:24 +0100 Subject: [PATCH] Various fixes to PathBrowser etc to handle browsing HTTP subfolders --- Common/File/Path.cpp | 9 ++++----- Common/File/PathBrowser.cpp | 19 ++++++++++++++----- Common/Net/URL.cpp | 6 ++++-- UI/RemoteISOScreen.cpp | 7 ++++++- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/Common/File/Path.cpp b/Common/File/Path.cpp index b9db9aba2c..24bc8bdee0 100644 --- a/Common/File/Path.cpp +++ b/Common/File/Path.cpp @@ -314,17 +314,16 @@ std::string Path::ToVisualString(const char *relativeRoot) const { bool Path::CanNavigateUp() const { if (type_ == PathType::CONTENT_URI) { return AndroidContentURI(path_).CanNavigateUp(); - } - if (path_ == "/" || path_.empty()) { - return false; - } - if (type_ == PathType::HTTP) { + } else if (type_ == PathType::HTTP) { size_t rootSlash = path_.find_first_of('/', strlen("https://")); if (rootSlash == path_.npos || path_.size() == rootSlash + 1) { // This means, "http://server" or "http://server/". Can't go up. return false; } } + if (path_ == "/" || path_.empty()) { + return false; + } return true; } diff --git a/Common/File/PathBrowser.cpp b/Common/File/PathBrowser.cpp index f9c0ba221c..5f29866799 100644 --- a/Common/File/PathBrowser.cpp +++ b/Common/File/PathBrowser.cpp @@ -77,24 +77,33 @@ bool LoadRemoteFileList(const Path &url, const std::string &userAgent, bool *can ERROR_LOG(IO, "Unsupported Content-Type: %s", contentType.c_str()); return false; } - + Path basePath(baseURL.ToString()); for (auto &item : items) { // Apply some workarounds. if (item.empty()) continue; - if (item.back() == '\r') + if (item.back() == '\r') { item.pop_back(); + if (item.empty()) + continue; + } if (item == baseURL.Resource()) continue; File::FileInfo info; + if (item.back() == '/') { + item.pop_back(); + if (item.empty()) + continue; + info.isDirectory = true; + } else { + info.isDirectory = false; + } info.name = item; - info.fullName = Path(baseURL.Relative(item).ToString()); - info.isDirectory = endsWith(item, "/"); + info.fullName = basePath / item; info.exists = true; info.size = 0; info.isWritable = false; - files.push_back(info); } diff --git a/Common/Net/URL.cpp b/Common/Net/URL.cpp index 43e297128a..3280c39cc9 100644 --- a/Common/Net/URL.cpp +++ b/Common/Net/URL.cpp @@ -42,12 +42,14 @@ void Url::Split() { size_t sep = url_.find('/', colonSlashSlash + 3); if (sep == std::string::npos) { - valid_ = false; - return; + sep = url_.size(); } host_ = url_.substr(colonSlashSlash + 3, sep - colonSlashSlash - 3); resource_ = url_.substr(sep); // include the slash! + if (resource_.empty()) { + resource_ = "/"; // Assume what was meant was the root. + } size_t portsep = host_.rfind(':'); if (portsep != host_.npos) { diff --git a/UI/RemoteISOScreen.cpp b/UI/RemoteISOScreen.cpp index 1441dd55e0..f504270711 100644 --- a/UI/RemoteISOScreen.cpp +++ b/UI/RemoteISOScreen.cpp @@ -160,8 +160,13 @@ bool RemoteISOConnectScreen::FindServer(std::string &resultHost, int &resultPort bool supported = false; for (const std::string &item : items) { - if (!RemoteISOFileSupported(item)) { + if (item.empty()) continue; + if (!RemoteISOFileSupported(item)) { + if (item.back() != '/') { + // We accept lists of just directories - we kinda have to. + continue; + } } supported = true; break;