12,162
社区成员
发帖
与我相关
我的任务
分享
private void Form1_Load(object sender, EventArgs e)
{
System.Diagnostics.Process[] proc = System.Diagnostics.Process.GetProcessesByName("SisenMESS");
//关闭原有应用程序的所有进程
foreach (System.Diagnostics.Process pro in proc)
{
pro.Kill();
}
XmlDocument doc = new XmlDocument();
doc.Load(Application.StartupPath + @"\update.xml");
XmlElement root = doc.DocumentElement;
XmlNode updateNode = root.SelectSingleNode("filelist");
string path = updateNode.Attributes["sourcepath"].Value;
int count = int.Parse(updateNode.Attributes["count"].Value);
for (int i = 0; i < count; i++)
{
XmlNode itemNode = updateNode.ChildNodes[i];
string fileName = itemNode.Attributes["name"].Value;
FileInfo fi = new FileInfo(fileName);
fi.Delete();
//File.Delete(Application.StartupPath + @"\" + fileName);
this.label1.Text = "正在更新: " + fileName + " (" + itemNode.Attributes["size"].Value + " ...";
FileStream fs = File.Open(fileName, FileMode.Create, FileAccess.Write);
fs.Write(System.Convert.FromBase64String(itemNode.SelectSingleNode("val").InnerText), 0, int.Parse(itemNode.Attributes["size"].Value));
fs.Close();
}
label1.Text = "更新完成";
File.Delete(Application.StartupPath + @"\update.xml");
label1.Text = "正在重新启动应用程序...";
System.Diagnostics.Process.Start("SisenMESS.exe");
Close();
Application.Exit();
}