Files
AnotherReplayReader/Window1.xaml.cs
2026-06-21 14:42:04 +02:00

111 lines
3.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using AnotherReplayReader.Utils;
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using System.Windows;
namespace AnotherReplayReader
{
/// <summary>
/// Window1.xaml 的交互逻辑
/// </summary>
internal partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
Refresh(true);
}
private async void Refresh(bool showCached)
{
_setIPButton.IsEnabled = false;
try
{
var loading = new IpAndPlayer[] { new() { Ip = 0, Id = "正在加载..." } };
_dataGrid.ItemsSource = loading;
if (showCached)
{
await Display();
_dataGrid.ItemsSource = loading.Concat(_dataGrid.ItemsSource.Cast<IpAndPlayer>());
}
await Display();
}
catch (Exception e)
{
MessageBox.Show(this, $"无法加载IP表{e}");
}
finally
{
_setIPButton.IsEnabled = true;
}
}
private Task Display(string filter = "", string nameFilter = "")
{
return Task.CompletedTask;
}
private async void OnClick(object sender, RoutedEventArgs e)
{
_setIPButton.IsEnabled = false;
try
{
var ipText = _ipField.Text;
if (!IPAddress.TryParse(ipText, out var ip))
{
MessageBox.Show(this, "IP 格式不正确");
return;
}
var idText = _idField.Text;
if (string.IsNullOrWhiteSpace(idText))
{
var choice = MessageBox.Show(this, "没有输入任何关于该玩家的说明,是否继续?", "注意", MessageBoxButton.OKCancel);
if (choice != MessageBoxResult.OK)
{
return;
}
}
var result = await UpdateIpTable(ip, idText);
if (!result)
{
MessageBox.Show(this, "设置 IP 表失败");
}
Refresh(false);
}
catch (Exception exception)
{
MessageBox.Show(this, $"设置 IP 表时发生错误。\r\n{exception}");
}
finally
{
_setIPButton.IsEnabled = true;
}
}
private Task<bool> UpdateIpTable(IPAddress ip, string idText)
{
var bytes = ip.GetAddressBytes();
var ipNum = (uint)bytes[0] * 256 * 256 * 256 + bytes[1] * 256 * 256 + bytes[2] * 256 + bytes[3];
return Task.FromResult(false);
}
private async void OnIpFieldChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
{
var ipText = _ipField.Text;
var idText = _idField.Text;
await Display(ipText, idText);
}
private void OnDataGridMouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
}
}
}