diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/file_sys/fsmitm_romfsbuild.cpp | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/src/core/file_sys/fsmitm_romfsbuild.cpp b/src/core/file_sys/fsmitm_romfsbuild.cpp index 1ff83c08c..e39c7b62b 100644 --- a/src/core/file_sys/fsmitm_romfsbuild.cpp +++ b/src/core/file_sys/fsmitm_romfsbuild.cpp | |||
| @@ -105,19 +105,11 @@ static u64 romfs_get_hash_table_count(u64 num_entries) { | |||
| 105 | return count; | 105 | return count; |
| 106 | } | 106 | } |
| 107 | 107 | ||
| 108 | void RomFSBuildContext::VisitDirectory(VirtualDir root_romfs, VirtualDir ext_dir, | 108 | void RomFSBuildContext::VisitDirectory(VirtualDir romfs_dir, VirtualDir ext_dir, |
| 109 | std::shared_ptr<RomFSBuildDirectoryContext> parent) { | 109 | std::shared_ptr<RomFSBuildDirectoryContext> parent) { |
| 110 | std::vector<std::shared_ptr<RomFSBuildDirectoryContext>> child_dirs; | 110 | std::vector<std::shared_ptr<RomFSBuildDirectoryContext>> child_dirs; |
| 111 | 111 | ||
| 112 | VirtualDir dir; | 112 | const auto entries = romfs_dir->GetEntries(); |
| 113 | |||
| 114 | if (parent->path_len == 0) { | ||
| 115 | dir = root_romfs; | ||
| 116 | } else { | ||
| 117 | dir = root_romfs->GetDirectoryRelative(parent->path); | ||
| 118 | } | ||
| 119 | |||
| 120 | const auto entries = dir->GetEntries(); | ||
| 121 | 113 | ||
| 122 | for (const auto& kv : entries) { | 114 | for (const auto& kv : entries) { |
| 123 | if (kv.second == VfsEntryType::Directory) { | 115 | if (kv.second == VfsEntryType::Directory) { |
| @@ -127,7 +119,7 @@ void RomFSBuildContext::VisitDirectory(VirtualDir root_romfs, VirtualDir ext_dir | |||
| 127 | child->path_len = child->cur_path_ofs + static_cast<u32>(kv.first.size()); | 119 | child->path_len = child->cur_path_ofs + static_cast<u32>(kv.first.size()); |
| 128 | child->path = parent->path + "/" + kv.first; | 120 | child->path = parent->path + "/" + kv.first; |
| 129 | 121 | ||
| 130 | if (ext_dir != nullptr && ext_dir->GetFileRelative(child->path + ".stub") != nullptr) { | 122 | if (ext_dir != nullptr && ext_dir->GetFile(kv.first + ".stub") != nullptr) { |
| 131 | continue; | 123 | continue; |
| 132 | } | 124 | } |
| 133 | 125 | ||
| @@ -144,17 +136,17 @@ void RomFSBuildContext::VisitDirectory(VirtualDir root_romfs, VirtualDir ext_dir | |||
| 144 | child->path_len = child->cur_path_ofs + static_cast<u32>(kv.first.size()); | 136 | child->path_len = child->cur_path_ofs + static_cast<u32>(kv.first.size()); |
| 145 | child->path = parent->path + "/" + kv.first; | 137 | child->path = parent->path + "/" + kv.first; |
| 146 | 138 | ||
| 147 | if (ext_dir != nullptr && ext_dir->GetFileRelative(child->path + ".stub") != nullptr) { | 139 | if (ext_dir != nullptr && ext_dir->GetFile(kv.first + ".stub") != nullptr) { |
| 148 | continue; | 140 | continue; |
| 149 | } | 141 | } |
| 150 | 142 | ||
| 151 | // Sanity check on path_len | 143 | // Sanity check on path_len |
| 152 | ASSERT(child->path_len < FS_MAX_PATH); | 144 | ASSERT(child->path_len < FS_MAX_PATH); |
| 153 | 145 | ||
| 154 | child->source = root_romfs->GetFileRelative(child->path); | 146 | child->source = romfs_dir->GetFile(kv.first); |
| 155 | 147 | ||
| 156 | if (ext_dir != nullptr) { | 148 | if (ext_dir != nullptr) { |
| 157 | if (const auto ips = ext_dir->GetFileRelative(child->path + ".ips")) { | 149 | if (const auto ips = ext_dir->GetFile(kv.first + ".ips")) { |
| 158 | if (auto patched = PatchIPS(child->source, ips)) { | 150 | if (auto patched = PatchIPS(child->source, ips)) { |
| 159 | child->source = std::move(patched); | 151 | child->source = std::move(patched); |
| 160 | } | 152 | } |
| @@ -168,23 +160,27 @@ void RomFSBuildContext::VisitDirectory(VirtualDir root_romfs, VirtualDir ext_dir | |||
| 168 | } | 160 | } |
| 169 | 161 | ||
| 170 | for (auto& child : child_dirs) { | 162 | for (auto& child : child_dirs) { |
| 171 | this->VisitDirectory(root_romfs, ext_dir, child); | 163 | auto subdir_name = std::string_view(child->path).substr(child->cur_path_ofs); |
| 164 | auto child_romfs_dir = romfs_dir->GetSubdirectory(subdir_name); | ||
| 165 | auto child_ext_dir = ext_dir != nullptr ? ext_dir->GetSubdirectory(subdir_name) : nullptr; | ||
| 166 | this->VisitDirectory(child_romfs_dir, child_ext_dir, child); | ||
| 172 | } | 167 | } |
| 173 | } | 168 | } |
| 174 | 169 | ||
| 175 | bool RomFSBuildContext::AddDirectory(std::shared_ptr<RomFSBuildDirectoryContext> parent_dir_ctx, | 170 | bool RomFSBuildContext::AddDirectory(std::shared_ptr<RomFSBuildDirectoryContext> parent_dir_ctx, |
| 176 | std::shared_ptr<RomFSBuildDirectoryContext> dir_ctx) { | 171 | std::shared_ptr<RomFSBuildDirectoryContext> dir_ctx) { |
| 177 | // Check whether it's already in the known directories. | 172 | // Check whether it's already in the known directories. |
| 178 | const auto existing = directories.find(dir_ctx->path); | 173 | const auto [it, is_new] = directories.emplace(dir_ctx->path, nullptr); |
| 179 | if (existing != directories.end()) | 174 | if (!is_new) { |
| 180 | return false; | 175 | return false; |
| 176 | } | ||
| 181 | 177 | ||
| 182 | // Add a new directory. | 178 | // Add a new directory. |
| 183 | num_dirs++; | 179 | num_dirs++; |
| 184 | dir_table_size += | 180 | dir_table_size += |
| 185 | sizeof(RomFSDirectoryEntry) + Common::AlignUp(dir_ctx->path_len - dir_ctx->cur_path_ofs, 4); | 181 | sizeof(RomFSDirectoryEntry) + Common::AlignUp(dir_ctx->path_len - dir_ctx->cur_path_ofs, 4); |
| 186 | dir_ctx->parent = parent_dir_ctx; | 182 | dir_ctx->parent = parent_dir_ctx; |
| 187 | directories.emplace(dir_ctx->path, dir_ctx); | 183 | it->second = dir_ctx; |
| 188 | 184 | ||
| 189 | return true; | 185 | return true; |
| 190 | } | 186 | } |
| @@ -192,8 +188,8 @@ bool RomFSBuildContext::AddDirectory(std::shared_ptr<RomFSBuildDirectoryContext> | |||
| 192 | bool RomFSBuildContext::AddFile(std::shared_ptr<RomFSBuildDirectoryContext> parent_dir_ctx, | 188 | bool RomFSBuildContext::AddFile(std::shared_ptr<RomFSBuildDirectoryContext> parent_dir_ctx, |
| 193 | std::shared_ptr<RomFSBuildFileContext> file_ctx) { | 189 | std::shared_ptr<RomFSBuildFileContext> file_ctx) { |
| 194 | // Check whether it's already in the known files. | 190 | // Check whether it's already in the known files. |
| 195 | const auto existing = files.find(file_ctx->path); | 191 | const auto [it, is_new] = files.emplace(file_ctx->path, nullptr); |
| 196 | if (existing != files.end()) { | 192 | if (!is_new) { |
| 197 | return false; | 193 | return false; |
| 198 | } | 194 | } |
| 199 | 195 | ||
| @@ -202,7 +198,7 @@ bool RomFSBuildContext::AddFile(std::shared_ptr<RomFSBuildDirectoryContext> pare | |||
| 202 | file_table_size += | 198 | file_table_size += |
| 203 | sizeof(RomFSFileEntry) + Common::AlignUp(file_ctx->path_len - file_ctx->cur_path_ofs, 4); | 199 | sizeof(RomFSFileEntry) + Common::AlignUp(file_ctx->path_len - file_ctx->cur_path_ofs, 4); |
| 204 | file_ctx->parent = parent_dir_ctx; | 200 | file_ctx->parent = parent_dir_ctx; |
| 205 | files.emplace(file_ctx->path, file_ctx); | 201 | it->second = file_ctx; |
| 206 | 202 | ||
| 207 | return true; | 203 | return true; |
| 208 | } | 204 | } |