reapack

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

commit 9e840a893fdc06da07d3770113bdf3e13a9e15a3
parent 4b5d1fb9a0f9170abc0df49c110615eb59daecf5
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Sun,  4 Jun 2017 04:16:56 -0400

Merge branch 'repo-api'

Diffstat:
Msrc/api.cpp | 83+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/api.hpp | 3+++
Msrc/main.cpp | 3+++
3 files changed, 89 insertions(+), 0 deletions(-)

diff --git a/src/api.cpp b/src/api.cpp @@ -17,12 +17,15 @@ #include "api.hpp" +#include <boost/lexical_cast.hpp> +#include <boost/logic/tribool_io.hpp> // required to get correct tribool casts #include <boost/mpl/aux_/preprocessor/token_equal.hpp> #include <boost/preprocessor.hpp> #include <reaper_plugin_functions.h> #include "about.hpp" +#include "config.hpp" #include "errors.hpp" #include "index.hpp" #include "reapack.hpp" @@ -181,6 +184,27 @@ DEFINE_API(bool, EnumOwnedFiles, ((PackageEntry*, entry))((int, index)) return entry->files.size() > i + 1; }); +DEFINE_API(bool, EnumRepositories, ((int, index)) + ((char*, nameOut))((int, nameOut_sz)), R"( + Enumerate the repository list. Returns false once the end of the list is reached. +)", { + const size_t i = index; + const RemoteList &list = reapack->config()->remotes; + + if(i >= list.size()) + return false; + + auto it = list.begin(); + advance(it, i); + + const Remote &remote = *it; + + if(nameOut) + snprintf(nameOut, nameOut_sz, "%s", remote.name().c_str()); + + return list.size() > i + 1; +}); + DEFINE_API(bool, FreeEntry, ((PackageEntry*, entry)), R"( Free resources allocated for the given package entry. )", { @@ -262,3 +286,62 @@ DEFINE_API(PackageEntry*, GetOwner, ((const char*, fn))((char*, errorOut))((int, return nullptr; } }); + +DEFINE_API(bool, GetRepositoryInfo, ((const char*, name)) + ((char*, urlOut))((int, urlOut_sz)) + ((bool*, enabledOut))((int*, autoInstallOut)), R"( + Get the infos of the given repository. + + autoInstall: 0=manual, 1=when sychronizing, 2=obey user setting +)", { + const Remote &remote = reapack->remote(name); + + if(!remote) + return false; + + if(urlOut) + snprintf(urlOut, urlOut_sz, "%s", remote.url().c_str()); + if(enabledOut) + *enabledOut = remote.isEnabled(); + if(autoInstallOut) + *autoInstallOut = boost::lexical_cast<int>(remote.autoInstall()); + + return true; +}); + +DEFINE_API(bool, AddSetRepository, ((const char*, name))((const char*, url)) + ((bool, enabled))((int, autoInstall))((bool, commit)) + ((char*, errorOut))((int, errorOut_sz)), R"( + Add or modify a repository. Set commit to true for the last call to save the new list and update the GUI. + + autoInstall: default is 2 (obey user setting). +)", { + try { + if(reapack->remote(name).isProtected()) { + if(errorOut) + snprintf(errorOut, errorOut_sz, "this repository is protected"); + return false; + } + + Remote remote(name, url, enabled, boost::lexical_cast<tribool>(autoInstall)); + reapack->config()->remotes.add(remote); + } + catch(const reapack_error &e) { + if(errorOut) + snprintf(errorOut, errorOut_sz, "%s", e.what()); + return false; + } + catch(const boost::bad_lexical_cast &) { + if(errorOut) + snprintf(errorOut, errorOut_sz, "invalid value for autoInstall"); + return false; + } + + if(commit) { + reapack->refreshManager(); + reapack->refreshBrowser(); + reapack->config()->write(); + } + + return true; +}); diff --git a/src/api.hpp b/src/api.hpp @@ -47,11 +47,14 @@ namespace API { extern APIFunc AboutInstalledPackage; extern APIFunc AboutRepository; + extern APIFunc AddSetRepository; extern APIFunc CompareVersions; extern APIFunc EnumOwnedFiles; + extern APIFunc EnumRepositories; extern APIFunc FreeEntry; extern APIFunc GetEntryInfo; extern APIFunc GetOwner; + extern APIFunc GetRepositoryInfo; }; #endif diff --git a/src/main.cpp b/src/main.cpp @@ -162,11 +162,14 @@ static void setupAPI() { reapack->setupAPI(&API::AboutInstalledPackage); reapack->setupAPI(&API::AboutRepository); + reapack->setupAPI(&API::AddSetRepository); reapack->setupAPI(&API::CompareVersions); reapack->setupAPI(&API::EnumOwnedFiles); + reapack->setupAPI(&API::EnumRepositories); reapack->setupAPI(&API::FreeEntry); reapack->setupAPI(&API::GetEntryInfo); reapack->setupAPI(&API::GetOwner); + reapack->setupAPI(&API::GetRepositoryInfo); } extern "C" REAPER_PLUGIN_DLL_EXPORT int REAPER_PLUGIN_ENTRYPOINT(