libnedit
Lightweight C++ library for Nintendo DS(i) formats
Loading...
Searching...
No Matches
fmt_NARC.hpp
1
2#pragma once
3#include <ntr/fmt/fmt_Common.hpp>
4#include <ntr/fmt/nfs/nfs_NitroFs.hpp>
5
6namespace ntr::fmt {
7
8 struct NARC : public nfs::NitroFsFileFormat {
9
10 struct Header : public CommonHeader<0x4352414E /* "NARC" */ > {
11 };
12
13 struct FileAllocationTableBlock : public CommonBlock<0x46415442 /* "BTAF" */ > {
14 u16 entry_count;
15 u8 reserved[2];
16 };
17
18 struct FileNameTableBlock : public CommonBlock<0x464E5442 /* "BTNF" */ > {
19 };
20
21 struct FileImageBlock : public CommonBlock<0x46494D47 /* "GMIF" */ > {
22 };
23
24 Header header;
27 FileImageBlock fimg;
28
29 NARC() {}
30 NARC(const NARC&) = delete;
31
32 size_t GetBaseOffset() override {
33 // Offset after GMIF header, where all file data starts
34 return util::AlignUp(this->header.header_size + this->fat.block_size + this->fnt.block_size, 0x4) + sizeof(FileImageBlock);
35 }
36
37 size_t GetFatEntriesOffset() override {
38 return sizeof(Header) + sizeof(FileAllocationTableBlock);
39 }
40
41 size_t GetFatEntryCount() override {
42 return this->fat.entry_count;
43 }
44
45 Result OnFileSystemWrite(fs::BinaryFile &w_bf, const ssize_t size_diff) override {
46 this->header.file_size += size_diff;
47 this->fimg.block_size += size_diff;
48
49 NTR_R_TRY(w_bf.SetAbsoluteOffset(0));
50 NTR_R_TRY(w_bf.Write(this->header));
51
52 const auto fimg_offset = this->header.header_size + this->fat.block_size + this->fnt.block_size;
53 NTR_R_TRY(w_bf.SetAbsoluteOffset(fimg_offset));
54 NTR_R_TRY(w_bf.Write(this->fimg));
55
56 NTR_R_SUCCEED();
57 }
58
59 Result ValidateImpl(const std::string &path, std::shared_ptr<fs::FileHandle> file_handle, const fs::FileCompression comp) override;
60 Result ReadImpl(const std::string &path, std::shared_ptr<fs::FileHandle> file_handle, const fs::FileCompression comp) override;
61 };
62
63 // Note: a CARC file is basically an LZ-compressed NARC
64
65 using NARCFileHandle = nfs::NitroFsFileHandle<NARC>;
66
67}
Definition fmt_Common.hpp:53
Definition fmt_Common.hpp:35
Definition fmt_NARC.hpp:21
Definition fmt_NARC.hpp:18
Definition fmt_NARC.hpp:10
Definition fmt_NARC.hpp:8
Definition nfs_NitroFs.hpp:43