summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Lioncash2018-11-27 13:52:13 -0500
committerGravatar Lioncash2018-11-27 16:33:14 -0500
commitd72c809030ac74c532dd0126bf2ce7494a01cc9b (patch)
treecdccfa369f2be364e8b58bfad41fa1b1f8093790
parentMerge pull request #1806 from ReinUsesLisp/morton-fixup (diff)
downloadyuzu-d72c809030ac74c532dd0126bf2ce7494a01cc9b.tar.gz
yuzu-d72c809030ac74c532dd0126bf2ce7494a01cc9b.tar.xz
yuzu-d72c809030ac74c532dd0126bf2ce7494a01cc9b.zip
file_sys/registered_cache: Use regular const references instead of std::shared_ptr for InstallEntry()
These parameters don't need to utilize a shared lifecycle directly in the interface. Instead, the caller should provide a regular reference for the function to use. This also allows the type system to flag attempts to pass nullptr and makes it more generic, since it can now be used in contexts where a shared_ptr isn't being used (in other words, we don't constrain the usage of the interface to a particular mode of memory management).
-rw-r--r--src/core/file_sys/registered_cache.cpp44
-rw-r--r--src/core/file_sys/registered_cache.h9
-rw-r--r--src/yuzu/main.cpp10
3 files changed, 31 insertions, 32 deletions
diff --git a/src/core/file_sys/registered_cache.cpp b/src/core/file_sys/registered_cache.cpp
index a3f8f2f73..07c3af64a 100644
--- a/src/core/file_sys/registered_cache.cpp
+++ b/src/core/file_sys/registered_cache.cpp
@@ -381,22 +381,22 @@ std::vector<RegisteredCacheEntry> RegisteredCache::ListEntriesFilter(
381 return out; 381 return out;
382} 382}
383 383
384static std::shared_ptr<NCA> GetNCAFromNSPForID(std::shared_ptr<NSP> nsp, const NcaID& id) { 384static std::shared_ptr<NCA> GetNCAFromNSPForID(const NSP& nsp, const NcaID& id) {
385 const auto file = nsp->GetFile(fmt::format("{}.nca", Common::HexArrayToString(id, false))); 385 const auto file = nsp.GetFile(fmt::format("{}.nca", Common::HexArrayToString(id, false)));
386 if (file == nullptr) 386 if (file == nullptr)
387 return nullptr; 387 return nullptr;
388 return std::make_shared<NCA>(file); 388 return std::make_shared<NCA>(file);
389} 389}
390 390
391InstallResult RegisteredCache::InstallEntry(std::shared_ptr<XCI> xci, bool overwrite_if_exists, 391InstallResult RegisteredCache::InstallEntry(const XCI& xci, bool overwrite_if_exists,
392 const VfsCopyFunction& copy) { 392 const VfsCopyFunction& copy) {
393 return InstallEntry(xci->GetSecurePartitionNSP(), overwrite_if_exists, copy); 393 return InstallEntry(*xci.GetSecurePartitionNSP(), overwrite_if_exists, copy);
394} 394}
395 395
396InstallResult RegisteredCache::InstallEntry(std::shared_ptr<NSP> nsp, bool overwrite_if_exists, 396InstallResult RegisteredCache::InstallEntry(const NSP& nsp, bool overwrite_if_exists,
397 const VfsCopyFunction& copy) { 397 const VfsCopyFunction& copy) {
398 const auto& ncas = nsp->GetNCAsCollapsed(); 398 const auto ncas = nsp.GetNCAsCollapsed();
399 const auto& meta_iter = std::find_if(ncas.begin(), ncas.end(), [](std::shared_ptr<NCA> nca) { 399 const auto meta_iter = std::find_if(ncas.begin(), ncas.end(), [](const auto& nca) {
400 return nca->GetType() == NCAContentType::Meta; 400 return nca->GetType() == NCAContentType::Meta;
401 }); 401 });
402 402
@@ -410,7 +410,7 @@ InstallResult RegisteredCache::InstallEntry(std::shared_ptr<NSP> nsp, bool overw
410 const auto meta_id_raw = (*meta_iter)->GetName().substr(0, 32); 410 const auto meta_id_raw = (*meta_iter)->GetName().substr(0, 32);
411 const auto meta_id = Common::HexStringToArray<16>(meta_id_raw); 411 const auto meta_id = Common::HexStringToArray<16>(meta_id_raw);
412 412
413 const auto res = RawInstallNCA(*meta_iter, copy, overwrite_if_exists, meta_id); 413 const auto res = RawInstallNCA(**meta_iter, copy, overwrite_if_exists, meta_id);
414 if (res != InstallResult::Success) 414 if (res != InstallResult::Success)
415 return res; 415 return res;
416 416
@@ -422,7 +422,7 @@ InstallResult RegisteredCache::InstallEntry(std::shared_ptr<NSP> nsp, bool overw
422 const auto nca = GetNCAFromNSPForID(nsp, record.nca_id); 422 const auto nca = GetNCAFromNSPForID(nsp, record.nca_id);
423 if (nca == nullptr) 423 if (nca == nullptr)
424 return InstallResult::ErrorCopyFailed; 424 return InstallResult::ErrorCopyFailed;
425 const auto res2 = RawInstallNCA(nca, copy, overwrite_if_exists, record.nca_id); 425 const auto res2 = RawInstallNCA(*nca, copy, overwrite_if_exists, record.nca_id);
426 if (res2 != InstallResult::Success) 426 if (res2 != InstallResult::Success)
427 return res2; 427 return res2;
428 } 428 }
@@ -431,21 +431,21 @@ InstallResult RegisteredCache::InstallEntry(std::shared_ptr<NSP> nsp, bool overw
431 return InstallResult::Success; 431 return InstallResult::Success;
432} 432}
433 433
434InstallResult RegisteredCache::InstallEntry(std::shared_ptr<NCA> nca, TitleType type, 434InstallResult RegisteredCache::InstallEntry(const NCA& nca, TitleType type,
435 bool overwrite_if_exists, const VfsCopyFunction& copy) { 435 bool overwrite_if_exists, const VfsCopyFunction& copy) {
436 CNMTHeader header{ 436 CNMTHeader header{
437 nca->GetTitleId(), ///< Title ID 437 nca.GetTitleId(), ///< Title ID
438 0, ///< Ignore/Default title version 438 0, ///< Ignore/Default title version
439 type, ///< Type 439 type, ///< Type
440 {}, ///< Padding 440 {}, ///< Padding
441 0x10, ///< Default table offset 441 0x10, ///< Default table offset
442 1, ///< 1 Content Entry 442 1, ///< 1 Content Entry
443 0, ///< No Meta Entries 443 0, ///< No Meta Entries
444 {}, ///< Padding 444 {}, ///< Padding
445 }; 445 };
446 OptionalHeader opt_header{0, 0}; 446 OptionalHeader opt_header{0, 0};
447 ContentRecord c_rec{{}, {}, {}, GetCRTypeFromNCAType(nca->GetType()), {}}; 447 ContentRecord c_rec{{}, {}, {}, GetCRTypeFromNCAType(nca.GetType()), {}};
448 const auto& data = nca->GetBaseFile()->ReadBytes(0x100000); 448 const auto& data = nca.GetBaseFile()->ReadBytes(0x100000);
449 mbedtls_sha256(data.data(), data.size(), c_rec.hash.data(), 0); 449 mbedtls_sha256(data.data(), data.size(), c_rec.hash.data(), 0);
450 memcpy(&c_rec.nca_id, &c_rec.hash, 16); 450 memcpy(&c_rec.nca_id, &c_rec.hash, 16);
451 const CNMT new_cnmt(header, opt_header, {c_rec}, {}); 451 const CNMT new_cnmt(header, opt_header, {c_rec}, {});
@@ -454,10 +454,10 @@ InstallResult RegisteredCache::InstallEntry(std::shared_ptr<NCA> nca, TitleType
454 return RawInstallNCA(nca, copy, overwrite_if_exists, c_rec.nca_id); 454 return RawInstallNCA(nca, copy, overwrite_if_exists, c_rec.nca_id);
455} 455}
456 456
457InstallResult RegisteredCache::RawInstallNCA(std::shared_ptr<NCA> nca, const VfsCopyFunction& copy, 457InstallResult RegisteredCache::RawInstallNCA(const NCA& nca, const VfsCopyFunction& copy,
458 bool overwrite_if_exists, 458 bool overwrite_if_exists,
459 std::optional<NcaID> override_id) { 459 std::optional<NcaID> override_id) {
460 const auto in = nca->GetBaseFile(); 460 const auto in = nca.GetBaseFile();
461 Core::Crypto::SHA256Hash hash{}; 461 Core::Crypto::SHA256Hash hash{};
462 462
463 // Calculate NcaID 463 // Calculate NcaID
diff --git a/src/core/file_sys/registered_cache.h b/src/core/file_sys/registered_cache.h
index 6b89db8de..d2269fd4b 100644
--- a/src/core/file_sys/registered_cache.h
+++ b/src/core/file_sys/registered_cache.h
@@ -104,17 +104,16 @@ public:
104 104
105 // Raw copies all the ncas from the xci/nsp to the csache. Does some quick checks to make sure 105 // Raw copies all the ncas from the xci/nsp to the csache. Does some quick checks to make sure
106 // there is a meta NCA and all of them are accessible. 106 // there is a meta NCA and all of them are accessible.
107 InstallResult InstallEntry(std::shared_ptr<XCI> xci, bool overwrite_if_exists = false, 107 InstallResult InstallEntry(const XCI& xci, bool overwrite_if_exists = false,
108 const VfsCopyFunction& copy = &VfsRawCopy); 108 const VfsCopyFunction& copy = &VfsRawCopy);
109 InstallResult InstallEntry(std::shared_ptr<NSP> nsp, bool overwrite_if_exists = false, 109 InstallResult InstallEntry(const NSP& nsp, bool overwrite_if_exists = false,
110 const VfsCopyFunction& copy = &VfsRawCopy); 110 const VfsCopyFunction& copy = &VfsRawCopy);
111 111
112 // Due to the fact that we must use Meta-type NCAs to determine the existance of files, this 112 // Due to the fact that we must use Meta-type NCAs to determine the existance of files, this
113 // poses quite a challenge. Instead of creating a new meta NCA for this file, yuzu will create a 113 // poses quite a challenge. Instead of creating a new meta NCA for this file, yuzu will create a
114 // dir inside the NAND called 'yuzu_meta' and store the raw CNMT there. 114 // dir inside the NAND called 'yuzu_meta' and store the raw CNMT there.
115 // TODO(DarkLordZach): Author real meta-type NCAs and install those. 115 // TODO(DarkLordZach): Author real meta-type NCAs and install those.
116 InstallResult InstallEntry(std::shared_ptr<NCA> nca, TitleType type, 116 InstallResult InstallEntry(const NCA& nca, TitleType type, bool overwrite_if_exists = false,
117 bool overwrite_if_exists = false,
118 const VfsCopyFunction& copy = &VfsRawCopy); 117 const VfsCopyFunction& copy = &VfsRawCopy);
119 118
120private: 119private:
@@ -128,7 +127,7 @@ private:
128 std::optional<NcaID> GetNcaIDFromMetadata(u64 title_id, ContentRecordType type) const; 127 std::optional<NcaID> GetNcaIDFromMetadata(u64 title_id, ContentRecordType type) const;
129 VirtualFile GetFileAtID(NcaID id) const; 128 VirtualFile GetFileAtID(NcaID id) const;
130 VirtualFile OpenFileOrDirectoryConcat(const VirtualDir& dir, std::string_view path) const; 129 VirtualFile OpenFileOrDirectoryConcat(const VirtualDir& dir, std::string_view path) const;
131 InstallResult RawInstallNCA(std::shared_ptr<NCA> nca, const VfsCopyFunction& copy, 130 InstallResult RawInstallNCA(const NCA& nca, const VfsCopyFunction& copy,
132 bool overwrite_if_exists, std::optional<NcaID> override_id = {}); 131 bool overwrite_if_exists, std::optional<NcaID> override_id = {});
133 bool RawInstallYuzuMeta(const CNMT& cnmt); 132 bool RawInstallYuzuMeta(const CNMT& cnmt);
134 133
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index 9c6d150a5..93bf117c8 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -1105,14 +1105,14 @@ void GMainWindow::OnMenuInstallToNAND() {
1105 return; 1105 return;
1106 } 1106 }
1107 const auto res = 1107 const auto res =
1108 Service::FileSystem::GetUserNANDContents()->InstallEntry(nsp, false, qt_raw_copy); 1108 Service::FileSystem::GetUserNANDContents()->InstallEntry(*nsp, false, qt_raw_copy);
1109 if (res == FileSys::InstallResult::Success) { 1109 if (res == FileSys::InstallResult::Success) {
1110 success(); 1110 success();
1111 } else { 1111 } else {
1112 if (res == FileSys::InstallResult::ErrorAlreadyExists) { 1112 if (res == FileSys::InstallResult::ErrorAlreadyExists) {
1113 if (overwrite()) { 1113 if (overwrite()) {
1114 const auto res2 = Service::FileSystem::GetUserNANDContents()->InstallEntry( 1114 const auto res2 = Service::FileSystem::GetUserNANDContents()->InstallEntry(
1115 nsp, true, qt_raw_copy); 1115 *nsp, true, qt_raw_copy);
1116 if (res2 == FileSys::InstallResult::Success) { 1116 if (res2 == FileSys::InstallResult::Success) {
1117 success(); 1117 success();
1118 } else { 1118 } else {
@@ -1167,10 +1167,10 @@ void GMainWindow::OnMenuInstallToNAND() {
1167 FileSys::InstallResult res; 1167 FileSys::InstallResult res;
1168 if (index >= static_cast<size_t>(FileSys::TitleType::Application)) { 1168 if (index >= static_cast<size_t>(FileSys::TitleType::Application)) {
1169 res = Service::FileSystem::GetUserNANDContents()->InstallEntry( 1169 res = Service::FileSystem::GetUserNANDContents()->InstallEntry(
1170 nca, static_cast<FileSys::TitleType>(index), false, qt_raw_copy); 1170 *nca, static_cast<FileSys::TitleType>(index), false, qt_raw_copy);
1171 } else { 1171 } else {
1172 res = Service::FileSystem::GetSystemNANDContents()->InstallEntry( 1172 res = Service::FileSystem::GetSystemNANDContents()->InstallEntry(
1173 nca, static_cast<FileSys::TitleType>(index), false, qt_raw_copy); 1173 *nca, static_cast<FileSys::TitleType>(index), false, qt_raw_copy);
1174 } 1174 }
1175 1175
1176 if (res == FileSys::InstallResult::Success) { 1176 if (res == FileSys::InstallResult::Success) {
@@ -1178,7 +1178,7 @@ void GMainWindow::OnMenuInstallToNAND() {
1178 } else if (res == FileSys::InstallResult::ErrorAlreadyExists) { 1178 } else if (res == FileSys::InstallResult::ErrorAlreadyExists) {
1179 if (overwrite()) { 1179 if (overwrite()) {
1180 const auto res2 = Service::FileSystem::GetUserNANDContents()->InstallEntry( 1180 const auto res2 = Service::FileSystem::GetUserNANDContents()->InstallEntry(
1181 nca, static_cast<FileSys::TitleType>(index), true, qt_raw_copy); 1181 *nca, static_cast<FileSys::TitleType>(index), true, qt_raw_copy);
1182 if (res2 == FileSys::InstallResult::Success) { 1182 if (res2 == FileSys::InstallResult::Success) {
1183 success(); 1183 success();
1184 } else { 1184 } else {