Skip to content

Commit

Permalink
feat: 添加 ChangeLog 提示
Browse files Browse the repository at this point in the history
  • Loading branch information
Dissectum committed Sep 17, 2023
1 parent 5d56468 commit 0090087
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 5 deletions.
12 changes: 12 additions & 0 deletions src/MBA.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ static Program()

static int Main(string[] args)
{
TipChangeLog();
Console.WriteLine(Greeting);

if (!ResetConfig())
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/MBA.Core/Data/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,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;
Expand Down
1 change: 1 addition & 0 deletions src/MBA.Core/MBA.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<Content Include="..\..\assets\**" Exclude="..\..\assets\*.*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<EmbeddedResource Include="..\..\CHANGELOG.md" Visible="false" />
</ItemGroup>

</Project>
48 changes: 43 additions & 5 deletions src/MBA.Core/Managers/VersionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; } = "<failed to read>";
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();
}

Expand All @@ -37,10 +47,38 @@ private static string GetInformationalVersion()
?? AssemblyVersion + "-<Unidentified>";
}

private static void SetUpdatedAndChangeLog()
{
if (IsPreviewVersion)
return;
if (Config.UI.CurrentMBACoreVersion == InformationalVersion)
return;

Updated = true;
Config.UI.CurrentMBACoreVersion = InformationalVersion;

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 = "<NullOrWhiteSpace>";
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
Expand All @@ -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);
}
}
Expand All @@ -67,12 +105,12 @@ private static async Task<string> 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,
};
Expand Down

0 comments on commit 0090087

Please sign in to comment.