Skip to content

Commit

Permalink
Merge pull request #245 from taooceros/InformUserWhenUpdateFail
Browse files Browse the repository at this point in the history
Inform user when checking update fail
  • Loading branch information
jjw24 authored Dec 31, 2020
2 parents fd32d36 + 47bae47 commit 5f345e1
Showing 1 changed file with 43 additions and 64 deletions.
107 changes: 43 additions & 64 deletions Flow.Launcher.Core/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,86 +31,65 @@ public Updater(string gitHubRepository)

public async Task UpdateApp(IPublicAPI api, bool silentUpdate = true)
{
UpdateManager updateManager;
UpdateInfo newUpdateInfo;

if (!silentUpdate)
api.ShowMsg("Please wait...", "Checking for new update");

try
{
updateManager = await GitHubUpdateManager(GitHubRepository).ConfigureAwait(false);
}
catch (Exception e) when (e is HttpRequestException || e is WebException || e is SocketException)
{
Log.Exception($"|Updater.UpdateApp|Please check your connection and proxy settings to api.github.com.", e);
return;
}
UpdateInfo newUpdateInfo;

if (!silentUpdate)
api.ShowMsg("Please wait...", "Checking for new update");

using var updateManager = await GitHubUpdateManager(GitHubRepository).ConfigureAwait(false);


try
{
// UpdateApp CheckForUpdate will return value only if the app is squirrel installed
newUpdateInfo = await updateManager.CheckForUpdate().NonNull().ConfigureAwait(false);
}
catch (Exception e) when (e is HttpRequestException || e is WebException || e is SocketException)
{
Log.Exception($"|Updater.UpdateApp|Check your connection and proxy settings to api.github.com.", e);
updateManager.Dispose();
return;
}

var newReleaseVersion = Version.Parse(newUpdateInfo.FutureReleaseEntry.Version.ToString());
var currentVersion = Version.Parse(Constant.Version);
var newReleaseVersion = Version.Parse(newUpdateInfo.FutureReleaseEntry.Version.ToString());
var currentVersion = Version.Parse(Constant.Version);

Log.Info($"|Updater.UpdateApp|Future Release <{newUpdateInfo.FutureReleaseEntry.Formatted()}>");

if (newReleaseVersion <= currentVersion)
{
if (!silentUpdate)
MessageBox.Show("You already have the latest Flow Launcher version");
updateManager.Dispose();
return;
}
Log.Info($"|Updater.UpdateApp|Future Release <{newUpdateInfo.FutureReleaseEntry.Formatted()}>");

if (!silentUpdate)
api.ShowMsg("Update found", "Updating...");
if (newReleaseVersion <= currentVersion)
{
if (!silentUpdate)
MessageBox.Show("You already have the latest Flow Launcher version");
return;
}

try
{
await updateManager.DownloadReleases(newUpdateInfo.ReleasesToApply);
}
catch (Exception e) when (e is HttpRequestException || e is WebException || e is SocketException)
{
Log.Exception($"|Updater.UpdateApp|Check your connection and proxy settings to github-cloud.s3.amazonaws.com.", e);
updateManager.Dispose();
return;
}
if (!silentUpdate)
api.ShowMsg("Update found", "Updating...");

await updateManager.ApplyReleases(newUpdateInfo).ConfigureAwait(false);
await updateManager.DownloadReleases(newUpdateInfo.ReleasesToApply).ConfigureAwait(false);

if (DataLocation.PortableDataLocationInUse())
{
var targetDestination = updateManager.RootAppDirectory + $"\\app-{newReleaseVersion.ToString()}\\{DataLocation.PortableFolderName}";
FilesFolders.CopyAll(DataLocation.PortableDataPath, targetDestination);
if (!FilesFolders.VerifyBothFolderFilesEqual(DataLocation.PortableDataPath, targetDestination))
MessageBox.Show("Flow Launcher was not able to move your user profile data to the new update version. Please manually " +
$"move your profile data folder from {DataLocation.PortableDataPath} to {targetDestination}");
}
else
{
await updateManager.CreateUninstallerRegistryEntry().ConfigureAwait(false);
}
await updateManager.ApplyReleases(newUpdateInfo).ConfigureAwait(false);

var newVersionTips = NewVersinoTips(newReleaseVersion.ToString());
if (DataLocation.PortableDataLocationInUse())
{
var targetDestination = updateManager.RootAppDirectory + $"\\app-{newReleaseVersion.ToString()}\\{DataLocation.PortableFolderName}";
FilesFolders.CopyAll(DataLocation.PortableDataPath, targetDestination);
if (!FilesFolders.VerifyBothFolderFilesEqual(DataLocation.PortableDataPath, targetDestination))
MessageBox.Show("Flow Launcher was not able to move your user profile data to the new update version. Please manually " +
$"move your profile data folder from {DataLocation.PortableDataPath} to {targetDestination}");
}
else
{
await updateManager.CreateUninstallerRegistryEntry().ConfigureAwait(false);
}

Log.Info($"|Updater.UpdateApp|Update success:{newVersionTips}");
var newVersionTips = NewVersinoTips(newReleaseVersion.ToString());

// always dispose UpdateManager
updateManager.Dispose();
Log.Info($"|Updater.UpdateApp|Update success:{newVersionTips}");

if (MessageBox.Show(newVersionTips, "New Update", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
if (MessageBox.Show(newVersionTips, "New Update", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
UpdateManager.RestartApp(Constant.ApplicationFileName);
}
}
catch (Exception e) when (e is HttpRequestException || e is WebException || e is SocketException)
{
UpdateManager.RestartApp(Constant.ApplicationFileName);
Log.Exception($"|Updater.UpdateApp|Check your connection and proxy settings to github-cloud.s3.amazonaws.com.", e);
api.ShowMsg("Update Failed", "Check your connection and try updating proxy settings to github-cloud.s3.amazonaws.com.");
return;
}
}

Expand Down

0 comments on commit 5f345e1

Please sign in to comment.