2013-05-02 4 views
-2

Что бы я добавил к этому, чтобы, если обновления нет, появляется окно с сообщением об обновлении? Хотя это, вероятно, легкое решение, в последнее время я работаю над множеством систем обновления, но я просто на него напуган.Обновление C# - чтение кода/читатель xml

 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); 
      } 
     } 
+0

Непонятный вопрос. Не можете ли вы добавить ветку else при сравнении версий и показать там сообщение? – Patrick

+0

Но вы знаете, как работает ключевое слово 'else', правильно? Если обновление отсутствует, оно будет вписываться в ветку else, или я не получу это? – Patrick

+0

@Patrick Да, но так, как у меня есть код для чтения версии, я не могу этого сделать, потому что тогда он неправильно читает версию и всегда возвращает новое обновление. –

ответ

1

Что-то случилось с сравнением curVersion к newVersion?

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