Exemple #1
0
        private void cancelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ListViewItem selitem = lvwUpdates.SelectedItems[0];

            BCUpdate.UpdateInfo uinfo = selitem.Tag as BCUpdate.UpdateInfo;
            uinfo.CancelDownload();
        }
Exemple #2
0
        private void frmUpdates_Load(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                Debug.Print("frmUpdates Loaded");
                switch (mUpdateMode)
                {
                case EUpdateMode.Update_Full:


                    grpBasicUpdate.Visible = false;
tryagain:
                    updateobj = new BCUpdate();
                    lvwUpdates.Items.Clear();
                    lvwUpdates.Columns.Clear();
                    lvwUpdates.Columns.Add("NAME", "Name");
                    lvwUpdates.Columns.Add("INSTALLEDVER", "Installed");
                    lvwUpdates.Columns.Add("VERSION", "Version");
                    lvwUpdates.Columns.Add("PROGRESS", "Download Progress", 128);
                    lvwUpdates.Columns.Add("SIZE", "Size", 128);
                    lvwUpdates.Columns.Add("PATCH", "Patch For", 128);
                    lsorter = new GenericListViewSorter(lvwUpdates, sortproc);
                    lookupinfo.Clear();

                    //queued delegates to call after all other elements are added.
                    //this is used for adding patches last.
                    Queue <Action> DeferPatchItems = new Queue <Action>();
                    var            Typelookup      = new Dictionary <int, BCUpdate.UpdateInfo>();
                    try
                    {
                        foreach (BCUpdate.UpdateInfo looper in updateobj.LoadedUpdates)
                        {
                            var loopupdate = looper;
                            //we copy to a local variable because otherwise how a foreach control variable
                            //is closed over can be compiler specific.
                            Dictionary <int, BCUpdate.UpdateInfo> typelookup = Typelookup;
                            loopupdate.Tag = new DrawItemData("", null, null);

                            Action loopbody = (() =>
                            {
                                Color useForeColor = SystemColors.WindowText;
                                String usepatchString = "";
                                if (loopupdate.DownloadFor > 0)
                                {
                                    if (!typelookup.ContainsKey(loopupdate.DownloadFor))
                                    {
                                        usepatchString = "<Unknown>";
                                    }
                                    else
                                    {
                                        var appliedto = typelookup[loopupdate.DownloadFor];
                                        usepatchString = appliedto.DlName;
                                        if (updateobj.getinstalledVersion(appliedto.dlID) == "")
                                        {
                                            useForeColor = SystemColors.GrayText;
                                            usepatchString = "<" + appliedto.DlName + " Not Installed>";
                                        }
                                    }
                                }
                                string[] createdstrings = new string[] { loopupdate.DlName, updateobj.getinstalledVersion(loopupdate.dlID), loopupdate.UpdateVersion, "0", ByteSizeFormatter.FormatSize(loopupdate.FileSize), usepatchString };

                                ListViewItem newitem = new ListViewItem(createdstrings);
                                ((DrawItemData)loopupdate.Tag).lvwitem = newitem;
                                newitem.Tag = loopupdate;
                                newitem.ForeColor = useForeColor;
                                lookupinfo.Add(loopupdate, newitem);
                                lvwUpdates.Items.Add(newitem);
                                typelookup.Add(loopupdate.dlID, loopupdate);
                            });

                            //if we need to defer it, add it to the queue. Otherwise, call it now.
                            if (loopupdate.DownloadFor == 0)
                            {
                                loopbody();
                            }
                            else
                            {
                                DeferPatchItems.Enqueue(loopbody);
                            }
                        }

                        while (DeferPatchItems.Any())
                        {
                            DeferPatchItems.Dequeue()();
                        }
                    }
                    catch (Exception except)
                    {
                        switch (
                            MessageBox.Show(
                                "The Following Exception occured trying to retrieve update information:\n" +
                                except.ToString(), "Unexpected Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error)
                            )
                        {
                        case DialogResult.Retry:
                            goto tryagain;

                        case DialogResult.Cancel:
                            Close();
                            break;
                        }
                    }
                    break;

                case EUpdateMode.Update_Immediate:
                    //resize to Grp
                    Debug.Print("Immediate Update...");
                    //grpBasicUpdate.Location = new Point(ClientRectangle.Left, ClientRectangle.Top);
                    ClientSize = grpBasicUpdate.Size;
                    fraavailupdates.Hide();
                    MinimizeBox            = true;
                    terminateonupdate      = true;
                    grpBasicUpdate.Visible = true;
                    grpBasicUpdate.BringToFront();
                    this.Invalidate();
                    grpBasicUpdate.Invalidate();
                    grpBasicUpdate.Update();
                    this.Invalidate();
                    this.Update();
                    Debug.Print("grpBasicUpdate.Visible=" + grpBasicUpdate.Visible);
                    immediateupdate.CancelDownload();

                    String downloadresult = immediateupdate.DownloadUpdate(progressroutine, completionroutine);
                    if (updatingItems == null)
                    {
                        updatingItems = new List <BCUpdate.UpdateInfo>();
                    }
                    updatingItems.Add(immediateupdate);



                    break;
                }

                Cursor.Current = Cursors.Default;
            }
            catch (Exception exx)
            {
                panRefreshing.Visible = true;
                panRefreshing.BringToFront();
                panRefreshing.Location = new Point(0, 0);
                panRefreshing.Size     = new Size(ClientSize.Width, panLower.Top);
                lblrefreshing.Text     = "An Exception occured retrieving update information.";
                txtException.Text      = exx.ToString();

                btnDownload.Visible = false;
            }
        }