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

Replace path_get_directory()

This commit is contained in:
Gymnasiast
2022-02-26 17:51:05 +01:00
parent 33edc59883
commit 060c430c64
3 changed files with 2 additions and 44 deletions

View File

@@ -579,7 +579,7 @@ int32_t cmdline_for_sprite(const char** argv, int32_t argc)
const char* spriteFilePath = argv[1];
const char* spriteDescriptionPath = argv[2];
char* directoryPath = path_get_directory(spriteDescriptionPath);
const auto directoryPath = Path::GetDirectory(spriteDescriptionPath);
json_t jsonSprites = Json::ReadFromFile(spriteDescriptionPath);
if (jsonSprites.is_null())
@@ -630,7 +630,7 @@ int32_t cmdline_for_sprite(const char** argv, int32_t argc)
: ImageImporter::Palette::OpenRCT2;
bool forceBmp = !jsonSprite["palette"].is_null() && Json::GetBoolean(jsonSprite["forceBmp"]);
auto imagePath = Path::GetAbsolute(std::string(directoryPath) + "/" + strPath);
auto imagePath = Path::GetAbsolute(directoryPath + u8"/" + strPath);
auto importResult = SpriteImageImport(
imagePath.c_str(), Json::GetNumber<int16_t>(x_offset), Json::GetNumber<int16_t>(y_offset), palette, forceBmp,
@@ -653,8 +653,6 @@ int32_t cmdline_for_sprite(const char** argv, int32_t argc)
return -1;
}
free(directoryPath);
fprintf(stdout, "Finished\n");
return 1;
}

View File

@@ -62,45 +62,6 @@ bool filename_valid_characters(const utf8* filename)
return true;
}
utf8* path_get_directory(const utf8* path)
{
// Find the last slash or backslash in the path
char* filename = const_cast<char*>(strrchr(path, *PATH_SEPARATOR));
char* filename_posix = const_cast<char*>(strrchr(path, '/'));
filename = filename < filename_posix ? filename_posix : filename;
// If the path is invalid (e.g. just a file name), return NULL
if (filename == nullptr)
{
return nullptr;
}
char* directory = _strdup(path);
safe_strtrunc(directory, strlen(path) - strlen(filename) + 2);
return directory;
}
static const char* path_get_filename(const utf8* path)
{
// Find last slash or backslash in the path
char* filename = const_cast<char*>(strrchr(path, *PATH_SEPARATOR));
char* filename_posix = const_cast<char*>(strchr(path, '/'));
filename = filename < filename_posix ? filename_posix : filename;
// Checks if the path is valid (e.g. not just a file name)
if (filename == nullptr)
{
// Return the input string to keep things working
return path;
}
// Increase pointer by one, to get rid of the slashes
filename++;
return filename;
}
void path_append_extension(utf8* path, const utf8* newExtension, size_t size)
{
// Skip to the dot if the extension starts with a pattern (starts with "*.")

View File

@@ -25,7 +25,6 @@ int32_t mph_to_dmps(int32_t mph);
bool filename_valid_characters(const utf8* filename);
char* path_get_directory(const utf8* path);
void path_append_extension(utf8* path, const utf8* newExtension, size_t size);
void path_end_with_separator(utf8* path, size_t size);