mirror of https://github.com/OpenRCT2/OpenRCT2.git
Refactor uses of safe_strcat_path
This commit is contained in:
parent
3773fa4cb0
commit
159a76d7ec
|
@ -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<std::string>(autosavesCount);
|
||||
std::vector<u8string> 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());
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue