diff --git a/src/openrct2-ui/windows/LoadSave.cpp b/src/openrct2-ui/windows/LoadSave.cpp index 659939f68e..bc46faf9c1 100644 --- a/src/openrct2-ui/windows/LoadSave.cpp +++ b/src/openrct2-ui/windows/LoadSave.cpp @@ -1087,7 +1087,8 @@ static void WindowLoadsaveSelect(rct_window* w, const char* path) { SetAndSaveConfigPath(gConfigGeneral.last_save_track_directory, pathBuffer); - path_set_extension(pathBuffer, "td6", sizeof(pathBuffer)); + const auto withExtension = Path::WithExtension(pathBuffer, "td6"); + String::Set(pathBuffer, sizeof(pathBuffer), withExtension.c_str()); RCT2::T6Exporter t6Export{ _trackDesign }; diff --git a/src/openrct2/core/Path.cpp b/src/openrct2/core/Path.cpp index 303e45cef0..4814ad7574 100644 --- a/src/openrct2/core/Path.cpp +++ b/src/openrct2/core/Path.cpp @@ -80,6 +80,11 @@ namespace Path return u8path(path).extension().u8string(); } + u8string WithExtension(u8string_view path, u8string_view newExtension) + { + return u8path(path).replace_extension(u8path(newExtension)).u8string(); + } + u8string GetAbsolute(u8string_view relative) { std::error_code ec; diff --git a/src/openrct2/core/Path.hpp b/src/openrct2/core/Path.hpp index d3179ae50b..b32ab85d27 100644 --- a/src/openrct2/core/Path.hpp +++ b/src/openrct2/core/Path.hpp @@ -30,6 +30,7 @@ namespace Path u8string GetFileName(u8string_view origPath); u8string GetFileNameWithoutExtension(u8string_view path); u8string GetExtension(u8string_view path); + u8string WithExtension(u8string_view path, u8string_view newExtension); u8string GetAbsolute(u8string_view relative); bool Equals(u8string_view a, u8string_view b); diff --git a/src/openrct2/util/Util.cpp b/src/openrct2/util/Util.cpp index bbebe2170e..1b4594bc79 100644 --- a/src/openrct2/util/Util.cpp +++ b/src/openrct2/util/Util.cpp @@ -101,15 +101,6 @@ static const char* path_get_filename(const utf8* path) return filename; } -void path_set_extension(utf8* path, const utf8* newExtension, size_t size) -{ - // Remove existing extension (check first if there is one) - if (!Path::GetExtension(path).empty()) - path_remove_extension(path); - // Append new extension - path_append_extension(path, newExtension, size); -} - 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 e62f285baf..327a282716 100644 --- a/src/openrct2/util/Util.h +++ b/src/openrct2/util/Util.h @@ -26,7 +26,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_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); void path_end_with_separator(utf8* path, size_t size);