From f6174d2bf0eec7b931073c01283441d08b77108c Mon Sep 17 00:00:00 2001 From: ehofman Date: Sat, 17 Dec 2005 15:34:37 +0000 Subject: [PATCH] Stefan Seifert: implement persistent dialog options, so changes in rendering, static LOD and sound settings dialogs are made permanent. --- src/Main/fg_commands.cxx | 23 ++++++++++++++++++++--- src/Main/fg_init.cxx | 12 ++++++++++++ src/Main/fg_props.cxx | 4 ++-- src/Main/fg_props.hxx | 2 +- 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/Main/fg_commands.cxx b/src/Main/fg_commands.cxx index 21a5b7d2a..a23b5355e 100644 --- a/src/Main/fg_commands.cxx +++ b/src/Main/fg_commands.cxx @@ -189,9 +189,26 @@ do_nasal (const SGPropertyNode * arg) static bool do_exit (const SGPropertyNode * arg) { - SG_LOG(SG_INPUT, SG_INFO, "Program exit requested."); - fgExit(arg->getIntValue("status", 0)); - return true; + SG_LOG(SG_INPUT, SG_INFO, "Program exit requested."); + + char* envp = ::getenv( "HOME" ); + if ( envp != NULL ) { + SGPath config( globals->get_fg_root() ); + config.set( envp ); + config.append( ".fgfs" ); + config.append( "preferences.xml" ); + config.create_dir( 0700 ); + SG_LOG(SG_IO, SG_INFO, "Saving user preferences"); + try { + writeProperties(config.str(), globals->get_props(), false, SGPropertyNode::USERARCHIVE); + } catch (const sg_exception &e) { + guiErrorMessage("Error saving preferences: ", e); + } + + SG_LOG(SG_INPUT, SG_BULK, "Finished Saving user preferences"); + } + fgExit(arg->getIntValue("status", 0)); + return true; } diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 14660cd45..e1bb2e565 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -607,6 +607,18 @@ bool fgInitConfig ( int argc, char **argv ) { SG_LOG( SG_INPUT, SG_ALERT, "No default aircraft specified" ); } + + char* envp = ::getenv( "HOME" ); + if ( envp != NULL ) { + SGPath config( globals->get_fg_root() ); + config.set( envp ); + config.append( ".fgfs" ); + config.append( "preferences.xml" ); + SG_LOG(SG_INPUT, SG_INFO, "Reading user preferences"); + fgLoadProps(config.str().c_str(), globals->get_props(), false, SGPropertyNode::USERARCHIVE); + SG_LOG(SG_INPUT, SG_BULK, "Finished Reading user preferences"); + } + // parse options after loading aircraft to ensure any user // overrides of defaults are honored. do_options(argc, argv); diff --git a/src/Main/fg_props.cxx b/src/Main/fg_props.cxx index 4e3c9a3d4..9c32d1d11 100644 --- a/src/Main/fg_props.cxx +++ b/src/Main/fg_props.cxx @@ -585,7 +585,7 @@ fgLoadFlight (istream &input) bool -fgLoadProps (const char * path, SGPropertyNode * props, bool in_fg_root) +fgLoadProps (const char * path, SGPropertyNode * props, bool in_fg_root, int default_mode) { string fullpath; if (in_fg_root) { @@ -597,7 +597,7 @@ fgLoadProps (const char * path, SGPropertyNode * props, bool in_fg_root) } try { - readProperties(fullpath, props); + readProperties(fullpath, props, default_mode); } catch (const sg_exception &e) { guiErrorMessage("Error reading properties: ", e); return false; diff --git a/src/Main/fg_props.hxx b/src/Main/fg_props.hxx index 8a53147c7..a6faf0b1e 100644 --- a/src/Main/fg_props.hxx +++ b/src/Main/fg_props.hxx @@ -69,7 +69,7 @@ extern bool fgLoadFlight (istream &input); * otherwise. */ extern bool fgLoadProps (const char * path, SGPropertyNode * props, - bool in_fg_root = true); + bool in_fg_root = true, int default_mode = 0); -- 2.39.5