diff options
author | Zach Hilman <zachhilman@gmail.com> | 2018-09-20 03:54:14 +0200 |
---|---|---|
committer | Zach Hilman <zachhilman@gmail.com> | 2018-09-22 01:53:05 +0200 |
commit | d6cbb3a3e0d89508e53accac1c2b823dae5e8cc2 (patch) | |
tree | a3a84cdbe3dead1399c8c6d4bdf5c2c394be5b73 | |
parent | common_paths: Add Load and Dump dirs (diff) | |
download | yuzu-d6cbb3a3e0d89508e53accac1c2b823dae5e8cc2.tar yuzu-d6cbb3a3e0d89508e53accac1c2b823dae5e8cc2.tar.gz yuzu-d6cbb3a3e0d89508e53accac1c2b823dae5e8cc2.tar.bz2 yuzu-d6cbb3a3e0d89508e53accac1c2b823dae5e8cc2.tar.lz yuzu-d6cbb3a3e0d89508e53accac1c2b823dae5e8cc2.tar.xz yuzu-d6cbb3a3e0d89508e53accac1c2b823dae5e8cc2.tar.zst yuzu-d6cbb3a3e0d89508e53accac1c2b823dae5e8cc2.zip |
-rw-r--r-- | src/core/file_sys/vfs.cpp | 9 | ||||
-rw-r--r-- | src/core/file_sys/vfs.h | 5 | ||||
-rw-r--r-- | src/core/file_sys/vfs_real.cpp | 17 | ||||
-rw-r--r-- | src/core/file_sys/vfs_real.h | 1 |
4 files changed, 32 insertions, 0 deletions
diff --git a/src/core/file_sys/vfs.cpp b/src/core/file_sys/vfs.cpp index d7b52abfd..1ddfb7600 100644 --- a/src/core/file_sys/vfs.cpp +++ b/src/core/file_sys/vfs.cpp @@ -399,6 +399,15 @@ bool VfsDirectory::Copy(std::string_view src, std::string_view dest) { return f2->WriteBytes(f1->ReadAllBytes()) == f1->GetSize(); } +std::map<std::string, VfsEntryType> VfsDirectory::GetEntries() const { + std::map<std::string, VfsEntryType> out; + for (const auto& dir : GetSubdirectories()) + out.emplace(dir->GetName(), VfsEntryType::Directory); + for (const auto& file : GetFiles()) + out.emplace(file->GetName(), VfsEntryType::File); + return out; +} + std::string VfsDirectory::GetFullPath() const { if (IsRoot()) return GetName(); diff --git a/src/core/file_sys/vfs.h b/src/core/file_sys/vfs.h index 74489b452..828e87f38 100644 --- a/src/core/file_sys/vfs.h +++ b/src/core/file_sys/vfs.h @@ -4,6 +4,7 @@ #pragma once +#include <map> #include <memory> #include <string> #include <string_view> @@ -265,6 +266,10 @@ public: // dest. virtual bool Copy(std::string_view src, std::string_view dest); + // Gets all of the entries directly in the directory (files and dirs), returning a map between + // item name -> type. + virtual std::map<std::string, VfsEntryType> GetEntries() const; + // Interprets the file with name file instead as a directory of type directory. // The directory must have a constructor that takes a single argument of type // std::shared_ptr<VfsFile>. Allows to reinterpret container files (i.e NCA, zip, XCI, etc) as a diff --git a/src/core/file_sys/vfs_real.cpp b/src/core/file_sys/vfs_real.cpp index 5e242e20f..a58a02de7 100644 --- a/src/core/file_sys/vfs_real.cpp +++ b/src/core/file_sys/vfs_real.cpp @@ -413,6 +413,23 @@ std::string RealVfsDirectory::GetFullPath() const { return out; } +std::map<std::string, VfsEntryType> RealVfsDirectory::GetEntries() const { + if (perms == Mode::Append) + return {}; + + std::map<std::string, VfsEntryType> out; + FileUtil::ForeachDirectoryEntry( + nullptr, path, + [&out](u64* entries_out, const std::string& directory, const std::string& filename) { + const std::string full_path = directory + DIR_SEP + filename; + out.emplace(filename, FileUtil::IsDirectory(full_path) ? VfsEntryType::Directory + : VfsEntryType::File); + return true; + }); + + return out; +} + bool RealVfsDirectory::ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) { return false; } diff --git a/src/core/file_sys/vfs_real.h b/src/core/file_sys/vfs_real.h index 681c43e82..3af2a6961 100644 --- a/src/core/file_sys/vfs_real.h +++ b/src/core/file_sys/vfs_real.h @@ -98,6 +98,7 @@ public: bool DeleteFile(std::string_view name) override; bool Rename(std::string_view name) override; std::string GetFullPath() const override; + std::map<std::string, VfsEntryType> GetEntries() const override; protected: bool ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) override; |