reapack

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

commit 6c2d587b8a88d2fe2594ffc9df1b45aec43a6c3d
parent c0d4bb9ce9765c49abf9cb898bdc9cde1ad96f79
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Thu,  4 Feb 2016 18:56:14 -0500

download index files before displaying an about dialog for the first time

Diffstat:
Msrc/manager.cpp | 5+++++
Msrc/manager.hpp | 5+++--
Msrc/reapack.cpp | 15+++++++++++++--
Msrc/reapack.hpp | 1+
Msrc/transaction.cpp | 57+++++++++++++++++++++++++++++++++++----------------------
Msrc/transaction.hpp | 8++++++--
6 files changed, 63 insertions(+), 28 deletions(-)

diff --git a/src/manager.cpp b/src/manager.cpp @@ -203,6 +203,11 @@ void Manager::about() // show the pending enable state changes as if they were already applied remote.setEnabled(isRemoteEnabled(remote)); + m_reapack->requireIndex(remote, bind(&Manager::showAbout, this, remote)); +} + +void Manager::showAbout(const Remote &remote) +{ const RemoteIndex *index; try { diff --git a/src/manager.hpp b/src/manager.hpp @@ -40,13 +40,14 @@ protected: void onContextMenu(HWND, int x, int y) override; private: - ListView::Row makeRow(const Remote &remote) const; + ListView::Row makeRow(const Remote &) const; Remote currentRemote() const; void setRemoteEnabled(bool); - bool isRemoteEnabled(const Remote &remote) const; + bool isRemoteEnabled(const Remote &) const; void uninstall(); void about(); + void showAbout(const Remote &); bool confirm() const; void apply(); diff --git a/src/reapack.cpp b/src/reapack.cpp @@ -17,8 +17,9 @@ #include "reapack.hpp" -#include "errors.hpp" #include "config.hpp" +#include "errors.hpp" +#include "index.hpp" #include "manager.hpp" #include "progress.hpp" #include "report.hpp" @@ -137,6 +138,16 @@ void ReaPack::disable(Remote remote) m_transaction->unregisterAll(remote); } +void ReaPack::requireIndex(const Remote &remote, const function<void ()> &cb) +{ + if(file_exists(RemoteIndex::pathFor(remote.name()).join().c_str())) + return cb(); + else if(!hitchhikeTransaction()) + return; + + m_transaction->fetchIndex(remote, cb); +} + void ReaPack::uninstall(const Remote &remote) { if(remote.isProtected()) @@ -259,7 +270,7 @@ Transaction *ReaPack::createTransaction() // hide the progress dialog m_progress->setTransaction(nullptr); - if(m_transaction->isCancelled() || !m_transaction->isReportEnabled()) + if(!m_transaction->isReportEnabled()) return; LockDialog lock(m_manager); diff --git a/src/reapack.hpp b/src/reapack.hpp @@ -50,6 +50,7 @@ public: void synchronizeAll(); void enable(Remote); void disable(Remote); + void requireIndex(const Remote &, const std::function<void ()> &); void uninstall(const Remote &); void importRemote(); void manageRemotes(); diff --git a/src/transaction.cpp b/src/transaction.cpp @@ -56,39 +56,50 @@ Transaction::~Transaction() void Transaction::synchronize(const Remote &remote, const bool isUserAction) { - if(m_remotes.count(remote)) - return; - - Download *dl = new Download(remote.name(), remote.url()); - dl->onFinish(bind(&Transaction::upgradeAll, this, dl)); - - m_downloadQueue.push(dl); - m_remotes.insert(remote); - // show the report dialog even if no task are ran if(isUserAction) m_enableReport = true; + + fetchIndex(remote, [=] { + const RemoteIndex *ri; + + try { + ri = RemoteIndex::load(remote.name()); + m_remoteIndexes.push_back(ri); + } + catch(const reapack_error &e) { + // index file is invalid (load error) + addError(e.what(), remote.name()); + return; + } + + for(const Package *pkg : ri->packages()) + upgrade(pkg); + }); } -void Transaction::upgradeAll(Download *dl) +void Transaction::fetchIndex(const Remote &remote, const IndexCallback &cb) { - if(!saveFile(dl, RemoteIndex::pathFor(dl->name()))) + m_remotes.insert({remote, cb}); + + if(m_remotes.count(remote) > 1) return; - const RemoteIndex *ri; + Download *dl = new Download(remote.name(), remote.url()); + m_downloadQueue.push(dl); - try { - ri = RemoteIndex::load(dl->name()); - m_remoteIndexes.push_back(ri); - } - catch(const reapack_error &e) { - // index file is invalid (load error) - addError(e.what(), dl->url()); + dl->onFinish(bind(&Transaction::saveIndex, this, dl, remote)); +} + +void Transaction::saveIndex(Download *dl, const Remote &remote) +{ + if(!saveFile(dl, RemoteIndex::pathFor(remote.name()))) return; - } - for(const Package *pkg : ri->packages()) - upgrade(pkg); + const auto end = m_remotes.upper_bound(remote); + + for(auto it = m_remotes.lower_bound(remote); it != end; it++) + it->second(); } void Transaction::upgrade(const Package *pkg) @@ -207,6 +218,7 @@ void Transaction::uninstall(const Remote &remote) void Transaction::cancel() { m_isCancelled = true; + m_enableReport = false; for(Task *task : m_tasks) task->rollback(); @@ -260,6 +272,7 @@ void Transaction::finish() void Transaction::addError(const string &message, const string &title) { m_errors.push_back({message, title}); + m_enableReport = true; } bool Transaction::allFilesExists(const set<Path> &list) const diff --git a/src/transaction.hpp b/src/transaction.hpp @@ -23,6 +23,7 @@ #include "registry.hpp" #include <boost/signals2.hpp> +#include <functional> #include <set> class InstallTask; @@ -33,6 +34,8 @@ class Task; class Transaction { public: + typedef std::function<void ()> IndexCallback; + typedef boost::signals2::signal<void ()> Signal; typedef Signal::slot_type Callback; @@ -52,6 +55,7 @@ public: void onFinish(const Callback &callback) { m_onFinish.connect(callback); } void onDestroy(const Callback &callback) { m_onDestroy.connect(callback); } + void fetchIndex(const Remote &, const IndexCallback &cb); void synchronize(const Remote &, bool userAction = true); void uninstall(const Remote &); void registerAll(const Remote &); @@ -76,7 +80,7 @@ private: void install(); void finish(); - void upgradeAll(Download *); + void saveIndex(Download *, const Remote &); void upgrade(const Package *pkg); bool allFilesExists(const std::set<Path> &) const; void addTask(Task *); @@ -88,7 +92,7 @@ private: bool m_enableReport; Registry *m_registry; - std::set<Remote> m_remotes; + std::multimap<Remote, IndexCallback> m_remotes; std::vector<const RemoteIndex *> m_remoteIndexes; DownloadQueue m_downloadQueue; std::queue<InstallTicket> m_installQueue;