Skip to content

Commit

Permalink
Check for Updates on Startup
Browse files Browse the repository at this point in the history
  • Loading branch information
yousinix committed Aug 15, 2019
1 parent 5f03523 commit b9a59f5
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
37 changes: 34 additions & 3 deletions ScoutsEncoder/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
using MaterialDesignThemes.Wpf;
using Microsoft.Win32;
using Octokit;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Xml.Serialization;
using Application = System.Windows.Application;
using FileMode = System.IO.FileMode;

namespace ScoutsEncoder
{
Expand Down Expand Up @@ -60,6 +64,10 @@ public MainWindow()
{
InitializeComponent();

// Initialize messageQueue and Assign it to Snackbar's MessageQueue
var messageQueue = new SnackbarMessageQueue(TimeSpan.FromSeconds(2));
Snackbar.MessageQueue = messageQueue;

// Initialize CiphersComboBox
foreach (var c in _ciphers)
{
Expand All @@ -74,12 +82,35 @@ public MainWindow()
_lettersTextBoxes.AddRange(children.OfType<TextBox>());
}

// Initialize messageQueue and Assign it to Snackbar's MessageQueue
var messageQueue = new SnackbarMessageQueue(TimeSpan.FromMilliseconds(1800));
Snackbar.MessageQueue = messageQueue;
// Check for updates
CheckForUpdates();
}


private void CheckForUpdates()
{
Release latest;

try
{
var client = new GitHubClient(new ProductHeaderValue(RepoName));
latest = client.Repository.Release.GetLatest(OwnerName, RepoName).Result;
}
catch (Exception)
{
return;
}

var currentVersion = Assembly.GetEntryAssembly()?.GetName().Version;
var latestVersion = new Version(latest.TagName.Substring(1) + ".0");
var isUpToDate = currentVersion.Equals(latestVersion);

if (isUpToDate) return;
var content = $"ScoutsEncoder {latest.TagName} is Now Available!";
void Action() => Process.Start(latest.Assets[0].BrowserDownloadUrl);
Snackbar.MessageQueue.Enqueue(content, "Download", Action);
}

//// Dialog Event Handlers ////

private Cipher GetNewCipher()
Expand Down
4 changes: 2 additions & 2 deletions ScoutsEncoder/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,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("2.1.0.0")]
[assembly: AssemblyFileVersion("2.1.0.0")]
[assembly: AssemblyVersion("2.2.0.0")]
[assembly: AssemblyFileVersion("2.2.0.0")]
3 changes: 3 additions & 0 deletions ScoutsEncoder/ScoutsEncoder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
<Reference Include="MaterialDesignThemes.Wpf, Version=2.5.0.1205, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MaterialDesignThemes.2.5.0.1205\lib\net45\MaterialDesignThemes.Wpf.dll</HintPath>
</Reference>
<Reference Include="Octokit, Version=0.32.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Octokit.0.32.0\lib\net45\Octokit.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
Expand Down
1 change: 1 addition & 0 deletions ScoutsEncoder/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
<package id="Fody" version="3.3.5" targetFramework="net461" developmentDependency="true" />
<package id="MaterialDesignColors" version="1.1.3" targetFramework="net461" />
<package id="MaterialDesignThemes" version="2.5.0.1205" targetFramework="net461" />
<package id="Octokit" version="0.32.0" targetFramework="net461" />
</packages>

0 comments on commit b9a59f5

Please sign in to comment.