- save pairs of <file>/<path> for each *-set.xml file in autosave.xml
- loop up file name in the cache at startup. If it's found, check if the file exists and use it, otherwise scan $FG_ROOT/Aircraft/ as usual, and create a new cache while doing that. Rebuild cache on FG_ROOT change.
This commit is contained in:
parent
d996d27121
commit
df4f1aa248
1 changed files with 84 additions and 29 deletions
|
@ -506,8 +506,11 @@ do_options (int argc, char ** argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define MAXDEPTH 1
|
static string fgFindAircraftPath( const SGPath &path, const string &aircraft,
|
||||||
static string fgFindAircraftPath( const SGPath &path, const string &aircraft, int depth = 0 ) {
|
SGPropertyNode *cache, int depth = 0 )
|
||||||
|
{
|
||||||
|
const int MAXDEPTH = 1;
|
||||||
|
|
||||||
ulDirEnt* dire;
|
ulDirEnt* dire;
|
||||||
ulDir *dirp = ulOpenDir(path.str().c_str());
|
ulDir *dirp = ulOpenDir(path.str().c_str());
|
||||||
if (dirp == NULL) {
|
if (dirp == NULL) {
|
||||||
|
@ -528,14 +531,35 @@ static string fgFindAircraftPath( const SGPath &path, const string &aircraft, in
|
||||||
SGPath next = path;
|
SGPath next = path;
|
||||||
next.append(dire->d_name);
|
next.append(dire->d_name);
|
||||||
|
|
||||||
result = fgFindAircraftPath( next, aircraft, depth + 1 );
|
result = fgFindAircraftPath( next, aircraft, cache, depth + 1 );
|
||||||
if ( ! result.empty() ) {
|
if ( ! result.empty() )
|
||||||
|
break;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
int len = strlen(dire->d_name);
|
||||||
|
if (len < 9 || strcmp(dire->d_name + len - 8, "-set.xml"))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// create cache node
|
||||||
|
int i = 0;
|
||||||
|
while (1)
|
||||||
|
if (!cache->getChild("aircraft", i++, false))
|
||||||
|
break;
|
||||||
|
|
||||||
|
SGPropertyNode *n, *entry = cache->getChild("aircraft", --i, true);
|
||||||
|
|
||||||
|
n = entry->getNode("file", true);
|
||||||
|
n->setStringValue(dire->d_name);
|
||||||
|
n->setAttribute(SGPropertyNode::USERARCHIVE, true);
|
||||||
|
|
||||||
|
n = entry->getNode("path", true);
|
||||||
|
n->setStringValue(path.str().c_str());
|
||||||
|
n->setAttribute(SGPropertyNode::USERARCHIVE, true);
|
||||||
|
|
||||||
|
if ( !strcmp(dire->d_name, aircraft.c_str()) ) {
|
||||||
|
result = path.str();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if ( !strcmp(dire->d_name, aircraft.c_str()) ) {
|
|
||||||
result = path.str();
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -560,6 +584,30 @@ bool fgInitConfig ( int argc, char **argv ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SGPropertyNode autosave;
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
char *envp = ::getenv( "APPDATA" );
|
||||||
|
if (envp != NULL ) {
|
||||||
|
SGPath config( envp );
|
||||||
|
config.append( "flightgear.org" );
|
||||||
|
#else
|
||||||
|
if ( homedir != NULL ) {
|
||||||
|
SGPath config( homedir );
|
||||||
|
config.append( ".fgfs" );
|
||||||
|
#endif
|
||||||
|
fgSetString("/sim/fg-home", config.c_str());
|
||||||
|
config.append( "autosave.xml" );
|
||||||
|
SG_LOG(SG_INPUT, SG_INFO, "Reading user settings from " << config.str());
|
||||||
|
try {
|
||||||
|
readProperties(config.str(), &autosave, SGPropertyNode::USERARCHIVE);
|
||||||
|
} catch (...) {
|
||||||
|
SG_LOG(SG_INPUT, SG_DEBUG, "First time reading user settings");
|
||||||
|
}
|
||||||
|
SG_LOG(SG_INPUT, SG_DEBUG, "Finished Reading user settings");
|
||||||
|
}
|
||||||
|
SGPropertyNode *cache_root = autosave.getNode("sim/startup/path-cache", true);
|
||||||
|
|
||||||
|
|
||||||
// Scan user config files and command line for a specified aircraft.
|
// Scan user config files and command line for a specified aircraft.
|
||||||
fgInitFGAircraft(argc, argv);
|
fgInitFGAircraft(argc, argv);
|
||||||
|
|
||||||
|
@ -569,8 +617,34 @@ bool fgInitConfig ( int argc, char **argv ) {
|
||||||
aircraft_search.append( "Aircraft" );
|
aircraft_search.append( "Aircraft" );
|
||||||
|
|
||||||
string aircraft_set = aircraft + "-set.xml";
|
string aircraft_set = aircraft + "-set.xml";
|
||||||
|
string result;
|
||||||
|
|
||||||
|
// check if the *-set.xml file is already in the cache
|
||||||
|
if (globals->get_fg_root() == cache_root->getStringValue("fg-root", "")) {
|
||||||
|
vector<SGPropertyNode_ptr> cache = cache_root->getChildren("aircraft");
|
||||||
|
for (unsigned int i = 0; i < cache.size(); i++) {
|
||||||
|
const char *name = cache[i]->getStringValue("file", "");
|
||||||
|
if (aircraft_set == name) {
|
||||||
|
const char *path = cache[i]->getStringValue("path", "");
|
||||||
|
SGPath xml(path);
|
||||||
|
xml.append(name);
|
||||||
|
if (xml.exists())
|
||||||
|
result = path;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.empty()) {
|
||||||
|
// prepare cache for rescan
|
||||||
|
SGPropertyNode *n = cache_root->getNode("fg-root", true);
|
||||||
|
n->setStringValue(globals->get_fg_root().c_str());
|
||||||
|
n->setAttribute(SGPropertyNode::USERARCHIVE, true);
|
||||||
|
cache_root->removeChildren("aircraft");
|
||||||
|
|
||||||
|
result = fgFindAircraftPath( aircraft_search, aircraft_set, cache_root );
|
||||||
|
}
|
||||||
|
|
||||||
string result = fgFindAircraftPath( aircraft_search, aircraft_set );
|
|
||||||
if ( !result.empty() ) {
|
if ( !result.empty() ) {
|
||||||
fgSetString( "/sim/aircraft-dir", result.c_str() );
|
fgSetString( "/sim/aircraft-dir", result.c_str() );
|
||||||
SGPath full_name( result );
|
SGPath full_name( result );
|
||||||
|
@ -596,26 +670,7 @@ bool fgInitConfig ( int argc, char **argv ) {
|
||||||
SG_LOG( SG_INPUT, SG_ALERT, "No default aircraft specified" );
|
SG_LOG( SG_INPUT, SG_ALERT, "No default aircraft specified" );
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
copyProperties(&autosave, globals->get_props());
|
||||||
char *envp = ::getenv( "APPDATA" );
|
|
||||||
if (envp != NULL ) {
|
|
||||||
SGPath config( envp );
|
|
||||||
config.append( "flightgear.org" );
|
|
||||||
#else
|
|
||||||
if ( homedir != NULL ) {
|
|
||||||
SGPath config( homedir );
|
|
||||||
config.append( ".fgfs" );
|
|
||||||
#endif
|
|
||||||
fgSetString("/sim/fg-home", config.c_str());
|
|
||||||
config.append( "autosave.xml" );
|
|
||||||
SG_LOG(SG_INPUT, SG_INFO, "Reading user settings from " << config.str());
|
|
||||||
try {
|
|
||||||
readProperties(config.str(), globals->get_props(), SGPropertyNode::USERARCHIVE);
|
|
||||||
} catch (...) {
|
|
||||||
SG_LOG(SG_INPUT, SG_DEBUG, "First time reading user settings");
|
|
||||||
}
|
|
||||||
SG_LOG(SG_INPUT, SG_DEBUG, "Finished Reading user settings");
|
|
||||||
}
|
|
||||||
|
|
||||||
// parse options after loading aircraft to ensure any user
|
// parse options after loading aircraft to ensure any user
|
||||||
// overrides of defaults are honored.
|
// overrides of defaults are honored.
|
||||||
|
|
Loading…
Reference in a new issue