Fixed init-order bug that caused c172-set.xml defaults always to be
used unless explicitly overwritten. Now, the options are parsed twice, and only the *-set.xml file for the *last* aircraft specified is loaded.
This commit is contained in:
parent
e8db622ce1
commit
76cda01641
2 changed files with 49 additions and 50 deletions
|
@ -341,48 +341,11 @@ bool fgDetectLanguage() {
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Read in configuration (file and command line)
|
||||
bool fgInitConfig ( int argc, char **argv ) {
|
||||
|
||||
// First, set some sane default values
|
||||
fgSetDefaults();
|
||||
|
||||
// Read global preferences from $FG_ROOT/preferences.xml
|
||||
SGPath props_path(globals->get_fg_root());
|
||||
props_path.append("preferences.xml");
|
||||
SG_LOG(SG_INPUT, SG_INFO, "Reading global preferences");
|
||||
readProperties(props_path.str(), globals->get_props());
|
||||
SG_LOG(SG_INPUT, SG_INFO, "Finished Reading global preferences");
|
||||
|
||||
// Detect the required language as early as possible
|
||||
if (fgDetectLanguage() != true)
|
||||
return false;
|
||||
|
||||
// Read the default aircraft config file.
|
||||
string aircraft = fgGetString("/sim/aircraft", "");
|
||||
if (aircraft.size() > 0) {
|
||||
SGPath aircraft_path(globals->get_fg_root());
|
||||
aircraft_path.append("Aircraft");
|
||||
aircraft_path.append(aircraft);
|
||||
aircraft_path.concat("-set.xml");
|
||||
SG_LOG(SG_INPUT, SG_INFO, "Reading default aircraft: " << aircraft
|
||||
<< " from " << aircraft_path.str());
|
||||
try {
|
||||
readProperties(aircraft_path.str(), globals->get_props());
|
||||
} catch (const sg_exception &e) {
|
||||
string message = "Error reading default aircraft: ";
|
||||
message += e.getFormattedMessage();
|
||||
SG_LOG(SG_INPUT, SG_ALERT, message);
|
||||
exit(2);
|
||||
}
|
||||
} else {
|
||||
SG_LOG(SG_INPUT, SG_ALERT, "No default aircraft specified");
|
||||
}
|
||||
|
||||
// Attempt to locate and parse the various config files in order
|
||||
// from least precidence to greatest precidence
|
||||
|
||||
// Attempt to locate and parse the various non-XML config files in order
|
||||
// from least precidence to greatest precidence
|
||||
static void
|
||||
do_options (int argc, char ** argv)
|
||||
{
|
||||
// Check for $fg_root/system.fgfsrc
|
||||
SGPath config( globals->get_fg_root() );
|
||||
config.append( "system.fgfsrc" );
|
||||
|
@ -416,6 +379,49 @@ bool fgInitConfig ( int argc, char **argv ) {
|
|||
// Parse remaining command line options
|
||||
// These will override anything specified in a config file
|
||||
fgParseArgs(argc, argv);
|
||||
}
|
||||
|
||||
|
||||
// Read in configuration (file and command line)
|
||||
bool fgInitConfig ( int argc, char **argv ) {
|
||||
|
||||
// First, set some sane default values
|
||||
fgSetDefaults();
|
||||
|
||||
// Read global preferences from $FG_ROOT/preferences.xml
|
||||
SGPath props_path(globals->get_fg_root());
|
||||
props_path.append("preferences.xml");
|
||||
SG_LOG(SG_INPUT, SG_INFO, "Reading global preferences");
|
||||
readProperties(props_path.str(), globals->get_props());
|
||||
SG_LOG(SG_INPUT, SG_INFO, "Finished Reading global preferences");
|
||||
|
||||
// Detect the required language as early as possible
|
||||
if (fgDetectLanguage() != true)
|
||||
return false;
|
||||
|
||||
// Read the default aircraft config file.
|
||||
do_options(argc, argv); // preparse options for default aircraft
|
||||
string aircraft = fgGetString("/sim/aircraft", "");
|
||||
if (aircraft.size() > 0) {
|
||||
SGPath aircraft_path(globals->get_fg_root());
|
||||
aircraft_path.append("Aircraft");
|
||||
aircraft_path.append(aircraft);
|
||||
aircraft_path.concat("-set.xml");
|
||||
SG_LOG(SG_INPUT, SG_INFO, "Reading default aircraft: " << aircraft
|
||||
<< " from " << aircraft_path.str());
|
||||
try {
|
||||
readProperties(aircraft_path.str(), globals->get_props());
|
||||
} catch (const sg_exception &e) {
|
||||
string message = "Error reading default aircraft: ";
|
||||
message += e.getFormattedMessage();
|
||||
SG_LOG(SG_INPUT, SG_ALERT, message);
|
||||
exit(2);
|
||||
}
|
||||
} else {
|
||||
SG_LOG(SG_INPUT, SG_ALERT, "No default aircraft specified");
|
||||
}
|
||||
|
||||
do_options(argc, argv);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -989,14 +989,7 @@ parse_option (const string& arg)
|
|||
exit(2);
|
||||
}
|
||||
} else if ( arg.find( "--aircraft=" ) == 0 ) {
|
||||
// read in the top level aircraft definition file
|
||||
SGPath apath( globals->get_fg_root() );
|
||||
apath.append( "Aircraft" );
|
||||
apath.append( arg.substr(11) );
|
||||
apath.concat( "-set.xml" );
|
||||
SG_LOG(SG_INPUT, SG_INFO, "Reading aircraft: " << arg.substr(11)
|
||||
<< " from " << apath.str());
|
||||
readProperties( apath.str(), globals->get_props() );
|
||||
fgSetString("/sim/aircraft", arg.substr(11).c_str());
|
||||
} else {
|
||||
SG_LOG( SG_GENERAL, SG_ALERT, "Unknown option '" << arg << "'" );
|
||||
return FG_OPTIONS_ERROR;
|
||||
|
|
Loading…
Add table
Reference in a new issue