diff options
| -rw-r--r-- | src/core/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/core/hle/romfs.cpp | 102 | ||||
| -rw-r--r-- | src/core/hle/romfs.h | 22 |
3 files changed, 0 insertions, 126 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 0abf7edc1..cceb1564b 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -104,8 +104,6 @@ add_library(core STATIC | |||
| 104 | hle/lock.cpp | 104 | hle/lock.cpp |
| 105 | hle/lock.h | 105 | hle/lock.h |
| 106 | hle/result.h | 106 | hle/result.h |
| 107 | hle/romfs.cpp | ||
| 108 | hle/romfs.h | ||
| 109 | hle/service/acc/acc.cpp | 107 | hle/service/acc/acc.cpp |
| 110 | hle/service/acc/acc.h | 108 | hle/service/acc/acc.h |
| 111 | hle/service/acc/acc_aa.cpp | 109 | hle/service/acc/acc_aa.cpp |
diff --git a/src/core/hle/romfs.cpp b/src/core/hle/romfs.cpp deleted file mode 100644 index 3157df71d..000000000 --- a/src/core/hle/romfs.cpp +++ /dev/null | |||
| @@ -1,102 +0,0 @@ | |||
| 1 | // Copyright 2017 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <cstring> | ||
| 6 | #include "common/swap.h" | ||
| 7 | #include "core/hle/romfs.h" | ||
| 8 | |||
| 9 | namespace RomFS { | ||
| 10 | |||
| 11 | struct Header { | ||
| 12 | u32_le header_length; | ||
| 13 | u32_le dir_hash_table_offset; | ||
| 14 | u32_le dir_hash_table_length; | ||
| 15 | u32_le dir_table_offset; | ||
| 16 | u32_le dir_table_length; | ||
| 17 | u32_le file_hash_table_offset; | ||
| 18 | u32_le file_hash_table_length; | ||
| 19 | u32_le file_table_offset; | ||
| 20 | u32_le file_table_length; | ||
| 21 | u32_le data_offset; | ||
| 22 | }; | ||
| 23 | |||
| 24 | static_assert(sizeof(Header) == 0x28, "Header has incorrect size"); | ||
| 25 | |||
| 26 | struct DirectoryMetadata { | ||
| 27 | u32_le parent_dir_offset; | ||
| 28 | u32_le next_dir_offset; | ||
| 29 | u32_le first_child_dir_offset; | ||
| 30 | u32_le first_file_offset; | ||
| 31 | u32_le same_hash_next_dir_offset; | ||
| 32 | u32_le name_length; // in bytes | ||
| 33 | // followed by directory name | ||
| 34 | }; | ||
| 35 | |||
| 36 | static_assert(sizeof(DirectoryMetadata) == 0x18, "DirectoryMetadata has incorrect size"); | ||
| 37 | |||
| 38 | struct FileMetadata { | ||
| 39 | u32_le parent_dir_offset; | ||
| 40 | u32_le next_file_offset; | ||
| 41 | u64_le data_offset; | ||
| 42 | u64_le data_length; | ||
| 43 | u32_le same_hash_next_file_offset; | ||
| 44 | u32_le name_length; // in bytes | ||
| 45 | // followed by file name | ||
| 46 | }; | ||
| 47 | |||
| 48 | static_assert(sizeof(FileMetadata) == 0x20, "FileMetadata has incorrect size"); | ||
| 49 | |||
| 50 | static bool MatchName(const u8* buffer, u32 name_length, const std::u16string& name) { | ||
| 51 | std::vector<char16_t> name_buffer(name_length / sizeof(char16_t)); | ||
| 52 | std::memcpy(name_buffer.data(), buffer, name_length); | ||
| 53 | return name == std::u16string(name_buffer.begin(), name_buffer.end()); | ||
| 54 | } | ||
| 55 | |||
| 56 | const u8* GetFilePointer(const u8* romfs, const std::vector<std::u16string>& path) { | ||
| 57 | constexpr u32 INVALID_FIELD = 0xFFFFFFFF; | ||
| 58 | |||
| 59 | // Split path into directory names and file name | ||
| 60 | std::vector<std::u16string> dir_names = path; | ||
| 61 | dir_names.pop_back(); | ||
| 62 | const std::u16string& file_name = path.back(); | ||
| 63 | |||
| 64 | Header header; | ||
| 65 | std::memcpy(&header, romfs, sizeof(header)); | ||
| 66 | |||
| 67 | // Find directories of each level | ||
| 68 | DirectoryMetadata dir; | ||
| 69 | const u8* current_dir = romfs + header.dir_table_offset; | ||
| 70 | std::memcpy(&dir, current_dir, sizeof(dir)); | ||
| 71 | for (const std::u16string& dir_name : dir_names) { | ||
| 72 | u32 child_dir_offset; | ||
| 73 | child_dir_offset = dir.first_child_dir_offset; | ||
| 74 | while (true) { | ||
| 75 | if (child_dir_offset == INVALID_FIELD) { | ||
| 76 | return nullptr; | ||
| 77 | } | ||
| 78 | const u8* current_child_dir = romfs + header.dir_table_offset + child_dir_offset; | ||
| 79 | std::memcpy(&dir, current_child_dir, sizeof(dir)); | ||
| 80 | if (MatchName(current_child_dir + sizeof(dir), dir.name_length, dir_name)) { | ||
| 81 | current_dir = current_child_dir; | ||
| 82 | break; | ||
| 83 | } | ||
| 84 | child_dir_offset = dir.next_dir_offset; | ||
| 85 | } | ||
| 86 | } | ||
| 87 | |||
| 88 | // Find the file | ||
| 89 | FileMetadata file; | ||
| 90 | u32 file_offset = dir.first_file_offset; | ||
| 91 | while (file_offset != INVALID_FIELD) { | ||
| 92 | const u8* current_file = romfs + header.file_table_offset + file_offset; | ||
| 93 | std::memcpy(&file, current_file, sizeof(file)); | ||
| 94 | if (MatchName(current_file + sizeof(file), file.name_length, file_name)) { | ||
| 95 | return romfs + header.data_offset + file.data_offset; | ||
| 96 | } | ||
| 97 | file_offset = file.next_file_offset; | ||
| 98 | } | ||
| 99 | return nullptr; | ||
| 100 | } | ||
| 101 | |||
| 102 | } // namespace RomFS | ||
diff --git a/src/core/hle/romfs.h b/src/core/hle/romfs.h deleted file mode 100644 index ee9f29760..000000000 --- a/src/core/hle/romfs.h +++ /dev/null | |||
| @@ -1,22 +0,0 @@ | |||
| 1 | // Copyright 2017 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <string> | ||
| 8 | #include <vector> | ||
| 9 | #include "common/common_types.h" | ||
| 10 | |||
| 11 | namespace RomFS { | ||
| 12 | |||
| 13 | /** | ||
| 14 | * Gets the pointer to a file in a RomFS image. | ||
| 15 | * @param romfs The pointer to the RomFS image | ||
| 16 | * @param path A vector containing the directory names and file name of the path to the file | ||
| 17 | * @return the pointer to the file | ||
| 18 | * @todo reimplement this with a full RomFS manager | ||
| 19 | */ | ||
| 20 | const u8* GetFilePointer(const u8* romfs, const std::vector<std::u16string>& path); | ||
| 21 | |||
| 22 | } // namespace RomFS | ||