using System;
|
using System.IO;
|
using System.Text;
|
using System.Windows;
|
|
namespace IDViewer_2D
|
{
|
public static class VersionHelper
|
{
|
public static void ShowVersionInfo()
|
{
|
try
|
{
|
string versionFile = "版本说明.txt";
|
if (!File.Exists(versionFile))
|
{
|
MessageBox.Show("版本说明文件不存在", "错误", MessageBoxButton.OK, MessageBoxImage.Warning);
|
return;
|
}
|
|
string[] lines = File.ReadAllLines(versionFile, Encoding.UTF8);
|
string latestVersion = "";
|
string latestDate = "";
|
StringBuilder changes = new StringBuilder();
|
|
// 从后向前查找最新版本
|
for (int i = lines.Length - 1; i >= 0; i--)
|
{
|
string line = lines[i].Trim();
|
|
// 查找版本行 (包含日期和v版本号)
|
if (IsVersionLine(line))
|
{
|
ParseVersionLine(line, ref latestVersion, ref latestDate);
|
|
// 收集更新内容
|
for (int j = i + 1; j < lines.Length; j++)
|
{
|
string contentLine = lines[j].Trim();
|
if (string.IsNullOrEmpty(contentLine) || IsVersionLine(contentLine))
|
break;
|
|
changes.AppendLine(contentLine);
|
if (j - i > 8) break; // 最多8行
|
}
|
break;
|
}
|
}
|
|
if (string.IsNullOrEmpty(latestVersion))
|
{
|
MessageBox.Show("未找到版本信息", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
return;
|
}
|
|
string message = $"当前软件版本: {latestVersion}\n" +
|
$"发布日期: {latestDate}\n\n" +
|
$"最新更新内容:\n{changes}\n" +
|
$"完整版本历史记录请查看版本说明.txt文件";
|
|
MessageBox.Show(message, "软件版本说明", MessageBoxButton.OK, MessageBoxImage.Information);
|
}
|
catch (Exception ex)
|
{
|
MessageBox.Show($"读取版本信息出错: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
}
|
}
|
|
private static bool IsVersionLine(string line)
|
{
|
return !string.IsNullOrEmpty(line) &&
|
line.Contains("v") &&
|
line.Contains(".") &&
|
line.Length > 8 &&
|
char.IsDigit(line[0]);
|
}
|
|
private static void ParseVersionLine(string line, ref string version, ref string date)
|
{
|
string[] parts = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
|
|
foreach (string part in parts)
|
{
|
if (part.Contains("v") && part.Contains("."))
|
{
|
version = part;
|
}
|
else if (part.Contains(".") && part.Length >= 8 && char.IsDigit(part[0]))
|
{
|
date = part;
|
}
|
}
|
}
|
}
|
}
|