From 3d0254f6ecf6ee759565a37053b48d41680db046 Mon Sep 17 00:00:00 2001 From: James Turner Date: Sun, 16 Oct 2011 21:15:54 +0100 Subject: [PATCH] Allow aircraft-dir option to override aircraft search logic completely. --- src/Main/fg_init.cxx | 23 +++++++++++++++++++++++ src/Main/options.cxx | 7 ++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 3a3bad44f..a504c7cb8 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -338,6 +338,29 @@ public: } _searchAircraft = aircraft + "-set.xml"; + std::string aircraftDir = fgGetString("/sim/aircraft-dir", ""); + if (!aircraftDir.empty()) { + // aircraft-dir was set, skip any searching at all, if it's valid + simgear::Dir acPath(aircraftDir); + SGPath setFile = acPath.file(_searchAircraft); + if (setFile.exists()) { + SG_LOG(SG_GENERAL, SG_INFO, "found aircraft in dir: " << aircraftDir ); + + try { + readProperties(setFile.str(), globals->get_props()); + } catch ( const sg_exception &e ) { + SG_LOG(SG_INPUT, SG_ALERT, "Error reading aircraft: " << e.getFormattedMessage()); + return false; + } + + return true; + } else { + SG_LOG(SG_GENERAL, SG_ALERT, "aircraft '" << _searchAircraft << + "' not found in specified dir:" << aircraftDir); + return false; + } + } + if (!checkCache()) { // prepare cache for re-scan SGPropertyNode *n = _cache->getNode("fg-root", true); diff --git a/src/Main/options.cxx b/src/Main/options.cxx index b76922142..d6ab0b7df 100644 --- a/src/Main/options.cxx +++ b/src/Main/options.cxx @@ -1395,7 +1395,7 @@ struct OptionDesc { {"fg-aircraft", true, OPTION_IGNORE | OPTION_MULTI, "", false, "", 0 }, {"fdm", true, OPTION_STRING, "/sim/flight-model", false, "", 0 }, {"aero", true, OPTION_STRING, "/sim/aero", false, "", 0 }, - {"aircraft-dir", true, OPTION_STRING, "/sim/aircraft-dir", false, "", 0 }, + {"aircraft-dir", true, OPTION_IGNORE, "", false, "", 0 }, {"model-hz", true, OPTION_INT, "/sim/model-hz", false, "", 0 }, {"speed", true, OPTION_INT, "/sim/speed-up", false, "", 0 }, {"trim", false, OPTION_BOOL, "/sim/presets/trim", true, "", 0 }, @@ -1764,6 +1764,11 @@ void Options::initAircraft() fgShowAircraft(path); exit(0); } + + if (isOptionSet("aircraft-dir")) { + // set this now, so it's available in FindAndCacheAircraft + fgSetString("/sim/aircraft-dir", valueForOption("aircraft-dir")); + } } void Options::processArgResult(int result)