-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
191 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using Squirrel; | ||
using System; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
|
||
namespace ProcessCpuUsageStatusWindow | ||
{ | ||
public static class UpdateCheck | ||
{ | ||
public enum UpdateStatus | ||
{ | ||
Checking, | ||
None, | ||
Downloading, | ||
Installing, | ||
Restarting | ||
} | ||
|
||
public delegate void UpdateStatusDelegate(UpdateStatus updateStatus, string message); | ||
|
||
public static Version LocalVersion => Assembly.GetEntryAssembly().GetName().Version; | ||
|
||
public static async Task<bool> CheckUpdate(UpdateStatusDelegate onUpdateStatus) | ||
{ | ||
try | ||
{ | ||
onUpdateStatus.Invoke(UpdateStatus.Checking, Properties.Resources.CheckingForUpdate); | ||
|
||
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; | ||
|
||
using (var updateManager = await UpdateManager.GitHubUpdateManager(App.UpdateUrl)) | ||
{ | ||
var updates = await updateManager.CheckForUpdate(); | ||
|
||
var lastVersion = updates?.ReleasesToApply?.OrderBy(releaseEntry => releaseEntry.Version).LastOrDefault(); | ||
|
||
if (lastVersion == null) | ||
{ | ||
onUpdateStatus.Invoke(UpdateStatus.None, Properties.Resources.NoUpdate); | ||
return false; | ||
} | ||
|
||
onUpdateStatus.Invoke(UpdateStatus.Downloading, Properties.Resources.DownloadingUpdate); | ||
|
||
Common.Settings.Extensions.BackupSettings(); | ||
|
||
await updateManager.DownloadReleases(new[] { lastVersion }); | ||
|
||
onUpdateStatus.Invoke(UpdateStatus.Installing, Properties.Resources.InstallingUpdate); | ||
|
||
await updateManager.ApplyReleases(updates); | ||
await updateManager.UpdateApp(); | ||
} | ||
|
||
onUpdateStatus.Invoke(UpdateStatus.Restarting, Properties.Resources.RestartingAfterUpdate); | ||
|
||
UpdateManager.RestartApp(); | ||
|
||
return true; | ||
} | ||
catch (Exception exception) | ||
{ | ||
Console.WriteLine(exception); | ||
|
||
return false; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters