From 6a31d2598e1273dc40a0149821345107368f6502 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Tue, 4 Jul 2017 20:25:53 +0200 Subject: [PATCH 1/2] Support leading slashes in FileSystemGCWii::FindFileInfo --- Source/Core/DiscIO/FileSystemGCWii.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Source/Core/DiscIO/FileSystemGCWii.cpp b/Source/Core/DiscIO/FileSystemGCWii.cpp index bbc89cfc15..6abcc016e0 100644 --- a/Source/Core/DiscIO/FileSystemGCWii.cpp +++ b/Source/Core/DiscIO/FileSystemGCWii.cpp @@ -270,21 +270,24 @@ std::unique_ptr FileSystemGCWii::FindFileInfo(const std::string& path, // Given a path like "directory1/directory2/fileA.bin", this function will // find directory1 and then call itself to search for "directory2/fileA.bin". - if (path.empty() || path == "/") - return file_info.clone(); + size_t name_start = 0; + while (name_start < path.size() && path[name_start] == '/') + ++name_start; + + if (name_start == path.size()) + return file_info.clone(); // We're done // It's only possible to search in directories. Searching in a file is an error if (!file_info.IsDirectory()) return nullptr; - size_t first_dir_separator = path.find('/'); - const std::string searching_for = path.substr(0, first_dir_separator); - const std::string rest_of_path = - (first_dir_separator != std::string::npos) ? path.substr(first_dir_separator + 1) : ""; + const size_t name_end = path.find('/', name_start); + const std::string name = path.substr(name_start, name_end - name_start); + const std::string rest_of_path = (name_end != std::string::npos) ? path.substr(name_end + 1) : ""; for (const FileInfo& child : file_info) { - if (!strcasecmp(child.GetName().c_str(), searching_for.c_str())) + if (!strcasecmp(child.GetName().c_str(), name.c_str())) { // A match is found. The rest of the path is passed on to finish the search. std::unique_ptr result = FindFileInfo(rest_of_path, child); From 93e974068328d435792ade46e7488fe1009c6584 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Tue, 4 Jul 2017 20:27:18 +0200 Subject: [PATCH 2/2] Drop unnecessary check from FileSystemGCWii::FindFileInfo If the current file_info is a file, the ranged for loop will run 0 times, and we'll reach the last line of the function. --- Source/Core/DiscIO/FileSystemGCWii.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Source/Core/DiscIO/FileSystemGCWii.cpp b/Source/Core/DiscIO/FileSystemGCWii.cpp index 6abcc016e0..fca68113ba 100644 --- a/Source/Core/DiscIO/FileSystemGCWii.cpp +++ b/Source/Core/DiscIO/FileSystemGCWii.cpp @@ -277,10 +277,6 @@ std::unique_ptr FileSystemGCWii::FindFileInfo(const std::string& path, if (name_start == path.size()) return file_info.clone(); // We're done - // It's only possible to search in directories. Searching in a file is an error - if (!file_info.IsDirectory()) - return nullptr; - const size_t name_end = path.find('/', name_start); const std::string name = path.substr(name_start, name_end - name_start); const std::string rest_of_path = (name_end != std::string::npos) ? path.substr(name_end + 1) : "";