]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/fg_init.cxx
Goodbye automake.
[flightgear.git] / src / Main / fg_init.cxx
index e402167c139520fb993e6e52a2e90a30a363de35..ad85151c3831082c88616258ea51238a1f82ccaa 100644 (file)
@@ -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);
@@ -451,10 +474,68 @@ private:
   SGPropertyNode* _cache;
 };
 
-// Read in configuration (file and command line)
-bool fgInitConfig ( int argc, char **argv ) {
+#ifdef _WIN32
+static SGPath platformDefaultDataPath()
+{
+  char *envp = ::getenv( "APPDATA" );
+  SGPath config( envp );
+  config.append( "flightgear.org" );
+  return config;
+}
+#elif __APPLE__
 
-    flightgear::Options::sharedInstance()->init(argc, argv);
+#include <CoreServices/CoreServices.h>
+
+static SGPath platformDefaultDataPath()
+{
+  FSRef ref;
+  OSErr err = FSFindFolder(kUserDomain, kApplicationSupportFolderType, false, &ref);
+  if (err) {
+    return SGPath();
+  }
+  
+  unsigned char path[1024];
+  if (FSRefMakePath(&ref, path, 1024) != noErr) {
+    return SGPath();
+  }
+  
+  SGPath appData;
+  appData.set((const char*) path);
+  appData.append("flightgear.org");
+  return appData;
+}
+#else
+static SGPath platformDefaultDataPath()
+{
+  SGPath config( homedir );
+  config.append( ".fgfs" );
+  return config;
+}
+#endif
+
+// Read in configuration (file and command line)
+bool fgInitConfig ( int argc, char **argv )
+{
+    SGPath dataPath = platformDefaultDataPath();
+    
+    const char *fg_home = getenv("FG_HOME");
+    if (fg_home)
+      dataPath = fg_home;
+    
+    simgear::Dir exportDir(simgear::Dir(dataPath).file("Export"));
+    if (!exportDir.exists()) {
+      exportDir.create(0777);
+    }
+    
+    // Set /sim/fg-home and don't allow malign code to override it until
+    // Nasal security is set up.  Use FG_HOME if necessary.
+    SGPropertyNode *home = fgGetNode("/sim", true);
+    home->removeChild("fg-home", 0, false);
+    home = home->getChild("fg-home", 0, true);
+    home->setStringValue(dataPath.c_str());
+    home->setAttribute(SGPropertyNode::WRITE, false);
+  
+    flightgear::Options::sharedInstance()->init(argc, argv, dataPath);
   
     // Read global preferences from $FG_ROOT/preferences.xml
     SG_LOG(SG_INPUT, SG_INFO, "Reading global preferences");
@@ -467,44 +548,19 @@ bool fgInitConfig ( int argc, char **argv ) {
     }
 
     SGPropertyNode autosave;
-#ifdef _WIN32
-    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
-        const char *fg_home = getenv("FG_HOME");
-        if (fg_home)
-            config = fg_home;
-
-        SGPath home_export(config.str());
-        home_export.append("Export/dummy");
-        home_export.create_dir(0777);
-
-        // Set /sim/fg-home and don't allow malign code to override it until
-        // Nasal security is set up.  Use FG_HOME if necessary.
-        SGPropertyNode *home = fgGetNode("/sim", true);
-        home->removeChild("fg-home", 0, false);
-        home = home->getChild("fg-home", 0, true);
-        home->setStringValue(config.c_str());
-        home->setAttribute(SGPropertyNode::WRITE, false);
-
-        config.append( "autosave.xml" );
-        if (config.exists()) {
-          SG_LOG(SG_INPUT, SG_INFO, "Reading user settings from " << config.str());
-          try {
-              readProperties(config.str(), &autosave, SGPropertyNode::USERARCHIVE);
-          } catch (sg_exception& e) {
-              SG_LOG(SG_INPUT, SG_WARN, "failed to read user settings:" << e.getMessage()
-                << "(from " << e.getOrigin() << ")");
-          }
-        }
+
+
+    SGPath autosaveFile = simgear::Dir(dataPath).file("autosave.xml");
+    if (autosaveFile.exists()) {
+      SG_LOG(SG_INPUT, SG_INFO, "Reading user settings from " << autosaveFile.str());
+      try {
+          readProperties(autosaveFile.str(), &autosave, SGPropertyNode::USERARCHIVE);
+      } catch (sg_exception& e) {
+          SG_LOG(SG_INPUT, SG_WARN, "failed to read user settings:" << e.getMessage()
+            << "(from " << e.getOrigin() << ")");
+      }
     }
-    
+  
   // Scan user config files and command line for a specified aircraft.
     flightgear::Options::sharedInstance()->initAircraft();