diff options
| author | 2014-12-15 22:15:08 -0500 | |
|---|---|---|
| committer | 2014-12-15 22:15:08 -0500 | |
| commit | cd2a31eaf4a35568a18840eba7d3cdac59881d2f (patch) | |
| tree | 37a4d61adebae300e8ef172538c6a2d2eae80ff1 /src/core/file_sys | |
| parent | Update README.md (diff) | |
| parent | Work around libstdc++'s lack of support for std::hash on enums (diff) | |
| download | yuzu-cd2a31eaf4a35568a18840eba7d3cdac59881d2f.tar.gz yuzu-cd2a31eaf4a35568a18840eba7d3cdac59881d2f.tar.xz yuzu-cd2a31eaf4a35568a18840eba7d3cdac59881d2f.zip | |
Merge pull request #283 from yuriks/archive-refactor
Archive refactor
Diffstat (limited to 'src/core/file_sys')
| -rw-r--r-- | src/core/file_sys/archive_backend.h (renamed from src/core/file_sys/archive.h) | 59 | ||||
| -rw-r--r-- | src/core/file_sys/archive_romfs.cpp | 54 | ||||
| -rw-r--r-- | src/core/file_sys/archive_romfs.h | 47 | ||||
| -rw-r--r-- | src/core/file_sys/archive_sdmc.cpp | 49 | ||||
| -rw-r--r-- | src/core/file_sys/archive_sdmc.h | 44 | ||||
| -rw-r--r-- | src/core/file_sys/directory_backend.h (renamed from src/core/file_sys/directory.h) | 6 | ||||
| -rw-r--r-- | src/core/file_sys/directory_romfs.h | 4 | ||||
| -rw-r--r-- | src/core/file_sys/directory_sdmc.h | 4 | ||||
| -rw-r--r-- | src/core/file_sys/file_backend.h (renamed from src/core/file_sys/file.h) | 6 | ||||
| -rw-r--r-- | src/core/file_sys/file_romfs.cpp | 19 | ||||
| -rw-r--r-- | src/core/file_sys/file_romfs.h | 12 | ||||
| -rw-r--r-- | src/core/file_sys/file_sdmc.h | 4 |
12 files changed, 59 insertions, 249 deletions
diff --git a/src/core/file_sys/archive.h b/src/core/file_sys/archive_backend.h index 27ed23cd0..18c314884 100644 --- a/src/core/file_sys/archive.h +++ b/src/core/file_sys/archive_backend.h | |||
| @@ -10,8 +10,8 @@ | |||
| 10 | #include "common/string_util.h" | 10 | #include "common/string_util.h" |
| 11 | #include "common/bit_field.h" | 11 | #include "common/bit_field.h" |
| 12 | 12 | ||
| 13 | #include "core/file_sys/file.h" | 13 | #include "core/file_sys/file_backend.h" |
| 14 | #include "core/file_sys/directory.h" | 14 | #include "core/file_sys/directory_backend.h" |
| 15 | 15 | ||
| 16 | #include "core/mem_map.h" | 16 | #include "core/mem_map.h" |
| 17 | #include "core/hle/kernel/kernel.h" | 17 | #include "core/hle/kernel/kernel.h" |
| @@ -160,27 +160,14 @@ private: | |||
| 160 | std::u16string u16str; | 160 | std::u16string u16str; |
| 161 | }; | 161 | }; |
| 162 | 162 | ||
| 163 | class Archive : NonCopyable { | 163 | class ArchiveBackend : NonCopyable { |
| 164 | public: | 164 | public: |
| 165 | /// Supported archive types | 165 | virtual ~ArchiveBackend() { } |
| 166 | enum class IdCode : u32 { | ||
| 167 | RomFS = 0x00000003, | ||
| 168 | SaveData = 0x00000004, | ||
| 169 | ExtSaveData = 0x00000006, | ||
| 170 | SharedExtSaveData = 0x00000007, | ||
| 171 | SystemSaveData = 0x00000008, | ||
| 172 | SDMC = 0x00000009, | ||
| 173 | SDMCWriteOnly = 0x0000000A, | ||
| 174 | }; | ||
| 175 | |||
| 176 | Archive() { } | ||
| 177 | virtual ~Archive() { } | ||
| 178 | 166 | ||
| 179 | /** | 167 | /** |
| 180 | * Get the IdCode of the archive (e.g. RomFS, SaveData, etc.) | 168 | * Get a descriptive name for the archive (e.g. "RomFS", "SaveData", etc.) |
| 181 | * @return IdCode of the archive | ||
| 182 | */ | 169 | */ |
| 183 | virtual IdCode GetIdCode() const = 0; | 170 | virtual std::string GetName() const = 0; |
| 184 | 171 | ||
| 185 | /** | 172 | /** |
| 186 | * Open a file specified by its path, using the specified mode | 173 | * Open a file specified by its path, using the specified mode |
| @@ -188,7 +175,7 @@ public: | |||
| 188 | * @param mode Mode to open the file with | 175 | * @param mode Mode to open the file with |
| 189 | * @return Opened file, or nullptr | 176 | * @return Opened file, or nullptr |
| 190 | */ | 177 | */ |
| 191 | virtual std::unique_ptr<File> OpenFile(const Path& path, const Mode mode) const = 0; | 178 | virtual std::unique_ptr<FileBackend> OpenFile(const Path& path, const Mode mode) const = 0; |
| 192 | 179 | ||
| 193 | /** | 180 | /** |
| 194 | * Delete a file specified by its path | 181 | * Delete a file specified by its path |
| @@ -232,37 +219,7 @@ public: | |||
| 232 | * @param path Path relative to the archive | 219 | * @param path Path relative to the archive |
| 233 | * @return Opened directory, or nullptr | 220 | * @return Opened directory, or nullptr |
| 234 | */ | 221 | */ |
| 235 | virtual std::unique_ptr<Directory> OpenDirectory(const Path& path) const = 0; | 222 | virtual std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const = 0; |
| 236 | |||
| 237 | /** | ||
| 238 | * Read data from the archive | ||
| 239 | * @param offset Offset in bytes to start reading data from | ||
| 240 | * @param length Length in bytes of data to read from archive | ||
| 241 | * @param buffer Buffer to read data into | ||
| 242 | * @return Number of bytes read | ||
| 243 | */ | ||
| 244 | virtual size_t Read(const u64 offset, const u32 length, u8* buffer) const = 0; | ||
| 245 | |||
| 246 | /** | ||
| 247 | * Write data to the archive | ||
| 248 | * @param offset Offset in bytes to start writing data to | ||
| 249 | * @param length Length in bytes of data to write to archive | ||
| 250 | * @param buffer Buffer to write data from | ||
| 251 | * @param flush The flush parameters (0 == do not flush) | ||
| 252 | * @return Number of bytes written | ||
| 253 | */ | ||
| 254 | virtual size_t Write(const u64 offset, const u32 length, const u32 flush, u8* buffer) = 0; | ||
| 255 | |||
| 256 | /** | ||
| 257 | * Get the size of the archive in bytes | ||
| 258 | * @return Size of the archive in bytes | ||
| 259 | */ | ||
| 260 | virtual size_t GetSize() const = 0; | ||
| 261 | |||
| 262 | /** | ||
| 263 | * Set the size of the archive in bytes | ||
| 264 | */ | ||
| 265 | virtual void SetSize(const u64 size) = 0; | ||
| 266 | }; | 223 | }; |
| 267 | 224 | ||
| 268 | } // namespace FileSys | 225 | } // namespace FileSys |
diff --git a/src/core/file_sys/archive_romfs.cpp b/src/core/file_sys/archive_romfs.cpp index 74974c2df..0709b62a1 100644 --- a/src/core/file_sys/archive_romfs.cpp +++ b/src/core/file_sys/archive_romfs.cpp | |||
| @@ -2,6 +2,8 @@ | |||
| 2 | // Licensed under GPLv2 | 2 | // Licensed under GPLv2 |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <memory> | ||
| 6 | |||
| 5 | #include "common/common_types.h" | 7 | #include "common/common_types.h" |
| 6 | 8 | ||
| 7 | #include "core/file_sys/archive_romfs.h" | 9 | #include "core/file_sys/archive_romfs.h" |
| @@ -20,17 +22,14 @@ Archive_RomFS::Archive_RomFS(const Loader::AppLoader& app_loader) { | |||
| 20 | } | 22 | } |
| 21 | } | 23 | } |
| 22 | 24 | ||
| 23 | Archive_RomFS::~Archive_RomFS() { | ||
| 24 | } | ||
| 25 | |||
| 26 | /** | 25 | /** |
| 27 | * Open a file specified by its path, using the specified mode | 26 | * Open a file specified by its path, using the specified mode |
| 28 | * @param path Path relative to the archive | 27 | * @param path Path relative to the archive |
| 29 | * @param mode Mode to open the file with | 28 | * @param mode Mode to open the file with |
| 30 | * @return Opened file, or nullptr | 29 | * @return Opened file, or nullptr |
| 31 | */ | 30 | */ |
| 32 | std::unique_ptr<File> Archive_RomFS::OpenFile(const Path& path, const Mode mode) const { | 31 | std::unique_ptr<FileBackend> Archive_RomFS::OpenFile(const Path& path, const Mode mode) const { |
| 33 | return std::unique_ptr<File>(new File_RomFS); | 32 | return std::make_unique<File_RomFS>(this); |
| 34 | } | 33 | } |
| 35 | 34 | ||
| 36 | /** | 35 | /** |
| @@ -78,49 +77,8 @@ bool Archive_RomFS::RenameDirectory(const FileSys::Path& src_path, const FileSys | |||
| 78 | * @param path Path relative to the archive | 77 | * @param path Path relative to the archive |
| 79 | * @return Opened directory, or nullptr | 78 | * @return Opened directory, or nullptr |
| 80 | */ | 79 | */ |
| 81 | std::unique_ptr<Directory> Archive_RomFS::OpenDirectory(const Path& path) const { | 80 | std::unique_ptr<DirectoryBackend> Archive_RomFS::OpenDirectory(const Path& path) const { |
| 82 | return std::unique_ptr<Directory>(new Directory_RomFS); | 81 | return std::make_unique<Directory_RomFS>(); |
| 83 | } | ||
| 84 | |||
| 85 | /** | ||
| 86 | * Read data from the archive | ||
| 87 | * @param offset Offset in bytes to start reading data from | ||
| 88 | * @param length Length in bytes of data to read from archive | ||
| 89 | * @param buffer Buffer to read data into | ||
| 90 | * @return Number of bytes read | ||
| 91 | */ | ||
| 92 | size_t Archive_RomFS::Read(const u64 offset, const u32 length, u8* buffer) const { | ||
| 93 | LOG_TRACE(Service_FS, "called offset=%llu, length=%d", offset, length); | ||
| 94 | memcpy(buffer, &raw_data[(u32)offset], length); | ||
| 95 | return length; | ||
| 96 | } | ||
| 97 | |||
| 98 | /** | ||
| 99 | * Write data to the archive | ||
| 100 | * @param offset Offset in bytes to start writing data to | ||
| 101 | * @param length Length in bytes of data to write to archive | ||
| 102 | * @param buffer Buffer to write data from | ||
| 103 | * @param flush The flush parameters (0 == do not flush) | ||
| 104 | * @return Number of bytes written | ||
| 105 | */ | ||
| 106 | size_t Archive_RomFS::Write(const u64 offset, const u32 length, const u32 flush, u8* buffer) { | ||
| 107 | LOG_WARNING(Service_FS, "Attempted to write to ROMFS."); | ||
| 108 | return 0; | ||
| 109 | } | ||
| 110 | |||
| 111 | /** | ||
| 112 | * Get the size of the archive in bytes | ||
| 113 | * @return Size of the archive in bytes | ||
| 114 | */ | ||
| 115 | size_t Archive_RomFS::GetSize() const { | ||
| 116 | return sizeof(u8) * raw_data.size(); | ||
| 117 | } | ||
| 118 | |||
| 119 | /** | ||
| 120 | * Set the size of the archive in bytes | ||
| 121 | */ | ||
| 122 | void Archive_RomFS::SetSize(const u64 size) { | ||
| 123 | LOG_WARNING(Service_FS, "Attempted to set the size of ROMFS"); | ||
| 124 | } | 82 | } |
| 125 | 83 | ||
| 126 | } // namespace FileSys | 84 | } // namespace FileSys |
diff --git a/src/core/file_sys/archive_romfs.h b/src/core/file_sys/archive_romfs.h index 222bdc356..5b1ee6332 100644 --- a/src/core/file_sys/archive_romfs.h +++ b/src/core/file_sys/archive_romfs.h | |||
| @@ -8,7 +8,7 @@ | |||
| 8 | 8 | ||
| 9 | #include "common/common_types.h" | 9 | #include "common/common_types.h" |
| 10 | 10 | ||
| 11 | #include "core/file_sys/archive.h" | 11 | #include "core/file_sys/archive_backend.h" |
| 12 | #include "core/loader/loader.h" | 12 | #include "core/loader/loader.h" |
| 13 | 13 | ||
| 14 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 14 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| @@ -17,16 +17,11 @@ | |||
| 17 | namespace FileSys { | 17 | namespace FileSys { |
| 18 | 18 | ||
| 19 | /// File system interface to the RomFS archive | 19 | /// File system interface to the RomFS archive |
| 20 | class Archive_RomFS final : public Archive { | 20 | class Archive_RomFS final : public ArchiveBackend { |
| 21 | public: | 21 | public: |
| 22 | Archive_RomFS(const Loader::AppLoader& app_loader); | 22 | Archive_RomFS(const Loader::AppLoader& app_loader); |
| 23 | ~Archive_RomFS() override; | ||
| 24 | 23 | ||
| 25 | /** | 24 | std::string GetName() const override { return "RomFS"; } |
| 26 | * Get the IdCode of the archive (e.g. RomFS, SaveData, etc.) | ||
| 27 | * @return IdCode of the archive | ||
| 28 | */ | ||
| 29 | IdCode GetIdCode() const override { return IdCode::RomFS; } | ||
| 30 | 25 | ||
| 31 | /** | 26 | /** |
| 32 | * Open a file specified by its path, using the specified mode | 27 | * Open a file specified by its path, using the specified mode |
| @@ -34,7 +29,7 @@ public: | |||
| 34 | * @param mode Mode to open the file with | 29 | * @param mode Mode to open the file with |
| 35 | * @return Opened file, or nullptr | 30 | * @return Opened file, or nullptr |
| 36 | */ | 31 | */ |
| 37 | std::unique_ptr<File> OpenFile(const Path& path, const Mode mode) const override; | 32 | std::unique_ptr<FileBackend> OpenFile(const Path& path, const Mode mode) const override; |
| 38 | 33 | ||
| 39 | /** | 34 | /** |
| 40 | * Delete a file specified by its path | 35 | * Delete a file specified by its path |
| @@ -78,39 +73,11 @@ public: | |||
| 78 | * @param path Path relative to the archive | 73 | * @param path Path relative to the archive |
| 79 | * @return Opened directory, or nullptr | 74 | * @return Opened directory, or nullptr |
| 80 | */ | 75 | */ |
| 81 | std::unique_ptr<Directory> OpenDirectory(const Path& path) const override; | 76 | std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const override; |
| 82 | |||
| 83 | /** | ||
| 84 | * Read data from the archive | ||
| 85 | * @param offset Offset in bytes to start reading data from | ||
| 86 | * @param length Length in bytes of data to read from archive | ||
| 87 | * @param buffer Buffer to read data into | ||
| 88 | * @return Number of bytes read | ||
| 89 | */ | ||
| 90 | size_t Read(const u64 offset, const u32 length, u8* buffer) const override; | ||
| 91 | |||
| 92 | /** | ||
| 93 | * Write data to the archive | ||
| 94 | * @param offset Offset in bytes to start writing data to | ||
| 95 | * @param length Length in bytes of data to write to archive | ||
| 96 | * @param buffer Buffer to write data from | ||
| 97 | * @param flush The flush parameters (0 == do not flush) | ||
| 98 | * @return Number of bytes written | ||
| 99 | */ | ||
| 100 | size_t Write(const u64 offset, const u32 length, const u32 flush, u8* buffer) override; | ||
| 101 | |||
| 102 | /** | ||
| 103 | * Get the size of the archive in bytes | ||
| 104 | * @return Size of the archive in bytes | ||
| 105 | */ | ||
| 106 | size_t GetSize() const override; | ||
| 107 | |||
| 108 | /** | ||
| 109 | * Set the size of the archive in bytes | ||
| 110 | */ | ||
| 111 | void SetSize(const u64 size) override; | ||
| 112 | 77 | ||
| 113 | private: | 78 | private: |
| 79 | friend class File_RomFS; | ||
| 80 | |||
| 114 | std::vector<u8> raw_data; | 81 | std::vector<u8> raw_data; |
| 115 | }; | 82 | }; |
| 116 | 83 | ||
diff --git a/src/core/file_sys/archive_sdmc.cpp b/src/core/file_sys/archive_sdmc.cpp index 9e524b60e..9d58668e0 100644 --- a/src/core/file_sys/archive_sdmc.cpp +++ b/src/core/file_sys/archive_sdmc.cpp | |||
| @@ -49,12 +49,12 @@ bool Archive_SDMC::Initialize() { | |||
| 49 | * @param mode Mode to open the file with | 49 | * @param mode Mode to open the file with |
| 50 | * @return Opened file, or nullptr | 50 | * @return Opened file, or nullptr |
| 51 | */ | 51 | */ |
| 52 | std::unique_ptr<File> Archive_SDMC::OpenFile(const Path& path, const Mode mode) const { | 52 | std::unique_ptr<FileBackend> Archive_SDMC::OpenFile(const Path& path, const Mode mode) const { |
| 53 | LOG_DEBUG(Service_FS, "called path=%s mode=%u", path.DebugStr().c_str(), mode.hex); | 53 | LOG_DEBUG(Service_FS, "called path=%s mode=%u", path.DebugStr().c_str(), mode.hex); |
| 54 | File_SDMC* file = new File_SDMC(this, path, mode); | 54 | File_SDMC* file = new File_SDMC(this, path, mode); |
| 55 | if (!file->Open()) | 55 | if (!file->Open()) |
| 56 | return nullptr; | 56 | return nullptr; |
| 57 | return std::unique_ptr<File>(file); | 57 | return std::unique_ptr<FileBackend>(file); |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | /** | 60 | /** |
| @@ -97,53 +97,12 @@ bool Archive_SDMC::RenameDirectory(const FileSys::Path& src_path, const FileSys: | |||
| 97 | * @param path Path relative to the archive | 97 | * @param path Path relative to the archive |
| 98 | * @return Opened directory, or nullptr | 98 | * @return Opened directory, or nullptr |
| 99 | */ | 99 | */ |
| 100 | std::unique_ptr<Directory> Archive_SDMC::OpenDirectory(const Path& path) const { | 100 | std::unique_ptr<DirectoryBackend> Archive_SDMC::OpenDirectory(const Path& path) const { |
| 101 | LOG_DEBUG(Service_FS, "called path=%s", path.DebugStr().c_str()); | 101 | LOG_DEBUG(Service_FS, "called path=%s", path.DebugStr().c_str()); |
| 102 | Directory_SDMC* directory = new Directory_SDMC(this, path); | 102 | Directory_SDMC* directory = new Directory_SDMC(this, path); |
| 103 | if (!directory->Open()) | 103 | if (!directory->Open()) |
| 104 | return nullptr; | 104 | return nullptr; |
| 105 | return std::unique_ptr<Directory>(directory); | 105 | return std::unique_ptr<DirectoryBackend>(directory); |
| 106 | } | ||
| 107 | |||
| 108 | /** | ||
| 109 | * Read data from the archive | ||
| 110 | * @param offset Offset in bytes to start reading archive from | ||
| 111 | * @param length Length in bytes to read data from archive | ||
| 112 | * @param buffer Buffer to read data into | ||
| 113 | * @return Number of bytes read | ||
| 114 | */ | ||
| 115 | size_t Archive_SDMC::Read(const u64 offset, const u32 length, u8* buffer) const { | ||
| 116 | LOG_ERROR(Service_FS, "(UNIMPLEMENTED)"); | ||
| 117 | return -1; | ||
| 118 | } | ||
| 119 | |||
| 120 | /** | ||
| 121 | * Write data to the archive | ||
| 122 | * @param offset Offset in bytes to start writing data to | ||
| 123 | * @param length Length in bytes of data to write to archive | ||
| 124 | * @param buffer Buffer to write data from | ||
| 125 | * @param flush The flush parameters (0 == do not flush) | ||
| 126 | * @return Number of bytes written | ||
| 127 | */ | ||
| 128 | size_t Archive_SDMC::Write(const u64 offset, const u32 length, const u32 flush, u8* buffer) { | ||
| 129 | LOG_ERROR(Service_FS, "(UNIMPLEMENTED)"); | ||
| 130 | return -1; | ||
| 131 | } | ||
| 132 | |||
| 133 | /** | ||
| 134 | * Get the size of the archive in bytes | ||
| 135 | * @return Size of the archive in bytes | ||
| 136 | */ | ||
| 137 | size_t Archive_SDMC::GetSize() const { | ||
| 138 | LOG_ERROR(Service_FS, "(UNIMPLEMENTED)"); | ||
| 139 | return 0; | ||
| 140 | } | ||
| 141 | |||
| 142 | /** | ||
| 143 | * Set the size of the archive in bytes | ||
| 144 | */ | ||
| 145 | void Archive_SDMC::SetSize(const u64 size) { | ||
| 146 | LOG_ERROR(Service_FS, "(UNIMPLEMENTED)"); | ||
| 147 | } | 106 | } |
| 148 | 107 | ||
| 149 | /** | 108 | /** |
diff --git a/src/core/file_sys/archive_sdmc.h b/src/core/file_sys/archive_sdmc.h index 19f563a62..059045245 100644 --- a/src/core/file_sys/archive_sdmc.h +++ b/src/core/file_sys/archive_sdmc.h | |||
| @@ -6,7 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | #include "common/common_types.h" | 7 | #include "common/common_types.h" |
| 8 | 8 | ||
| 9 | #include "core/file_sys/archive.h" | 9 | #include "core/file_sys/archive_backend.h" |
| 10 | #include "core/loader/loader.h" | 10 | #include "core/loader/loader.h" |
| 11 | 11 | ||
| 12 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 12 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| @@ -15,7 +15,7 @@ | |||
| 15 | namespace FileSys { | 15 | namespace FileSys { |
| 16 | 16 | ||
| 17 | /// File system interface to the SDMC archive | 17 | /// File system interface to the SDMC archive |
| 18 | class Archive_SDMC final : public Archive { | 18 | class Archive_SDMC final : public ArchiveBackend { |
| 19 | public: | 19 | public: |
| 20 | Archive_SDMC(const std::string& mount_point); | 20 | Archive_SDMC(const std::string& mount_point); |
| 21 | ~Archive_SDMC() override; | 21 | ~Archive_SDMC() override; |
| @@ -26,11 +26,7 @@ public: | |||
| 26 | */ | 26 | */ |
| 27 | bool Initialize(); | 27 | bool Initialize(); |
| 28 | 28 | ||
| 29 | /** | 29 | std::string GetName() const override { return "SDMC"; } |
| 30 | * Get the IdCode of the archive (e.g. RomFS, SaveData, etc.) | ||
| 31 | * @return IdCode of the archive | ||
| 32 | */ | ||
| 33 | IdCode GetIdCode() const override { return IdCode::SDMC; } | ||
| 34 | 30 | ||
| 35 | /** | 31 | /** |
| 36 | * Open a file specified by its path, using the specified mode | 32 | * Open a file specified by its path, using the specified mode |
| @@ -38,7 +34,7 @@ public: | |||
| 38 | * @param mode Mode to open the file with | 34 | * @param mode Mode to open the file with |
| 39 | * @return Opened file, or nullptr | 35 | * @return Opened file, or nullptr |
| 40 | */ | 36 | */ |
| 41 | std::unique_ptr<File> OpenFile(const Path& path, const Mode mode) const override; | 37 | std::unique_ptr<FileBackend> OpenFile(const Path& path, const Mode mode) const override; |
| 42 | 38 | ||
| 43 | /** | 39 | /** |
| 44 | * Delete a file specified by its path | 40 | * Delete a file specified by its path |
| @@ -82,37 +78,7 @@ public: | |||
| 82 | * @param path Path relative to the archive | 78 | * @param path Path relative to the archive |
| 83 | * @return Opened directory, or nullptr | 79 | * @return Opened directory, or nullptr |
| 84 | */ | 80 | */ |
| 85 | std::unique_ptr<Directory> OpenDirectory(const Path& path) const override; | 81 | std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const override; |
| 86 | |||
| 87 | /** | ||
| 88 | * Read data from the archive | ||
| 89 | * @param offset Offset in bytes to start reading archive from | ||
| 90 | * @param length Length in bytes to read data from archive | ||
| 91 | * @param buffer Buffer to read data into | ||
| 92 | * @return Number of bytes read | ||
| 93 | */ | ||
| 94 | size_t Read(const u64 offset, const u32 length, u8* buffer) const override; | ||
| 95 | |||
| 96 | /** | ||
| 97 | * Write data to the archive | ||
| 98 | * @param offset Offset in bytes to start writing data to | ||
| 99 | * @param length Length in bytes of data to write to archive | ||
| 100 | * @param buffer Buffer to write data from | ||
| 101 | * @param flush The flush parameters (0 == do not flush) | ||
| 102 | * @return Number of bytes written | ||
| 103 | */ | ||
| 104 | size_t Write(const u64 offset, const u32 length, const u32 flush, u8* buffer) override; | ||
| 105 | |||
| 106 | /** | ||
| 107 | * Get the size of the archive in bytes | ||
| 108 | * @return Size of the archive in bytes | ||
| 109 | */ | ||
| 110 | size_t GetSize() const override; | ||
| 111 | |||
| 112 | /** | ||
| 113 | * Set the size of the archive in bytes | ||
| 114 | */ | ||
| 115 | void SetSize(const u64 size) override; | ||
| 116 | 82 | ||
| 117 | /** | 83 | /** |
| 118 | * Getter for the path used for this Archive | 84 | * Getter for the path used for this Archive |
diff --git a/src/core/file_sys/directory.h b/src/core/file_sys/directory_backend.h index 1bb4101d6..188746a6f 100644 --- a/src/core/file_sys/directory.h +++ b/src/core/file_sys/directory_backend.h | |||
| @@ -36,10 +36,10 @@ static_assert(offsetof(Entry, extension) == 0x216, "Wrong offset for extension i | |||
| 36 | static_assert(offsetof(Entry, is_archive) == 0x21E, "Wrong offset for is_archive in Entry."); | 36 | static_assert(offsetof(Entry, is_archive) == 0x21E, "Wrong offset for is_archive in Entry."); |
| 37 | static_assert(offsetof(Entry, file_size) == 0x220, "Wrong offset for file_size in Entry."); | 37 | static_assert(offsetof(Entry, file_size) == 0x220, "Wrong offset for file_size in Entry."); |
| 38 | 38 | ||
| 39 | class Directory : NonCopyable { | 39 | class DirectoryBackend : NonCopyable { |
| 40 | public: | 40 | public: |
| 41 | Directory() { } | 41 | DirectoryBackend() { } |
| 42 | virtual ~Directory() { } | 42 | virtual ~DirectoryBackend() { } |
| 43 | 43 | ||
| 44 | /** | 44 | /** |
| 45 | * Open the directory | 45 | * Open the directory |
diff --git a/src/core/file_sys/directory_romfs.h b/src/core/file_sys/directory_romfs.h index e2944099e..b775f014d 100644 --- a/src/core/file_sys/directory_romfs.h +++ b/src/core/file_sys/directory_romfs.h | |||
| @@ -6,7 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | #include "common/common_types.h" | 7 | #include "common/common_types.h" |
| 8 | 8 | ||
| 9 | #include "core/file_sys/directory.h" | 9 | #include "core/file_sys/directory_backend.h" |
| 10 | #include "core/loader/loader.h" | 10 | #include "core/loader/loader.h" |
| 11 | 11 | ||
| 12 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 12 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| @@ -14,7 +14,7 @@ | |||
| 14 | 14 | ||
| 15 | namespace FileSys { | 15 | namespace FileSys { |
| 16 | 16 | ||
| 17 | class Directory_RomFS final : public Directory { | 17 | class Directory_RomFS final : public DirectoryBackend { |
| 18 | public: | 18 | public: |
| 19 | Directory_RomFS(); | 19 | Directory_RomFS(); |
| 20 | ~Directory_RomFS() override; | 20 | ~Directory_RomFS() override; |
diff --git a/src/core/file_sys/directory_sdmc.h b/src/core/file_sys/directory_sdmc.h index 4c08b0d61..407a256ef 100644 --- a/src/core/file_sys/directory_sdmc.h +++ b/src/core/file_sys/directory_sdmc.h | |||
| @@ -7,7 +7,7 @@ | |||
| 7 | #include "common/common_types.h" | 7 | #include "common/common_types.h" |
| 8 | #include "common/file_util.h" | 8 | #include "common/file_util.h" |
| 9 | 9 | ||
| 10 | #include "core/file_sys/directory.h" | 10 | #include "core/file_sys/directory_backend.h" |
| 11 | #include "core/file_sys/archive_sdmc.h" | 11 | #include "core/file_sys/archive_sdmc.h" |
| 12 | #include "core/loader/loader.h" | 12 | #include "core/loader/loader.h" |
| 13 | 13 | ||
| @@ -16,7 +16,7 @@ | |||
| 16 | 16 | ||
| 17 | namespace FileSys { | 17 | namespace FileSys { |
| 18 | 18 | ||
| 19 | class Directory_SDMC final : public Directory { | 19 | class Directory_SDMC final : public DirectoryBackend { |
| 20 | public: | 20 | public: |
| 21 | Directory_SDMC(); | 21 | Directory_SDMC(); |
| 22 | Directory_SDMC(const Archive_SDMC* archive, const Path& path); | 22 | Directory_SDMC(const Archive_SDMC* archive, const Path& path); |
diff --git a/src/core/file_sys/file.h b/src/core/file_sys/file_backend.h index 4013b6c3e..1b81d5fe9 100644 --- a/src/core/file_sys/file.h +++ b/src/core/file_sys/file_backend.h | |||
| @@ -13,10 +13,10 @@ | |||
| 13 | 13 | ||
| 14 | namespace FileSys { | 14 | namespace FileSys { |
| 15 | 15 | ||
| 16 | class File : NonCopyable { | 16 | class FileBackend : NonCopyable { |
| 17 | public: | 17 | public: |
| 18 | File() { } | 18 | FileBackend() { } |
| 19 | virtual ~File() { } | 19 | virtual ~FileBackend() { } |
| 20 | 20 | ||
| 21 | /** | 21 | /** |
| 22 | * Open the file | 22 | * Open the file |
diff --git a/src/core/file_sys/file_romfs.cpp b/src/core/file_sys/file_romfs.cpp index b55708df4..5f38c2704 100644 --- a/src/core/file_sys/file_romfs.cpp +++ b/src/core/file_sys/file_romfs.cpp | |||
| @@ -5,24 +5,19 @@ | |||
| 5 | #include "common/common_types.h" | 5 | #include "common/common_types.h" |
| 6 | 6 | ||
| 7 | #include "core/file_sys/file_romfs.h" | 7 | #include "core/file_sys/file_romfs.h" |
| 8 | #include "core/file_sys/archive_romfs.h" | ||
| 8 | 9 | ||
| 9 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 10 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 10 | // FileSys namespace | 11 | // FileSys namespace |
| 11 | 12 | ||
| 12 | namespace FileSys { | 13 | namespace FileSys { |
| 13 | 14 | ||
| 14 | File_RomFS::File_RomFS() { | ||
| 15 | } | ||
| 16 | |||
| 17 | File_RomFS::~File_RomFS() { | ||
| 18 | } | ||
| 19 | |||
| 20 | /** | 15 | /** |
| 21 | * Open the file | 16 | * Open the file |
| 22 | * @return true if the file opened correctly | 17 | * @return true if the file opened correctly |
| 23 | */ | 18 | */ |
| 24 | bool File_RomFS::Open() { | 19 | bool File_RomFS::Open() { |
| 25 | return false; | 20 | return true; |
| 26 | } | 21 | } |
| 27 | 22 | ||
| 28 | /** | 23 | /** |
| @@ -33,7 +28,9 @@ bool File_RomFS::Open() { | |||
| 33 | * @return Number of bytes read | 28 | * @return Number of bytes read |
| 34 | */ | 29 | */ |
| 35 | size_t File_RomFS::Read(const u64 offset, const u32 length, u8* buffer) const { | 30 | size_t File_RomFS::Read(const u64 offset, const u32 length, u8* buffer) const { |
| 36 | return -1; | 31 | LOG_TRACE(Service_FS, "called offset=%llu, length=%d", offset, length); |
| 32 | memcpy(buffer, &archive->raw_data[(u32)offset], length); | ||
| 33 | return length; | ||
| 37 | } | 34 | } |
| 38 | 35 | ||
| 39 | /** | 36 | /** |
| @@ -45,7 +42,8 @@ size_t File_RomFS::Read(const u64 offset, const u32 length, u8* buffer) const { | |||
| 45 | * @return Number of bytes written | 42 | * @return Number of bytes written |
| 46 | */ | 43 | */ |
| 47 | size_t File_RomFS::Write(const u64 offset, const u32 length, const u32 flush, const u8* buffer) const { | 44 | size_t File_RomFS::Write(const u64 offset, const u32 length, const u32 flush, const u8* buffer) const { |
| 48 | return -1; | 45 | LOG_WARNING(Service_FS, "Attempted to write to ROMFS."); |
| 46 | return 0; | ||
| 49 | } | 47 | } |
| 50 | 48 | ||
| 51 | /** | 49 | /** |
| @@ -53,7 +51,7 @@ size_t File_RomFS::Write(const u64 offset, const u32 length, const u32 flush, co | |||
| 53 | * @return Size of the file in bytes | 51 | * @return Size of the file in bytes |
| 54 | */ | 52 | */ |
| 55 | size_t File_RomFS::GetSize() const { | 53 | size_t File_RomFS::GetSize() const { |
| 56 | return -1; | 54 | return sizeof(u8) * archive->raw_data.size(); |
| 57 | } | 55 | } |
| 58 | 56 | ||
| 59 | /** | 57 | /** |
| @@ -62,6 +60,7 @@ size_t File_RomFS::GetSize() const { | |||
| 62 | * @return true if successful | 60 | * @return true if successful |
| 63 | */ | 61 | */ |
| 64 | bool File_RomFS::SetSize(const u64 size) const { | 62 | bool File_RomFS::SetSize(const u64 size) const { |
| 63 | LOG_WARNING(Service_FS, "Attempted to set the size of ROMFS"); | ||
| 65 | return false; | 64 | return false; |
| 66 | } | 65 | } |
| 67 | 66 | ||
diff --git a/src/core/file_sys/file_romfs.h b/src/core/file_sys/file_romfs.h index 5196701d3..09fa2e7e3 100644 --- a/src/core/file_sys/file_romfs.h +++ b/src/core/file_sys/file_romfs.h | |||
| @@ -6,7 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | #include "common/common_types.h" | 7 | #include "common/common_types.h" |
| 8 | 8 | ||
| 9 | #include "core/file_sys/file.h" | 9 | #include "core/file_sys/file_backend.h" |
| 10 | #include "core/loader/loader.h" | 10 | #include "core/loader/loader.h" |
| 11 | 11 | ||
| 12 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 12 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| @@ -14,10 +14,11 @@ | |||
| 14 | 14 | ||
| 15 | namespace FileSys { | 15 | namespace FileSys { |
| 16 | 16 | ||
| 17 | class File_RomFS final : public File { | 17 | class Archive_RomFS; |
| 18 | |||
| 19 | class File_RomFS final : public FileBackend { | ||
| 18 | public: | 20 | public: |
| 19 | File_RomFS(); | 21 | File_RomFS(const Archive_RomFS* archive) : archive(archive) {} |
| 20 | ~File_RomFS() override; | ||
| 21 | 22 | ||
| 22 | /** | 23 | /** |
| 23 | * Open the file | 24 | * Open the file |
| @@ -62,6 +63,9 @@ public: | |||
| 62 | * @return true if the file closed correctly | 63 | * @return true if the file closed correctly |
| 63 | */ | 64 | */ |
| 64 | bool Close() const override; | 65 | bool Close() const override; |
| 66 | |||
| 67 | private: | ||
| 68 | const Archive_RomFS* archive; | ||
| 65 | }; | 69 | }; |
| 66 | 70 | ||
| 67 | } // namespace FileSys | 71 | } // namespace FileSys |
diff --git a/src/core/file_sys/file_sdmc.h b/src/core/file_sys/file_sdmc.h index 80b445968..e01548598 100644 --- a/src/core/file_sys/file_sdmc.h +++ b/src/core/file_sys/file_sdmc.h | |||
| @@ -7,7 +7,7 @@ | |||
| 7 | #include "common/common_types.h" | 7 | #include "common/common_types.h" |
| 8 | #include "common/file_util.h" | 8 | #include "common/file_util.h" |
| 9 | 9 | ||
| 10 | #include "core/file_sys/file.h" | 10 | #include "core/file_sys/file_backend.h" |
| 11 | #include "core/file_sys/archive_sdmc.h" | 11 | #include "core/file_sys/archive_sdmc.h" |
| 12 | #include "core/loader/loader.h" | 12 | #include "core/loader/loader.h" |
| 13 | 13 | ||
| @@ -16,7 +16,7 @@ | |||
| 16 | 16 | ||
| 17 | namespace FileSys { | 17 | namespace FileSys { |
| 18 | 18 | ||
| 19 | class File_SDMC final : public File { | 19 | class File_SDMC final : public FileBackend { |
| 20 | public: | 20 | public: |
| 21 | File_SDMC(); | 21 | File_SDMC(); |
| 22 | File_SDMC(const Archive_SDMC* archive, const Path& path, const Mode mode); | 22 | File_SDMC(const Archive_SDMC* archive, const Path& path, const Mode mode); |