Skip to content

Commit b4d25d1

Browse files
committed
Versioning
1 parent 1e8ba4b commit b4d25d1

File tree

3 files changed

+91
-2
lines changed

3 files changed

+91
-2
lines changed

SmartImage/Config.cs

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
using System;
44
using System.IO;
55
using System.Linq;
6+
using System.Reflection;
67
using Neocmd;
8+
using Newtonsoft.Json.Linq;
9+
using RestSharp;
710
using SmartImage.Searching;
811
using SmartImage.Utilities;
912

1013
#endregion
1114

15+
1216
namespace 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
}

SmartImage/SmartImage.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<PackageReference Include="JetBrains.Annotations" Version="2020.1.0" />
2222
<PackageReference Include="Microsoft.Win32.Registry" Version="4.7.0" />
2323
<PackageReference Include="Neocmd" Version="1.0.6" />
24+
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
2425
<PackageReference Include="RestSharp" Version="106.10.1" />
2526
<PackageReference Include="System.Json" Version="4.7.0" />
2627

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// Generated by the MSBuild WriteCodeFragment class.
4+
// </auto-generated>
5+
//------------------------------------------------------------------------------
6+
7+
using System;
8+
using System.Reflection;
9+
10+
[assembly: System.Reflection.AssemblyCompany("SmartImage")]
11+
[assembly: System.Reflection.AssemblyConfiguration("Release")]
12+
[assembly: System.Reflection.AssemblyFileVersion("1.0.0.0")]
13+
[assembly: System.Reflection.AssemblyInformationalVersion("1.0.0")]
14+
[assembly: System.Reflection.AssemblyProduct("SmartImage")]
15+
[assembly: System.Reflection.AssemblyTitle("SmartImage")]
16+
[assembly: System.Reflection.AssemblyVersion("1.3.0.0")]

0 commit comments

Comments
 (0)