From b82f9827d4007d47a0264570fcc24605dac2f2d3 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Wed, 6 May 2026 14:54:29 -0700 Subject: [PATCH] feat(editor): add --info-zone-bytes for per-file size breakdown Drills into one zone's contents with categorized + sorted file sizes. --zone-stats aggregates across multiple zones; this answers 'which file is 80% of THIS zone?' and 'how much would --strip-zone free?': wowee_editor --info-zone-bytes custom_zones/MyZone Zone bytes: custom_zones/MyZone total: 2282178 bytes (2228.7 KB) across 6 file(s) Per-file (largest first): path bytes category Z_30_30.woc 1212456 terrain Z.glb 891736 3D export (derived) Z_30_30.whm 150540 terrain Z_30_30.wot 26680 terrain zone.json 446 json (source) quests.json 320 json (source) Per-category: 3D export (derived) 1 files 891736 bytes ( 39.1%) json (source) 2 files 766 bytes ( 0.0%) terrain 3 files 1389676 bytes ( 60.9%) Categories: terrain / model (open|proprietary) / building (open| proprietary) / texture (open|proprietary) / DBC / json (source) / 3D export (derived) / doc (derived) / other. Source vs derived split surfaces what --strip-zone would clean up (any 'derived' category) so capacity planning shows both 'what's mine' (source) and 'what's regeneratable' (derived). Recursive walk so subdirs (data/) are included with relative paths. JSON mode emits per-file records + per-category aggregate for programmatic consumption. --- tools/editor/main.cpp | 105 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 104 insertions(+), 1 deletion(-) diff --git a/tools/editor/main.cpp b/tools/editor/main.cpp index 43d6cb62..5ce30f78 100644 --- a/tools/editor/main.cpp +++ b/tools/editor/main.cpp @@ -537,6 +537,8 @@ static void printUsage(const char* argv0) { std::printf(" One-shot validate + creature/object/quest counts and exit\n"); std::printf(" --info-zone-tree \n"); std::printf(" Render a hierarchical tree view of a zone's contents (no --json)\n"); + std::printf(" --info-zone-bytes [--json]\n"); + std::printf(" Per-file size breakdown grouped by category, sorted largest-first\n"); std::printf(" --export-zone-summary-md [out.md]\n"); std::printf(" Render a markdown documentation page for a zone (manifest + content)\n"); std::printf(" --export-zone-csv [outDir]\n"); @@ -664,7 +666,7 @@ int main(int argc, char* argv[]) { "--info-glb-tree", "--validate-jsondbc", "--check-glb-bounds", "--validate-stl", "--validate-png", - "--zone-summary", "--info-zone-tree", + "--zone-summary", "--info-zone-tree", "--info-zone-bytes", "--export-zone-summary-md", "--export-quest-graph", "--export-zone-csv", "--export-zone-html", "--scaffold-zone", "--add-tile", "--remove-tile", "--list-tiles", @@ -3943,6 +3945,107 @@ int main(int argc, char* argv[]) { std::printf(" %s%s\n", branch(last), diskFiles[k].c_str()); } return 0; + } else if (std::strcmp(argv[i], "--info-zone-bytes") == 0 && i + 1 < argc) { + // Per-file size breakdown grouped by category, sorted by size + // descending. Useful for capacity planning ('which file is + // 80% of my zone?') and pre-strip-zone audits ('how much + // would --strip-zone free?'). --zone-stats aggregates across + // multiple zones; this drills into one zone's contents. + std::string zoneDir = argv[++i]; + bool jsonOut = (i + 1 < argc && + std::strcmp(argv[i + 1], "--json") == 0); + if (jsonOut) i++; + namespace fs = std::filesystem; + if (!fs::exists(zoneDir)) { + std::fprintf(stderr, + "info-zone-bytes: %s does not exist\n", zoneDir.c_str()); + return 1; + } + // Categorize by extension into source vs derived buckets so + // the breakdown surfaces what would be stripped. + struct Entry { + std::string path; // relative to zoneDir + uint64_t bytes; + std::string category; + }; + std::vector entries; + uint64_t totalBytes = 0; + std::error_code ec; + for (const auto& e : fs::recursive_directory_iterator(zoneDir, ec)) { + if (!e.is_regular_file()) continue; + std::string ext = e.path().extension().string(); + std::string name = e.path().filename().string(); + std::string rel = fs::relative(e.path(), zoneDir, ec).string(); + if (ec) rel = e.path().string(); + std::string cat; + if (ext == ".whm" || ext == ".wot" || ext == ".woc") cat = "terrain"; + else if (ext == ".wom") cat = "model (open)"; + else if (ext == ".wob") cat = "building (open)"; + else if (ext == ".m2" || ext == ".skin") cat = "model (proprietary)"; + else if (ext == ".wmo") cat = "building (proprietary)"; + else if (ext == ".blp") cat = "texture (proprietary)"; + else if (ext == ".png") cat = "texture (open/derived)"; + else if (ext == ".dbc") cat = "DBC (proprietary)"; + else if (ext == ".json") cat = "json (source)"; + else if (ext == ".glb" || ext == ".obj" || ext == ".stl") cat = "3D export (derived)"; + else if (ext == ".html" || ext == ".dot" || ext == ".csv") cat = "doc (derived)"; + else if (name == "ZONE.md" || name == "DEPS.md") cat = "doc (derived)"; + else cat = "other"; + uint64_t sz = e.file_size(ec); + if (ec) continue; + totalBytes += sz; + entries.push_back({rel, sz, cat}); + } + // Sort largest first so the heaviest contributors are at the + // top of the table. + std::sort(entries.begin(), entries.end(), + [](const Entry& a, const Entry& b) { return a.bytes > b.bytes; }); + // Aggregate per-category for the summary footer. + std::map> byCategory; + for (const auto& e : entries) { + byCategory[e.category].first += e.bytes; + byCategory[e.category].second++; + } + if (jsonOut) { + nlohmann::json j; + j["zone"] = zoneDir; + j["totalBytes"] = totalBytes; + j["fileCount"] = entries.size(); + nlohmann::json arr = nlohmann::json::array(); + for (const auto& e : entries) { + arr.push_back({{"path", e.path}, + {"bytes", e.bytes}, + {"category", e.category}}); + } + j["files"] = arr; + nlohmann::json catObj; + for (const auto& [c, p] : byCategory) { + catObj[c] = {{"bytes", p.first}, {"count", p.second}}; + } + j["byCategory"] = catObj; + std::printf("%s\n", j.dump(2).c_str()); + return 0; + } + std::printf("Zone bytes: %s\n", zoneDir.c_str()); + std::printf(" total: %llu bytes (%.1f KB) across %zu file(s)\n", + static_cast(totalBytes), + totalBytes / 1024.0, entries.size()); + std::printf("\n Per-file (largest first):\n"); + std::printf(" %-50s %12s category\n", "path", "bytes"); + for (const auto& e : entries) { + std::printf(" %-50s %12llu %s\n", + e.path.substr(0, 50).c_str(), + static_cast(e.bytes), + e.category.c_str()); + } + std::printf("\n Per-category:\n"); + for (const auto& [c, p] : byCategory) { + std::printf(" %-26s %4d files %12llu bytes (%5.1f%%)\n", + c.c_str(), p.second, + static_cast(p.first), + totalBytes ? (100.0 * p.first / totalBytes) : 0.0); + } + return 0; } else if (std::strcmp(argv[i], "--export-zone-summary-md") == 0 && i + 1 < argc) { // Render a Markdown documentation page for a zone. Useful for // designers tracking changes between versions, generating