summaryrefslogtreecommitdiffstats
path: root/src/core/file_sys
diff options
context:
space:
mode:
authorZach Hilman <zachhilman@gmail.com>2018-09-20 03:58:33 +0200
committerZach Hilman <zachhilman@gmail.com>2018-09-22 01:53:05 +0200
commitb52343a428b76ef0fa74c6a939aef7eab33feedb (patch)
tree9cbbc5df26915a7213705644dd39c2cf48512afe /src/core/file_sys
parentvfs_static: Add StaticVfsFile (diff)
downloadyuzu-b52343a428b76ef0fa74c6a939aef7eab33feedb.tar
yuzu-b52343a428b76ef0fa74c6a939aef7eab33feedb.tar.gz
yuzu-b52343a428b76ef0fa74c6a939aef7eab33feedb.tar.bz2
yuzu-b52343a428b76ef0fa74c6a939aef7eab33feedb.tar.lz
yuzu-b52343a428b76ef0fa74c6a939aef7eab33feedb.tar.xz
yuzu-b52343a428b76ef0fa74c6a939aef7eab33feedb.tar.zst
yuzu-b52343a428b76ef0fa74c6a939aef7eab33feedb.zip
Diffstat (limited to 'src/core/file_sys')
-rw-r--r--src/core/file_sys/vfs_vector.cpp51
-rw-r--r--src/core/file_sys/vfs_vector.h24
2 files changed, 75 insertions, 0 deletions
diff --git a/src/core/file_sys/vfs_vector.cpp b/src/core/file_sys/vfs_vector.cpp
index ec7f735b5..efca3d4ad 100644
--- a/src/core/file_sys/vfs_vector.cpp
+++ b/src/core/file_sys/vfs_vector.cpp
@@ -7,6 +7,57 @@
#include "core/file_sys/vfs_vector.h"
namespace FileSys {
+VectorVfsFile::VectorVfsFile(std::vector<u8> initial_data, std::string name, VirtualDir parent)
+ : data(std::move(initial_data)), name(std::move(name)), parent(std::move(parent)) {}
+
+std::string VectorVfsFile::GetName() const {
+ return name;
+}
+
+size_t VectorVfsFile::GetSize() const {
+ return data.size();
+}
+
+bool VectorVfsFile::Resize(size_t new_size) {
+ data.resize(new_size);
+ return data.size() == new_size;
+}
+
+std::shared_ptr<VfsDirectory> VectorVfsFile::GetContainingDirectory() const {
+ return parent;
+}
+
+bool VectorVfsFile::IsWritable() const {
+ return true;
+}
+
+bool VectorVfsFile::IsReadable() const {
+ return true;
+}
+
+size_t VectorVfsFile::Read(u8* data_, size_t length, size_t offset) const {
+ const auto read = std::min(length, data.size() - offset);
+ std::memcpy(data_, data.data() + offset, read);
+ return read;
+}
+
+size_t VectorVfsFile::Write(const u8* data_, size_t length, size_t offset) {
+ if (offset + length > data.size())
+ data.resize(offset + length);
+ const auto write = std::min(length, data.size() - offset);
+ std::memcpy(data.data(), data_, write);
+ return write;
+}
+
+bool VectorVfsFile::Rename(std::string_view name_) {
+ name = name_;
+ return true;
+}
+
+void VectorVfsFile::Assign(std::vector<u8> new_data) {
+ data = new_data;
+}
+
VectorVfsDirectory::VectorVfsDirectory(std::vector<VirtualFile> files_,
std::vector<VirtualDir> dirs_, std::string name_,
VirtualDir parent_)
diff --git a/src/core/file_sys/vfs_vector.h b/src/core/file_sys/vfs_vector.h
index cba44a7a6..c84e137a9 100644
--- a/src/core/file_sys/vfs_vector.h
+++ b/src/core/file_sys/vfs_vector.h
@@ -8,6 +8,30 @@
namespace FileSys {
+// An implementation of VfsFile that is backed by a vector optionally supplied upon construction
+class VectorVfsFile : public VfsFile {
+public:
+ explicit VectorVfsFile(std::vector<u8> initial_data = {}, std::string name = "",
+ VirtualDir parent = nullptr);
+
+ std::string GetName() const override;
+ size_t GetSize() const override;
+ bool Resize(size_t new_size) override;
+ std::shared_ptr<VfsDirectory> GetContainingDirectory() const override;
+ bool IsWritable() const override;
+ bool IsReadable() const override;
+ size_t Read(u8* data, size_t length, size_t offset) const override;
+ size_t Write(const u8* data, size_t length, size_t offset) override;
+ bool Rename(std::string_view name) override;
+
+ virtual void Assign(std::vector<u8> new_data);
+
+private:
+ std::vector<u8> data;
+ VirtualDir parent;
+ std::string name;
+};
+
// An implementation of VfsDirectory that maintains two vectors for subdirectories and files.
// Vector data is supplied upon construction.
class VectorVfsDirectory : public VfsDirectory {