reapack

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

commit c264a7c4ad951aa9657d60f4500be8e52a5984a7
parent b08e4d990bb616cd45be8c9b6f30521cb649f7f1
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Mon, 25 Jan 2016 18:45:36 -0500

prepare for script (un)registration

Diffstat:
Msrc/manager.cpp | 7+++----
Msrc/reapack.cpp | 42+++++++++++++++++++++++++++++-------------
Msrc/reapack.hpp | 5++++-
Msrc/registry.cpp | 19-------------------
Msrc/registry.hpp | 2--
Msrc/transaction.cpp | 8++++++++
Msrc/transaction.hpp | 2++
7 files changed, 46 insertions(+), 39 deletions(-)

diff --git a/src/manager.cpp b/src/manager.cpp @@ -210,12 +210,11 @@ void Manager::apply() m_reapack->disable(remote); } - for(auto it = m_uninstall.begin(); it != m_uninstall.end(); it++) { - const Remote &remote = *it; - m_reapack->uninstall(remote, next(it) == m_uninstall.end()); - } + for(const Remote &remote : m_uninstall) + m_reapack->uninstall(remote); m_reapack->config()->write(); + m_reapack->runTasks(); } void Manager::reset() diff --git a/src/reapack.cpp b/src/reapack.cpp @@ -112,10 +112,7 @@ void ReaPack::synchronizeAll() void ReaPack::synchronize(const Remote &remote) { - if(!m_transaction) { - if(!createTransaction()) - return; - } + hitchhikeTransaction(); // hitchhike currently running transactions m_transaction->synchronize(remote); @@ -126,30 +123,34 @@ void ReaPack::enable(Remote remote) remote.setEnabled(true); m_config->remotes()->add(remote); - synchronize(remote); + if(!hitchhikeTransaction()) + return; + + m_transaction->registerAll(remote); + m_transaction->synchronize(remote); } void ReaPack::disable(Remote remote) { remote.setEnabled(false); m_config->remotes()->add(remote); + + if(!hitchhikeTransaction()) + return; + + m_transaction->unregisterAll(remote); } -void ReaPack::uninstall(const Remote &remote, const bool start) +void ReaPack::uninstall(const Remote &remote) { if(remote.isProtected()) return; - if(!m_transaction) { - if(!createTransaction()) - return; - } + if(!hitchhikeTransaction()) + return; m_transaction->uninstall(remote); m_config->remotes()->remove(remote); - - if(start) - m_transaction->runTasks(); } void ReaPack::importRemote() @@ -274,3 +275,18 @@ Transaction *ReaPack::createTransaction() return m_transaction; } + +bool ReaPack::hitchhikeTransaction() +{ + if(m_transaction) + return true; + else + return createTransaction() != nullptr; +} + + +void ReaPack::runTasks() +{ + if(m_transaction) + m_transaction->runTasks(); +} diff --git a/src/reapack.hpp b/src/reapack.hpp @@ -49,14 +49,17 @@ public: void synchronize(const Remote &); void enable(Remote); void disable(Remote); - void uninstall(const Remote &, const bool start = true); + void uninstall(const Remote &); void importRemote(); void manageRemotes(); + void runTasks(); + Config *config() const { return m_config; } private: Transaction *createTransaction(); + bool hitchhikeTransaction(); std::map<int, ActionCallback> m_actions; diff --git a/src/registry.cpp b/src/registry.cpp @@ -221,22 +221,3 @@ void Registry::commit() { m_db.commit(); } - -bool Registry::addToREAPER(Version *ver, const Path &root) -{ - if(ver->package()->type() != Package::ScriptType) - return false; - - Source *src = ver->mainSource(); - - if(!src) - return false; - - enum { MainSection = 0 }; - const string &path = (root + src->targetPath()).join(); - - custom_action_register_t ca{MainSection, nullptr, path.c_str()}; - const int id = plugin_register("custom_action", (void *)&ca); - - return id > 0; -} diff --git a/src/registry.hpp b/src/registry.hpp @@ -53,8 +53,6 @@ public: void forget(const Entry &); void commit(); - bool addToREAPER(Version *ver, const Path &root); - private: void migrate(); diff --git a/src/transaction.cpp b/src/transaction.cpp @@ -149,6 +149,14 @@ void Transaction::install() runTasks(); } +void Transaction::registerAll(const Remote &) +{ +} + +void Transaction::unregisterAll(const Remote &) +{ +} + void Transaction::uninstall(const Remote &remote) { const vector<Registry::Entry> &entries = m_registry->queryAll(remote); diff --git a/src/transaction.hpp b/src/transaction.hpp @@ -54,6 +54,8 @@ public: void synchronize(const Remote &); void uninstall(const Remote &); + void registerAll(const Remote &); + void unregisterAll(const Remote &); void runTasks(); void cancel();