1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 11:03:00 +01:00

Remove C string overload for Path::GetAbsolute()

This commit is contained in:
Gymnasiast
2022-01-26 14:54:49 +01:00
parent 0577497c32
commit d7dcffbee8
5 changed files with 17 additions and 29 deletions

View File

@@ -819,9 +819,8 @@ static void WindowLoadsaveSortList()
static void WindowLoadsavePopulateList(rct_window* w, int32_t includeNewItem, const char* directory, const char* extension)
{
utf8 absoluteDirectory[MAX_PATH];
Path::GetAbsolute(absoluteDirectory, std::size(absoluteDirectory), directory);
safe_strcpy(_directory, absoluteDirectory, std::size(_directory));
const auto absoluteDirectory = Path::GetAbsolute(directory);
safe_strcpy(_directory, absoluteDirectory.c_str(), std::size(_directory));
// Note: This compares the pointers, not values
if (_extension != extension)
{
@@ -857,7 +856,7 @@ static void WindowLoadsavePopulateList(rct_window* w, int32_t includeNewItem, co
else
{
// Remove the separator at the end of the path, if present
safe_strcpy(_parentDirectory, absoluteDirectory, std::size(_parentDirectory));
safe_strcpy(_parentDirectory, absoluteDirectory.c_str(), std::size(_parentDirectory));
if (_parentDirectory[strlen(_parentDirectory) - 1] == *PATH_SEPARATOR
|| _parentDirectory[strlen(_parentDirectory) - 1] == '/')
_parentDirectory[strlen(_parentDirectory) - 1] = '\0';

View File

@@ -41,9 +41,8 @@ exitcode_t CommandLine::HandleCommandConvert(CommandLineArgEnumerator* enumerato
return EXITCODE_FAIL;
}
utf8 sourcePath[MAX_PATH];
Path::GetAbsolute(sourcePath, sizeof(sourcePath), rawSourcePath);
uint32_t sourceFileType = get_file_extension_type(sourcePath);
const auto sourcePath = Path::GetAbsolute(rawSourcePath);
uint32_t sourceFileType = get_file_extension_type(sourcePath.c_str());
// Get the destination path
const utf8* rawDestinationPath;
@@ -53,9 +52,8 @@ exitcode_t CommandLine::HandleCommandConvert(CommandLineArgEnumerator* enumerato
return EXITCODE_FAIL;
}
utf8 destinationPath[MAX_PATH];
Path::GetAbsolute(destinationPath, sizeof(sourcePath), rawDestinationPath);
uint32_t destinationFileType = get_file_extension_type(destinationPath);
const auto destinationPath = Path::GetAbsolute(rawDestinationPath);
uint32_t destinationFileType = get_file_extension_type(destinationPath.c_str());
// Validate target type
if (destinationFileType != FILE_EXTENSION_PARK)
@@ -101,7 +99,7 @@ exitcode_t CommandLine::HandleCommandConvert(CommandLineArgEnumerator* enumerato
try
{
auto importer = ParkImporter::Create(sourcePath);
auto loadResult = importer->Load(sourcePath);
auto loadResult = importer->Load(sourcePath.c_str());
objManager.LoadObjects(loadResult.RequiredObjects);

View File

@@ -201,17 +201,15 @@ exitcode_t CommandLine::HandleCommandDefault()
if (_userDataPath != nullptr)
{
utf8 absolutePath[MAX_PATH]{};
Path::GetAbsolute(absolutePath, std::size(absolutePath), _userDataPath);
String::Set(gCustomUserDataPath, std::size(gCustomUserDataPath), absolutePath);
const auto absolutePath = Path::GetAbsolute(_userDataPath);
String::Set(gCustomUserDataPath, std::size(gCustomUserDataPath), absolutePath.c_str());
Memory::Free(_userDataPath);
}
if (_openrct2DataPath != nullptr)
{
utf8 absolutePath[MAX_PATH]{};
Path::GetAbsolute(absolutePath, std::size(absolutePath), _openrct2DataPath);
String::Set(gCustomOpenRCT2DataPath, std::size(gCustomOpenRCT2DataPath), absolutePath);
const auto absolutePath = Path::GetAbsolute(_openrct2DataPath);
String::Set(gCustomOpenRCT2DataPath, std::size(gCustomOpenRCT2DataPath), absolutePath.c_str());
Memory::Free(_openrct2DataPath);
}
@@ -352,14 +350,13 @@ static exitcode_t HandleCommandSetRCT2(CommandLineArgEnumerator* enumerator)
return EXITCODE_FAIL;
}
utf8 path[MAX_PATH];
Path::GetAbsolute(path, sizeof(path), rawPath);
const auto path = Path::GetAbsolute(rawPath);
// Check if path exists
Console::WriteLine("Checking path...");
if (!Path::DirectoryExists(path))
{
Console::Error::WriteLine("The path '%s' does not exist", path);
Console::Error::WriteLine("The path '%s' does not exist", path.c_str());
return EXITCODE_FAIL;
}
@@ -367,7 +364,7 @@ static exitcode_t HandleCommandSetRCT2(CommandLineArgEnumerator* enumerator)
Console::WriteLine("Checking g1.dat...");
utf8 pathG1Check[MAX_PATH];
String::Set(pathG1Check, sizeof(pathG1Check), path);
String::Set(pathG1Check, sizeof(pathG1Check), path.c_str());
Path::Append(pathG1Check, sizeof(pathG1Check), "Data");
Path::Append(pathG1Check, sizeof(pathG1Check), "g1.dat");
if (!File::Exists(pathG1Check))
@@ -385,7 +382,7 @@ static exitcode_t HandleCommandSetRCT2(CommandLineArgEnumerator* enumerator)
gConfigGeneral.rct2_path = std::string(path);
if (config_save(configPath.c_str()))
{
Console::WriteFormat("Updating RCT2 path to '%s'.", path);
Console::WriteFormat("Updating RCT2 path to '%s'.", path.c_str());
Console::WriteLine();
Console::WriteLine("Updated config.ini");
return EXITCODE_OK;

View File

@@ -84,15 +84,10 @@ namespace Path
return u8path(path).extension().u8string();
}
utf8* GetAbsolute(utf8* buffer, size_t bufferSize, const utf8* relativePath)
{
return Platform::GetAbsolutePath(buffer, bufferSize, relativePath);
}
std::string GetAbsolute(std::string_view relative)
{
utf8 absolute[MAX_PATH];
return GetAbsolute(absolute, sizeof(absolute), std::string(relative).c_str());
return Platform::GetAbsolutePath(absolute, sizeof(absolute), std::string(relative).c_str());
}
bool Equals(std::string_view a, std::string_view b)

View File

@@ -31,7 +31,6 @@ namespace Path
std::string GetFileName(std::string_view origPath);
std::string GetFileNameWithoutExtension(std::string_view path);
std::string GetExtension(std::string_view path);
utf8* GetAbsolute(utf8* buffer, size_t bufferSize, const utf8* relativePath);
std::string GetAbsolute(std::string_view relative);
bool Equals(std::string_view a, std::string_view b);