using Microsoft.Win32; using System; using System.IO; using System.Windows; namespace AnotherReplayReader { public sealed class DebugMessageWrapper { public readonly struct Proxy { public readonly string Payload; public Proxy(string text) { Payload = text; } public static Proxy operator +(Proxy p, string text) { return string.IsNullOrEmpty(p.Payload) ? new Proxy(text) : new Proxy(p.Payload + text); } } public event Action NewText; public Proxy DebugMessage { get => new Proxy(); set => NewText?.Invoke(value.Payload); } } /// /// Debug.xaml 的交互逻辑 /// public sealed partial class Debug : Window { public static readonly DebugMessageWrapper Instance = new DebugMessageWrapper(); public Debug() { InitializeComponent(); Instance.NewText += t => Dispatcher.Invoke(() => _textBox.AppendText(t)); } private void OnExport_Click(object sender, RoutedEventArgs e) { var saveFileDialog = new SaveFileDialog { Filter = "文本文档 (*.txt)|*.txt|所有文件 (*.*)|*.*", OverwritePrompt = true, }; var result = saveFileDialog.ShowDialog(this); if (result == true) { using (var file = saveFileDialog.OpenFile()) using (var writer = new StreamWriter(file)) { writer.Write(Instance.DebugMessage); } } } private void OnClear_Click(object sender, RoutedEventArgs e) { _textBox.Clear(); } } }