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 54e5707..14c3755 100644 --- a/ValheimMjod/ValheimMjod.csproj +++ b/ValheimMjod/ValheimMjod.csproj @@ -1,5 +1,6 @@  + Debug @@ -14,6 +15,8 @@ 4 true true + + AnyCPU @@ -38,9 +41,39 @@ mug.ico + + ..\packages\DeltaCompressionDotNet.1.1.0\lib\net20\DeltaCompressionDotNet.dll + + + ..\packages\DeltaCompressionDotNet.1.1.0\lib\net20\DeltaCompressionDotNet.MsDelta.dll + + + ..\packages\DeltaCompressionDotNet.1.1.0\lib\net20\DeltaCompressionDotNet.PatchApi.dll + ..\packages\Microsoft.Xaml.Behaviors.Wpf.1.1.31\lib\net45\Microsoft.Xaml.Behaviors.dll + + ..\packages\Mono.Cecil.0.11.2\lib\net40\Mono.Cecil.dll + + + ..\packages\Mono.Cecil.0.11.2\lib\net40\Mono.Cecil.Mdb.dll + + + ..\packages\Mono.Cecil.0.11.2\lib\net40\Mono.Cecil.Pdb.dll + + + ..\packages\Mono.Cecil.0.11.2\lib\net40\Mono.Cecil.Rocks.dll + + + ..\packages\squirrel.windows.2.0.1\lib\Net45\NuGet.Squirrel.dll + + + ..\packages\SharpCompress.0.17.1\lib\net45\SharpCompress.dll + + + ..\packages\squirrel.windows.2.0.1\lib\Net45\Squirrel.dll + @@ -87,6 +120,7 @@ Designer + @@ -104,6 +138,7 @@ + @@ -170,4 +205,17 @@ + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + + \ 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 diff --git a/ValheimMjod/packages.config b/ValheimMjod/packages.config index 0ff297a..ae3a23a 100644 --- a/ValheimMjod/packages.config +++ b/ValheimMjod/packages.config @@ -1,5 +1,9 @@  + + + + \ No newline at end of file