2022-04-23 08:59:50 +00:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2018-07-19 01:07:11 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2018-07-22 05:23:29 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2018-07-19 01:07:11 +00:00
|
|
|
#include "core/file_sys/vfs.h"
|
|
|
|
|
|
|
|
namespace FileSys {
|
|
|
|
|
|
|
|
// An implementation of VfsFile that wraps around another VfsFile at a certain offset.
|
|
|
|
// Similar to seeking to an offset.
|
|
|
|
// If the file is writable, operations that would write past the end of the offset file will expand
|
|
|
|
// the size of this wrapper.
|
2018-08-12 20:37:38 +00:00
|
|
|
class OffsetVfsFile : public VfsFile {
|
|
|
|
public:
|
2020-12-10 06:31:58 +00:00
|
|
|
OffsetVfsFile(VirtualFile file, std::size_t size, std::size_t offset = 0,
|
2018-07-27 22:14:03 +00:00
|
|
|
std::string new_name = "", VirtualDir new_parent = nullptr);
|
2018-09-19 23:19:05 +00:00
|
|
|
~OffsetVfsFile() override;
|
2018-07-19 01:07:11 +00:00
|
|
|
|
|
|
|
std::string GetName() const override;
|
2018-09-15 13:21:06 +00:00
|
|
|
std::size_t GetSize() const override;
|
|
|
|
bool Resize(std::size_t new_size) override;
|
2020-12-10 06:31:58 +00:00
|
|
|
VirtualDir GetContainingDirectory() const override;
|
2018-07-19 01:07:11 +00:00
|
|
|
bool IsWritable() const override;
|
|
|
|
bool IsReadable() const override;
|
2018-09-15 13:21:06 +00:00
|
|
|
std::size_t Read(u8* data, std::size_t length, std::size_t offset) const override;
|
|
|
|
std::size_t Write(const u8* data, std::size_t length, std::size_t offset) override;
|
2018-10-30 04:03:25 +00:00
|
|
|
std::optional<u8> ReadByte(std::size_t offset) const override;
|
2018-09-15 13:21:06 +00:00
|
|
|
std::vector<u8> ReadBytes(std::size_t size, std::size_t offset) const override;
|
2018-07-19 01:07:11 +00:00
|
|
|
std::vector<u8> ReadAllBytes() const override;
|
2018-09-15 13:21:06 +00:00
|
|
|
bool WriteByte(u8 data, std::size_t offset) override;
|
|
|
|
std::size_t WriteBytes(const std::vector<u8>& data, std::size_t offset) override;
|
2018-07-19 01:07:11 +00:00
|
|
|
|
2021-05-02 06:34:40 +00:00
|
|
|
bool Rename(std::string_view new_name) override;
|
2018-07-19 01:07:11 +00:00
|
|
|
|
2018-09-15 13:21:06 +00:00
|
|
|
std::size_t GetOffset() const;
|
2018-07-19 01:07:11 +00:00
|
|
|
|
|
|
|
private:
|
2018-09-15 13:21:06 +00:00
|
|
|
std::size_t TrimToFit(std::size_t r_size, std::size_t r_offset) const;
|
2018-07-19 01:07:11 +00:00
|
|
|
|
2020-12-10 06:31:58 +00:00
|
|
|
VirtualFile file;
|
2018-09-15 13:21:06 +00:00
|
|
|
std::size_t offset;
|
|
|
|
std::size_t size;
|
2018-07-19 01:07:11 +00:00
|
|
|
std::string name;
|
2018-07-27 22:14:03 +00:00
|
|
|
VirtualDir parent;
|
2018-07-19 01:07:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace FileSys
|