commit 6c43dd7252c26383aedca63684289d97dfb4af7d
parent a42cb15f86eac60b2603510451bd7a81d912ee7e
Author: cfillion <cfillion@users.noreply.github.com>
Date: Fri, 12 Feb 2016 02:42:45 -0500
mild refactoring
Diffstat:
3 files changed, 46 insertions(+), 41 deletions(-)
diff --git a/src/transaction.cpp b/src/transaction.cpp
@@ -265,7 +265,7 @@ void Transaction::finish()
m_registry->commit();
- registerScriptsInHost();
+ registerQueued();
}
m_onFinish();
@@ -309,51 +309,53 @@ void Transaction::runTasks()
void Transaction::registerInHost(const bool add, const Registry::Entry &entry)
{
- // don't actually do anything until commit()
-
- switch(entry.type) {
- case Package::ScriptType:
- m_scriptRegs.push({add, entry, m_registry->getMainFile(entry)});
- break;
- default:
- break;
- }
+ // don't actually do anything until commit() – which will calls registerQueued
+ m_regQueue.push({add, entry, m_registry->getMainFile(entry)});
}
-void Transaction::registerScriptsInHost()
+void Transaction::registerQueued()
{
- if(!AddRemoveReaScript) {
- // do nothing if REAPER < v5.12
- m_scriptRegs = {};
- return;
- }
+ while(!m_regQueue.empty()) {
+ const HostRegistration ® = m_regQueue.front();
- enum Section { MainSection = 0, MidiEditorSection = 32060 };
+ // 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())) {
+ m_regQueue.pop();
+ return;
+ }
- while(!m_scriptRegs.empty()) {
- const HostRegistration ® = m_scriptRegs.front();
- const Registry::Entry &entry = reg.entry;
+ switch(reg.entry.type) {
+ case Package::ScriptType:
+ registerScript(reg);
+ break;
+ default:
+ break;
+ }
- const Remote &remote = m_remoteList->get(entry.remote);
- if(reg.add && (remote.isNull() || !remote.isEnabled()))
- continue; // don't register in host if the remote got disabled meanwhile
+ m_regQueue.pop();
+ }
+}
- string category = Path(entry.category).first();
- boost::algorithm::to_lower(category);
+void Transaction::registerScript(const HostRegistration ®)
+{
+ enum Section { MainSection = 0, MidiEditorSection = 32060 };
- Section section;
+ if(!AddRemoveReaScript)
+ return; // do nothing if REAPER < v5.12
- if(category == "midi editor")
- section = MidiEditorSection;
- else
- section = MainSection;
+ Section section;
+ string category = Path(reg.entry.category).first();
+ boost::algorithm::to_lower(category);
- const std::string &path = Path::prefixRoot(reg.file).join();
- const bool isLast = m_scriptRegs.size() == 1;
+ if(category == "midi editor")
+ section = MidiEditorSection;
+ else
+ section = MainSection;
- if(!AddRemoveReaScript(reg.add, section, path.c_str(), isLast) && reg.add)
- addError("Script could not be registered in REAPER.", reg.file);
+ const std::string &path = Path::prefixRoot(reg.file).join();
+ const bool isLast = m_regQueue.size() == 1;
- m_scriptRegs.pop();
- }
+ if(!AddRemoveReaScript(reg.add, section, path.c_str(), isLast) && reg.add)
+ addError("Script could not be registered in REAPER.", reg.file);
}
diff --git a/src/transaction.hpp b/src/transaction.hpp
@@ -78,6 +78,8 @@ public:
void addError(const std::string &msg, const std::string &title);
private:
+ struct HostRegistration { bool add; Registry::Entry entry; std::string file; };
+
void installQueued();
void installTicket(const InstallTicket &);
void finish();
@@ -88,7 +90,8 @@ private:
void addTask(Task *);
void registerInHost(bool add, const Registry::Entry &);
- void registerScriptsInHost();
+ void registerQueued();
+ void registerScript(const HostRegistration &);
const RemoteList *m_remoteList;
bool m_isCancelled;
@@ -97,13 +100,12 @@ private:
std::multimap<Remote, IndexCallback> m_remotes;
std::vector<const RemoteIndex *> m_remoteIndexes;
+ std::vector<Task *> m_tasks;
+
DownloadQueue m_downloadQueue;
std::queue<InstallTicket> m_installQueue;
- std::vector<Task *> m_tasks;
std::queue<Task *> m_taskQueue;
-
- struct HostRegistration { bool add; Registry::Entry entry; std::string file; };
- std::queue<HostRegistration> m_scriptRegs;
+ std::queue<HostRegistration> m_regQueue;
InstallTicketList m_new;
InstallTicketList m_updates;
diff --git a/test/remote.cpp b/test/remote.cpp
@@ -115,6 +115,7 @@ TEST_CASE("valide remote urls", M) {
TEST_CASE("null remote", M) {
Remote remote;
REQUIRE(remote.isNull());
+ CHECK(remote.isEnabled());
SECTION("set name") {
remote.setName("test");