private void lvwUpdates_DrawSubItem(object sender, DrawListViewSubItemEventArgs e) { // ListViewItem thisitem = e.Item; BCUpdate.UpdateInfo upinfo = (BCUpdate.UpdateInfo)thisitem.Tag; DrawItemData usedrawdata = (DrawItemData)upinfo.Tag; //upinfo.DrawSubItem(sender, e) DrawItemData drawdata = (DrawItemData)upinfo.Tag; if (e.ColumnIndex == 3) { StringFormat centeralign = new StringFormat(); centeralign.Alignment = StringAlignment.Center; e.DrawDefault = false; e.DrawBackground(); int usepercent; int.TryParse(e.SubItem.Text, out usepercent); double percentfraction = (double)usepercent / 100; e.Graphics.DrawRectangle(new Pen(Color.Black), e.Bounds.Left + 2, e.Bounds.Top + 2, e.Bounds.Width - 4, e.Bounds.Height - 4); ThemePaint.DrawProgress(lvwUpdates.Handle, e.Graphics, e.Bounds, (float)percentfraction, ThemePaint.FILLSTATES.PBFS_NORMAL); e.Graphics.DrawString(drawdata.StringDraw, new Font("Consolas", 10), Brushes.Black, e.Bounds, centeralign); } else { e.DrawDefault = true; } }
/// <summary> /// installs all downloaded updates. /// EXE and MSI files will be run directly; .ZIP files will be handled specially (via ZipInstall() which starts out as a stub) /// </summary> private void InstallDownloaded() { foreach (BCUpdate.UpdateInfo loopdownloaded in completeddownloads) { //MessageBox.Show("Downloaded file:" + loopdownloaded.DownloadedFilename); String installfile = loopdownloaded.DownloadedFilename; String grabextension = Path.GetExtension(installfile).ToUpper(); DrawItemData updatedrawdata = (DrawItemData)loopdownloaded.Tag; if (grabextension == ".EXE" || grabextension == ".MSI") { //MessageBox.Show("Running external Program:" + installfile); try { updatedrawdata.StringDraw = "Installing..."; this.Invoke((MethodInvoker)(() => lvwUpdates.Invalidate())); Process executableProgram = Process.Start(installfile); //wait for it to complete. updatedrawdata.StringDraw = "Installing..."; while (!executableProgram.HasExited) { Thread.Sleep(0); } if (executableProgram.ExitCode != 0) { updatedrawdata.StringDraw = "Install Error: " + executableProgram.ExitCode.ToString(); } else { updatedrawdata.StringDraw = "Installed."; } } catch (Exception ex) { updatedrawdata.StringDraw = "Exec Error:" + ex.Message; } } else if (grabextension == ".ZIP") { ZipInstall(installfile); } try { this.Invoke((MethodInvoker)(() => lvwUpdates.Invalidate())); } catch (InvalidOperationException) { return; } } }
private float getAverageCompletion() { double runningtotal = 0; if (updatingItems.Count == 0) { return(0); } foreach (var UpdateItem in this.updatingItems) { DrawItemData did = ((DrawItemData)(UpdateItem).Tag); runningtotal += did.PercentComplete; } return((float)(runningtotal / this.updatingItems.Count)); }
private void updateprogressforitem(ListViewItem UpdateItem, DownloadProgressChangedEventArgs args) { //updates the progress for one of the items. uses the DrawItemData found in the tag of the stored BCUpdate.UpdateInfo which itself is the tag of the given item. float percentage = (float)args.BytesReceived / (float)args.TotalBytesToReceive; //long bytespeed = args.BytesReceived - lastBytesreceived; //UpdateItem.ProgressEvent = args; UpdateItem.SubItems[lvwUpdates.Columns["PROGRESS"].Index].Text = percentage.ToString(); UpdateItem.SubItems[3].Text = percentage.ToString(); DrawItemData itemdraw = ((DrawItemData)((BCUpdate.UpdateInfo)UpdateItem.Tag).Tag); long currspeed = args.BytesReceived - lastBytesreceived; if (currspeed > 0) { itemdraw.ByteSpeed = currspeed; } lastBytesreceived = args.BytesReceived; long speedpersecond = interpolatepersecond(DateTime.Now - lastprogress, itemdraw.ByteSpeed); String speedshow = ByteSizeFormatter.FormatSize(speedpersecond); if (0 < percentage && percentage < 100) { itemdraw.PercentComplete = percentage; itemdraw.StringDraw = String.Format("{0}% ({1}/s)", percentage, speedshow); } else if (args.BytesReceived == args.TotalBytesToReceive) { //complete if (itemdraw.DownloadError == null) { itemdraw.StringDraw = "Ready to Install"; itemdraw.PercentComplete = 100; } else { itemdraw.StringDraw = "Error"; UpdateItem.ToolTipText = "Error:" + itemdraw.DownloadError.Message; } } }