mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-11-25 16:25:39 +01:00
vfs_vector: Add VectorVfsFile
Maps a vector into the VFS interface.
This commit is contained in:
parent
c65d4d119f
commit
b52343a428
@ -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_)
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user