33using System ;
44using System . IO ;
55using System . Linq ;
6+ using System . Reflection ;
67using Neocmd ;
8+ using Newtonsoft . Json . Linq ;
9+ using RestSharp ;
710using SmartImage . Searching ;
811using SmartImage . Utilities ;
912
1013#endregion
1114
15+
1216namespace SmartImage
1317{
1418 public static class Config
@@ -104,6 +108,26 @@ internal static AuthInfo SauceNaoAuth {
104108 set => RegConfig . Write ( REG_SAUCENAO_APIKEY , value . Id ) ;
105109 }
106110
111+
112+ internal static ReleaseInfo LatestRelease ( )
113+ {
114+ // todo
115+ var rc = new RestClient ( "https://api.github.com/" ) ;
116+ var re = new RestRequest ( "repos/Decimation/SmartImage/releases" ) ;
117+ var rs = rc . Execute ( re ) ;
118+ var ja = JArray . Parse ( rs . Content ) ;
119+
120+ var first = ja [ 0 ] ;
121+
122+
123+ var tagName = first [ "tag_name" ] ;
124+ var url = first [ "html_url" ] ;
125+ var publish = first [ "published_at" ] ;
126+
127+ var r = new ReleaseInfo ( tagName . ToString ( ) , url . ToString ( ) , publish . ToString ( ) ) ;
128+ return r ;
129+ }
130+
107131 private static void RemoveFromContextMenu ( )
108132 {
109133 // reg delete HKEY_CLASSES_ROOT\*\shell\SmartImage
@@ -168,10 +192,34 @@ internal static void Info()
168192 CliOutput . WriteInfo ( "Application folder: {0}" , AppFolder ) ;
169193 CliOutput . WriteInfo ( "Executable location: {0}" , Location ) ;
170194 CliOutput . WriteInfo ( "Context menu integrated: {0}" , IsContextMenuAdded ) ;
171- CliOutput . WriteInfo ( "In path: {0}" , IsAppFolderInPath ) ;
195+ CliOutput . WriteInfo ( "In path: {0}\n " , IsAppFolderInPath ) ;
196+
197+ //
198+
199+ CliOutput . WriteInfo ( "Supported search engines: {0}\n " , SearchEngines . All ) ;
200+
201+ //
172202
173203 CliOutput . WriteInfo ( "Readme: {0}" , Readme ) ;
174- CliOutput . WriteInfo ( "Supported search engines: {0}" , SearchEngines . All ) ;
204+
205+ var asm = typeof ( Config ) . Assembly . GetName ( ) ;
206+ var currentVersion = asm . Version ;
207+ CliOutput . WriteInfo ( "Current version: {0}" , currentVersion ) ;
208+
209+ var release = LatestRelease ( ) ;
210+ CliOutput . WriteInfo ( "Latest version: {0} ({1})" , release . Version , release . PublishedAt ) ;
211+
212+ int vcmp = currentVersion . CompareTo ( release . Version ) ;
213+
214+ if ( vcmp < 0 ) {
215+ CliOutput . WriteInfo ( "Update available" ) ;
216+ }
217+ else if ( vcmp == 0 ) {
218+ CliOutput . WriteInfo ( "Up to date" ) ;
219+ }
220+ else if ( vcmp > 0 ) {
221+ CliOutput . WriteInfo ( "(preview)" ) ;
222+ }
175223 }
176224
177225 internal static void AddToContextMenu ( )
@@ -257,5 +305,29 @@ private static string FindExecutableLocation(string exe)
257305
258306 return path ;
259307 }
308+
309+ public struct ReleaseInfo
310+ {
311+ public ReleaseInfo ( string tagName , string htmlUrl , string publishedAt )
312+ {
313+ TagName = tagName ;
314+ HtmlUrl = htmlUrl ;
315+ PublishedAt = DateTime . Parse ( publishedAt ) ;
316+
317+
318+ // hacky
319+ const string buildRevision = ".0.0" ;
320+
321+ var parse = System . Version . Parse ( tagName + buildRevision ) ;
322+
323+
324+ Version = parse ;
325+ }
326+
327+ public string TagName { get ; }
328+ public string HtmlUrl { get ; }
329+ public DateTime PublishedAt { get ; }
330+ public Version Version { get ; }
331+ }
260332 }
261333}
0 commit comments