summaryrefslogtreecommitdiff
path: root/tools/knarc
diff options
context:
space:
mode:
Diffstat (limited to 'tools/knarc')
-rw-r--r--tools/knarc/Narc.cpp46
-rw-r--r--tools/knarc/Source.cpp5
2 files changed, 51 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
{
diff --git a/tools/knarc/Source.cpp b/tools/knarc/Source.cpp
index d9a5cf83..587c8527 100644
--- a/tools/knarc/Source.cpp
+++ b/tools/knarc/Source.cpp
@@ -8,6 +8,7 @@ using namespace std;
bool debug = false;
bool pack_no_fnt = true;
+bool output_header = false;
void PrintError(NarcError error)
{
@@ -40,6 +41,7 @@ static inline void usage() {
cout << "\t-n\tBuild the filename table (default: discards filenames)" << endl;
cout << "\t-D/--debug\tPrint additional debug messages" << endl;
cout << "\t-h/--help\tPrint this message and exit" << endl;
+ cout << "\t-i\tOutput a .naix header" << endl;
}
int main(int argc, char* argv[])
@@ -104,6 +106,9 @@ int main(int argc, char* argv[])
else if (!strcmp(argv[i], "-n")) {
pack_no_fnt = false;
}
+ else if (!strcmp(argv[i], "-i")) {
+ output_header = true;
+ }
else {
usage();
cerr << "ERROR: Unrecognized argument: " << argv[i] << endl;