Skip to content

Commit

Permalink
Minor renames, new README
Browse files Browse the repository at this point in the history
  • Loading branch information
XorTroll committed Aug 6, 2023
1 parent 2b38932 commit 7916448
Show file tree
Hide file tree
Showing 9 changed files with 411 additions and 429 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,51 @@

#pragma once
#include <fs/fs_FileSystem.hpp>
#include <nsp/nsp_Types.hpp>

namespace nsp {
namespace fs {

class PFS0 {
public:
struct Header {
u32 magic;
u32 file_count;
u32 string_table_size;
u32 reserved;
};
static_assert(sizeof(Header) == 0x10);

struct FileEntry {
u64 offset;
u64 size;
u32 string_table_offset;
u32 pad;
};
static_assert(sizeof(FileEntry) == 0x18);

static constexpr u32 Magic = 0x30534650; // 'PFS0'

static constexpr u32 InvalidFileIndex = UINT32_MAX;

struct File {
FileEntry entry;
std::string name;
};

private:
std::string path;
fs::Explorer *exp;
u8 *string_table;
u32 header_size;
PFS0Header header;
std::vector<PFS0File> files;
Header header;
std::vector<File> files;
bool ok;

public:
static constexpr u32 InvalidFileIndex = UINT32_MAX;

NX_CONSTEXPR bool IsValidFileIndex(u32 idx) {
static constexpr inline bool IsValidFileIndex(u32 idx) {
return idx != InvalidFileIndex;
}

NX_CONSTEXPR bool IsInvalidFileIndex(u32 idx) {
static constexpr inline bool IsInvalidFileIndex(u32 idx) {
return idx == InvalidFileIndex;
}

Expand Down
2 changes: 1 addition & 1 deletion Goldleaf/include/nsp/nsp_Builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/

#pragma once
#include <nsp/nsp_Types.hpp>
#include <base_Common.hpp>

namespace nsp {

Expand Down
4 changes: 2 additions & 2 deletions Goldleaf/include/nsp/nsp_Installer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
*/

#pragma once
#include <nsp/nsp_PFS0.hpp>
#include <ncm/ncm_PackagedContentMeta.hpp>
#include <es/es_Service.hpp>
#include <ns/ns_Service.hpp>
#include <fs/fs_FileSystem.hpp>
#include <fs/fs_PFS0.hpp>
#include <hos/hos_Content.hpp>
#include <hos/hos_Titles.hpp>

Expand Down Expand Up @@ -59,7 +59,7 @@ namespace nsp {

class Installer {
private:
PFS0 pfs0_file;
fs::PFS0 pfs0_file;
u8 keygen;
hos::TicketFile tik_file;
ncm::PackagedContentMeta packaged_cnt_meta;
Expand Down
50 changes: 0 additions & 50 deletions Goldleaf/include/nsp/nsp_Types.hpp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
*/

#include <nsp/nsp_PFS0.hpp>
#include <fs/fs_PFS0.hpp>

namespace nsp {
namespace fs {

PFS0::PFS0(fs::Explorer *exp, const std::string &path) {
this->path = path;
Expand All @@ -34,13 +34,13 @@ namespace nsp {
this->exp->ReadFile(this->path, 0, sizeof(this->header), &this->header);
if(this->header.magic == Magic) {
this->ok = true;
const auto string_table_offset = sizeof(PFS0Header) + (sizeof(PFS0FileEntry) * this->header.file_count);
const auto string_table_offset = sizeof(Header) + (sizeof(FileEntry) * this->header.file_count);
this->string_table = new u8[this->header.string_table_size]();
this->header_size = string_table_offset + this->header.string_table_size;
this->exp->ReadFile(this->path, string_table_offset, this->header.string_table_size, this->string_table);
for(u32 i = 0; i < this->header.file_count; i++) {
const auto offset = sizeof(PFS0Header) + (i * sizeof(PFS0FileEntry));
PFS0FileEntry ent = {};
const auto offset = sizeof(Header) + (i * sizeof(FileEntry));
FileEntry ent = {};
this->exp->ReadFile(this->path, offset, sizeof(ent), &ent);
std::string name;
for(u32 j = ent.string_table_offset; j < this->header.string_table_size; j++) {
Expand All @@ -50,7 +50,7 @@ namespace nsp {
}
name += ch;
}
const PFS0File file = {
const File file = {
.entry = ent,
.name = name,
};
Expand Down
9 changes: 5 additions & 4 deletions Goldleaf/source/nsp/nsp_Builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,25 @@

#include <nsp/nsp_Builder.hpp>
#include <fs/fs_FileSystem.hpp>
#include <fs/fs_PFS0.hpp>

namespace nsp {

bool GenerateFrom(const std::string &input_path, const std::string &output_nsp, GenerateStartCallback start_cb, GenerateProgressCallback prog_cb) {
auto exp = fs::GetExplorerForPath(input_path);
const auto files = exp->GetFiles(input_path);
PFS0Header header = {
.magic = Magic,
fs::PFS0::Header header = {
.magic = fs::PFS0::Magic,
.file_count = static_cast<u32>(files.size()),
};

const size_t string_table_max_size = files.size() * FS_MAX_PATH;
auto string_table_buf = fs::AllocateWorkBuffer(string_table_max_size);
size_t string_table_size = 0;
std::vector<PFS0File> file_entries;
std::vector<fs::PFS0::File> file_entries;
size_t base_offset = 0;
for(auto &file: files) {
PFS0File entry = {};
fs::PFS0::File entry = {};
entry.entry.offset = base_offset;
entry.entry.string_table_offset = string_table_size;
const auto file_size = exp->GetFileSize(input_path + "/" + file);
Expand Down
10 changes: 5 additions & 5 deletions Goldleaf/source/nsp/nsp_Installer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ namespace nsp {
GLEAF_RC_TRY(ncmOpenContentMetaDatabase(&this->cnt_meta_db, this->storage_id));

std::string cnmt_nca_file_name;
auto cnmt_nca_file_idx = PFS0::InvalidFileIndex;
auto cnmt_nca_file_idx = fs::PFS0::InvalidFileIndex;
u64 cnmt_nca_file_size = 0;
auto tik_file_idx = PFS0::InvalidFileIndex;
auto tik_file_idx = fs::PFS0::InvalidFileIndex;
tik_file_size = 0;
const auto pfs0_files = pfs0_file.GetFiles();
for(u32 i = 0; i < pfs0_files.size(); i++) {
Expand All @@ -199,7 +199,7 @@ namespace nsp {
}
}
}
GLEAF_RC_UNLESS(PFS0::IsValidFileIndex(cnmt_nca_file_idx), rc::goldleaf::ResultMetaNotFound);
GLEAF_RC_UNLESS(fs::PFS0::IsValidFileIndex(cnmt_nca_file_idx), rc::goldleaf::ResultMetaNotFound);
GLEAF_RC_UNLESS(cnmt_nca_file_size > 0, rc::goldleaf::ResultMetaNotFound);
const auto cnmt_nca_content_id = fs::GetBaseName(cnmt_nca_file_name);

Expand Down Expand Up @@ -295,7 +295,7 @@ namespace nsp {
const auto control_nca_content_id = hos::ContentIdAsString(cnt.info.content_id);
const auto control_nca_file_name = control_nca_content_id + ".nca";
const auto control_nca_file_idx = this->pfs0_file.GetFileIndexByName(control_nca_file_name);
if(PFS0::IsValidFileIndex(control_nca_file_idx)) {
if(fs::PFS0::IsValidFileIndex(control_nca_file_idx)) {
const auto control_nca_temp_path = nand_sys_explorer->MakeFull("Contents/temp/" + control_nca_file_name);
this->pfs0_file.SaveFile(control_nca_file_idx, nand_sys_explorer, control_nca_temp_path);

Expand Down Expand Up @@ -394,7 +394,7 @@ namespace nsp {
for(const auto &cnt: this->contents) {
const auto content_file_name = hos::ContentIdAsString(cnt.content_id) + ((cnt.content_type == NcmContentType_Meta) ? ".cnmt" : "") + ".nca";
const auto content_file_idx = this->pfs0_file.GetFileIndexByName(content_file_name);
GLEAF_RC_UNLESS(PFS0::IsValidFileIndex(content_file_idx), rc::goldleaf::ResultInvalidNsp);
GLEAF_RC_UNLESS(fs::PFS0::IsValidFileIndex(content_file_idx), rc::goldleaf::ResultInvalidNsp);
total_size += pfs0_file.GetFileSize(content_file_idx);
content_file_idxs.push_back(content_file_idx);
}
Expand Down
61 changes: 0 additions & 61 deletions Quark.md

This file was deleted.

Loading

0 comments on commit 7916448

Please sign in to comment.