private async void reloadWbfsIsoFile() { using (var cancelTokenSource = new CancellationTokenSource()) using (var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(exitTokenSource.Token, cancelTokenSource.Token)) { CancellationToken ct = linkedTokenSource.Token; ProgressBar progressBar = new ProgressBar(verboseToolStripMenuItem.Checked); progressBar.callback = (b) => { try { cancelTokenSource?.Cancel(); } catch (ObjectDisposedException) { } }; progressBar.Show(this); var progress = new Progress <ProgressInfo>(progressInfo => { progressBar.update(progressInfo); Debug.WriteLine(progressInfo.line); }); var inputWbfsIso = setInputISOLocation.Text; try { await ExeChecker.makeSureWitInstalled(ct, ProgressInfo.makeSubProgress(progress, 0, 1)).ConfigureAwait(true); var mapDescriptors = await PatchProcess.Open(inputWbfsIso, progress, ct); Go.Enabled = true; clearListButton.Enabled = true; buttonAddMap.Enabled = true; setOutputLocationButton.Enabled = true; buttonSaveConfiguration.Enabled = false; buttonLoadConfiguration.Enabled = true; BindingSource bs = new BindingSource(); bs.DataSource = mapDescriptors; dataGridView1.DataSource = bs; DataGridView1_CellEndEdit(null, null); for (int i = 0; i < this.dataGridView1.Columns.Count; i++) { DataGridViewColumn column = dataGridView1.Columns[i]; if (column.Name == "VentureCardActiveCount") { dataGridView1.Columns.RemoveAt(i); if (!dataGridView1.Columns.Contains(VentureCards)) { dataGridView1.Columns.Insert(i, VentureCards); } break; } } for (int i = 0; i < this.dataGridView1.Columns.Count; i++) { DataGridViewColumn column = this.dataGridView1.Columns[i]; // set autosizing column.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCellsExceptHeader; //store autosized widths int colw = column.Width; //remove autosizing column.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; //set width to calculated by autosize if (colw > 75 && column.Name.StartsWith("SwitchRotation")) { colw = 75; } if (colw > 100 && column.Name != "Name_EN") { colw = 100; } column.Width = colw; column.Resizable = DataGridViewTriState.True; if (column.Name == "ExportMd" || column.Name == "ImportMd") { column.Frozen = true; column.Resizable = DataGridViewTriState.False; } else if (column.ReadOnly) { column.DefaultCellStyle = readOnlyColumnStyle; } else { column.DefaultCellStyle = editColumnStyle; column.Frozen = true; column.Width += 25; } if (column.Name == "Name_EN") { column.Frozen = true; } } } catch (Exception e) { setInputISOLocation.Text = "None"; Go.Enabled = false; clearListButton.Enabled = false; buttonAddMap.Enabled = false; buttonRemoveMap.Enabled = false; setOutputLocationButton.Enabled = false; buttonSaveConfiguration.Enabled = false; buttonLoadConfiguration.Enabled = false; progressBar.appendText(e.Message); progressBar.appendText(Environment.NewLine + Environment.NewLine + e.ToString()); progressBar.EnableButton(); Debug.WriteLine(e.ToString()); } } }
private async void Go_Click(object sender, EventArgs e) { var outputFile = setOutputPathLabel.Text; var inputFile = setInputISOLocation.Text; if (String.IsNullOrWhiteSpace(outputFile) || outputFile.ToLower() == "none") { DialogResult dialogResult = MessageBox.Show("Do you want to patch the existing location?" + Environment.NewLine + inputFile + Environment.NewLine + Environment.NewLine + "Make sure you have a backup.", "Files already exist", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { outputFile = inputFile; } else { return; } } using (var cancelTokenSource = new CancellationTokenSource()) using (var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(exitTokenSource.Token, cancelTokenSource.Token)) { CancellationToken ct = linkedTokenSource.Token; ProgressBar progressBar = new ProgressBar(verboseToolStripMenuItem.Checked); progressBar.callback = (b) => { try { cancelTokenSource?.Cancel(); } catch (ObjectDisposedException) { } }; progressBar.Show(this); var progress = new Progress <ProgressInfo>(progressInfo => { progressBar.update(progressInfo); Debug.WriteLine(progressInfo.line); }); try { await ExeChecker.makeSureWszstInstalled(ct, ProgressInfo.makeSubProgress(progress, 0, 1)).ConfigureAwait(true); await ExeChecker.makeSureBenzinInstalled(ct, ProgressInfo.makeSubProgress(progress, 1, 2)).ConfigureAwait(true); await PatchProcess.Save(inputFile, outputFile, GetMapDescriptors(), this.patchWiimmfi.Checked, progress, ct); // TODO, better cleanup Invoke((MethodInvoker) delegate { progressBar.ShowCheckbox("Cleanup temporary files.", false); progressBar.callback = (c) => { if (c) { PatchProcess.CleanCache(inputFile); PatchProcess.CleanRiivolution(); } PatchProcess.CleanTemp(); }; }); } catch (Exception e2) { Invoke((MethodInvoker) delegate { progressBar.appendText(e2.Message); progressBar.appendText(Environment.NewLine + Environment.NewLine + e2.ToString()); progressBar.EnableButton(); }); Debug.WriteLine(e2.ToString()); } } }