改了一亿个东西,修了一亿个 BUG
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
using Microsoft.Win32;
|
||||
using AnotherReplayReader.Utils;
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Windows;
|
||||
|
||||
namespace AnotherReplayReader
|
||||
@@ -21,11 +23,33 @@ namespace AnotherReplayReader
|
||||
}
|
||||
}
|
||||
|
||||
private readonly object _lock = new();
|
||||
private readonly List<string> _list = new();
|
||||
|
||||
public event Action<string>? NewText;
|
||||
public Proxy DebugMessage
|
||||
{
|
||||
get => new Proxy();
|
||||
set => NewText?.Invoke(value.Payload);
|
||||
get => new();
|
||||
set
|
||||
{
|
||||
var text = value.Payload;
|
||||
using var locker = new Lock(_lock);
|
||||
if (NewText is null || _list.Count > 0)
|
||||
{
|
||||
_list.Add(text);
|
||||
if (NewText is not null)
|
||||
{
|
||||
text = string.Join(string.Empty, _list);
|
||||
_list.Clear();
|
||||
_list.Capacity = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
NewText(text);
|
||||
}
|
||||
}
|
||||
|
||||
public event Action? RequestedSave;
|
||||
@@ -36,18 +60,31 @@ namespace AnotherReplayReader
|
||||
/// </summary>
|
||||
public sealed partial class Debug : Window
|
||||
{
|
||||
public static readonly DebugMessageWrapper Instance = new DebugMessageWrapper();
|
||||
public static readonly DebugMessageWrapper Instance = new();
|
||||
private static readonly object _lock = new();
|
||||
private static Debug? _window = null;
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
Interlocked.CompareExchange(ref _window, new(), null);
|
||||
_window.InitializeComponent();
|
||||
using var locker = new Lock(_lock);
|
||||
if (_window is not null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var window = new Debug();
|
||||
window.InitializeComponent();
|
||||
_window = window;
|
||||
Instance.NewText += _window.AppendText;
|
||||
Instance.RequestedSave += _window.ExportInMainWindow;
|
||||
}
|
||||
|
||||
public static new void ShowDialog() => (_window as Window)?.ShowDialog();
|
||||
public static new void ShowDialog() => Lock.Run(_lock, () => (_window as Window)?.ShowDialog());
|
||||
|
||||
protected override void OnClosing(CancelEventArgs e)
|
||||
{
|
||||
e.Cancel = true;
|
||||
Hide();
|
||||
}
|
||||
|
||||
private Debug() { }
|
||||
|
||||
@@ -55,7 +92,7 @@ namespace AnotherReplayReader
|
||||
|
||||
private void OnClear_Click(object sender, RoutedEventArgs e) => _textBox.Clear();
|
||||
|
||||
private void AppendText(string s) => Dispatcher.Invoke(() => _textBox.AppendText(s));
|
||||
private void AppendText(string s) => Dispatcher.InvokeAsync(() => _textBox.AppendText(s));
|
||||
|
||||
private void ExportInMainWindow() => Export(Application.Current.MainWindow);
|
||||
|
||||
@@ -72,11 +109,9 @@ namespace AnotherReplayReader
|
||||
var result = saveFileDialog.ShowDialog(owner);
|
||||
if (result == true)
|
||||
{
|
||||
using (var file = saveFileDialog.OpenFile())
|
||||
using (var writer = new StreamWriter(file))
|
||||
{
|
||||
writer.Write(_textBox.Text);
|
||||
}
|
||||
using var file = saveFileDialog.OpenFile();
|
||||
using var writer = new StreamWriter(file);
|
||||
writer.Write(_textBox.Text);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user