updating: add support for prereleases (#8296)

This commit is contained in:
Andrey Nekrasov
2020-12-10 19:05:43 +03:00
committed by GitHub
parent 8a7824924a
commit 84932eb9da
9 changed files with 114 additions and 64 deletions

View File

@@ -22,6 +22,7 @@
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<Import Project="..\..\deps\expected.props" />
<ImportGroup Label="Shared" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>

View File

@@ -81,13 +81,14 @@ std::optional<std::wstring> dispatch_json_action_to_module(const json::JsonObjec
}
else if (action == L"check_for_updates")
{
std::wstring latestVersion = check_for_updates();
VersionHelper current_version(VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION);
bool isRunningLatest = latestVersion.compare(current_version.toWstring()) == 0;
auto new_version_info = check_for_updates();
const VersionHelper latestVersion =
new_version_info ? new_version_info->version :
VersionHelper{ VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION };
json::JsonObject json;
json.SetNamedValue(L"version", json::JsonValue::CreateStringValue(latestVersion));
json.SetNamedValue(L"isVersionLatest", json::JsonValue::CreateBooleanValue(isRunningLatest));
json.SetNamedValue(L"version", json::JsonValue::CreateStringValue(latestVersion.toWstring()));
json.SetNamedValue(L"isVersionLatest", json::JsonValue::CreateBooleanValue(!new_version_info));
result.emplace(json.Stringify());
}

View File

@@ -10,6 +10,7 @@
#include <common/timeutil.h>
#include <common/updating/installer.h>
#include <common/updating/updating.h>
#include <common/updating/notifications.h>
#include <runner/general_settings.h>
extern "C" IMAGE_DOS_HEADER __ImageBase;
@@ -74,17 +75,25 @@ void github_update_worker()
}
}
std::wstring check_for_updates()
std::optional<updating::new_version_download_info> check_for_updates()
{
try
{
return updating::check_new_version_available(Strings).get();
const auto new_version = updating::get_new_github_version_info_async(Strings).get();
if (!new_version)
{
updating::notifications::show_unavailable(Strings, std::move(new_version.error()));
return std::nullopt;
}
updating::notifications::show_available(new_version.value(), Strings);
return std::move(new_version.value());
}
catch (...)
{
// Couldn't autoupdate
return std::wstring();
}
return std::nullopt;
}
bool launch_pending_update()

View File

@@ -1,6 +1,8 @@
#pragma once
#include <common/updating/updating.h>
bool start_msi_uninstallation_sequence();
void github_update_worker();
std::wstring check_for_updates();
std::optional<updating::new_version_download_info> check_for_updates();
bool launch_pending_update();