Logging improvements, add "Copy" btn to error message boxes

This commit is contained in:
n00mkrad
2026-01-11 17:39:49 +01:00
parent 58aa582f33
commit 557b0d3a30
4 changed files with 40 additions and 7 deletions

View File

@@ -2,6 +2,7 @@
using System;
using System.Drawing;
using System.Windows.Forms;
using static Flowframes.Ui.UiUtils;
namespace Flowframes.Forms
{
@@ -10,17 +11,32 @@ namespace Flowframes.Forms
private string _text = "";
private string _title = "";
private MessageBoxButtons _btns;
private MessageType _type = MessageType.Message;
private bool _monospace;
private bool _dialogResultSet = false;
public MessageForm(string text, MessageType type, MessageBoxButtons buttons = MessageBoxButtons.OK, bool monospace = false)
{
_type = type;
_text = text;
_title = $"{type}";
_btns = buttons;
_monospace = monospace;
Init();
}
public MessageForm(string text, string title, MessageBoxButtons buttons = MessageBoxButtons.OK, bool monospace = false)
{
_text = text;
_title = title;
_btns = buttons;
_monospace = monospace;
Init();
}
private void Init ()
{
InitializeComponent();
}
@@ -28,6 +44,7 @@ namespace Flowframes.Forms
{
Text = _title;
textLabel.Text = _text;
bool isError = _type == MessageType.Error;
if (_monospace)
{
@@ -36,9 +53,15 @@ namespace Flowframes.Forms
if(_btns == MessageBoxButtons.OK)
{
SetButtons(true, false, false);
SetButtons(true, isError, false);
btn1.Text = "OK";
AcceptButton = btn1;
if(isError)
{
btn2.Text = "Copy";
btn2.Click += (s, ev) => Clipboard.SetText(_text);
}
}
else if(_btns == MessageBoxButtons.YesNo)
{
@@ -95,6 +118,8 @@ namespace Flowframes.Forms
DialogResult = DialogResult.Yes;
else if (_btns == MessageBoxButtons.YesNoCancel) // No Button
DialogResult = DialogResult.No;
else
return;
_dialogResultSet = true;
Close();

View File

@@ -377,7 +377,7 @@ namespace Flowframes.Main
{
if (!File.Exists(outVideo))
{
I.Cancel($"No video was encoded!\n\nFFmpeg Output:\n{AvProcess.lastOutputFfmpeg}");
I.Cancel($"No video was encoded! Check logs and error messages.{(AvProcess.lastOutputFfmpeg.IsEmpty() ? "" : $"\n\nFFmpeg Output:\n{AvProcess.lastOutputFfmpeg}")}");
return;
}

View File

@@ -563,9 +563,17 @@ namespace Flowframes.Os
private static readonly Regex FfmpegLogMemAddr = new Regex(@" @\s*(?:0x)?(?<addr>[0-9A-Fa-f]{8,16})(?=\])", RegexOptions.Compiled);
private static string GetLastLogLines(string logName, int lineCount = 6, bool beautify = true)
private static string GetLastLogLines(string log = "", int lineCount = 6, bool beautify = true)
{
var lll = Logger.GetSessionLogLastLines(logName, lineCount);
if (log.IsEmpty())
{
if (logName.IsNotEmpty())
log = logName;
else
return "N/A";
}
var lll = Logger.GetSessionLogLastLines(log, lineCount);
if (!beautify)
return string.Join("\n", lll);
@@ -668,7 +676,7 @@ namespace Flowframes.Os
if (!hasShownError && line.Contains("vapoursynth.Error:"))
{
hasShownError = true;
ShowErrorBox($"VapourSynth Error:\n\n{line}");
ShowErrorBox($"VapourSynth Error:\n\n{GetLastLogLines()}");
}
}

View File

@@ -9,7 +9,7 @@ using System.Windows.Forms;
namespace Flowframes.Ui
{
class UiUtils
public class UiUtils
{
public static void InitCombox(ComboBox box, int index)
{
@@ -100,7 +100,7 @@ namespace Flowframes.Ui
if (type == MessageType.Warning) icon = MessageBoxIcon.Warning;
else if (type == MessageType.Error) icon = MessageBoxIcon.Error;
var msgForm = new MessageForm(text, type.ToString(), monospace: monospace) { TopMost = true };
var msgForm = new MessageForm(text, type, monospace: monospace) { TopMost = true };
Program.mainForm.Invoke(() => msgForm.ShowDialog());
return DialogResult.OK;
}