mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-03 05:57:40 -05:00
feat: Ask the users if they want to check for updates (#803)
* ask the users for updates * Only treat 1 as enabled * Fix formatting * update locales * comment to document value
This commit is contained in:
@@ -25,23 +25,27 @@ namespace hex::init {
|
||||
using namespace std::literals::string_literals;
|
||||
|
||||
static bool checkForUpdates() {
|
||||
hex::Net net;
|
||||
// documentation of the value above the setting definition
|
||||
int showCheckForUpdates = ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.check_for_updates", 2);
|
||||
if (showCheckForUpdates == 1){
|
||||
hex::Net net;
|
||||
|
||||
auto releases = net.getJson(GitHubApiURL + "/releases/latest"s, 2000).get();
|
||||
if (releases.code != 200)
|
||||
return false;
|
||||
auto releases = net.getJson(GitHubApiURL + "/releases/latest"s, 2000).get();
|
||||
if (releases.code != 200)
|
||||
return false;
|
||||
|
||||
if (!releases.body.contains("tag_name") || !releases.body["tag_name"].is_string())
|
||||
return false;
|
||||
if (!releases.body.contains("tag_name") || !releases.body["tag_name"].is_string())
|
||||
return false;
|
||||
|
||||
auto versionString = std::string(IMHEX_VERSION);
|
||||
size_t versionLength = std::min(versionString.find_first_of('-'), versionString.length());
|
||||
auto currVersion = "v" + versionString.substr(0, versionLength);
|
||||
auto latestVersion = releases.body["tag_name"].get<std::string_view>();
|
||||
auto versionString = std::string(IMHEX_VERSION);
|
||||
size_t versionLength = std::min(versionString.find_first_of('-'), versionString.length());
|
||||
auto currVersion = "v" + versionString.substr(0, versionLength);
|
||||
auto latestVersion = releases.body["tag_name"].get<std::string_view>();
|
||||
|
||||
if (latestVersion != currVersion)
|
||||
ImHexApi::System::impl::addInitArgument("update-available", latestVersion.data());
|
||||
if (latestVersion != currVersion)
|
||||
ImHexApi::System::impl::addInitArgument("update-available", latestVersion.data());
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user