mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-07-17 22:22:21 +02:00
ncm client: implement PackageInstallTask
This commit is contained in:
parent
1d6c2d2245
commit
5d301d20b4
@ -29,8 +29,9 @@
|
|||||||
#include <stratosphere/ncm/ncm_content_meta_utils.hpp>
|
#include <stratosphere/ncm/ncm_content_meta_utils.hpp>
|
||||||
#include <stratosphere/ncm/ncm_firmware_variation.hpp>
|
#include <stratosphere/ncm/ncm_firmware_variation.hpp>
|
||||||
#include <stratosphere/ncm/ncm_install_task_base.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_data.hpp>
|
||||||
#include <stratosphere/ncm/ncm_install_task_occupied_size.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_storage_id_utils.hpp>
|
||||||
#include <stratosphere/ncm/ncm_api.hpp>
|
#include <stratosphere/ncm/ncm_api.hpp>
|
||||||
|
@ -26,6 +26,7 @@ namespace ams::ncm {
|
|||||||
};
|
};
|
||||||
|
|
||||||
enum InstallConfig {
|
enum InstallConfig {
|
||||||
|
InstallConfig_None = (0 << 0),
|
||||||
InstallConfig_SystemUpdate = (1 << 2),
|
InstallConfig_SystemUpdate = (1 << 2),
|
||||||
InstallConfig_RequiresExFatDriver = (1 << 3),
|
InstallConfig_RequiresExFatDriver = (1 << 3),
|
||||||
InstallConfig_IgnoreTicket = (1 << 4),
|
InstallConfig_IgnoreTicket = (1 << 4),
|
||||||
|
@ -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;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
@ -29,7 +29,7 @@ namespace ams::ncm {
|
|||||||
public:
|
public:
|
||||||
PackageInstallTaskBase() : package_root() { /* ... */ }
|
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:
|
protected:
|
||||||
const char *GetPackageRootPath() {
|
const char *GetPackageRootPath() {
|
||||||
return this->package_root.Get();
|
return this->package_root.Get();
|
||||||
|
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -17,9 +17,9 @@
|
|||||||
|
|
||||||
namespace ams::ncm {
|
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));
|
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 = buffer;
|
||||||
this->buffer_size = buffer_size;
|
this->buffer_size = buffer_size;
|
||||||
return ResultSuccess();
|
return ResultSuccess();
|
||||||
|
Loading…
Reference in New Issue
Block a user