|
|
|
@ -16,14 +16,15 @@ namespace FileSys::Fsa {
|
|
|
|
|
|
|
|
|
|
class IDirectory {
|
|
|
|
|
public:
|
|
|
|
|
IDirectory(VirtualDir backend_, OpenDirectoryMode mode) : backend(std::move(backend_)) {
|
|
|
|
|
explicit IDirectory(VirtualDir backend_, OpenDirectoryMode mode)
|
|
|
|
|
: backend(std::move(backend_)) {
|
|
|
|
|
// TODO(DarkLordZach): Verify that this is the correct behavior.
|
|
|
|
|
// Build entry index now to save time later.
|
|
|
|
|
if (True(mode & OpenDirectoryMode::Directory)) {
|
|
|
|
|
BuildEntryIndex(entries, backend->GetSubdirectories(), DirectoryEntryType::Directory);
|
|
|
|
|
BuildEntryIndex(backend->GetSubdirectories(), DirectoryEntryType::Directory);
|
|
|
|
|
}
|
|
|
|
|
if (True(mode & OpenDirectoryMode::File)) {
|
|
|
|
|
BuildEntryIndex(entries, backend->GetFiles(), DirectoryEntryType::File);
|
|
|
|
|
BuildEntryIndex(backend->GetFiles(), DirectoryEntryType::File);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
virtual ~IDirectory() {}
|
|
|
|
@ -45,28 +46,29 @@ public:
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
virtual Result DoRead(s64* out_count, DirectoryEntry* out_entries, s64 max_entries) {
|
|
|
|
|
Result DoRead(s64* out_count, DirectoryEntry* out_entries, s64 max_entries) {
|
|
|
|
|
const u64 actual_entries =
|
|
|
|
|
std::min(static_cast<u64>(max_entries), entries.size() - next_entry_index);
|
|
|
|
|
auto* begin = reinterpret_cast<u8*>(entries.data() + next_entry_index);
|
|
|
|
|
const auto* begin = reinterpret_cast<u8*>(entries.data() + next_entry_index);
|
|
|
|
|
const auto* end = reinterpret_cast<u8*>(entries.data() + next_entry_index + actual_entries);
|
|
|
|
|
const auto range_size = static_cast<std::size_t>(std::distance(begin, end));
|
|
|
|
|
|
|
|
|
|
next_entry_index += actual_entries;
|
|
|
|
|
*out_count = actual_entries;
|
|
|
|
|
|
|
|
|
|
out_entries = reinterpret_cast<DirectoryEntry*>(begin);
|
|
|
|
|
std::memcpy(out_entries, entries.data(), range_size);
|
|
|
|
|
|
|
|
|
|
R_SUCCEED();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual Result DoGetEntryCount(s64* out) {
|
|
|
|
|
Result DoGetEntryCount(s64* out) {
|
|
|
|
|
*out = entries.size() - next_entry_index;
|
|
|
|
|
R_SUCCEED();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: Remove this when VFS is gone
|
|
|
|
|
template <typename T>
|
|
|
|
|
void BuildEntryIndex(std::vector<DirectoryEntry>& entries, const std::vector<T>& new_data,
|
|
|
|
|
DirectoryEntryType type) {
|
|
|
|
|
void BuildEntryIndex(const std::vector<T>& new_data, DirectoryEntryType type) {
|
|
|
|
|
entries.reserve(entries.size() + new_data.size());
|
|
|
|
|
|
|
|
|
|
for (const auto& new_entry : new_data) {
|
|
|
|
|