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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace Misc
{
/// <summary>
/// 给定 程序集其中一个类,需要获取程序集版本号
/// </summary>
public class Ver
{
/// <summary>
/// 产品名
/// </summary>
public string Product { get; private set; }
/// <summary>
/// 版本号
/// </summary>
public string V { get; private set; }
/// <summary>
/// 编译时间
/// </summary>
public string BuildTime { get; private set; }
public Ver()
{
}
private Type srcType;
/// <summary>
/// 需要获取程序集版本号, 程序集其中一个类
/// </summary>
public Type SrcType
{
get { return srcType; }
set {
srcType = value;
update();
}
}
void update()
{
Assembly asm = Assembly.GetAssembly(SrcType);
AssemblyProductAttribute asmproduct = (AssemblyProductAttribute)Attribute.GetCustomAttribute(asm, typeof(AssemblyProductAttribute));
Version version = asm.GetName().Version;
string version_str = "v" + version.Major;
if (version.Minor != -1)
{
version_str += "." + version.Minor;
}
if (version.Build != -1)
{
version_str += "." + version.Build;
}
if (version.Revision != -1)
{
version_str += "." + version.Revision;
}
string location = asm.Location;
string buliddt;
if (!string.IsNullOrEmpty(location))
{
buliddt = System.IO.File.GetLastWriteTime(location).ToString("yyyyMMdd");
}
else
{
buliddt = "";
}
Product = asmproduct.Product;
V = version_str;
BuildTime = buliddt;
}
public override string ToString()
{
if (!string.IsNullOrEmpty(BuildTime))
{
return Product + " " + V + " at " + BuildTime;
}
else
{
return Product + " " + V;
}
}
}
public class MainWindowTitle
{
public string Title;
public bool Load()
{
try
{
string json = File.ReadAllText("title.json");
Newtonsoft.Json.JsonConvert.PopulateObject(json, this);
return true;
}
catch
{
return false;
}
}
}
}