/
AboutBox1.cs
218 lines (201 loc) · 8.17 KB
/
AboutBox1.cs
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Threading;
using System.Windows.Forms;
using System.Xml;
namespace 血狮2_全球战火启动器
{
partial class AboutBox1 : Form
{
public AboutBox1()
{
InitializeComponent();
}
#region 程序集特性访问器
public string AssemblyTitle
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
if (attributes.Length > 0)
{
AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
if (titleAttribute.Title != "")
{
return titleAttribute.Title;
}
}
return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
}
}
public string AssemblyVersion
{
get
{
return Assembly.GetExecutingAssembly().GetName().Version.ToString();
}
}
public string AssemblyDescription
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyDescriptionAttribute)attributes[0]).Description;
}
}
public string AssemblyProduct
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyProductAttribute)attributes[0]).Product;
}
}
public string AssemblyCopyright
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
}
}
public string AssemblyCompany
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyCompanyAttribute)attributes[0]).Company;
}
}
#endregion
private void logoPictureBox_Click(object sender, EventArgs e)
{
}
private void okButton_Click(object sender, EventArgs e)
{
this.Close();
}
private void AboutBox1_Load(object sender, EventArgs e)
{
}
public const string updateUrl = "http://peacher.sszx.live/BloodLionStarterUpdate.xml";
public const string AppName = "BloodLionStarterUpdate";
public string Version;
public string NewVersion;
public string DownloadUrl;
public string NewDescription;
public void checkUpdate()
{
try
{
Version = label1.Text;
WebClient wc = new WebClient();
Stream stream = wc.OpenRead(updateUrl);
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(stream);
XmlNode list = xmlDoc.SelectSingleNode("Update");
foreach (XmlNode node in list)
{
if (node.Name == "Soft" && node.Attributes["Name"].Value.ToLower() == AppName.ToLower())
{
foreach (XmlNode xml in node)
{
if (xml.Name == "Version") NewVersion = xml.InnerText;
else if (xml.Name == "Download") DownloadUrl = xml.InnerText;
else if (xml.Name == "NewDescription") NewDescription = xml.InnerText;
}
}
}
int VersionNum;
int NewVersionNum;
int.TryParse(Version, out VersionNum);
int.TryParse(NewVersion, out NewVersionNum);
if (NewVersionNum > VersionNum)
{
if (MessageBox.Show("当前版本 " + Version + " 检测到新版本 " + NewVersion + "\n\n" + NewDescription+ "\n\n是否更新?", "发现新版本",MessageBoxButtons.YesNo,MessageBoxIcon.Information).ToString()=="Yes")
{
//下载并替换
try
{
Process UpdateProgram = new Process();
UpdateProgram.StartInfo.UseShellExecute = true;
UpdateProgram.StartInfo.FileName = @".\BLUpdate.exe";
UpdateProgram.Start();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString() + "\n\n简短解释:\n可能是更新程序丢失,请检查BLUpdate.exe程序是否在游戏根目录下");
}
}
}
else
{
MessageBox.Show("当前版本 " + Version + " 已是最新版本", "已是最新版本", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception ex)
{
throw new Exception("更新出现错误,请确认网络连接无误后重试!" + ex.ToString());
}
}
public void DownloadFile(string URL, string filename)
{
float percent = 0;
try
{
System.Net.HttpWebRequest Myrq = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(URL);
System.Net.HttpWebResponse myrp = (System.Net.HttpWebResponse)Myrq.GetResponse();
long totalBytes = myrp.ContentLength;
System.IO.Stream st = myrp.GetResponseStream();
System.IO.Stream so = new System.IO.FileStream(filename, System.IO.FileMode.Create);
long totalDownloadedByte = 0;
byte[] by = new byte[1024];
int osize = st.Read(by, 0, (int)by.Length);
while (osize > 0)
{
totalDownloadedByte = osize + totalDownloadedByte;
System.Windows.Forms.Application.DoEvents();
so.Write(by, 0, osize);
osize = st.Read(by, 0, (int)by.Length);
percent = (float)totalDownloadedByte / (float)totalBytes * 100;
int mypercent = (int)percent;
System.Windows.Forms.Application.DoEvents(); //必须加注这句代码,否则label1将因为循环执行太快而来不及显示信息
}
so.Close();
st.Close();
}
catch (Exception downee)
{
MessageBox.Show(downee.ToString() + "\n\n简短解释:\n下载出错,请检查是否有目录权限;磁盘空间是否已满;若无法解决请进群咨询管理员");
}
}
private void button1_Click(object sender, EventArgs e)
{
DownloadFile("http://peacher.sszx.live/istudioupdate/BLUpdate.exe",@".\BLUpdate.exe");
checkUpdate();
}
}
}