commit ee411e86be8878b7afee04eaad158e22b558f52e
parent d6ccad991ecc7f553573db76c51a441d7b8bb08a
Author: cfillion <cfillion@users.noreply.github.com>
Date: Tue, 7 Jun 2016 16:15:03 -0400
config: better handling of default options
Diffstat:
3 files changed, 20 insertions(+), 15 deletions(-)
diff --git a/src/config.cpp b/src/config.cpp
@@ -50,16 +50,19 @@ static auto_string ArrayKey(const auto_string &key, const unsigned int i)
static const int BUFFER_SIZE = 2083;
Config::Config()
- : m_isFirstRun(false), m_version(0), m_install(), m_browser(),
- m_remotesIniSize(0)
+ : m_isFirstRun(false), m_version(0), m_remotesIniSize(0)
{
+ resetOptions();
}
-void Config::reset()
+void Config::resetOptions()
{
m_install = {false, false};
m_browser = {0};
+}
+void Config::restoreDefaultRemotes()
+{
const vector<pair<string,string> > repos = {
{"ReaTeam Scripts",
"https://github.com/ReaTeam/ReaScripts/raw/master/index.xml"},
@@ -71,8 +74,6 @@ void Config::reset()
"https://github.com/X-Raym/REAPER-ReaScripts/raw/master/index.xml"},
};
- restoreSelfRemote();
-
for(const auto &pair : repos) {
Remote remote = m_remotes.get(pair.first);
@@ -92,7 +93,7 @@ void Config::migrate()
switch(version) {
case 0:
m_isFirstRun = true;
- reset();
+ restoreDefaultRemotes();
break;
default:
// configuration is up-to-date, don't write anything now
@@ -109,16 +110,16 @@ void Config::read(const Path &path)
{
m_path = make_autostring(path.join());
- m_install = {
- getUInt(INSTALL_GRP, AUTOINSTALL_KEY) > 0,
- getUInt(INSTALL_GRP, PRERELEASES_KEY) > 0,
- };
+ m_install.autoInstall = getUInt(INSTALL_GRP,
+ AUTOINSTALL_KEY, m_install.autoInstall) > 0;
+ m_install.bleedingEdge = getUInt(INSTALL_GRP,
+ PRERELEASES_KEY, m_install.bleedingEdge) > 0;
- m_browser = {
- getUInt(BROWSER_GRP, TYPEFILTER_KEY),
- };
+ m_browser.typeFilter = getUInt(BROWSER_GRP,
+ TYPEFILTER_KEY, m_browser.typeFilter);
readRemotes();
+ restoreSelfRemote();
migrate();
}
diff --git a/src/config.hpp b/src/config.hpp
@@ -38,10 +38,12 @@ class Config {
public:
Config();
- void reset();
void read(const Path &);
void write();
+ void resetOptions();
+ void restoreDefaultRemotes();
+
bool isFirstRun() const { return m_isFirstRun; }
RemoteList *remotes() { return &m_remotes; }
InstallOpts *install() { return &m_install; }
@@ -64,6 +66,7 @@ private:
InstallOpts m_install;
BrowserOpts m_browser;
+ void readOption(bool &, const auto_char *, const auto_string &);
void readRemotes();
void restoreSelfRemote();
void writeRemotes();
diff --git a/src/manager.cpp b/src/manager.cpp
@@ -93,7 +93,8 @@ void Manager::onCommand(const int id, int)
toggle(m_bleedingEdge, m_config->install()->bleedingEdge);
break;
case ACTION_RESETCONFIG:
- m_config->reset();
+ m_config->resetOptions();
+ m_config->restoreDefaultRemotes();
refresh();
break;
case ACTION_SELECT: