mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-06-04 16:53:48 -04:00
NCM client implementation (#858)
* ncm: Implement InstallTaskDataBase and FileInstallTaskData * ncm: minor bugfixes * ncm: Implemented MemoryInstallTaskData * ncm: more std * ncm: begin implementing install task base * ncm: move protected funcs * ncm: fix recursive include * ncm: more install task progress * ncm install task: implement IncrementProgress and update UpdateThroughputMeasurement * ncm: more work * ncm client: more progress * ncm client: more progress * ncm client: finish implementing GetContentMetaInfoList * ncm client: more progress * ncm client: finished InstallTaskBase * ncm client: implement PackageInstallTaskBase * ncm client: fixes * ncm: improve accuracy * ncm client: implement PackageInstallTask * ncm client: implement PackageSystemUpdateTask * ncm client: minor name tweaks * ncm client: implement SubmissionPackageInstallTask * ncm client: add missing this to SubmissionPackageInstallTask * ncm client: add missing nullptr check to SubmissionPackageInstallTask destructor * ncm client: SubmissionPackageInstallTask fixes * ncm: fix forward declarations * ncm client: added simplified funcs * ncm: cleanup client code * ncm: fix bug introduced by cleanup * ncm: fix typo * ncm: implement correct ReadVariationContentMetaInfoList behavior * ncm: correct InstallContentMetaWriter ctor * ncm: correct conversion of content meta header types Co-authored-by: Michael Scire <SciresM@gmail.com>
This commit is contained in:
parent
76d72fa946
commit
a50d6a2696
48 changed files with 4163 additions and 56 deletions
|
@ -77,4 +77,83 @@ namespace ams::ncm {
|
|||
return ncm::ResultContentMetaNotFound();
|
||||
}
|
||||
|
||||
Result ReadVariationContentMetaInfoList(s32 *out_count, std::unique_ptr<ContentMetaInfo[]> *out_meta_infos, const Path &path, FirmwareVariationId firmware_variation_id) {
|
||||
AutoBuffer meta;
|
||||
{
|
||||
/* TODO: fs::ScopedAutoAbortDisabler aad; */
|
||||
R_TRY(ReadContentMetaPath(std::addressof(meta), path.str));
|
||||
}
|
||||
|
||||
/* Create a reader for the content meta. */
|
||||
PackagedContentMetaReader reader(meta.Get(), meta.GetSize());
|
||||
|
||||
/* Define a helper to output the base meta infos. */
|
||||
/* TODO: C++20 ALWAYS_INLINE_LAMBDA */
|
||||
const auto ReadMetaInfoListFromBase = [&]() -> Result {
|
||||
/* Output the base content meta info count. */
|
||||
*out_count = reader.GetContentMetaCount();
|
||||
|
||||
/* Create a buffer to hold the infos. NOTE: N does not check for nullptr before accessing. */
|
||||
std::unique_ptr<ContentMetaInfo[]> buffer(new (std::nothrow) ContentMetaInfo[reader.GetContentMetaCount()]);
|
||||
AMS_ABORT_UNLESS(buffer != nullptr);
|
||||
|
||||
/* Copy all base meta infos to output */
|
||||
for (size_t i = 0; i < reader.GetContentMetaCount(); i++) {
|
||||
buffer[i] = *reader.GetContentMetaInfo(i);
|
||||
}
|
||||
|
||||
/* Write out the buffer we've populated. */
|
||||
*out_meta_infos = std::move(buffer);
|
||||
return ResultSuccess();
|
||||
};
|
||||
|
||||
/* If there are no firmware variations to list, read meta infos from base. */
|
||||
R_UNLESS(reader.GetExtendedDataSize() != 0, ReadMetaInfoListFromBase());
|
||||
|
||||
SystemUpdateMetaExtendedDataReader extended_data_reader(reader.GetExtendedData(), reader.GetExtendedDataSize());
|
||||
std::optional<s32> firmware_variation_index = std::nullopt;
|
||||
|
||||
/* Find the input firmware variation id. */
|
||||
for (size_t i = 0; i < extended_data_reader.GetFirmwareVariationCount(); i++) {
|
||||
if (*extended_data_reader.GetFirmwareVariationId(i) == firmware_variation_id) {
|
||||
firmware_variation_index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* We couldn't find the input firmware variation id. */
|
||||
R_UNLESS(firmware_variation_index, ncm::ResultInvalidFirmwareVariation());
|
||||
|
||||
/* Obtain the variation info. */
|
||||
const FirmwareVariationInfo *variation_info = extended_data_reader.GetFirmwareVariationInfo(*firmware_variation_index);
|
||||
|
||||
/* Refer to base if variation info says we should, or if unk is 1 (unk is usually 2, probably a version). */
|
||||
const bool refer_to_base = variation_info->refer_to_base || extended_data_reader.GetHeader()->unk == 1;
|
||||
R_UNLESS(!refer_to_base, ReadMetaInfoListFromBase());
|
||||
|
||||
/* Output the content meta count. */
|
||||
const u32 content_meta_count = variation_info->content_meta_count;
|
||||
*out_count = content_meta_count;
|
||||
|
||||
/* We're done if there are no content metas to list. */
|
||||
R_SUCCEED_IF(content_meta_count == 0);
|
||||
|
||||
/* Allocate a buffer for the content meta infos. */
|
||||
std::unique_ptr<ContentMetaInfo[]> buffer(new (std::nothrow) ContentMetaInfo[content_meta_count]);
|
||||
AMS_ABORT_UNLESS(buffer != nullptr);
|
||||
|
||||
/* Get the content meta infos. */
|
||||
Span<const ContentMetaInfo> meta_infos;
|
||||
extended_data_reader.GetContentMetaInfoList(std::addressof(meta_infos), content_meta_count);
|
||||
|
||||
/* Copy the meta infos to the buffer. */
|
||||
for (size_t i = 0; i < content_meta_count; i++) {
|
||||
buffer[i] = meta_infos[i];
|
||||
}
|
||||
|
||||
/* Output the content meta info buffer. */
|
||||
*out_meta_infos = std::move(buffer);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue