diff options
Diffstat (limited to 'tools/knarc/Narc.cpp')
-rw-r--r-- | tools/knarc/Narc.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/tools/knarc/Narc.cpp b/tools/knarc/Narc.cpp index 7e698571..cce7cdea 100644 --- a/tools/knarc/Narc.cpp +++ b/tools/knarc/Narc.cpp @@ -29,6 +29,7 @@ using namespace std; extern bool debug; extern bool pack_no_fnt; +extern bool output_header; void Narc::AlignDword(ofstream& ofs, uint8_t paddingChar) { @@ -145,6 +146,39 @@ bool Narc::Pack(const fs::path& fileName, const fs::path& directory) if (!ofs.good()) { return Cleanup(ofs, NarcError::InvalidOutputFile); } + ofstream ofhs; + string stem; + string stem_upper; + // Pikalax 29 May 2021 + // Output an includable header that enumerates the NARC contents + if (output_header) + { + fs::path naixfname = fileName; + naixfname.replace_extension(".naix"); + + ofhs.open(naixfname); + if (!ofhs.good()) + { + ofhs.close(); + return Cleanup(ofs, NarcError::InvalidOutputFile); + } + + stem = fileName.stem().string(); + stem_upper = stem; + for (char &c : stem_upper) + { c = toupper(c); } + + ofhs << "/*\n" + " * THIS FILE WAS AUTOMATICALLY\n" + " * GENERATED BY tools/knarc\n" + " * DO NOT MODIFY!!!\n" + " */\n" + "\n" + "#ifndef NARC_" << stem_upper << "_NAIX_\n" + "#define NARC_" << stem_upper << "_NAIX_\n" + "\n" + "enum {\n"; + } vector<FileAllocationTableEntry> fatEntries; uint16_t directoryCounter = 1; @@ -153,6 +187,7 @@ bool Narc::Pack(const fs::path& fileName, const fs::path& directory) ignore_patterns.push_back(".*keep"); WildcardVector keep_patterns(directory / ".knarckeep"); + int memberNo = 0; for (const auto& de : OrderedDirectoryIterator(directory, true)) { if (is_directory(de)) @@ -164,6 +199,12 @@ bool Narc::Pack(const fs::path& fileName, const fs::path& directory) if (debug) { cerr << "DEBUG: adding file " << de.path() << endl; } + if (output_header) + { + string de_stem = de.path().filename().string(); + std::replace(de_stem.begin(), de_stem.end(), '.', '_'); + ofhs << "\tNARC_" << stem << "_" << de_stem << " = " << (memberNo++) << ",\n"; + } fatEntries.push_back(FileAllocationTableEntry { .Start = 0x0, @@ -183,6 +224,11 @@ bool Narc::Pack(const fs::path& fileName, const fs::path& directory) fatEntries.back().End = fatEntries.back().Start + static_cast<uint32_t>(file_size(de)); } } + if (output_header) + { + ofhs << "};\n\n#endif //NARC_" << stem_upper << "_NAIX_\n"; + ofhs.close(); + } FileAllocationTable fat { |