Services/AM: Expose CIAFile class in AM header
This commit is contained in:
parent
1edbbf7f8c
commit
750e7e06b1
2 changed files with 171 additions and 164 deletions
|
@ -10,9 +10,7 @@
|
|||
#include "common/file_util.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "common/string_util.h"
|
||||
#include "core/file_sys/cia_container.h"
|
||||
#include "core/file_sys/errors.h"
|
||||
#include "core/file_sys/file_backend.h"
|
||||
#include "core/file_sys/ncch_container.h"
|
||||
#include "core/file_sys/title_metadata.h"
|
||||
#include "core/hle/ipc.h"
|
||||
|
@ -23,7 +21,6 @@
|
|||
#include "core/hle/kernel/handle_table.h"
|
||||
#include "core/hle/kernel/server_session.h"
|
||||
#include "core/hle/kernel/session.h"
|
||||
#include "core/hle/result.h"
|
||||
#include "core/hle/service/am/am.h"
|
||||
#include "core/hle/service/am/am_app.h"
|
||||
#include "core/hle/service/am/am_net.h"
|
||||
|
@ -82,17 +79,12 @@ struct TicketInfo {
|
|||
|
||||
static_assert(sizeof(TicketInfo) == 0x18, "Ticket info structure size is wrong");
|
||||
|
||||
// A file handled returned for CIAs to be written into and subsequently installed.
|
||||
class CIAFile final : public FileSys::FileBackend {
|
||||
public:
|
||||
explicit CIAFile(Service::FS::MediaType media_type) : media_type(media_type) {}
|
||||
|
||||
ResultVal<size_t> Read(u64 offset, size_t length, u8* buffer) const override {
|
||||
ResultVal<size_t> CIAFile::Read(u64 offset, size_t length, u8* buffer) const {
|
||||
UNIMPLEMENTED();
|
||||
return MakeResult<size_t>(length);
|
||||
}
|
||||
}
|
||||
|
||||
ResultVal<size_t> WriteTitleMetadata(u64 offset, size_t length, const u8* buffer) {
|
||||
ResultVal<size_t> CIAFile::WriteTitleMetadata(u64 offset, size_t length, const u8* buffer) {
|
||||
container.LoadTitleMetadata(data, container.GetTitleMetadataOffset());
|
||||
FileSys::TitleMetadata tmd = container.GetTitleMetadata();
|
||||
cia_installing_tid = tmd.GetTitleID();
|
||||
|
@ -126,9 +118,9 @@ public:
|
|||
install_state = CIAInstallState::TMDLoaded;
|
||||
|
||||
return MakeResult<size_t>(length);
|
||||
}
|
||||
}
|
||||
|
||||
ResultVal<size_t> WriteContentData(u64 offset, size_t length, const u8* buffer) {
|
||||
ResultVal<size_t> CIAFile::WriteContentData(u64 offset, size_t length, const u8* buffer) {
|
||||
// Data is not being buffered, so we have to keep track of how much of each <ID>.app
|
||||
// has been written since we might get a written buffer which contains multiple .app
|
||||
// contents or only part of a larger .app's contents.
|
||||
|
@ -151,8 +143,7 @@ public:
|
|||
// Since the incoming TMD has already been written, we can use GetTitleContentPath
|
||||
// to get the content paths to write to.
|
||||
FileSys::TitleMetadata tmd = container.GetTitleMetadata();
|
||||
FileUtil::IOFile file(
|
||||
GetTitleContentPath(media_type, tmd.GetTitleID(), i, is_update),
|
||||
FileUtil::IOFile file(GetTitleContentPath(media_type, tmd.GetTitleID(), i, is_update),
|
||||
content_written[i] ? "ab" : "wb");
|
||||
|
||||
if (!file.IsOpen())
|
||||
|
@ -169,9 +160,9 @@ public:
|
|||
}
|
||||
|
||||
return MakeResult<size_t>(length);
|
||||
}
|
||||
}
|
||||
|
||||
ResultVal<size_t> Write(u64 offset, size_t length, bool flush, const u8* buffer) override {
|
||||
ResultVal<size_t> CIAFile::Write(u64 offset, size_t length, bool flush, const u8* buffer) {
|
||||
written += length;
|
||||
|
||||
// TODO(shinyquagsire23): Can we assume that things will only be written in sequence?
|
||||
|
@ -219,8 +210,7 @@ public:
|
|||
|
||||
// The end of our TMD is at the beginning of Content data, so ensure we have that much
|
||||
// buffered before trying to parse.
|
||||
if (written >= container.GetContentOffset() &&
|
||||
install_state != CIAInstallState::TMDLoaded) {
|
||||
if (written >= container.GetContentOffset() && install_state != CIAInstallState::TMDLoaded) {
|
||||
auto result = WriteTitleMetadata(offset, length, buffer);
|
||||
if (result.Failed())
|
||||
return result;
|
||||
|
@ -236,36 +226,21 @@ public:
|
|||
return result;
|
||||
|
||||
return MakeResult<size_t>(length);
|
||||
}
|
||||
}
|
||||
|
||||
u64 GetSize() const override {
|
||||
u64 CIAFile::GetSize() const {
|
||||
return written;
|
||||
}
|
||||
}
|
||||
|
||||
bool SetSize(u64 size) const override {
|
||||
bool CIAFile::SetSize(u64 size) const {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool Close() const override {
|
||||
bool CIAFile::Close() const {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void Flush() const override {}
|
||||
|
||||
private:
|
||||
// Whether it's installing an update, and what step of installation it is at
|
||||
bool is_update = false;
|
||||
CIAInstallState install_state = CIAInstallState::InstallStarted;
|
||||
|
||||
// How much has been written total, CIAContainer for the installing CIA, buffer of all data
|
||||
// prior to content data, how much of each content index has been written, and where the CIA
|
||||
// is being installed to
|
||||
u64 written = 0;
|
||||
FileSys::CIAContainer container;
|
||||
std::vector<u8> data;
|
||||
std::vector<u64> content_written;
|
||||
Service::FS::MediaType media_type;
|
||||
};
|
||||
void CIAFile::Flush() const {}
|
||||
|
||||
Service::FS::MediaType GetTitleMediaType(u64 titleId) {
|
||||
u16 platform = static_cast<u16>(titleId >> 48);
|
||||
|
|
|
@ -6,6 +6,9 @@
|
|||
|
||||
#include <string>
|
||||
#include "common/common_types.h"
|
||||
#include "core/file_sys/cia_container.h"
|
||||
#include "core/file_sys/file_backend.h"
|
||||
#include "core/hle/result.h"
|
||||
|
||||
namespace Service {
|
||||
namespace FS {
|
||||
|
@ -38,6 +41,35 @@ enum class CIAInstallState : u32 {
|
|||
ContentWritten,
|
||||
};
|
||||
|
||||
// A file handled returned for CIAs to be written into and subsequently installed.
|
||||
class CIAFile final : public FileSys::FileBackend {
|
||||
public:
|
||||
explicit CIAFile(Service::FS::MediaType media_type) : media_type(media_type) {}
|
||||
|
||||
ResultVal<size_t> Read(u64 offset, size_t length, u8* buffer) const override;
|
||||
ResultVal<size_t> WriteTitleMetadata(u64 offset, size_t length, const u8* buffer);
|
||||
ResultVal<size_t> WriteContentData(u64 offset, size_t length, const u8* buffer);
|
||||
ResultVal<size_t> Write(u64 offset, size_t length, bool flush, const u8* buffer) override;
|
||||
u64 GetSize() const override;
|
||||
bool SetSize(u64 size) const override;
|
||||
bool Close() const override;
|
||||
void Flush() const override;
|
||||
|
||||
private:
|
||||
// Whether it's installing an update, and what step of installation it is at
|
||||
bool is_update = false;
|
||||
CIAInstallState install_state = CIAInstallState::InstallStarted;
|
||||
|
||||
// How much has been written total, CIAContainer for the installing CIA, buffer of all data
|
||||
// prior to content data, how much of each content index has been written, and where the CIA
|
||||
// is being installed to
|
||||
u64 written = 0;
|
||||
FileSys::CIAContainer container;
|
||||
std::vector<u8> data;
|
||||
std::vector<u64> content_written;
|
||||
Service::FS::MediaType media_type;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the mediatype for an installed title
|
||||
* @param titleId the installed title ID
|
||||
|
|
Loading…
Reference in a new issue