hac2l: it's 2024, prefer 'nsp' to 'pfs' for various reasons

This commit is contained in:
Michael Scire 2024-10-30 00:23:08 -07:00
parent 217f047375
commit e98a8f5262
6 changed files with 32 additions and 32 deletions

View File

@ -146,8 +146,8 @@ namespace ams::hactool {
MakeOptionHandler("outfile", "Specify output file path.", [] (Options &options, const char *arg) { return CreateFilePath(std::addressof(options.default_out_file_path), arg); }),
MakeOptionHandler("basenca", "Specify a base nca to use when processing.", [] (Options &options, const char *arg) { return CreateFilePath(std::addressof(options.base_nca_path), arg); }),
MakeOptionHandler("basexci", "Specify a base xci to use when processing.", [] (Options &options, const char *arg) { return CreateFilePath(std::addressof(options.base_xci_path), arg); }),
MakeOptionHandler("basepfs", "Specify a base pfs to use when processing.", [] (Options &options, const char *arg) { return CreateFilePath(std::addressof(options.base_pfs_path), arg); }),
MakeOptionHandler("basensp", "Specify a base nsp to use when processing. Synonym for basepfs.", [] (Options &options, const char *arg) { return CreateFilePath(std::addressof(options.base_pfs_path), arg); }),
MakeOptionHandler("basepfs", "Specify a base pfs to use when processing.", [] (Options &options, const char *arg) { return CreateFilePath(std::addressof(options.base_nsp_path), arg); }),
MakeOptionHandler("basensp", "Specify a base nsp to use when processing. Synonym for basepfs.", [] (Options &options, const char *arg) { return CreateFilePath(std::addressof(options.base_nsp_path), arg); }),
MakeOptionHandler("baseappfs", "Specify a base appfs to use when processing.", [] (Options &options, const char *arg) { return CreateFilePath(std::addressof(options.base_appfs_path), arg); }),
MakeOptionHandler("appindex", "[appfs] Specify a preferred application index.", [] (Options &options, const char *arg) { return ParseIntegerArgument(std::addressof(options.preferred_app_index), arg); }),
MakeOptionHandler("programindex", "[appfs] Specify a preferred program index.", [] (Options &options, const char *arg) { return ParseIntegerArgument(std::addressof(options.preferred_program_index), arg); }),

View File

@ -38,7 +38,7 @@ namespace ams::hactool {
FileType file_type = FileType::Nca;
const char *base_nca_path = nullptr;
const char *base_xci_path = nullptr;
const char *base_pfs_path = nullptr;
const char *base_nsp_path = nullptr;
const char *base_appfs_path = nullptr;
bool valid = false;
bool raw = false;

View File

@ -126,7 +126,7 @@ namespace ams::hactool {
ProcessAsApplicationFileSystemContext app_ctx;
};
struct ProcessAsPfsContext {
struct ProcessAsNspContext {
std::shared_ptr<fs::IStorage> storage;
std::shared_ptr<fs::fsa::IFileSystem> fs;
@ -148,11 +148,11 @@ namespace ams::hactool {
bool m_has_base_nca;
bool m_has_base_xci;
bool m_has_base_pfs;
bool m_has_base_nsp;
bool m_has_base_appfs;
ProcessAsNcaContext m_base_nca_ctx;
ProcessAsXciContext m_base_xci_ctx;
ProcessAsPfsContext m_base_pfs_ctx;
ProcessAsNspContext m_base_nsp_ctx;
ProcessAsApplicationFileSystemContext m_base_appfs_ctx;
os::SdkMutex m_print_lock;
@ -240,7 +240,7 @@ namespace ams::hactool {
Result ProcessAsNca(std::shared_ptr<fs::IStorage> storage, ProcessAsNcaContext *ctx = nullptr);
Result ProcessAsNpdm(std::shared_ptr<fs::IStorage> storage, ProcessAsNpdmContext *ctx = nullptr);
Result ProcessAsXci(std::shared_ptr<fs::IStorage> storage, ProcessAsXciContext *ctx = nullptr);
Result ProcessAsPfs(std::shared_ptr<fs::IStorage> storage, ProcessAsPfsContext *ctx = nullptr);
Result ProcessAsNsp(std::shared_ptr<fs::IStorage> storage, ProcessAsNspContext *ctx = nullptr);
Result ProcessAsRomfs(std::shared_ptr<fs::IStorage> storage, ProcessAsRomfsContext *ctx = nullptr);
Result ProcessAsApplicationFileSystem(std::shared_ptr<fs::fsa::IFileSystem> fs, ProcessAsApplicationFileSystemContext *ctx = nullptr);
@ -248,7 +248,7 @@ namespace ams::hactool {
void PrintAsNca(ProcessAsNcaContext &ctx);
void PrintAsNpdm(ProcessAsNpdmContext &ctx);
void PrintAsXci(ProcessAsXciContext &ctx);
void PrintAsPfs(ProcessAsPfsContext &ctx);
void PrintAsNsp(ProcessAsNspContext &ctx);
void PrintAsRomfs(ProcessAsRomfsContext &ctx);
void PrintAsApplicationFileSystem(ProcessAsApplicationFileSystemContext &ctx);
@ -256,7 +256,7 @@ namespace ams::hactool {
void SaveAsNca(ProcessAsNcaContext &ctx);
void SaveAsNpdm(ProcessAsNpdmContext &ctx);
void SaveAsXci(ProcessAsXciContext &ctx);
void SaveAsPfs(ProcessAsPfsContext &ctx);
void SaveAsNsp(ProcessAsNspContext &ctx);
void SaveAsRomfs(ProcessAsRomfsContext &ctx);
void SaveAsApplicationFileSystem(ProcessAsApplicationFileSystemContext &ctx);
};

View File

@ -19,11 +19,11 @@
namespace ams::hactool {
Processor::Processor(const Options &options) : m_options(options), m_base_nca_ctx{}, m_base_xci_ctx{}, m_base_pfs_ctx{}, m_base_appfs_ctx{} {
Processor::Processor(const Options &options) : m_options(options), m_base_nca_ctx{}, m_base_xci_ctx{}, m_base_nsp_ctx{}, m_base_appfs_ctx{} {
/* Default to no bases. */
m_has_base_nca = false;
m_has_base_xci = false;
m_has_base_pfs = false;
m_has_base_nsp = false;
m_has_base_appfs = false;
/* Create local file system for host root. */
@ -67,16 +67,16 @@ namespace ams::hactool {
}
}
if (m_options.base_pfs_path != nullptr) {
if (m_options.base_nsp_path != nullptr) {
std::shared_ptr<fs::IStorage> storage = nullptr;
if (const auto open_res = OpenFileStorage(std::addressof(storage), m_local_fs, m_options.base_pfs_path); R_SUCCEEDED(open_res)) {
if (const auto proc_res = this->ProcessAsPfs(std::move(storage), std::addressof(m_base_pfs_ctx)); R_SUCCEEDED(proc_res)) {
m_has_base_pfs = true;
if (const auto open_res = OpenFileStorage(std::addressof(storage), m_local_fs, m_options.base_nsp_path); R_SUCCEEDED(open_res)) {
if (const auto proc_res = this->ProcessAsNsp(std::move(storage), std::addressof(m_base_nsp_ctx)); R_SUCCEEDED(proc_res)) {
m_has_base_nsp = true;
} else {
fprintf(stderr, "Failed to process base pfs (%s): 2%03d-%04d\n", m_options.base_pfs_path, proc_res.GetModule(), proc_res.GetDescription());
fprintf(stderr, "Failed to process base nsp (%s): 2%03d-%04d\n", m_options.base_nsp_path, proc_res.GetModule(), proc_res.GetDescription());
}
} else {
fprintf(stderr, "Failed to open base pfs (%s): 2%03d-%04d\n", m_options.base_pfs_path, open_res.GetModule(), open_res.GetDescription());
fprintf(stderr, "Failed to open base nsp (%s): 2%03d-%04d\n", m_options.base_nsp_path, open_res.GetModule(), open_res.GetDescription());
}
}
@ -121,7 +121,7 @@ namespace ams::hactool {
R_TRY(this->ProcessAsXci(std::move(input)));
break;
case FileType::Pfs:
R_TRY(this->ProcessAsPfs(std::move(input)));
R_TRY(this->ProcessAsNsp(std::move(input)));
break;
case FileType::Romfs:
R_TRY(this->ProcessAsRomfs(std::move(input)));

View File

@ -134,7 +134,7 @@ namespace ams::hactool {
ctx->base_reader = m_base_nca_ctx.reader;
}
/* Next, we'll try looking for a match in the appfs of a base xci, pfs, or appfs. */
/* Next, we'll try looking for a match in the appfs of a base xci, nsp, or appfs. */
auto GetBaseFromAppFs = [&](ProcessAsApplicationFileSystemContext &app_ctx, const char *src) {
if (ctx->base_reader == nullptr) {
if (auto app_prog = app_ctx.apps.Find(ncm::ApplicationId{ctx->reader->GetProgramId() & ~static_cast<u64>(0xFF)}, 0, ctx->reader->GetProgramId() & 0xFF, ncm::ContentType::Program, ncm::ContentMetaType::Application); app_prog != app_ctx.apps.end()) {
@ -155,10 +155,10 @@ namespace ams::hactool {
m_has_base_xci = true;
}
if (m_has_base_pfs && !m_base_pfs_ctx.is_exefs) {
m_has_base_pfs = false;
GetBaseFromAppFs(m_base_pfs_ctx.app_ctx, "basepfs");
m_has_base_pfs = true;
if (m_has_base_nsp && !m_base_nsp_ctx.is_exefs) {
m_has_base_nsp = false;
GetBaseFromAppFs(m_base_nsp_ctx.app_ctx, "basensp");
m_has_base_nsp = true;
}
if (m_has_base_appfs) {

View File

@ -19,9 +19,9 @@
namespace ams::hactool {
Result Processor::ProcessAsPfs(std::shared_ptr<fs::IStorage> storage, ProcessAsPfsContext *ctx) {
Result Processor::ProcessAsNsp(std::shared_ptr<fs::IStorage> storage, ProcessAsNspContext *ctx) {
/* Ensure we have a context. */
ProcessAsPfsContext local_ctx{};
ProcessAsNspContext local_ctx{};
if (ctx == nullptr) {
ctx = std::addressof(local_ctx);
}
@ -78,18 +78,18 @@ namespace ams::hactool {
/* Print. */
if (ctx == std::addressof(local_ctx)) {
this->PrintAsPfs(*ctx);
this->PrintAsNsp(*ctx);
}
/* Save. */
if (ctx == std::addressof(local_ctx)) {
this->SaveAsPfs(*ctx);
this->SaveAsNsp(*ctx);
}
R_SUCCEED();
}
void Processor::PrintAsPfs(ProcessAsPfsContext &ctx) {
void Processor::PrintAsNsp(ProcessAsNspContext &ctx) {
{
auto _ = this->PrintHeader("PartitionFileSystem");
this->PrintMagic(ctx.magic);
@ -98,7 +98,7 @@ namespace ams::hactool {
char print_prefix[1_KB + 5];
std::memset(print_prefix, ' ', WidthToPrintFieldValue);
util::TSNPrintf(print_prefix, sizeof(print_prefix), "%s%s", m_indent_buffer, "pfs:");
util::TSNPrintf(print_prefix, sizeof(print_prefix), "%s%s", m_indent_buffer, "nsp:");
PrintDirectory(ctx.fs, print_prefix, "/");
}
@ -111,8 +111,8 @@ namespace ams::hactool {
}
}
void Processor::SaveAsPfs(ProcessAsPfsContext &ctx) {
/* Save pfs contents. */
void Processor::SaveAsNsp(ProcessAsNspContext &ctx) {
/* Save nsp contents. */
{
/* Determine path to extract to. */
const char *dir_path = nullptr;
@ -128,7 +128,7 @@ namespace ams::hactool {
/* If we have a path, extract to it. */
if (dir_path != nullptr) {
ExtractDirectory(m_local_fs, ctx.fs, "pfs:", dir_path, "/");
ExtractDirectory(m_local_fs, ctx.fs, "nsp:", dir_path, "/");
}
}
if (ctx.is_exefs) {