Update --showaircraft and --aircraft= options to recursively search the
$FGROOT/data/Aircraft hierarchy. There could be some long term performance concerns if a person has a *huge* collection of aircraft or a really slow file system, but I see zero performance blip here from recursing the default CVS tree. We should also allow the user to specify the whole path to the -set.xml file if they don't want to recurse ... this way we could eventually come up with an aircraft selection dialog box on the front end so the user could manually walk the tree to the desired aircraft. There also the system wouldn't have to search for the aircraft.
This commit is contained in:
parent
b262586763
commit
46caf8576b
3 changed files with 83 additions and 54 deletions
|
@ -508,6 +508,38 @@ do_options (int argc, char ** argv)
|
|||
}
|
||||
|
||||
|
||||
static string fgFindAircraftPath( const SGPath &path, const string &aircraft ) {
|
||||
ulDirEnt* dire;
|
||||
ulDir *dirp = ulOpenDir(path.str().c_str());
|
||||
if (dirp == NULL) {
|
||||
cerr << "Unable to open aircraft directory." << endl;
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
while ((dire = ulReadDir(dirp)) != NULL) {
|
||||
if (dire->d_isdir) {
|
||||
if ( strcmp("CVS", dire->d_name) && strcmp(".", dire->d_name)
|
||||
&& strcmp("..", dire->d_name) )
|
||||
{
|
||||
SGPath next = path;
|
||||
next.append(dire->d_name);
|
||||
|
||||
string result = fgFindAircraftPath( next, aircraft );
|
||||
if ( ! result.empty() ) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
} else if ( !strcmp(dire->d_name, aircraft.c_str()) ) {
|
||||
return path.str();
|
||||
}
|
||||
}
|
||||
|
||||
ulCloseDir(dirp);
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
// Read in configuration (file and command line)
|
||||
bool fgInitConfig ( int argc, char **argv ) {
|
||||
|
||||
|
@ -527,42 +559,35 @@ bool fgInitConfig ( int argc, char **argv ) {
|
|||
// Scan user config files and command line for a specified aircraft.
|
||||
fgInitFGAircraft(argc, argv);
|
||||
|
||||
string aircraft = fgGetString("/sim/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");
|
||||
SGPath aircraft_search( globals->get_fg_root() );
|
||||
aircraft_search.append( "Aircraft" );
|
||||
|
||||
if ( !ulFileExists(aircraft_path.c_str()) ) {
|
||||
string adir = aircraft;
|
||||
int pos, alen = adir.length();
|
||||
string aircraft_set = aircraft + "-set.xml";
|
||||
|
||||
if ( ((pos = adir.rfind("-jsbsim")) != string::npos) ||
|
||||
((pos = adir.rfind("-yasim")) != string::npos) ||
|
||||
((pos = adir.rfind("-uiuc")) != string::npos) )
|
||||
{
|
||||
adir.erase(pos, alen);
|
||||
string result = fgFindAircraftPath( aircraft_search, aircraft_set );
|
||||
if ( !result.empty() ) {
|
||||
SGPath full_name( result );
|
||||
full_name.append( aircraft_set );
|
||||
|
||||
SG_LOG(SG_INPUT, SG_INFO, "Reading default aircraft: " << aircraft
|
||||
<< " from " << full_name.str());
|
||||
try {
|
||||
readProperties( full_name.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, "Cannot find specified aircraft: "
|
||||
<< aircraft );
|
||||
}
|
||||
|
||||
aircraft_path = globals->get_fg_root();
|
||||
aircraft_path.append("Aircraft");
|
||||
aircraft_path.append(adir);
|
||||
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");
|
||||
SG_LOG( SG_INPUT, SG_ALERT, "No default aircraft specified" );
|
||||
}
|
||||
|
||||
// parse options after loading aircraft to ensure any user
|
||||
|
|
|
@ -1521,7 +1521,7 @@ fgParseArgs (int argc, char **argv)
|
|||
else if (result == FG_OPTIONS_SHOW_AIRCRAFT) {
|
||||
SGPath path( globals->get_fg_root() );
|
||||
path.append("Aircraft");
|
||||
fgShowAircraft(path);
|
||||
fgShowAircraft(path, true);
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
@ -1714,17 +1714,9 @@ fgUsage (bool verbose)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Search in the current directory, and in on directory deeper
|
||||
* for <aircraft>-set.xml configuration files and show the aircaft name
|
||||
* and the contents of the<description> tag in a sorted manner.
|
||||
*
|
||||
* @parampath the directory to search for configuration files
|
||||
* @param recursive defines whether the directory should be searched recursively
|
||||
*/
|
||||
void fgShowAircraft(const SGPath &path, bool recursive) {
|
||||
static vector<string> aircraft;
|
||||
|
||||
static void fgSearchAircraft(const SGPath &path, string_list &aircraft,
|
||||
bool recursive)
|
||||
{
|
||||
ulDirEnt* dire;
|
||||
ulDir *dirp = ulOpenDir(path.str().c_str());
|
||||
if (dirp == NULL) {
|
||||
|
@ -1742,7 +1734,7 @@ void fgShowAircraft(const SGPath &path, bool recursive) {
|
|||
SGPath next = path;
|
||||
next.append(dire->d_name);
|
||||
|
||||
fgShowAircraft(next, false);
|
||||
fgSearchAircraft(next, aircraft, true);
|
||||
}
|
||||
} else if ((ptr = strstr(dire->d_name, "-set.xml")) && (ptr[8] == '\0')) {
|
||||
|
||||
|
@ -1778,14 +1770,26 @@ void fgShowAircraft(const SGPath &path, bool recursive) {
|
|||
}
|
||||
}
|
||||
|
||||
if (recursive) {
|
||||
sort(aircraft.begin(), aircraft.end());
|
||||
cout << "Available aircraft:" << endl;
|
||||
for ( unsigned int i = 0; i < aircraft.size(); i++ ) {
|
||||
cout << aircraft[i] << endl;
|
||||
}
|
||||
|
||||
aircraft.clear();
|
||||
}
|
||||
ulCloseDir(dirp);
|
||||
ulCloseDir(dirp);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Search in the current directory, and in on directory deeper
|
||||
* for <aircraft>-set.xml configuration files and show the aircaft name
|
||||
* and the contents of the<description> tag in a sorted manner.
|
||||
*
|
||||
* @parampath the directory to search for configuration files
|
||||
* @param recursive defines whether the directory should be searched recursively
|
||||
*/
|
||||
void fgShowAircraft(const SGPath &path, bool recursive) {
|
||||
string_list aircraft;
|
||||
|
||||
fgSearchAircraft( path, aircraft, recursive );
|
||||
|
||||
sort(aircraft.begin(), aircraft.end());
|
||||
cout << "Available aircraft:" << endl;
|
||||
for ( unsigned int i = 0; i < aircraft.size(); i++ ) {
|
||||
cout << aircraft[i] << endl;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,6 @@ extern void fgSetDefaults ();
|
|||
extern void fgParseArgs (int argc, char ** argv);
|
||||
extern void fgParseOptions (const string &file_path);
|
||||
extern void fgUsage (bool verbose = false);
|
||||
extern void fgShowAircraft(const SGPath &path, bool recursive = true);
|
||||
extern void fgShowAircraft(const SGPath &path, bool recursive);
|
||||
|
||||
#endif /* _OPTIONS_HXX */
|
||||
|
|
Loading…
Reference in a new issue