mirror of
https://github.com/yuzu-emu/yuzu-android.git
synced 2024-11-27 15:04:20 +01:00
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).
This commit is contained in:
parent
1cd40f107f
commit
d72c809030
@ -381,22 +381,22 @@ std::vector<RegisteredCacheEntry> RegisteredCache::ListEntriesFilter(
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::shared_ptr<NCA> GetNCAFromNSPForID(std::shared_ptr<NSP> nsp, const NcaID& id) {
|
static std::shared_ptr<NCA> GetNCAFromNSPForID(const NSP& nsp, const NcaID& id) {
|
||||||
const auto file = nsp->GetFile(fmt::format("{}.nca", Common::HexArrayToString(id, false)));
|
const auto file = nsp.GetFile(fmt::format("{}.nca", Common::HexArrayToString(id, false)));
|
||||||
if (file == nullptr)
|
if (file == nullptr)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return std::make_shared<NCA>(file);
|
return std::make_shared<NCA>(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
InstallResult RegisteredCache::InstallEntry(std::shared_ptr<XCI> xci, bool overwrite_if_exists,
|
InstallResult RegisteredCache::InstallEntry(const XCI& xci, bool overwrite_if_exists,
|
||||||
const VfsCopyFunction& copy) {
|
const VfsCopyFunction& copy) {
|
||||||
return InstallEntry(xci->GetSecurePartitionNSP(), overwrite_if_exists, copy);
|
return InstallEntry(*xci.GetSecurePartitionNSP(), overwrite_if_exists, copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
InstallResult RegisteredCache::InstallEntry(std::shared_ptr<NSP> nsp, bool overwrite_if_exists,
|
InstallResult RegisteredCache::InstallEntry(const NSP& nsp, bool overwrite_if_exists,
|
||||||
const VfsCopyFunction& copy) {
|
const VfsCopyFunction& copy) {
|
||||||
const auto& ncas = nsp->GetNCAsCollapsed();
|
const auto ncas = nsp.GetNCAsCollapsed();
|
||||||
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(), [](const auto& nca) {
|
||||||
return nca->GetType() == NCAContentType::Meta;
|
return nca->GetType() == NCAContentType::Meta;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -410,7 +410,7 @@ InstallResult RegisteredCache::InstallEntry(std::shared_ptr<NSP> nsp, bool overw
|
|||||||
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 = Common::HexStringToArray<16>(meta_id_raw);
|
const auto meta_id = Common::HexStringToArray<16>(meta_id_raw);
|
||||||
|
|
||||||
const auto res = RawInstallNCA(*meta_iter, copy, overwrite_if_exists, meta_id);
|
const auto res = RawInstallNCA(**meta_iter, copy, overwrite_if_exists, meta_id);
|
||||||
if (res != InstallResult::Success)
|
if (res != InstallResult::Success)
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
@ -422,7 +422,7 @@ InstallResult RegisteredCache::InstallEntry(std::shared_ptr<NSP> nsp, bool overw
|
|||||||
const auto nca = GetNCAFromNSPForID(nsp, record.nca_id);
|
const auto nca = GetNCAFromNSPForID(nsp, record.nca_id);
|
||||||
if (nca == nullptr)
|
if (nca == nullptr)
|
||||||
return InstallResult::ErrorCopyFailed;
|
return InstallResult::ErrorCopyFailed;
|
||||||
const auto res2 = RawInstallNCA(nca, copy, overwrite_if_exists, record.nca_id);
|
const auto res2 = RawInstallNCA(*nca, copy, overwrite_if_exists, record.nca_id);
|
||||||
if (res2 != InstallResult::Success)
|
if (res2 != InstallResult::Success)
|
||||||
return res2;
|
return res2;
|
||||||
}
|
}
|
||||||
@ -431,10 +431,10 @@ InstallResult RegisteredCache::InstallEntry(std::shared_ptr<NSP> nsp, bool overw
|
|||||||
return InstallResult::Success;
|
return InstallResult::Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
InstallResult RegisteredCache::InstallEntry(std::shared_ptr<NCA> nca, TitleType type,
|
InstallResult RegisteredCache::InstallEntry(const NCA& nca, TitleType type,
|
||||||
bool overwrite_if_exists, const VfsCopyFunction& copy) {
|
bool overwrite_if_exists, 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
|
||||||
type, ///< Type
|
type, ///< Type
|
||||||
{}, ///< Padding
|
{}, ///< Padding
|
||||||
@ -444,8 +444,8 @@ InstallResult RegisteredCache::InstallEntry(std::shared_ptr<NCA> nca, TitleType
|
|||||||
{}, ///< Padding
|
{}, ///< Padding
|
||||||
};
|
};
|
||||||
OptionalHeader opt_header{0, 0};
|
OptionalHeader opt_header{0, 0};
|
||||||
ContentRecord c_rec{{}, {}, {}, GetCRTypeFromNCAType(nca->GetType()), {}};
|
ContentRecord c_rec{{}, {}, {}, GetCRTypeFromNCAType(nca.GetType()), {}};
|
||||||
const auto& data = nca->GetBaseFile()->ReadBytes(0x100000);
|
const auto& data = nca.GetBaseFile()->ReadBytes(0x100000);
|
||||||
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}, {});
|
||||||
@ -454,10 +454,10 @@ InstallResult RegisteredCache::InstallEntry(std::shared_ptr<NCA> nca, TitleType
|
|||||||
return RawInstallNCA(nca, copy, overwrite_if_exists, c_rec.nca_id);
|
return RawInstallNCA(nca, copy, overwrite_if_exists, c_rec.nca_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
InstallResult RegisteredCache::RawInstallNCA(std::shared_ptr<NCA> nca, const VfsCopyFunction& copy,
|
InstallResult RegisteredCache::RawInstallNCA(const NCA& nca, const VfsCopyFunction& copy,
|
||||||
bool overwrite_if_exists,
|
bool overwrite_if_exists,
|
||||||
std::optional<NcaID> override_id) {
|
std::optional<NcaID> override_id) {
|
||||||
const auto in = nca->GetBaseFile();
|
const auto in = nca.GetBaseFile();
|
||||||
Core::Crypto::SHA256Hash hash{};
|
Core::Crypto::SHA256Hash hash{};
|
||||||
|
|
||||||
// Calculate NcaID
|
// Calculate NcaID
|
||||||
|
@ -104,17 +104,16 @@ public:
|
|||||||
|
|
||||||
// Raw copies all the ncas from the xci/nsp to the csache. Does some quick checks to make sure
|
// Raw copies all the ncas from the xci/nsp to the csache. Does some quick checks to make sure
|
||||||
// there is a meta NCA and all of them are accessible.
|
// there is a meta NCA and all of them are accessible.
|
||||||
InstallResult InstallEntry(std::shared_ptr<XCI> xci, bool overwrite_if_exists = false,
|
InstallResult InstallEntry(const XCI& xci, bool overwrite_if_exists = false,
|
||||||
const VfsCopyFunction& copy = &VfsRawCopy);
|
const VfsCopyFunction& copy = &VfsRawCopy);
|
||||||
InstallResult InstallEntry(std::shared_ptr<NSP> nsp, bool overwrite_if_exists = false,
|
InstallResult InstallEntry(const NSP& nsp, bool overwrite_if_exists = false,
|
||||||
const VfsCopyFunction& copy = &VfsRawCopy);
|
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.
|
||||||
InstallResult InstallEntry(std::shared_ptr<NCA> nca, TitleType type,
|
InstallResult InstallEntry(const NCA& nca, TitleType type, bool overwrite_if_exists = false,
|
||||||
bool overwrite_if_exists = false,
|
|
||||||
const VfsCopyFunction& copy = &VfsRawCopy);
|
const VfsCopyFunction& copy = &VfsRawCopy);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -128,7 +127,7 @@ private:
|
|||||||
std::optional<NcaID> GetNcaIDFromMetadata(u64 title_id, ContentRecordType type) const;
|
std::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;
|
||||||
InstallResult RawInstallNCA(std::shared_ptr<NCA> nca, const VfsCopyFunction& copy,
|
InstallResult RawInstallNCA(const NCA& nca, const VfsCopyFunction& copy,
|
||||||
bool overwrite_if_exists, std::optional<NcaID> override_id = {});
|
bool overwrite_if_exists, std::optional<NcaID> override_id = {});
|
||||||
bool RawInstallYuzuMeta(const CNMT& cnmt);
|
bool RawInstallYuzuMeta(const CNMT& cnmt);
|
||||||
|
|
||||||
|
@ -1105,14 +1105,14 @@ void GMainWindow::OnMenuInstallToNAND() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto res =
|
const auto res =
|
||||||
Service::FileSystem::GetUserNANDContents()->InstallEntry(nsp, false, qt_raw_copy);
|
Service::FileSystem::GetUserNANDContents()->InstallEntry(*nsp, false, qt_raw_copy);
|
||||||
if (res == FileSys::InstallResult::Success) {
|
if (res == FileSys::InstallResult::Success) {
|
||||||
success();
|
success();
|
||||||
} else {
|
} else {
|
||||||
if (res == FileSys::InstallResult::ErrorAlreadyExists) {
|
if (res == FileSys::InstallResult::ErrorAlreadyExists) {
|
||||||
if (overwrite()) {
|
if (overwrite()) {
|
||||||
const auto res2 = Service::FileSystem::GetUserNANDContents()->InstallEntry(
|
const auto res2 = Service::FileSystem::GetUserNANDContents()->InstallEntry(
|
||||||
nsp, true, qt_raw_copy);
|
*nsp, true, qt_raw_copy);
|
||||||
if (res2 == FileSys::InstallResult::Success) {
|
if (res2 == FileSys::InstallResult::Success) {
|
||||||
success();
|
success();
|
||||||
} else {
|
} else {
|
||||||
@ -1167,10 +1167,10 @@ void GMainWindow::OnMenuInstallToNAND() {
|
|||||||
FileSys::InstallResult res;
|
FileSys::InstallResult res;
|
||||||
if (index >= static_cast<size_t>(FileSys::TitleType::Application)) {
|
if (index >= static_cast<size_t>(FileSys::TitleType::Application)) {
|
||||||
res = Service::FileSystem::GetUserNANDContents()->InstallEntry(
|
res = Service::FileSystem::GetUserNANDContents()->InstallEntry(
|
||||||
nca, static_cast<FileSys::TitleType>(index), false, qt_raw_copy);
|
*nca, static_cast<FileSys::TitleType>(index), false, qt_raw_copy);
|
||||||
} else {
|
} else {
|
||||||
res = Service::FileSystem::GetSystemNANDContents()->InstallEntry(
|
res = Service::FileSystem::GetSystemNANDContents()->InstallEntry(
|
||||||
nca, static_cast<FileSys::TitleType>(index), false, qt_raw_copy);
|
*nca, static_cast<FileSys::TitleType>(index), false, qt_raw_copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res == FileSys::InstallResult::Success) {
|
if (res == FileSys::InstallResult::Success) {
|
||||||
@ -1178,7 +1178,7 @@ void GMainWindow::OnMenuInstallToNAND() {
|
|||||||
} else if (res == FileSys::InstallResult::ErrorAlreadyExists) {
|
} else if (res == FileSys::InstallResult::ErrorAlreadyExists) {
|
||||||
if (overwrite()) {
|
if (overwrite()) {
|
||||||
const auto res2 = Service::FileSystem::GetUserNANDContents()->InstallEntry(
|
const auto res2 = Service::FileSystem::GetUserNANDContents()->InstallEntry(
|
||||||
nca, static_cast<FileSys::TitleType>(index), true, qt_raw_copy);
|
*nca, static_cast<FileSys::TitleType>(index), true, qt_raw_copy);
|
||||||
if (res2 == FileSys::InstallResult::Success) {
|
if (res2 == FileSys::InstallResult::Success) {
|
||||||
success();
|
success();
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user