]> git.mxchange.org Git - flightgear.git/commitdiff
#545 related: User settings not saved when window was closed
authorThorstenB <brehmt@gmail.com>
Thu, 29 Dec 2011 23:39:08 +0000 (00:39 +0100)
committerThorstenB <brehmt@gmail.com>
Thu, 29 Dec 2011 23:39:31 +0000 (00:39 +0100)
via the window buttons instead of pressing ESC or using menu exit.
(More code should be moved after the 2.6 release)

src/Main/fg_commands.cxx
src/Main/fg_init.cxx
src/Main/globals.cxx
src/Main/globals.hxx

index a07739d2ae74352e831ce59ee31ccb3eebdff6f6..2c8c4ed2065d7669e1bf22ca86e5d7a6755ac04c 100644 (file)
@@ -189,22 +189,7 @@ do_exit (const SGPropertyNode * arg)
 {
     SG_LOG(SG_INPUT, SG_INFO, "Program exit requested.");
     fgSetBool("/sim/signals/exit", true);
-
-    if (fgGetBool("/sim/startup/save-on-exit")) {
-      SGPath autosaveFile(fgGetString("/sim/fg-home"));
-      autosaveFile.append( "autosave.xml" );
-      autosaveFile.create_dir( 0700 );
-      SG_LOG(SG_IO, SG_INFO, "Saving user settings to " << autosaveFile.str());
-      try {
-        writeProperties(autosaveFile.str(), globals->get_props(), false, SGPropertyNode::USERARCHIVE);
-      } catch (const sg_exception &e) {
-        guiErrorMessage("Error writing autosave.xml: ", e);
-      }
-      
-      SG_LOG(SG_INPUT, SG_DEBUG, "Finished Saving user settings");
-
-    }
-    
+    globals->saveUserSettings();
     fgOSExit(arg->getIntValue("status", 0));
     return true;
 }
index 807606916fe2dfd61e2b8ef942d0398ce8a5c909..cf08e334c3ae5ff8ef74b613eaaec1a8e1697893 100644 (file)
@@ -561,10 +561,10 @@ bool fgInitConfig ( int argc, char **argv )
             << "(from " << e.getOrigin() << ")");
       }
     }
-  
-  // Scan user config files and command line for a specified aircraft.
+
+    // Scan user config files and command line for a specified aircraft.
     flightgear::Options::sharedInstance()->initAircraft();
-      
+
     FindAndCacheAircraft f(&autosave);
     if (!f.loadAircraft()) {
       return false;
@@ -572,6 +572,10 @@ bool fgInitConfig ( int argc, char **argv )
 
     copyProperties(&autosave, globals->get_props());
 
+    // TODO Move some of the code above into loadUserSettings after the 2.6 release
+    // call dummy function, for now just to indicate that data was loaded
+    globals->loadUserSettings();
+
     // parse options after loading aircraft to ensure any user
     // overrides of defaults are honored.
     flightgear::Options::sharedInstance()->processOptions();
index 4eb26f21f7ec3296239bf04c745bb846a9620b88..8631fa1b07e9fb553e3bc2de83d99d16aa856cb4 100644 (file)
@@ -48,6 +48,7 @@
 #include <Autopilot/route_mgr.hxx>
 #include <Cockpit/panel.hxx>
 #include <GUI/FGFontCache.hxx>
+#include <GUI/gui.h>
 #include <Model/acmodel.hxx>
 #include <Model/modelmgr.hxx>
 #include <MultiPlayer/multiplaymgr.hxx>
@@ -150,17 +151,20 @@ FGGlobals::FGGlobals() :
     dmelist( NULL ),
     tacanlist( NULL ),
     carrierlist( NULL ),
-    channellist( NULL )
+    channellist( NULL ),
+    haveUserSettings(false)
 {
   simgear::ResourceManager::instance()->addProvider(new AircraftResourceProvider());
   simgear::PropertyObjectBase::setDefaultRoot(props);
 }
 
-
 // Destructor
 FGGlobals::~FGGlobals() 
-{    
-// The AIModels manager performs a number of actions upon
+{
+    // save user settings (unless already saved)
+    saveUserSettings();
+
+    // The AIModels manager performs a number of actions upon
     // Shutdown that implicitly assume that other subsystems
     // are still operational (Due to the dynamic allocation and
     // deallocation of AIModel objects. To ensure we can safely
@@ -436,6 +440,41 @@ FGGlobals::restoreInitialState ()
 
 }
 
+// Load user settings from autosave.xml
+void
+FGGlobals::loadUserSettings()
+{
+    // dummy method for now.
+    //TODO Move code loading autosave.xml in here after the 2.6.0 release.
+    haveUserSettings = true;
+}
+
+// Save user settings in autosave.xml
+void
+FGGlobals::saveUserSettings()
+{
+    // only save settings when we have (tried) to load the previous
+    // settings (otherwise user data was lost)
+    if (!haveUserSettings)
+        return;
+
+    if (fgGetBool("/sim/startup/save-on-exit")) {
+      // don't save settings more than once on shutdown
+      haveUserSettings = false;
+
+      SGPath autosaveFile(fgGetString("/sim/fg-home"));
+      autosaveFile.append( "autosave.xml" );
+      autosaveFile.create_dir( 0700 );
+      SG_LOG(SG_IO, SG_INFO, "Saving user settings to " << autosaveFile.str());
+      try {
+        writeProperties(autosaveFile.str(), globals->get_props(), false, SGPropertyNode::USERARCHIVE);
+      } catch (const sg_exception &e) {
+        guiErrorMessage("Error writing autosave.xml: ", e);
+      }
+      SG_LOG(SG_INPUT, SG_DEBUG, "Finished Saving user settings");
+    }
+}
+
 FGViewer *
 FGGlobals::get_current_view () const
 {
index 11dc124dc3129d41983f94233db6275f9ee19501..fd81b0b50e59eca3dcd876df89124e2c7a5cfcef 100644 (file)
@@ -164,6 +164,9 @@ private:
 
     /// roots of Aircraft trees
     string_list fg_aircraft_dirs;
+
+    bool haveUserSettings;
+
 public:
 
     FGGlobals();
@@ -324,6 +327,15 @@ public:
      */
     void restoreInitialState ();
 
+    /**
+     * Load user settings from autosave.xml
+     */
+    void loadUserSettings();
+
+    /**
+     * Save user settings in autosave.xml
+     */
+    void saveUserSettings();
 };