From 320f8c12cc4e139b8aaa106b6b7735d2343c3852 Mon Sep 17 00:00:00 2001 From: poroh-kun Date: Fri, 12 Mar 2021 16:17:23 +0300 Subject: [PATCH] updating setup --- ValheimMjod/App.xaml | 3 +- ValheimMjod/App.xaml.cs | 16 +++--- ValheimMjod/Properties/AssemblyInfo.cs | 6 +- ValheimMjod/Updater.cs | 80 ++++++++++++++++++++++++++ ValheimMjod/ValheimMjod.csproj | 9 +++ ValheimMjod/ValheimMjod.nuspec | 17 ++++++ 6 files changed, 118 insertions(+), 13 deletions(-) create mode 100644 ValheimMjod/Updater.cs create mode 100644 ValheimMjod/ValheimMjod.nuspec diff --git a/ValheimMjod/App.xaml b/ValheimMjod/App.xaml index 5fabf41..09efcc0 100644 --- a/ValheimMjod/App.xaml +++ b/ValheimMjod/App.xaml @@ -2,8 +2,7 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:ValheimMjod" - xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" - StartupUri="MainWindow.xaml"> + xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"> diff --git a/ValheimMjod/App.xaml.cs b/ValheimMjod/App.xaml.cs index 68817ff..7d2f97b 100644 --- a/ValheimMjod/App.xaml.cs +++ b/ValheimMjod/App.xaml.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Configuration; -using System.Data; -using System.Linq; -using System.Threading.Tasks; -using System.Windows; +using System.Windows; namespace ValheimMjod { @@ -13,5 +7,13 @@ namespace ValheimMjod /// public partial class App : Application { + Updater _updater; + protected override void OnStartup(StartupEventArgs e) + { + var window = new MainWindow(); + window.Show(); + _updater = new Updater(); + base.OnStartup(e); + } } } diff --git a/ValheimMjod/Properties/AssemblyInfo.cs b/ValheimMjod/Properties/AssemblyInfo.cs index a9025d7..a4ef9a1 100644 --- a/ValheimMjod/Properties/AssemblyInfo.cs +++ b/ValheimMjod/Properties/AssemblyInfo.cs @@ -1,6 +1,4 @@ using System.Reflection; -using System.Resources; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Windows; @@ -51,5 +49,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("0.4.0.0")] +[assembly: AssemblyFileVersion("0.4.0.0")] diff --git a/ValheimMjod/Updater.cs b/ValheimMjod/Updater.cs new file mode 100644 index 0000000..266386d --- /dev/null +++ b/ValheimMjod/Updater.cs @@ -0,0 +1,80 @@ +using Squirrel; +using System; +using System.Threading; +using System.Windows; + +namespace ValheimMjod +{ + public class Updater + { + private readonly string Path = @"https://github.com/porohkun/ValheimMjod/releases/latest/download/"; + private readonly AutoResetEvent _autoEvent; + [System.Diagnostics.CodeAnalysis.SuppressMessage("CodeQuality", "IDE0052:Remove unread private members", Justification = "")] + private readonly Timer _timer; + + public Updater() + { +#if DEBUG + return; +#endif + _autoEvent = new AutoResetEvent(false); + _timer = new Timer(CheckStatus, _autoEvent, 5000, 30000); + } + + private void CheckStatus(object stateInfo) + { + CheckUpdates(); + } + + public async void CheckUpdates() + { + try + { + using (var mgr = new UpdateManager(Path)) + { + SquirrelAwareApp.HandleEvents( + onInitialInstall: v => + { + mgr.CreateShortcutForThisExe(); + }, + onAppUpdate: v => + { + mgr.CreateShortcutForThisExe(); + }, + onAppUninstall: v => + { + mgr.RemoveShortcutForThisExe(); + }, + onFirstRun: () => + { + }); + + if (!mgr.IsInstalledApp) //not installed during Squirrel, skipping update + return; + + try + { + var installedVersion = mgr.CurrentlyInstalledVersion(); + var entry = await mgr.UpdateApp(); + if (entry != null && (installedVersion == null || entry.Version > installedVersion)) + { + MessageBox.Show("You need to restart app for apply changes", "Valheim Mjöð have been updated", MessageBoxButton.OK); + } + } + catch (Exception ex) + { + var errorMessage = $"{ex.Message}\r\n\r\n{ex.StackTrace}\r\n\r\nCopy error message to clipboard?"; + if (MessageBox.Show(errorMessage, "Error in update/install process", MessageBoxButton.YesNo) == MessageBoxResult.Yes) + Clipboard.SetText(errorMessage); + } + } + } + catch (Exception ex) + { + var errorMessage = $"{ex.Message}\r\n\r\n{ex.StackTrace}\r\n\r\nCopy error message to clipboard?"; + if (MessageBox.Show(errorMessage, "Error before update/install process", MessageBoxButton.YesNo) == MessageBoxResult.Yes) + Clipboard.SetText(errorMessage); + } + } + } +} diff --git a/ValheimMjod/ValheimMjod.csproj b/ValheimMjod/ValheimMjod.csproj index 9d45281..14c3755 100644 --- a/ValheimMjod/ValheimMjod.csproj +++ b/ValheimMjod/ValheimMjod.csproj @@ -120,6 +120,7 @@ Designer + @@ -137,6 +138,7 @@ + @@ -209,4 +211,11 @@ + + + + + + + \ No newline at end of file diff --git a/ValheimMjod/ValheimMjod.nuspec b/ValheimMjod/ValheimMjod.nuspec new file mode 100644 index 0000000..d7fc4c5 --- /dev/null +++ b/ValheimMjod/ValheimMjod.nuspec @@ -0,0 +1,17 @@ + + + + ValheimMjod + 0.0.0.0 + + Valheim Mjöð + Porohkun + Valheim teach us: drink mead - and you characteristics will change. But we need moar. Use truly nordic mjöð - and ALL you characteristics can be changed forewer (including inventory). + false + Copyright © Porohkun 2021 + + + + + + \ No newline at end of file