@@ -2158,41 +2158,34 @@ private static async void CheckForUpdates()
21582158 try
21592159 {
21602160 Tuple < Version , Version , DateTime > versionLocal = GetVersionAndBuildDate ( ) ;
2161- TraceLogger logger = new TraceLogger ( "CheckForUpdate" ) ;
21622161 HashCode hashCode = HashCode . Compute ( $ "{ versionLocal . Item1 } \\ { versionLocal . Item2 } \\ { GetUnixTimeSeconds ( ) / 3593 } ") ;
21632162 ulong ? lastUpdateCheck = ReadRegValue ( REGISTRY_VALUE_NAME ) ;
21642163 if ( ( ! lastUpdateCheck . HasValue ) || ( lastUpdateCheck . Value != hashCode . Value ) )
21652164 {
2166- logger . WriteLine ( $ "Update check is starting...") ;
2165+ TraceLog . WriteLine ( $ "Update check is starting...") ;
21672166 Version versionRemote = await Task . Run ( ( ) => CheckForUpdatesTask ( VERSION_URL , SIGNKEY_PUB ) ) ;
2168- if ( IsNotNull ( versionRemote ) )
2167+ if ( versionRemote . CompareTo ( versionLocal . Item1 ) > 0 )
21692168 {
2170- try
2169+ const string message = "A new program version is available!\n \n Installed version: {0}\n Latest available version: {1}\n \n It is recommended that you upgrade to the new version. Do you want to download the new version now?" ;
2170+ TraceLog . WriteLine ( $ "New program version is available: { versionLocal . Item1 } -> { versionRemote } ") ;
2171+ if ( MessageBox . Show ( string . Format ( message , versionLocal . Item1 , versionRemote ) , "Update Notification" , MessageBoxButton . YesNo , MessageBoxImage . Information ) == MessageBoxResult . Yes )
21712172 {
2172- if ( versionRemote . CompareTo ( versionLocal . Item1 ) > 0 )
2173- {
2174- const string message = "A new program version is available!\n \n Installed version: {0}\n Latest available version: {1}\n \n It is recommended that you upgrade to the new version. Do you want to download the new version now?" ;
2175- logger . WriteLine ( $ "New program version is available: { versionLocal . Item1 } -> { versionRemote } ") ;
2176- if ( MessageBox . Show ( string . Format ( message , versionLocal . Item1 , versionRemote ) , "Update Notification" , MessageBoxButton . YesNo , MessageBoxImage . Information ) == MessageBoxResult . Yes )
2177- {
2178- Process . Start ( new ProcessStartInfo { FileName = WEBSITE_URL , UseShellExecute = true } ) ;
2179- Application . Current . Shutdown ( ) ;
2180- }
2181- }
2182- else
2183- {
2184- logger . WriteLine ( $ "The installed program version is up to date -> nothing to do!") ;
2185- }
2173+ Process . Start ( new ProcessStartInfo { FileName = WEBSITE_URL , UseShellExecute = true } ) ;
2174+ Application . Current . Shutdown ( ) ;
21862175 }
2187- finally
2176+ }
2177+ else
2178+ {
2179+ TraceLog . WriteLine ( $ "The installed program version is still up to date.") ;
2180+ if ( versionRemote . Major > 0 )
21882181 {
21892182 WriteRegValue ( REGISTRY_VALUE_NAME , hashCode . Value ) ;
21902183 }
21912184 }
21922185 }
21932186 else
21942187 {
2195- logger . WriteLine ( $ "Skipping update check this time.") ;
2188+ TraceLog . WriteLine ( $ "Skipping update check this time.") ;
21962189 }
21972190 }
21982191 catch
@@ -2203,47 +2196,46 @@ private static async void CheckForUpdates()
22032196
22042197 private static Version CheckForUpdatesTask ( string versionUrl , string verificationKey )
22052198 {
2206- TraceLogger logger = new TraceLogger ( "ChckUpdateTask" ) ;
22072199 const int MAX_TRIES = 5 ;
22082200 Tuple < string , string > updateInfo ;
22092201 Version version ;
22102202 for ( int retry = 0 ; retry < MAX_TRIES ; ++ retry )
22112203 {
2212- logger . WriteLine ( $ "Downloading update information (attempt { retry + 1 } /{ MAX_TRIES } )") ;
2204+ TraceLog . WriteLine ( $ "Downloading update information (attempt { retry + 1 } /{ MAX_TRIES } )") ;
22132205 try
22142206 {
2215- if ( IsNotNull ( updateInfo = DownloadFileContents ( versionUrl ) ) )
2207+ if ( IsNotNull ( updateInfo = DownloadFile ( versionUrl ) ) )
22162208 {
2217- logger . WriteLine ( $ "Update information: info=\" { updateInfo . Item1 } \" , signature=\" { updateInfo . Item2 } \" ") ;
2209+ TraceLog . WriteLine ( $ "Update information: info=\" { updateInfo . Item1 } \" , signature=\" { updateInfo . Item2 } \" ") ;
22182210 if ( VerifySignature ( updateInfo . Item1 , updateInfo . Item2 , verificationKey ) )
22192211 {
2220- logger . WriteLine ( $ "Signature is valid.") ;
2212+ TraceLog . WriteLine ( $ "Signature is valid.") ;
22212213 if ( Version . TryParse ( updateInfo . Item1 , out version ) )
22222214 {
2223- logger . WriteLine ( $ "Latest available program version is: { version } ") ;
2215+ TraceLog . WriteLine ( $ "Latest available program version is: { version } ") ;
22242216 return version ;
22252217 }
22262218 else
22272219 {
2228- logger . WriteLine ( $ "Failed to parse version string!") ;
2220+ TraceLog . WriteLine ( $ "Failed to parse version string!") ;
22292221 }
22302222 }
22312223 else
22322224 {
2233- logger . WriteLine ( $ "Signature verification has failed -> discarding update information!") ;
2225+ TraceLog . WriteLine ( $ "Signature verification has failed -> discarding update information!") ;
22342226 }
22352227 }
22362228 else
22372229 {
2238- logger . WriteLine ( $ "Failed to download update information!") ;
2230+ TraceLog . WriteLine ( $ "Failed to download update information!") ;
22392231 }
22402232 }
22412233 catch
22422234 {
22432235 if ( IS_DEBUG ) throw ;
22442236 }
22452237 }
2246- return null ;
2238+ return new Version ( ) ;
22472239 }
22482240
22492241 private static void StartNewInstance ( )
0 commit comments