mirror of https://github.com/OpenRCT2/OpenRCT2.git
Remove remaining uses of platform_enumerate_files_begin
This commit is contained in:
parent
d8b3fb01a7
commit
6fd56d140d
|
@ -16,10 +16,13 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include <ctime>
|
||||
#include <memory>
|
||||
#include <openrct2-ui/windows/Window.h>
|
||||
#include <openrct2/config/Config.h>
|
||||
#include <openrct2/Context.h>
|
||||
#include <openrct2/core/FileScanner.h>
|
||||
#include <openrct2/core/Guard.hpp>
|
||||
#include <openrct2/core/Path.hpp>
|
||||
#include <openrct2/core/String.hpp>
|
||||
#include <openrct2/Editor.h>
|
||||
#include <openrct2/Game.h>
|
||||
|
@ -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<IFileScanner>(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
|
||||
|
|
|
@ -14,10 +14,12 @@
|
|||
*****************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#include <memory>
|
||||
#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<IFileScanner>(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<IFileScanner>(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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue