private Comparison <ListViewItem> sortproc(ColumnHeader columnobj) { ColumnHeader header = columnobj; if (header.Name == "NAME") { return((a, b) => { var at = a.Tag as BCUpdate.UpdateInfo; var bt = b.Tag as BCUpdate.UpdateInfo; return at.DlName.CompareTo(bt.DlName); }); } //"VERSION" if (header.Name == "INSTALLEDVER") { return((a, b) => { var at = a.Tag as BCUpdate.UpdateInfo; var bt = b.Tag as BCUpdate.UpdateInfo; return BCUpdate.UpdateInfo.CompareVersions(updateobj.getinstalledVersion(at.dlID), updateobj.getinstalledVersion(bt.dlID)); }); } if (header.Name == "VERSION") { return((a, b) => { var at = a.Tag as BCUpdate.UpdateInfo; var bt = b.Tag as BCUpdate.UpdateInfo; return BCUpdate.UpdateInfo.CompareVersions(at.UpdateVersion, bt.UpdateVersion); }); } if (header.Name == "PROGRESS") { return((a, b) => { var at = a.Tag as BCUpdate.UpdateInfo; var bt = b.Tag as BCUpdate.UpdateInfo; var dat = at.Tag as DrawItemData; var dbt = bt.Tag as DrawItemData; int usepercenta, usepercentb; int progindex = header.ListView.Columns["PROGRESS"].Index; int.TryParse(a.SubItems[progindex].Text, out usepercenta); int.TryParse(b.SubItems[progindex].Text, out usepercentb); return usepercenta.CompareTo(usepercentb); }); } if (header.Name == "SIZE") { return((a, b) => { var at = a.Tag as BCUpdate.UpdateInfo; var bt = b.Tag as BCUpdate.UpdateInfo; return at.FileSize.CompareTo(bt.FileSize); }); } return(lvwSortManager.CompareDefault); }
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; } }