From 060c430c64da2b2cd56a8f21aa296fa8eb6b7883 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Sat, 26 Feb 2022 17:51:05 +0100 Subject: [PATCH] Replace path_get_directory() --- src/openrct2/CmdlineSprite.cpp | 6 ++---- src/openrct2/util/Util.cpp | 39 ---------------------------------- src/openrct2/util/Util.h | 1 - 3 files changed, 2 insertions(+), 44 deletions(-) diff --git a/src/openrct2/CmdlineSprite.cpp b/src/openrct2/CmdlineSprite.cpp index b3a68580a7..cc2301841e 100644 --- a/src/openrct2/CmdlineSprite.cpp +++ b/src/openrct2/CmdlineSprite.cpp @@ -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(x_offset), Json::GetNumber(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; } diff --git a/src/openrct2/util/Util.cpp b/src/openrct2/util/Util.cpp index e2c0ca2ac6..cfe793ea19 100644 --- a/src/openrct2/util/Util.cpp +++ b/src/openrct2/util/Util.cpp @@ -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(strrchr(path, *PATH_SEPARATOR)); - char* filename_posix = const_cast(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(strrchr(path, *PATH_SEPARATOR)); - char* filename_posix = const_cast(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 "*.") diff --git a/src/openrct2/util/Util.h b/src/openrct2/util/Util.h index 12932b0f34..5491f65ac4 100644 --- a/src/openrct2/util/Util.h +++ b/src/openrct2/util/Util.h @@ -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);