2023-02-28 01:15:26 +00:00
|
|
|
// AUTOGENERATED COPYRIGHT HEADER START
|
|
|
|
// Copyright (C) 2020-2023 Michael Fabian 'Xaymar' Dirks <info@xaymar.com>
|
|
|
|
// AUTOGENERATED COPYRIGHT HEADER END
|
2020-09-09 03:06:15 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include "util/util-curl.hpp"
|
|
|
|
#include "util/util-event.hpp"
|
|
|
|
#include "util/util-threadpool.hpp"
|
|
|
|
|
2022-08-29 10:29:44 +00:00
|
|
|
#include "warning-disable.hpp"
|
|
|
|
#include <atomic>
|
|
|
|
#include <chrono>
|
|
|
|
#include <map>
|
2022-08-28 12:28:37 +00:00
|
|
|
#include <nlohmann/json.hpp>
|
2022-08-29 10:29:44 +00:00
|
|
|
#include "warning-enable.hpp"
|
2022-08-28 12:28:37 +00:00
|
|
|
|
2020-09-09 03:06:15 +00:00
|
|
|
namespace streamfx {
|
2022-06-11 06:02:41 +00:00
|
|
|
enum class version_stage : uint8_t {
|
2023-05-13 12:35:46 +00:00
|
|
|
STABLE, // A.B.C
|
2022-06-11 06:02:41 +00:00
|
|
|
CANDIDATE, // A.B.CcD
|
2023-05-13 12:35:46 +00:00
|
|
|
BETA, // A.B.CbD
|
|
|
|
ALPHA, // A.B.CaD
|
2020-09-09 03:06:15 +00:00
|
|
|
};
|
2022-06-11 06:02:41 +00:00
|
|
|
version_stage stage_from_string(std::string_view str);
|
|
|
|
std::string_view stage_to_string(version_stage t);
|
2020-09-09 03:06:15 +00:00
|
|
|
|
2022-06-11 06:02:41 +00:00
|
|
|
void to_json(nlohmann::json&, const version_stage&);
|
|
|
|
void from_json(const nlohmann::json&, version_stage&);
|
|
|
|
|
|
|
|
struct version_info {
|
|
|
|
public:
|
|
|
|
uint16_t major;
|
|
|
|
uint16_t minor;
|
|
|
|
uint16_t patch;
|
|
|
|
uint16_t tweak;
|
|
|
|
version_stage stage;
|
|
|
|
std::string url;
|
|
|
|
std::string name;
|
|
|
|
|
|
|
|
public:
|
|
|
|
version_info();
|
|
|
|
version_info(const std::string text);
|
|
|
|
|
|
|
|
bool is_older_than(const version_info other);
|
|
|
|
|
|
|
|
operator std::string();
|
2020-09-09 03:06:15 +00:00
|
|
|
};
|
|
|
|
|
2022-06-11 06:02:41 +00:00
|
|
|
void to_json(nlohmann::json&, const version_info&);
|
|
|
|
void from_json(const nlohmann::json&, version_info&);
|
2020-09-09 03:06:15 +00:00
|
|
|
|
|
|
|
class updater {
|
|
|
|
// Internal
|
2022-06-11 06:02:41 +00:00
|
|
|
std::recursive_mutex _lock;
|
2021-06-08 02:18:02 +00:00
|
|
|
std::weak_ptr<::streamfx::util::threadpool::task> _task;
|
2020-09-09 03:06:15 +00:00
|
|
|
|
|
|
|
// Options
|
2022-06-11 06:02:41 +00:00
|
|
|
std::atomic_bool _data_sharing_allowed;
|
2020-09-09 03:06:15 +00:00
|
|
|
std::atomic_bool _automation;
|
2022-06-11 06:02:41 +00:00
|
|
|
version_stage _channel;
|
2020-09-09 03:06:15 +00:00
|
|
|
std::chrono::seconds _lastcheckedat;
|
|
|
|
|
|
|
|
// Update Information
|
2022-06-11 06:02:41 +00:00
|
|
|
version_info _current_info;
|
|
|
|
std::map<version_stage, version_info> _updates;
|
|
|
|
bool _dirty;
|
2020-09-09 03:06:15 +00:00
|
|
|
|
|
|
|
private:
|
2022-09-18 16:30:15 +00:00
|
|
|
void task(streamfx::util::threadpool::task_data_t);
|
2020-09-09 03:06:15 +00:00
|
|
|
|
|
|
|
bool can_check();
|
|
|
|
|
|
|
|
void load();
|
|
|
|
void save();
|
|
|
|
|
|
|
|
public:
|
|
|
|
updater();
|
|
|
|
~updater();
|
|
|
|
|
|
|
|
// GDPR compliance (must require user interaction!)
|
2022-06-11 06:02:41 +00:00
|
|
|
bool is_data_sharing_allowed();
|
|
|
|
void set_data_sharing_allowed(bool);
|
2020-09-09 03:06:15 +00:00
|
|
|
|
|
|
|
// Automatic Update checks
|
2022-06-11 06:02:41 +00:00
|
|
|
bool is_automated();
|
2020-09-09 03:06:15 +00:00
|
|
|
void set_automation(bool);
|
|
|
|
|
|
|
|
// Update Channel
|
2022-06-11 06:02:41 +00:00
|
|
|
version_stage get_channel();
|
|
|
|
void set_channel(version_stage channel);
|
2020-09-09 03:06:15 +00:00
|
|
|
|
|
|
|
// Refresh information.
|
|
|
|
void refresh();
|
|
|
|
|
|
|
|
// Check current data.
|
2022-06-11 06:02:41 +00:00
|
|
|
version_info get_current_info();
|
|
|
|
|
|
|
|
// Check update data.
|
|
|
|
bool is_update_available();
|
|
|
|
bool is_update_available(version_stage channel);
|
|
|
|
version_info get_update_info();
|
|
|
|
version_info get_update_info(version_stage channel);
|
2020-09-09 03:06:15 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
struct _ {
|
2022-06-11 06:02:41 +00:00
|
|
|
streamfx::util::event<updater&, bool> gdpr_changed;
|
|
|
|
streamfx::util::event<updater&, bool> automation_changed;
|
|
|
|
streamfx::util::event<updater&, version_stage> channel_changed;
|
2020-09-09 03:06:15 +00:00
|
|
|
|
2021-06-08 02:18:02 +00:00
|
|
|
streamfx::util::event<updater&, std::string&> error;
|
|
|
|
streamfx::util::event<updater&> refreshed;
|
2020-09-09 03:06:15 +00:00
|
|
|
} events;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static std::shared_ptr<streamfx::updater> instance();
|
|
|
|
};
|
|
|
|
} // namespace streamfx
|