diff --git a/Bloxstrap.Builder/Bloxstrap.Builder.csproj b/Bloxstrap.Builder/Bloxstrap.Builder.csproj index 7984642..fcc45ed 100644 --- a/Bloxstrap.Builder/Bloxstrap.Builder.csproj +++ b/Bloxstrap.Builder/Bloxstrap.Builder.csproj @@ -2,7 +2,7 @@ Exe - net6.0 + net6.0-windows enable enable Bloxstrap.ico diff --git a/Bloxstrap.Builder/GitHubRelease.cs b/Bloxstrap.Builder/GitHubRelease.cs new file mode 100644 index 0000000..7428cd3 --- /dev/null +++ b/Bloxstrap.Builder/GitHubRelease.cs @@ -0,0 +1,10 @@ +using System.Text.Json.Serialization; + +namespace Bloxstrap.Builder +{ + public class GitHubRelease + { + [JsonPropertyName("tag_name")] + public string TagName { get; set; } = null!; + } +} \ No newline at end of file diff --git a/Bloxstrap.Builder/Program.cs b/Bloxstrap.Builder/Program.cs index e7a207f..8649b33 100644 --- a/Bloxstrap.Builder/Program.cs +++ b/Bloxstrap.Builder/Program.cs @@ -1,8 +1,11 @@ using System.Diagnostics; +using System.Net.Http.Json; +using System.Reflection; using System.Text.Json; + using Crowdin.Api; -using Crowdin.Api.SourceFiles; using Crowdin.Api.Translations; + using LibGit2Sharp; namespace Bloxstrap.Builder @@ -59,6 +62,8 @@ internal class Program static HttpClient HttpClient = new(); + static System.Version Version = Assembly.GetExecutingAssembly().GetName().Version!; + static void WriteLineColor(string line, ConsoleColor color) { Console.ForegroundColor = color; @@ -68,6 +73,8 @@ static void WriteLineColor(string line, ConsoleColor color) static void Main(string[] args) { + HttpClient.DefaultRequestHeaders.Add("User-Agent", $"Bloxstrap.Builder/{Version}"); + Console.ForegroundColor = ConsoleColor.White; Console.Title = "Bloxstrap Builder v1.0.2"; @@ -83,7 +90,7 @@ static void Main(string[] args) try { - Config = JsonSerializer.Deserialize(System.IO.File.ReadAllText("config.json"))!; + Config = JsonSerializer.Deserialize(File.ReadAllText("config.json"))!; } catch (Exception) { @@ -92,6 +99,8 @@ static void Main(string[] args) OriginalConfigValidation = ValidateConfig(true, true); + CheckForUpdate().Wait(); + Console.WriteLine("Type \"help\" to see a list of commands."); while (Running) @@ -209,7 +218,7 @@ static void SetLanguage(string prompt) Save(); } - static void Save() => System.IO.File.WriteAllText("config.json", JsonSerializer.Serialize(Config)); + static void Save() => File.WriteAllText("config.json", JsonSerializer.Serialize(Config)); static void ConfigureCrowdin() { @@ -239,7 +248,7 @@ static void Build() if (!ValidateConfig(true, false)) return; - bool exists = System.IO.Directory.Exists("bloxstrap"); + bool exists = Directory.Exists("bloxstrap"); if (!exists) { @@ -270,7 +279,7 @@ static void Build() { using var httpStream = HttpClient.GetStreamAsync(response.Link!.Url).Result; - using var fileStream = System.IO.File.Create($"bloxstrap\\Bloxstrap\\Resources\\Strings.{Config.ChosenLocale!}.resx"); + using var fileStream = File.Create($"bloxstrap\\Bloxstrap\\Resources\\Strings.{Config.ChosenLocale!}.resx"); httpStream.CopyTo(fileStream); } @@ -282,12 +291,26 @@ static void Build() Console.WriteLine(""); - if (System.IO.File.Exists(exePath)) + // TODO: don't do this + if (File.Exists(exePath)) Console.WriteLine("Build succeeded. Type \"run\" to run it."); else WriteLineColor("Build failed.", ConsoleColor.Red); } + static async Task CheckForUpdate() + { + var releaseInfo = await HttpClient.GetFromJsonAsync("https://api.github.com/repos/bloxstraplabs/builder/releases/latest"); + + if (releaseInfo is null) + return; + + var latestVersion = new System.Version(releaseInfo.TagName[1..]); + + if (Version < latestVersion) + WriteLineColor($"A new version of Bloxstrap Builder is available (v{Version.ToString()[..^2]} -> v{latestVersion}).\r\nDownload it from https://github.com/bloxstraplabs/builder/releases/latest.", ConsoleColor.Blue); + } + static void Run() => Process.Start(exePath); } }