mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-11-10 07:06:34 +00:00
a50d6a2696
* 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>
129 lines
5.2 KiB
C++
129 lines
5.2 KiB
C++
/*
|
|
* Copyright (c) 2019-2020 Adubbz, Atmosphère-NX
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
* under the terms and conditions of the GNU General Public License,
|
|
* version 2, as published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
* more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
#include <stratosphere.hpp>
|
|
|
|
namespace ams::ncm {
|
|
|
|
Result PackageInstallTaskBase::Initialize(const char *package_root_path, void *buffer, size_t buffer_size, StorageId storage_id, InstallTaskDataBase *data, u32 config) {
|
|
R_TRY(InstallTaskBase::Initialize(storage_id, data, config));
|
|
this->package_root.Set(package_root_path);
|
|
this->buffer = buffer;
|
|
this->buffer_size = buffer_size;
|
|
return ResultSuccess();
|
|
}
|
|
|
|
Result PackageInstallTaskBase::OnWritePlaceHolder(const ContentMetaKey &key, InstallContentInfo *content_info) {
|
|
PackagePath path;
|
|
if (content_info->GetType() == ContentType::Meta) {
|
|
this->CreateContentMetaPath(std::addressof(path), content_info->GetId());
|
|
} else {
|
|
this->CreateContentPath(std::addressof(path), content_info->GetId());
|
|
}
|
|
|
|
/* Open the file. */
|
|
fs::FileHandle file;
|
|
R_TRY(fs::OpenFile(std::addressof(file), path, fs::OpenMode_Read));
|
|
ON_SCOPE_EXIT { fs::CloseFile(file); };
|
|
|
|
/* Continuously write the file to the placeholder until there is nothing left to write. */
|
|
while (true) {
|
|
/* Read as much of the remainder of the file as possible. */
|
|
size_t size_read;
|
|
R_TRY(fs::ReadFile(std::addressof(size_read), file, content_info->written, this->buffer, this->buffer_size));
|
|
|
|
/* There is nothing left to read. */
|
|
if (size_read == 0) {
|
|
break;
|
|
}
|
|
|
|
/* Write the placeholder. */
|
|
R_TRY(this->WritePlaceHolderBuffer(content_info, this->buffer, size_read));
|
|
}
|
|
|
|
return ResultSuccess();
|
|
}
|
|
|
|
Result PackageInstallTaskBase::InstallTicket(const fs::RightsId &rights_id, ContentMetaType meta_type) {
|
|
/* Read ticket from file. */
|
|
s64 ticket_size;
|
|
std::unique_ptr<char[]> ticket;
|
|
{
|
|
fs::FileHandle ticket_file;
|
|
{
|
|
PackagePath ticket_path;
|
|
this->CreateTicketPath(std::addressof(ticket_path), rights_id);
|
|
R_TRY(fs::OpenFile(std::addressof(ticket_file), ticket_path, fs::OpenMode_Read));
|
|
}
|
|
ON_SCOPE_EXIT { fs::CloseFile(ticket_file); };
|
|
|
|
R_TRY(fs::GetFileSize(std::addressof(ticket_size), ticket_file));
|
|
|
|
ticket.reset(new (std::nothrow) char[static_cast<size_t>(ticket_size)]);
|
|
R_UNLESS(ticket != nullptr, ncm::ResultAllocationFailed());
|
|
R_TRY(fs::ReadFile(ticket_file, 0, ticket.get(), static_cast<size_t>(ticket_size)));
|
|
}
|
|
|
|
|
|
/* Read certificate from file. */
|
|
s64 cert_size;
|
|
std::unique_ptr<char[]> cert;
|
|
{
|
|
fs::FileHandle cert_file;
|
|
{
|
|
PackagePath cert_path;
|
|
this->CreateCertificatePath(std::addressof(cert_path), rights_id);
|
|
R_TRY(fs::OpenFile(std::addressof(cert_file), cert_path, fs::OpenMode_Read));
|
|
}
|
|
ON_SCOPE_EXIT { fs::CloseFile(cert_file); };
|
|
|
|
R_TRY(fs::GetFileSize(std::addressof(cert_size), cert_file));
|
|
|
|
cert.reset(new (std::nothrow) char[static_cast<size_t>(cert_size)]);
|
|
R_UNLESS(cert != nullptr, ncm::ResultAllocationFailed());
|
|
R_TRY(fs::ReadFile(cert_file, 0, cert.get(), static_cast<size_t>(cert_size)));
|
|
}
|
|
|
|
/* TODO: es::ImportTicket() */
|
|
/* TODO: How should es be handled without undesired effects? */
|
|
|
|
return ResultSuccess();
|
|
}
|
|
|
|
void PackageInstallTaskBase::CreateContentPath(PackagePath *out_path, ContentId content_id) {
|
|
char str[ContentIdStringLength + 1] = {};
|
|
GetStringFromContentId(str, sizeof(str), content_id);
|
|
out_path->SetFormat("%s%s%s", this->package_root.Get(), str, ".nca");
|
|
}
|
|
|
|
void PackageInstallTaskBase::CreateContentMetaPath(PackagePath *out_path, ContentId content_id) {
|
|
char str[ContentIdStringLength + 1] = {};
|
|
GetStringFromContentId(str, sizeof(str), content_id);
|
|
out_path->SetFormat("%s%s%s", this->package_root.Get(), str, ".cnmt.nca");
|
|
}
|
|
|
|
void PackageInstallTaskBase::CreateTicketPath(PackagePath *out_path, fs::RightsId id) {
|
|
char str[RightsIdStringLength + 1] = {};
|
|
GetStringFromRightsId(str, sizeof(str), id);
|
|
out_path->SetFormat("%s%s%s", this->package_root.Get(), str, ".tik");
|
|
}
|
|
|
|
void PackageInstallTaskBase::CreateCertificatePath(PackagePath *out_path, fs::RightsId id) {
|
|
char str[RightsIdStringLength + 1] = {};
|
|
GetStringFromRightsId(str, sizeof(str), id);
|
|
out_path->SetFormat("%s%s%s", this->package_root.Get(), str, ".cert");
|
|
}
|
|
|
|
}
|