// packtool — cross-platform replacement for the fork's PackMaker.exe. // packtool pack [--encrypt] // packtool unpack // packtool list #include "../src/pack/eterpack.h" #include #include #include #include #include #include namespace fs = std::filesystem; using namespace mtpack; static std::vector slurp(const fs::path &p) { std::ifstream f(p, std::ios::binary); return {std::istreambuf_iterator(f), std::istreambuf_iterator()}; } static int do_pack(const char *folder, const char *out, bool enc) { fs::path root(folder); std::vector files; for (auto &e : fs::recursive_directory_iterator(root)) { if (!e.is_regular_file()) { continue; } std::string rel = fs::relative(e.path(), root).generic_string(); files.push_back({rel, slurp(e.path())}); } std::string err; if (!write_pack(out, files, enc, &err)) { std::fprintf(stderr, "pack failed: %s\n", err.c_str()); return 1; } std::printf("packed %zu files -> %s%s\n", files.size(), out, enc ? " (encrypted)" : ""); return 0; } static int do_unpack(const char *in, const char *out_folder) { EterPack pk; std::string err; if (!pk.open(in, &err)) { std::fprintf(stderr, "open failed: %s\n", err.c_str()); return 1; } for (const auto &name : pk.names()) { std::vector data; if (!pk.read(name, data, &err)) { std::fprintf(stderr, "read %s: %s\n", name.c_str(), err.c_str()); return 1; } fs::path dst = fs::path(out_folder) / name; fs::create_directories(dst.parent_path()); std::ofstream f(dst, std::ios::binary); f.write(reinterpret_cast(data.data()), static_cast(data.size())); } std::printf("unpacked %zu files -> %s\n", pk.count(), out_folder); return 0; } static int do_list(const char *in) { EterPack pk; std::string err; if (!pk.open(in, &err)) { std::fprintf(stderr, "open failed: %s\n", err.c_str()); return 1; } std::printf("%zu entries, name-field=%d\n", pk.count(), pk.name_field()); for (const auto &n : pk.names()) { std::printf(" %s\n", n.c_str()); } return 0; } int main(int argc, char **argv) { if (argc >= 4 && std::strcmp(argv[1], "pack") == 0) { bool enc = argc >= 5 && std::strcmp(argv[4], "--encrypt") == 0; return do_pack(argv[2], argv[3], enc); } if (argc == 4 && std::strcmp(argv[1], "unpack") == 0) { return do_unpack(argv[2], argv[3]); } if (argc == 3 && std::strcmp(argv[1], "list") == 0) { return do_list(argv[2]); } std::fprintf(stderr, "usage:\n" " packtool pack [--encrypt]\n" " packtool unpack \n" " packtool list \n"); return 2; }