Skip to content

Commit

Permalink
Added version checking and an update button, this will serve as a tes…
Browse files Browse the repository at this point in the history
…t release
  • Loading branch information
sirdoombox committed Mar 11, 2020
1 parent 0a60b72 commit 5508f33
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@
<HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Octokit, Version=0.43.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\Octokit.0.43.0\lib\net46\Octokit.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="PanAndZoom, Version=2.3.1.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\packages\PanAndZoom.2.3.1\lib\net461\PanAndZoom.dll</HintPath>
<Private>True</Private>
Expand Down Expand Up @@ -126,6 +130,7 @@
<Compile Include="Models\UserConfigModel.cs" />
<Compile Include="Services\ConfigService.cs" />
<Compile Include="Services\DataResourceService.cs" />
<Compile Include="Services\UpdateService.cs" />
<Compile Include="Utils\RoundedVector2.cs" />
<Compile Include="ViewModels\CalculatorViewModel.cs" />
<Compile Include="ViewModels\CreditsViewModel.cs" />
Expand Down
3 changes: 2 additions & 1 deletion PostScriptumMortarCalculator/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0.0")]
48 changes: 48 additions & 0 deletions PostScriptumMortarCalculator/Services/UpdateService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System.Reflection;
using System.Threading.Tasks;
using Octokit;

namespace PostScriptumMortarCalculator.Services
{
public class UpdateService
{
private const string c_OWNER_NAME = "sirdoombox";
private const string c_REPO_NAME = "PostScriptumMortarCalculator";
private const string c_RELEASE_PATH = "https://github.com/sirdoombox/PostScriptumMortarCalculator/releases/latest";

private readonly GitHubClient m_client;

public UpdateService()
{
m_client = new GitHubClient(new ProductHeaderValue("PostScriptumMortarCalculator"));
}

public async Task<UpdateInfo> CheckForUpdate()
{
#if (!DEBUG)
var release = await m_client.Repository.Release.GetLatest(c_OWNER_NAME, c_REPO_NAME);
var releaseVersion = decimal.Parse(release.TagName);
var currentVersionString = Assembly.GetExecutingAssembly().GetName().Version.ToString();
var currentVersion = decimal.Parse(currentVersionString);
return new UpdateInfo(currentVersion, releaseVersion, c_RELEASE_PATH);
#endif
return new UpdateInfo(1.0m,1.1m,c_RELEASE_PATH);
}

public struct UpdateInfo
{
public decimal CurrentVersion { get; }
public decimal NewVersion { get; }
public string ReleasePath { get; }

public bool IsUpdateAvailable => NewVersion > CurrentVersion;

public UpdateInfo(decimal currentVersion, decimal newVersion, string releasePath)
{
CurrentVersion = currentVersion;
NewVersion = newVersion;
ReleasePath = releasePath;
}
}
}
}
25 changes: 25 additions & 0 deletions PostScriptumMortarCalculator/ViewModels/PsmcRootViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Windows;
using System.Windows.Controls;
using MahApps.Metro.Controls;
using PostScriptumMortarCalculator.Services;
using Stylet;

namespace PostScriptumMortarCalculator.ViewModels
Expand All @@ -9,19 +11,42 @@ public sealed class PsmcRootViewModel : Conductor<IScreen>
public MenuFlyoutViewModel MenuFlyoutViewModel { get; set; }
public MapViewModel MapViewModel { get; set; }
public CalculatorViewModel CalculatorViewModel { get; set; }

public bool IsUpdateAvailable { get; private set; }

public string UpdateTooltip { get; private set; }

private readonly UpdateService m_updateService;

private string m_updatePath;

public PsmcRootViewModel(CalculatorViewModel calcViewModel,
UpdateService updateService,
MapViewModel mapViewModel,
MenuFlyoutViewModel menuFlyoutViewModel)
{
MapViewModel = mapViewModel;
ActivateItem(MapViewModel);
CalculatorViewModel = calcViewModel;
m_updateService = updateService;
ActivateItem(CalculatorViewModel);
MenuFlyoutViewModel = menuFlyoutViewModel;
ActivateItem(MenuFlyoutViewModel);
}

protected override async void OnViewLoaded()
{
var result = await m_updateService.CheckForUpdate();
IsUpdateAvailable = result.IsUpdateAvailable;
m_updatePath = result.ReleasePath;
UpdateTooltip = $"Current: {result.CurrentVersion} | New: {result.NewVersion}";
}

public void UpdateAvailableClicked()
{
System.Diagnostics.Process.Start(m_updatePath);
}

public void OpenMenuFlyout()
{
var flyout = ((MetroWindow) Application.Current.MainWindow).Flyouts.Items[0];
Expand Down
5 changes: 5 additions & 0 deletions PostScriptumMortarCalculator/Views/PsmcRootView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
MinWidth="900"
MinHeight="500"
Icon="pack://application:,,,/psmc_icon.ico"
ShowIconOnTitleBar="False"
SaveWindowPosition="True">
<mah:MetroWindow.Flyouts>
<mah:FlyoutsControl>
Expand All @@ -28,6 +29,10 @@
</mah:MetroWindow.Flyouts>
<mah:MetroWindow.RightWindowCommands>
<mah:WindowCommands>
<Button Content="Update Available"
Command="{s:Action UpdateAvailableClicked}"
ToolTip="{Binding UpdateTooltip}"
Visibility="{Binding IsUpdateAvailable, Converter={StaticResource BooleanToVisibility}}"/>
<Button Content="Menu"
Command="{s:Action OpenMenuFlyout}" />
</mah:WindowCommands>
Expand Down
1 change: 1 addition & 0 deletions PostScriptumMortarCalculator/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<package id="MahApps.Metro" version="2.0.0-alpha0660" targetFramework="net48" />
<package id="Microsoft.Xaml.Behaviors.Wpf" version="1.1.3" targetFramework="net48" />
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net48" />
<package id="Octokit" version="0.43.0" targetFramework="net48" />
<package id="PanAndZoom" version="2.3.1" targetFramework="net48" />
<package id="PropertyChanged.Fody" version="3.2.6" targetFramework="net48" />
<package id="Stylet" version="1.3.1" targetFramework="net48" />
Expand Down
5 changes: 5 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ skip_commits:
skip_tags: true
image: Visual Studio 2019
configuration: Release
assembly_info:
patch: true
file: 'PostScriptumMortarCalculator\**\AssemblyInfo.*'
assembly_version: '{version}'
assembly_file_version: '{version}'
before_build:
- cmd: nuget restore
build:
Expand Down

0 comments on commit 5508f33

Please sign in to comment.