11using MaterialDesignThemes . Wpf ;
22using Microsoft . Win32 ;
3+ using Octokit ;
34using System ;
45using System . Collections . Generic ;
56using System . Diagnostics ;
67using System . IO ;
78using System . Linq ;
9+ using System . Reflection ;
810using System . Windows ;
911using System . Windows . Controls ;
1012using System . Windows . Media ;
1113using System . Xml . Serialization ;
14+ using Application = System . Windows . Application ;
15+ using FileMode = System . IO . FileMode ;
1216
1317namespace ScoutsEncoder
1418{
@@ -60,6 +64,10 @@ public MainWindow()
6064 {
6165 InitializeComponent ( ) ;
6266
67+ // Initialize messageQueue and Assign it to Snackbar's MessageQueue
68+ var messageQueue = new SnackbarMessageQueue ( TimeSpan . FromSeconds ( 2 ) ) ;
69+ Snackbar . MessageQueue = messageQueue ;
70+
6371 // Initialize CiphersComboBox
6472 foreach ( var c in _ciphers )
6573 {
@@ -74,12 +82,35 @@ public MainWindow()
7482 _lettersTextBoxes . AddRange ( children . OfType < TextBox > ( ) ) ;
7583 }
7684
77- // Initialize messageQueue and Assign it to Snackbar's MessageQueue
78- var messageQueue = new SnackbarMessageQueue ( TimeSpan . FromMilliseconds ( 1800 ) ) ;
79- Snackbar . MessageQueue = messageQueue ;
85+ // Check for updates
86+ CheckForUpdates ( ) ;
8087 }
8188
8289
90+ private void CheckForUpdates ( )
91+ {
92+ Release latest ;
93+
94+ try
95+ {
96+ var client = new GitHubClient ( new ProductHeaderValue ( RepoName ) ) ;
97+ latest = client . Repository . Release . GetLatest ( OwnerName , RepoName ) . Result ;
98+ }
99+ catch ( Exception )
100+ {
101+ return ;
102+ }
103+
104+ var currentVersion = Assembly . GetEntryAssembly ( ) ? . GetName ( ) . Version ;
105+ var latestVersion = new Version ( latest . TagName . Substring ( 1 ) + ".0" ) ;
106+ var isUpToDate = currentVersion . Equals ( latestVersion ) ;
107+
108+ if ( isUpToDate ) return ;
109+ var content = $ "ScoutsEncoder { latest . TagName } is Now Available!";
110+ void Action ( ) => Process . Start ( latest . Assets [ 0 ] . BrowserDownloadUrl ) ;
111+ Snackbar . MessageQueue . Enqueue ( content , "Download" , Action ) ;
112+ }
113+
83114 //// Dialog Event Handlers ////
84115
85116 private Cipher GetNewCipher ( )
0 commit comments