mirror of https://git.suyu.dev/suyu/suyu
file_sys/program_metadata: Remove obsolete TODOs
BitField has been trivially copyable since
e99a148628
, so we can eliminate these
TODO comments and use ReadObject() directly instead of memcpying the
data.
This commit is contained in:
parent
66be5150d6
commit
37b23efece
|
@ -3,7 +3,6 @@
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstring>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
|
@ -17,28 +16,30 @@ ProgramMetadata::ProgramMetadata() = default;
|
||||||
ProgramMetadata::~ProgramMetadata() = default;
|
ProgramMetadata::~ProgramMetadata() = default;
|
||||||
|
|
||||||
Loader::ResultStatus ProgramMetadata::Load(VirtualFile file) {
|
Loader::ResultStatus ProgramMetadata::Load(VirtualFile file) {
|
||||||
std::size_t total_size = static_cast<std::size_t>(file->GetSize());
|
const std::size_t total_size = file->GetSize();
|
||||||
if (total_size < sizeof(Header))
|
if (total_size < sizeof(Header)) {
|
||||||
return Loader::ResultStatus::ErrorBadNPDMHeader;
|
return Loader::ResultStatus::ErrorBadNPDMHeader;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO(DarkLordZach): Use ReadObject when Header/AcidHeader becomes trivially copyable.
|
if (sizeof(Header) != file->ReadObject(&npdm_header)) {
|
||||||
std::vector<u8> npdm_header_data = file->ReadBytes(sizeof(Header));
|
|
||||||
if (sizeof(Header) != npdm_header_data.size())
|
|
||||||
return Loader::ResultStatus::ErrorBadNPDMHeader;
|
return Loader::ResultStatus::ErrorBadNPDMHeader;
|
||||||
std::memcpy(&npdm_header, npdm_header_data.data(), sizeof(Header));
|
}
|
||||||
|
|
||||||
std::vector<u8> acid_header_data = file->ReadBytes(sizeof(AcidHeader), npdm_header.acid_offset);
|
if (sizeof(AcidHeader) != file->ReadObject(&acid_header, npdm_header.acid_offset)) {
|
||||||
if (sizeof(AcidHeader) != acid_header_data.size())
|
|
||||||
return Loader::ResultStatus::ErrorBadACIDHeader;
|
return Loader::ResultStatus::ErrorBadACIDHeader;
|
||||||
std::memcpy(&acid_header, acid_header_data.data(), sizeof(AcidHeader));
|
}
|
||||||
|
|
||||||
if (sizeof(AciHeader) != file->ReadObject(&aci_header, npdm_header.aci_offset))
|
if (sizeof(AciHeader) != file->ReadObject(&aci_header, npdm_header.aci_offset)) {
|
||||||
return Loader::ResultStatus::ErrorBadACIHeader;
|
return Loader::ResultStatus::ErrorBadACIHeader;
|
||||||
|
}
|
||||||
|
|
||||||
if (sizeof(FileAccessControl) != file->ReadObject(&acid_file_access, acid_header.fac_offset))
|
if (sizeof(FileAccessControl) != file->ReadObject(&acid_file_access, acid_header.fac_offset)) {
|
||||||
return Loader::ResultStatus::ErrorBadFileAccessControl;
|
return Loader::ResultStatus::ErrorBadFileAccessControl;
|
||||||
if (sizeof(FileAccessHeader) != file->ReadObject(&aci_file_access, aci_header.fah_offset))
|
}
|
||||||
|
|
||||||
|
if (sizeof(FileAccessHeader) != file->ReadObject(&aci_file_access, aci_header.fah_offset)) {
|
||||||
return Loader::ResultStatus::ErrorBadFileAccessHeader;
|
return Loader::ResultStatus::ErrorBadFileAccessHeader;
|
||||||
|
}
|
||||||
|
|
||||||
aci_kernel_capabilities.resize(aci_header.kac_size / sizeof(u32));
|
aci_kernel_capabilities.resize(aci_header.kac_size / sizeof(u32));
|
||||||
const u64 read_size = aci_header.kac_size;
|
const u64 read_size = aci_header.kac_size;
|
||||||
|
|
|
@ -58,7 +58,6 @@ public:
|
||||||
void Print() const;
|
void Print() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// TODO(DarkLordZach): BitField is not trivially copyable.
|
|
||||||
struct Header {
|
struct Header {
|
||||||
std::array<char, 4> magic;
|
std::array<char, 4> magic;
|
||||||
std::array<u8, 8> reserved;
|
std::array<u8, 8> reserved;
|
||||||
|
@ -85,7 +84,6 @@ private:
|
||||||
|
|
||||||
static_assert(sizeof(Header) == 0x80, "NPDM header structure size is wrong");
|
static_assert(sizeof(Header) == 0x80, "NPDM header structure size is wrong");
|
||||||
|
|
||||||
// TODO(DarkLordZach): BitField is not trivially copyable.
|
|
||||||
struct AcidHeader {
|
struct AcidHeader {
|
||||||
std::array<u8, 0x100> signature;
|
std::array<u8, 0x100> signature;
|
||||||
std::array<u8, 0x100> nca_modulus;
|
std::array<u8, 0x100> nca_modulus;
|
||||||
|
|
Loading…
Reference in New Issue