C3032
2025-12-20 38c333f8091e5062be0bbdd81960315ebce69008
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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;
                }
            }
        }
    }
}