From a9ba2c2000d9f2e4c6018aa6fc1e754eca82f72c Mon Sep 17 00:00:00 2001 From: Subv Date: Mon, 19 Mar 2018 22:58:55 -0500 Subject: FS: Updated the Directory Entry structure to match the Switch. --- src/core/file_sys/disk_filesystem.cpp | 48 ++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 6 deletions(-) (limited to 'src/core/file_sys/disk_filesystem.cpp') diff --git a/src/core/file_sys/disk_filesystem.cpp b/src/core/file_sys/disk_filesystem.cpp index 9d456e0bf..e2092b9df 100644 --- a/src/core/file_sys/disk_filesystem.cpp +++ b/src/core/file_sys/disk_filesystem.cpp @@ -153,14 +153,50 @@ bool Disk_Storage::SetSize(const u64 size) const { return false; } -u32 Disk_Directory::Read(const u32 count, Entry* entries) { - LOG_WARNING(Service_FS, "(STUBBED) called"); - return 0; +Disk_Directory::Disk_Directory(const std::string& path) : directory() { + unsigned size = FileUtil::ScanDirectoryTree(path, directory); + directory.size = size; + directory.isDirectory = true; + children_iterator = directory.children.begin(); +} + +u64 Disk_Directory::Read(const u64 count, Entry* entries) { + u64 entries_read = 0; + + while (entries_read < count && children_iterator != directory.children.cend()) { + const FileUtil::FSTEntry& file = *children_iterator; + const std::string& filename = file.virtualName; + Entry& entry = entries[entries_read]; + + LOG_TRACE(Service_FS, "File %s: size=%llu dir=%d", filename.c_str(), file.size, + file.isDirectory); + + // TODO(Link Mauve): use a proper conversion to UTF-16. + for (size_t j = 0; j < FILENAME_LENGTH; ++j) { + entry.filename[j] = filename[j]; + if (!filename[j]) + break; + } + + if (file.isDirectory) { + entry.file_size = 0; + entry.type = EntryType::Directory; + } else { + entry.file_size = file.size; + entry.type = EntryType::File; + } + + ++entries_read; + ++children_iterator; + } + return entries_read; } -bool Disk_Directory::Close() const { - LOG_WARNING(Service_FS, "(STUBBED) called"); - return true; +u64 Disk_Directory::GetEntryCount() const { + // We convert the children iterator into a const_iterator to allow template argument deduction + // in std::distance. + std::vector::const_iterator current = children_iterator; + return std::distance(current, directory.children.end()); } } // namespace FileSys -- cgit v1.2.3