This repository has been archived by the owner on Dec 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from porohkun/0.4/feature/updates
0.4/feature/updates
- Loading branch information
Showing
7 changed files
with
161 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = "<Pending>")] | ||
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); | ||
} | ||
} | ||
} | ||
} |
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,17 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> | ||
<metadata> | ||
<id>ValheimMjod</id> | ||
<version>0.0.0.0</version> | ||
<!-- version will be replaced by MSBuild --> | ||
<title>Valheim Mjöð</title> | ||
<authors>Porohkun</authors> | ||
<description>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).</description> | ||
<requireLicenseAcceptance>false</requireLicenseAcceptance> | ||
<copyright>Copyright © Porohkun 2021</copyright> | ||
<dependencies /> | ||
</metadata> | ||
<files> | ||
<file src="*.*" target="lib\net45\" exclude="*.pdb;*.nupkg;*.vshost.*"/> | ||
</files> | ||
</package> |
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 |
---|---|---|
@@ -1,5 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="DeltaCompressionDotNet" version="1.1.0" targetFramework="net472" /> | ||
<package id="Extended.Wpf.Toolkit" version="4.0.2" targetFramework="net472" /> | ||
<package id="Microsoft.Xaml.Behaviors.Wpf" version="1.1.31" targetFramework="net472" /> | ||
<package id="Mono.Cecil" version="0.11.2" targetFramework="net472" /> | ||
<package id="SharpCompress" version="0.17.1" targetFramework="net472" /> | ||
<package id="squirrel.windows" version="2.0.1" targetFramework="net472" /> | ||
</packages> |