summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Zach Hilman2018-08-10 15:06:37 -0400
committerGravatar Zach Hilman2018-08-11 22:50:48 -0400
commit3b3c919e204a8fc5d2a4e7f372514f257acbe96e (patch)
tree48c45e8b08058a2d54afa940419f66750ce0cdcb /src
parentgame_list: Populate control data from installed NAND (diff)
downloadyuzu-3b3c919e204a8fc5d2a4e7f372514f257acbe96e.tar.gz
yuzu-3b3c919e204a8fc5d2a4e7f372514f257acbe96e.tar.xz
yuzu-3b3c919e204a8fc5d2a4e7f372514f257acbe96e.zip
registration: Take RawCopy function as parameter
Instead of defaulting to VfsRawCopy
Diffstat (limited to 'src')
-rw-r--r--src/core/file_sys/registered_cache.cpp16
-rw-r--r--src/core/file_sys/registered_cache.h9
2 files changed, 15 insertions, 10 deletions
diff --git a/src/core/file_sys/registered_cache.cpp b/src/core/file_sys/registered_cache.cpp
index 665126c1c..aaadb7463 100644
--- a/src/core/file_sys/registered_cache.cpp
+++ b/src/core/file_sys/registered_cache.cpp
@@ -335,7 +335,7 @@ static std::shared_ptr<NCA> GetNCAFromXCIForID(std::shared_ptr<XCI> xci, const N
335 return iter == xci->GetNCAs().end() ? nullptr : *iter; 335 return iter == xci->GetNCAs().end() ? nullptr : *iter;
336} 336}
337 337
338bool RegisteredCache::InstallEntry(std::shared_ptr<XCI> xci) { 338bool RegisteredCache::InstallEntry(std::shared_ptr<XCI> xci, const VfsCopyFunction& copy) {
339 const auto& ncas = xci->GetNCAs(); 339 const auto& ncas = xci->GetNCAs();
340 const auto& meta_iter = std::find_if(ncas.begin(), ncas.end(), [](std::shared_ptr<NCA> nca) { 340 const auto& meta_iter = std::find_if(ncas.begin(), ncas.end(), [](std::shared_ptr<NCA> nca) {
341 return nca->GetType() == NCAContentType::Meta; 341 return nca->GetType() == NCAContentType::Meta;
@@ -350,7 +350,7 @@ bool RegisteredCache::InstallEntry(std::shared_ptr<XCI> xci) {
350 // Install Metadata File 350 // Install Metadata File
351 const auto meta_id_raw = (*meta_iter)->GetName().substr(0, 32); 351 const auto meta_id_raw = (*meta_iter)->GetName().substr(0, 32);
352 const auto meta_id = HexStringToArray<16>(meta_id_raw); 352 const auto meta_id = HexStringToArray<16>(meta_id_raw);
353 if (!RawInstallNCA(*meta_iter, meta_id)) 353 if (!RawInstallNCA(*meta_iter, copy, meta_id))
354 return false; 354 return false;
355 355
356 // Install all the other NCAs 356 // Install all the other NCAs
@@ -359,7 +359,7 @@ bool RegisteredCache::InstallEntry(std::shared_ptr<XCI> xci) {
359 const CNMT cnmt(cnmt_file); 359 const CNMT cnmt(cnmt_file);
360 for (const auto& record : cnmt.GetContentRecords()) { 360 for (const auto& record : cnmt.GetContentRecords()) {
361 const auto nca = GetNCAFromXCIForID(xci, record.nca_id); 361 const auto nca = GetNCAFromXCIForID(xci, record.nca_id);
362 if (nca == nullptr || !RawInstallNCA(nca, record.nca_id)) 362 if (nca == nullptr || !RawInstallNCA(nca, copy, record.nca_id))
363 return false; 363 return false;
364 } 364 }
365 365
@@ -367,7 +367,8 @@ bool RegisteredCache::InstallEntry(std::shared_ptr<XCI> xci) {
367 return true; 367 return true;
368} 368}
369 369
370bool RegisteredCache::InstallEntry(std::shared_ptr<NCA> nca, TitleType type) { 370bool RegisteredCache::InstallEntry(std::shared_ptr<NCA> nca, TitleType type,
371 const VfsCopyFunction& copy) {
371 CNMTHeader header{ 372 CNMTHeader header{
372 nca->GetTitleId(), ///< Title ID 373 nca->GetTitleId(), ///< Title ID
373 0, ///< Ignore/Default title version 374 0, ///< Ignore/Default title version
@@ -384,10 +385,11 @@ bool RegisteredCache::InstallEntry(std::shared_ptr<NCA> nca, TitleType type) {
384 mbedtls_sha256(data.data(), data.size(), c_rec.hash.data(), 0); 385 mbedtls_sha256(data.data(), data.size(), c_rec.hash.data(), 0);
385 memcpy(&c_rec.nca_id, &c_rec.hash, 16); 386 memcpy(&c_rec.nca_id, &c_rec.hash, 16);
386 const CNMT new_cnmt(header, opt_header, {c_rec}, {}); 387 const CNMT new_cnmt(header, opt_header, {c_rec}, {});
387 return RawInstallYuzuMeta(new_cnmt) && RawInstallNCA(nca, c_rec.nca_id); 388 return RawInstallYuzuMeta(new_cnmt) && RawInstallNCA(nca, copy, c_rec.nca_id);
388} 389}
389 390
390bool RegisteredCache::RawInstallNCA(std::shared_ptr<NCA> nca, boost::optional<NcaID> override_id) { 391bool RegisteredCache::RawInstallNCA(std::shared_ptr<NCA> nca, const VfsCopyFunction& copy,
392 boost::optional<NcaID> override_id) {
391 const auto in = nca->GetBaseFile(); 393 const auto in = nca->GetBaseFile();
392 Core::Crypto::SHA256Hash hash{}; 394 Core::Crypto::SHA256Hash hash{};
393 395
@@ -414,7 +416,7 @@ bool RegisteredCache::RawInstallNCA(std::shared_ptr<NCA> nca, boost::optional<Nc
414 auto out = dir->CreateFileRelative(path); 416 auto out = dir->CreateFileRelative(path);
415 if (out == nullptr) 417 if (out == nullptr)
416 return false; 418 return false;
417 return VfsRawCopy(in, out); 419 return copy(in, out);
418} 420}
419 421
420bool RegisteredCache::RawInstallYuzuMeta(const CNMT& cnmt) { 422bool RegisteredCache::RawInstallYuzuMeta(const CNMT& cnmt) {
diff --git a/src/core/file_sys/registered_cache.h b/src/core/file_sys/registered_cache.h
index baaed02dd..f2b07eec8 100644
--- a/src/core/file_sys/registered_cache.h
+++ b/src/core/file_sys/registered_cache.h
@@ -23,6 +23,7 @@ class CNMT;
23 23
24using NcaID = std::array<u8, 0x10>; 24using NcaID = std::array<u8, 0x10>;
25using RegisteredCacheParsingFunction = std::function<VirtualFile(const VirtualFile&, const NcaID&)>; 25using RegisteredCacheParsingFunction = std::function<VirtualFile(const VirtualFile&, const NcaID&)>;
26using VfsCopyFunction = std::function<bool(VirtualFile, VirtualFile)>;
26 27
27struct RegisteredCacheEntry { 28struct RegisteredCacheEntry {
28 u64 title_id; 29 u64 title_id;
@@ -76,13 +77,14 @@ public:
76 77
77 // Raw copies all the ncas from the xci to the csache. Does some quick checks to make sure there 78 // Raw copies all the ncas from the xci to the csache. Does some quick checks to make sure there
78 // is a meta NCA and all of them are accessible. 79 // is a meta NCA and all of them are accessible.
79 bool InstallEntry(std::shared_ptr<XCI> xci); 80 bool InstallEntry(std::shared_ptr<XCI> xci, const VfsCopyFunction& copy = &VfsRawCopy);
80 81
81 // Due to the fact that we must use Meta-type NCAs to determine the existance of files, this 82 // Due to the fact that we must use Meta-type NCAs to determine the existance of files, this
82 // poses quite a challenge. Instead of creating a new meta NCA for this file, yuzu will create a 83 // poses quite a challenge. Instead of creating a new meta NCA for this file, yuzu will create a
83 // dir inside the NAND called 'yuzu_meta' and store the raw CNMT there. 84 // dir inside the NAND called 'yuzu_meta' and store the raw CNMT there.
84 // TODO(DarkLordZach): Author real meta-type NCAs and install those. 85 // TODO(DarkLordZach): Author real meta-type NCAs and install those.
85 bool InstallEntry(std::shared_ptr<NCA> nca, TitleType type); 86 bool InstallEntry(std::shared_ptr<NCA> nca, TitleType type,
87 const VfsCopyFunction& copy = &VfsRawCopy);
86 88
87private: 89private:
88 template <typename T> 90 template <typename T>
@@ -95,7 +97,8 @@ private:
95 boost::optional<NcaID> GetNcaIDFromMetadata(u64 title_id, ContentRecordType type) const; 97 boost::optional<NcaID> GetNcaIDFromMetadata(u64 title_id, ContentRecordType type) const;
96 VirtualFile GetFileAtID(NcaID id) const; 98 VirtualFile GetFileAtID(NcaID id) const;
97 VirtualFile OpenFileOrDirectoryConcat(const VirtualDir& dir, std::string_view path) const; 99 VirtualFile OpenFileOrDirectoryConcat(const VirtualDir& dir, std::string_view path) const;
98 bool RawInstallNCA(std::shared_ptr<NCA> nca, boost::optional<NcaID> override_id = boost::none); 100 bool RawInstallNCA(std::shared_ptr<NCA> nca, const VfsCopyFunction& copy,
101 boost::optional<NcaID> override_id = boost::none);
99 bool RawInstallYuzuMeta(const CNMT& cnmt); 102 bool RawInstallYuzuMeta(const CNMT& cnmt);
100 103
101 VirtualDir dir; 104 VirtualDir dir;