diff options
| author | 2018-09-25 20:09:20 -0400 | |
|---|---|---|
| committer | 2018-09-25 20:09:23 -0400 | |
| commit | 11104b48834b2f8e5c59edc46b794e6ab0bd9c4f (patch) | |
| tree | 96e9e8906d1facc976b199be17b03094d23310f1 | |
| parent | vfs_vector: Amend initializer list order in VectorVfsFile's constructor initi... (diff) | |
| download | yuzu-11104b48834b2f8e5c59edc46b794e6ab0bd9c4f.tar.gz yuzu-11104b48834b2f8e5c59edc46b794e6ab0bd9c4f.tar.xz yuzu-11104b48834b2f8e5c59edc46b794e6ab0bd9c4f.zip | |
patch_manager: Invert conditionals within ApplyLayeredFS()
Avoids the need to nest code quite a bit by early-exiting in error
cases.
| -rw-r--r-- | src/core/file_sys/patch_manager.cpp | 57 |
1 files changed, 30 insertions, 27 deletions
diff --git a/src/core/file_sys/patch_manager.cpp b/src/core/file_sys/patch_manager.cpp index 561ad67a7..4b3b5e665 100644 --- a/src/core/file_sys/patch_manager.cpp +++ b/src/core/file_sys/patch_manager.cpp | |||
| @@ -70,37 +70,40 @@ VirtualDir PatchManager::PatchExeFS(VirtualDir exefs) const { | |||
| 70 | 70 | ||
| 71 | static void ApplyLayeredFS(VirtualFile& romfs, u64 title_id, ContentRecordType type) { | 71 | static void ApplyLayeredFS(VirtualFile& romfs, u64 title_id, ContentRecordType type) { |
| 72 | const auto load_dir = Service::FileSystem::GetModificationLoadRoot(title_id); | 72 | const auto load_dir = Service::FileSystem::GetModificationLoadRoot(title_id); |
| 73 | if (type == ContentRecordType::Program && load_dir != nullptr && load_dir->GetSize() > 0) { | 73 | if (type != ContentRecordType::Program || load_dir == nullptr || load_dir->GetSize() <= 0) { |
| 74 | auto extracted = ExtractRomFS(romfs); | 74 | return; |
| 75 | 75 | } | |
| 76 | if (extracted != nullptr) { | ||
| 77 | auto patch_dirs = load_dir->GetSubdirectories(); | ||
| 78 | std::sort(patch_dirs.begin(), patch_dirs.end(), | ||
| 79 | [](const VirtualDir& l, const VirtualDir& r) { | ||
| 80 | return l->GetName() < r->GetName(); | ||
| 81 | }); | ||
| 82 | |||
| 83 | std::vector<VirtualDir> layers; | ||
| 84 | layers.reserve(patch_dirs.size() + 1); | ||
| 85 | for (const auto& subdir : patch_dirs) { | ||
| 86 | auto romfs_dir = subdir->GetSubdirectory("romfs"); | ||
| 87 | if (romfs_dir != nullptr) | ||
| 88 | layers.push_back(std::move(romfs_dir)); | ||
| 89 | } | ||
| 90 | 76 | ||
| 91 | layers.push_back(std::move(extracted)); | 77 | auto extracted = ExtractRomFS(romfs); |
| 78 | if (extracted == nullptr) { | ||
| 79 | return; | ||
| 80 | } | ||
| 92 | 81 | ||
| 93 | auto layered = LayeredVfsDirectory::MakeLayeredDirectory(std::move(layers)); | 82 | auto patch_dirs = load_dir->GetSubdirectories(); |
| 94 | if (layered != nullptr) { | 83 | std::sort(patch_dirs.begin(), patch_dirs.end(), |
| 95 | auto packed = CreateRomFS(std::move(layered)); | 84 | [](const VirtualDir& l, const VirtualDir& r) { return l->GetName() < r->GetName(); }); |
| 96 | 85 | ||
| 97 | if (packed != nullptr) { | 86 | std::vector<VirtualDir> layers; |
| 98 | LOG_INFO(Loader, " RomFS: LayeredFS patches applied successfully"); | 87 | layers.reserve(patch_dirs.size() + 1); |
| 99 | romfs = std::move(packed); | 88 | for (const auto& subdir : patch_dirs) { |
| 100 | } | 89 | auto romfs_dir = subdir->GetSubdirectory("romfs"); |
| 101 | } | 90 | if (romfs_dir != nullptr) |
| 102 | } | 91 | layers.push_back(std::move(romfs_dir)); |
| 103 | } | 92 | } |
| 93 | layers.push_back(std::move(extracted)); | ||
| 94 | |||
| 95 | auto layered = LayeredVfsDirectory::MakeLayeredDirectory(std::move(layers)); | ||
| 96 | if (layered == nullptr) { | ||
| 97 | return; | ||
| 98 | } | ||
| 99 | |||
| 100 | auto packed = CreateRomFS(std::move(layered)); | ||
| 101 | if (packed == nullptr) { | ||
| 102 | return; | ||
| 103 | } | ||
| 104 | |||
| 105 | LOG_INFO(Loader, " RomFS: LayeredFS patches applied successfully"); | ||
| 106 | romfs = std::move(packed); | ||
| 104 | } | 107 | } |
| 105 | 108 | ||
| 106 | VirtualFile PatchManager::PatchRomFS(VirtualFile romfs, u64 ivfc_offset, | 109 | VirtualFile PatchManager::PatchRomFS(VirtualFile romfs, u64 ivfc_offset, |