diff options
| author | liamwhite <liamwhite@users.noreply.github.com> | 2024-01-26 09:55:25 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-26 09:55:25 -0500 |
| commit | 55482ab5dce463d5014498b006c18a90d0d004e6 (patch) | |
| tree | b343faa9cadc692265efb4b6b88e157c97ef76d2 /src/core/file_sys/vfs/vfs_static.h | |
| parent | 4526fdaf642d092ce1a6f5b1da4adf5eb4793005 (diff) | |
| parent | 975deb7528cd98460528553f6a9162bfbcd6cab1 (diff) | |
Merge pull request #12707 from FearlessTobi/fs-housekeeping
fs: Various cleanups & add path class for later use
Diffstat (limited to 'src/core/file_sys/vfs/vfs_static.h')
| -rw-r--r-- | src/core/file_sys/vfs/vfs_static.h | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/core/file_sys/vfs/vfs_static.h b/src/core/file_sys/vfs/vfs_static.h new file mode 100644 index 000000000..bb53560ac --- /dev/null +++ b/src/core/file_sys/vfs/vfs_static.h @@ -0,0 +1,80 @@ +// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include <algorithm> +#include <memory> +#include <string_view> + +#include "core/file_sys/vfs/vfs.h" + +namespace FileSys { + +class StaticVfsFile : public VfsFile { +public: + explicit StaticVfsFile(u8 value_, std::size_t size_ = 0, std::string name_ = "", + VirtualDir parent_ = nullptr) + : value{value_}, size{size_}, name{std::move(name_)}, parent{std::move(parent_)} {} + + std::string GetName() const override { + return name; + } + + std::size_t GetSize() const override { + return size; + } + + bool Resize(std::size_t new_size) override { + size = new_size; + return true; + } + + VirtualDir GetContainingDirectory() const override { + return parent; + } + + bool IsWritable() const override { + return false; + } + + bool IsReadable() const override { + return true; + } + + std::size_t Read(u8* data, std::size_t length, std::size_t offset) const override { + const auto read = std::min(length, size - offset); + std::fill(data, data + read, value); + return read; + } + + std::size_t Write(const u8* data, std::size_t length, std::size_t offset) override { + return 0; + } + + std::optional<u8> ReadByte(std::size_t offset) const override { + if (offset >= size) { + return std::nullopt; + } + + return value; + } + + std::vector<u8> ReadBytes(std::size_t length, std::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: + u8 value; + std::size_t size; + std::string name; + VirtualDir parent; +}; + +} // namespace FileSys |
