Implement save-on-exit configuration flag.
Signed-off-by: mariofutire@gmail.com <pi@raspberrypi>
This commit is contained in:
parent
65effc121d
commit
bc74b5fbfb
4 changed files with 69 additions and 61 deletions
|
@ -5,10 +5,12 @@
|
|||
|
||||
#include <boost/property_tree/ini_parser.hpp>
|
||||
|
||||
class Configuration
|
||||
namespace
|
||||
{
|
||||
class Configuration
|
||||
{
|
||||
public:
|
||||
Configuration(const std::string & filename);
|
||||
Configuration(const std::string & filename, const bool saveOnExit);
|
||||
~Configuration();
|
||||
|
||||
static std::shared_ptr<Configuration> instance;
|
||||
|
@ -23,14 +25,15 @@ class Configuration
|
|||
|
||||
private:
|
||||
const std::string myFilename;
|
||||
bool mySaveOnExit;
|
||||
|
||||
boost::property_tree::ptree myINI;
|
||||
};
|
||||
};
|
||||
|
||||
std::shared_ptr<Configuration> Configuration::instance;
|
||||
std::shared_ptr<Configuration> Configuration::instance;
|
||||
|
||||
Configuration::Configuration(const std::string & filename) : myFilename(filename)
|
||||
{
|
||||
Configuration::Configuration(const std::string & filename, const bool saveOnExit) : myFilename(filename), mySaveOnExit(saveOnExit)
|
||||
{
|
||||
if (GetFileAttributes(myFilename.c_str()) != INVALID_FILE_ATTRIBUTES)
|
||||
{
|
||||
boost::property_tree::ini_parser::read_ini(myFilename, myINI);
|
||||
|
@ -39,36 +42,41 @@ Configuration::Configuration(const std::string & filename) : myFilename(filename
|
|||
{
|
||||
LogFileOutput("Registry: configuration file '%s' not found\n", filename.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Configuration::~Configuration()
|
||||
{
|
||||
Configuration::~Configuration()
|
||||
{
|
||||
if (mySaveOnExit)
|
||||
{
|
||||
boost::property_tree::ini_parser::write_ini(myFilename, myINI);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const boost::property_tree::ptree & Configuration::getProperties() const
|
||||
{
|
||||
const boost::property_tree::ptree & Configuration::getProperties() const
|
||||
{
|
||||
return myINI;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T Configuration::getValue(const std::string & section, const std::string & key) const
|
||||
{
|
||||
template <typename T>
|
||||
T Configuration::getValue(const std::string & section, const std::string & key) const
|
||||
{
|
||||
const std::string path = section + "." + key;
|
||||
const T value = myINI.get<T>(path);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Configuration::putValue(const std::string & section, const std::string & key, const T & value)
|
||||
{
|
||||
template <typename T>
|
||||
void Configuration::putValue(const std::string & section, const std::string & key, const T & value)
|
||||
{
|
||||
const std::string path = section + "." + key;
|
||||
myINI.put(path, value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void InitializeRegistry(const std::string & filename)
|
||||
void InitializeRegistry(const std::string & filename, const bool saveOnExit)
|
||||
{
|
||||
Configuration::instance.reset(new Configuration(filename));
|
||||
Configuration::instance.reset(new Configuration(filename, saveOnExit));
|
||||
}
|
||||
|
||||
BOOL RegLoadString (LPCTSTR section, LPCTSTR key, BOOL peruser,
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <string>
|
||||
|
||||
void InitializeRegistry(const std::string & filename);
|
||||
void InitializeRegistry(const std::string & filename, const bool saveOnExit);
|
||||
|
||||
const boost::property_tree::ptree & getProperties();
|
||||
|
||||
|
|
|
@ -137,7 +137,7 @@ namespace
|
|||
LogInit();
|
||||
}
|
||||
|
||||
InitializeRegistry("applen.conf");
|
||||
InitializeRegistry("applen.conf", options.saveConfigurationOnExit);
|
||||
|
||||
g_nMemoryClearType = options.memclear;
|
||||
|
||||
|
|
|
@ -32,8 +32,6 @@ namespace
|
|||
{
|
||||
void initialiseEmulator()
|
||||
{
|
||||
InitializeRegistry("applen.conf");
|
||||
|
||||
g_fh = fopen("/tmp/applewin.txt", "w");
|
||||
setbuf(g_fh, nullptr);
|
||||
|
||||
|
@ -230,6 +228,8 @@ void run_sdl(int argc, const char * argv [])
|
|||
if (!run)
|
||||
return;
|
||||
|
||||
InitializeRegistry("applen.conf", options.saveConfigurationOnExit);
|
||||
|
||||
initialiseEmulator();
|
||||
loadEmulator();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue