mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-15 05:47:56 -07:00
Merge pull request #5747 from JosJuice/filesystem-slash
Support leading slashes in FileSystemGCWii::FindFileInfo
This commit is contained in:
commit
d498a9b3d5
@ -270,21 +270,20 @@ std::unique_ptr<FileInfo> FileSystemGCWii::FindFileInfo(const std::string& path,
|
|||||||
// Given a path like "directory1/directory2/fileA.bin", this function will
|
// Given a path like "directory1/directory2/fileA.bin", this function will
|
||||||
// find directory1 and then call itself to search for "directory2/fileA.bin".
|
// find directory1 and then call itself to search for "directory2/fileA.bin".
|
||||||
|
|
||||||
if (path.empty() || path == "/")
|
size_t name_start = 0;
|
||||||
return file_info.clone();
|
while (name_start < path.size() && path[name_start] == '/')
|
||||||
|
++name_start;
|
||||||
|
|
||||||
// It's only possible to search in directories. Searching in a file is an error
|
if (name_start == path.size())
|
||||||
if (!file_info.IsDirectory())
|
return file_info.clone(); // We're done
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
size_t first_dir_separator = path.find('/');
|
const size_t name_end = path.find('/', name_start);
|
||||||
const std::string searching_for = path.substr(0, first_dir_separator);
|
const std::string name = path.substr(name_start, name_end - name_start);
|
||||||
const std::string rest_of_path =
|
const std::string rest_of_path = (name_end != std::string::npos) ? path.substr(name_end + 1) : "";
|
||||||
(first_dir_separator != std::string::npos) ? path.substr(first_dir_separator + 1) : "";
|
|
||||||
|
|
||||||
for (const FileInfo& child : file_info)
|
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.
|
// A match is found. The rest of the path is passed on to finish the search.
|
||||||
std::unique_ptr<FileInfo> result = FindFileInfo(rest_of_path, child);
|
std::unique_ptr<FileInfo> result = FindFileInfo(rest_of_path, child);
|
||||||
|
Loading…
Reference in New Issue
Block a user