Skip to content
This repository has been archived by the owner on Dec 11, 2022. It is now read-only.

Commit

Permalink
updating setup
Browse files Browse the repository at this point in the history
  • Loading branch information
porohkun committed Mar 12, 2021
1 parent d353420 commit 320f8c1
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 13 deletions.
3 changes: 1 addition & 2 deletions ValheimMjod/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
Expand Down
16 changes: 9 additions & 7 deletions ValheimMjod/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -13,5 +7,13 @@ namespace ValheimMjod
/// </summary>
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);
}
}
}
6 changes: 2 additions & 4 deletions ValheimMjod/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;

Expand Down Expand Up @@ -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")]
80 changes: 80 additions & 0 deletions ValheimMjod/Updater.cs
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);
}
}
}
}
9 changes: 9 additions & 0 deletions ValheimMjod/ValheimMjod.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="CharacterViewModel.cs" />
<None Include="ValheimMjod.nuspec" />
<Compile Include="Converters\StringCamelCaseConverter.cs" />
<Compile Include="Converters\Vector3ToColorConverter.cs" />
<Compile Include="Converters\Vector3ToBrushConverter.cs" />
Expand All @@ -137,6 +138,7 @@
<Compile Include="UnityEngine\Vector2.cs" />
<Compile Include="UnityEngine\Vector2i.cs" />
<Compile Include="UnityEngine\Vector3.cs" />
<Compile Include="Updater.cs" />
<Compile Include="Valheim\Biome.cs" />
<Compile Include="Valheim\Inventory.cs" />
<Compile Include="Valheim\ItemData.cs" />
Expand Down Expand Up @@ -209,4 +211,11 @@
</PropertyGroup>
<Error Condition="!Exists('..\packages\squirrel.windows.2.0.1\build\squirrel.windows.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\squirrel.windows.2.0.1\build\squirrel.windows.props'))" />
</Target>
<Target Name="AfterBuild" AfterTargets="PostBuildEvent" Condition=" '$(Configuration)' == 'Release'">
<GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
<Output TaskParameter="Assemblies" ItemName="myAssemblyInfo" />
</GetAssemblyIdentity>
<Exec Command="nuget.exe pack $(ProjectName).nuspec -Version %(myAssemblyInfo.Version) -Properties Configuration=Release -OutputDirectory $(OutDir) -BasePath $(OutDir)" />
<Exec Command="..\packages\squirrel.windows.2.0.1\tools\Squirrel.exe --releasify $(TargetDir)$(ProjectName).$([System.Version]::Parse(%(myAssemblyInfo.Version)).ToString(3)).nupkg -r ..\Releases\" />
</Target>
</Project>
17 changes: 17 additions & 0 deletions ValheimMjod/ValheimMjod.nuspec
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>

0 comments on commit 320f8c1

Please sign in to comment.