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