reapack

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

commit 755f48c5fb9887954dc19f9c00145ae360ab2cec
parent e48c9bdcc8066e2961f590a2accb08e4e3254621
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Mon,  6 Jun 2016 22:52:40 -0400

import: open the manager along with the import dialog

Diffstat:
Msrc/import.cpp | 87+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------
Msrc/import.hpp | 6+++---
Msrc/manager.cpp | 8+++++++-
Msrc/manager.hpp | 3++-
Msrc/reapack.cpp | 91++++---------------------------------------------------------------------------
Msrc/reapack.hpp | 3---
6 files changed, 92 insertions(+), 106 deletions(-)

diff --git a/src/import.cpp b/src/import.cpp @@ -17,6 +17,7 @@ #include "import.hpp" +#include "config.hpp" #include "download.hpp" #include "errors.hpp" #include "filesystem.hpp" @@ -24,10 +25,11 @@ #include "reapack.hpp" #include "remote.hpp" #include "resource.hpp" +#include "transaction.hpp" using namespace std; -const auto_char *Import::TITLE = AUTO_STR("ReaPack: Import a repository"); +static const auto_char *TITLE = AUTO_STR("ReaPack: Import a repository"); Import::Import(ReaPack *reapack) : Dialog(IDD_IMPORT_DIALOG), m_reapack(reapack), m_download(nullptr) @@ -109,8 +111,7 @@ void Import::fetch() return; } - if(!import()) - SetFocus(m_url); + read(); }); dl->setCleanupHandler([=] { @@ -124,26 +125,90 @@ void Import::fetch() dl->start(); } -bool Import::import() +void Import::read() { assert(m_download); try { IndexPtr index = Index::load({}, m_download->contents().c_str()); - if(m_reapack->import({index->name(), m_download->url()}, handle())) - FS::write(Index::pathFor(index->name()), m_download->contents()); - - close(); - - return true; + close(import({index->name(), m_download->url()})); } catch(const reapack_error &e) { const string msg = "The received file is invalid: " + string(e.what()); MessageBox(handle(), make_autostring(msg).c_str(), TITLE, MB_OK); - return false; + SetFocus(m_url); } } +bool Import::import(const Remote &remote) +{ + if(const Remote &existing = m_reapack->remote(remote.name())) { + if(existing.isProtected()) { + MessageBox(handle(), + AUTO_STR("This repository is protected and cannot be overwritten."), + TITLE, MB_OK); + + return false; + } + else if(existing.url() != remote.url()) { + auto_char msg[1024] = {}; + auto_snprintf(msg, auto_size(msg), + AUTO_STR("%s is already configured with a different URL.\r\n") + AUTO_STR("Do you want to overwrite it?"), + make_autostring(remote.name()).c_str()); + + const auto answer = MessageBox(handle(), msg, TITLE, MB_YESNO); + + if(answer != IDYES) + return false; + } + else if(existing.isEnabled()) { + auto_char msg[1024] = {}; + auto_snprintf(msg, auto_size(msg), + AUTO_STR("%s is already configured.\r\nNothing to do!"), + make_autostring(remote.name()).c_str()); + MessageBox(handle(), msg, TITLE, MB_OK); + + return false; + } + else { + Transaction *tx = m_reapack->setupTransaction(); + + if(!tx) + return true; + + m_reapack->enable(existing); + tx->runTasks(); + + m_reapack->config()->write(); + + auto_char msg[1024] = {}; + auto_snprintf(msg, auto_size(msg), AUTO_STR("%s has been enabled."), + make_autostring(remote.name()).c_str()); + MessageBox(handle(), msg, TITLE, MB_OK); + + return true; + } + } + + Config *config = m_reapack->config(); + config->remotes()->add(remote); + config->write(); + + FS::write(Index::pathFor(remote.name()), m_download->contents()); + + auto_char msg[1024] = {}; + auto_snprintf(msg, auto_size(msg), + AUTO_STR("%s has been successfully imported into your repository list."), + make_autostring(remote.name()).c_str()); + MessageBox(handle(), msg, TITLE, MB_OK); + + m_reapack->refreshManager(); + m_reapack->refreshBrowser(); + + return true; +} + void Import::setWaiting(const bool wait) { setVisible(wait, m_progress); diff --git a/src/import.hpp b/src/import.hpp @@ -26,12 +26,11 @@ class Download; class ReaPack; +class Remote; class Import : public Dialog { public: - static const auto_char *TITLE; - Import(ReaPack *); protected: @@ -41,7 +40,8 @@ protected: private: void fetch(); - bool import(); + void read(); + bool import(const Remote &); void setWaiting(bool); ReaPack *m_reapack; diff --git a/src/manager.cpp b/src/manager.cpp @@ -21,6 +21,7 @@ #include "config.hpp" #include "encoding.hpp" #include "errors.hpp" +#include "import.hpp" #include "index.hpp" #include "menu.hpp" #include "reapack.hpp" @@ -64,7 +65,7 @@ void Manager::onCommand(const int id, int) { switch(id) { case IDC_IMPORT: - m_reapack->importRemote(); + Dialog::Show<Import>(instance(), handle(), m_reapack); break; case IDC_BROWSE: launchBrowser(); @@ -323,6 +324,11 @@ void Manager::copyUrl(const int index) setClipboard(remote.url()); } +void Manager::triggerImport() +{ + SendMessage(handle(), WM_COMMAND, IDC_IMPORT, 0); +} + void Manager::launchBrowser() { const auto promptApply = [&] { diff --git a/src/manager.hpp b/src/manager.hpp @@ -35,6 +35,7 @@ public: Manager(ReaPack *); void refresh(); + void triggerImport(); protected: void onInit() override; @@ -53,8 +54,8 @@ private: void refreshIndex(); void about(int index); void copyUrl(int index); - void options(); void launchBrowser(); + void options(); void setChange(int); bool confirm() const; diff --git a/src/reapack.cpp b/src/reapack.cpp @@ -22,7 +22,6 @@ #include "config.hpp" #include "errors.hpp" #include "filesystem.hpp" -#include "import.hpp" #include "index.hpp" #include "manager.hpp" #include "progress.hpp" @@ -74,8 +73,8 @@ std::string ReaPack::resourcePath() ReaPack::ReaPack(REAPER_PLUGIN_HINSTANCE instance) : syncAction(), browseAction(),importAction(), configAction(), - m_tx(nullptr), m_progress(nullptr), m_browser(nullptr), - m_import(nullptr), m_manager(nullptr), m_instance(instance) + m_tx(nullptr), m_progress(nullptr), m_browser(nullptr), m_manager(nullptr), + m_instance(instance) { m_mainWindow = GetMainHwnd(); m_useRootPath = new UseRootPath(resourcePath()); @@ -194,90 +193,8 @@ void ReaPack::uninstall(const Remote &remote) void ReaPack::importRemote() { - if(m_import) { - m_import->setFocus(); - return; - } - - m_import = Dialog::Create<Import>(m_instance, m_mainWindow, this); - m_import->show(); - m_import->setCloseHandler([=] (INT_PTR) { - Dialog::Destroy(m_import); - m_import = nullptr; - }); -} - -bool ReaPack::import(const Remote &remote, HWND parent) -{ - if(!parent) - parent = m_mainWindow; - - RemoteList *remotes = m_config->remotes(); - - const Remote &existing = remotes->get(remote.name()); - - if(existing) { - if(existing.isProtected()) { - MessageBox(parent, - AUTO_STR("This repository is protected and cannot be overwritten."), - Import::TITLE, MB_OK); - - return false; - } - else if(existing.url() != remote.url()) { - auto_char msg[1024] = {}; - auto_snprintf(msg, auto_size(msg), - AUTO_STR("%s is already configured with a different URL.\r\n") - AUTO_STR("Do you want to overwrite it?"), - make_autostring(remote.name()).c_str()); - - const auto answer = MessageBox(parent, msg, Import::TITLE, MB_YESNO); - - if(answer != IDYES) - return false; - } - else if(existing.isEnabled()) { - auto_char msg[1024] = {}; - auto_snprintf(msg, auto_size(msg), - AUTO_STR("%s is already configured.\r\nNothing to do!"), - make_autostring(remote.name()).c_str()); - MessageBox(parent, msg, Import::TITLE, MB_OK); - - return false; - } - else { - Transaction *tx = setupTransaction(); - - if(!tx) - return true; - - enable(existing); - tx->runTasks(); - - m_config->write(); - - auto_char msg[1024] = {}; - auto_snprintf(msg, auto_size(msg), AUTO_STR("%s has been enabled."), - make_autostring(remote.name()).c_str()); - MessageBox(parent, msg, Import::TITLE, MB_OK); - - return true; - } - } - - remotes->add(remote); - m_config->write(); - - refreshManager(); - refreshBrowser(); - - auto_char msg[1024] = {}; - auto_snprintf(msg, auto_size(msg), - AUTO_STR("%s has been successfully imported into your repository list."), - make_autostring(remote.name()).c_str()); - MessageBox(parent, msg, Import::TITLE, MB_OK); - - return true; + manageRemotes(); + m_manager->triggerImport(); } void ReaPack::manageRemotes() diff --git a/src/reapack.hpp b/src/reapack.hpp @@ -31,7 +31,6 @@ class Browser; class Config; class DownloadQueue; -class Import; class Index; class Manager; class Progress; @@ -70,7 +69,6 @@ public: void uninstall(const Remote &); void importRemote(); - bool import(const Remote &, HWND = nullptr); void manageRemotes(); void aboutSelf(); void about(const std::string &, HWND parent); @@ -100,7 +98,6 @@ private: Transaction *m_tx; Progress *m_progress; Browser *m_browser; - Import *m_import; Manager *m_manager; REAPER_PLUGIN_HINSTANCE m_instance;