|
|
|
@ -107,46 +107,25 @@ static u64 romfs_get_hash_table_count(u64 num_entries) { |
|
|
|
|
|
|
|
void RomFSBuildContext::VisitDirectory(VirtualDir romfs_dir, VirtualDir ext_dir, |
|
|
|
std::shared_ptr<RomFSBuildDirectoryContext> parent) { |
|
|
|
std::vector<std::shared_ptr<RomFSBuildDirectoryContext>> child_dirs; |
|
|
|
|
|
|
|
const auto entries = romfs_dir->GetEntries(); |
|
|
|
|
|
|
|
for (const auto& kv : entries) { |
|
|
|
if (kv.second == VfsEntryType::Directory) { |
|
|
|
const auto child = std::make_shared<RomFSBuildDirectoryContext>(); |
|
|
|
// Set child's path.
|
|
|
|
child->cur_path_ofs = parent->path_len + 1; |
|
|
|
child->path_len = child->cur_path_ofs + static_cast<u32>(kv.first.size()); |
|
|
|
child->path = parent->path + "/" + kv.first; |
|
|
|
|
|
|
|
if (ext_dir != nullptr && ext_dir->GetFile(kv.first + ".stub") != nullptr) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
// Sanity check on path_len
|
|
|
|
ASSERT(child->path_len < FS_MAX_PATH); |
|
|
|
|
|
|
|
if (AddDirectory(parent, child)) { |
|
|
|
child_dirs.push_back(child); |
|
|
|
} |
|
|
|
} else { |
|
|
|
for (auto& child_romfs_file : romfs_dir->GetFiles()) { |
|
|
|
const auto name = child_romfs_file->GetName(); |
|
|
|
const auto child = std::make_shared<RomFSBuildFileContext>(); |
|
|
|
// Set child's path.
|
|
|
|
child->cur_path_ofs = parent->path_len + 1; |
|
|
|
child->path_len = child->cur_path_ofs + static_cast<u32>(kv.first.size()); |
|
|
|
child->path = parent->path + "/" + kv.first; |
|
|
|
child->path_len = child->cur_path_ofs + static_cast<u32>(name.size()); |
|
|
|
child->path = parent->path + "/" + name; |
|
|
|
|
|
|
|
if (ext_dir != nullptr && ext_dir->GetFile(kv.first + ".stub") != nullptr) { |
|
|
|
if (ext_dir != nullptr && ext_dir->GetFile(name + ".stub") != nullptr) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
// Sanity check on path_len
|
|
|
|
ASSERT(child->path_len < FS_MAX_PATH); |
|
|
|
|
|
|
|
child->source = romfs_dir->GetFile(kv.first); |
|
|
|
child->source = std::move(child_romfs_file); |
|
|
|
|
|
|
|
if (ext_dir != nullptr) { |
|
|
|
if (const auto ips = ext_dir->GetFile(kv.first + ".ips")) { |
|
|
|
if (const auto ips = ext_dir->GetFile(name + ".ips")) { |
|
|
|
if (auto patched = PatchIPS(child->source, ips)) { |
|
|
|
child->source = std::move(patched); |
|
|
|
} |
|
|
|
@ -157,12 +136,27 @@ void RomFSBuildContext::VisitDirectory(VirtualDir romfs_dir, VirtualDir ext_dir, |
|
|
|
|
|
|
|
AddFile(parent, child); |
|
|
|
} |
|
|
|
|
|
|
|
for (auto& child_romfs_dir : romfs_dir->GetSubdirectories()) { |
|
|
|
const auto name = child_romfs_dir->GetName(); |
|
|
|
const auto child = std::make_shared<RomFSBuildDirectoryContext>(); |
|
|
|
// Set child's path.
|
|
|
|
child->cur_path_ofs = parent->path_len + 1; |
|
|
|
child->path_len = child->cur_path_ofs + static_cast<u32>(name.size()); |
|
|
|
child->path = parent->path + "/" + name; |
|
|
|
|
|
|
|
if (ext_dir != nullptr && ext_dir->GetFile(name + ".stub") != nullptr) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
// Sanity check on path_len
|
|
|
|
ASSERT(child->path_len < FS_MAX_PATH); |
|
|
|
|
|
|
|
if (!AddDirectory(parent, child)) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
for (auto& child : child_dirs) { |
|
|
|
auto subdir_name = std::string_view(child->path).substr(child->cur_path_ofs); |
|
|
|
auto child_romfs_dir = romfs_dir->GetSubdirectory(subdir_name); |
|
|
|
auto child_ext_dir = ext_dir != nullptr ? ext_dir->GetSubdirectory(subdir_name) : nullptr; |
|
|
|
auto child_ext_dir = ext_dir != nullptr ? ext_dir->GetSubdirectory(name) : nullptr; |
|
|
|
this->VisitDirectory(child_romfs_dir, child_ext_dir, child); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -293,7 +287,7 @@ std::multimap<u64, VirtualFile> RomFSBuildContext::Build() { |
|
|
|
|
|
|
|
cur_entry.name_size = name_size; |
|
|
|
|
|
|
|
out.emplace(cur_file->offset + ROMFS_FILEPARTITION_OFS, cur_file->source); |
|
|
|
out.emplace(cur_file->offset + ROMFS_FILEPARTITION_OFS, std::move(cur_file->source)); |
|
|
|
std::memcpy(file_table.data() + cur_file->entry_offset, &cur_entry, sizeof(RomFSFileEntry)); |
|
|
|
std::memset(file_table.data() + cur_file->entry_offset + sizeof(RomFSFileEntry), 0, |
|
|
|
Common::AlignUp(cur_entry.name_size, 4)); |
|
|
|
|