reapack

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

commit 95d5236e13d0118879447091cd0c6399b11b4d74
parent 8f8f55d69b86f2004317b606d143dd6138c3300d
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Thu, 17 Mar 2016 22:49:03 -0400

remove the Cleanup packages feature that was doing a part of the browser's job

Diffstat:
Dsrc/cleanup.cpp | 174-------------------------------------------------------------------------------
Dsrc/cleanup.hpp | 60------------------------------------------------------------
Msrc/main.cpp | 6------
Msrc/reapack.cpp | 33+++------------------------------
Msrc/reapack.hpp | 4----
5 files changed, 3 insertions(+), 274 deletions(-)

diff --git a/src/cleanup.cpp b/src/cleanup.cpp @@ -1,174 +0,0 @@ -/* ReaPack: Package manager for REAPER - * Copyright (C) 2015-2016 Christian Fillion - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "cleanup.hpp" - -#include "encoding.hpp" -#include "errors.hpp" -#include "index.hpp" -#include "listview.hpp" -#include "menu.hpp" -#include "reapack.hpp" -#include "resource.hpp" - -using namespace std; - -enum { ACTION_SELECT = 300, ACTION_UNSELECT }; - -Cleanup::Cleanup(const std::vector<IndexPtr> &indexes, ReaPack *reapack) - : Dialog(IDD_CLEANUP_DIALOG), m_indexes(indexes), m_reapack(reapack) -{ -} - -void Cleanup::onInit() -{ - (void)m_reapack; - m_ok = getControl(IDOK); - m_stateLabel = getControl(IDC_LABEL2); - - disable(m_ok); - - m_list = createControl<ListView>(IDC_LIST, ListView::Columns{ - {AUTO_STR("Name"), 560}, - }); - - m_list->sortByColumn(0); - m_list->onSelect(bind(&Cleanup::onSelectionChanged, this)); - - try { - populate(); - } - catch(const reapack_error &e) { - const auto_string &desc = make_autostring(e.what()); - auto_char msg[255] = {}; - auto_snprintf(msg, sizeof(msg), - AUTO_STR("The file list is currently unavailable.\x20") - AUTO_STR("Retry later when all installation task are completed.\r\n") - AUTO_STR("\r\nError description: %s"), - desc.c_str()); - MessageBox(handle(), msg, AUTO_STR("AAA"), MB_OK); - } - -#ifdef LVSCW_AUTOSIZE_USEHEADER - m_list->resizeColumn(0, LVSCW_AUTOSIZE_USEHEADER); -#endif - - onSelectionChanged(); - - if(m_list->empty()) - startTimer(10); -} - -void Cleanup::onCommand(const int id) -{ - switch(id) { - case ACTION_SELECT: - m_list->selectAll(); - break; - case ACTION_UNSELECT: - m_list->unselectAll(); - break; - case IDOK: - if(confirm()) - apply(); - else - break; - case IDCANCEL: - close(); - break; - } -} - -void Cleanup::onContextMenu(HWND target, const int x, const int y) -{ - if(target != m_list->handle()) - return; - - Menu menu; - menu.addAction(AUTO_STR("&Select all"), ACTION_SELECT); - menu.addAction(AUTO_STR("&Unselect all"), ACTION_UNSELECT); - menu.show(x, y, handle()); -} - -void Cleanup::onTimer(const int id) -{ - stopTimer(id); - - MessageBox(handle(), AUTO_STR("No obsolete package found!"), - AUTO_STR("ReaPack"), MB_OK); - - close(); -} - -void Cleanup::populate() -{ - Registry reg(Path::prefixRoot(Path::REGISTRY)); - - for(IndexPtr index : m_indexes) { - for(const Registry::Entry &entry : reg.getEntries(index->name())) { - const Category *cat = index->category(entry.category); - - if(cat && cat->package(entry.package)) - continue; - - const string row = entry.remote + "/" + entry.category + "/" + entry.package; - m_list->addRow({make_autostring(row)}); - - m_entries.push_back(entry); - } - } - - m_list->sort(); -} - -void Cleanup::onSelectionChanged() -{ - const int selectionSize = m_list->selectionSize(); - - auto_char state[255] = {}; - auto_snprintf(state, sizeof(state), AUTO_STR("%d of %d package%s selected"), - selectionSize, m_list->rowCount(), - selectionSize == 1 ? AUTO_STR("") : AUTO_STR("s")); - - SetWindowText(m_stateLabel, state); - - setEnabled(selectionSize > 0, m_ok); -} - -bool Cleanup::confirm() const -{ - const int count = m_list->selectionSize(); - - auto_char msg[255] = {}; - auto_snprintf(msg, sizeof(msg), - AUTO_STR("Uninstall %d package%s?\n") - AUTO_STR("Every file they contain will be removed from your computer."), - count, count == 1 ? AUTO_STR("") : AUTO_STR("s")); - - const auto_char *title = AUTO_STR("ReaPack Query"); - const int btn = MessageBox(handle(), msg, title, MB_YESNO); - - return btn == IDYES; -} - -void Cleanup::apply() -{ - for(const int i : m_list->selection()) - m_reapack->uninstall(m_entries[i]); - - m_reapack->runTasks(); -} diff --git a/src/cleanup.hpp b/src/cleanup.hpp @@ -1,60 +0,0 @@ -/* ReaPack: Package manager for REAPER - * Copyright (C) 2015-2016 Christian Fillion - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef REAPACK_CLEANUP_HPP -#define REAPACK_CLEANUP_HPP - -#include "dialog.hpp" - -#include "registry.hpp" - -#include <memory> -#include <vector> - -class Index; -class ListView; -class ReaPack; - -typedef std::shared_ptr<const Index> IndexPtr; - -class Cleanup : public Dialog { -public: - Cleanup(const std::vector<IndexPtr> &, ReaPack *); - -protected: - void onInit() override; - void onCommand(int) override; - void onContextMenu(HWND, int x, int y) override; - void onTimer(int) override; - -private: - void populate(); - void onSelectionChanged(); - bool confirm() const; - void apply(); - - std::vector<IndexPtr> m_indexes; - ReaPack *m_reapack; - - HWND m_ok; - HWND m_stateLabel; - ListView *m_list; - - std::vector<Registry::Entry> m_entries; -}; - -#endif diff --git a/src/main.cpp b/src/main.cpp @@ -84,9 +84,6 @@ static void menuHook(const char *name, HMENU handle, int f) menu.addAction(AUTO_STR("&Browse packages..."), NamedCommandLookup("_REAPACK_BROWSE")); - menu.addAction(AUTO_STR("&Clean up packages..."), - NamedCommandLookup("_REAPACK_CLEANUP")); - menu.addAction(AUTO_STR("&Import a repository..."), NamedCommandLookup("_REAPACK_IMPORT")); @@ -165,9 +162,6 @@ extern "C" REAPER_PLUGIN_DLL_EXPORT int REAPER_PLUGIN_ENTRYPOINT( reapack->setupAction("REAPACK_BROWSE", "ReaPack: Browse packages...", &reapack->browseAction, bind(&ReaPack::browsePackages, reapack)); - reapack->setupAction("REAPACK_CLEANUP", "ReaPack: Clean up packages...", - &reapack->cleanupAction, bind(&ReaPack::cleanupPackages, reapack)); - reapack->setupAction("REAPACK_IMPORT", "ReaPack: Import a repository...", &reapack->importAction, bind(&ReaPack::importRemote, reapack)); diff --git a/src/reapack.cpp b/src/reapack.cpp @@ -19,7 +19,6 @@ #include "about.hpp" #include "browser.hpp" -#include "cleanup.hpp" #include "config.hpp" #include "errors.hpp" #include "filesystem.hpp" @@ -63,9 +62,9 @@ static void CleanupTempFiles() #endif ReaPack::ReaPack(REAPER_PLUGIN_HINSTANCE instance) - : syncAction(), browseAction(), cleanupAction(), importAction(), configAction(), + : syncAction(), browseAction(),importAction(), configAction(), m_transaction(nullptr), m_progress(nullptr), m_browser(nullptr), - m_cleanup(nullptr), m_import(nullptr), m_manager(nullptr), m_instance(instance) + m_import(nullptr), m_manager(nullptr), m_instance(instance) { m_mainWindow = GetMainHwnd(); m_useRootPath = new UseRootPath(GetResourcePath()); @@ -313,32 +312,6 @@ void ReaPack::about(const Remote &remote, HWND parent) }, parent); } -void ReaPack::cleanupPackages() -{ - if(m_cleanup) { - m_cleanup->setFocus(); - return; - } - else if(m_transaction) { - ShowMessageBox( - "This feature cannot be used while packages are being installed. " - "Try again later.", "Clean up packages", MB_OK - ); - return; - } - - const vector<Remote> &remotes = m_config->remotes()->getEnabled(); - - fetchIndexes(remotes, [=] (const vector<IndexPtr> &indexes) { - m_cleanup = Dialog::Create<Cleanup>(m_instance, m_mainWindow, indexes, this); - m_cleanup->show(); - m_cleanup->setCloseHandler([=] (INT_PTR) { - Dialog::Destroy(m_cleanup); - m_cleanup = nullptr; - }); - }); -} - void ReaPack::browsePackages() { if(m_browser) { @@ -512,7 +485,7 @@ Transaction *ReaPack::createTransaction() return; LockDialog managerLock(m_manager); - LockDialog cleanupLock(m_cleanup); + LockDialog cleanupLock(m_browser); if(m_transaction->taskCount() == 0 && !receipt->hasErrors()) ShowMessageBox("Nothing to do!", "ReaPack", 0); diff --git a/src/reapack.hpp b/src/reapack.hpp @@ -29,7 +29,6 @@ #include <reaper_plugin.h> class Browser; -class Cleanup; class Config; class DownloadQueue; class Import; @@ -52,7 +51,6 @@ public: gaccel_register_t syncAction; gaccel_register_t browseAction; - gaccel_register_t cleanupAction; gaccel_register_t importAction; gaccel_register_t configAction; @@ -76,7 +74,6 @@ public: void aboutSelf(); void about(const std::string &, HWND parent); void about(const Remote &, HWND parent); - void cleanupPackages(); void browsePackages(); void fetchIndexes(const std::vector<Remote> &, const IndexesCallback &, HWND = nullptr); @@ -99,7 +96,6 @@ private: Transaction *m_transaction; Progress *m_progress; Browser *m_browser; - Cleanup *m_cleanup; Import *m_import; Manager *m_manager;