From 6fd56d140da03ddc45c38567f646140c2f6d24cb Mon Sep 17 00:00:00 2001 From: Ted John Date: Sat, 6 Jan 2018 18:52:12 +0000 Subject: [PATCH] Remove remaining uses of platform_enumerate_files_begin --- src/openrct2-ui/windows/LoadSave.cpp | 23 +++++--------- src/openrct2/Game.cpp | 46 ++++++++++++++-------------- 2 files changed, 31 insertions(+), 38 deletions(-) diff --git a/src/openrct2-ui/windows/LoadSave.cpp b/src/openrct2-ui/windows/LoadSave.cpp index 7bd5dc1eef..b5ddb4c60f 100644 --- a/src/openrct2-ui/windows/LoadSave.cpp +++ b/src/openrct2-ui/windows/LoadSave.cpp @@ -16,10 +16,13 @@ #include #include +#include #include #include #include +#include #include +#include #include #include #include @@ -845,19 +848,12 @@ static void window_loadsave_populate_list(rct_window *w, sint32 includeNewItem, safe_strcat_path(filter, "*", sizeof(filter)); path_append_extension(filter, extToken, sizeof(filter)); - file_info fileInfo; - fileEnumHandle = platform_enumerate_files_begin(filter); - while (platform_enumerate_files_next(fileEnumHandle, &fileInfo)) + auto scanner = std::unique_ptr(Path::ScanDirectory(filter, false)); + while (scanner->Next()) { LoadSaveListItem newListItem; - - char path[MAX_PATH]; - safe_strcpy(path, directory, sizeof(path)); - safe_strcat_path(path, fileInfo.path, sizeof(path)); - - newListItem.path = path; + newListItem.path = scanner->GetPath(); newListItem.type = TYPE_FILE; - newListItem.date_modified = platform_file_get_modified_time(newListItem.path.c_str()); // Cache a human-readable version of the modified date. @@ -870,18 +866,15 @@ static void window_loadsave_populate_list(rct_window *w, sint32 includeNewItem, // Remove the extension (but only the first extension token) if (!showExtension) { - utf8 * removeExt = (utf8 *) fileInfo.path; - path_remove_extension(removeExt); - newListItem.name = String::ToStd(removeExt); + newListItem.name = Path::GetFileNameWithoutExtension(newListItem.path); } else { - newListItem.name = fileInfo.path; + newListItem.name = Path::GetFileName(newListItem.path); } _listItems.push_back(newListItem); } - platform_enumerate_files_end(fileEnumHandle); extToken = strtok(nullptr, ";"); showExtension = true; //Show any extension after the first iteration diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index 1924783ec5..63080b2f1c 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -14,10 +14,12 @@ *****************************************************************************/ #pragma endregion +#include #include "audio/audio.h" #include "Cheats.h" #include "config/Config.h" #include "Context.h" +#include "core/FileScanner.h" #include "core/Math.hpp" #include "core/Util.hpp" #include "Editor.h" @@ -1430,13 +1432,9 @@ static sint32 compare_autosave_file_paths(const void * a, const void * b) static void limit_autosave_count(const size_t numberOfFilesToKeep, bool processLandscapeFolder) { - sint32 fileEnumHandle = 0; - size_t autosavesCount = 0; size_t numAutosavesToDelete = 0; - file_info fileInfo; - utf8 filter[MAX_PATH]; utf8 ** autosaveFiles = nullptr; @@ -1455,12 +1453,13 @@ static void limit_autosave_count(const size_t numberOfFilesToKeep, bool processL } // At first, count how many autosaves there are - fileEnumHandle = platform_enumerate_files_begin(filter); - while (platform_enumerate_files_next(fileEnumHandle, &fileInfo)) { - autosavesCount++; + auto scanner = std::unique_ptr(Path::ScanDirectory(filter, false)); + while (scanner->Next()) + { + autosavesCount++; + } } - platform_enumerate_files_end(fileEnumHandle); // If there are fewer autosaves than the number of files to keep we don't need to delete anything if (autosavesCount <= numberOfFilesToKeep) @@ -1470,27 +1469,28 @@ static void limit_autosave_count(const size_t numberOfFilesToKeep, bool processL autosaveFiles = (utf8 **) malloc(sizeof(utf8 *) * autosavesCount); - fileEnumHandle = platform_enumerate_files_begin(filter); - for (size_t i = 0; i < autosavesCount; i++) { - autosaveFiles[i] = (utf8 *) malloc(sizeof(utf8) * MAX_PATH); - memset(autosaveFiles[i], 0, sizeof(utf8) * MAX_PATH); - - if (platform_enumerate_files_next(fileEnumHandle, &fileInfo)) + auto scanner = std::unique_ptr(Path::ScanDirectory(filter, false)); + for (size_t i = 0; i < autosavesCount; i++) { - if (processLandscapeFolder) + autosaveFiles[i] = (utf8 *)malloc(sizeof(utf8) * MAX_PATH); + memset(autosaveFiles[i], 0, sizeof(utf8) * MAX_PATH); + + if (scanner->Next()) { - platform_get_user_directory(autosaveFiles[i], "landscape", sizeof(utf8) * MAX_PATH); + if (processLandscapeFolder) + { + platform_get_user_directory(autosaveFiles[i], "landscape", sizeof(utf8) * MAX_PATH); + } + else + { + platform_get_user_directory(autosaveFiles[i], "save", sizeof(utf8) * MAX_PATH); + } + safe_strcat_path(autosaveFiles[i], "autosave", sizeof(utf8) * MAX_PATH); + safe_strcat_path(autosaveFiles[i], scanner->GetPathRelative(), sizeof(utf8) * MAX_PATH); } - else - { - platform_get_user_directory(autosaveFiles[i], "save", sizeof(utf8) * MAX_PATH); - } - safe_strcat_path(autosaveFiles[i], "autosave", sizeof(utf8) * MAX_PATH); - safe_strcat_path(autosaveFiles[i], fileInfo.path, sizeof(utf8) * MAX_PATH); } } - platform_enumerate_files_end(fileEnumHandle); qsort(autosaveFiles, autosavesCount, sizeof(char *), compare_autosave_file_paths);