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,70 +5,78 @@
|
||||||
|
|
||||||
#include <boost/property_tree/ini_parser.hpp>
|
#include <boost/property_tree/ini_parser.hpp>
|
||||||
|
|
||||||
class Configuration
|
namespace
|
||||||
{
|
{
|
||||||
public:
|
class Configuration
|
||||||
Configuration(const std::string & filename);
|
|
||||||
~Configuration();
|
|
||||||
|
|
||||||
static std::shared_ptr<Configuration> instance;
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
T getValue(const std::string & section, const std::string & key) const;
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
void putValue(const std::string & section, const std::string & key, const T & value);
|
|
||||||
|
|
||||||
const boost::property_tree::ptree & getProperties() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
const std::string myFilename;
|
|
||||||
|
|
||||||
boost::property_tree::ptree myINI;
|
|
||||||
};
|
|
||||||
|
|
||||||
std::shared_ptr<Configuration> Configuration::instance;
|
|
||||||
|
|
||||||
Configuration::Configuration(const std::string & filename) : myFilename(filename)
|
|
||||||
{
|
|
||||||
if (GetFileAttributes(myFilename.c_str()) != INVALID_FILE_ATTRIBUTES)
|
|
||||||
{
|
{
|
||||||
boost::property_tree::ini_parser::read_ini(myFilename, myINI);
|
public:
|
||||||
}
|
Configuration(const std::string & filename, const bool saveOnExit);
|
||||||
else
|
~Configuration();
|
||||||
|
|
||||||
|
static std::shared_ptr<Configuration> instance;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
T getValue(const std::string & section, const std::string & key) const;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void putValue(const std::string & section, const std::string & key, const T & value);
|
||||||
|
|
||||||
|
const boost::property_tree::ptree & getProperties() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
const std::string myFilename;
|
||||||
|
bool mySaveOnExit;
|
||||||
|
|
||||||
|
boost::property_tree::ptree myINI;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::shared_ptr<Configuration> Configuration::instance;
|
||||||
|
|
||||||
|
Configuration::Configuration(const std::string & filename, const bool saveOnExit) : myFilename(filename), mySaveOnExit(saveOnExit)
|
||||||
{
|
{
|
||||||
LogFileOutput("Registry: configuration file '%s' not found\n", filename.c_str());
|
if (GetFileAttributes(myFilename.c_str()) != INVALID_FILE_ATTRIBUTES)
|
||||||
|
{
|
||||||
|
boost::property_tree::ini_parser::read_ini(myFilename, myINI);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LogFileOutput("Registry: configuration file '%s' not found\n", filename.c_str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Configuration::~Configuration()
|
||||||
|
{
|
||||||
|
if (mySaveOnExit)
|
||||||
|
{
|
||||||
|
boost::property_tree::ini_parser::write_ini(myFilename, myINI);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
const std::string path = section + "." + key;
|
||||||
|
myINI.put(path, value);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Configuration::~Configuration()
|
void InitializeRegistry(const std::string & filename, const bool saveOnExit)
|
||||||
{
|
{
|
||||||
boost::property_tree::ini_parser::write_ini(myFilename, myINI);
|
Configuration::instance.reset(new Configuration(filename, saveOnExit));
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
{
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
const std::string path = section + "." + key;
|
|
||||||
myINI.put(path, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
void InitializeRegistry(const std::string & filename)
|
|
||||||
{
|
|
||||||
Configuration::instance.reset(new Configuration(filename));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL RegLoadString (LPCTSTR section, LPCTSTR key, BOOL peruser,
|
BOOL RegLoadString (LPCTSTR section, LPCTSTR key, BOOL peruser,
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include <boost/property_tree/ptree.hpp>
|
#include <boost/property_tree/ptree.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
void InitializeRegistry(const std::string & filename);
|
void InitializeRegistry(const std::string & filename, const bool saveOnExit);
|
||||||
|
|
||||||
const boost::property_tree::ptree & getProperties();
|
const boost::property_tree::ptree & getProperties();
|
||||||
|
|
||||||
|
|
|
@ -137,7 +137,7 @@ namespace
|
||||||
LogInit();
|
LogInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
InitializeRegistry("applen.conf");
|
InitializeRegistry("applen.conf", options.saveConfigurationOnExit);
|
||||||
|
|
||||||
g_nMemoryClearType = options.memclear;
|
g_nMemoryClearType = options.memclear;
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,6 @@ namespace
|
||||||
{
|
{
|
||||||
void initialiseEmulator()
|
void initialiseEmulator()
|
||||||
{
|
{
|
||||||
InitializeRegistry("applen.conf");
|
|
||||||
|
|
||||||
g_fh = fopen("/tmp/applewin.txt", "w");
|
g_fh = fopen("/tmp/applewin.txt", "w");
|
||||||
setbuf(g_fh, nullptr);
|
setbuf(g_fh, nullptr);
|
||||||
|
|
||||||
|
@ -230,6 +228,8 @@ void run_sdl(int argc, const char * argv [])
|
||||||
if (!run)
|
if (!run)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
InitializeRegistry("applen.conf", options.saveConfigurationOnExit);
|
||||||
|
|
||||||
initialiseEmulator();
|
initialiseEmulator();
|
||||||
loadEmulator();
|
loadEmulator();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue