api_repo.cpp (3012B)
1 /* ReaPack: Package manager for REAPER 2 * Copyright (C) 2015-2025 Christian Fillion 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 #include "api.hpp" 19 #include "api_helper.hpp" 20 21 #include "errors.hpp" 22 #include "reapack.hpp" 23 #include "remote.hpp" 24 25 #include <boost/lexical_cast.hpp> 26 #include <boost/logic/tribool_io.hpp> // required to get correct tribool casts 27 28 DEFINE_API(bool, AboutRepository, ((const char*, repoName)), 29 R"(Show the about dialog of the given repository. Returns true if the repository exists in the user configuration. 30 The repository index is downloaded asynchronously if the cached copy doesn't exist or is older than one week.)", 31 { 32 if(const Remote &repo = g_reapack->remote(repoName)) { 33 g_reapack->about(repo); 34 return true; 35 } 36 37 return false; 38 }); 39 40 DEFINE_API(bool, AddSetRepository, ((const char*, name))((const char*, url)) 41 ((bool, enable))((int, autoInstall))((char*, errorOut))((int, errorOut_sz)), 42 R"(Add or modify a repository. Set url to nullptr (or empty string in Lua) to keep the existing URL. Call <a href="#ReaPack_ProcessQueue">ReaPack_ProcessQueue(true)</a> when done to process the new list and update the GUI. 43 44 autoInstall: usually set to 2 (obey user setting).)", 45 { 46 try { 47 Remote remote = g_reapack->remote(name); 48 remote.setName(name); 49 remote.setUrl(url && strlen(url) > 0 ? url : remote.url()); 50 remote.setEnabled(enable); 51 remote.setAutoInstall(boost::lexical_cast<tribool>(autoInstall)); 52 g_reapack->addSetRemote(remote); 53 } 54 catch(const reapack_error &e) { 55 if(errorOut) 56 snprintf(errorOut, errorOut_sz, "%s", e.what()); 57 return false; 58 } 59 catch(const boost::bad_lexical_cast &) { 60 if(errorOut) 61 snprintf(errorOut, errorOut_sz, "invalid value for autoInstall"); 62 return false; 63 } 64 65 return true; 66 }); 67 68 DEFINE_API(bool, GetRepositoryInfo, ((const char*, name)) 69 ((char*, urlOut))((int, urlOut_sz)) 70 ((bool*, enabledOut))((int*, autoInstallOut)), 71 R"(Get the infos of the given repository. 72 73 autoInstall: 0=manual, 1=when sychronizing, 2=obey user setting)", 74 { 75 const Remote &remote = g_reapack->remote(name); 76 77 if(!remote) 78 return false; 79 80 if(urlOut) 81 snprintf(urlOut, urlOut_sz, "%s", remote.url().c_str()); 82 if(enabledOut) 83 *enabledOut = remote.isEnabled(); 84 if(autoInstallOut) 85 *autoInstallOut = boost::lexical_cast<int>(remote.autoInstall()); 86 87 return true; 88 });