From f3827c82c78653fd8ba5fb489b9ba57e1e83463c Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Wed, 23 Jun 2021 23:02:20 -0400 Subject: [PATCH] Add major version checking to library plugin update check. --- include/common.hpp | 5 +---- include/network.hpp | 2 +- src/common.cpp | 4 +--- src/library.cpp | 17 +++++++++-------- src/patch.cpp | 4 ++-- src/plugin.cpp | 2 +- src/plugin/Plugin.cpp | 4 ++-- src/settings.cpp | 2 +- 8 files changed, 18 insertions(+), 22 deletions(-) diff --git a/include/common.hpp b/include/common.hpp index e9f22b28..818a0056 100644 --- a/include/common.hpp +++ b/include/common.hpp @@ -262,12 +262,9 @@ typename C::mapped_type get(const C& m, const typename C::key_type& key, const t extern const std::string APP_NAME; extern const std::string APP_VARIANT; extern const std::string APP_VERSION; +extern const std::string APP_VERSION_MAJOR; extern const std::string APP_ARCH; - -extern const std::string ABI_VERSION; - extern const std::string API_URL; -extern const std::string API_VERSION; } // namespace rack diff --git a/include/network.hpp b/include/network.hpp index 4603f315..73a45e22 100644 --- a/include/network.hpp +++ b/include/network.hpp @@ -27,7 +27,7 @@ void init(); /** Requests a JSON API URL over HTTP(S), using the data as the query (GET) or the body (POST, etc) Caller must json_decref() if return value is non-NULL. */ -json_t* requestJson(Method method, const std::string& url, json_t* dataJ, const CookieMap& cookies = {}); +json_t* requestJson(Method method, const std::string& url, json_t* dataJ = NULL, const CookieMap& cookies = {}); /** Returns true if downloaded successfully */ bool requestDownload(const std::string& url, const std::string& filename, float* progress, const CookieMap& cookies = {}); /** URL-encodes `s` */ diff --git a/src/common.cpp b/src/common.cpp index ee3d414b..adc380a2 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -18,6 +18,7 @@ namespace rack { const std::string APP_NAME = "VCV Rack"; const std::string APP_VARIANT = "Community Edition"; const std::string APP_VERSION = TOSTRING(VERSION); +const std::string APP_VERSION_MAJOR = "2"; #if defined ARCH_WIN const std::string APP_ARCH = "win"; #elif ARCH_MAC @@ -26,10 +27,7 @@ const std::string APP_VERSION = TOSTRING(VERSION); const std::string APP_ARCH = "lin"; #endif -const std::string ABI_VERSION = "2"; - const std::string API_URL = "https://api.vcvrack.com"; -const std::string API_VERSION = "2"; Exception::Exception(const char* format, ...) { diff --git a/src/library.cpp b/src/library.cpp index 8890c99c..b8ebf433 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -176,7 +176,7 @@ void checkUpdates() { // Get library manifests std::string manifestsUrl = API_URL + "/library/manifests"; json_t* manifestsReq = json_object(); - json_object_set(manifestsReq, "version", json_string(API_VERSION.c_str())); + json_object_set(manifestsReq, "version", json_string(APP_VERSION_MAJOR.c_str())); json_t* manifestsResJ = network::requestJson(network::METHOD_GET, manifestsUrl, manifestsReq); json_decref(manifestsReq); if (!manifestsResJ) { @@ -216,22 +216,23 @@ void checkUpdates() { // Get version json_t* versionJ = json_object_get(manifestJ, "version"); if (!versionJ) { - WARN("Plugin %s has no version in manifest", slug.c_str()); + // WARN("Plugin %s has no version in manifest", slug.c_str()); continue; } update.version = json_string_value(versionJ); + // Reject plugins with ABI mismatch + if (!string::startsWith(update.version, APP_VERSION_MAJOR + ".")) { + continue; + } // Check if update is needed plugin::Plugin* p = plugin::getPlugin(slug); if (p && p->version == update.version) continue; - // Require that "status" is "available" - json_t* statusJ = json_object_get(manifestJ, "status"); - if (!statusJ) - continue; - std::string status = json_string_value(statusJ); - if (status != "available") + // Require that plugin is available + json_t* availableJ = json_object_get(manifestJ, "available"); + if (!json_boolean_value(availableJ)) continue; // Get changelog URL diff --git a/src/patch.cpp b/src/patch.cpp index 6286ca8f..db37a1d3 100644 --- a/src/patch.cpp +++ b/src/patch.cpp @@ -28,8 +28,8 @@ PatchManager::PatchManager() { templatePath = asset::user("template.vcv"); } else { - autosavePath = asset::user("autosave-v" + ABI_VERSION); - templatePath = asset::user("template-v" + ABI_VERSION + ".vcv"); + autosavePath = asset::user("autosave-v" + APP_VERSION_MAJOR); + templatePath = asset::user("template-v" + APP_VERSION_MAJOR + ".vcv"); } factoryTemplatePath = asset::system("template.vcv"); } diff --git a/src/plugin.cpp b/src/plugin.cpp index fe37a715..1a515664 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -217,7 +217,7 @@ void init() { pluginsPath = asset::user("plugins"); } else { - pluginsPath = asset::user("plugins-v" + ABI_VERSION); + pluginsPath = asset::user("plugins-v" + APP_VERSION_MAJOR); } // Get user plugins directory diff --git a/src/plugin/Plugin.cpp b/src/plugin/Plugin.cpp index 4a214b45..6cdae4ef 100644 --- a/src/plugin/Plugin.cpp +++ b/src/plugin/Plugin.cpp @@ -48,8 +48,8 @@ void Plugin::fromJson(json_t* rootJ) { json_t* versionJ = json_object_get(rootJ, "version"); if (versionJ) version = json_string_value(versionJ); - if (!string::startsWith(version, ABI_VERSION + ".")) - throw Exception("Plugin version %s does not match Rack ABI version %s", version.c_str(), ABI_VERSION.c_str()); + if (!string::startsWith(version, APP_VERSION_MAJOR + ".")) + throw Exception("Plugin version %s does not match Rack ABI version %s", version.c_str(), APP_VERSION_MAJOR.c_str()); if (version == "") throw Exception("No plugin version"); diff --git a/src/settings.cpp b/src/settings.cpp index 00131f15..0eb10fb2 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -70,7 +70,7 @@ void init() { settingsPath = asset::user("settings.json"); } else { - settingsPath = asset::user("settings-v" + ABI_VERSION + ".json"); + settingsPath = asset::user("settings-v" + APP_VERSION_MAJOR + ".json"); } }