mirror of
https://git.h3cjp.net/H3cJP/yuzu.git
synced 2024-12-16 15:55:30 +00:00
registration: Take RawCopy function as parameter
Instead of defaulting to VfsRawCopy
This commit is contained in:
parent
10812f8407
commit
3b3c919e20
|
@ -335,7 +335,7 @@ static std::shared_ptr<NCA> GetNCAFromXCIForID(std::shared_ptr<XCI> xci, const N
|
||||||
return iter == xci->GetNCAs().end() ? nullptr : *iter;
|
return iter == xci->GetNCAs().end() ? nullptr : *iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RegisteredCache::InstallEntry(std::shared_ptr<XCI> xci) {
|
bool RegisteredCache::InstallEntry(std::shared_ptr<XCI> xci, const VfsCopyFunction& copy) {
|
||||||
const auto& ncas = xci->GetNCAs();
|
const auto& ncas = xci->GetNCAs();
|
||||||
const auto& meta_iter = std::find_if(ncas.begin(), ncas.end(), [](std::shared_ptr<NCA> nca) {
|
const auto& meta_iter = std::find_if(ncas.begin(), ncas.end(), [](std::shared_ptr<NCA> nca) {
|
||||||
return nca->GetType() == NCAContentType::Meta;
|
return nca->GetType() == NCAContentType::Meta;
|
||||||
|
@ -350,7 +350,7 @@ bool RegisteredCache::InstallEntry(std::shared_ptr<XCI> xci) {
|
||||||
// Install Metadata File
|
// Install Metadata File
|
||||||
const auto meta_id_raw = (*meta_iter)->GetName().substr(0, 32);
|
const auto meta_id_raw = (*meta_iter)->GetName().substr(0, 32);
|
||||||
const auto meta_id = HexStringToArray<16>(meta_id_raw);
|
const auto meta_id = HexStringToArray<16>(meta_id_raw);
|
||||||
if (!RawInstallNCA(*meta_iter, meta_id))
|
if (!RawInstallNCA(*meta_iter, copy, meta_id))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Install all the other NCAs
|
// Install all the other NCAs
|
||||||
|
@ -359,7 +359,7 @@ bool RegisteredCache::InstallEntry(std::shared_ptr<XCI> xci) {
|
||||||
const CNMT cnmt(cnmt_file);
|
const CNMT cnmt(cnmt_file);
|
||||||
for (const auto& record : cnmt.GetContentRecords()) {
|
for (const auto& record : cnmt.GetContentRecords()) {
|
||||||
const auto nca = GetNCAFromXCIForID(xci, record.nca_id);
|
const auto nca = GetNCAFromXCIForID(xci, record.nca_id);
|
||||||
if (nca == nullptr || !RawInstallNCA(nca, record.nca_id))
|
if (nca == nullptr || !RawInstallNCA(nca, copy, record.nca_id))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,7 +367,8 @@ bool RegisteredCache::InstallEntry(std::shared_ptr<XCI> xci) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RegisteredCache::InstallEntry(std::shared_ptr<NCA> nca, TitleType type) {
|
bool RegisteredCache::InstallEntry(std::shared_ptr<NCA> nca, TitleType type,
|
||||||
|
const VfsCopyFunction& copy) {
|
||||||
CNMTHeader header{
|
CNMTHeader header{
|
||||||
nca->GetTitleId(), ///< Title ID
|
nca->GetTitleId(), ///< Title ID
|
||||||
0, ///< Ignore/Default title version
|
0, ///< Ignore/Default title version
|
||||||
|
@ -384,10 +385,11 @@ bool RegisteredCache::InstallEntry(std::shared_ptr<NCA> nca, TitleType type) {
|
||||||
mbedtls_sha256(data.data(), data.size(), c_rec.hash.data(), 0);
|
mbedtls_sha256(data.data(), data.size(), c_rec.hash.data(), 0);
|
||||||
memcpy(&c_rec.nca_id, &c_rec.hash, 16);
|
memcpy(&c_rec.nca_id, &c_rec.hash, 16);
|
||||||
const CNMT new_cnmt(header, opt_header, {c_rec}, {});
|
const CNMT new_cnmt(header, opt_header, {c_rec}, {});
|
||||||
return RawInstallYuzuMeta(new_cnmt) && RawInstallNCA(nca, c_rec.nca_id);
|
return RawInstallYuzuMeta(new_cnmt) && RawInstallNCA(nca, copy, c_rec.nca_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RegisteredCache::RawInstallNCA(std::shared_ptr<NCA> nca, boost::optional<NcaID> override_id) {
|
bool RegisteredCache::RawInstallNCA(std::shared_ptr<NCA> nca, const VfsCopyFunction& copy,
|
||||||
|
boost::optional<NcaID> override_id) {
|
||||||
const auto in = nca->GetBaseFile();
|
const auto in = nca->GetBaseFile();
|
||||||
Core::Crypto::SHA256Hash hash{};
|
Core::Crypto::SHA256Hash hash{};
|
||||||
|
|
||||||
|
@ -414,7 +416,7 @@ bool RegisteredCache::RawInstallNCA(std::shared_ptr<NCA> nca, boost::optional<Nc
|
||||||
auto out = dir->CreateFileRelative(path);
|
auto out = dir->CreateFileRelative(path);
|
||||||
if (out == nullptr)
|
if (out == nullptr)
|
||||||
return false;
|
return false;
|
||||||
return VfsRawCopy(in, out);
|
return copy(in, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RegisteredCache::RawInstallYuzuMeta(const CNMT& cnmt) {
|
bool RegisteredCache::RawInstallYuzuMeta(const CNMT& cnmt) {
|
||||||
|
|
|
@ -23,6 +23,7 @@ class CNMT;
|
||||||
|
|
||||||
using NcaID = std::array<u8, 0x10>;
|
using NcaID = std::array<u8, 0x10>;
|
||||||
using RegisteredCacheParsingFunction = std::function<VirtualFile(const VirtualFile&, const NcaID&)>;
|
using RegisteredCacheParsingFunction = std::function<VirtualFile(const VirtualFile&, const NcaID&)>;
|
||||||
|
using VfsCopyFunction = std::function<bool(VirtualFile, VirtualFile)>;
|
||||||
|
|
||||||
struct RegisteredCacheEntry {
|
struct RegisteredCacheEntry {
|
||||||
u64 title_id;
|
u64 title_id;
|
||||||
|
@ -76,13 +77,14 @@ public:
|
||||||
|
|
||||||
// Raw copies all the ncas from the xci to the csache. Does some quick checks to make sure there
|
// Raw copies all the ncas from the xci to the csache. Does some quick checks to make sure there
|
||||||
// is a meta NCA and all of them are accessible.
|
// is a meta NCA and all of them are accessible.
|
||||||
bool InstallEntry(std::shared_ptr<XCI> xci);
|
bool InstallEntry(std::shared_ptr<XCI> xci, const VfsCopyFunction& copy = &VfsRawCopy);
|
||||||
|
|
||||||
// Due to the fact that we must use Meta-type NCAs to determine the existance of files, this
|
// Due to the fact that we must use Meta-type NCAs to determine the existance of files, this
|
||||||
// poses quite a challenge. Instead of creating a new meta NCA for this file, yuzu will create a
|
// poses quite a challenge. Instead of creating a new meta NCA for this file, yuzu will create a
|
||||||
// dir inside the NAND called 'yuzu_meta' and store the raw CNMT there.
|
// dir inside the NAND called 'yuzu_meta' and store the raw CNMT there.
|
||||||
// TODO(DarkLordZach): Author real meta-type NCAs and install those.
|
// TODO(DarkLordZach): Author real meta-type NCAs and install those.
|
||||||
bool InstallEntry(std::shared_ptr<NCA> nca, TitleType type);
|
bool InstallEntry(std::shared_ptr<NCA> nca, TitleType type,
|
||||||
|
const VfsCopyFunction& copy = &VfsRawCopy);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -95,7 +97,8 @@ private:
|
||||||
boost::optional<NcaID> GetNcaIDFromMetadata(u64 title_id, ContentRecordType type) const;
|
boost::optional<NcaID> GetNcaIDFromMetadata(u64 title_id, ContentRecordType type) const;
|
||||||
VirtualFile GetFileAtID(NcaID id) const;
|
VirtualFile GetFileAtID(NcaID id) const;
|
||||||
VirtualFile OpenFileOrDirectoryConcat(const VirtualDir& dir, std::string_view path) const;
|
VirtualFile OpenFileOrDirectoryConcat(const VirtualDir& dir, std::string_view path) const;
|
||||||
bool RawInstallNCA(std::shared_ptr<NCA> nca, boost::optional<NcaID> override_id = boost::none);
|
bool RawInstallNCA(std::shared_ptr<NCA> nca, const VfsCopyFunction& copy,
|
||||||
|
boost::optional<NcaID> override_id = boost::none);
|
||||||
bool RawInstallYuzuMeta(const CNMT& cnmt);
|
bool RawInstallYuzuMeta(const CNMT& cnmt);
|
||||||
|
|
||||||
VirtualDir dir;
|
VirtualDir dir;
|
||||||
|
|
Loading…
Reference in a new issue