diff --git a/src/openrct2/core/Path.cpp b/src/openrct2/core/Path.cpp index a90be9b6ec..33a3667d28 100644 --- a/src/openrct2/core/Path.cpp +++ b/src/openrct2/core/Path.cpp @@ -7,10 +7,7 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ -#include -#ifndef _WIN32 -# include -#endif +#include "Path.hpp" #include "../localisation/Language.h" #include "../platform/Platform2.h" @@ -19,9 +16,9 @@ #include "File.h" #include "FileSystem.hpp" #include "Memory.hpp" -#include "Path.hpp" #include "String.hpp" +#include #include namespace Path @@ -217,42 +214,6 @@ namespace Path std::string ResolveCasing(const std::string& path) { - std::string result; - if (File::Exists(path)) - { - // Windows is case insensitive so it will exist and that is all that matters - // for now. We can properly resolve the casing if we ever need to. - result = path; - } -#ifndef _WIN32 - else - { - std::string fileName = Path::GetFileName(path); - std::string directory = Path::GetDirectory(path); - - struct dirent** files; - auto count = scandir(directory.c_str(), &files, nullptr, alphasort); - if (count != -1) - { - // Find a file which matches by name (case insensitive) - for (int32_t i = 0; i < count; i++) - { - if (String::Equals(files[i]->d_name, fileName.c_str(), true)) - { - result = Path::Combine(directory, std::string(files[i]->d_name)); - break; - } - } - - // Free memory - for (int32_t i = 0; i < count; i++) - { - free(files[i]); - } - free(files); - } - } -#endif - return result; + return Platform::ResolveCasing(path, File::Exists(path)); } } // namespace Path diff --git a/src/openrct2/platform/Platform.Posix.cpp b/src/openrct2/platform/Platform.Posix.cpp index 52fd7149da..9948a8fa55 100644 --- a/src/openrct2/platform/Platform.Posix.cpp +++ b/src/openrct2/platform/Platform.Posix.cpp @@ -10,6 +10,7 @@ #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD__) # include "../core/Memory.hpp" +# include "../core/Path.hpp" # include "../core/String.hpp" # include "Platform2.h" # include "platform.h" @@ -18,6 +19,7 @@ # include # include # include +# include # include # include @@ -199,6 +201,45 @@ namespace Platform return buffer; } } + + std::string ResolveCasing(const std::string& path, bool fileExists) + { + std::string result; + if (fileExists) + { + // Windows is case insensitive so it will exist and that is all that matters + // for now. We can properly resolve the casing if we ever need to. + result = path; + } + else + { + std::string fileName = Path::GetFileName(path); + std::string directory = Path::GetDirectory(path); + + struct dirent** files; + auto count = scandir(directory.c_str(), &files, nullptr, alphasort); + if (count != -1) + { + // Find a file which matches by name (case insensitive) + for (int32_t i = 0; i < count; i++) + { + if (String::Equals(files[i]->d_name, fileName.c_str(), true)) + { + result = Path::Combine(directory, std::string(files[i]->d_name)); + break; + } + } + + // Free memory + for (int32_t i = 0; i < count; i++) + { + free(files[i]); + } + free(files); + } + } + return result; + } } // namespace Platform #endif diff --git a/src/openrct2/platform/Platform.Win32.cpp b/src/openrct2/platform/Platform.Win32.cpp index a1fd9fc8e0..02f9be341d 100644 --- a/src/openrct2/platform/Platform.Win32.cpp +++ b/src/openrct2/platform/Platform.Win32.cpp @@ -582,6 +582,17 @@ namespace Platform } } + std::string ResolveCasing(const std::string& path, bool fileExists) + { + std::string result; + if (fileExists) + { + // Windows is case insensitive so it will exist and that is all that matters + // for now. We can properly resolve the casing if we ever need to. + result = path; + } + return result; + } } // namespace Platform #endif diff --git a/src/openrct2/platform/Platform2.h b/src/openrct2/platform/Platform2.h index 79c0b3f77a..9a2daaba83 100644 --- a/src/openrct2/platform/Platform2.h +++ b/src/openrct2/platform/Platform2.h @@ -39,6 +39,7 @@ namespace Platform bool IsPathSeparator(char c); utf8* GetAbsolutePath(utf8* buffer, size_t bufferSize, const utf8* relativePath); uint64_t GetLastModified(const std::string& path); + std::string ResolveCasing(const std::string& path, bool fileExists); rct2_time GetTimeLocal(); rct2_date GetDateLocal(); bool FindApp(const std::string& app, std::string* output);