reapack

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

commit fa002afed8726d428cbaf2e596d8c65666e3e318
parent 87a604b3258fa2e83b3b305925d8b5ad240f0b66
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Sat,  5 Dec 2015 21:58:18 -0800

Merge branch 'master' of https://github.com/cfillion/reapack

Diffstat:
Msrc/package.cpp | 3+++
Msrc/progress.cpp | 18++++++++++++++----
Msrc/progress.hpp | 7++++---
Msrc/registry.cpp | 9+++++++--
Msrc/transaction.cpp | 12++++++++++--
Msrc/transaction.hpp | 1+
Mtest/package.cpp | 1+
Atest/registry.cpp | 49+++++++++++++++++++++++++++++++++++++++++++++++++
Mtest/version.cpp | 2+-
9 files changed, 90 insertions(+), 12 deletions(-)

diff --git a/src/package.cpp b/src/package.cpp @@ -44,6 +44,9 @@ Version *Package::version(const size_t index) const Version *Package::lastVersion() const { + if(m_versions.empty()) + return 0; + return *prev(m_versions.end()); } diff --git a/src/progress.cpp b/src/progress.cpp @@ -10,7 +10,8 @@ using namespace std; Progress::Progress() : Dialog(IDD_PROGRESS_DIALOG), - m_transaction(0), m_done(0), m_total(0), m_label(0), m_progress(0) + m_transaction(0), m_current(0), m_label(0), m_progress(0), + m_done(0), m_total(0) { } @@ -53,19 +54,28 @@ void Progress::addDownload(Download *dl) updateProgress(); dl->onStart([=] { - const string text = "Downloading: " + dl->name() + "\n" + dl->url(); - SetWindowText(m_label, text.c_str()); + m_current = dl; + updateProgress(); }); dl->onFinish([=] { m_done++; updateProgress(); + m_current = 0; }); } void Progress::updateProgress() { - const double pos = m_done / m_total; + if(m_current) { + const string text = "Downloading " + + to_string(m_done + 1) + " of " + to_string(m_total) + ": " + + m_current->name() + "\n" + m_current->url(); + + SetWindowText(m_label, text.c_str()); + } + + const double pos = (double)m_done / m_total; const int percent = (int)(pos * 100); const string title = string(TITLE) + " (" + to_string(percent) + "%)"; diff --git a/src/progress.hpp b/src/progress.hpp @@ -21,12 +21,13 @@ private: void updateProgress(); Transaction *m_transaction; - - int m_done; - double m_total; + Download *m_current; HWND m_label; HWND m_progress; + + int m_done; + int m_total; }; #endif diff --git a/src/registry.cpp b/src/registry.cpp @@ -7,12 +7,17 @@ using namespace std; void Registry::push(Package *pkg) { - push(pkg->targetPath().join(), pkg->lastVersion()->name()); + Version *lastVer = pkg->lastVersion(); + + if(!lastVer) + return; + + push(pkg->targetPath().join(), lastVer->name()); } void Registry::push(const std::string &key, const std::string &value) { - m_map.insert({key, value}); + m_map[key] = value; } string Registry::versionOf(Package *pkg) const diff --git a/src/transaction.cpp b/src/transaction.cpp @@ -72,7 +72,10 @@ void Transaction::prepare() for(Database *db : m_databases) { for(Package *pkg : db->packages()) { - if(m_registry->versionOf(pkg) != pkg->lastVersion()->name()) + bool hasLatest = m_registry->versionOf(pkg) == pkg->lastVersion()->name(); + bool exists = file_exists(installPath(pkg).join().c_str()); + + if(!hasLatest || !exists) m_packages.push_back(pkg); } } @@ -106,7 +109,7 @@ void Transaction::cancel() void Transaction::install(Package *pkg) { const string &url = pkg->lastVersion()->source(0)->url(); - const Path path = m_root + pkg->targetPath(); + const Path path = installPath(pkg); const string dbName = pkg->category()->database()->name(); Download *dl = new Download(dbName + "/" + pkg->name(), url); @@ -137,6 +140,11 @@ void Transaction::install(Package *pkg) dl->onFinish(bind(&Transaction::finish, this)); } +Path Transaction::installPath(Package *pkg) const +{ + return m_root + pkg->targetPath(); +} + void Transaction::finish() { if(!m_queue.empty()) diff --git a/src/transaction.hpp b/src/transaction.hpp @@ -35,6 +35,7 @@ private: void install(Package *); void addError(const std::string &msg, const std::string &title); + Path installPath(Package *) const; Registry *m_registry; diff --git a/test/package.cpp b/test/package.cpp @@ -51,6 +51,7 @@ TEST_CASE("drop empty version", M) { pack.addVersion(new Version("1")); REQUIRE(pack.versions().empty()); + REQUIRE(pack.lastVersion() == 0); } TEST_CASE("unknown target path", M) { diff --git a/test/registry.cpp b/test/registry.cpp @@ -0,0 +1,49 @@ +#include <catch.hpp> + +#include <database.hpp> +#include <package.hpp> +#include <registry.hpp> + +using namespace std; + +static const char *M = "[registry]"; + +#define MAKE_PACKAGE \ + Database db; \ + db.setName("Hello"); \ + Category cat("Hello"); \ + cat.setDatabase(&db); \ + Package pkg(Package::ScriptType, "Hello"); \ + pkg.setCategory(&cat); \ + Version *ver = new Version("1.0"); \ + Source *src = new Source(Source::GenericPlatform, "https://..."); \ + ver->addSource(src); \ + pkg.addVersion(ver); + +TEST_CASE("version of uninstalled", M) { + MAKE_PACKAGE + + Registry reg; + REQUIRE(reg.versionOf(&pkg) == string()); +} + +TEST_CASE("version of installed", M) { + MAKE_PACKAGE + + Registry reg; + reg.push(&pkg); + REQUIRE(reg.versionOf(&pkg) == "1.0"); +} + +TEST_CASE("bump version", M) { + MAKE_PACKAGE + + Version *ver2 = new Version("2.0"); + ver2->addSource(new Source(Source::GenericPlatform, "https://...")); + + Registry reg; + reg.push(&pkg); + pkg.addVersion(ver2); + reg.push(&pkg); + REQUIRE(reg.versionOf(&pkg) == "2.0"); +} diff --git a/test/version.cpp b/test/version.cpp @@ -7,7 +7,7 @@ using namespace std; -static const char *M = "[database]"; +static const char *M = "[version]"; TEST_CASE("invalid", M) { try {