ISOReader: Fix recursing into subdirectories

This commit is contained in:
Connor McLaughlin 2021-03-02 01:37:14 +10:00
parent 93861f2977
commit f6b8e2121b

View file

@ -1,6 +1,6 @@
#include "iso_reader.h" #include "iso_reader.h"
#include "log.h"
#include "cd_image.h" #include "cd_image.h"
#include "log.h"
#include <cctype> #include <cctype>
Log_SetChannel(ISOReader); Log_SetChannel(ISOReader);
@ -84,12 +84,12 @@ std::optional<ISOReader::ISODirectoryEntry> ISOReader::LocateFile(const char* pa
// strip any leading slashes // strip any leading slashes
const char* path_component_start = path; const char* path_component_start = path;
while (*path_component_start == '/') while (*path_component_start == '/' || *path_component_start == '\\')
path_component_start++; path_component_start++;
u32 path_component_length = 0; u32 path_component_length = 0;
const char* path_component_end = path_component_start; const char* path_component_end = path_component_start;
while (*path_component_end != '\0' && *path_component_end != '/') while (*path_component_end != '\0' && *path_component_end != '/' && *path_component_end != '\\')
{ {
path_component_length++; path_component_length++;
path_component_end++; path_component_end++;
@ -133,12 +133,24 @@ std::optional<ISOReader::ISODirectoryEntry> ISOReader::LocateFile(const char* pa
if (de->filename_length < path_component_length) if (de->filename_length < path_component_length)
continue; continue;
if (de->flags & ISODirectoryEntryFlag_Directory)
{
// directories don't have the version? so check the length instead
if (de->filename_length != path_component_length ||
!FilenamesEqual(de_filename, path_component_start, path_component_length))
{
continue;
}
}
else
{
// compare filename // compare filename
if (!FilenamesEqual(de_filename, path_component_start, path_component_length) || if (!FilenamesEqual(de_filename, path_component_start, path_component_length) ||
de_filename[path_component_length] != ';') de_filename[path_component_length] != ';')
{ {
continue; continue;
} }
}
// found it. is this the file we're looking for? // found it. is this the file we're looking for?
if (*path_component_end == '\0') if (*path_component_end == '\0')