summaryrefslogtreecommitdiff
path: root/src/frontend_common
diff options
context:
space:
mode:
Diffstat (limited to 'src/frontend_common')
-rw-r--r--src/frontend_common/CMakeLists.txt1
-rw-r--r--src/frontend_common/config.cpp52
-rw-r--r--src/frontend_common/config.h17
-rw-r--r--src/frontend_common/content_manager.h379
4 files changed, 423 insertions, 26 deletions
diff --git a/src/frontend_common/CMakeLists.txt b/src/frontend_common/CMakeLists.txt
index 22e9337c4..94d8cc4c3 100644
--- a/src/frontend_common/CMakeLists.txt
+++ b/src/frontend_common/CMakeLists.txt
@@ -4,6 +4,7 @@
4add_library(frontend_common STATIC 4add_library(frontend_common STATIC
5 config.cpp 5 config.cpp
6 config.h 6 config.h
7 content_manager.h
7) 8)
8 9
9create_target_directory_groups(frontend_common) 10create_target_directory_groups(frontend_common)
diff --git a/src/frontend_common/config.cpp b/src/frontend_common/config.cpp
index 93365394e..905f35118 100644
--- a/src/frontend_common/config.cpp
+++ b/src/frontend_common/config.cpp
@@ -5,13 +5,14 @@
5#include <array> 5#include <array>
6#include "common/fs/fs.h" 6#include "common/fs/fs.h"
7#include "common/fs/path_util.h" 7#include "common/fs/path_util.h"
8#include "common/logging/log.h"
8#include "common/settings.h" 9#include "common/settings.h"
9#include "common/settings_common.h" 10#include "common/settings_common.h"
10#include "common/settings_enums.h" 11#include "common/settings_enums.h"
11#include "config.h" 12#include "config.h"
12#include "core/core.h" 13#include "core/core.h"
13#include "core/hle/service/acc/profile_manager.h" 14#include "core/hle/service/acc/profile_manager.h"
14#include "core/hle/service/hid/controllers/npad.h" 15#include "hid_core/resources/npad/npad.h"
15#include "network/network.h" 16#include "network/network.h"
16 17
17#include <boost/algorithm/string/replace.hpp> 18#include <boost/algorithm/string/replace.hpp>
@@ -58,6 +59,19 @@ void Config::Initialize(const std::optional<std::string> config_path) {
58} 59}
59 60
60void Config::WriteToIni() const { 61void Config::WriteToIni() const {
62 std::string config_type;
63 switch (type) {
64 case ConfigType::GlobalConfig:
65 config_type = "Global";
66 break;
67 case ConfigType::PerGameConfig:
68 config_type = "Game Specific";
69 break;
70 case ConfigType::InputProfile:
71 config_type = "Input Profile";
72 break;
73 }
74 LOG_INFO(Config, "Writing {} configuration to: {}", config_type, config_loc);
61 FILE* fp = nullptr; 75 FILE* fp = nullptr;
62#ifdef _WIN32 76#ifdef _WIN32
63 fp = _wfopen(Common::UTF8ToUTF16W(config_loc).data(), L"wb"); 77 fp = _wfopen(Common::UTF8ToUTF16W(config_loc).data(), L"wb");
@@ -117,10 +131,10 @@ void Config::ReadPlayerValues(const std::size_t player_index) {
117 player_prefix.append("player_").append(ToString(player_index)).append("_"); 131 player_prefix.append("player_").append(ToString(player_index)).append("_");
118 } 132 }
119 133
134 const auto profile_name = ReadStringSetting(std::string(player_prefix).append("profile_name"));
135
120 auto& player = Settings::values.players.GetValue()[player_index]; 136 auto& player = Settings::values.players.GetValue()[player_index];
121 if (IsCustomConfig()) { 137 if (IsCustomConfig()) {
122 const auto profile_name =
123 ReadStringSetting(std::string(player_prefix).append("profile_name"));
124 if (profile_name.empty()) { 138 if (profile_name.empty()) {
125 // Use the global input config 139 // Use the global input config
126 player = Settings::values.players.GetValue(true)[player_index]; 140 player = Settings::values.players.GetValue(true)[player_index];
@@ -139,6 +153,10 @@ void Config::ReadPlayerValues(const std::size_t player_index) {
139 player.controller_type = controller; 153 player.controller_type = controller;
140 } 154 }
141 } else { 155 } else {
156 if (global) {
157 auto& player_global = Settings::values.players.GetValue(true)[player_index];
158 player_global.profile_name = profile_name;
159 }
142 std::string connected_key = player_prefix; 160 std::string connected_key = player_prefix;
143 player.connected = ReadBooleanSetting(connected_key.append("connected"), 161 player.connected = ReadBooleanSetting(connected_key.append("connected"),
144 std::make_optional(player_index == 0)); 162 std::make_optional(player_index == 0));
@@ -425,6 +443,11 @@ void Config::SavePlayerValues(const std::size_t player_index) {
425 std::make_optional(static_cast<u8>(Settings::ControllerType::ProController))); 443 std::make_optional(static_cast<u8>(Settings::ControllerType::ProController)));
426 444
427 if (!player_prefix.empty() || !Settings::IsConfiguringGlobal()) { 445 if (!player_prefix.empty() || !Settings::IsConfiguringGlobal()) {
446 if (global) {
447 const auto& player_global = Settings::values.players.GetValue(true)[player_index];
448 WriteStringSetting(std::string(player_prefix).append("profile_name"),
449 player_global.profile_name, std::make_optional(std::string("")));
450 }
428 WriteBooleanSetting(std::string(player_prefix).append("connected"), player.connected, 451 WriteBooleanSetting(std::string(player_prefix).append("connected"), player.connected,
429 std::make_optional(player_index == 0)); 452 std::make_optional(player_index == 0));
430 WriteIntegerSetting(std::string(player_prefix).append("vibration_enabled"), 453 WriteIntegerSetting(std::string(player_prefix).append("vibration_enabled"),
@@ -481,12 +504,15 @@ void Config::SaveMotionTouchValues() {
481 504
482void Config::SaveValues() { 505void Config::SaveValues() {
483 if (global) { 506 if (global) {
507 LOG_DEBUG(Config, "Saving global generic configuration values");
484 SaveDataStorageValues(); 508 SaveDataStorageValues();
485 SaveDebuggingValues(); 509 SaveDebuggingValues();
486 SaveDisabledAddOnValues(); 510 SaveDisabledAddOnValues();
487 SaveNetworkValues(); 511 SaveNetworkValues();
488 SaveWebServiceValues(); 512 SaveWebServiceValues();
489 SaveMiscellaneousValues(); 513 SaveMiscellaneousValues();
514 } else {
515 LOG_DEBUG(Config, "Saving only generic configuration values");
490 } 516 }
491 SaveControlValues(); 517 SaveControlValues();
492 SaveCoreValues(); 518 SaveCoreValues();
@@ -788,17 +814,6 @@ void Config::WriteBooleanSetting(const std::string& key, const bool& value,
788 WritePreparedSetting(key, AdjustOutputString(ToString(value)), string_default, use_global); 814 WritePreparedSetting(key, AdjustOutputString(ToString(value)), string_default, use_global);
789} 815}
790 816
791template <typename T>
792std::enable_if_t<std::is_integral_v<T>> Config::WriteIntegerSetting(
793 const std::string& key, const T& value, const std::optional<T>& default_value,
794 const std::optional<bool>& use_global) {
795 std::optional<std::string> string_default = std::nullopt;
796 if (default_value.has_value()) {
797 string_default = std::make_optional(ToString(default_value.value()));
798 }
799 WritePreparedSetting(key, AdjustOutputString(ToString(value)), string_default, use_global);
800}
801
802void Config::WriteDoubleSetting(const std::string& key, const double& value, 817void Config::WriteDoubleSetting(const std::string& key, const double& value,
803 const std::optional<double>& default_value, 818 const std::optional<double>& default_value,
804 const std::optional<bool>& use_global) { 819 const std::optional<bool>& use_global) {
@@ -851,10 +866,6 @@ void Config::Reload() {
851 SaveValues(); 866 SaveValues();
852} 867}
853 868
854void Config::Save() {
855 SaveValues();
856}
857
858void Config::ClearControlPlayerValues() const { 869void Config::ClearControlPlayerValues() const {
859 // If key is an empty string, all keys in the current group() are removed. 870 // If key is an empty string, all keys in the current group() are removed.
860 const char* section = Settings::TranslateCategory(Settings::Category::Controls); 871 const char* section = Settings::TranslateCategory(Settings::Category::Controls);
@@ -920,9 +931,10 @@ void Config::WriteSettingGeneric(const Settings::BasicSetting* const setting) {
920 WriteBooleanSetting(std::string(key).append("\\use_global"), setting->UsingGlobal()); 931 WriteBooleanSetting(std::string(key).append("\\use_global"), setting->UsingGlobal());
921 } 932 }
922 if (global || !setting->UsingGlobal()) { 933 if (global || !setting->UsingGlobal()) {
934 auto value = global ? setting->ToStringGlobal() : setting->ToString();
923 WriteBooleanSetting(std::string(key).append("\\default"), 935 WriteBooleanSetting(std::string(key).append("\\default"),
924 setting->ToString() == setting->DefaultToString()); 936 value == setting->DefaultToString());
925 WriteStringSetting(key, setting->ToString()); 937 WriteStringSetting(key, value);
926 } 938 }
927 } else if (global) { 939 } else if (global) {
928 WriteBooleanSetting(std::string(key).append("\\default"), 940 WriteBooleanSetting(std::string(key).append("\\default"),
diff --git a/src/frontend_common/config.h b/src/frontend_common/config.h
index a6c80ddc1..4ecb97044 100644
--- a/src/frontend_common/config.h
+++ b/src/frontend_common/config.h
@@ -51,7 +51,6 @@ protected:
51 [[nodiscard]] bool IsCustomConfig() const; 51 [[nodiscard]] bool IsCustomConfig() const;
52 52
53 void Reload(); 53 void Reload();
54 void Save();
55 54
56 /** 55 /**
57 * Derived config classes must implement this so they can reload all platform-specific 56 * Derived config classes must implement this so they can reload all platform-specific
@@ -163,17 +162,23 @@ protected:
163 void WriteBooleanSetting(const std::string& key, const bool& value, 162 void WriteBooleanSetting(const std::string& key, const bool& value,
164 const std::optional<bool>& default_value = std::nullopt, 163 const std::optional<bool>& default_value = std::nullopt,
165 const std::optional<bool>& use_global = std::nullopt); 164 const std::optional<bool>& use_global = std::nullopt);
166 template <typename T>
167 std::enable_if_t<std::is_integral_v<T>> WriteIntegerSetting(
168 const std::string& key, const T& value,
169 const std::optional<T>& default_value = std::nullopt,
170 const std::optional<bool>& use_global = std::nullopt);
171 void WriteDoubleSetting(const std::string& key, const double& value, 165 void WriteDoubleSetting(const std::string& key, const double& value,
172 const std::optional<double>& default_value = std::nullopt, 166 const std::optional<double>& default_value = std::nullopt,
173 const std::optional<bool>& use_global = std::nullopt); 167 const std::optional<bool>& use_global = std::nullopt);
174 void WriteStringSetting(const std::string& key, const std::string& value, 168 void WriteStringSetting(const std::string& key, const std::string& value,
175 const std::optional<std::string>& default_value = std::nullopt, 169 const std::optional<std::string>& default_value = std::nullopt,
176 const std::optional<bool>& use_global = std::nullopt); 170 const std::optional<bool>& use_global = std::nullopt);
171 template <typename T>
172 std::enable_if_t<std::is_integral_v<T>> WriteIntegerSetting(
173 const std::string& key, const T& value,
174 const std::optional<T>& default_value = std::nullopt,
175 const std::optional<bool>& use_global = std::nullopt) {
176 std::optional<std::string> string_default = std::nullopt;
177 if (default_value.has_value()) {
178 string_default = std::make_optional(ToString(default_value.value()));
179 }
180 WritePreparedSetting(key, AdjustOutputString(ToString(value)), string_default, use_global);
181 }
177 182
178 void ReadCategory(Settings::Category category); 183 void ReadCategory(Settings::Category category);
179 void WriteCategory(Settings::Category category); 184 void WriteCategory(Settings::Category category);
diff --git a/src/frontend_common/content_manager.h b/src/frontend_common/content_manager.h
new file mode 100644
index 000000000..f3efe3465
--- /dev/null
+++ b/src/frontend_common/content_manager.h
@@ -0,0 +1,379 @@
1// SPDX-FileCopyrightText: 2024 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#pragma once
5
6#include <boost/algorithm/string.hpp>
7#include "common/common_types.h"
8#include "common/literals.h"
9#include "core/core.h"
10#include "core/file_sys/common_funcs.h"
11#include "core/file_sys/content_archive.h"
12#include "core/file_sys/fs_filesystem.h"
13#include "core/file_sys/nca_metadata.h"
14#include "core/file_sys/patch_manager.h"
15#include "core/file_sys/registered_cache.h"
16#include "core/file_sys/submission_package.h"
17#include "core/hle/service/filesystem/filesystem.h"
18#include "core/loader/loader.h"
19#include "core/loader/nca.h"
20
21namespace ContentManager {
22
23enum class InstallResult {
24 Success,
25 Overwrite,
26 Failure,
27 BaseInstallAttempted,
28};
29
30enum class GameVerificationResult {
31 Success,
32 Failed,
33 NotImplemented,
34};
35
36/**
37 * \brief Removes a single installed DLC
38 * \param fs_controller [FileSystemController] reference from the Core::System instance
39 * \param title_id Unique title ID representing the DLC which will be removed
40 * \return 'true' if successful
41 */
42inline bool RemoveDLC(const Service::FileSystem::FileSystemController& fs_controller,
43 const u64 title_id) {
44 return fs_controller.GetUserNANDContents()->RemoveExistingEntry(title_id) ||
45 fs_controller.GetSDMCContents()->RemoveExistingEntry(title_id);
46}
47
48/**
49 * \brief Removes all DLC for a game
50 * \param system Reference to the system instance
51 * \param program_id Program ID for the game that will have all of its DLC removed
52 * \return Number of DLC removed
53 */
54inline size_t RemoveAllDLC(Core::System& system, const u64 program_id) {
55 size_t count{};
56 const auto& fs_controller = system.GetFileSystemController();
57 const auto dlc_entries = system.GetContentProvider().ListEntriesFilter(
58 FileSys::TitleType::AOC, FileSys::ContentRecordType::Data);
59 std::vector<u64> program_dlc_entries;
60
61 for (const auto& entry : dlc_entries) {
62 if (FileSys::GetBaseTitleID(entry.title_id) == program_id) {
63 program_dlc_entries.push_back(entry.title_id);
64 }
65 }
66
67 for (const auto& entry : program_dlc_entries) {
68 if (RemoveDLC(fs_controller, entry)) {
69 ++count;
70 }
71 }
72 return count;
73}
74
75/**
76 * \brief Removes the installed update for a game
77 * \param fs_controller [FileSystemController] reference from the Core::System instance
78 * \param program_id Program ID for the game that will have its installed update removed
79 * \return 'true' if successful
80 */
81inline bool RemoveUpdate(const Service::FileSystem::FileSystemController& fs_controller,
82 const u64 program_id) {
83 const auto update_id = program_id | 0x800;
84 return fs_controller.GetUserNANDContents()->RemoveExistingEntry(update_id) ||
85 fs_controller.GetSDMCContents()->RemoveExistingEntry(update_id);
86}
87
88/**
89 * \brief Removes the base content for a game
90 * \param fs_controller [FileSystemController] reference from the Core::System instance
91 * \param program_id Program ID for the game that will have its base content removed
92 * \return 'true' if successful
93 */
94inline bool RemoveBaseContent(const Service::FileSystem::FileSystemController& fs_controller,
95 const u64 program_id) {
96 return fs_controller.GetUserNANDContents()->RemoveExistingEntry(program_id) ||
97 fs_controller.GetSDMCContents()->RemoveExistingEntry(program_id);
98}
99
100/**
101 * \brief Removes a mod for a game
102 * \param fs_controller [FileSystemController] reference from the Core::System instance
103 * \param program_id Program ID for the game where [mod_name] will be removed
104 * \param mod_name The name of a mod as given by FileSys::PatchManager::GetPatches. This corresponds
105 * with the name of the mod's directory in a game's load folder.
106 * \return 'true' if successful
107 */
108inline bool RemoveMod(const Service::FileSystem::FileSystemController& fs_controller,
109 const u64 program_id, const std::string& mod_name) {
110 // Check general Mods (LayeredFS and IPS)
111 const auto mod_dir = fs_controller.GetModificationLoadRoot(program_id);
112 if (mod_dir != nullptr) {
113 return mod_dir->DeleteSubdirectoryRecursive(mod_name);
114 }
115
116 // Check SDMC mod directory (RomFS LayeredFS)
117 const auto sdmc_mod_dir = fs_controller.GetSDMCModificationLoadRoot(program_id);
118 if (sdmc_mod_dir != nullptr) {
119 return sdmc_mod_dir->DeleteSubdirectoryRecursive(mod_name);
120 }
121
122 return false;
123}
124
125/**
126 * \brief Installs an NSP
127 * \param system Reference to the system instance
128 * \param vfs Reference to the VfsFilesystem instance in Core::System
129 * \param filename Path to the NSP file
130 * \param callback Callback to report the progress of the installation. The first size_t
131 * parameter is the total size of the virtual file and the second is the current progress. If you
132 * return true to the callback, it will cancel the installation as soon as possible.
133 * \return [InstallResult] representing how the installation finished
134 */
135inline InstallResult InstallNSP(Core::System& system, FileSys::VfsFilesystem& vfs,
136 const std::string& filename,
137 const std::function<bool(size_t, size_t)>& callback) {
138 const auto copy = [callback](const FileSys::VirtualFile& src, const FileSys::VirtualFile& dest,
139 std::size_t block_size) {
140 if (src == nullptr || dest == nullptr) {
141 return false;
142 }
143 if (!dest->Resize(src->GetSize())) {
144 return false;
145 }
146
147 using namespace Common::Literals;
148 std::vector<u8> buffer(1_MiB);
149
150 for (std::size_t i = 0; i < src->GetSize(); i += buffer.size()) {
151 if (callback(src->GetSize(), i)) {
152 dest->Resize(0);
153 return false;
154 }
155 const auto read = src->Read(buffer.data(), buffer.size(), i);
156 dest->Write(buffer.data(), read, i);
157 }
158 return true;
159 };
160
161 std::shared_ptr<FileSys::NSP> nsp;
162 FileSys::VirtualFile file = vfs.OpenFile(filename, FileSys::OpenMode::Read);
163 if (boost::to_lower_copy(file->GetName()).ends_with(std::string("nsp"))) {
164 nsp = std::make_shared<FileSys::NSP>(file);
165 if (nsp->IsExtractedType()) {
166 return InstallResult::Failure;
167 }
168 } else {
169 return InstallResult::Failure;
170 }
171
172 if (nsp->GetStatus() != Loader::ResultStatus::Success) {
173 return InstallResult::Failure;
174 }
175 const auto res =
176 system.GetFileSystemController().GetUserNANDContents()->InstallEntry(*nsp, true, copy);
177 switch (res) {
178 case FileSys::InstallResult::Success:
179 return InstallResult::Success;
180 case FileSys::InstallResult::OverwriteExisting:
181 return InstallResult::Overwrite;
182 case FileSys::InstallResult::ErrorBaseInstall:
183 return InstallResult::BaseInstallAttempted;
184 default:
185 return InstallResult::Failure;
186 }
187}
188
189/**
190 * \brief Installs an NCA
191 * \param vfs Reference to the VfsFilesystem instance in Core::System
192 * \param filename Path to the NCA file
193 * \param registered_cache Reference to the registered cache that the NCA will be installed to
194 * \param title_type Type of NCA package to install
195 * \param callback Callback to report the progress of the installation. The first size_t
196 * parameter is the total size of the virtual file and the second is the current progress. If you
197 * return true to the callback, it will cancel the installation as soon as possible.
198 * \return [InstallResult] representing how the installation finished
199 */
200inline InstallResult InstallNCA(FileSys::VfsFilesystem& vfs, const std::string& filename,
201 FileSys::RegisteredCache& registered_cache,
202 const FileSys::TitleType title_type,
203 const std::function<bool(size_t, size_t)>& callback) {
204 const auto copy = [callback](const FileSys::VirtualFile& src, const FileSys::VirtualFile& dest,
205 std::size_t block_size) {
206 if (src == nullptr || dest == nullptr) {
207 return false;
208 }
209 if (!dest->Resize(src->GetSize())) {
210 return false;
211 }
212
213 using namespace Common::Literals;
214 std::vector<u8> buffer(1_MiB);
215
216 for (std::size_t i = 0; i < src->GetSize(); i += buffer.size()) {
217 if (callback(src->GetSize(), i)) {
218 dest->Resize(0);
219 return false;
220 }
221 const auto read = src->Read(buffer.data(), buffer.size(), i);
222 dest->Write(buffer.data(), read, i);
223 }
224 return true;
225 };
226
227 const auto nca =
228 std::make_shared<FileSys::NCA>(vfs.OpenFile(filename, FileSys::OpenMode::Read));
229 const auto id = nca->GetStatus();
230
231 // Game updates necessary are missing base RomFS
232 if (id != Loader::ResultStatus::Success &&
233 id != Loader::ResultStatus::ErrorMissingBKTRBaseRomFS) {
234 return InstallResult::Failure;
235 }
236
237 const auto res = registered_cache.InstallEntry(*nca, title_type, true, copy);
238 if (res == FileSys::InstallResult::Success) {
239 return InstallResult::Success;
240 } else if (res == FileSys::InstallResult::OverwriteExisting) {
241 return InstallResult::Overwrite;
242 } else {
243 return InstallResult::Failure;
244 }
245}
246
247/**
248 * \brief Verifies the installed contents for a given ManualContentProvider
249 * \param system Reference to the system instance
250 * \param provider Reference to the content provider that's tracking indexed games
251 * \param callback Callback to report the progress of the installation. The first size_t
252 * parameter is the total size of the installed contents and the second is the current progress. If
253 * you return true to the callback, it will cancel the installation as soon as possible.
254 * \return A list of entries that failed to install. Returns an empty vector if successful.
255 */
256inline std::vector<std::string> VerifyInstalledContents(
257 Core::System& system, FileSys::ManualContentProvider& provider,
258 const std::function<bool(size_t, size_t)>& callback) {
259 // Get content registries.
260 auto bis_contents = system.GetFileSystemController().GetSystemNANDContents();
261 auto user_contents = system.GetFileSystemController().GetUserNANDContents();
262
263 std::vector<FileSys::RegisteredCache*> content_providers;
264 if (bis_contents) {
265 content_providers.push_back(bis_contents);
266 }
267 if (user_contents) {
268 content_providers.push_back(user_contents);
269 }
270
271 // Get associated NCA files.
272 std::vector<FileSys::VirtualFile> nca_files;
273
274 // Get all installed IDs.
275 size_t total_size = 0;
276 for (auto nca_provider : content_providers) {
277 const auto entries = nca_provider->ListEntriesFilter();
278
279 for (const auto& entry : entries) {
280 auto nca_file = nca_provider->GetEntryRaw(entry.title_id, entry.type);
281 if (!nca_file) {
282 continue;
283 }
284
285 total_size += nca_file->GetSize();
286 nca_files.push_back(std::move(nca_file));
287 }
288 }
289
290 // Declare a list of file names which failed to verify.
291 std::vector<std::string> failed;
292
293 size_t processed_size = 0;
294 bool cancelled = false;
295 auto nca_callback = [&](size_t nca_processed, size_t nca_total) {
296 cancelled = callback(total_size, processed_size + nca_processed);
297 return !cancelled;
298 };
299
300 // Using the NCA loader, determine if all NCAs are valid.
301 for (auto& nca_file : nca_files) {
302 Loader::AppLoader_NCA nca_loader(nca_file);
303
304 auto status = nca_loader.VerifyIntegrity(nca_callback);
305 if (cancelled) {
306 break;
307 }
308 if (status != Loader::ResultStatus::Success) {
309 FileSys::NCA nca(nca_file);
310 const auto title_id = nca.GetTitleId();
311 std::string title_name = "unknown";
312
313 const auto control = provider.GetEntry(FileSys::GetBaseTitleID(title_id),
314 FileSys::ContentRecordType::Control);
315 if (control && control->GetStatus() == Loader::ResultStatus::Success) {
316 const FileSys::PatchManager pm{title_id, system.GetFileSystemController(),
317 provider};
318 const auto [nacp, logo] = pm.ParseControlNCA(*control);
319 if (nacp) {
320 title_name = nacp->GetApplicationName();
321 }
322 }
323
324 if (title_id > 0) {
325 failed.push_back(
326 fmt::format("{} ({:016X}) ({})", nca_file->GetName(), title_id, title_name));
327 } else {
328 failed.push_back(fmt::format("{} (unknown)", nca_file->GetName()));
329 }
330 }
331
332 processed_size += nca_file->GetSize();
333 }
334 return failed;
335}
336
337/**
338 * \brief Verifies the contents of a given game
339 * \param system Reference to the system instance
340 * \param game_path Patch to the game file
341 * \param callback Callback to report the progress of the installation. The first size_t
342 * parameter is the total size of the installed contents and the second is the current progress. If
343 * you return true to the callback, it will cancel the installation as soon as possible.
344 * \return GameVerificationResult representing how the verification process finished
345 */
346inline GameVerificationResult VerifyGameContents(
347 Core::System& system, const std::string& game_path,
348 const std::function<bool(size_t, size_t)>& callback) {
349 const auto loader = Loader::GetLoader(
350 system, system.GetFilesystem()->OpenFile(game_path, FileSys::OpenMode::Read));
351 if (loader == nullptr) {
352 return GameVerificationResult::NotImplemented;
353 }
354
355 bool cancelled = false;
356 auto loader_callback = [&](size_t processed, size_t total) {
357 cancelled = callback(total, processed);
358 return !cancelled;
359 };
360
361 const auto status = loader->VerifyIntegrity(loader_callback);
362 if (cancelled || status == Loader::ResultStatus::ErrorIntegrityVerificationNotImplemented) {
363 return GameVerificationResult::NotImplemented;
364 }
365
366 if (status == Loader::ResultStatus::ErrorIntegrityVerificationFailed) {
367 return GameVerificationResult::Failed;
368 }
369 return GameVerificationResult::Success;
370}
371
372/**
373 * Checks if the keys required for decrypting firmware and games are available
374 */
375inline bool AreKeysPresent() {
376 return !Core::Crypto::KeyManager::Instance().BaseDeriveNecessary();
377}
378
379} // namespace ContentManager