private void DoCheckForUpdates()
        {
            BackgroundWorker worker = new BackgroundWorker();
            worker.WorkerReportsProgress = true;
            worker.WorkerSupportsCancellation = true;
            worker.DoWork += delegate(object sender, DoWorkEventArgs e)
            {
                BackgroundWorker thisWorker = (BackgroundWorker)sender;

                thisWorker.ReportProgress(0, "Checking Configuration");
                List<Updater> updaterList = new List<Updater>();
                foreach (AutoUpdateTaskConfigurationElement updateTask in Program.LauncherConfiguration.AutoUpdate.AutoUpdateTasks)
                {
                    Updater updater = new Updater();
                    updater.Name = updateTask.Name;

                    // Get the client's dir
                    if (updater.Name == "Client")
                    {
                        updater.RootPath = Directory.GetParent(Path.GetDirectoryName(c_TextBox_Client.Text)).Parent.FullName + "\\";
                    }

                    updater.BaseUrl = updateTask.BaseUrl;
                    updater.VersionFileName = updateTask.VersionFileName;
                    updater.FileListFileName = updateTask.FileListName;
                    updater.VersionCompareMode = updateTask.VersionCompareMode;
                    updater.RestartOnUpdate = updateTask.RestartOnUpdate;
                    updater.ChangelogFileName = updateTask.ChangelogFileName;
                    updaterList.Add(updater);
                }

                Progress progress = new Progress(0, updaterList.Count * 3);
                foreach (Updater updater in updaterList)
                {
                    if (thisWorker.CancellationPending)
                    {
                        e.Cancel = true;
                        return;
                    }

                    thisWorker.ReportProgress(progress.ToProgressPercentage());
                    thisWorker.ReportProgress(0, "Checking Updates For " + updater.Name);
                    switch (updater.CheckForUpdates())
                    {
                        case UpdateCheckResult.DownloadRequired:
                        case UpdateCheckResult.UpdateAvailable:
                            {
                                progress.Increment();
                                thisWorker.ReportProgress(progress.ToProgressPercentage());
                                thisWorker.ReportProgress(0, String.Format("Downloading Changelog for '{0}'", updater.Name));
                                updater.DownloadPatchlog();

                                progress.Increment();
                                thisWorker.ReportProgress(progress.ToProgressPercentage());
                                thisWorker.ReportProgress(0, "Updating " + updater.Name);
                                DialogResult? result = (DialogResult?)this.Invoke(new DoDisplayUpdateCallback(DoDisplayUpdate), updater);
                                if (result.GetValueOrDefault() == DialogResult.Cancel)
                                {
                                    e.Cancel = true;
                                    return;
                                }

                                progress.Increment();
                                thisWorker.ReportProgress(progress.ToProgressPercentage());

                                if (updater.SelfUpdateDetected && updater.SelfUpdateItem.CheckStatus != UpdateCheckStatus.Ok)
                                {
                                    DoRunSelfUpdate(updater.SelfUpdateItem.TargetFileName);
                                    e.Cancel = true;
                                    return;
                                }
                            }
                            break;

                        default:
                            progress.Increment();
                            progress.Increment();
                            progress.Increment();
                            thisWorker.ReportProgress(progress.ToProgressPercentage());
                            break;
                    }
                }
                e.Result = updaterList;
            };
            worker.ProgressChanged += delegate(object sender, ProgressChangedEventArgs e)
            {
                if (e.UserState != null)
                {
                    c_Status.Text = e.UserState.ToString();
                }
                else
                {
                    c_ProgressBar.Value = e.ProgressPercentage;
                }
            };
            worker.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs e)
            {
                DoEnableUI();

                if (e.Error != null)
                {
                    DisplayErrorMessage("Error on client validation.", e.Error);
                    this.Close();
                }
                else if (e.Cancelled)
                {
                    this.Close();
                }
                else
                {
                    DoFillServerList();

                    m_FullErrorText = String.Empty;

                    List<Updater> updaters = e.Result as List<Updater>;
                    if (updaters != null)
                    {
                        int errorCount = 0;
                        StringBuilder errorText = new StringBuilder();
                        foreach (Updater updater in updaters)
                        {
                            if (String.Equals(updater.Name, "Net7", StringComparison.InvariantCultureIgnoreCase))
                            {
                                string version = String.Empty;
                                if (String.IsNullOrEmpty(updater.CurrentVersionText) == false)
                                {
                                    version += "Current Version: " + updater.CurrentVersionText;
                                }
                                if (String.Equals(updater.CurrentVersionText, updater.NewVersionText, StringComparison.InvariantCultureIgnoreCase) == false &&
                                    String.IsNullOrEmpty(updater.NewVersionText) == false)
                                {
                                    if (version.Length > 0) version += ", ";
                                    version += "Server Version: " + updater.NewVersionText;
                                }
                                c_ToolStripStatusLabel_Version.Text = version;
                                c_ToolStripStatusLabel_Version.Visible = (version.Length > 0);
                            }

                            if (updater.CheckResult != UpdateCheckResult.Timeout &&
                                updater.CheckResult != UpdateCheckResult.Error) continue;

                            errorCount++;

                            if (errorText.Length > 0) errorText.Append("\n\n");
                            if (updater.CheckResult == UpdateCheckResult.Timeout)
                            {
                                errorText.Append("Timeout while checking updates for '" + updater.Name + "'");
                            }
                            else if (updater.CheckResult == UpdateCheckResult.Error)
                            {
                                errorText.Append("Error while checking updates for '" + updater.Name + "'");
                            }

                            if (updater.Error != null)
                            {
                                errorText.Append("\nDetails: " + updater.Error.Message);
                            }
                        }

                        if (errorCount > 0)
                        {
                            m_FullErrorText = errorText.ToString();
                            c_ToolStripStatusLabel.Text = "Errors occured while checking for updates (click here for details)";
                            c_ToolStripStatusLabel.Image = LauncherResources.Warning_16x16x32;
                        }
                        else
                        {
                            m_FullErrorText = null;
                            c_ToolStripStatusLabel.Text = String.Empty;
                            c_ToolStripStatusLabel.Image = null;
                        }
                    }
                }

                DoDisplayDefaultStatus();
            };
            m_Worker = worker;
            DoDisableUI();
            worker.RunWorkerAsync();
        }
        private DialogResult DoDisplayUpdate(Updater updater)
        {
            if (updater == null) return DialogResult.None;

            using (FormUpdate dlg = new FormUpdate(updater))
            {
                return dlg.ShowDialog(this);
            }
        }
 public FormUpdate(Updater updater)
 {
     InitializeComponent();
     m_Updater = updater;
 }