diff options
| author | 2018-09-19 21:57:39 -0400 | |
|---|---|---|
| committer | 2018-09-21 19:53:05 -0400 | |
| commit | c65d4d119fceac4b08530e372d0a6e4ca24f121a (patch) | |
| tree | 9cda6f99f1688215cbbaced529cd61463dc32444 /src | |
| parent | vfs: Add and rewite VfsRawCopy functions (diff) | |
| download | yuzu-c65d4d119fceac4b08530e372d0a6e4ca24f121a.tar.gz yuzu-c65d4d119fceac4b08530e372d0a6e4ca24f121a.tar.xz yuzu-c65d4d119fceac4b08530e372d0a6e4ca24f121a.zip | |
vfs_static: Add StaticVfsFile
Always returns the template argument byte for all reads. Doesn't support writes.
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/core/file_sys/vfs_static.h | 77 |
2 files changed, 78 insertions, 0 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 26f727d96..67d1f9615 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -63,6 +63,7 @@ add_library(core STATIC | |||
| 63 | file_sys/vfs_offset.h | 63 | file_sys/vfs_offset.h |
| 64 | file_sys/vfs_real.cpp | 64 | file_sys/vfs_real.cpp |
| 65 | file_sys/vfs_real.h | 65 | file_sys/vfs_real.h |
| 66 | file_sys/vfs_static.h | ||
| 66 | file_sys/vfs_vector.cpp | 67 | file_sys/vfs_vector.cpp |
| 67 | file_sys/vfs_vector.h | 68 | file_sys/vfs_vector.h |
| 68 | file_sys/xts_archive.cpp | 69 | file_sys/xts_archive.cpp |
diff --git a/src/core/file_sys/vfs_static.h b/src/core/file_sys/vfs_static.h new file mode 100644 index 000000000..5bc8ca52e --- /dev/null +++ b/src/core/file_sys/vfs_static.h | |||
| @@ -0,0 +1,77 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <memory> | ||
| 8 | #include <string_view> | ||
| 9 | |||
| 10 | #include "core/file_sys/vfs.h" | ||
| 11 | |||
| 12 | namespace FileSys { | ||
| 13 | |||
| 14 | template <u8 value> | ||
| 15 | class StaticVfsFile : public VfsFile { | ||
| 16 | public: | ||
| 17 | explicit StaticVfsFile(size_t size = 0, std::string name = "", VirtualDir parent = nullptr) | ||
| 18 | : size(size), name(name), parent(parent) {} | ||
| 19 | |||
| 20 | std::string GetName() const override { | ||
| 21 | return name; | ||
| 22 | } | ||
| 23 | |||
| 24 | size_t GetSize() const override { | ||
| 25 | return size; | ||
| 26 | } | ||
| 27 | |||
| 28 | bool Resize(size_t new_size) override { | ||
| 29 | size = new_size; | ||
| 30 | return true; | ||
| 31 | } | ||
| 32 | |||
| 33 | std::shared_ptr<VfsDirectory> GetContainingDirectory() const override { | ||
| 34 | return parent; | ||
| 35 | } | ||
| 36 | |||
| 37 | bool IsWritable() const override { | ||
| 38 | return false; | ||
| 39 | } | ||
| 40 | |||
| 41 | bool IsReadable() const override { | ||
| 42 | return true; | ||
| 43 | } | ||
| 44 | |||
| 45 | size_t Read(u8* data, size_t length, size_t offset) const override { | ||
| 46 | const auto read = std::min(length, size - offset); | ||
| 47 | std::fill(data, data + read, value); | ||
| 48 | return read; | ||
| 49 | } | ||
| 50 | |||
| 51 | size_t Write(const u8* data, size_t length, size_t offset) override { | ||
| 52 | return 0; | ||
| 53 | } | ||
| 54 | |||
| 55 | boost::optional<u8> ReadByte(size_t offset) const override { | ||
| 56 | if (offset < size) | ||
| 57 | return value; | ||
| 58 | return boost::none; | ||
| 59 | } | ||
| 60 | |||
| 61 | std::vector<u8> ReadBytes(size_t length, size_t offset) const override { | ||
| 62 | const auto read = std::min(length, size - offset); | ||
| 63 | return std::vector<u8>(read, value); | ||
| 64 | } | ||
| 65 | |||
| 66 | bool Rename(std::string_view new_name) override { | ||
| 67 | name = new_name; | ||
| 68 | return true; | ||
| 69 | } | ||
| 70 | |||
| 71 | private: | ||
| 72 | size_t size; | ||
| 73 | std::string name; | ||
| 74 | VirtualDir parent; | ||
| 75 | }; | ||
| 76 | |||
| 77 | } // namespace FileSys | ||