From e9c0fce549ad36df7ec0fbb80841cdfe0cd82be1 Mon Sep 17 00:00:00 2001 From: Chris Kaczor Date: Thu, 22 Feb 2018 12:23:48 -0500 Subject: [PATCH] Attempt auto-update --- App.xaml.cs | 14 ++++++ ProcessCpuUsageStatusWindow.csproj | 38 +++++++++------- Properties/AssemblyInfo.cs | 2 + Properties/Resources.Designer.cs | 9 ++++ Properties/Resources.resx | 3 ++ WindowSource.cs | 72 +++++++++++++++++++++++------- packages.config | 2 +- 7 files changed, 106 insertions(+), 34 deletions(-) diff --git a/App.xaml.cs b/App.xaml.cs index 4768dab..39b40a8 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -1,7 +1,9 @@ using FloatingStatusWindowLibrary; using ProcessCpuUsageStatusWindow.Properties; +using System; using System.Diagnostics; using System.Windows; +using Squirrel; namespace ProcessCpuUsageStatusWindow { @@ -9,6 +11,18 @@ namespace ProcessCpuUsageStatusWindow { private WindowSource _windowSource; + public static string UpdateUrl = "https://github.com/ckaczor/ProcessCpuUsageStatusWindow"; + + [STAThread] + public static void Main(string[] args) + { + SquirrelAwareApp.HandleEvents(); + + var application = new App(); + application.InitializeComponent(); + application.Run(); + } + protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); diff --git a/ProcessCpuUsageStatusWindow.csproj b/ProcessCpuUsageStatusWindow.csproj index a66a084..66e8798 100644 --- a/ProcessCpuUsageStatusWindow.csproj +++ b/ProcessCpuUsageStatusWindow.csproj @@ -33,12 +33,16 @@ prompt 4 + + + + - - packages\FloatingStatusWindow.1.0.0.8\lib\net45\Common.Native.dll + + packages\FloatingStatusWindow.1.0.0.9\lib\net45\Common.Native.dll - - packages\FloatingStatusWindow.1.0.0.8\lib\net45\Common.Wpf.dll + + packages\FloatingStatusWindow.1.0.0.9\lib\net45\Common.Wpf.dll packages\DeltaCompressionDotNet.1.1.0\lib\net20\DeltaCompressionDotNet.dll @@ -49,14 +53,14 @@ packages\DeltaCompressionDotNet.1.1.0\lib\net20\DeltaCompressionDotNet.PatchApi.dll - - packages\FloatingStatusWindow.1.0.0.8\lib\net45\FloatingStatusWindowLibrary.dll + + packages\FloatingStatusWindow.1.0.0.9\lib\net45\FloatingStatusWindowLibrary.dll - packages\FloatingStatusWindow.1.0.0.8\lib\net45\Hardcodet.Wpf.TaskbarNotification.dll + packages\FloatingStatusWindow.1.0.0.9\lib\net45\Hardcodet.Wpf.TaskbarNotification.dll - packages\FloatingStatusWindow.1.0.0.8\lib\net45\Microsoft.Expression.Interactions.dll + packages\FloatingStatusWindow.1.0.0.9\lib\net45\Microsoft.Expression.Interactions.dll True @@ -86,7 +90,7 @@ - packages\FloatingStatusWindow.1.0.0.8\lib\net45\System.Windows.Interactivity.dll + packages\FloatingStatusWindow.1.0.0.9\lib\net45\System.Windows.Interactivity.dll True @@ -98,29 +102,29 @@ - packages\FloatingStatusWindow.1.0.0.8\lib\net45\Xceed.Wpf.AvalonDock.dll + packages\FloatingStatusWindow.1.0.0.9\lib\net45\Xceed.Wpf.AvalonDock.dll - packages\FloatingStatusWindow.1.0.0.8\lib\net45\Xceed.Wpf.AvalonDock.Themes.Aero.dll + packages\FloatingStatusWindow.1.0.0.9\lib\net45\Xceed.Wpf.AvalonDock.Themes.Aero.dll - packages\FloatingStatusWindow.1.0.0.8\lib\net45\Xceed.Wpf.AvalonDock.Themes.Metro.dll + packages\FloatingStatusWindow.1.0.0.9\lib\net45\Xceed.Wpf.AvalonDock.Themes.Metro.dll - packages\FloatingStatusWindow.1.0.0.8\lib\net45\Xceed.Wpf.AvalonDock.Themes.VS2010.dll + packages\FloatingStatusWindow.1.0.0.9\lib\net45\Xceed.Wpf.AvalonDock.Themes.VS2010.dll - packages\FloatingStatusWindow.1.0.0.8\lib\net45\Xceed.Wpf.DataGrid.dll + packages\FloatingStatusWindow.1.0.0.9\lib\net45\Xceed.Wpf.DataGrid.dll - packages\FloatingStatusWindow.1.0.0.8\lib\net45\Xceed.Wpf.Toolkit.dll + packages\FloatingStatusWindow.1.0.0.9\lib\net45\Xceed.Wpf.Toolkit.dll - + MSBuild:Compile Designer - + App.xaml Code diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index c7efd37..7add056 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -53,3 +53,5 @@ using System.Windows; // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] + +[assembly: AssemblyMetadata("SquirrelAwareVersion", "1")] \ No newline at end of file diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs index 28ed31e..73d0bb0 100644 --- a/Properties/Resources.Designer.cs +++ b/Properties/Resources.Designer.cs @@ -114,5 +114,14 @@ namespace ProcessCpuUsageStatusWindow.Properties { return ResourceManager.GetString("ProcessLine", resourceCulture); } } + + /// + /// Looks up a localized string similar to Updating application.... + /// + internal static string Updating { + get { + return ResourceManager.GetString("Updating", resourceCulture); + } + } } } diff --git a/Properties/Resources.resx b/Properties/Resources.resx index a7434f6..5c3204d 100644 --- a/Properties/Resources.resx +++ b/Properties/Resources.resx @@ -136,4 +136,7 @@ CPU: {1,4:f1}% - {0} + + Updating application... + \ No newline at end of file diff --git a/WindowSource.cs b/WindowSource.cs index 38e8987..66ebb18 100644 --- a/WindowSource.cs +++ b/WindowSource.cs @@ -1,12 +1,15 @@ -using System.Threading.Tasks; -using System.Windows.Threading; -using FloatingStatusWindowLibrary; +using FloatingStatusWindowLibrary; using ProcessCpuUsageStatusWindow.Properties; +using Squirrel; using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; -using Squirrel; +using System.Threading; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Threading; namespace ProcessCpuUsageStatusWindow { @@ -14,6 +17,7 @@ namespace ProcessCpuUsageStatusWindow { private readonly FloatingStatusWindow _floatingStatusWindow; private readonly ProcessCpuUsageWatcher _processCpuUsageWatcher; + private readonly Dispatcher _dispatcher = Dispatcher.CurrentDispatcher; internal WindowSource() { @@ -22,19 +26,47 @@ namespace ProcessCpuUsageStatusWindow _processCpuUsageWatcher = new ProcessCpuUsageWatcher(); - var dispatcher = Dispatcher.CurrentDispatcher; - Task.Factory.StartNew(() => _processCpuUsageWatcher.Initialize(Settings.Default.UpdateInterval, UpdateDisplay, dispatcher)); - - //CheckUpdate(); + Task.Factory.StartNew(UpdateApp); } - //private static async void CheckUpdate() - //{ - // using (var updateManager = UpdateManager.GitHubUpdateManager("https://github.com/ckaczor/ProcessCpuUsageStatusWindow")) - // { - // await updateManager.Result.UpdateApp(); - // } - //} + private async Task UpdateApp() + { + try + { + 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) + return; + + _dispatcher.Invoke(() => _floatingStatusWindow.SetText(Resources.Updating)); + Thread.Sleep(1000); + +#if !DEBUGr + await updateManager.DownloadReleases(new[] { lastVersion }); + await updateManager.ApplyReleases(updates); + await updateManager.UpdateApp(); + + Thread.Sleep(1000); +#endif + } + +#if !DEBUGr + UpdateManager.RestartApp(); +#endif + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + finally + { + await Task.Factory.StartNew(() => _processCpuUsageWatcher.Initialize(Settings.Default.UpdateInterval, UpdateDisplay, _dispatcher)); + } + } public void Dispose() { @@ -58,6 +90,14 @@ namespace ProcessCpuUsageStatusWindow public bool HasSettingsMenu => false; public bool HasRefreshMenu => false; + public bool HasAboutMenu => true; + + public void ShowAbout() + { + var version = Assembly.GetEntryAssembly().GetName().Version.ToString(); + + MessageBox.Show(version); + } public string WindowSettings { @@ -78,7 +118,7 @@ namespace ProcessCpuUsageStatusWindow } private void UpdateDisplay(Dictionary currentProcessList) - { + { // Filter the process list to valid ones and exclude the idle and total values var validProcessList = (currentProcessList.Values.Where( process => diff --git a/packages.config b/packages.config index aa9a7f6..55773b7 100644 --- a/packages.config +++ b/packages.config @@ -1,7 +1,7 @@  - +