mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-03-22 23:30:14 +00:00
Extract assets from MPQ archives into organized loose files indexed by manifest.json, enabling fully parallel reads without StormLib serialization. Add asset_extract and blp_convert tools, PNG texture override support.
67 lines
2 KiB
C++
67 lines
2 KiB
C++
#include "manifest_writer.hpp"
|
|
#include <fstream>
|
|
#include <sstream>
|
|
#include <iomanip>
|
|
#include <zlib.h>
|
|
|
|
namespace wowee {
|
|
namespace tools {
|
|
|
|
uint32_t ManifestWriter::computeCRC32(const uint8_t* data, size_t size) {
|
|
return static_cast<uint32_t>(::crc32(::crc32(0L, Z_NULL, 0), data, static_cast<uInt>(size)));
|
|
}
|
|
|
|
bool ManifestWriter::write(const std::string& outputPath,
|
|
const std::string& basePath,
|
|
const std::vector<FileEntry>& entries) {
|
|
// Write JSON manually to avoid pulling nlohmann/json into the tool
|
|
// (though it would also work fine). This keeps the tool dependency-light.
|
|
std::ofstream file(outputPath);
|
|
if (!file.is_open()) {
|
|
return false;
|
|
}
|
|
|
|
file << "{\n";
|
|
file << " \"version\": 1,\n";
|
|
file << " \"basePath\": \"" << basePath << "\",\n";
|
|
file << " \"fileCount\": " << entries.size() << ",\n";
|
|
file << " \"entries\": {\n";
|
|
|
|
for (size_t i = 0; i < entries.size(); ++i) {
|
|
const auto& e = entries[i];
|
|
|
|
// Escape backslashes in WoW path for JSON
|
|
std::string escapedKey;
|
|
for (char c : e.wowPath) {
|
|
if (c == '\\') escapedKey += "\\\\";
|
|
else if (c == '"') escapedKey += "\\\"";
|
|
else escapedKey += c;
|
|
}
|
|
|
|
std::string escapedPath;
|
|
for (char c : e.filesystemPath) {
|
|
if (c == '\\') escapedPath += "\\\\";
|
|
else if (c == '"') escapedPath += "\\\"";
|
|
else escapedPath += c;
|
|
}
|
|
|
|
// CRC32 as hex
|
|
std::ostringstream hexCrc;
|
|
hexCrc << std::hex << std::setfill('0') << std::setw(8) << e.crc32;
|
|
|
|
file << " \"" << escapedKey << "\": {\"p\": \"" << escapedPath
|
|
<< "\", \"s\": " << e.size
|
|
<< ", \"h\": \"" << hexCrc.str() << "\"}";
|
|
|
|
if (i + 1 < entries.size()) file << ",";
|
|
file << "\n";
|
|
}
|
|
|
|
file << " }\n";
|
|
file << "}\n";
|
|
|
|
return file.good();
|
|
}
|
|
|
|
} // namespace tools
|
|
} // namespace wowee
|