public Task Close(string fortuneStreetPath, string configPath, ConsoleProgress progress, CancellationToken ct)
 {
     if (File.Exists(configPath))
     {
         File.Delete(configPath);
         PatchProcess.CleanCache(fortuneStreetPath);
         progress?.Report("All cleaned up");
     }
     else
     {
         throw new ArgumentException(fortuneStreetPath + " was not open");
     }
     return(Task.CompletedTask);
 }
Exemplo n.º 2
0
        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());
                    }
                }
        }