diff --git a/src/openrct2/Editor.cpp b/src/openrct2/Editor.cpp index 71ac481da9..15cfd03793 100644 --- a/src/openrct2/Editor.cpp +++ b/src/openrct2/Editor.cpp @@ -19,6 +19,7 @@ #include "actions/LandBuyRightsAction.h" #include "actions/LandSetRightsAction.h" #include "audio/audio.h" +#include "core/Path.hpp" #include "entity/EntityList.h" #include "entity/EntityRegistry.h" #include "entity/Guest.h" @@ -282,7 +283,8 @@ namespace Editor */ static bool ReadS6(const char* path) { - auto extension = path_get_extension(path); + auto extensionS = Path::GetExtension(path); + const char* extension = extensionS.c_str(); auto loadedFromSave = false; if (_stricmp(extension, ".sc6") == 0) { diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 481b5810c1..6539b731fc 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -178,8 +178,8 @@ namespace RCT2 if (path) { - auto extension = path_get_extension(path); - _isSV7 = _stricmp(extension, ".sv7") == 0; + auto extension = Path::GetExtension(path); + _isSV7 = _stricmp(extension.c_str(), ".sv7") == 0; } chunkReader.ReadChunk(&_s6.Objects, sizeof(_s6.Objects)); diff --git a/src/openrct2/util/Util.cpp b/src/openrct2/util/Util.cpp index 35521adf21..2aa0575271 100644 --- a/src/openrct2/util/Util.cpp +++ b/src/openrct2/util/Util.cpp @@ -11,6 +11,7 @@ #include "../common.h" #include "../core/Guard.hpp" +#include "../core/Path.hpp" #include "../interface/Window.h" #include "../localisation/Localisation.h" #include "../platform/platform.h" @@ -100,27 +101,10 @@ const char* path_get_filename(const utf8* path) return filename; } -// Returns the extension (dot inclusive) from the given path, or the end of the -// string when no extension was found. -const char* path_get_extension(const utf8* path) -{ - // Get the filename from the path - const char* filename = path_get_filename(path); - - // Try to find the most-right dot in the filename - char* extension = const_cast(strrchr(filename, '.')); - - // When no dot was found, return a pointer to the null-terminator - if (extension == nullptr) - extension = const_cast(strrchr(filename, '\0')); - - return extension; -} - void path_set_extension(utf8* path, const utf8* newExtension, size_t size) { // Remove existing extension (check first if there is one) - if (path_get_extension(path) < strrchr(path, '\0')) + if (!Path::GetExtension(path).empty()) path_remove_extension(path); // Append new extension path_append_extension(path, newExtension, size); diff --git a/src/openrct2/util/Util.h b/src/openrct2/util/Util.h index 6fa3914a0a..5ac0956e67 100644 --- a/src/openrct2/util/Util.h +++ b/src/openrct2/util/Util.h @@ -26,7 +26,6 @@ bool filename_valid_characters(const utf8* filename); char* path_get_directory(const utf8* path); const char* path_get_filename(const utf8* path); -const char* path_get_extension(const utf8* path); void path_set_extension(utf8* path, const utf8* newExtension, size_t size); void path_append_extension(utf8* path, const utf8* newExtension, size_t size); void path_remove_extension(utf8* path);