summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar bunnei2018-11-27 19:20:12 -0500
committerGravatar GitHub2018-11-27 19:20:12 -0500
commitadb882bf909a1acfaa9d55a6a9fea64b428c9510 (patch)
tree24770715215581b9c3b49d6ac80d837bc3b579a9 /src
parentMerge pull request #1811 from lioncash/input (diff)
parentfile_sys/registered_cache: Remove unused <map> include (diff)
downloadyuzu-adb882bf909a1acfaa9d55a6a9fea64b428c9510.tar.gz
yuzu-adb882bf909a1acfaa9d55a6a9fea64b428c9510.tar.xz
yuzu-adb882bf909a1acfaa9d55a6a9fea64b428c9510.zip
Merge pull request #1814 from lioncash/ptr
file_sys/registered_cache: Use regular const references instead of std::shared_ptr for InstallEntry()
Diffstat (limited to 'src')
-rw-r--r--src/core/file_sys/registered_cache.cpp44
-rw-r--r--src/core/file_sys/registered_cache.h10
-rw-r--r--src/yuzu/main.cpp10
3 files changed, 31 insertions, 33 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..3b77af4e0 100644
--- a/src/core/file_sys/registered_cache.h
+++ b/src/core/file_sys/registered_cache.h
@@ -6,7 +6,6 @@
6 6
7#include <array> 7#include <array>
8#include <functional> 8#include <functional>
9#include <map>
10#include <memory> 9#include <memory>
11#include <string> 10#include <string>
12#include <vector> 11#include <vector>
@@ -104,17 +103,16 @@ public:
104 103
105 // Raw copies all the ncas from the xci/nsp to the csache. Does some quick checks to make sure 104 // 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. 105 // there is a meta NCA and all of them are accessible.
107 InstallResult InstallEntry(std::shared_ptr<XCI> xci, bool overwrite_if_exists = false, 106 InstallResult InstallEntry(const XCI& xci, bool overwrite_if_exists = false,
108 const VfsCopyFunction& copy = &VfsRawCopy); 107 const VfsCopyFunction& copy = &VfsRawCopy);
109 InstallResult InstallEntry(std::shared_ptr<NSP> nsp, bool overwrite_if_exists = false, 108 InstallResult InstallEntry(const NSP& nsp, bool overwrite_if_exists = false,
110 const VfsCopyFunction& copy = &VfsRawCopy); 109 const VfsCopyFunction& copy = &VfsRawCopy);
111 110
112 // Due to the fact that we must use Meta-type NCAs to determine the existance of files, this 111 // 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 112 // 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. 113 // dir inside the NAND called 'yuzu_meta' and store the raw CNMT there.
115 // TODO(DarkLordZach): Author real meta-type NCAs and install those. 114 // TODO(DarkLordZach): Author real meta-type NCAs and install those.
116 InstallResult InstallEntry(std::shared_ptr<NCA> nca, TitleType type, 115 InstallResult InstallEntry(const NCA& nca, TitleType type, bool overwrite_if_exists = false,
117 bool overwrite_if_exists = false,
118 const VfsCopyFunction& copy = &VfsRawCopy); 116 const VfsCopyFunction& copy = &VfsRawCopy);
119 117
120private: 118private:
@@ -128,7 +126,7 @@ private:
128 std::optional<NcaID> GetNcaIDFromMetadata(u64 title_id, ContentRecordType type) const; 126 std::optional<NcaID> GetNcaIDFromMetadata(u64 title_id, ContentRecordType type) const;
129 VirtualFile GetFileAtID(NcaID id) const; 127 VirtualFile GetFileAtID(NcaID id) const;
130 VirtualFile OpenFileOrDirectoryConcat(const VirtualDir& dir, std::string_view path) const; 128 VirtualFile OpenFileOrDirectoryConcat(const VirtualDir& dir, std::string_view path) const;
131 InstallResult RawInstallNCA(std::shared_ptr<NCA> nca, const VfsCopyFunction& copy, 129 InstallResult RawInstallNCA(const NCA& nca, const VfsCopyFunction& copy,
132 bool overwrite_if_exists, std::optional<NcaID> override_id = {}); 130 bool overwrite_if_exists, std::optional<NcaID> override_id = {});
133 bool RawInstallYuzuMeta(const CNMT& cnmt); 131 bool RawInstallYuzuMeta(const CNMT& cnmt);
134 132
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 {