mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-05-24 04:26:25 +12:00
Better FS::ReadDirectory
This commit is contained in:
parent
4f08a2dd7a
commit
42c86ac541
2 changed files with 82 additions and 3 deletions
include/fs
|
@ -116,15 +116,35 @@ struct ArchiveSession {
|
|||
ArchiveSession(ArchiveBase* archive, const FSPath& filePath, bool isOpen = true) : archive(archive), path(filePath), isOpen(isOpen) {}
|
||||
};
|
||||
|
||||
struct DirectoryEntry {
|
||||
std::filesystem::path path;
|
||||
bool isDirectory;
|
||||
};
|
||||
|
||||
struct DirectorySession {
|
||||
ArchiveBase* archive = nullptr;
|
||||
// For directories which are mirrored to a specific path on the disk, this contains that path
|
||||
// Otherwise this is a nullopt
|
||||
std::optional<std::filesystem::path> pathOnDisk;
|
||||
|
||||
// Iterators for traversing the directory in Directory::Read
|
||||
std::vector<DirectoryEntry> entries;
|
||||
size_t currentEntry;
|
||||
|
||||
bool isOpen;
|
||||
|
||||
DirectorySession(ArchiveBase* archive, std::filesystem::path path, bool isOpen = true) : archive(archive), pathOnDisk(path),
|
||||
isOpen(isOpen) {}
|
||||
isOpen(isOpen) {
|
||||
currentEntry = 0; // Start from entry 0
|
||||
|
||||
// Read all directory entries, cache them
|
||||
for (auto& e : std::filesystem::directory_iterator(path)) {
|
||||
DirectoryEntry entry;
|
||||
entry.path = e.path();
|
||||
entry.isDirectory = std::filesystem::is_directory(e);
|
||||
entries.push_back(entry);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Represents a file descriptor obtained from OpenFile. If the optional is nullopt, opening the file failed.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue