00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "fltTrans.h"
00020
00021 #include <fltHeader.h>
00022
00023
00024
00025
00026
00027
00028 FltTrans::
00029 FltTrans() :
00030 WithOutputFile(true, false, true)
00031 {
00032
00033
00034 _preferred_extension = ".flt";
00035
00036 set_program_description
00037 ("This program reads a MultiGen OpenFlight (.flt) file and writes an "
00038 "essentially equivalent .flt file, to the file specified with -o (or "
00039 "as the second parameter). Some simple operations may be performed.");
00040
00041 clear_runlines();
00042 add_runline("[opts] input.flt output.flt");
00043 add_runline("[opts] -o output.flt input.flt");
00044
00045 add_path_replace_options();
00046 add_path_store_options();
00047
00048 add_option
00049 ("v", "version", 0,
00050 "Upgrade (or downgrade) the flt file to the indicated version. This "
00051 "may not be completely correct for all version-to-version combinations.",
00052 &FltTrans::dispatch_double, &_got_new_version, &_new_version);
00053
00054 add_option
00055 ("o", "filename", 0,
00056 "Specify the filename to which the resulting .flt file will be written. "
00057 "If this option is omitted, the last parameter name is taken to be the "
00058 "name of the output file.",
00059 &FltTrans::dispatch_filename, &_got_output_filename, &_output_filename);
00060 }
00061
00062
00063
00064
00065
00066
00067
00068 void FltTrans::
00069 run() {
00070 if (_got_new_version) {
00071 int new_version = (int)floor(_new_version * 100.0 + 0.5);
00072 if (new_version < FltHeader::min_flt_version() ||
00073 new_version > FltHeader::max_flt_version()) {
00074 nout << "Cannot write flt files of version " << new_version / 100.0
00075 << ". This program only understands how to write flt files between version "
00076 << FltHeader::min_flt_version() / 100.0 << " and "
00077 << FltHeader::max_flt_version() / 100.0 << ".\n";
00078 exit(1);
00079 }
00080 }
00081
00082 PT(FltHeader) header = new FltHeader(_path_replace);
00083
00084 nout << "Reading " << _input_filename << "\n";
00085 FltError result = header->read_flt(_input_filename);
00086 if (result != FE_ok) {
00087 nout << "Unable to read: " << result << "\n";
00088 exit(1);
00089 }
00090
00091 if (header->check_version()) {
00092 nout << "Version is " << header->get_flt_version() / 100.0 << "\n";
00093 }
00094
00095 if (_got_new_version) {
00096 int new_version = (int)floor(_new_version * 100.0 + 0.5);
00097 header->set_flt_version(new_version);
00098 }
00099
00100 header->apply_converted_filenames();
00101
00102 result = header->write_flt(get_output());
00103 if (result != FE_ok) {
00104 nout << "Unable to write: " << result << "\n";
00105 exit(1);
00106 }
00107
00108 nout << "Successfully written.\n";
00109 }
00110
00111
00112
00113
00114
00115
00116
00117 bool FltTrans::
00118 handle_args(ProgramBase::Args &args) {
00119 if (!check_last_arg(args, 1)) {
00120 return false;
00121 }
00122
00123 if (args.empty()) {
00124 nout << "You must specify the .flt file to read on the command line.\n";
00125 return false;
00126
00127 } else if (args.size() != 1) {
00128 nout << "You must specify only one .flt file to read on the command line.\n";
00129 return false;
00130 }
00131
00132 _input_filename = args[0];
00133
00134 return true;
00135 }
00136
00137
00138 int main(int argc, char *argv[]) {
00139 FltTrans prog;
00140 prog.parse_command_line(argc, argv);
00141 prog.run();
00142 return 0;
00143 }