reapack

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

commit 2b95b803865f69f72ccb1a7c1795e66140cb7d8e
parent 418d9ed06ed6772cdd50641393ca24754c1c18a0
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Sat, 18 Jun 2016 18:42:43 -0400

add proxy support

Diffstat:
Msrc/config.cpp | 13+++++++++++--
Msrc/config.hpp | 20++++++++++++++++----
Msrc/download.cpp | 6++++--
Msrc/download.hpp | 6+++++-
Msrc/import.cpp | 3++-
Msrc/index.cpp | 5+++--
Msrc/index.hpp | 3++-
Msrc/reapack.cpp | 11++++-------
Msrc/task.cpp | 4+++-
Msrc/transaction.cpp | 12++++++++----
Msrc/transaction.hpp | 7+++++--
11 files changed, 63 insertions(+), 27 deletions(-)

diff --git a/src/config.cpp b/src/config.cpp @@ -37,6 +37,9 @@ static const auto_char *PRERELEASES_KEY = AUTO_STR("prereleases"); static const auto_char *BROWSER_GRP = AUTO_STR("browser"); static const auto_char *TYPEFILTER_KEY = AUTO_STR("typefilter"); +static const auto_char *DOWNLOAD_GRP = AUTO_STR("download"); +static const auto_char *PROXY_KEY = AUTO_STR("proxy"); + static const auto_char *SIZE_KEY = AUTO_STR("size"); static const auto_char *REMOTES_GRP = AUTO_STR("remotes"); @@ -59,6 +62,7 @@ void Config::resetOptions() { m_install = {false, false}; m_browser = {0}; + m_download = {""}; } void Config::restoreSelfRemote() @@ -131,6 +135,8 @@ void Config::read(const Path &path) m_browser.typeFilter = getUInt(BROWSER_GRP, TYPEFILTER_KEY, m_browser.typeFilter); + m_download.proxy = getString(DOWNLOAD_GRP, PROXY_KEY, m_download.proxy); + readRemotes(); restoreSelfRemote(); migrate(); @@ -145,6 +151,8 @@ void Config::write() setUInt(BROWSER_GRP, TYPEFILTER_KEY, m_browser.typeFilter); + setString(DOWNLOAD_GRP, PROXY_KEY, m_download.proxy); + writeRemotes(); } @@ -173,10 +181,11 @@ void Config::writeRemotes() setUInt(REMOTES_GRP, SIZE_KEY, m_remotesIniSize = i); } -string Config::getString(const auto_char *group, const auto_string &key) const +string Config::getString(const auto_char *group, + const auto_string &key, const string &fallback) const { auto_char buffer[BUFFER_SIZE]; - GetPrivateProfileString(group, key.c_str(), AUTO_STR(""), + GetPrivateProfileString(group, key.c_str(), make_autostring(fallback).c_str(), buffer, sizeof(buffer), m_path.c_str()); return from_autostring(buffer); diff --git a/src/config.hpp b/src/config.hpp @@ -34,6 +34,10 @@ struct BrowserOpts { unsigned int typeFilter; }; +struct DownloadOpts { + std::string proxy; +}; + class Config { public: Config(); @@ -45,15 +49,21 @@ public: void restoreDefaultRemotes(); bool isFirstRun() const { return m_isFirstRun; } - RemoteList *remotes() { return &m_remotes; } InstallOpts *install() { return &m_install; } BrowserOpts *browser() { return &m_browser; } + DownloadOpts *download() { return &m_download; } + RemoteList *remotes() { return &m_remotes; } private: - std::string getString(const auto_char *, const auto_string &) const; - void setString(const auto_char *, const auto_string &, const std::string &) const; - unsigned int getUInt(const auto_char *, const auto_string &, unsigned int = 0) const; + std::string getString(const auto_char *grp, + const auto_string &key, const std::string &fallback = {}) const; + void setString(const auto_char *grp, + const auto_string &key, const std::string &val) 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; + void deleteKey(const auto_char *, const auto_string &) const; void cleanupArray(const auto_char *, const auto_string &, unsigned int begin, unsigned int end) const; @@ -63,8 +73,10 @@ private: auto_string m_path; bool m_isFirstRun; unsigned int m_version; + InstallOpts m_install; BrowserOpts m_browser; + DownloadOpts m_download; void readRemotes(); void restoreSelfRemote(); diff --git a/src/download.cpp b/src/download.cpp @@ -40,8 +40,8 @@ void Download::Cleanup() curl_global_cleanup(); } -Download::Download(const string &name, const string &url) - : m_name(name), m_url(url), m_threadHandle(nullptr) +Download::Download(const string &name, const string &url, const DownloadOpts &opts) + : m_name(name), m_url(url), m_opts(opts), m_threadHandle(nullptr) { reset(); } @@ -108,6 +108,8 @@ DWORD WINAPI Download::Worker(void *ptr) CURL *curl = curl_easy_init(); curl_easy_setopt(curl, CURLOPT_URL, download->url().c_str()); curl_easy_setopt(curl, CURLOPT_USERAGENT, userAgent); + curl_easy_setopt(curl, CURLOPT_PROXY, download->options().proxy.c_str()); + curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1); curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, DOWNLOAD_TIMEOUT); curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, DOWNLOAD_TIMEOUT); diff --git a/src/download.hpp b/src/download.hpp @@ -18,6 +18,8 @@ #ifndef REAPACK_DOWNLOAD_HPP #define REAPACK_DOWNLOAD_HPP +#include "config.hpp" + #include <functional> #include <queue> #include <string> @@ -45,11 +47,12 @@ public: static void Init(); static void Cleanup(); - Download(const std::string &name, const std::string &url); + Download(const std::string &name, const std::string &url, const DownloadOpts &); ~Download(); const std::string &name() const { return m_name; } const std::string &url() const { return m_url; } + const DownloadOpts &options() const { return m_opts; } State state(); const std::string &contents(); @@ -84,6 +87,7 @@ private: std::string m_name; std::string m_url; + DownloadOpts m_opts; WDL_Mutex m_mutex; diff --git a/src/import.cpp b/src/import.cpp @@ -92,7 +92,8 @@ void Import::fetch() setWaiting(true); - Download *dl = m_download = new Download({}, from_autostring(url)); + const DownloadOpts &opts = *m_reapack->config()->download(); + Download *dl = m_download = new Download({}, from_autostring(url), opts); dl->onFinish([=] { const Download::State state = dl->state(); diff --git a/src/index.cpp b/src/index.cpp @@ -92,7 +92,8 @@ IndexPtr Index::load(const string &name, const char *data) return IndexPtr(ri); } -Download *Index::fetch(const Remote &remote, const bool stale) +Download *Index::fetch(const Remote &remote, + const bool stale, const DownloadOpts &opts) { time_t mtime = 0, now = time(nullptr); @@ -103,7 +104,7 @@ Download *Index::fetch(const Remote &remote, const bool stale) return nullptr; } - return new Download(remote.name() + ".xml", remote.url()); + return new Download(remote.name() + ".xml", remote.url(), opts); } Index::Index(const string &name) diff --git a/src/index.hpp b/src/index.hpp @@ -35,6 +35,7 @@ class Index; class Path; class Remote; class TiXmlElement; +struct DownloadOpts; struct Link { std::string name; std::string url; }; @@ -49,7 +50,7 @@ public: static Path pathFor(const std::string &name); static LinkType linkTypeFor(const char *rel); static IndexPtr load(const std::string &name, const char *data = nullptr); - static Download *fetch(const Remote &, bool stale = false); + static Download *fetch(const Remote &, bool stale, const DownloadOpts &); Index(const std::string &name); ~Index(); diff --git a/src/reapack.cpp b/src/reapack.cpp @@ -154,7 +154,7 @@ void ReaPack::synchronizeAll() return; for(const Remote &remote : remotes) - tx->synchronize(remote, *m_config->install()); + tx->synchronize(remote); tx->runTasks(); } @@ -247,10 +247,7 @@ void ReaPack::about(const Remote &remote, HWND parent) enable(remote); - InstallOpts opts = *m_config->install(); - opts.autoInstall = true; - tx->synchronize(remote, opts); - + tx->synchronize(remote, true); tx->runTasks(); } }, parent); @@ -326,7 +323,7 @@ void ReaPack::fetchIndexes(const vector<Remote> &remotes, void ReaPack::doFetchIndex(const Remote &remote, DownloadQueue *queue, HWND parent, const bool stale) { - Download *dl = Index::fetch(remote, stale); + Download *dl = Index::fetch(remote, stale, *m_config->download()); if(!dl) return; @@ -400,7 +397,7 @@ Transaction *ReaPack::setupTransaction() return m_tx; try { - m_tx = new Transaction; + m_tx = new Transaction(m_config); } catch(const reapack_error &e) { const auto_string &desc = make_autostring(e.what()); diff --git a/src/task.cpp b/src/task.cpp @@ -17,6 +17,7 @@ #include "task.hpp" +#include "config.hpp" #include "filesystem.hpp" #include "source.hpp" #include "transaction.hpp" @@ -66,7 +67,8 @@ void InstallTask::doStart() const Path &path = it->first; const Source *src = it->second; - Download *dl = new Download(src->fullName(), src->url()); + const DownloadOpts &opts = *transaction()->config()->download(); + Download *dl = new Download(src->fullName(), src->url(), opts); dl->onFinish(bind(&InstallTask::saveSource, this, dl, src)); transaction()->downloadQueue()->push(dl); diff --git a/src/transaction.cpp b/src/transaction.cpp @@ -31,8 +31,8 @@ using namespace std; -Transaction::Transaction() - : m_isCancelled(false) +Transaction::Transaction(Config *config) + : m_isCancelled(false), m_config(config) { m_registry = new Registry(Path::prefixRoot(Path::REGISTRY)); @@ -70,11 +70,15 @@ Transaction::~Transaction() delete m_registry; } -void Transaction::synchronize(const Remote &remote, const InstallOpts &opts) +void Transaction::synchronize(const Remote &remote, const bool forceAutoInstall) { // show the report dialog or "nothing to do" even if no task are ran m_receipt.setEnabled(true); + InstallOpts opts = *m_config->install(); + if(forceAutoInstall) + opts.autoInstall = true; + fetchIndex(remote, [=] { IndexPtr ri; @@ -125,7 +129,7 @@ void Transaction::fetchIndex(const Remote &remote, const IndexCallback &cb) if(m_remotes.count(name) > 1) return; - Download *dl = Index::fetch(remote, true); + Download *dl = Index::fetch(remote, true, *m_config->download()); if(!dl) { // the index was last downloaded less than a few seconds ago diff --git a/src/transaction.hpp b/src/transaction.hpp @@ -28,6 +28,7 @@ #include <set> #include <unordered_set> +class Config; class Index; class Path; class Remote; @@ -43,13 +44,13 @@ public: typedef boost::signals2::signal<void ()> VoidSignal; typedef std::function<void()> CleanupHandler; - Transaction(); + Transaction(Config *); ~Transaction(); void onFinish(const VoidSignal::slot_type &slot) { m_onFinish.connect(slot); } void setCleanupHandler(const CleanupHandler &cb) { m_cleanupHandler = cb; } - void synchronize(const Remote &, const InstallOpts &); + void synchronize(const Remote &, bool forceAutoInstall = false); void install(const Version *); void setPinned(const Package *, bool pinned); void setPinned(const Registry::Entry &, bool pinned); @@ -63,6 +64,7 @@ public: size_t taskCount() const { return m_tasks.size(); } DownloadQueue *downloadQueue() { return &m_downloadQueue; } + Config *config() { return m_config; } bool saveFile(Download *, const Path &); void addError(const std::string &msg, const std::string &title); @@ -87,6 +89,7 @@ private: void inhibit(const Remote &); bool m_isCancelled; + Config *m_config; Registry *m_registry; Receipt m_receipt;