36 lines
1.4 KiB
C++
36 lines
1.4 KiB
C++
#pragma once
|
|
#include <istream>
|
|
#include <map>
|
|
#include <string>
|
|
#include <string_view>
|
|
namespace gateway::client_update {
|
|
enum class State { unknown, current, pending };
|
|
inline State compare_signatures(bool remote_ok, std::string_view remote,
|
|
bool local_ok, std::string_view local) {
|
|
if (!remote_ok || !local_ok || remote.empty() || local.empty()) return State::unknown;
|
|
return remote == local ? State::current : State::pending;
|
|
}
|
|
using Config = std::map<std::string, std::string>;
|
|
// Shared with OctoUpdater: preserve its exact key/value and comment semantics.
|
|
inline Config read_config(std::istream& in) {
|
|
Config c{{"url", "https://dl.hybridgateway.eu/"}, {"channel", "octo"},
|
|
{"launch", "1"}, {"p2p", "1"}};
|
|
for (std::string line; std::getline(in, line);) {
|
|
if (!line.empty() && line.back() == '\r') line.pop_back();
|
|
auto equal = line.find('=');
|
|
if (equal != std::string::npos && line[0] != '#')
|
|
c[line.substr(0, equal)] = line.substr(equal + 1);
|
|
}
|
|
return c;
|
|
}
|
|
inline std::string manifest_url(const Config& c) {
|
|
auto base = c.at("url");
|
|
if (base.empty()) return {};
|
|
if (base.back() != '/') base += '/';
|
|
return base + c.at("channel") + "/manifest.txt.sig";
|
|
}
|
|
inline bool should_launch(const Config& c, bool explicit_launch, bool no_launch) {
|
|
return !no_launch && (explicit_launch || c.at("launch") != "0");
|
|
}
|
|
}
|