internal static void StartProgressDialog(this IProgressDialog progressDialog, IntPtr hwndParent, string pwzString) { progressDialog.SetTitle(Application.ProductName); progressDialog.SetCancelMsg("Please wait until the current process is finished", IntPtr.Zero); progressDialog.SetLine(1, pwzString, false, IntPtr.Zero); progressDialog.StartProgressDialog(hwndParent, null, (uint)(IPD_Flags.Modal | IPD_Flags.AutoTime | IPD_Flags.NoMinimize), IntPtr.Zero); progressDialog.SetProgress(0, 100); }
private void backgroundWorkerProcess_ProgressChanged(object sender, ProgressChangedEventArgs e) { if (progressDialog.HasUserCancelled()) { if (backgroundWorkerProcess.IsBusy) { backgroundWorkerProcess.CancelAsync(); } } progressDialog.SetLine(2, e.UserState as string, true, IntPtr.Zero); progressDialog.SetProgress((uint)e.ProgressPercentage, 100); }
public void reloadData() { uint index = 0, count = (uint)titles.Count; objectListView.SetObjects(titles); foreach (OLVListItem listItem in objectListView.Items) { Title title = listItem.RowObject as Title; progressDialog?.SetLine(2, title.titleName, true, IntPtr.Zero); progressDialog?.SetProgress(index++, count); string titleID = title.type == TitleType.AddOnContent ? title.titleID : title.baseTitleID ?? ""; Process.latestVersions.TryGetValue(titleID, out uint latestVersion); Process.versionList.TryGetValue(titleID, out uint version); Process.titleVersions.TryGetValue(titleID, out uint titleVersion); if (latestVersion < version || latestVersion < titleVersion) { listItem.BackColor = title.signature != true ? Color.OldLace : Color.LightYellow; } else if (title.signature != true) { listItem.BackColor = Color.WhiteSmoke; } if (title.permission == Title.Permission.Dangerous) { listItem.ForeColor = Color.DarkRed; } else if (title.permission == Title.Permission.Unsafe) { listItem.ForeColor = Color.Indigo; } } }
public void InitTest() { var idlg = new IProgressDialog(); idlg.SetTitle("Testing progress"); idlg.SetCancelMsg("Don't like this?"); idlg.SetLine(1, "Doing something really slow.", false); idlg.SetLine(2, @"C:\Users\you\Documents\GitHubRepos\Vanara\UnitTests\PInvoke\Shell32\ProgressDialogTests.cs", true); idlg.StartProgressDialog(IntPtr.Zero, null, PROGDLG.PROGDLG_AUTOTIME); var rnd = new Random(); for (uint i = 0; i < 100; i++) { if (idlg.HasUserCancelled()) { break; } idlg.SetProgress(i, 100); Thread.Sleep(rnd.Next(50, 750)); } idlg.StopProgressDialog(); }
private void _backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { _cancellationPending = _dialog.HasUserCancelled(); // ReportProgress doesn't allow values outside this range. However, CancellationPending will call // BackgroundWorker.ReportProgress directly with a value that is outside this range to update the value of the property. if (e.ProgressPercentage >= 0 && e.ProgressPercentage <= 100) { _dialog.SetProgress((uint)e.ProgressPercentage, 100); ProgressChangedData data = e.UserState as ProgressChangedData; if (data != null) { if (data.Text != null) { Text = data.Text; } if (data.Description != null) { Description = data.Description; } OnProgressChanged(new ProgressChangedEventArgs(e.ProgressPercentage, data.UserState)); } } }
private void exportToolStripMenuItem_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Title = "Export Titles"; saveFileDialog.Filter = "CSV File (*.csv)|*.csv"; Process.log?.WriteLine("\nExport Titles"); if (saveFileDialog.ShowDialog() == DialogResult.OK) { string filename = saveFileDialog.FileName; if (filename.EndsWith(".csv", StringComparison.OrdinalIgnoreCase)) { using (var writer = new StreamWriter(filename)) { progressDialog = (IProgressDialog) new ProgressDialog(); progressDialog.StartProgressDialog(Handle, "Exporting titles"); char separator = Common.Settings.Default.CsvSeparator; if (separator != '\0') { writer.WriteLine("sep={0}", separator); } else { separator = ','; } writer.WriteLine("# publisher {0} {1}", Application.ProductName, Application.ProductVersion); writer.WriteLine("# updated {0}", String.Format("{0:F}", DateTime.Now)); writer.WriteLine(String.Join(separator.ToString(), Common.Title.Properties)); uint index = 0, count = (uint)titles.Count; foreach (var title in titles) { if (progressDialog.HasUserCancelled()) { break; } progressDialog.SetLine(2, title.titleName, true, IntPtr.Zero); progressDialog.SetProgress(index++, count); writer.WriteLine(String.Join(separator.ToString(), new string[] { title.titleID.Quote(separator), title.baseTitleID.Quote(separator), title.titleName.Quote(separator), title.displayVersion.Quote(separator), title.versionString.Quote(separator), title.latestVersionString.Quote(separator), title.systemUpdateString.Quote(separator), title.systemVersionString.Quote(separator), title.applicationVersionString.Quote(separator), title.masterkeyString.Quote(separator), title.titleKey.Quote(separator), title.publisher.Quote(separator), title.languagesString.Quote(separator), title.filename.Quote(separator), title.filesizeString.Quote(separator), title.typeString.Quote(separator), title.distribution.ToString().Quote(separator), title.structureString.Quote(separator), title.signatureString.Quote(separator), title.permissionString.Quote(separator), title.error.Quote(separator), })); } Process.log?.WriteLine("\n{0} of {1} titles exported", index, titles.Count); progressDialog.StopProgressDialog(); Activate(); MessageBox.Show(String.Format("{0} of {1} titles exported", index, titles.Count), Application.ProductName); } } else { MessageBox.Show(String.Format("This file type is not supported {0}", Path.GetExtension(filename)), Application.ProductName); } } }
private void exportToolStripMenuItem_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Title = "Export Titles"; saveFileDialog.Filter = "Text Documents (*.txt)|*.txt|All Files (*.*)|*.*"; Process.log?.WriteLine("\nExport Titles"); if (saveFileDialog.ShowDialog() == DialogResult.OK) { using (var writer = new StreamWriter(saveFileDialog.FileName)) { progressDialog = (IProgressDialog) new ProgressDialog(); progressDialog.StartProgressDialog(Handle, "Exporting titles"); writer.WriteLine("{0} {1}", aboutBox.AssemblyTitle, aboutBox.AssemblyVersion); writer.WriteLine("--------------------------------------------------------------\n"); writer.WriteLine("Export titles starts at {0}\n", String.Format("{0:F}", DateTime.Now)); uint index = 0, count = (uint)titles.Count; foreach (var title in titles) { if (progressDialog.HasUserCancelled()) { break; } progressDialog.SetLine(2, title.titleName, true, IntPtr.Zero); progressDialog.SetProgress(index++, count); writer.WriteLine("{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{9}|{10}|{11}|{12}|{13}|{14}", title.titleID, title.titleName, title.displayVersion, title.versionString, title.latestVersionString, title.firmware, title.masterkeyString, title.filename, title.filesizeString, title.typeString, title.distribution, title.structureString, title.signatureString, title.permissionString, title.error); } writer.WriteLine("\n{0} of {1} titles exported", index, titles.Count); Process.log?.WriteLine("\n{0} of {1} titles exported", index, titles.Count); progressDialog.StopProgressDialog(); Activate(); MessageBox.Show(String.Format("{0} of {1} titles exported", index, titles.Count), Application.ProductName); } } }
private void exportToolStripMenuItem_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Title = "Export Titles"; saveFileDialog.Filter = "CSV File (*.csv)|*.csv|Excel Workbook (*.xlsx)|*.xlsx"; Process.log?.WriteLine("\nExport Titles"); if (saveFileDialog.ShowDialog() == DialogResult.OK) { string filename = saveFileDialog.FileName; if (filename.EndsWith(".csv", StringComparison.OrdinalIgnoreCase)) { using (var writer = new StreamWriter(filename)) { progressDialog = (IProgressDialog) new ProgressDialog(); progressDialog.StartProgressDialog(Handle, "Exporting titles"); char separator = Common.Settings.Default.CsvSeparator; if (separator != '\0') { writer.WriteLine("sep={0}", separator); } else { separator = ','; } writer.WriteLine("# publisher {0} {1}", Application.ProductName, Application.ProductVersion); writer.WriteLine("# updated {0}", String.Format("{0:F}", DateTime.Now)); writer.WriteLine(String.Join(separator.ToString(), Common.Title.Properties)); uint index = 0, count = (uint)titles.Count; foreach (var title in titles) { if (progressDialog.HasUserCancelled()) { break; } progressDialog.SetLine(2, title.titleName, true, IntPtr.Zero); progressDialog.SetProgress(index++, count); writer.WriteLine(String.Join(separator.ToString(), new string[] { title.titleID.Quote(separator), title.baseTitleID.Quote(separator), title.titleName.Quote(separator), title.displayVersion.Quote(separator), title.versionString.Quote(separator), title.latestVersionString.Quote(separator), title.systemUpdateString.Quote(separator), title.systemVersionString.Quote(separator), title.applicationVersionString.Quote(separator), title.masterkeyString.Quote(separator), title.titleKey.Quote(separator), title.publisher.Quote(separator), title.languagesString.Quote(separator), title.filename.Quote(separator), title.filesizeString.Quote(separator), title.typeString.Quote(separator), title.distribution.ToString().Quote(separator), title.structureString.Quote(separator), title.signatureString.Quote(separator), title.permissionString.Quote(separator), title.error.Quote(separator), })); } Process.log?.WriteLine("\n{0} of {1} titles exported", index, titles.Count); progressDialog.StopProgressDialog(); Activate(); MessageBox.Show(String.Format("{0} of {1} titles exported", index, titles.Count), Application.ProductName); } } else if (filename.EndsWith(".xlsx", StringComparison.OrdinalIgnoreCase)) { using (ExcelPackage excel = new ExcelPackage()) { progressDialog = (IProgressDialog) new ProgressDialog(); progressDialog.StartProgressDialog(Handle, "Exporting titles"); ExcelWorksheet worksheet = excel.Workbook.Worksheets.Add(Common.History.Default.Titles.LastOrDefault().description ?? Application.ProductName); worksheet.Cells[1, 1, 1, Title.Properties.Count()].LoadFromArrays(new List <string[]> { Title.Properties }); worksheet.Cells["1:1"].Style.Font.Bold = true; worksheet.Cells["1:1"].Style.Font.Color.SetColor(Color.White); worksheet.Cells["1:1"].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; worksheet.Cells["1:1"].Style.Fill.BackgroundColor.SetColor(Color.MidnightBlue); uint index = 0, count = (uint)titles.Count; foreach (var title in titles) { if (progressDialog.HasUserCancelled()) { break; } progressDialog.SetLine(2, title.titleName, true, IntPtr.Zero); progressDialog.SetProgress(index++, count); var data = new List <string[]> { new string[] { title.titleID, title.baseTitleID, title.titleName, title.displayVersion, title.versionString, title.latestVersionString, title.systemUpdateString, title.systemVersionString, title.applicationVersionString, title.masterkeyString, title.titleKey, title.publisher, title.languagesString, title.filename, title.filesizeString, title.typeString, title.distribution.ToString(), title.structureString, title.signatureString, title.permissionString, title.error, } }; worksheet.Cells[(int)index + 1, 1].LoadFromArrays(data); string titleID = title.type == TitleType.AddOnContent ? title.titleID : title.baseTitleID ?? ""; Process.latestVersions.TryGetValue(titleID, out uint latestVersion); Process.versionList.TryGetValue(titleID, out uint version); Process.titleVersions.TryGetValue(titleID, out uint titleVersion); if (latestVersion < version || latestVersion < titleVersion) { worksheet.Cells[(int)index + 1, 1, (int)index + 1, Title.Properties.Count()].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; worksheet.Cells[(int)index + 1, 1, (int)index + 1, Title.Properties.Count()].Style.Fill.BackgroundColor.SetColor(title.signature != true ? Color.OldLace : Color.LightYellow); } else if (title.signature != true) { worksheet.Cells[(int)index + 1, 1, (int)index + 1, Title.Properties.Count()].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; worksheet.Cells[(int)index + 1, 1, (int)index + 1, Title.Properties.Count()].Style.Fill.BackgroundColor.SetColor(Color.WhiteSmoke); } if (title.permission == Title.Permission.Dangerous) { worksheet.Cells[(int)index + 1, 1, (int)index + 1, Title.Properties.Count()].Style.Font.Color.SetColor(Color.DarkRed); } else if (title.permission == Title.Permission.Unsafe) { worksheet.Cells[(int)index + 1, 1, (int)index + 1, Title.Properties.Count()].Style.Font.Color.SetColor(Color.Indigo); } } ExcelRange range = worksheet.Cells[1, 1, (int)count + 1, Title.Properties.Count()]; range.Style.Border.Top.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; range.Style.Border.Left.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; range.Style.Border.Right.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; range.Style.Border.Bottom.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; worksheet.Column(1).Width = 18; worksheet.Column(2).Width = 18; worksheet.Column(3).AutoFit(); worksheet.Column(3).Width = Math.Max(worksheet.Column(3).Width, 30); worksheet.Column(4).Width = 16; worksheet.Column(5).Width = 16; worksheet.Column(6).Width = 16; worksheet.Column(7).Width = 16; worksheet.Column(8).Width = 16; worksheet.Column(9).Width = 16; worksheet.Column(10).Width = 16; worksheet.Column(11).AutoFit(); worksheet.Column(11).Width = Math.Max(worksheet.Column(11).Width, 36); worksheet.Column(12).AutoFit(); worksheet.Column(12).Width = Math.Max(worksheet.Column(12).Width, 30); worksheet.Column(13).Width = 18; worksheet.Column(14).AutoFit(); worksheet.Column(14).Width = Math.Max(worksheet.Column(14).Width, 54); worksheet.Column(15).Width = 10; worksheet.Column(16).Width = 10; worksheet.Column(17).Width = 12; worksheet.Column(18).Width = 12; worksheet.Column(19).Width = 10; worksheet.Column(20).Width = 10; worksheet.Column(21).Width = 40; excel.SaveAs(new FileInfo(filename)); Process.log?.WriteLine("\n{0} of {1} titles exported", index, titles.Count); progressDialog.StopProgressDialog(); Activate(); MessageBox.Show(String.Format("{0} of {1} titles exported", index, titles.Count), Application.ProductName); } } else { MessageBox.Show(String.Format("This file type is not supported {0}", Path.GetExtension(filename)), Application.ProductName); } } }
/// <summary> /// Установить прогресс выполнения в диалоге /// </summary> /// <param name="completed">Сколько выполнено</param> /// <param name="total">Сколько всего надо выполнить</param> public void SetProgress(uint completed, uint total) { _progressDialog.SetProgress(completed, total); }