|
| 1 | +/* xoreos-tools - Tools to help with xoreos development |
| 2 | + * |
| 3 | + * xoreos-tools is the legal property of its developers, whose names |
| 4 | + * can be found in the AUTHORS file distributed with this source |
| 5 | + * distribution. |
| 6 | + * |
| 7 | + * xoreos-tools is free software; you can redistribute it and/or |
| 8 | + * modify it under the terms of the GNU General Public License |
| 9 | + * as published by the Free Software Foundation; either version 3 |
| 10 | + * of the License, or (at your option) any later version. |
| 11 | + * |
| 12 | + * xoreos-tools is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License |
| 18 | + * along with xoreos-tools. If not, see <http://www.gnu.org/licenses/>. |
| 19 | + */ |
| 20 | + |
| 21 | +/** @file |
| 22 | + * Tool to convert TLK files into XML. |
| 23 | + */ |
| 24 | + |
| 25 | +#include <cstring> |
| 26 | +#include <cstdio> |
| 27 | + |
| 28 | +#include "src/version/version.h" |
| 29 | + |
| 30 | +#include "src/common/scopedptr.h" |
| 31 | +#include "src/common/ustring.h" |
| 32 | +#include "src/common/util.h" |
| 33 | +#include "src/common/error.h" |
| 34 | +#include "src/common/platform.h" |
| 35 | +#include "src/common/readfile.h" |
| 36 | +#include "src/common/writefile.h" |
| 37 | +#include "src/common/cli.h" |
| 38 | + |
| 39 | +#include "src/aurora/types.h" |
| 40 | + |
| 41 | +#include "src/xml/fevdumper.h" |
| 42 | + |
| 43 | +#include "src/util.h" |
| 44 | + |
| 45 | +bool parseCommandLine(const std::vector<Common::UString> &argv, int &returnValue, |
| 46 | + Common::UString &inFile, Common::UString &outFile); |
| 47 | + |
| 48 | +void dumpFEV(const Common::UString &inFile, const Common::UString &outFile); |
| 49 | + |
| 50 | +int main(int argc, char **argv) { |
| 51 | + initPlatform(); |
| 52 | + |
| 53 | + try { |
| 54 | + std::vector<Common::UString> args; |
| 55 | + Common::Platform::getParameters(argc, argv, args); |
| 56 | + |
| 57 | + int returnValue = 1; |
| 58 | + Common::UString inFile, outFile; |
| 59 | + |
| 60 | + if (!parseCommandLine(args, returnValue, inFile, outFile)) |
| 61 | + return returnValue; |
| 62 | + |
| 63 | + dumpFEV(inFile, outFile); |
| 64 | + } catch (...) { |
| 65 | + Common::exceptionDispatcherError(); |
| 66 | + } |
| 67 | + |
| 68 | + return 0; |
| 69 | +} |
| 70 | + |
| 71 | +bool parseCommandLine(const std::vector<Common::UString> &argv, int &returnValue, |
| 72 | + Common::UString &inFile, Common::UString &outFile) { |
| 73 | + using Common::CLI::NoOption; |
| 74 | + using Common::CLI::Parser; |
| 75 | + using Common::CLI::ValGetter; |
| 76 | + using Common::CLI::makeEndArgs; |
| 77 | + |
| 78 | + NoOption inFileOpt(false, new ValGetter<Common::UString &>(inFile, "input file")); |
| 79 | + NoOption outFileOpt(true, new ValGetter<Common::UString &>(outFile, "output file")); |
| 80 | + Parser parser(argv[0], "FMOD FEV to XML converter", |
| 81 | + "If no output file is given, the output is written to stdout.\n", |
| 82 | + returnValue, |
| 83 | + makeEndArgs(&inFileOpt, &outFileOpt)); |
| 84 | + |
| 85 | + return parser.process(argv); |
| 86 | +} |
| 87 | + |
| 88 | +void dumpFEV(const Common::UString &inFile, const Common::UString &outFile) { |
| 89 | + Common::ScopedPtr<Common::SeekableReadStream> fev(new Common::ReadFile(inFile)); |
| 90 | + Common::ScopedPtr<Common::WriteStream> out(openFileOrStdOut(outFile)); |
| 91 | + |
| 92 | + XML::FEVDumper::dump(*out, *fev); |
| 93 | + |
| 94 | + out->flush(); |
| 95 | + |
| 96 | + if (!outFile.empty()) |
| 97 | + status("Converted \"%s\" to \"%s\"", inFile.c_str(), outFile.c_str()); |
| 98 | +} |
0 commit comments