patch_manager: Use strings for patch type instead of enum
This commit is contained in:
		| @@ -34,16 +34,6 @@ std::string FormatTitleVersion(u32 version, TitleVersionFormat format) { | |||||||
|     return fmt::format("v{}.{}.{}", bytes[3], bytes[2], bytes[1]); |     return fmt::format("v{}.{}.{}", bytes[3], bytes[2], bytes[1]); | ||||||
| } | } | ||||||
|  |  | ||||||
| constexpr std::array<const char*, 3> PATCH_TYPE_NAMES{ |  | ||||||
|     "Update", |  | ||||||
|     "LayeredFS", |  | ||||||
|     "DLC", |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| std::string FormatPatchTypeName(PatchType type) { |  | ||||||
|     return PATCH_TYPE_NAMES.at(static_cast<std::size_t>(type)); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| PatchManager::PatchManager(u64 title_id) : title_id(title_id) {} | PatchManager::PatchManager(u64 title_id) : title_id(title_id) {} | ||||||
|  |  | ||||||
| PatchManager::~PatchManager() = default; | PatchManager::~PatchManager() = default; | ||||||
| @@ -138,8 +128,19 @@ VirtualFile PatchManager::PatchRomFS(VirtualFile romfs, u64 ivfc_offset, | |||||||
|     return romfs; |     return romfs; | ||||||
| } | } | ||||||
|  |  | ||||||
| std::map<PatchType, std::string> PatchManager::GetPatchVersionNames() const { | void AppendCommaIfNotEmpty(std::string& to, const std::string& with) { | ||||||
|     std::map<PatchType, std::string> out; |     if (to.empty()) | ||||||
|  |         to += with; | ||||||
|  |     else | ||||||
|  |         to += ", " + with; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | static bool IsDirValidAndNonEmpty(const VirtualDir& dir) { | ||||||
|  |     return dir != nullptr && (!dir->GetFiles().empty() || !dir->GetSubdirectories().empty()); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | std::map<std::string, std::string> PatchManager::GetPatchVersionNames() const { | ||||||
|  |     std::map<std::string, std::string> out; | ||||||
|     const auto installed = Service::FileSystem::GetUnionContents(); |     const auto installed = Service::FileSystem::GetUnionContents(); | ||||||
|  |  | ||||||
|     // Game Updates |     // Game Updates | ||||||
| @@ -148,23 +149,34 @@ std::map<PatchType, std::string> PatchManager::GetPatchVersionNames() const { | |||||||
|     auto [nacp, discard_icon_file] = update.GetControlMetadata(); |     auto [nacp, discard_icon_file] = update.GetControlMetadata(); | ||||||
|  |  | ||||||
|     if (nacp != nullptr) { |     if (nacp != nullptr) { | ||||||
|         out[PatchType::Update] = nacp->GetVersionString(); |         out["Update"] = nacp->GetVersionString(); | ||||||
|     } else { |     } else { | ||||||
|         if (installed->HasEntry(update_tid, ContentRecordType::Program)) { |         if (installed->HasEntry(update_tid, ContentRecordType::Program)) { | ||||||
|             const auto meta_ver = installed->GetEntryVersion(update_tid); |             const auto meta_ver = installed->GetEntryVersion(update_tid); | ||||||
|             if (meta_ver == boost::none || meta_ver.get() == 0) { |             if (meta_ver == boost::none || meta_ver.get() == 0) { | ||||||
|                 out[PatchType::Update] = ""; |                 out["Update"] = ""; | ||||||
|             } else { |             } else { | ||||||
|                 out[PatchType::Update] = |                 out["Update"] = | ||||||
|                     FormatTitleVersion(meta_ver.get(), TitleVersionFormat::ThreeElements); |                     FormatTitleVersion(meta_ver.get(), TitleVersionFormat::ThreeElements); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     // LayeredFS |     const auto mod_dir = Service::FileSystem::GetModificationLoadRoot(title_id); | ||||||
|     const auto lfs_dir = Service::FileSystem::GetModificationLoadRoot(title_id); |     if (mod_dir != nullptr && mod_dir->GetSize() > 0) { | ||||||
|     if (lfs_dir != nullptr && lfs_dir->GetSize() > 0) |         for (const auto& mod : mod_dir->GetSubdirectories()) { | ||||||
|         out.insert_or_assign(PatchType::LayeredFS, ""); |             std::string types; | ||||||
|  |             if (IsDirValidAndNonEmpty(mod->GetSubdirectory("exefs"))) | ||||||
|  |                 AppendCommaIfNotEmpty(types, "IPS"); | ||||||
|  |             if (IsDirValidAndNonEmpty(mod->GetSubdirectory("romfs"))) | ||||||
|  |                 AppendCommaIfNotEmpty(types, "LayeredFS"); | ||||||
|  |  | ||||||
|  |             if (types.empty()) | ||||||
|  |                 continue; | ||||||
|  |  | ||||||
|  |             out.insert_or_assign(mod->GetName(), types); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     // DLC |     // DLC | ||||||
|     const auto dlc_entries = installed->ListEntriesFilter(TitleType::AOC, ContentRecordType::Data); |     const auto dlc_entries = installed->ListEntriesFilter(TitleType::AOC, ContentRecordType::Data); | ||||||
|   | |||||||
| @@ -24,14 +24,6 @@ enum class TitleVersionFormat : u8 { | |||||||
| std::string FormatTitleVersion(u32 version, | std::string FormatTitleVersion(u32 version, | ||||||
|                                TitleVersionFormat format = TitleVersionFormat::ThreeElements); |                                TitleVersionFormat format = TitleVersionFormat::ThreeElements); | ||||||
|  |  | ||||||
| enum class PatchType { |  | ||||||
|     Update, |  | ||||||
|     LayeredFS, |  | ||||||
|     DLC, |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| std::string FormatPatchTypeName(PatchType type); |  | ||||||
|  |  | ||||||
| // A centralized class to manage patches to games. | // A centralized class to manage patches to games. | ||||||
| class PatchManager { | class PatchManager { | ||||||
| public: | public: | ||||||
| @@ -49,8 +41,8 @@ public: | |||||||
|                            ContentRecordType type = ContentRecordType::Program) const; |                            ContentRecordType type = ContentRecordType::Program) const; | ||||||
|  |  | ||||||
|     // Returns a vector of pairs between patch names and patch versions. |     // Returns a vector of pairs between patch names and patch versions. | ||||||
|     // i.e. Update v80 will return {Update, 80} |     // i.e. Update 3.2.2 will return {"Update", "3.2.2"} | ||||||
|     std::map<PatchType, std::string> GetPatchVersionNames() const; |     std::map<std::string, std::string> GetPatchVersionNames() const; | ||||||
|  |  | ||||||
|     // Given title_id of the program, attempts to get the control data of the update and parse it, |     // Given title_id of the program, attempts to get the control data of the update and parse it, | ||||||
|     // falling back to the base control data. |     // falling back to the base control data. | ||||||
|   | |||||||
| @@ -60,14 +60,13 @@ QString FormatGameName(const std::string& physical_name) { | |||||||
| QString FormatPatchNameVersions(const FileSys::PatchManager& patch_manager, bool updatable = true) { | QString FormatPatchNameVersions(const FileSys::PatchManager& patch_manager, bool updatable = true) { | ||||||
|     QString out; |     QString out; | ||||||
|     for (const auto& kv : patch_manager.GetPatchVersionNames()) { |     for (const auto& kv : patch_manager.GetPatchVersionNames()) { | ||||||
|         if (!updatable && kv.first == FileSys::PatchType::Update) |         if (!updatable && kv.first == "Update") | ||||||
|             continue; |             continue; | ||||||
|  |  | ||||||
|         if (kv.second.empty()) { |         if (kv.second.empty()) { | ||||||
|             out.append(fmt::format("{}\n", FileSys::FormatPatchTypeName(kv.first)).c_str()); |             out.append(fmt::format("{}\n", kv.first).c_str()); | ||||||
|         } else { |         } else { | ||||||
|             out.append(fmt::format("{} ({})\n", FileSys::FormatPatchTypeName(kv.first), kv.second) |             out.append(fmt::format("{} ({})\n", kv.first, kv.second).c_str()); | ||||||
|                            .c_str()); |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user