title: Programming an autoupdater / launcher application in c# that works with any program
body: <p>I am making a program updater / launcher that can be used for any program.
  I have a config file on the client and a config file on a http server. I get version numbers from both of them and compare them and if they are are not = then update the client.</p>
  
  <p>I have everything working except for when the update starts. What I need is say if someone downloaded my application and do not use if for say a month and in between that time I have 5 or so updates.
  The problem is how to I get my program to download the first update , install it and then download the next update untill they have all been downloaded?</p>
  
  <p>I am new to programming and this is the only kind of app I can think of to work on to learn.
  Thanks</p>
  
  <p>My settings.conf on http server XML File.</p>
  
  <pre><code>&lt;Table&gt;
  &lt;Product&gt;
  &lt;Product_id&gt;1&lt;/Product_id&gt;
  &lt;Product_name&gt;Infected&lt;/Product_name&gt;
  &lt;Product_version&gt;1.0.0.1&lt;/Product_version&gt;
  &lt;Product_Url&gt;http://localhost/update/v1.0.0.1.exe&lt;/Product_Url&gt;
  &lt;Product_id&gt;2&lt;/Product_id&gt;
  &lt;Product_name&gt;Infected&lt;/Product_name&gt;
  &lt;Product_version&gt;1.0.0.2&lt;/Product_version&gt;
  &lt;Product_Url&gt;http://localhost/update/v1.0.0.2.exe&lt;/Product_Url&gt;
  
  &lt;Product_id&gt;3&lt;/Product_id&gt;
  &lt;Product_name&gt;Infected&lt;/Product_name&gt;
  &lt;Product_version&gt;1.0.0.3&lt;/Product_version&gt;
  &lt;Product_Url&gt;http://localhost/update/v1.0.0.3.exe&lt;/Product_Url&gt;
  
  &lt;Product_id&gt;4&lt;/Product_id&gt;
  &lt;Product_name&gt;Infected&lt;/Product_name&gt;
  &lt;Product_version&gt;1.0.0.4&lt;/Product_version&gt;
  &lt;Product_Url&gt;http://localhost/update/v1.0.0.4.exe&lt;/Product_Url&gt;
  
  &lt;Product_id&gt;5&lt;/Product_id&gt;
  &lt;Product_name&gt;Infected&lt;/Product_name&gt;
  &lt;Product_version&gt;1.0.0.5&lt;/Product_version&gt;
  &lt;Product_Url&gt;http://localhost/update/v1.0.0.5.exe&lt;/Product_Url&gt;
  
  
  &lt;/Product&gt;
  &lt;/Table&gt;
  </code></pre>
  
  <p>My Client Config XML file.</p>
  
  <pre><code>&lt;Table&gt;
  &lt;Product&gt;
  &lt;Product_id&gt;1&lt;/Product_id&gt;
  &lt;Product_name&gt;Infected&lt;/Product_name&gt;
  &lt;Product_version&gt;1.0.0.0&lt;/Product_version&gt;
  &lt;Product_Url&gt;http://localhost/update/v1.0.0.1.exe&lt;/Product_Url&gt;
  &lt;/Product&gt;
  &lt;/Table&gt;
  </code></pre>
  
  <p>My C# Form.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Windows.Forms;
  using System.Xml;
  using System.IO;
  using System.Net;
  using System.Diagnostics;
  using System.Runtime.Remoting;
  
  namespace Launcher
  {
      public partial class Form1 : Form
      {
  
          public Form1()
          {
  
              InitializeComponent();
          }
  
          public string localversion { get; set; }
          public string remoteversion { get; set; }
          public string UpdateURL { get; set; }
  
          private void Form1_Load(object sender, EventArgs e)
          {
  
              webBrowser1.Navigate("http://www.kceoc.com/");
              webBrowser2.Navigate("http://www.kceoc.com/");
  
              button1.Enabled = false;    // Disable the launch button untill all updates are completed.
              GetLocalXMLFile();          //Run first xml function to start everything off.
  
  
          }
  
          private void GetLocalXMLFile()
          {
              try     //Start error checking.
              {
                  using (XmlTextReader localxml = new XmlTextReader("settings.conf"))  //Load xml file in same folder as launcher.exe
                  {
                      while (localxml.Read())  // Start reading the settings.conf file
                      {
                          switch (localxml.NodeType) //Get the Node that we will use.
                          {
                              case XmlNodeType.Text:
                                  label1.Text = localxml.Value;  //Change the text of label1 to value of Node.
                                  string localversion = localxml.Value;  // Store Node Value in string localversion for latter use.
                                  GetRemoteXMLFile(localversion, remoteversion); //Everything went ok and got a value from Node so pass this all to our next function witch is get remote xml.
                                  break;
                          }
                      }
                  }
  
              }
              catch (FileNotFoundException)
              {
                  label1.Text = "Local Config not found. Reinstall the application"; // Catch error incase file is not there.
              }
          }
  
          private void GetRemoteXMLFile(string localversion, string remoteversion)
          {
              try  //Start error checking
              {
                  using (XmlTextReader remotexml = new XmlTextReader("http://localhost/update/settings.conf"))  //Load up remote xml on web server
                  {
                      while (remotexml.Read())  //Start reading xml file from server.
                      {
                          switch (remotexml.NodeType)
                          {
                              case XmlNodeType.Text:
                                  label2.Text = remotexml.Value; // Change value of label2 to remote xml node value
                                  remoteversion = remotexml.Value; // Set the remoteversion string to remotexml.value
                                  CompareXMLFileVersions(localversion, remoteversion); // Everything went ok so send localversion string and remoteversion string to compare function.
                                  break;
                          }
                      }
                  }
  
              }
              catch (FileNotFoundException)
              {
                  label1.Text = "Remote config not found. Maby website id down?"; // Catch error incase file is not there.
              }
          }
  
  
          private void CompareXMLFileVersions(string localversion, string remoteversion)
          {
  
              label1.Text = localversion;         // Just so we can see the value in the lables to konw if they have value or not.
              label2.Text = remoteversion;         // Just so we can see the value in the lables to konw if they have value or not.
  
              if (localversion == remoteversion)  // Comparing the values of localversion and remoteversion and if they have same value then
              {                                   // change label3 to You have latest version.
                  label3.Text = "You have the latest version";
  
              }
              else
              {
                  label3.Text = "There is a new version. Starting update process here"; // If localversion and remoteversion are diffrent then let user know the files are out of date and start the updating process..
                  GetListOfUpdates(remoteversion);  // Starting the updating process function..     
  
              }
          }
  
          private void GetListOfUpdates(string remoteversion)
          {
  
              //WebClient webClient = new WebClient();
              //webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
              //webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
              //webClient.DownloadFileAsync(new Uri(remoteversion), @"v1.0.0.1.exe");
  
              string url = "http://localhost/update/v1.0.0.1.exe";
              WebClient downloader = new WebClient();
              downloader.DownloadFileCompleted += new AsyncCompletedEventHandler(downloader_DownloadFileCompleted);
              downloader.DownloadProgressChanged += new DownloadProgressChangedEventHandler(downloader_DownloadProgressChanged);
              downloader.DownloadFileAsync(new Uri(url), "temp.exe");
  
  
  
          }
  
  
          void downloader_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
          {
  
              label1.Text = e.BytesReceived + " " + e.ProgressPercentage;
          }
          void downloader_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
          {
              //if (e.Error != null)
              //    MessageBox.Show(e.Error.Message);
              //else
              //    MessageBox.Show("Completed!!!");
          }
  
  
      }
  }
  </code></pre>
  
  <p>Thanks</p>