summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/core/CMakeLists.txt1
-rw-r--r--src/core/file_sys/vfs_static.h77
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
file_sys/vfs_offset.h
file_sys/vfs_real.cpp
file_sys/vfs_real.h
+ file_sys/vfs_static.h
file_sys/vfs_vector.cpp
file_sys/vfs_vector.h
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 @@
+// Copyright 2018 yuzu emulator team
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include <memory>
+#include <string_view>
+
+#include "core/file_sys/vfs.h"
+
+namespace FileSys {
+
+template <u8 value>
+class StaticVfsFile : public VfsFile {
+public:
+ explicit StaticVfsFile(size_t size = 0, std::string name = "", VirtualDir parent = nullptr)
+ : size(size), name(name), parent(parent) {}
+
+ std::string GetName() const override {
+ return name;
+ }
+
+ size_t GetSize() const override {
+ return size;
+ }
+
+ bool Resize(size_t new_size) override {
+ size = new_size;
+ return true;
+ }
+
+ std::shared_ptr<VfsDirectory> GetContainingDirectory() const override {
+ return parent;
+ }
+
+ bool IsWritable() const override {
+ return false;
+ }
+
+ bool IsReadable() const override {
+ return true;
+ }
+
+ size_t Read(u8* data, size_t length, size_t offset) const override {
+ const auto read = std::min(length, size - offset);
+ std::fill(data, data + read, value);
+ return read;
+ }
+
+ size_t Write(const u8* data, size_t length, size_t offset) override {
+ return 0;
+ }
+
+ boost::optional<u8> ReadByte(size_t offset) const override {
+ if (offset < size)
+ return value;
+ return boost::none;
+ }
+
+ std::vector<u8> ReadBytes(size_t length, size_t offset) const override {
+ const auto read = std::min(length, size - offset);
+ return std::vector<u8>(read, value);
+ }
+
+ bool Rename(std::string_view new_name) override {
+ name = new_name;
+ return true;
+ }
+
+private:
+ size_t size;
+ std::string name;
+ VirtualDir parent;
+};
+
+} // namespace FileSys