diff --git a/Options/AboutOptionsPanel.xaml b/Options/AboutOptionsPanel.xaml
index 09c7830..4789e7e 100644
--- a/Options/AboutOptionsPanel.xaml
+++ b/Options/AboutOptionsPanel.xaml
@@ -4,21 +4,43 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:windows="clr-namespace:Common.Wpf.Windows;assembly=Common.Wpf"
+ xmlns:properties="clr-namespace:ProcessCpuUsageStatusWindow.Properties"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="300">
+
+
+
+
+
+
+
+ FontWeight="Bold"
+ Grid.Row="0" />
+ VerticalAlignment="Top"
+ Grid.Row="1" />
+ VerticalAlignment="Top"
+ Grid.Row="2" />
+
+
+
+
diff --git a/Options/AboutOptionsPanel.xaml.cs b/Options/AboutOptionsPanel.xaml.cs
index 57fcb17..143fa84 100644
--- a/Options/AboutOptionsPanel.xaml.cs
+++ b/Options/AboutOptionsPanel.xaml.cs
@@ -1,5 +1,5 @@
-using Common.Update;
-using System.Reflection;
+using System.Reflection;
+using System.Windows;
namespace ProcessCpuUsageStatusWindow.Options
{
@@ -32,5 +32,10 @@ namespace ProcessCpuUsageStatusWindow.Options
}
public override string CategoryName => Properties.Resources.OptionCategory_About;
+
+ private async void HandleCheckForUpdateButtonClick(object sender, RoutedEventArgs e)
+ {
+ await UpdateCheck.CheckUpdate((status, message) => UpdateMessage.Content = message);
+ }
}
}
diff --git a/Options/GeneralOptionsPanel.xaml b/Options/GeneralOptionsPanel.xaml
index 8ec5671..886edcd 100644
--- a/Options/GeneralOptionsPanel.xaml
+++ b/Options/GeneralOptionsPanel.xaml
@@ -27,14 +27,16 @@
+ Margin="0,4,6,0"
+ Padding="0"
+ VerticalContentAlignment="Center" VerticalAlignment="Center" Target="{x:Reference NumberOfProcesses}" />
diff --git a/ProcessCpuUsageStatusWindow.csproj b/ProcessCpuUsageStatusWindow.csproj
index 2194ba7..510a436 100644
--- a/ProcessCpuUsageStatusWindow.csproj
+++ b/ProcessCpuUsageStatusWindow.csproj
@@ -136,6 +136,7 @@
GeneralOptionsPanel.xaml
+
MSBuild:Compile
diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs
index b79960b..35ce6fe 100644
--- a/Properties/Resources.Designer.cs
+++ b/Properties/Resources.Designer.cs
@@ -88,6 +88,33 @@ namespace ProcessCpuUsageStatusWindow.Properties {
}
}
+ ///
+ /// Looks up a localized string similar to Checking for update....
+ ///
+ public static string CheckingForUpdate {
+ get {
+ return ResourceManager.GetString("CheckingForUpdate", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to _Check for Update.
+ ///
+ public static string CheckUpdate {
+ get {
+ return ResourceManager.GetString("CheckUpdate", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string similar to Downloading update....
+ ///
+ public static string DownloadingUpdate {
+ get {
+ return ResourceManager.GetString("DownloadingUpdate", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to CPU: {0,4:f1}% - Total.
///
@@ -106,6 +133,15 @@ namespace ProcessCpuUsageStatusWindow.Properties {
}
}
+ ///
+ /// Looks up a localized string similar to Installing update....
+ ///
+ public static string InstallingUpdate {
+ get {
+ return ResourceManager.GetString("InstallingUpdate", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Loading....
///
@@ -115,6 +151,15 @@ namespace ProcessCpuUsageStatusWindow.Properties {
}
}
+ ///
+ /// Looks up a localized string similar to No update found.
+ ///
+ public static string NoUpdate {
+ get {
+ return ResourceManager.GetString("NoUpdate", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to _Number of processes:.
///
@@ -188,6 +233,15 @@ namespace ProcessCpuUsageStatusWindow.Properties {
}
}
+ ///
+ /// Looks up a localized string similar to Restarting application....
+ ///
+ public static string RestartingAfterUpdate {
+ get {
+ return ResourceManager.GetString("RestartingAfterUpdate", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to _Start when Windows starts.
///
diff --git a/Properties/Resources.resx b/Properties/Resources.resx
index bc38e56..f1c025c 100644
--- a/Properties/Resources.resx
+++ b/Properties/Resources.resx
@@ -127,15 +127,30 @@
Process CPU Usage
+
+ Checking for update...
+
+
+ _Check for Update
+
+
+ Downloading update...
+
CPU: {0,4:f1}% - Total
+
+ Installing update...
+
Loading...
+
+ No update found
+
_Number of processes:
@@ -166,4 +181,7 @@
Updating application...
+
+ Restarting application...
+
\ No newline at end of file
diff --git a/UpdateCheck.cs b/UpdateCheck.cs
new file mode 100644
index 0000000..212612d
--- /dev/null
+++ b/UpdateCheck.cs
@@ -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 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;
+ }
+ }
+ }
+}
diff --git a/WindowSource.cs b/WindowSource.cs
index 8d5a188..ba22f24 100644
--- a/WindowSource.cs
+++ b/WindowSource.cs
@@ -42,45 +42,15 @@ namespace ProcessCpuUsageStatusWindow
private async Task UpdateApp()
{
- try
- {
- ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
+ return await UpdateCheck.CheckUpdate(HandleUpdateStatus);
+ }
- using (var updateManager = await UpdateManager.GitHubUpdateManager(App.UpdateUrl))
- {
- var updates = await updateManager.CheckForUpdate();
+ private void HandleUpdateStatus(UpdateCheck.UpdateStatus status, string message)
+ {
+ if (status == UpdateCheck.UpdateStatus.None)
+ message = Resources.Loading;
- var lastVersion = updates?.ReleasesToApply?.OrderBy(releaseEntry => releaseEntry.Version).LastOrDefault();
-
- if (lastVersion == null)
- return false;
-
- _dispatcher.Invoke(() => _floatingStatusWindow.SetText(Resources.Updating));
- Thread.Sleep(500);
-
- Common.Settings.Extensions.BackupSettings();
-
-#if !DEBUG
- await updateManager.DownloadReleases(new[] { lastVersion });
- await updateManager.ApplyReleases(updates);
- await updateManager.UpdateApp();
-#endif
- }
-
-#if !DEBUG
- _dispatcher.Invoke(Dispose);
-
- UpdateManager.RestartApp();
-#endif
-
- return true;
- }
- catch (Exception exception)
- {
- Console.WriteLine(exception);
-
- return false;
- }
+ _dispatcher.Invoke(() => _floatingStatusWindow.SetText(message));
}
public void Dispose()