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

Commit

Permalink
Merge pull request #1 from porohkun/0.4/feature/updates
Browse files Browse the repository at this point in the history
0.4/feature/updates
  • Loading branch information
porohkun authored Mar 12, 2021
2 parents 2e41fd7 + 320f8c1 commit 660ed8e
Show file tree
Hide file tree
Showing 7 changed files with 161 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);
}
}
}
}
48 changes: 48 additions & 0 deletions ValheimMjod/ValheimMjod.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\squirrel.windows.2.0.1\build\squirrel.windows.props" Condition="Exists('..\packages\squirrel.windows.2.0.1\build\squirrel.windows.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand All @@ -14,6 +15,8 @@
<WarningLevel>4</WarningLevel>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -38,9 +41,39 @@
<ApplicationIcon>mug.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="DeltaCompressionDotNet, Version=1.1.0.0, Culture=neutral, PublicKeyToken=1d14d6e5194e7f4a, processorArchitecture=MSIL">
<HintPath>..\packages\DeltaCompressionDotNet.1.1.0\lib\net20\DeltaCompressionDotNet.dll</HintPath>
</Reference>
<Reference Include="DeltaCompressionDotNet.MsDelta, Version=1.1.0.0, Culture=neutral, PublicKeyToken=46b2138a390abf55, processorArchitecture=MSIL">
<HintPath>..\packages\DeltaCompressionDotNet.1.1.0\lib\net20\DeltaCompressionDotNet.MsDelta.dll</HintPath>
</Reference>
<Reference Include="DeltaCompressionDotNet.PatchApi, Version=1.1.0.0, Culture=neutral, PublicKeyToken=3e8888ee913ed789, processorArchitecture=MSIL">
<HintPath>..\packages\DeltaCompressionDotNet.1.1.0\lib\net20\DeltaCompressionDotNet.PatchApi.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Xaml.Behaviors, Version=1.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Xaml.Behaviors.Wpf.1.1.31\lib\net45\Microsoft.Xaml.Behaviors.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil, Version=0.11.2.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.11.2\lib\net40\Mono.Cecil.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil.Mdb, Version=0.11.2.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.11.2\lib\net40\Mono.Cecil.Mdb.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil.Pdb, Version=0.11.2.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.11.2\lib\net40\Mono.Cecil.Pdb.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil.Rocks, Version=0.11.2.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.11.2\lib\net40\Mono.Cecil.Rocks.dll</HintPath>
</Reference>
<Reference Include="NuGet.Squirrel, Version=3.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\squirrel.windows.2.0.1\lib\Net45\NuGet.Squirrel.dll</HintPath>
</Reference>
<Reference Include="SharpCompress, Version=0.17.1.0, Culture=neutral, PublicKeyToken=afb0a02973931d96, processorArchitecture=MSIL">
<HintPath>..\packages\SharpCompress.0.17.1\lib\net45\SharpCompress.dll</HintPath>
</Reference>
<Reference Include="Squirrel, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\squirrel.windows.2.0.1\lib\Net45\Squirrel.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Data" />
Expand Down Expand Up @@ -87,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 @@ -104,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 @@ -170,4 +205,17 @@
<Import Project="..\WPF.MyFlatTheme\WPF.MyFlatTheme.projitems" Label="Shared" />
<Import Project="..\WPF.Controls.IntUpDown\WPF.Controls.IntUpDown\WPF.Controls.IntUpDown.projitems" Label="Shared" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>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}.</ErrorText>
</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>
4 changes: 4 additions & 0 deletions ValheimMjod/packages.config
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>

0 comments on commit 660ed8e

Please sign in to comment.