diff --git a/src/openrct2/core/Path.cpp b/src/openrct2/core/Path.cpp index 4f8f42fb76..e45e1b2e1b 100644 --- a/src/openrct2/core/Path.cpp +++ b/src/openrct2/core/Path.cpp @@ -196,34 +196,7 @@ namespace Path utf8* GetAbsolute(utf8* buffer, size_t bufferSize, const utf8* relativePath) { -#ifdef _WIN32 - auto relativePathW = String::ToWideChar(relativePath); - wchar_t absolutePathW[MAX_PATH]; - DWORD length = GetFullPathNameW( - relativePathW.c_str(), static_cast(std::size(absolutePathW)), absolutePathW, nullptr); - if (length == 0) - { - return String::Set(buffer, bufferSize, relativePath); - } - else - { - auto absolutePath = String::ToUtf8(absolutePathW); - String::Set(buffer, bufferSize, absolutePath.c_str()); - return buffer; - } -#else - utf8* absolutePath = realpath(relativePath, nullptr); - if (absolutePath == nullptr) - { - return String::Set(buffer, bufferSize, relativePath); - } - else - { - String::Set(buffer, bufferSize, absolutePath); - Memory::Free(absolutePath); - return buffer; - } -#endif + return Platform::GetAbsolutePath(buffer, bufferSize, relativePath); } std::string GetAbsolute(const std::string& relative) diff --git a/src/openrct2/platform/Platform.Posix.cpp b/src/openrct2/platform/Platform.Posix.cpp index fbad60a74e..f1ae448934 100644 --- a/src/openrct2/platform/Platform.Posix.cpp +++ b/src/openrct2/platform/Platform.Posix.cpp @@ -9,6 +9,7 @@ #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD__) +# include "../core/Memory.hpp" # include "../core/String.hpp" # include "Platform2.h" # include "platform.h" @@ -178,6 +179,21 @@ namespace Platform { return c == '/'; } + + utf8* GetAbsolutePath(utf8* buffer, size_t bufferSize, const utf8* relativePath) + { + utf8* absolutePath = realpath(relativePath, nullptr); + if (absolutePath == nullptr) + { + return String::Set(buffer, bufferSize, relativePath); + } + else + { + String::Set(buffer, bufferSize, absolutePath); + Memory::Free(absolutePath); + return buffer; + } + } } // namespace Platform #endif diff --git a/src/openrct2/platform/Platform.Win32.cpp b/src/openrct2/platform/Platform.Win32.cpp index cb99189578..f898911f1b 100644 --- a/src/openrct2/platform/Platform.Win32.cpp +++ b/src/openrct2/platform/Platform.Win32.cpp @@ -559,6 +559,24 @@ namespace Platform return c == '\\' || c == '/'; } + utf8* GetAbsolutePath(utf8* buffer, size_t bufferSize, const utf8* relativePath) + { + auto relativePathW = String::ToWideChar(relativePath); + wchar_t absolutePathW[MAX_PATH]; + DWORD length = GetFullPathNameW( + relativePathW.c_str(), static_cast(std::size(absolutePathW)), absolutePathW, nullptr); + if (length == 0) + { + return String::Set(buffer, bufferSize, relativePath); + } + else + { + auto absolutePath = String::ToUtf8(absolutePathW); + String::Set(buffer, bufferSize, absolutePath.c_str()); + return buffer; + } + } + } // namespace Platform #endif diff --git a/src/openrct2/platform/Platform2.h b/src/openrct2/platform/Platform2.h index d09fade07a..91c159fa05 100644 --- a/src/openrct2/platform/Platform2.h +++ b/src/openrct2/platform/Platform2.h @@ -36,6 +36,7 @@ namespace Platform std::string GetCurrentExecutableDirectory(); bool FileExists(const std::string path); bool IsPathSeparator(char c); + utf8* GetAbsolutePath(utf8* buffer, size_t bufferSize, const utf8* relativePath); uint64_t GetLastModified(const std::string& path); rct2_time GetTimeLocal(); rct2_date GetDateLocal();