1
0
Fork 0

#545 related: User settings not saved when window was closed

via the window buttons instead of pressing ESC or using menu exit.
(More code should be moved after the 2.6 release)
This commit is contained in:
ThorstenB 2011-12-30 00:39:08 +01:00
parent 48b4596a5f
commit 229d9273d7
4 changed files with 63 additions and 23 deletions

View file

@ -189,22 +189,7 @@ do_exit (const SGPropertyNode * arg)
{ {
SG_LOG(SG_INPUT, SG_INFO, "Program exit requested."); SG_LOG(SG_INPUT, SG_INFO, "Program exit requested.");
fgSetBool("/sim/signals/exit", true); fgSetBool("/sim/signals/exit", true);
globals->saveUserSettings();
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");
}
fgOSExit(arg->getIntValue("status", 0)); fgOSExit(arg->getIntValue("status", 0));
return true; return true;
} }

View file

@ -572,6 +572,10 @@ bool fgInitConfig ( int argc, char **argv )
copyProperties(&autosave, globals->get_props()); 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 // parse options after loading aircraft to ensure any user
// overrides of defaults are honored. // overrides of defaults are honored.
flightgear::Options::sharedInstance()->processOptions(); flightgear::Options::sharedInstance()->processOptions();

View file

@ -48,6 +48,7 @@
#include <Autopilot/route_mgr.hxx> #include <Autopilot/route_mgr.hxx>
#include <Cockpit/panel.hxx> #include <Cockpit/panel.hxx>
#include <GUI/FGFontCache.hxx> #include <GUI/FGFontCache.hxx>
#include <GUI/gui.h>
#include <Model/acmodel.hxx> #include <Model/acmodel.hxx>
#include <Model/modelmgr.hxx> #include <Model/modelmgr.hxx>
#include <MultiPlayer/multiplaymgr.hxx> #include <MultiPlayer/multiplaymgr.hxx>
@ -150,16 +151,19 @@ FGGlobals::FGGlobals() :
dmelist( NULL ), dmelist( NULL ),
tacanlist( NULL ), tacanlist( NULL ),
carrierlist( NULL ), carrierlist( NULL ),
channellist( NULL ) channellist( NULL ),
haveUserSettings(false)
{ {
simgear::ResourceManager::instance()->addProvider(new AircraftResourceProvider()); simgear::ResourceManager::instance()->addProvider(new AircraftResourceProvider());
simgear::PropertyObjectBase::setDefaultRoot(props); simgear::PropertyObjectBase::setDefaultRoot(props);
} }
// Destructor // Destructor
FGGlobals::~FGGlobals() FGGlobals::~FGGlobals()
{ {
// save user settings (unless already saved)
saveUserSettings();
// The AIModels manager performs a number of actions upon // The AIModels manager performs a number of actions upon
// Shutdown that implicitly assume that other subsystems // Shutdown that implicitly assume that other subsystems
// are still operational (Due to the dynamic allocation and // are still operational (Due to the dynamic allocation and
@ -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 * FGViewer *
FGGlobals::get_current_view () const FGGlobals::get_current_view () const
{ {

View file

@ -164,6 +164,9 @@ private:
/// roots of Aircraft trees /// roots of Aircraft trees
string_list fg_aircraft_dirs; string_list fg_aircraft_dirs;
bool haveUserSettings;
public: public:
FGGlobals(); FGGlobals();
@ -324,6 +327,15 @@ public:
*/ */
void restoreInitialState (); void restoreInitialState ();
/**
* Load user settings from autosave.xml
*/
void loadUserSettings();
/**
* Save user settings in autosave.xml
*/
void saveUserSettings();
}; };