更新程序是比较本地与局域网另一台机上的UpdateList.xml文件中Version差异来更新的.
如果Version不一样,会调用更新
更新程序检查Files下面各个File的ver如果本地与远程不一样, 或没有则会更新本地的文件.
在主程序开始时调一CheckUpdate 一时内打开多次只会提示一次
private static void CheckUpdate()
{
try
{
XmlDocument docLocal = new XmlDocument();
XmlDocument docServer = new XmlDocument();
docLocal.Load("UpdateList.xml");
string strServerXmlPath = docLocal.SelectSingleNode("/AutoUpdater/Updater/ServerXml").Attributes["Name"].InnerText;
docServer.Load(strServerXmlPath);//载入远程的xml
string strLocalVersion = docLocal.SelectSingleNode("/AutoUpdater/Updater/Version").InnerText;
string strServerVersion = docServer.SelectSingleNode("/AutoUpdater/Updater/Version").InnerText;
string strLocalTime = docLocal.SelectSingleNode("/AutoUpdater/Updater/LastUpdateTime").Attributes["Time"].InnerText;
TimeSpan span = DateTime.Now - DateTime.Parse(strLocalTime);
if (strLocalVersion != strServerVersion && span.Hours > 1)
{
if (MessageBox.Show("发现更新, 是否更新?", "更新提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk) == DialogResult.OK)
{
Process.Start("AutoUpdate.exe");
Process.GetCurrentProcess().Kill();
}
}
else
{
//修改下最后更新时间 退出 免得再次打开程序提示更新
docLocal.SelectSingleNode("/AutoUpdater/Updater/LastUpdateTime").Attributes["Time"].InnerText = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
docLocal.Save("UpdateList.xml");
}
}
catch { }
}