Ejemplo n.º 1
0
        private void UpdateCheck_Load(object sender, EventArgs e)
        {
            _updateStatusLabel.Text = String.Empty;

            TaskHandler.RunTask(delegate(object input)
            {
                object[] parameters = input as object[];
                UpdateCheckControl formReference = parameters[0] as UpdateCheckControl;

                DebugDetector.AssertCheckRunning();

                if (HasPendingUpdates == true)
                {
                    var signal = new TaskDelegate(delegate(object data)
                    {
                        var updateCount = Convert.ToInt32(data);

                        if (MessageBox.Show(new Form()
                        {
                            TopMost = true
                        }, "Free Allegiance Updater has " + updateCount + " files to download.\nYou will not be able to play until these updates are installed.\nWould you like to do this now?", "New updates found!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                        {
                            MessageBox.Show(new Form()
                            {
                                TopMost = true
                            }, "Please restart the application when you are ready to apply updates.", "Update Canceled", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            Application.Exit();
                        }
                    });

                    if (this.InvokeRequired == true)
                    {
                        this.Invoke(signal, PendingUpdates.PendingUpdateCount);
                    }
                    else
                    {
                        signal(PendingUpdates.PendingUpdateCount);
                    }
                }
                else
                {
                    return;
                }

                //Get available lobbies
                UpdateProgress(String.Empty, "Checking lobby status...", 0);
                var lobbies = ServiceHandler.Service.CheckAvailableLobbies();

                foreach (var lobby in lobbies)
                {
                    if (formReference._abortUpdate == true)
                    {
                        break;
                    }

                    UpdateProgress(lobby.Name, "Checking lobby for updates.", 0);

                    if (AutoUpdate.ProcessPendingUpdates(PendingUpdates, lobby, new AutoUpdate.AutoupdateProgressCallback(UpdateProgress), this))
                    {
                        return;
                    }
                }

                TaskDelegate onUpdateCompleteHandler = delegate(object data)
                {
                    UpdateCheckControl updateCompleteFormReference = data as UpdateCheckControl;

                    if (AutoupdateComplete != null)
                    {
                        AutoupdateComplete(updateCompleteFormReference._abortUpdate);
                    }
                };

                if (formReference.InvokeRequired == true)
                {
                    formReference.Invoke(onUpdateCompleteHandler, formReference);
                }
                else
                {
                    onUpdateCompleteHandler(formReference);
                }
            }, this);
        }