-2

我会添加什么,以便如果没有可用的更新,会弹出一个消息框说没有更新?虽然这可能是一个简单的解决方法,但我最近一直在进行很多更新系统的工作,但我只是被它难住了。

        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);
            }
        }
4

1 回答 1

1

比较有什么问题curVersionnewVersion

    if (curVersion == newVersion) {
        MessageBox.Show("No Update Needed");
    } else 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);
        }
    }
于 2013-05-02T21:04:55.600 回答