mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-15 11:03:00 +01:00
Replace platform_enumerate_directories_begin with FileScanner code
This is isn't a particularly pretty implementation but it is only temporary until we can use std::filesystem.
This commit is contained in:
committed by
Michael Steenbeek
parent
6fd56d140d
commit
cb720025fa
@@ -816,24 +816,19 @@ static void window_loadsave_populate_list(rct_window *w, sint32 includeNewItem,
|
||||
w->disabled_widgets &= ~(1 << WIDX_NEW_FOLDER);
|
||||
|
||||
// List all directories
|
||||
char subDir[MAX_PATH];
|
||||
sint32 fileEnumHandle = platform_enumerate_directories_begin(directory);
|
||||
while (platform_enumerate_directories_next(fileEnumHandle, subDir))
|
||||
auto subDirectories = Path::GetDirectories(directory);
|
||||
for (const auto &sdName : subDirectories)
|
||||
{
|
||||
auto subDir = sdName + PATH_SEPARATOR;
|
||||
|
||||
LoadSaveListItem newListItem;
|
||||
|
||||
char path[MAX_PATH];
|
||||
safe_strcpy(path, directory, sizeof(path));
|
||||
safe_strcat_path(path, subDir, sizeof(path));
|
||||
|
||||
newListItem.path = path;
|
||||
newListItem.path = Path::Combine(directory, subDir);
|
||||
newListItem.name = subDir;
|
||||
newListItem.type = TYPE_DIRECTORY;
|
||||
newListItem.loaded = false;
|
||||
|
||||
_listItems.push_back(newListItem);
|
||||
}
|
||||
platform_enumerate_files_end(fileEnumHandle);
|
||||
|
||||
// List all files with the wanted extensions
|
||||
char filter[MAX_PATH];
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "../localisation/Language.h"
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
#include <stack>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -170,6 +171,8 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual void GetDirectoryChildren(std::vector<DirectoryChild> &children, const std::string &path) abstract;
|
||||
|
||||
private:
|
||||
void PushState(const std::string &directory)
|
||||
{
|
||||
@@ -219,10 +222,6 @@ private:
|
||||
patterns.shrink_to_fit();
|
||||
return patterns;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void GetDirectoryChildren(std::vector<DirectoryChild> &children, const std::string &path) abstract;
|
||||
|
||||
};
|
||||
|
||||
#ifdef _WIN32
|
||||
@@ -235,7 +234,6 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
void GetDirectoryChildren(std::vector<DirectoryChild> &children, const std::string &path) override
|
||||
{
|
||||
std::string pattern = path + "\\*";
|
||||
@@ -296,7 +294,6 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
void GetDirectoryChildren(std::vector<DirectoryChild> &children, const std::string &path) override
|
||||
{
|
||||
struct dirent * * namelist;
|
||||
@@ -391,6 +388,25 @@ void Path::QueryDirectory(QueryDirectoryResult * result, const std::string &patt
|
||||
delete scanner;
|
||||
}
|
||||
|
||||
std::vector<std::string> Path::GetDirectories(const std::string &path)
|
||||
{
|
||||
auto scanner = std::unique_ptr<IFileScanner>(ScanDirectory(path, false));
|
||||
auto baseScanner = static_cast<FileScannerBase *>(scanner.get());
|
||||
|
||||
std::vector<DirectoryChild> children;
|
||||
baseScanner->GetDirectoryChildren(children, path);
|
||||
|
||||
std::vector<std::string> subDirectories;
|
||||
for (const auto &c : children)
|
||||
{
|
||||
if (c.Type == DIRECTORY_CHILD_TYPE::DC_DIRECTORY)
|
||||
{
|
||||
subDirectories.push_back(c.Name);
|
||||
}
|
||||
}
|
||||
return subDirectories;
|
||||
}
|
||||
|
||||
static uint32 GetPathChecksum(const utf8 * path)
|
||||
{
|
||||
uint32 hash = 0xD8430DED;
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "../common.h"
|
||||
|
||||
struct FileInfo
|
||||
@@ -66,6 +67,8 @@ namespace Path
|
||||
* @returns An aggregated result of all scanned files.
|
||||
*/
|
||||
void QueryDirectory(QueryDirectoryResult * result, const std::string &pattern);
|
||||
|
||||
std::vector<std::string> GetDirectories(const std::string &path);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user