diff options
| author | 2018-09-19 21:54:14 -0400 | |
|---|---|---|
| committer | 2018-09-21 19:53:05 -0400 | |
| commit | d6cbb3a3e0d89508e53accac1c2b823dae5e8cc2 (patch) | |
| tree | a3a84cdbe3dead1399c8c6d4bdf5c2c394be5b73 /src | |
| parent | common_paths: Add Load and Dump dirs (diff) | |
| download | yuzu-d6cbb3a3e0d89508e53accac1c2b823dae5e8cc2.tar.gz yuzu-d6cbb3a3e0d89508e53accac1c2b823dae5e8cc2.tar.xz yuzu-d6cbb3a3e0d89508e53accac1c2b823dae5e8cc2.zip | |
vfs: Add GetEntries method
Maps name string to directory or file.
Diffstat (limited to 'src')
| -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) { | |||
| 399 | return f2->WriteBytes(f1->ReadAllBytes()) == f1->GetSize(); | 399 | return f2->WriteBytes(f1->ReadAllBytes()) == f1->GetSize(); |
| 400 | } | 400 | } |
| 401 | 401 | ||
| 402 | std::map<std::string, VfsEntryType> VfsDirectory::GetEntries() const { | ||
| 403 | std::map<std::string, VfsEntryType> out; | ||
| 404 | for (const auto& dir : GetSubdirectories()) | ||
| 405 | out.emplace(dir->GetName(), VfsEntryType::Directory); | ||
| 406 | for (const auto& file : GetFiles()) | ||
| 407 | out.emplace(file->GetName(), VfsEntryType::File); | ||
| 408 | return out; | ||
| 409 | } | ||
| 410 | |||
| 402 | std::string VfsDirectory::GetFullPath() const { | 411 | std::string VfsDirectory::GetFullPath() const { |
| 403 | if (IsRoot()) | 412 | if (IsRoot()) |
| 404 | return GetName(); | 413 | 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 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <map> | ||
| 7 | #include <memory> | 8 | #include <memory> |
| 8 | #include <string> | 9 | #include <string> |
| 9 | #include <string_view> | 10 | #include <string_view> |
| @@ -265,6 +266,10 @@ public: | |||
| 265 | // dest. | 266 | // dest. |
| 266 | virtual bool Copy(std::string_view src, std::string_view dest); | 267 | virtual bool Copy(std::string_view src, std::string_view dest); |
| 267 | 268 | ||
| 269 | // Gets all of the entries directly in the directory (files and dirs), returning a map between | ||
| 270 | // item name -> type. | ||
| 271 | virtual std::map<std::string, VfsEntryType> GetEntries() const; | ||
| 272 | |||
| 268 | // Interprets the file with name file instead as a directory of type directory. | 273 | // Interprets the file with name file instead as a directory of type directory. |
| 269 | // The directory must have a constructor that takes a single argument of type | 274 | // The directory must have a constructor that takes a single argument of type |
| 270 | // std::shared_ptr<VfsFile>. Allows to reinterpret container files (i.e NCA, zip, XCI, etc) as a | 275 | // 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 { | |||
| 413 | return out; | 413 | return out; |
| 414 | } | 414 | } |
| 415 | 415 | ||
| 416 | std::map<std::string, VfsEntryType> RealVfsDirectory::GetEntries() const { | ||
| 417 | if (perms == Mode::Append) | ||
| 418 | return {}; | ||
| 419 | |||
| 420 | std::map<std::string, VfsEntryType> out; | ||
| 421 | FileUtil::ForeachDirectoryEntry( | ||
| 422 | nullptr, path, | ||
| 423 | [&out](u64* entries_out, const std::string& directory, const std::string& filename) { | ||
| 424 | const std::string full_path = directory + DIR_SEP + filename; | ||
| 425 | out.emplace(filename, FileUtil::IsDirectory(full_path) ? VfsEntryType::Directory | ||
| 426 | : VfsEntryType::File); | ||
| 427 | return true; | ||
| 428 | }); | ||
| 429 | |||
| 430 | return out; | ||
| 431 | } | ||
| 432 | |||
| 416 | bool RealVfsDirectory::ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) { | 433 | bool RealVfsDirectory::ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) { |
| 417 | return false; | 434 | return false; |
| 418 | } | 435 | } |
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: | |||
| 98 | bool DeleteFile(std::string_view name) override; | 98 | bool DeleteFile(std::string_view name) override; |
| 99 | bool Rename(std::string_view name) override; | 99 | bool Rename(std::string_view name) override; |
| 100 | std::string GetFullPath() const override; | 100 | std::string GetFullPath() const override; |
| 101 | std::map<std::string, VfsEntryType> GetEntries() const override; | ||
| 101 | 102 | ||
| 102 | protected: | 103 | protected: |
| 103 | bool ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) override; | 104 | bool ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) override; |