Preliminary Review Changes
This commit is contained in:
@@ -26,16 +26,13 @@ Loader::ResultStatus PartitionFilesystem::Load(const std::string& file_path, siz
|
||||
if (!file.ReadBytes(&pfs_header, sizeof(Header)))
|
||||
return Loader::ResultStatus::Error;
|
||||
|
||||
bool is_hfs;
|
||||
|
||||
if (pfs_header.magic == Common::MakeMagic('H', 'F', 'S', '0')) {
|
||||
is_hfs = true;
|
||||
} else if (pfs_header.magic == Common::MakeMagic('P', 'F', 'S', '0')) {
|
||||
is_hfs = false;
|
||||
} else {
|
||||
if (pfs_header.magic != Common::MakeMagic('H', 'F', 'S', '0') &&
|
||||
pfs_header.magic != Common::MakeMagic('P', 'F', 'S', '0')) {
|
||||
return Loader::ResultStatus::ErrorInvalidFormat;
|
||||
}
|
||||
|
||||
bool is_hfs = pfs_header.magic == Common::MakeMagic('H', 'F', 'S', '0');
|
||||
|
||||
size_t entry_size = is_hfs ? sizeof(HFSEntry) : sizeof(PFSEntry);
|
||||
size_t metadata_size =
|
||||
sizeof(Header) + (pfs_header.num_entries * entry_size) + pfs_header.strtab_size;
|
||||
@@ -60,14 +57,13 @@ Loader::ResultStatus PartitionFilesystem::Load(const std::vector<u8>& file_data,
|
||||
return Loader::ResultStatus::Error;
|
||||
|
||||
memcpy(&pfs_header, &file_data[offset], sizeof(Header));
|
||||
if (pfs_header.magic == Common::MakeMagic('H', 'F', 'S', '0')) {
|
||||
is_hfs = true;
|
||||
} else if (pfs_header.magic == Common::MakeMagic('P', 'F', 'S', '0')) {
|
||||
is_hfs = false;
|
||||
} else {
|
||||
if (pfs_header.magic != Common::MakeMagic('H', 'F', 'S', '0') &&
|
||||
pfs_header.magic != Common::MakeMagic('P', 'F', 'S', '0')) {
|
||||
return Loader::ResultStatus::ErrorInvalidFormat;
|
||||
}
|
||||
|
||||
is_hfs = pfs_header.magic == Common::MakeMagic('H', 'F', 'S', '0');
|
||||
|
||||
size_t entries_offset = offset + sizeof(Header);
|
||||
size_t entry_size = is_hfs ? sizeof(HFSEntry) : sizeof(PFSEntry);
|
||||
size_t strtab_offset = entries_offset + (pfs_header.num_entries * entry_size);
|
||||
|
||||
@@ -5,21 +5,18 @@
|
||||
#include <vector>
|
||||
|
||||
#include "common/common_funcs.h"
|
||||
#include "common/common_paths.h"
|
||||
#include "common/file_util.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "common/swap.h"
|
||||
#include "core/core.h"
|
||||
#include "core/file_sys/disk_filesystem.h"
|
||||
#include "core/file_sys/program_metadata.h"
|
||||
#include "core/file_sys/romfs_factory.h"
|
||||
#include "core/hle/kernel/process.h"
|
||||
#include "core/hle/kernel/resource_limit.h"
|
||||
#include "core/hle/service/filesystem/filesystem.h"
|
||||
#include "core/loader/nro.h"
|
||||
#include "core/loader/nca.h"
|
||||
#include "core/loader/nso.h"
|
||||
#include "core/memory.h"
|
||||
#include "nca.h"
|
||||
#include "nso.h"
|
||||
|
||||
namespace Loader {
|
||||
|
||||
@@ -140,25 +137,25 @@ static bool IsPfsExeFs(const FileSys::PartitionFilesystem& pfs) {
|
||||
return pfs.GetFileSize("main") > 0 && pfs.GetFileSize("main.npdm") > 0;
|
||||
}
|
||||
|
||||
u8 Nca::GetExeFsPfsId() {
|
||||
for (int i = 0; i < pfs.size(); ++i) {
|
||||
boost::optional<u8> Nca::GetExeFsPfsId() {
|
||||
for (size_t i = 0; i < pfs.size(); ++i) {
|
||||
if (IsPfsExeFs(pfs[i]))
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
return boost::none;
|
||||
}
|
||||
|
||||
u64 Nca::GetExeFsFileOffset(const std::string& file_name) {
|
||||
if (GetExeFsPfsId() == 255)
|
||||
if (GetExeFsPfsId() == boost::none)
|
||||
return 0;
|
||||
return pfs[GetExeFsPfsId()].GetFileOffset(file_name) + pfs_offset[GetExeFsPfsId()];
|
||||
return pfs[*GetExeFsPfsId()].GetFileOffset(file_name) + pfs_offset[*GetExeFsPfsId()];
|
||||
}
|
||||
|
||||
u64 Nca::GetExeFsFileSize(const std::string& file_name) {
|
||||
if (GetExeFsPfsId() == 255)
|
||||
if (GetExeFsPfsId() == boost::none)
|
||||
return 0;
|
||||
return pfs[GetExeFsPfsId()].GetFileSize(file_name);
|
||||
return pfs[*GetExeFsPfsId()].GetFileSize(file_name);
|
||||
}
|
||||
|
||||
u64 Nca::GetRomFsOffset() {
|
||||
|
||||
@@ -20,7 +20,7 @@ struct Nca {
|
||||
|
||||
FileSys::PartitionFilesystem GetPfs(u8 id);
|
||||
|
||||
u8 GetExeFsPfsId();
|
||||
boost::optional<u8> GetExeFsPfsId();
|
||||
|
||||
u64 GetExeFsFileOffset(const std::string& file_name);
|
||||
u64 GetExeFsFileSize(const std::string& file_name);
|
||||
|
||||
Reference in New Issue
Block a user