reapack

Package manager for REAPER
Log | Files | Refs | Submodules | README | LICENSE

commit d76063238ff570926d1d79ec7e63ba5abf5b8d0d
parent d6ae46c3a2b218f79b378d966d88b139c723746f
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Tue,  6 Jun 2017 04:06:55 -0400

config: add setting for the cache refresh threshold

offline user should disable this setting for a better experience

Diffstat:
Msrc/config.cpp | 28+++++++++++++++++-----------
Msrc/config.hpp | 8++++++++
Msrc/dialog.cpp | 10++++++++++
Msrc/dialog.hpp | 2++
Msrc/manager.cpp | 10+++++++---
Msrc/manager.hpp | 1+
Msrc/obsquery.cpp | 4++--
Msrc/resource.hpp | 3++-
Msrc/resource.rc | 10++++++----
Msrc/transaction.cpp | 5++---
10 files changed, 57 insertions(+), 24 deletions(-)

diff --git a/src/config.cpp b/src/config.cpp @@ -45,6 +45,7 @@ static const auto_char *STATE_KEY = AUTO_STR("state"); static const auto_char *NETWORK_GRP = AUTO_STR("network"); static const auto_char *PROXY_KEY = AUTO_STR("proxy"); static const auto_char *VERIFYPEER_KEY = AUTO_STR("verifypeer"); +static const auto_char *STALETHRSH_KEY = AUTO_STR("stalethreshold"); static const auto_char *SIZE_KEY = AUTO_STR("size"); @@ -68,7 +69,7 @@ void Config::resetOptions() { browser = {true}; install = {false, false, true}; - network = {"", true}; + network = {"", true, NetworkOpts::OneWeekThreshold}; windowState = {}; } @@ -136,19 +137,17 @@ void Config::read(const Path &path) { m_path = make_autostring(path.join()); - install.autoInstall = getUInt(INSTALL_GRP, - AUTOINSTALL_KEY, install.autoInstall) > 0; - install.bleedingEdge = getUInt(INSTALL_GRP, - PRERELEASES_KEY, install.bleedingEdge) > 0; - install.promptObsolete = getUInt(INSTALL_GRP, - PROMPTOBSOLETE_KEY, install.promptObsolete) > 0; + install.autoInstall = getBool(INSTALL_GRP, AUTOINSTALL_KEY, install.autoInstall); + install.bleedingEdge = getBool(INSTALL_GRP, PRERELEASES_KEY, install.bleedingEdge); + install.promptObsolete = getBool(INSTALL_GRP, + PROMPTOBSOLETE_KEY, install.promptObsolete); - browser.showDescs = getUInt(BROWSER_GRP, - SHOWDESCS_KEY, browser.showDescs) > 0; + browser.showDescs = getBool(BROWSER_GRP, SHOWDESCS_KEY, browser.showDescs); network.proxy = getString(NETWORK_GRP, PROXY_KEY, network.proxy); - network.verifyPeer = getUInt(NETWORK_GRP, - VERIFYPEER_KEY, network.verifyPeer) > 0; + network.verifyPeer = getBool(NETWORK_GRP, VERIFYPEER_KEY, network.verifyPeer); + network.staleThreshold = (time_t)getUInt(NETWORK_GRP, + STALETHRSH_KEY, (unsigned int)network.staleThreshold); windowState.about = getString(ABOUT_GRP, STATE_KEY, windowState.about); windowState.browser = getString(BROWSER_GRP, STATE_KEY, windowState.browser); @@ -171,6 +170,7 @@ void Config::write() setString(NETWORK_GRP, PROXY_KEY, network.proxy); setUInt(NETWORK_GRP, VERIFYPEER_KEY, network.verifyPeer); + setUInt(NETWORK_GRP, STALETHRSH_KEY, (unsigned int)network.staleThreshold); setString(ABOUT_GRP, STATE_KEY, windowState.about); setString(BROWSER_GRP, STATE_KEY, windowState.browser); @@ -227,6 +227,12 @@ unsigned int Config::getUInt(const auto_char *group, return GetPrivateProfileInt(group, key.c_str(), fallback, m_path.c_str()); } +bool Config::getBool(const auto_char *group, + const auto_string &key, const bool fallback) const +{ + return getUInt(group, key, fallback) > 0; +} + void Config::setUInt(const auto_char *group, const auto_string &key, const unsigned int val) const { diff --git a/src/config.hpp b/src/config.hpp @@ -42,8 +42,14 @@ struct InstallOpts { }; struct NetworkOpts { + enum StaleThreshold { + NoThreshold = 0, + OneWeekThreshold = 7 * 24 * 3600, + }; + std::string proxy; bool verifyPeer; + time_t staleThreshold; }; class Config { @@ -71,6 +77,8 @@ private: void setString(const auto_char *grp, const auto_string &key, const std::string &val) const; + bool getBool(const auto_char *grp, + const auto_string &key, bool fallback = false) const; unsigned int getUInt(const auto_char *grp, const auto_string &key, unsigned int fallback = 0) const; void setUInt(const auto_char *, const auto_string &, unsigned int) const; diff --git a/src/dialog.cpp b/src/dialog.cpp @@ -296,6 +296,16 @@ void Dialog::setEnabled(const bool enabled, HWND handle) EnableWindow(handle, enabled); } +bool Dialog::isChecked(HWND handle) const +{ + return SendMessage(handle, BM_GETCHECK, 0, 0) == BST_CHECKED; +} + +void Dialog::setChecked(const bool checked, HWND handle) +{ + SendMessage(handle, BM_SETCHECK, checked ? BST_CHECKED : BST_UNCHECKED, 0); +} + int Dialog::startTimer(const int ms, int id, const bool replace) { if(id == 0) { diff --git a/src/dialog.hpp b/src/dialog.hpp @@ -85,6 +85,8 @@ public: void disable(HWND handle) { setEnabled(false, handle); } void setEnabled(bool enable) { setEnabled(enable, m_handle); } void setEnabled(bool, HWND); + bool isChecked(HWND) const; + void setChecked(bool, HWND); bool isVisible() const; void show(HWND handle = nullptr) { setVisible(true, handle); } diff --git a/src/manager.cpp b/src/manager.cpp @@ -744,8 +744,10 @@ void NetworkConfig::onInit() SetWindowText(m_proxy, make_autostring(m_opts->proxy).c_str()); m_verifyPeer = getControl(IDC_VERIFYPEER); - SendMessage(m_verifyPeer, BM_SETCHECK, - m_opts->verifyPeer ? BST_CHECKED : BST_UNCHECKED, 0); + setChecked(m_opts->verifyPeer, m_verifyPeer); + + m_staleThreshold = getControl(IDC_STALETHRSH); + setChecked(m_opts->staleThreshold > 0, m_staleThreshold); } void NetworkConfig::onCommand(const int id, int) @@ -763,5 +765,7 @@ void NetworkConfig::onCommand(const int id, int) void NetworkConfig::apply() { m_opts->proxy = getText(m_proxy); - m_opts->verifyPeer = SendMessage(m_verifyPeer, BM_GETCHECK, 0, 0) == BST_CHECKED; + m_opts->verifyPeer = isChecked(m_verifyPeer); + m_opts->staleThreshold = isChecked(m_staleThreshold) + ? NetworkOpts::OneWeekThreshold : NetworkOpts::NoThreshold; } diff --git a/src/manager.hpp b/src/manager.hpp @@ -111,6 +111,7 @@ private: NetworkOpts *m_opts; HWND m_proxy; + HWND m_staleThreshold; HWND m_verifyPeer; }; diff --git a/src/obsquery.cpp b/src/obsquery.cpp @@ -61,7 +61,7 @@ void ObsoleteQuery::onInit() m_list->autoSizeHeader(); - SendMessage(m_enableCtrl, BM_SETCHECK, BST_CHECKED, 0); + setChecked(true, m_enableCtrl); disable(m_okBtn); } @@ -73,7 +73,7 @@ void ObsoleteQuery::onCommand(const int id, int event) prepare(); break; case IDC_ENABLE: - *m_enable = SendMessage(m_enableCtrl, BM_GETCHECK, 0, 0) == BST_CHECKED; + *m_enable = isChecked(m_enableCtrl); break; case ACTION_SELECT_ALL: m_list->selectAll(); diff --git a/src/resource.hpp b/src/resource.hpp @@ -41,7 +41,7 @@ #define IDD_IMPORT_DIALOG 104 #define IDD_BROWSER_DIALOG 105 #define IDD_NETCONF_DIALOG 106 -#define IDD_OBSQUERY_DIALOG 107 +#define IDD_OBSQUERY_DIALOG 107 #define IDC_LABEL 200 #define IDC_LABEL2 201 @@ -71,5 +71,6 @@ #define IDC_ENABLE 232 #define IDC_CHANGELOG 233 #define IDC_DISCOVER 234 +#define IDC_STALETHRSH 235 #endif diff --git a/src/resource.rc b/src/resource.rc @@ -106,7 +106,7 @@ BEGIN PUSHBUTTON "&Apply", IDAPPLY, 455, 231, 40, 14 END -IDD_NETCONF_DIALOG DIALOGEX 0, 0, 220, 69 +IDD_NETCONF_DIALOG DIALOGEX 0, 0, 220, 80 STYLE DIALOG_STYLE FONT DIALOG_FONT CAPTION "ReaPack: Network Settings" @@ -115,10 +115,12 @@ BEGIN EDITTEXT IDC_PROXY, 30, 5, 185, 14, ES_AUTOHSCROLL LTEXT "Example: host:port, [ipv6]:port or scheme://host:port", IDC_LABEL2, 30, 22, 190, 10 + CHECKBOX "&Refresh index cache when older than one week", + IDC_STALETHRSH, 5, 33, 220, 14, BS_AUTOCHECKBOX | WS_TABSTOP CHECKBOX "&Verify the authenticity of SSL/TLS certificates (advanced)", - IDC_VERIFYPEER, 5, 33, 220, 14, BS_AUTOCHECKBOX | WS_TABSTOP - DEFPUSHBUTTON "&OK", IDOK, 132, 50, 40, 14 - PUSHBUTTON "&Cancel", IDCANCEL, 175, 50, 40, 14 + IDC_VERIFYPEER, 5, 45, 220, 14, BS_AUTOCHECKBOX | WS_TABSTOP + DEFPUSHBUTTON "&OK", IDOK, 132, 61, 40, 14 + PUSHBUTTON "&Cancel", IDCANCEL, 175, 61, 40, 14 END IDD_OBSQUERY_DIALOG DIALOGEX 0, 0, 350, 200 diff --git a/src/transaction.cpp b/src/transaction.cpp @@ -30,8 +30,6 @@ using namespace std; -static const time_t STALE_THRESHOLD = 7 * 24 * 3600; - Transaction::Transaction(Config *config) : m_isCancelled(false), m_config(config), m_registry(Path::prefixRoot(Path::REGISTRY)) @@ -139,7 +137,8 @@ void Transaction::fetchIndex(const Remote &remote, const bool stale, time_t mtime = 0, now = time(nullptr); FS::mtime(path, &mtime); - if(!stale && mtime > now - STALE_THRESHOLD) { + const time_t threshold = m_config->network.staleThreshold; + if(!stale && mtime && (!threshold || mtime > now - threshold)) { load(); return; }