Skip to content

Commit

Permalink
Various fixes to PathBrowser etc to handle browsing HTTP subfolders
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Dec 29, 2023
1 parent 80bd328 commit 9c1fd06
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
9 changes: 4 additions & 5 deletions Common/File/Path.cpp
Expand Up @@ -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;
}

Expand Down
19 changes: 14 additions & 5 deletions Common/File/PathBrowser.cpp
Expand Up @@ -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);
}

Expand Down
6 changes: 4 additions & 2 deletions Common/Net/URL.cpp
Expand Up @@ -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) {
Expand Down
7 changes: 6 additions & 1 deletion UI/RemoteISOScreen.cpp
Expand Up @@ -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;
Expand Down

0 comments on commit 9c1fd06

Please sign in to comment.