diff options
| author | 2018-09-29 22:14:01 -0400 | |
|---|---|---|
| committer | 2018-10-01 16:02:50 -0400 | |
| commit | 4c2a94fa94e0192402c816c74f5a09061e3df520 (patch) | |
| tree | 5600f34e700159ac679db7bc1bde6af96c447dd1 /src | |
| parent | file_sys: Implement function to apply IPS patches (diff) | |
| download | yuzu-4c2a94fa94e0192402c816c74f5a09061e3df520.tar.gz yuzu-4c2a94fa94e0192402c816c74f5a09061e3df520.tar.xz yuzu-4c2a94fa94e0192402c816c74f5a09061e3df520.zip | |
patch_manager: Use strings for patch type instead of enum
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/file_sys/patch_manager.cpp | 50 | ||||
| -rw-r--r-- | src/core/file_sys/patch_manager.h | 12 | ||||
| -rw-r--r-- | src/yuzu/game_list_worker.cpp | 7 |
3 files changed, 36 insertions, 33 deletions
diff --git a/src/core/file_sys/patch_manager.cpp b/src/core/file_sys/patch_manager.cpp index 57b7741f8..10b4acc92 100644 --- a/src/core/file_sys/patch_manager.cpp +++ b/src/core/file_sys/patch_manager.cpp | |||
| @@ -34,16 +34,6 @@ std::string FormatTitleVersion(u32 version, TitleVersionFormat format) { | |||
| 34 | return fmt::format("v{}.{}.{}", bytes[3], bytes[2], bytes[1]); | 34 | return fmt::format("v{}.{}.{}", bytes[3], bytes[2], bytes[1]); |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | constexpr std::array<const char*, 3> PATCH_TYPE_NAMES{ | ||
| 38 | "Update", | ||
| 39 | "LayeredFS", | ||
| 40 | "DLC", | ||
| 41 | }; | ||
| 42 | |||
| 43 | std::string FormatPatchTypeName(PatchType type) { | ||
| 44 | return PATCH_TYPE_NAMES.at(static_cast<std::size_t>(type)); | ||
| 45 | } | ||
| 46 | |||
| 47 | PatchManager::PatchManager(u64 title_id) : title_id(title_id) {} | 37 | PatchManager::PatchManager(u64 title_id) : title_id(title_id) {} |
| 48 | 38 | ||
| 49 | PatchManager::~PatchManager() = default; | 39 | PatchManager::~PatchManager() = default; |
| @@ -138,8 +128,19 @@ VirtualFile PatchManager::PatchRomFS(VirtualFile romfs, u64 ivfc_offset, | |||
| 138 | return romfs; | 128 | return romfs; |
| 139 | } | 129 | } |
| 140 | 130 | ||
| 141 | std::map<PatchType, std::string> PatchManager::GetPatchVersionNames() const { | 131 | void AppendCommaIfNotEmpty(std::string& to, const std::string& with) { |
| 142 | std::map<PatchType, std::string> out; | 132 | if (to.empty()) |
| 133 | to += with; | ||
| 134 | else | ||
| 135 | to += ", " + with; | ||
| 136 | } | ||
| 137 | |||
| 138 | static bool IsDirValidAndNonEmpty(const VirtualDir& dir) { | ||
| 139 | return dir != nullptr && (!dir->GetFiles().empty() || !dir->GetSubdirectories().empty()); | ||
| 140 | } | ||
| 141 | |||
| 142 | std::map<std::string, std::string> PatchManager::GetPatchVersionNames() const { | ||
| 143 | std::map<std::string, std::string> out; | ||
| 143 | const auto installed = Service::FileSystem::GetUnionContents(); | 144 | const auto installed = Service::FileSystem::GetUnionContents(); |
| 144 | 145 | ||
| 145 | // Game Updates | 146 | // Game Updates |
| @@ -148,23 +149,34 @@ std::map<PatchType, std::string> PatchManager::GetPatchVersionNames() const { | |||
| 148 | auto [nacp, discard_icon_file] = update.GetControlMetadata(); | 149 | auto [nacp, discard_icon_file] = update.GetControlMetadata(); |
| 149 | 150 | ||
| 150 | if (nacp != nullptr) { | 151 | if (nacp != nullptr) { |
| 151 | out[PatchType::Update] = nacp->GetVersionString(); | 152 | out["Update"] = nacp->GetVersionString(); |
| 152 | } else { | 153 | } else { |
| 153 | if (installed->HasEntry(update_tid, ContentRecordType::Program)) { | 154 | if (installed->HasEntry(update_tid, ContentRecordType::Program)) { |
| 154 | const auto meta_ver = installed->GetEntryVersion(update_tid); | 155 | const auto meta_ver = installed->GetEntryVersion(update_tid); |
| 155 | if (meta_ver == boost::none || meta_ver.get() == 0) { | 156 | if (meta_ver == boost::none || meta_ver.get() == 0) { |
| 156 | out[PatchType::Update] = ""; | 157 | out["Update"] = ""; |
| 157 | } else { | 158 | } else { |
| 158 | out[PatchType::Update] = | 159 | out["Update"] = |
| 159 | FormatTitleVersion(meta_ver.get(), TitleVersionFormat::ThreeElements); | 160 | FormatTitleVersion(meta_ver.get(), TitleVersionFormat::ThreeElements); |
| 160 | } | 161 | } |
| 161 | } | 162 | } |
| 162 | } | 163 | } |
| 163 | 164 | ||
| 164 | // LayeredFS | 165 | const auto mod_dir = Service::FileSystem::GetModificationLoadRoot(title_id); |
| 165 | const auto lfs_dir = Service::FileSystem::GetModificationLoadRoot(title_id); | 166 | if (mod_dir != nullptr && mod_dir->GetSize() > 0) { |
| 166 | if (lfs_dir != nullptr && lfs_dir->GetSize() > 0) | 167 | for (const auto& mod : mod_dir->GetSubdirectories()) { |
| 167 | out.insert_or_assign(PatchType::LayeredFS, ""); | 168 | std::string types; |
| 169 | if (IsDirValidAndNonEmpty(mod->GetSubdirectory("exefs"))) | ||
| 170 | AppendCommaIfNotEmpty(types, "IPS"); | ||
| 171 | if (IsDirValidAndNonEmpty(mod->GetSubdirectory("romfs"))) | ||
| 172 | AppendCommaIfNotEmpty(types, "LayeredFS"); | ||
| 173 | |||
| 174 | if (types.empty()) | ||
| 175 | continue; | ||
| 176 | |||
| 177 | out.insert_or_assign(mod->GetName(), types); | ||
| 178 | } | ||
| 179 | } | ||
| 168 | 180 | ||
| 169 | // DLC | 181 | // DLC |
| 170 | const auto dlc_entries = installed->ListEntriesFilter(TitleType::AOC, ContentRecordType::Data); | 182 | const auto dlc_entries = installed->ListEntriesFilter(TitleType::AOC, ContentRecordType::Data); |
diff --git a/src/core/file_sys/patch_manager.h b/src/core/file_sys/patch_manager.h index 3a2a9d212..7807515f9 100644 --- a/src/core/file_sys/patch_manager.h +++ b/src/core/file_sys/patch_manager.h | |||
| @@ -24,14 +24,6 @@ enum class TitleVersionFormat : u8 { | |||
| 24 | std::string FormatTitleVersion(u32 version, | 24 | std::string FormatTitleVersion(u32 version, |
| 25 | TitleVersionFormat format = TitleVersionFormat::ThreeElements); | 25 | TitleVersionFormat format = TitleVersionFormat::ThreeElements); |
| 26 | 26 | ||
| 27 | enum class PatchType { | ||
| 28 | Update, | ||
| 29 | LayeredFS, | ||
| 30 | DLC, | ||
| 31 | }; | ||
| 32 | |||
| 33 | std::string FormatPatchTypeName(PatchType type); | ||
| 34 | |||
| 35 | // A centralized class to manage patches to games. | 27 | // A centralized class to manage patches to games. |
| 36 | class PatchManager { | 28 | class PatchManager { |
| 37 | public: | 29 | public: |
| @@ -49,8 +41,8 @@ public: | |||
| 49 | ContentRecordType type = ContentRecordType::Program) const; | 41 | ContentRecordType type = ContentRecordType::Program) const; |
| 50 | 42 | ||
| 51 | // Returns a vector of pairs between patch names and patch versions. | 43 | // Returns a vector of pairs between patch names and patch versions. |
| 52 | // i.e. Update v80 will return {Update, 80} | 44 | // i.e. Update 3.2.2 will return {"Update", "3.2.2"} |
| 53 | std::map<PatchType, std::string> GetPatchVersionNames() const; | 45 | std::map<std::string, std::string> GetPatchVersionNames() const; |
| 54 | 46 | ||
| 55 | // Given title_id of the program, attempts to get the control data of the update and parse it, | 47 | // Given title_id of the program, attempts to get the control data of the update and parse it, |
| 56 | // falling back to the base control data. | 48 | // falling back to the base control data. |
diff --git a/src/yuzu/game_list_worker.cpp b/src/yuzu/game_list_worker.cpp index e228d61bd..1947bdb93 100644 --- a/src/yuzu/game_list_worker.cpp +++ b/src/yuzu/game_list_worker.cpp | |||
| @@ -60,14 +60,13 @@ QString FormatGameName(const std::string& physical_name) { | |||
| 60 | QString FormatPatchNameVersions(const FileSys::PatchManager& patch_manager, bool updatable = true) { | 60 | QString FormatPatchNameVersions(const FileSys::PatchManager& patch_manager, bool updatable = true) { |
| 61 | QString out; | 61 | QString out; |
| 62 | for (const auto& kv : patch_manager.GetPatchVersionNames()) { | 62 | for (const auto& kv : patch_manager.GetPatchVersionNames()) { |
| 63 | if (!updatable && kv.first == FileSys::PatchType::Update) | 63 | if (!updatable && kv.first == "Update") |
| 64 | continue; | 64 | continue; |
| 65 | 65 | ||
| 66 | if (kv.second.empty()) { | 66 | if (kv.second.empty()) { |
| 67 | out.append(fmt::format("{}\n", FileSys::FormatPatchTypeName(kv.first)).c_str()); | 67 | out.append(fmt::format("{}\n", kv.first).c_str()); |
| 68 | } else { | 68 | } else { |
| 69 | out.append(fmt::format("{} ({})\n", FileSys::FormatPatchTypeName(kv.first), kv.second) | 69 | out.append(fmt::format("{} ({})\n", kv.first, kv.second).c_str()); |
| 70 | .c_str()); | ||
| 71 | } | 70 | } |
| 72 | } | 71 | } |
| 73 | 72 | ||