From 8ec0d7fd1be8a7cc8de513646f61539d8eab1809 Mon Sep 17 00:00:00 2001 From: derrod Date: Sun, 23 Jul 2023 07:40:36 +0200 Subject: [PATCH 1/4] updater: Update manifest struct for use in UI --- UI/win-update/updater/manifest.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/UI/win-update/updater/manifest.hpp b/UI/win-update/updater/manifest.hpp index ab4936a1a..dce7a7d74 100644 --- a/UI/win-update/updater/manifest.hpp +++ b/UI/win-update/updater/manifest.hpp @@ -53,17 +53,17 @@ struct Manifest { uint8_t version_patch = 0; uint8_t beta = 0; uint8_t rc = 0; + std::string commit; /* Hash of VC redist file */ std::string vc2019_redist_x64; - /* Unused until UI is migrated to nlohmann_json */ - // std::string commit; - // std::string notes; + /* Release notes in HTML format */ + std::string notes; NLOHMANN_DEFINE_TYPE_INTRUSIVE(Manifest, packages, version_major, version_minor, version_patch, beta, rc, - vc2019_redist_x64) + commit, vc2019_redist_x64, notes) }; struct PatchRequest { From 01b21f67ff1f9982dff87b622cdbae063afde316 Mon Sep 17 00:00:00 2001 From: derrod Date: Sun, 23 Jul 2023 07:45:17 +0200 Subject: [PATCH 2/4] UI: Migrate Windows update check to nlohmann JSON --- UI/cmake/legacy.cmake | 4 ++- UI/cmake/os-windows.cmake | 7 +++-- UI/update/win-update.cpp | 63 ++++++++++++++------------------------- 3 files changed, 30 insertions(+), 44 deletions(-) diff --git a/UI/cmake/legacy.cmake b/UI/cmake/legacy.cmake index 77c0609ea..9638cbcab 100644 --- a/UI/cmake/legacy.cmake +++ b/UI/cmake/legacy.cmake @@ -340,6 +340,7 @@ if(OS_WINDOWS) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/obs.rc.in ${CMAKE_BINARY_DIR}/obs.rc) find_package(Detours REQUIRED) + find_package(nlohmann_json REQUIRED) target_sources( obs @@ -356,10 +357,11 @@ if(OS_WINDOWS) update/update-helpers.hpp update/crypto-helpers-mbedtls.cpp update/crypto-helpers.hpp + win-update/updater/manifest.hpp ${CMAKE_BINARY_DIR}/obs.rc) find_package(MbedTLS) - target_link_libraries(obs PRIVATE Mbedtls::Mbedtls OBS::blake2 Detours::Detours) + target_link_libraries(obs PRIVATE Mbedtls::Mbedtls nlohmann_json::nlohmann_json OBS::blake2 Detours::Detours) target_compile_features(obs PRIVATE cxx_std_17) diff --git a/UI/cmake/os-windows.cmake b/UI/cmake/os-windows.cmake index 13b194f2e..3a7b1843c 100644 --- a/UI/cmake/os-windows.cmake +++ b/UI/cmake/os-windows.cmake @@ -8,6 +8,7 @@ endif() find_package(MbedTLS) find_package(Detours REQUIRED) +find_package(nlohmann_json REQUIRED) configure_file(cmake/windows/obs.rc.in obs.rc) @@ -26,9 +27,11 @@ target_sources( update/update-window.cpp update/update-window.hpp update/win-update.cpp - update/win-update.hpp) + update/win-update.hpp + win-update/updater/manifest.hpp) -target_link_libraries(obs-studio PRIVATE crypt32 OBS::blake2 OBS::w32-pthreads MbedTLS::MbedTLS Detours::Detours) +target_link_libraries(obs-studio PRIVATE crypt32 OBS::blake2 OBS::w32-pthreads MbedTLS::MbedTLS + nlohmann_json::nlohmann_json Detours::Detours) target_compile_definitions(obs-studio PRIVATE PSAPI_VERSION=2) target_link_options(obs-studio PRIVATE /IGNORE:4098 /IGNORE:4099) diff --git a/UI/update/win-update.cpp b/UI/update/win-update.cpp index ae5671cf4..9b01c3dde 100644 --- a/UI/update/win-update.cpp +++ b/UI/update/win-update.cpp @@ -1,3 +1,4 @@ +#include "../win-update/updater/manifest.hpp" #include "update-helpers.hpp" #include "shared-update.hpp" #include "update-window.hpp" @@ -17,14 +18,13 @@ #include #include -#include #ifdef BROWSER_AVAILABLE #include #endif using namespace std; -using namespace json11; +using namespace updater; /* ------------------------------------------------------------------------ */ @@ -71,60 +71,41 @@ using namespace json11; #define CUR_COMMIT "00000000" #endif -static bool ParseUpdateManifest(const char *manifest, bool *updatesAvailable, - string ¬es_str, uint64_t &updateVer, - string &branch) +static bool ParseUpdateManifest(const char *manifest_data, + bool *updatesAvailable, string ¬es, + uint64_t &updateVer, const string &branch) try { + json manifestContents = json::parse(manifest_data); + Manifest manifest = manifestContents.get(); - string error; - Json root = Json::parse(manifest, error); - if (!error.empty()) - throw strprintf("Failed reading json string: %s", - error.c_str()); + if (manifest.version_major == 0 && manifest.commit.empty()) + throw strprintf("Invalid version number: %d.%d.%d", + manifest.version_major, manifest.version_minor, + manifest.version_patch); - if (!root.is_object()) - throw string("Root of manifest is not an object"); - - int major = root["version_major"].int_value(); - int minor = root["version_minor"].int_value(); - int patch = root["version_patch"].int_value(); - int rc = root["rc"].int_value(); - int beta = root["beta"].int_value(); - string commit_hash = root["commit"].string_value(); - - if (major == 0 && commit_hash.empty()) - throw strprintf("Invalid version number: %d.%d.%d", major, - minor, patch); - - const Json ¬es = root["notes"]; - if (!notes.is_string()) - throw string("'notes' value invalid"); - - notes_str = notes.string_value(); - - const Json &packages = root["packages"]; - if (!packages.is_array()) - throw string("'packages' value invalid"); + notes = manifest.notes; uint64_t cur_ver; uint64_t new_ver; - if (commit_hash.empty()) { + if (manifest.commit.empty()) { cur_ver = CUR_VER; - new_ver = MAKE_SEMANTIC_VERSION( - (uint64_t)major, (uint64_t)minor, (uint64_t)patch); + new_ver = + MAKE_SEMANTIC_VERSION((uint64_t)manifest.version_major, + (uint64_t)manifest.version_minor, + (uint64_t)manifest.version_patch); new_ver <<= 16; /* RC builds are shifted so that rc1 and beta1 versions do not result * in the same new_ver. */ - if (rc > 0) - new_ver |= (uint64_t)rc << 8; - else if (beta > 0) - new_ver |= (uint64_t)beta; + if (manifest.rc > 0) + new_ver |= (uint64_t)manifest.rc << 8; + else if (manifest.beta > 0) + new_ver |= (uint64_t)manifest.beta; } else { /* Test or nightly builds may not have a (valid) version number, * so compare commit hashes instead. */ cur_ver = stoul(CUR_COMMIT, nullptr, 16); - new_ver = stoul(commit_hash.substr(0, 8), nullptr, 16); + new_ver = stoul(manifest.commit.substr(0, 8), nullptr, 16); } updateVer = new_ver; From 72284a4837188b721b555be1408028b8b8c13b1f Mon Sep 17 00:00:00 2001 From: derrod Date: Sun, 23 Jul 2023 07:59:37 +0200 Subject: [PATCH 3/4] UI: Migrate branches to nlohmann JSON --- UI/cmake/feature-macos-update.cmake | 16 +++++++++-- UI/cmake/legacy.cmake | 18 +++++++++--- UI/cmake/os-windows.cmake | 1 + UI/obs-app.cpp | 33 ++++++++++++---------- UI/update/models/branches.hpp | 43 +++++++++++++++++++++++++++++ 5 files changed, 89 insertions(+), 22 deletions(-) create mode 100644 UI/update/models/branches.hpp diff --git a/UI/cmake/feature-macos-update.cmake b/UI/cmake/feature-macos-update.cmake index 2d50a66d9..d31ce424d 100644 --- a/UI/cmake/feature-macos-update.cmake +++ b/UI/cmake/feature-macos-update.cmake @@ -1,10 +1,20 @@ include_guard(DIRECTORY) +find_package(nlohmann_json REQUIRED) + if(NOT TARGET OBS::blake2) add_subdirectory("${CMAKE_SOURCE_DIR}/deps/blake2" "${CMAKE_BINARY_DIR}/deps/blake2") endif() -target_sources(obs-studio PRIVATE update/crypto-helpers.hpp update/crypto-helpers-mac.mm update/shared-update.cpp - update/shared-update.hpp update/update-helpers.cpp update/update-helpers.hpp) +target_sources( + obs-studio + PRIVATE update/crypto-helpers.hpp + update/crypto-helpers-mac.mm + update/shared-update.cpp + update/shared-update.hpp + update/update-helpers.cpp + update/update-helpers.hpp + update/models/branches.hpp) -target_link_libraries(obs-studio PRIVATE "$" OBS::blake2) +target_link_libraries(obs-studio PRIVATE "$" nlohmann_json::nlohmann_json + OBS::blake2) diff --git a/UI/cmake/legacy.cmake b/UI/cmake/legacy.cmake index 9638cbcab..aea502efe 100644 --- a/UI/cmake/legacy.cmake +++ b/UI/cmake/legacy.cmake @@ -357,6 +357,7 @@ if(OS_WINDOWS) update/update-helpers.hpp update/crypto-helpers-mbedtls.cpp update/crypto-helpers.hpp + update/models/branches.hpp win-update/updater/manifest.hpp ${CMAKE_BINARY_DIR}/obs.rc) @@ -425,17 +426,26 @@ elseif(OS_MACOS) if(ENABLE_WHATSNEW) find_library(SECURITY Security) + find_package(nlohmann_json REQUIRED) mark_as_advanced(SECURITY) - target_link_libraries(obs PRIVATE ${SECURITY} OBS::blake2) - target_sources(obs PRIVATE update/crypto-helpers.hpp update/crypto-helpers-mac.mm update/shared-update.cpp - update/shared-update.hpp update/update-helpers.cpp update/update-helpers.hpp) + target_link_libraries(obs PRIVATE ${SECURITY} OBS::blake2 nlohmann_json::nlohmann_json) + + target_sources( + obs + PRIVATE update/crypto-helpers.hpp + update/crypto-helpers-mac.mm + update/shared-update.cpp + update/shared-update.hpp + update/update-helpers.cpp + update/update-helpers.hpp) if(SPARKLE_APPCAST_URL AND SPARKLE_PUBLIC_KEY) find_library(SPARKLE Sparkle) mark_as_advanced(SPARKLE) - target_sources(obs PRIVATE update/mac-update.cpp update/mac-update.hpp update/sparkle-updater.mm) + target_sources(obs PRIVATE update/mac-update.cpp update/mac-update.hpp update/sparkle-updater.mm + update/models/branches.hpp) target_compile_definitions(obs PRIVATE ENABLE_SPARKLE_UPDATER) target_link_libraries(obs PRIVATE ${SPARKLE}) # Enable Automatic Reference Counting for Sparkle wrapper diff --git a/UI/cmake/os-windows.cmake b/UI/cmake/os-windows.cmake index 3a7b1843c..99b4254ad 100644 --- a/UI/cmake/os-windows.cmake +++ b/UI/cmake/os-windows.cmake @@ -28,6 +28,7 @@ target_sources( update/update-window.hpp update/win-update.cpp update/win-update.hpp + update/models/branches.hpp win-update/updater/manifest.hpp) target_link_libraries(obs-studio PRIVATE crypt32 OBS::blake2 OBS::w32-pthreads MbedTLS::MbedTLS diff --git a/UI/obs-app.cpp b/UI/obs-app.cpp index 77aabe005..02547d834 100644 --- a/UI/obs-app.cpp +++ b/UI/obs-app.cpp @@ -65,7 +65,7 @@ #endif #if defined(_WIN32) || defined(ENABLE_SPARKLE_UPDATER) -#include +#include "update/models/branches.hpp" #endif #if !defined(_WIN32) && !defined(__APPLE__) @@ -1289,28 +1289,31 @@ bool OBSApp::InitTheme() void ParseBranchesJson(const std::string &jsonString, vector &out, std::string &error) { - json11::Json root; - root = json11::Json::parse(jsonString, error); - if (!error.empty() || !root.is_array()) - return; + JsonBranches branches; - for (const json11::Json &item : root.array_items()) { + try { + nlohmann::json json = nlohmann::json::parse(jsonString); + branches = json.get(); + } catch (nlohmann::json::exception &e) { + error = e.what(); + return; + } + + for (const JsonBranch &json_branch : branches) { #ifdef _WIN32 - if (!item["windows"].bool_value()) + if (!json_branch.windows) continue; #elif defined(__APPLE__) - if (!item["macos"].bool_value()) + if (!json_branch.macos) continue; #endif UpdateBranch branch = { - QString::fromStdString(item["name"].string_value()), - QString::fromStdString( - item["display_name"].string_value()), - QString::fromStdString( - item["description"].string_value()), - item["enabled"].bool_value(), - item["visible"].bool_value(), + QString::fromStdString(json_branch.name), + QString::fromStdString(json_branch.display_name), + QString::fromStdString(json_branch.description), + json_branch.enabled, + json_branch.visible, }; out.push_back(branch); } diff --git a/UI/update/models/branches.hpp b/UI/update/models/branches.hpp new file mode 100644 index 000000000..eab488ab6 --- /dev/null +++ b/UI/update/models/branches.hpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023 Dennis Sädtler + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#pragma once + +#include +#include + +struct JsonBranch { + /* Internal name / ID of the branch (used in updater) */ + std::string name; + /* Human readable name */ + std::string display_name; + /* Description */ + std::string description; + /* Whether updating should use the branch if selected or fall back to stable */ + bool enabled = false; + /* Whether the branch should be displayed in the UI */ + bool visible = false; + /* OS compatibility */ + bool windows = false; + bool macos = false; + + NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(JsonBranch, name, + display_name, description, + enabled, visible, windows, + macos) +}; + +using JsonBranches = std::vector; From 89553386247eaded851df0bc6c1282533f507c7f Mon Sep 17 00:00:00 2001 From: derrod Date: Sun, 23 Jul 2023 08:42:40 +0200 Subject: [PATCH 4/4] UI: Migrate WhatsNew to nlohmann JSON --- UI/cmake/feature-macos-update.cmake | 3 +- UI/cmake/feature-whatsnew.cmake | 13 +++- UI/cmake/legacy.cmake | 7 ++- UI/cmake/os-windows.cmake | 1 + UI/update/models/whatsnew.hpp | 93 +++++++++++++++++++++++++++++ UI/window-basic-main.cpp | 45 +++++++------- 6 files changed, 132 insertions(+), 30 deletions(-) create mode 100644 UI/update/models/whatsnew.hpp diff --git a/UI/cmake/feature-macos-update.cmake b/UI/cmake/feature-macos-update.cmake index d31ce424d..4b4328c85 100644 --- a/UI/cmake/feature-macos-update.cmake +++ b/UI/cmake/feature-macos-update.cmake @@ -14,7 +14,8 @@ target_sources( update/shared-update.hpp update/update-helpers.cpp update/update-helpers.hpp - update/models/branches.hpp) + update/models/branches.hpp + update/models/whatsnew.hpp) target_link_libraries(obs-studio PRIVATE "$" nlohmann_json::nlohmann_json OBS::blake2) diff --git a/UI/cmake/feature-whatsnew.cmake b/UI/cmake/feature-whatsnew.cmake index a4d9be6d4..caa737f3a 100644 --- a/UI/cmake/feature-whatsnew.cmake +++ b/UI/cmake/feature-whatsnew.cmake @@ -5,11 +5,18 @@ if(ENABLE_WHATSNEW AND TARGET OBS::browser-panels) include(cmake/feature-macos-update.cmake) elseif(OS_LINUX) find_package(MbedTLS REQUIRED) - target_link_libraries(obs-studio PRIVATE MbedTLS::MbedTLS OBS::blake2) + find_package(nlohmann_json REQUIRED) + target_link_libraries(obs-studio PRIVATE MbedTLS::MbedTLS nlohmann_json::nlohmann_json OBS::blake2) target_sources( - obs-studio PRIVATE update/crypto-helpers-mbedtls.cpp update/crypto-helpers.hpp update/shared-update.cpp - update/shared-update.hpp update/update-helpers.cpp update/update-helpers.hpp) + obs-studio + PRIVATE update/crypto-helpers-mbedtls.cpp + update/crypto-helpers.hpp + update/shared-update.cpp + update/shared-update.hpp + update/update-helpers.cpp + update/update-helpers.hpp + update/models/whatsnew.hpp) endif() target_enable_feature(obs-studio "What's New panel" WHATSNEW_ENABLED) diff --git a/UI/cmake/legacy.cmake b/UI/cmake/legacy.cmake index aea502efe..99d4728d9 100644 --- a/UI/cmake/legacy.cmake +++ b/UI/cmake/legacy.cmake @@ -358,6 +358,7 @@ if(OS_WINDOWS) update/crypto-helpers-mbedtls.cpp update/crypto-helpers.hpp update/models/branches.hpp + update/models/whatsnew.hpp win-update/updater/manifest.hpp ${CMAKE_BINARY_DIR}/obs.rc) @@ -438,7 +439,8 @@ elseif(OS_MACOS) update/shared-update.cpp update/shared-update.hpp update/update-helpers.cpp - update/update-helpers.hpp) + update/update-helpers.hpp + update/models/whatsnew.hpp) if(SPARKLE_APPCAST_URL AND SPARKLE_PUBLIC_KEY) find_library(SPARKLE Sparkle) @@ -477,13 +479,14 @@ elseif(OS_POSIX) if(OS_LINUX AND ENABLE_WHATSNEW) find_package(MbedTLS) + find_package(nlohmann_json REQUIRED) if(NOT MBEDTLS_FOUND) obs_status(FATAL_ERROR "mbedTLS not found, but required for WhatsNew support on Linux") endif() target_sources(obs PRIVATE update/crypto-helpers.hpp update/crypto-helpers-mbedtls.cpp update/shared-update.cpp update/shared-update.hpp update/update-helpers.cpp update/update-helpers.hpp) - target_link_libraries(obs PRIVATE Mbedtls::Mbedtls OBS::blake2) + target_link_libraries(obs PRIVATE Mbedtls::Mbedtls nlohmann_json::nlohmann_json OBS::blake2) endif() endif() diff --git a/UI/cmake/os-windows.cmake b/UI/cmake/os-windows.cmake index 99b4254ad..645787f5f 100644 --- a/UI/cmake/os-windows.cmake +++ b/UI/cmake/os-windows.cmake @@ -29,6 +29,7 @@ target_sources( update/win-update.cpp update/win-update.hpp update/models/branches.hpp + update/models/whatsnew.hpp win-update/updater/manifest.hpp) target_link_libraries(obs-studio PRIVATE crypt32 OBS::blake2 OBS::w32-pthreads MbedTLS::MbedTLS diff --git a/UI/update/models/whatsnew.hpp b/UI/update/models/whatsnew.hpp new file mode 100644 index 000000000..59722ebf4 --- /dev/null +++ b/UI/update/models/whatsnew.hpp @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2023 Dennis Sädtler + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#pragma once + +#include +#include + +#include + +/* Ubuntu 22.04 be damned. */ +#ifndef NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT +#define NLOHMANN_JSON_FROM_WITH_DEFAULT(v1) \ + nlohmann_json_t.v1 = \ + nlohmann_json_j.value(#v1, nlohmann_json_default_obj.v1); + +#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Type, ...) \ + friend void to_json(nlohmann::json &nlohmann_json_j, \ + const Type &nlohmann_json_t) \ + { \ + NLOHMANN_JSON_EXPAND( \ + NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) \ + } \ + friend void from_json(const nlohmann::json &nlohmann_json_j, \ + Type &nlohmann_json_t) \ + { \ + Type nlohmann_json_default_obj; \ + NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE( \ + NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) \ + } + +#endif + +/* + * Support for (de-)serialising std::optional + * Adapted from https://github.com/nlohmann/json/issues/1749#issuecomment-1555093802 + */ +template struct nlohmann::adl_serializer> { + static std::optional from_json(const json &json) + { + return json.is_null() ? std::nullopt + : std::optional{json.get()}; + } + + static void to_json(json &json, std::optional t) + { + if (t) + json = *t; + else + json = nullptr; + } +}; + +struct WhatsNewPlatforms { + bool windows = false; + bool macos = false; + bool linux = false; + + NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(WhatsNewPlatforms, windows, + macos, linux) +}; + +struct WhatsNewItem { + /* Target OBS version (patch is ignored) */ + std::string version; + /* Beta/RC release to target */ + int Beta = 0; + int RC = 0; + /* URL of webpage to be displayed */ + std::string url; + /* Increment for this version's item */ + int increment = 0; + /* Optional OS filter */ + std::optional os = std::nullopt; + + NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(WhatsNewItem, version, Beta, + RC, url, increment, os) +}; + +using WhatsNewList = std::vector; diff --git a/UI/window-basic-main.cpp b/UI/window-basic-main.cpp index 80ff75d65..db2960917 100644 --- a/UI/window-basic-main.cpp +++ b/UI/window-basic-main.cpp @@ -97,13 +97,12 @@ #include -#include +#include "update/models/whatsnew.hpp" #ifdef ENABLE_WAYLAND #include #endif -using namespace json11; using namespace std; #ifdef BROWSER_AVAILABLE @@ -2397,54 +2396,52 @@ void OBSBasic::ReceivedIntroJson(const QString &text) if (closing) return; - std::string err; - Json json = Json::parse(QT_TO_UTF8(text), err); - if (!err.empty()) + WhatsNewList items; + try { + nlohmann::json json = nlohmann::json::parse(text.toStdString()); + items = json.get(); + } catch (nlohmann::json::exception &e) { + blog(LOG_WARNING, "Parsing whatsnew data failed: %s", e.what()); return; + } std::string info_url; int info_increment = -1; /* check to see if there's an info page for this version */ - const Json::array &items = json.array_items(); - for (const Json &item : items) { - if (item["os"].is_object()) { - Json::object platforms = item["os"].object_items(); + for (const WhatsNewItem &item : items) { + if (item.os) { + WhatsNewPlatforms platforms = *item.os; #ifdef _WIN32 - if (!platforms["windows"].bool_value()) + if (!platforms.windows) continue; #elif defined(__APPLE__) - if (!platforms["macos"].bool_value()) + if (!platforms.macos) continue; #else - if (!platforms["linux"].bool_value()) + if (!platforms.linux) continue; #endif } - const std::string &version = item["version"].string_value(); - const std::string &url = item["url"].string_value(); - int increment = item["increment"].int_value(); - int beta = item["Beta"].int_value(); - int rc = item["RC"].int_value(); - int major = 0; int minor = 0; - sscanf(version.c_str(), "%d.%d", &major, &minor); + sscanf(item.version.c_str(), "%d.%d", &major, &minor); #if defined(OBS_RELEASE_CANDIDATE) && OBS_RELEASE_CANDIDATE > 0 if (major == OBS_RELEASE_CANDIDATE_MAJOR && minor == OBS_RELEASE_CANDIDATE_MINOR && - rc == OBS_RELEASE_CANDIDATE) { + item.RC == OBS_RELEASE_CANDIDATE) { #elif OBS_BETA > 0 if (major == OBS_BETA_MAJOR && minor == OBS_BETA_MINOR && - beta == OBS_BETA) { + item.Beta == OBS_BETA) { #else if (major == LIBOBS_API_MAJOR_VER && - minor == LIBOBS_API_MINOR_VER && rc == 0 && beta == 0) { + minor == LIBOBS_API_MINOR_VER && item.RC == 0 && + item.Beta == 0) { #endif - info_url = url; - info_increment = increment; + info_url = item.url; + info_increment = item.increment; } }