From 446ce137c6823ba9eff273bdafdaf266287c7c98 Mon Sep 17 00:00:00 2001 From: Bryan Galdrikian Date: Tue, 21 Feb 2017 12:07:59 -0800 Subject: first commit --- NvBlast/tools/DataConverter/src/Main.cpp | 88 ++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 NvBlast/tools/DataConverter/src/Main.cpp (limited to 'NvBlast/tools/DataConverter/src/Main.cpp') diff --git a/NvBlast/tools/DataConverter/src/Main.cpp b/NvBlast/tools/DataConverter/src/Main.cpp new file mode 100644 index 0000000..fb9be66 --- /dev/null +++ b/NvBlast/tools/DataConverter/src/Main.cpp @@ -0,0 +1,88 @@ +#include "NvBlastExtDataConverter.h" +#include +#include +#include "tclap/CmdLine.h" +#include +#include +#include +#include + +#define IDE_DEBUG_MODE 0 + +int customMain(std::vector& args) +{ + try + { + // setup cmd line + TCLAP::CmdLine cmd("Blast SDK: Data Converter", ' ', "0.1"); + + TCLAP::ValueArg outversionArg("v", "outversion", "Output binary block version. Pass -1 or ignore this parameter to convert to latest version.", false, -1, "outversion"); + cmd.add(outversionArg); + TCLAP::ValueArg outfileArg("o", "outfile", "Output binary file.", true, "", "outfile"); + cmd.add(outfileArg); + TCLAP::ValueArg infileArg("i", "infile", "Input binary file.", true, "", "infile"); + cmd.add(infileArg); + + // parse cmd input + cmd.parse(args); + + // get cmd parse results + std::string infile = infileArg.getValue(); + std::string outfile = outfileArg.getValue(); + int32_t outBlockVersion = outversionArg.getValue(); + + // read input file + std::ifstream infileStream(infile.c_str(), std::ios::binary); + if (!infileStream.is_open()) + { + std::cerr << "FAIL: Can't open input file: " << infile << std::endl; + return 0; + } + std::vector inBlock((std::istreambuf_iterator(infileStream)), std::istreambuf_iterator()); + infileStream.close(); + + // convert + std::vector outBlock; + if (Nv::Blast::convertDataBlock(outBlock, inBlock, outBlockVersion >= 0 ? (uint32_t*)&outBlockVersion : nullptr)) + { + std::ofstream outfileStream(outfile, std::ios::binary | std::ios::out); + if (!outfileStream.is_open()) + { + std::cerr << "FAIL: Can't open output file: " << outfile << std::endl; + return 0; + } + outfileStream.write((char*)&outBlock[0], outBlock.size()); + outfileStream.close(); + + std::cout << "Conversion success, result written in file: " << outfile << std::endl; + } + else + { + std::cout << "Conversion failed." << std::endl; + } + } + catch (TCLAP::ArgException &e) // catch any exceptions + { + std::cout << "error: " << e.error() << " for arg " << e.argId() << std::endl; + } + + return 0; +} + +int main(int argc, const char* const* argv) +{ + std::vector args; +#if IDE_DEBUG_MODE + NV_UNUSED(argc); + NV_UNUSED(argv); + + args.push_back(""); + args.push_back("-i wall.blast"); + args.push_back("-o wall_new.blast"); + args.push_back("-v 5"); +#else + for (int i = 0; i < argc; i++) + args.push_back(argv[i]); +#endif + return customMain(args); +} -- cgit v1.2.3