From baf65730360a753bc74d028d62a5f71d4a65e349 Mon Sep 17 00:00:00 2001 From: libertyernie Date: Wed, 22 May 2024 13:22:20 -0500 Subject: [PATCH] Add error display --- LoopingAudioConverter.Conversion/Converter.cs | 2 +- LoopingAudioConverter/ErrorForm.Designer.cs | 87 +++++++++++++ LoopingAudioConverter/ErrorForm.cs | 18 +++ LoopingAudioConverter/ErrorForm.resx | 120 ++++++++++++++++++ .../LoopingAudioConverter.csproj | 9 ++ LoopingAudioConverter/OptionsForm.cs | 9 +- 6 files changed, 241 insertions(+), 4 deletions(-) create mode 100644 LoopingAudioConverter/ErrorForm.Designer.cs create mode 100644 LoopingAudioConverter/ErrorForm.cs create mode 100644 LoopingAudioConverter/ErrorForm.resx diff --git a/LoopingAudioConverter.Conversion/Converter.cs b/LoopingAudioConverter.Conversion/Converter.cs index f5b8f8e..73d0f29 100644 --- a/LoopingAudioConverter.Conversion/Converter.cs +++ b/LoopingAudioConverter.Conversion/Converter.cs @@ -22,7 +22,7 @@ public static class Converter { public static async Task ConvertFilesAsync(IConverterEnvironment env, IConverterOptions o, IReadOnlyList inputFiles, IProgress progress = null) { FFmpegEngine effectEngine = File.Exists(env.FFmpegPath) ? new FFmpegEngine(env.FFmpegPath) - : throw new Exception("Could not find ffmpeg - please specify ffmpeg_path in .config file"); + : throw new Exception("Either the file LoopingAudioConverter.config does not contain ffmpeg_path, or ffmpeg.exe could not be found at that path."); IAudioExporter getExporter() { switch (o.ExporterType) { diff --git a/LoopingAudioConverter/ErrorForm.Designer.cs b/LoopingAudioConverter/ErrorForm.Designer.cs new file mode 100644 index 0000000..deacbaa --- /dev/null +++ b/LoopingAudioConverter/ErrorForm.Designer.cs @@ -0,0 +1,87 @@ +namespace LoopingAudioConverter { + partial class ErrorForm { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) { + if (disposing && (components != null)) { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() { + this.label1 = new System.Windows.Forms.Label(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.button1 = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 12); + this.label1.Margin = new System.Windows.Forms.Padding(3); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(112, 13); + this.label1.TabIndex = 0; + this.label1.Text = "An error has occurred."; + // + // textBox1 + // + this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.textBox1.Location = new System.Drawing.Point(12, 31); + this.textBox1.Multiline = true; + this.textBox1.Name = "textBox1"; + this.textBox1.ReadOnly = true; + this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Both; + this.textBox1.Size = new System.Drawing.Size(360, 289); + this.textBox1.TabIndex = 1; + // + // button1 + // + this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.button1.DialogResult = System.Windows.Forms.DialogResult.OK; + this.button1.Location = new System.Drawing.Point(297, 326); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(75, 23); + this.button1.TabIndex = 2; + this.button1.Text = "OK"; + this.button1.UseVisualStyleBackColor = true; + // + // ErrorForm + // + this.AcceptButton = this.button1; + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(384, 361); + this.Controls.Add(this.button1); + this.Controls.Add(this.textBox1); + this.Controls.Add(this.label1); + this.Name = "ErrorForm"; + this.Text = "Error"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.Button button1; + } +} \ No newline at end of file diff --git a/LoopingAudioConverter/ErrorForm.cs b/LoopingAudioConverter/ErrorForm.cs new file mode 100644 index 0000000..9f200ed --- /dev/null +++ b/LoopingAudioConverter/ErrorForm.cs @@ -0,0 +1,18 @@ +using System.Windows.Forms; + +namespace LoopingAudioConverter { + public partial class ErrorForm : Form { + public string Message { + get { + return textBox1.Text; + } + set { + textBox1.Text = value; + } + } + + public ErrorForm() { + InitializeComponent(); + } + } +} diff --git a/LoopingAudioConverter/ErrorForm.resx b/LoopingAudioConverter/ErrorForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/LoopingAudioConverter/ErrorForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/LoopingAudioConverter/LoopingAudioConverter.csproj b/LoopingAudioConverter/LoopingAudioConverter.csproj index acb8c49..7e7445b 100644 --- a/LoopingAudioConverter/LoopingAudioConverter.csproj +++ b/LoopingAudioConverter/LoopingAudioConverter.csproj @@ -66,6 +66,12 @@ + + Form + + + ErrorForm.cs + @@ -113,6 +119,9 @@ AACQualityForm.cs + + ErrorForm.cs + VGAudioOptionsForm.cs diff --git a/LoopingAudioConverter/OptionsForm.cs b/LoopingAudioConverter/OptionsForm.cs index 70d43f9..44954a7 100644 --- a/LoopingAudioConverter/OptionsForm.cs +++ b/LoopingAudioConverter/OptionsForm.cs @@ -145,10 +145,10 @@ public OptionsForm() { }) { string v = ConfigurationManager.AppSettings[str]; if (v == null) { - MessageBox.Show(this, $"The .config file setting {str} could not be found.", Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); + MessageBox.Show(this, $"The file LoopingAudioConverter.config does not have a setting {str}.", Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } if (!File.Exists(v)) { - MessageBox.Show(this, $"The file {v} could not be found.", Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); + MessageBox.Show(this, $"The file LoopingAudioConverter.config has a {str} of {v}, but the file at that path is missing.", Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }; @@ -444,7 +444,10 @@ private async void btnOkay_Click(object sender, EventArgs e) { await t; } catch (Exception ex) { Console.Error.WriteLine(ex); - MessageBox.Show(this, "An error occurred.\r\nFor more details, run from cmd.exe and write a log file:\r\n\r\nLoopingAudioConverter.exe 2> log.txt", ex.GetType().Name, MessageBoxButtons.OK, MessageBoxIcon.Error); + using (var form = new ErrorForm()) { + form.Message = ex.ToString(); + form.ShowDialog(this); + } } runningTasks.Remove(t); UpdateTitle();