[nostalgia/tools/pack] Update for new ClArgs interface

This commit is contained in:
Gary Talent 2021-04-01 22:00:07 -05:00
parent 61fb5207ea
commit 786892dda1

View File

@ -15,47 +15,44 @@
#include "pack/pack.hpp" #include "pack/pack.hpp"
static void writeFileBuff(const std::string &path, std::vector<char> &buff) { static ox::Error writeFileBuff(const std::string &path, std::vector<char> &buff) {
try { try {
std::ofstream f(path, std::ios::binary); std::ofstream f(path, std::ios::binary);
f.write(buff.data(), static_cast<intptr_t>(buff.size())); f.write(buff.data(), static_cast<intptr_t>(buff.size()));
} catch (const std::fstream::failure&) { } catch (const std::fstream::failure&) {
throw OxError(2); return OxError(2, "failed to write file");
} }
return OxError(0);
} }
static void run(const ox::ClArgs &args) { static ox::Error run(const ox::ClArgs &args) {
std::string argSrc = args.getString("src").c_str(); auto argSrc = args.getString("src", "");
std::string argDst = args.getString("dst").c_str(); auto argDst = args.getString("dst", "");
if (argSrc == "") { if (argSrc == "") {
std::cerr << "error: must specify a source directory\n"; std::cerr << "error: must specify a source directory\n";
throw OxError(1); return OxError(1, "must specify a source directory");
} }
if (argDst == "") { if (argDst == "") {
std::cerr << "error: must specify a destination ROM file\n"; std::cerr << "error: must specify a destination ROM file\n";
throw OxError(1); return OxError(1, "must specify a destination ROM file");
} }
std::vector<char> buff(32 * ox::units::MB); std::vector<char> buff(32 * ox::units::MB);
oxThrowError(ox::FileSystem32::format(buff.data(), buff.size())); oxReturnError(ox::FileSystem32::format(buff.data(), buff.size()));
ox::PassThroughFS src(argSrc.c_str()); ox::PassThroughFS src(argSrc.c_str());
ox::FileSystem32 dst(ox::FileStore32(buff.data(), buff.size())); ox::FileSystem32 dst(ox::FileStore32(buff.data(), buff.size()));
oxThrowError(nostalgia::pack(&src, &dst)); oxReturnError(nostalgia::pack(&src, &dst));
oxThrowError(dst.resize()); oxReturnError(dst.resize());
std::cout << "new size: " << dst.size() << '\n'; std::cout << "new size: " << dst.size() << '\n';
buff.resize(dst.size()); buff.resize(dst.size());
writeFileBuff(argDst, buff); oxReturnError(writeFileBuff(argDst.c_str(), buff));
return OxError(0);
} }
int main(int argc, const char **args) { int main(int argc, const char **args) {
ox::trace::init(); ox::trace::init();
try { auto err = run(ox::ClArgs(argc, args));
run(ox::ClArgs(argc, args)); oxAssert(err, "pack failed");
} catch (const ox::Error &err) { return static_cast<int>(err);
oxPanic(err, "pack failed");
std::cerr << "pack failed...\n";
return static_cast<int>(err);
}
return 0;
} }