From 382df7b2af6a9842265bfe454675cf62fe134cdd Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Tue, 23 Jul 2019 21:18:01 -0500 Subject: [PATCH] [nostalgia/tools/pack] Add missing nost-pack changes to actually write ROM --- src/nostalgia/tools/pack.cpp | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/nostalgia/tools/pack.cpp b/src/nostalgia/tools/pack.cpp index f6752d12..0eeb443e 100644 --- a/src/nostalgia/tools/pack.cpp +++ b/src/nostalgia/tools/pack.cpp @@ -6,6 +6,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include + #include #include #include @@ -39,6 +41,16 @@ using namespace nostalgia::common; } } +[[nodiscard]] static ox::Error writeFileBuff(const std::string &path, const std::vector &buff) { + auto file = fopen(path.c_str(), "wb"); + if (!file) { + return OxError(1); + } + oxReturnError(OxError(fwrite(buff.data(), buff.size(), 1, file) != 1)); + oxReturnError(OxError(fclose(file))); + return OxError(0); +} + [[nodiscard]] ox::Error run(ClArgs args) { std::string argSrc = args.getString("src").c_str(); std::string argDst = args.getString("dst").c_str(); @@ -55,11 +67,20 @@ using namespace nostalgia::common; ox::PassThroughFS src(argSrc.c_str()); ox::FileSystem32 dst(ox::FileStore32(buff.data(), buff.size())); auto err = nostalgia::pack(&src, &dst); - oxAssert(err, "pack failed"); - oxReturnError(err); - return OxError(0); + if (err) { + std::cerr << "pack failed..."; + } + + oxReturnError(dst.resize()); + std::cout << "new size: " << dst.size() << '\n'; + buff.resize(dst.size()); + + oxReturnError(writeFileBuff(argDst, buff)); + return err; } int main(int argc, const char **args) { - return static_cast(run(ClArgs(argc, args))); + auto err = run(ClArgs(argc, args)); + oxAssert(err, "pack failed"); + return static_cast(err); }