From ca4d43992dae90b6895c66641724c0ecbd3fa92c Mon Sep 17 00:00:00 2001
From: Dissectum <124477333+Dissectum@users.noreply.github.com>
Date: Sun, 17 Sep 2023 15:29:31 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20ChangeLog=20?=
=?UTF-8?q?=E6=8F=90=E7=A4=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/MBA.Cli/Program.cs | 12 +++++++
src/MBA.Core/Data/Config.cs | 1 +
src/MBA.Core/MBA.Core.csproj | 1 +
src/MBA.Core/Managers/VersionManager.cs | 48 ++++++++++++++++++++++---
4 files changed, 57 insertions(+), 5 deletions(-)
diff --git a/src/MBA.Cli/Program.cs b/src/MBA.Cli/Program.cs
index ae8e48e..52690fb 100644
--- a/src/MBA.Cli/Program.cs
+++ b/src/MBA.Cli/Program.cs
@@ -17,6 +17,7 @@ static Program()
static int Main(string[] args)
{
+ TipChangeLog();
Console.WriteLine(Greeting);
if (!ResetConfig())
@@ -48,6 +49,17 @@ static int Main(string[] args)
return 0;
}
+ private static void TipChangeLog()
+ {
+ if (!VersionManager.Updated)
+ return;
+
+ Console.ForegroundColor = ConsoleColor.Yellow;
+ Console.WriteLine("\t\t\t ChangLog");
+ Console.WriteLine(VersionManager.ChangeLog);
+ Console.ForegroundColor = ConsoleColor.White;
+ }
+
private static void TipNewVersion()
{
if (!VersionManager.Released)
diff --git a/src/MBA.Core/Data/Config.cs b/src/MBA.Core/Data/Config.cs
index 578a0c1..f277d77 100644
--- a/src/MBA.Core/Data/Config.cs
+++ b/src/MBA.Core/Data/Config.cs
@@ -19,6 +19,7 @@ public class Config
public class UIConfig
{
+ public string CurrentMBACoreVersion { get; set; } = "0.0.0";
public bool FirstStartUp { get; set; } = true;
public bool DebugMode { get; set; } = false;
public string Proxy { get; set; } = string.Empty;
diff --git a/src/MBA.Core/MBA.Core.csproj b/src/MBA.Core/MBA.Core.csproj
index b54fb0e..291f931 100644
--- a/src/MBA.Core/MBA.Core.csproj
+++ b/src/MBA.Core/MBA.Core.csproj
@@ -9,6 +9,7 @@
Always
+
diff --git a/src/MBA.Core/Managers/VersionManager.cs b/src/MBA.Core/Managers/VersionManager.cs
index 177ad0e..84fb3e1 100644
--- a/src/MBA.Core/Managers/VersionManager.cs
+++ b/src/MBA.Core/Managers/VersionManager.cs
@@ -9,15 +9,25 @@ namespace MBA.Core.Managers;
public static class VersionManager
{
private static Serilog.ILogger Log => LogManager.Logger;
+ private static Config Config => ConfigManager.Config;
public static string AssemblyVersion { get; private set; }
public static string InformationalVersion { get; private set; }
+ public static bool IsPreviewVersion { get; private set; } = false;
+ public static bool Updated { get; private set; } = false;
+ public static string ChangeLog { get; private set; } = "";
public static bool Released { get; private set; } = false;
static VersionManager()
{
AssemblyVersion = GetAssemblyVersion();
InformationalVersion = GetInformationalVersion();
+ if (InformationalVersion.EndsWith("-dev") || InformationalVersion.Contains("Preview"))
+ {
+ IsPreviewVersion = true;
+ }
+
+ SetUpdatedAndChangeLog();
_ = SetReleasedAsync();
}
@@ -37,10 +47,38 @@ private static string GetInformationalVersion()
?? AssemblyVersion + "-";
}
+ private static void SetUpdatedAndChangeLog()
+ {
+ if (Config.UI.CurrentMBACoreVersion == InformationalVersion)
+ return;
+
+ Config.UI.CurrentMBACoreVersion = InformationalVersion;
+ if (IsPreviewVersion)
+ return;
+
+ Updated = true;
+ try
+ {
+ var name = Assembly.GetExecutingAssembly().GetManifestResourceNames().First(x => x.Contains("CHANGELOG.md"))!;
+ using var rs = Assembly.GetExecutingAssembly().GetManifestResourceStream(name)!;
+ using StreamReader sr = new StreamReader(rs, detectEncodingFromByteOrderMarks: true);
+ var changeLog = sr.ReadToEnd();
+
+ if (string.IsNullOrWhiteSpace(changeLog))
+ ChangeLog = "";
+ else
+ ChangeLog = changeLog;
+ }
+ catch (Exception e)
+ {
+ Log.Warning("Failed to read ChangeLog: {Message}", e.Message);
+ }
+ }
+
+
private static async Task SetReleasedAsync()
{
- if (InformationalVersion.EndsWith("-dev")
- || InformationalVersion.Contains("Preview"))
+ if (IsPreviewVersion)
return;
try
@@ -55,7 +93,7 @@ private static async Task SetReleasedAsync()
nameof(GetLatestReleaseVersionAsync),
e.Message);
Log.Warning("Setting the {Proxy} in {Path} may be useful.",
- nameof(ConfigManager.Config.UI.Proxy),
+ nameof(Config.UI.Proxy),
GlobalInfo.ConfigFileFullPath);
}
}
@@ -67,12 +105,12 @@ private static async Task GetLatestReleaseVersionAsync()
{
AllowAutoRedirect = true,
};
- if (ConfigManager.Config.UI.ProxyUri != null)
+ if (Config.UI.ProxyUri != null)
{
handler.UseProxy = true;
handler.Proxy = new WebProxy
{
- Address = ConfigManager.Config.UI.ProxyUri,
+ Address = Config.UI.ProxyUri,
BypassProxyOnLocal = false,
UseDefaultCredentials = false,
};