From e58407f156736c01a0a2d49147911040810de72d Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Mon, 17 Jun 2019 23:09:20 -0500 Subject: [PATCH] [nostalgia/tools/pack] Add input checking to nost-pack --- src/nostalgia/tools/pack.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/nostalgia/tools/pack.cpp b/src/nostalgia/tools/pack.cpp index 1ad5f4e5..bda989e1 100644 --- a/src/nostalgia/tools/pack.cpp +++ b/src/nostalgia/tools/pack.cpp @@ -6,7 +6,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include #include #include #include @@ -42,17 +41,25 @@ ox::ValErr> loadFileBuff(QString path, ::size_t *sizeOut = } } -int run(ClArgs args) { - QString argSrc = args.getString("src").c_str(); - QString argDst = args.getString("dst").c_str(); - std::array buff; +ox::Error run(ClArgs args) { + std::string argSrc = args.getString("src").c_str(); + std::string argDst = args.getString("dst").c_str(); + if (argSrc == "") { + std::cerr << "error: must specify a source directory\n"; + return OxError(1); + } + if (argDst == "") { + std::cerr << "error: must specify a destination ROM file\n"; + return OxError(1); + } + std::vector buff(32 * ox::units::MB); ox::FileSystem32::format(buff.data(), buff.size()); - ox::PassThroughFS src(argSrc.toUtf8()); + ox::PassThroughFS src(argSrc.c_str()); ox::FileSystem32 dst(ox::FileStore32(buff.data(), buff.size())); oxReturnError(nostalgia::pack(&src, &dst)); - return 0; + return OxError(0); } int main(int argc, const char **args) { - return run(ClArgs(argc, args)); + return static_cast(run(ClArgs(argc, args))); }