2022-08-09 00:35:38 +00:00
|
|
|
|
using System;
|
2017-03-07 19:23:42 +00:00
|
|
|
|
using System.Collections.Generic;
|
2024-03-24 18:41:07 +00:00
|
|
|
|
using System.IO;
|
2016-05-09 19:40:59 +00:00
|
|
|
|
using System.Net;
|
2016-05-10 18:24:15 +00:00
|
|
|
|
using System.Net.Http;
|
|
|
|
|
|
using System.Net.Sockets;
|
2017-03-07 19:23:42 +00:00
|
|
|
|
using System.Linq;
|
2016-05-09 19:40:59 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2017-03-06 00:25:17 +00:00
|
|
|
|
using System.Windows;
|
2017-03-07 19:37:38 +00:00
|
|
|
|
using JetBrains.Annotations;
|
2020-04-21 09:12:17 +00:00
|
|
|
|
using Flow.Launcher.Core.Resource;
|
|
|
|
|
|
using Flow.Launcher.Plugin.SharedCommands;
|
|
|
|
|
|
using Flow.Launcher.Infrastructure;
|
|
|
|
|
|
using Flow.Launcher.Infrastructure.Http;
|
|
|
|
|
|
using Flow.Launcher.Infrastructure.Logger;
|
|
|
|
|
|
using Flow.Launcher.Infrastructure.UserSettings;
|
2020-07-05 22:00:22 +00:00
|
|
|
|
using Flow.Launcher.Plugin;
|
2020-12-29 10:33:53 +00:00
|
|
|
|
using System.Text.Json.Serialization;
|
2021-10-09 16:34:41 +00:00
|
|
|
|
using System.Threading;
|
2024-03-24 18:41:07 +00:00
|
|
|
|
using System.Windows.Shapes;
|
2024-03-23 23:00:32 +00:00
|
|
|
|
using Velopack;
|
2024-03-24 18:41:07 +00:00
|
|
|
|
using Velopack.Locators;
|
2024-03-23 23:00:32 +00:00
|
|
|
|
using Velopack.Sources;
|
2024-03-24 18:41:07 +00:00
|
|
|
|
using Path = System.IO.Path;
|
2016-05-09 19:40:59 +00:00
|
|
|
|
|
2020-04-21 09:12:17 +00:00
|
|
|
|
namespace Flow.Launcher.Core
|
2016-05-09 19:40:59 +00:00
|
|
|
|
{
|
2020-01-07 00:34:46 +00:00
|
|
|
|
public class Updater
|
2016-05-09 19:40:59 +00:00
|
|
|
|
{
|
2020-01-07 00:34:46 +00:00
|
|
|
|
public string GitHubRepository { get; }
|
2017-03-26 23:08:56 +00:00
|
|
|
|
|
2020-01-07 00:34:46 +00:00
|
|
|
|
public Updater(string gitHubRepository)
|
|
|
|
|
|
{
|
|
|
|
|
|
GitHubRepository = gitHubRepository;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-10-09 16:34:41 +00:00
|
|
|
|
private SemaphoreSlim UpdateLock { get; } = new SemaphoreSlim(1);
|
|
|
|
|
|
|
2022-12-01 09:58:31 +00:00
|
|
|
|
public async Task UpdateAppAsync(IPublicAPI api, bool silentUpdate = true)
|
2016-05-09 19:40:59 +00:00
|
|
|
|
{
|
2023-01-04 04:23:56 +00:00
|
|
|
|
await UpdateLock.WaitAsync().ConfigureAwait(false);
|
2016-05-09 19:40:59 +00:00
|
|
|
|
try
|
|
|
|
|
|
{
|
2020-12-20 09:44:46 +00:00
|
|
|
|
if (!silentUpdate)
|
2021-01-23 04:20:52 +00:00
|
|
|
|
api.ShowMsg(api.GetTranslation("pleaseWait"),
|
2021-10-09 16:34:41 +00:00
|
|
|
|
api.GetTranslation("update_flowlauncher_update_check"));
|
2020-12-20 09:44:46 +00:00
|
|
|
|
|
2024-03-23 23:00:32 +00:00
|
|
|
|
var updateManager = new UpdateManager(new GithubSource(GitHubRepository, null, false));
|
2020-12-20 09:44:46 +00:00
|
|
|
|
|
2017-03-26 23:08:56 +00:00
|
|
|
|
// UpdateApp CheckForUpdate will return value only if the app is squirrel installed
|
2024-03-23 23:00:32 +00:00
|
|
|
|
var newUpdateInfo = await updateManager.CheckForUpdatesAsync().ConfigureAwait(false);
|
2016-05-09 19:40:59 +00:00
|
|
|
|
|
2024-03-23 23:00:32 +00:00
|
|
|
|
if (newUpdateInfo == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!silentUpdate)
|
|
|
|
|
|
api.ShowMsg(api.GetTranslation("update_flowlauncher_fail"),
|
|
|
|
|
|
api.GetTranslation("update_flowlauncher_check_connection"));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2024-03-24 18:41:07 +00:00
|
|
|
|
|
2024-03-23 23:00:32 +00:00
|
|
|
|
var newReleaseVersion = Version.Parse(newUpdateInfo.TargetFullRelease.Version.ToString());
|
2020-12-20 09:44:46 +00:00
|
|
|
|
var currentVersion = Version.Parse(Constant.Version);
|
2016-05-09 19:40:59 +00:00
|
|
|
|
|
2024-03-23 23:00:32 +00:00
|
|
|
|
Log.Info($"|Updater.UpdateApp|Future Release <{newUpdateInfo.TargetFullRelease.Formatted()}>");
|
2020-07-05 22:00:22 +00:00
|
|
|
|
|
2020-12-20 09:44:46 +00:00
|
|
|
|
if (newReleaseVersion <= currentVersion)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!silentUpdate)
|
2021-01-23 04:20:52 +00:00
|
|
|
|
MessageBox.Show(api.GetTranslation("update_flowlauncher_already_on_latest"));
|
2020-12-20 09:44:46 +00:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2020-07-05 22:00:22 +00:00
|
|
|
|
|
2020-12-20 09:44:46 +00:00
|
|
|
|
if (!silentUpdate)
|
2021-01-23 04:20:52 +00:00
|
|
|
|
api.ShowMsg(api.GetTranslation("update_flowlauncher_update_found"),
|
2021-10-09 16:34:41 +00:00
|
|
|
|
api.GetTranslation("update_flowlauncher_updating"));
|
2020-12-29 09:54:39 +00:00
|
|
|
|
|
2024-03-23 23:00:32 +00:00
|
|
|
|
await updateManager.DownloadUpdatesAsync(newUpdateInfo).ConfigureAwait(false);
|
2020-02-25 10:08:51 +00:00
|
|
|
|
|
2020-12-20 09:44:46 +00:00
|
|
|
|
if (DataLocation.PortableDataLocationInUse())
|
|
|
|
|
|
{
|
2024-03-24 18:41:07 +00:00
|
|
|
|
var targetDestination = Path.Combine(VelopackLocator.GetDefault(null).RootAppDir!,
|
|
|
|
|
|
DataLocation.PortableFolderName);
|
|
|
|
|
|
|
|
|
|
|
|
DataLocation.PortableDataPath.CopyAll(targetDestination);
|
|
|
|
|
|
if (!DataLocation.PortableDataPath.VerifyBothFolderFilesEqual(targetDestination))
|
2024-03-23 23:00:32 +00:00
|
|
|
|
MessageBox.Show(string.Format(
|
|
|
|
|
|
api.GetTranslation("update_flowlauncher_fail_moving_portable_user_profile_data"),
|
2021-10-09 16:34:41 +00:00
|
|
|
|
DataLocation.PortableDataPath,
|
|
|
|
|
|
targetDestination));
|
2020-12-20 09:44:46 +00:00
|
|
|
|
}
|
2020-12-29 09:54:39 +00:00
|
|
|
|
|
2022-10-30 19:23:04 +00:00
|
|
|
|
var newVersionTips = NewVersionTips(newReleaseVersion.ToString());
|
2020-02-25 10:08:51 +00:00
|
|
|
|
|
2020-12-20 09:44:46 +00:00
|
|
|
|
Log.Info($"|Updater.UpdateApp|Update success:{newVersionTips}");
|
2020-07-05 22:00:22 +00:00
|
|
|
|
|
2024-03-23 23:00:32 +00:00
|
|
|
|
if (MessageBox.Show(newVersionTips, api.GetTranslation("update_flowlauncher_new_update"),
|
|
|
|
|
|
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
2020-12-20 09:44:46 +00:00
|
|
|
|
{
|
2024-03-24 18:41:07 +00:00
|
|
|
|
updateManager.ApplyUpdatesAndRestart(newUpdateInfo);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
updateManager.WaitExitThenApplyUpdates(newUpdateInfo);
|
2020-12-20 09:44:46 +00:00
|
|
|
|
}
|
2020-02-25 10:08:51 +00:00
|
|
|
|
}
|
2023-01-04 04:23:56 +00:00
|
|
|
|
catch (Exception e)
|
2020-07-05 22:00:22 +00:00
|
|
|
|
{
|
2024-03-23 23:00:32 +00:00
|
|
|
|
if ((e is HttpRequestException or WebException or SocketException ||
|
|
|
|
|
|
e.InnerException is TimeoutException))
|
|
|
|
|
|
Log.Exception(
|
|
|
|
|
|
$"|Updater.UpdateApp|Check your connection and proxy settings to github-cloud.s3.amazonaws.com.",
|
|
|
|
|
|
e);
|
2023-01-04 04:23:56 +00:00
|
|
|
|
else
|
|
|
|
|
|
Log.Exception($"|Updater.UpdateApp|Error Occurred", e);
|
2024-03-23 23:00:32 +00:00
|
|
|
|
|
2021-12-19 17:37:27 +00:00
|
|
|
|
if (!silentUpdate)
|
|
|
|
|
|
api.ShowMsg(api.GetTranslation("update_flowlauncher_fail"),
|
|
|
|
|
|
api.GetTranslation("update_flowlauncher_check_connection"));
|
2021-10-09 16:34:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
finally
|
|
|
|
|
|
{
|
|
|
|
|
|
UpdateLock.Release();
|
2020-07-05 22:00:22 +00:00
|
|
|
|
}
|
2017-03-06 01:30:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-24 18:41:07 +00:00
|
|
|
|
public static void RecoverPortableData()
|
2017-03-07 19:23:42 +00:00
|
|
|
|
{
|
2024-03-24 18:41:07 +00:00
|
|
|
|
var locator = VelopackLocator.GetDefault(null);
|
2017-03-07 19:23:42 +00:00
|
|
|
|
|
2024-03-24 18:41:07 +00:00
|
|
|
|
var portableDataLocation = Path.Combine(VelopackLocator.GetDefault(null).RootAppDir!,
|
|
|
|
|
|
DataLocation.PortableFolderName);
|
|
|
|
|
|
|
|
|
|
|
|
if (Path.Exists(portableDataLocation))
|
|
|
|
|
|
{
|
|
|
|
|
|
portableDataLocation.CopyAll(Path.Combine(locator.AppContentDir!, DataLocation.PortableFolderName));
|
|
|
|
|
|
}
|
2017-03-07 19:23:42 +00:00
|
|
|
|
|
2024-03-24 18:41:07 +00:00
|
|
|
|
Directory.Delete(portableDataLocation);
|
2016-05-09 19:40:59 +00:00
|
|
|
|
}
|
2017-03-06 00:25:17 +00:00
|
|
|
|
|
2022-10-30 19:23:04 +00:00
|
|
|
|
public string NewVersionTips(string version)
|
2017-03-06 00:25:17 +00:00
|
|
|
|
{
|
2022-10-30 19:23:04 +00:00
|
|
|
|
var translator = InternationalizationManager.Instance;
|
|
|
|
|
|
var tips = string.Format(translator.GetTranslation("newVersionTips"), version);
|
|
|
|
|
|
|
2017-03-06 00:25:17 +00:00
|
|
|
|
return tips;
|
|
|
|
|
|
}
|
2016-05-09 19:40:59 +00:00
|
|
|
|
}
|
2022-08-09 00:35:38 +00:00
|
|
|
|
}
|