Search ObjData recursively

Enable recursive searching ObjData for Windows and non-Windows. This allows players to continue using sub directories for their official objects, e.g. WW and TT. There will be a slight performance hit if all objects are in a sub directory as a search is done for each official object that is loaded.
This commit is contained in:
Ted John 2018-04-08 19:03:33 +01:00
parent 9dba4a87cc
commit dea5d2754b
1 changed files with 4 additions and 7 deletions

View File

@ -212,24 +212,21 @@ namespace ObjectJsonHelpers
const auto env = GetContext()->GetPlatformEnvironment(); const auto env = GetContext()->GetPlatformEnvironment();
auto objectsPath = env->GetDirectoryPath(DIRBASE::RCT2, DIRID::OBJECT); auto objectsPath = env->GetDirectoryPath(DIRBASE::RCT2, DIRID::OBJECT);
auto objectPath = Path::Combine(objectsPath, name); auto objectPath = Path::Combine(objectsPath, name);
#ifndef _WIN32
if (!File::Exists(objectPath)) if (!File::Exists(objectPath))
{ {
// UNIX based systems need to search for any files with the same name // Search recursively for any file with the target name (case insensitive)
// due to case sensitivity.
auto filter = Path::Combine(objectsPath, "*.dat"); auto filter = Path::Combine(objectsPath, "*.dat");
auto scanner = std::unique_ptr<IFileScanner>(Path::ScanDirectory(filter, false)); auto scanner = std::unique_ptr<IFileScanner>(Path::ScanDirectory(filter, true));
while (scanner->Next()) while (scanner->Next())
{ {
auto relativePath = scanner->GetPathRelative(); auto currentName = Path::GetFileName(scanner->GetPathRelative());
if (String::Equals(relativePath, name, true)) if (String::Equals(currentName, name, true))
{ {
objectPath = scanner->GetPath(); objectPath = scanner->GetPath();
break; break;
} }
} }
} }
#endif
return objectPath; return objectPath;
} }