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;