From 201248895688605cf6b809ff51cfce2f05a2d40b Mon Sep 17 00:00:00 2001 From: Ted John Date: Fri, 13 May 2022 01:04:39 +0100 Subject: [PATCH] Fix issues with file finding on Linux --- src/openrct2/object/AudioSampleTable.cpp | 11 ++++++---- src/openrct2/object/Object.cpp | 26 +++++++++++++++--------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/openrct2/object/AudioSampleTable.cpp b/src/openrct2/object/AudioSampleTable.cpp index 00f90fd28e..17814ff346 100644 --- a/src/openrct2/object/AudioSampleTable.cpp +++ b/src/openrct2/object/AudioSampleTable.cpp @@ -74,7 +74,7 @@ static SourceInfo ParseSource(std::string_view source) auto env = GetContext()->GetPlatformEnvironment(); auto dataPath = env->GetDirectoryPath(DIRBASE::RCT1, DIRID::DATA); - info.Path = Path::Combine(dataPath, name); + info.Path = Path::ResolveCasing(Path::Combine(dataPath, name)); } else if (String::StartsWith(source, "$RCT2:DATA/")) { @@ -88,7 +88,7 @@ static SourceInfo ParseSource(std::string_view source) auto env = GetContext()->GetPlatformEnvironment(); auto dataPath = env->GetDirectoryPath(DIRBASE::RCT2, DIRID::DATA); - info.Path = Path::Combine(dataPath, name); + info.Path = Path::ResolveCasing(Path::Combine(dataPath, name)); } else if (String::StartsWith(source, "$[")) { @@ -191,8 +191,11 @@ void AudioSampleTable::Unload() { for (auto& entry : _entries) { - entry.Source->Release(); - entry.Source = nullptr; + if (entry.Source != nullptr) + { + entry.Source->Release(); + entry.Source = nullptr; + } } } diff --git a/src/openrct2/object/Object.cpp b/src/openrct2/object/Object.cpp index 451fa42a55..a6d16549cc 100644 --- a/src/openrct2/object/Object.cpp +++ b/src/openrct2/object/Object.cpp @@ -320,19 +320,25 @@ std::vector ObjectAsset::GetData() const std::unique_ptr ObjectAsset::GetStream() const { - if (_zipPath.empty()) + try { - return std::make_unique(_path, FILE_MODE_OPEN); - } - - auto zipArchive = Zip::TryOpen(_zipPath, ZIP_ACCESS::READ); - if (zipArchive != nullptr) - { - auto stream = zipArchive->GetFileStream(_path); - if (stream != nullptr) + if (_zipPath.empty()) { - return std::make_unique(std::move(zipArchive), std::move(stream)); + return std::make_unique(_path, FILE_MODE_OPEN); } + + auto zipArchive = Zip::TryOpen(_zipPath, ZIP_ACCESS::READ); + if (zipArchive != nullptr) + { + auto stream = zipArchive->GetFileStream(_path); + if (stream != nullptr) + { + return std::make_unique(std::move(zipArchive), std::move(stream)); + } + } + } + catch (...) + { } return {}; }