Skip to content
This repository has been archived by the owner on Mar 12, 2019. It is now read-only.

Commit

Permalink
Merge branch 'gaksen-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
extesy committed Sep 24, 2017
2 parents 958171f + e892b70 commit 359d97f
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 15 deletions.
17 changes: 2 additions & 15 deletions DeckTracker/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
using DeckTracker.LowLevel;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
#if !DEBUG
using Squirrel;
#endif

namespace DeckTracker
{
Expand Down Expand Up @@ -47,8 +44,8 @@ protected override void OnStartup(StartupEventArgs e)
}
GameMessageDispatcher.Start();
ProcessMonitor.Start();
#if !DEBUG
Update();
#if !DEBUG
UpdateManager.StartUpdateCheck();
#endif
}

Expand All @@ -70,15 +67,5 @@ protected override void OnExit(ExitEventArgs e)
base.OnExit(e);
}

#if !DEBUG
private static async void Update()
{
try {
using (var updateManager = await UpdateManager.GitHubUpdateManager("https://github.com/extesy/DeckTracker"))
await updateManager.UpdateApp();
} catch {
}
}
#endif
}
}
1 change: 1 addition & 0 deletions DeckTracker/DeckTracker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
<Compile Include="Domain\Deck.cs" />
<Compile Include="Domain\Game.cs" />
<Compile Include="Properties\AssemblyCommonInfo.cs" />
<Compile Include="UpdateManager.cs" />
<Compile Include="Windows\ImportDeckDialog.xaml.cs">
<DependentUpon>ImportDeckDialog.xaml</DependentUpon>
</Compile>
Expand Down
43 changes: 43 additions & 0 deletions DeckTracker/UpdateManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Threading.Tasks;
using Squirrel;
using System.Reflection;
using DeckTracker.LowLevel;

namespace DeckTracker
{
public static class UpdateManager
{
private const string UpdateUrl = "https://github.com/extesy/DeckTracker";

public delegate void OnNewVersionHandler(string newVersion);
public static event OnNewVersionHandler OnNewVersion;

private static async void CheckForUpdate()
{
try {
string currentVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(3);
using (var updateManager = await Squirrel.UpdateManager.GitHubUpdateManager(UpdateUrl)) {
var updateInfo = await updateManager.CheckForUpdate();
string newVersion = updateInfo.FutureReleaseEntry.Version.ToString();
if (!newVersion.Equals(currentVersion)) {
Logger.LogDebug(Domain.GameType.Eternal, $"Started update to version {newVersion}");
await updateManager.UpdateApp();
Logger.LogDebug(Domain.GameType.Eternal, $"Updated to version {newVersion}");
OnNewVersion?.Invoke(newVersion);
}
}
} catch (Exception e) {
Logger.LogError(e.ToString());
}
}

public static async void StartUpdateCheck()
{
while (true) {
CheckForUpdate();
await Task.Delay(TimeSpan.FromHours(1.0));
}
}
}
}
5 changes: 5 additions & 0 deletions DeckTracker/Windows/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
<Button Content="Report bugs" Click="ReportBugs_OnClick" ToolTip="https://github.com/extesy/decktracker/issues" />
</controls:WindowCommands>
</controls:MetroWindow.RightWindowCommands>
<controls:MetroWindow.LeftWindowCommands>
<controls:WindowCommands>
<Button x:Name="RestartButton" Content="New version is available. Restart?" Click="Restart_OnClick" ToolTip="Restart and update Universal Deck Tracker"/>
</controls:WindowCommands>
</controls:MetroWindow.LeftWindowCommands>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
Expand Down
15 changes: 15 additions & 0 deletions DeckTracker/Windows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,21 @@ public MainWindow()
ExportCollectionButton.IsEnabled = injectionState == InjectionState.Injected;
ImportDeckButton.IsEnabled = injectionState == InjectionState.Injected;
};

LeftWindowCommands.Visibility = Visibility.Collapsed;
UpdateManager.OnNewVersion += newVersion => Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => OnNewVersion(newVersion)));
}

private void OnNewVersion(string newVersion)
{
LeftWindowCommands.Visibility = Visibility.Visible;
RestartButton.Content = $"New version {newVersion} is available. Restart the tracker?";
}

private void Restart_OnClick(object sender, RoutedEventArgs e)
{
Process.Start(Application.ResourceAssembly.Location);
Application.Current.Shutdown();
}

private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
Expand Down

0 comments on commit 359d97f

Please sign in to comment.