From 159a76d7ec510fc36fe7e4a1454f3463c8ce0ca1 Mon Sep 17 00:00:00 2001 From: Silent Date: Thu, 10 Mar 2022 10:51:34 +0100 Subject: [PATCH] Refactor uses of safe_strcat_path --- src/openrct2/Game.cpp | 16 +++++----------- src/openrct2/util/Util.cpp | 10 ---------- src/openrct2/util/Util.h | 1 - 3 files changed, 5 insertions(+), 22 deletions(-) diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index 74115e8d20..9baa6162ea 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -601,10 +601,7 @@ static void limit_autosave_count(const size_t numberOfFilesToKeep, bool processL fileFilter = "autosave_*.park"; } - utf8 filter[MAX_PATH]; - safe_strcpy(filter, folderDirectory.c_str(), sizeof(filter)); - safe_strcat_path(filter, "autosave", sizeof(filter)); - safe_strcat_path(filter, fileFilter, sizeof(filter)); + const u8string filter = Path::Combine(folderDirectory, "autosave", fileFilter); // At first, count how many autosaves there are { @@ -621,17 +618,14 @@ static void limit_autosave_count(const size_t numberOfFilesToKeep, bool processL return; } - auto autosaveFiles = std::vector(autosavesCount); + std::vector autosaveFiles; { auto scanner = Path::ScanDirectory(filter, false); for (size_t i = 0; i < autosavesCount; i++) { - autosaveFiles[i].resize(MAX_PATH, 0); if (scanner->Next()) { - safe_strcpy(autosaveFiles[i].data(), folderDirectory.c_str(), sizeof(utf8) * MAX_PATH); - safe_strcat_path(autosaveFiles[i].data(), "autosave", sizeof(utf8) * MAX_PATH); - safe_strcat_path(autosaveFiles[i].data(), scanner->GetPathRelative(), sizeof(utf8) * MAX_PATH); + autosaveFiles.emplace_back(Path::Combine(folderDirectory, "autosave", scanner->GetPathRelative())); } } } @@ -641,11 +635,11 @@ static void limit_autosave_count(const size_t numberOfFilesToKeep, bool processL }); // Calculate how many saves we need to delete. - numAutosavesToDelete = autosavesCount - numberOfFilesToKeep; + numAutosavesToDelete = autosaveFiles.size() - numberOfFilesToKeep; for (size_t i = 0; numAutosavesToDelete > 0; i++, numAutosavesToDelete--) { - if (!File::Delete(autosaveFiles[i].data())) + if (!File::Delete(autosaveFiles[i])) { log_warning("Failed to delete autosave file: %s", autosaveFiles[i].data()); } diff --git a/src/openrct2/util/Util.cpp b/src/openrct2/util/Util.cpp index a644d0c820..9adad3b3dd 100644 --- a/src/openrct2/util/Util.cpp +++ b/src/openrct2/util/Util.cpp @@ -396,16 +396,6 @@ char* safe_strcat(char* destination, const char* source, size_t size) return result; } -char* safe_strcat_path(char* destination, const char* source, size_t size) -{ - path_end_with_separator(destination, size); - if (source[0] == *PATH_SEPARATOR) - { - source = source + 1; - } - return safe_strcat(destination, source, size); -} - #if defined(_WIN32) char* strcasestr(const char* haystack, const char* needle) { diff --git a/src/openrct2/util/Util.h b/src/openrct2/util/Util.h index fe924e624a..ee1b19745b 100644 --- a/src/openrct2/util/Util.h +++ b/src/openrct2/util/Util.h @@ -39,7 +39,6 @@ int32_t strlogicalcmp(char const* a, char const* b); utf8* safe_strtrunc(utf8* text, size_t size); char* safe_strcpy(char* destination, const char* source, size_t num); char* safe_strcat(char* destination, const char* source, size_t size); -char* safe_strcat_path(char* destination, const char* source, size_t size); #if defined(_WIN32) char* strcasestr(const char* haystack, const char* needle); #endif