ncm client: implement PackageInstallTask

This commit is contained in:
Adubbz 2020-03-25 15:05:46 +11:00
parent 4391980427
commit 2d680f965a
6 changed files with 104 additions and 4 deletions

View file

@ -29,8 +29,9 @@
#include <stratosphere/ncm/ncm_content_meta_utils.hpp>
#include <stratosphere/ncm/ncm_firmware_variation.hpp>
#include <stratosphere/ncm/ncm_install_task_base.hpp>
#include <stratosphere/ncm/ncm_package_install_task_base.hpp>
#include <stratosphere/ncm/ncm_install_task_data.hpp>
#include <stratosphere/ncm/ncm_install_task_occupied_size.hpp>
#include <stratosphere/ncm/ncm_package_install_task_base.hpp>
#include <stratosphere/ncm/ncm_package_install_task.hpp>
#include <stratosphere/ncm/ncm_storage_id_utils.hpp>
#include <stratosphere/ncm/ncm_api.hpp>

View file

@ -26,6 +26,7 @@ namespace ams::ncm {
};
enum InstallConfig {
InstallConfig_None = (0 << 0),
InstallConfig_SystemUpdate = (1 << 2),
InstallConfig_RequiresExFatDriver = (1 << 3),
InstallConfig_IgnoreTicket = (1 << 4),

View file

@ -0,0 +1,36 @@
/*
* 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/>.
*/
#pragma once
#include <stratosphere/ncm/ncm_package_install_task_base.hpp>
namespace ams::ncm {
class PackageInstallTask : public PackageInstallTaskBase {
private:
MemoryInstallTaskData data;
public:
PackageInstallTask() { /* ... */ }
virtual ~PackageInstallTask() override { /* ... */ }
Result Initialize(const char *package_path, StorageId storage_id, void *buffer, size_t buffer_size, bool ignore_ticket);
protected:
bool IsContentMetaContentName(const char *name);
virtual Result PrepareInstallContentMetaData() override;
private:
virtual Result GetInstallContentMetaInfo(InstallContentMetaInfo *out_info, const ContentMetaKey &key) override;
};
}

View file

@ -29,7 +29,7 @@ namespace ams::ncm {
public:
PackageInstallTaskBase() : package_root() { /* ... */ }
Result Initialize(const char *package_path, void *buffer, size_t buffer_size, StorageId storage_id, InstallTaskDataBase *data, u32 config);
Result Initialize(const char *package_root_path, void *buffer, size_t buffer_size, StorageId storage_id, InstallTaskDataBase *data, u32 config);
protected:
const char *GetPackageRootPath() {
return this->package_root.Get();

View file

@ -0,0 +1,62 @@
/*
* 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>
#include "ncm_fs_utils.hpp"
namespace ams::ncm {
bool PackageInstallTask::IsContentMetaContentName(const char *name) {
return impl::PathView(name).HasSuffix(".cnmt");
}
Result PackageInstallTask::Initialize(const char *package_root_path, StorageId storage_id, void *buffer, size_t buffer_size, bool ignore_ticket) {
return PackageInstallTaskBase::Initialize(package_root_path, buffer, buffer_size, storage_id, std::addressof(this->data), ignore_ticket ? InstallConfig_IgnoreTicket : InstallConfig_None);
}
Result PackageInstallTask::GetInstallContentMetaInfo(InstallContentMetaInfo *out_info, const ContentMetaKey &key) {
return ncm::ResultContentNotFound();
}
Result PackageInstallTask::PrepareInstallContentMetaData() {
/* Open the directory. */
fs::DirectoryHandle dir;
R_TRY(fs::OpenDirectory(std::addressof(dir), this->GetPackageRootPath(), fs::OpenDirectoryMode_File));
ON_SCOPE_EXIT { fs::CloseDirectory(dir); };
while (true) {
/* Read the current entry. */
s64 count;
fs::DirectoryEntry entry;
R_TRY(fs::ReadDirectory(std::addressof(count), std::addressof(entry), dir, 1));
/* No more entries remain, we are done. */
if (count == 0) {
break;
}
/* Check if this entry is content meta. */
if (this->IsContentMetaContentName(entry.name)) {
/* Prepare content meta if id is valid. */
std::optional<ContentId> id = GetContentIdFromString(entry.name, strnlen(entry.name, fs::EntryNameLengthMax + 1));
R_UNLESS(id, ncm::ResultInvalidPackageFormat());
R_TRY(this->PrepareContentMeta(InstallContentMetaInfo::MakeUnverifiable(*id, entry.file_size, ContentMetaKey::MakeUnknownType(0, 0)), std::nullopt, std::nullopt));
}
}
return ResultSuccess();
}
}

View file

@ -17,9 +17,9 @@
namespace ams::ncm {
Result PackageInstallTaskBase::Initialize(const char *package_path, void *buffer, size_t buffer_size, StorageId storage_id, InstallTaskDataBase *data, u32 config) {
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_path);
this->package_root.Set(package_root_path);
this->buffer = buffer;
this->buffer_size = buffer_size;
return ResultSuccess();