reapack

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

commit 244032c8ce7008ad08ee2bbe1c87a4d2fc5cd504
parent d47bc03ef174e450dc9fcab42f497e139c215dcb
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Mon, 15 Feb 2016 15:44:17 -0500

fix script registration upon initial installation

was broken since a42cb15f86eac60b2603510451bd7a81d912ee7e

Diffstat:
Msrc/reapack.cpp | 2+-
Msrc/transaction.cpp | 40+++++++++++++++++++++++++++-------------
Msrc/transaction.hpp | 8++++----
3 files changed, 32 insertions(+), 18 deletions(-)

diff --git a/src/reapack.cpp b/src/reapack.cpp @@ -300,7 +300,7 @@ Transaction *ReaPack::createTransaction() } try { - m_transaction = new Transaction(m_config->remotes()); + m_transaction = new Transaction; } catch(const reapack_error &e) { ShowMessageBox(e.what(), "ReaPack – Fatal Error", 0); diff --git a/src/transaction.cpp b/src/transaction.cpp @@ -30,9 +30,8 @@ using namespace std; -Transaction::Transaction(const RemoteList *rl) - : m_remoteList(rl), m_isCancelled(false), - m_enableReport(false), m_needRestart(false) +Transaction::Transaction() + : m_isCancelled(false), m_enableReport(false), m_needRestart(false) { m_registry = new Registry(Path::prefixCache("registry.db")); @@ -90,25 +89,27 @@ void Transaction::synchronize(const Remote &remote, const bool isUserAction) void Transaction::fetchIndex(const Remote &remote, const IndexCallback &cb) { - m_remotes.insert({remote, cb}); + // add the callback to the list, and start the download if it's the first one + const std::string &name = remote.name(); + m_remotes.insert({name, cb}); - if(m_remotes.count(remote) > 1) + if(m_remotes.count(name) > 1) return; - Download *dl = new Download(remote.name(), remote.url()); + Download *dl = new Download(name, remote.url()); m_downloadQueue.push(dl); - dl->onFinish(bind(&Transaction::saveIndex, this, dl, remote)); + dl->onFinish(bind(&Transaction::saveIndex, this, dl, name)); } -void Transaction::saveIndex(Download *dl, const Remote &remote) +void Transaction::saveIndex(Download *dl, const string &name) { - if(!saveFile(dl, RemoteIndex::pathFor(remote.name()))) + if(!saveFile(dl, RemoteIndex::pathFor(name))) return; - const auto end = m_remotes.upper_bound(remote); + const auto end = m_remotes.upper_bound(name); - for(auto it = m_remotes.lower_bound(remote); it != end; it++) + for(auto it = m_remotes.lower_bound(name); it != end; it++) it->second(); } @@ -201,10 +202,13 @@ void Transaction::unregisterAll(const Remote &remote) for(const auto &entry : entries) registerInHost(false, entry); + + inhibit(remote); } void Transaction::uninstall(const Remote &remote) { + inhibit(remote); remove(RemoteIndex::pathFor(remote.name()).join().c_str()); const vector<Registry::Entry> &entries = m_registry->getEntries(remote); @@ -337,8 +341,7 @@ void Transaction::registerQueued() const HostRegistration &reg = m_regQueue.front(); // don't register in host if the remote got disabled meanwhile - const Remote &remote = m_remoteList->get(reg.entry.remote); - if(reg.add && (remote.isNull() || !remote.isEnabled())) { + if(reg.add && m_remotes.count(reg.entry.remote) == 0) { m_regQueue.pop(); return; } @@ -377,3 +380,14 @@ void Transaction::registerScript(const HostRegistration &reg) if(!AddRemoveReaScript(reg.add, section, path.c_str(), isLast) && reg.add) addError("Script could not be registered in REAPER.", reg.file); } + +void Transaction::inhibit(const Remote &remote) +{ + // prevents index post-download callbacks from being called + // AND prevents files from this remote from being registered in REAPER + // (UNregistering is not affected) + + const auto it = m_remotes.find(remote.name()); + if(it != m_remotes.end()) + m_remotes.erase(it); +} diff --git a/src/transaction.hpp b/src/transaction.hpp @@ -50,7 +50,7 @@ public: typedef std::vector<const Error> ErrorList; - Transaction(const RemoteList *); + Transaction(); ~Transaction(); void onFinish(const Callback &callback) { m_onFinish.connect(callback); } @@ -85,7 +85,7 @@ private: void installTicket(const InstallTicket &); void finish(); - void saveIndex(Download *, const Remote &); + void saveIndex(Download *, const std::string &remoteName); void upgrade(const Package *pkg); bool allFilesExists(const std::set<Path> &) const; void addTask(Task *); @@ -93,14 +93,14 @@ private: void registerInHost(bool add, const Registry::Entry &); void registerQueued(); void registerScript(const HostRegistration &); + void inhibit(const Remote &); - const RemoteList *m_remoteList; bool m_isCancelled; bool m_enableReport; bool m_needRestart; Registry *m_registry; - std::multimap<Remote, IndexCallback> m_remotes; + std::multimap<std::string, IndexCallback> m_remotes; std::vector<const RemoteIndex *> m_remoteIndexes; std::vector<Task *> m_tasks;