mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-23 23:04:36 +01:00
Extract GetAbsolutePath to Platform
This commit is contained in:
@@ -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<DWORD>(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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<DWORD>(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
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user