X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FMain%2Fglobals.cxx;h=8631fa1b07e9fb553e3bc2de83d99d16aa856cb4;hb=229d9273d7a53cfa6a32dd1d3da73ac1d080cfa2;hp=4eb26f21f7ec3296239bf04c745bb846a9620b88;hpb=48b4596a5f0f61a73e1a12ea8739a85612416301;p=flightgear.git diff --git a/src/Main/globals.cxx b/src/Main/globals.cxx index 4eb26f21f..8631fa1b0 100644 --- a/src/Main/globals.cxx +++ b/src/Main/globals.cxx @@ -48,6 +48,7 @@ #include #include #include +#include #include #include #include @@ -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 {