我会添加什么,以便如果没有可用的更新,会弹出一个消息框说没有更新?虽然这可能是一个简单的解决方法,但我最近一直在进行很多更新系统的工作,但我只是被它难住了。
Version newVersion = null;
string url = "";
XmlTextReader reader = null;
try
{
string xmlURL = "URL";
reader = new XmlTextReader(xmlURL);
reader.MoveToContent();
string elementName = "";
if ((reader.NodeType == XmlNodeType.Element) &&
(reader.Name == "App"))
{
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
elementName = reader.Name;
else
{
if ((reader.NodeType == XmlNodeType.Text) &&
(reader.HasValue))
{
switch (elementName)
{
case "version":
newVersion = new Version(reader.Value);
break;
case "url":
url = reader.Value;
break;
}
}
}
}
}
}
catch
{
}
finally
{
if (reader != null) reader.Close();
}
Version curVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
if (curVersion.CompareTo(newVersion) < 0)
{
string title = "New Update Avaliable";
string question = "Download Now?";
if (DialogResult.Yes == MessageBoxEx.Show(this, question, title, MessageBoxButtons.YesNo, MessageBoxIcon.Question))
{
Process.Start(url);
}
}