|
|
@@ -506,7 +506,7 @@ public partial class DeviceDetailsWindow : Window
|
|
|
var routes = Array.Empty<RemoteInterfaceRouteConfig>();
|
|
|
if (!dhcp4)
|
|
|
{
|
|
|
- if (editor.Addresses.All(item => string.IsNullOrWhiteSpace(item.IP) && string.IsNullOrWhiteSpace(item.Mask)))
|
|
|
+ if (editor.Addresses.Count == 0)
|
|
|
{
|
|
|
ShowStatusMessage($"{editor.SystemName}:IP 地址不能为空,至少需要填写一行地址。", StatusMessageType.Error);
|
|
|
return null;
|
|
|
@@ -525,7 +525,12 @@ public partial class DeviceDetailsWindow : Window
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- var dns = editor.Dns.Select(item => item.Address.Trim()).Where(item => item != string.Empty).ToArray();
|
|
|
+ if (!TryBuildDns(editor, out var dns, out var dnsError))
|
|
|
+ {
|
|
|
+ ShowStatusMessage($"{editor.SystemName}:{dnsError}", StatusMessageType.Error);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
return new RemoteInterfaceConfig
|
|
|
{
|
|
|
Interface = editor.SystemName,
|
|
|
@@ -612,13 +617,16 @@ public partial class DeviceDetailsWindow : Window
|
|
|
private bool TryBuildAddresses(InterfaceEditor editor, out RemoteInterfaceAddressConfig[] addresses, out string error)
|
|
|
{
|
|
|
var result = new List<RemoteInterfaceAddressConfig>();
|
|
|
- foreach (var row in editor.Addresses)
|
|
|
+ for (var i = 0; i < editor.Addresses.Count; i++)
|
|
|
{
|
|
|
+ var row = editor.Addresses[i];
|
|
|
var ip = row.IP.Trim();
|
|
|
var maskText = row.Mask.Trim();
|
|
|
if (ip == string.Empty && maskText == string.Empty)
|
|
|
{
|
|
|
- continue;
|
|
|
+ addresses = [];
|
|
|
+ error = $"第 {i + 1} 行 IP 配置为空,请填写或删除该行。";
|
|
|
+ return false;
|
|
|
}
|
|
|
if (ip.Contains('/'))
|
|
|
{
|
|
|
@@ -651,8 +659,14 @@ public partial class DeviceDetailsWindow : Window
|
|
|
}
|
|
|
|
|
|
addresses = result.ToArray();
|
|
|
+ if (addresses.Length == 0)
|
|
|
+ {
|
|
|
+ error = "IP 地址不能为空,至少需要填写一行地址。";
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
error = string.Empty;
|
|
|
- return addresses.Length > 0;
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
private bool TryBuildRoutes(InterfaceEditor editor, out RemoteInterfaceRouteConfig[] routes, out string error)
|
|
|
@@ -671,14 +685,17 @@ public partial class DeviceDetailsWindow : Window
|
|
|
}
|
|
|
if (editor.CustomRoutesEnabled)
|
|
|
{
|
|
|
- foreach (var row in editor.Routes)
|
|
|
+ for (var i = 0; i < editor.Routes.Count; i++)
|
|
|
{
|
|
|
+ var row = editor.Routes[i];
|
|
|
var to = row.To.Trim();
|
|
|
var maskText = row.Mask.Trim();
|
|
|
var via = row.Via.Trim();
|
|
|
if (to == string.Empty && maskText == string.Empty && via == string.Empty)
|
|
|
{
|
|
|
- continue;
|
|
|
+ routes = [];
|
|
|
+ error = $"自定义路由第 {i + 1} 行为空,请填写或删除该行。";
|
|
|
+ return false;
|
|
|
}
|
|
|
if (to.Contains('/'))
|
|
|
{
|
|
|
@@ -716,6 +733,27 @@ public partial class DeviceDetailsWindow : Window
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ private static bool TryBuildDns(InterfaceEditor editor, out string[] dns, out string error)
|
|
|
+ {
|
|
|
+ var result = new List<string>();
|
|
|
+ for (var i = 0; i < editor.Dns.Count; i++)
|
|
|
+ {
|
|
|
+ var address = editor.Dns[i].Address.Trim();
|
|
|
+ if (address == string.Empty)
|
|
|
+ {
|
|
|
+ dns = [];
|
|
|
+ error = $"DNS 第 {i + 1} 行为空,请填写或删除该行。";
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ result.Add(address);
|
|
|
+ }
|
|
|
+
|
|
|
+ dns = result.ToArray();
|
|
|
+ error = string.Empty;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
private static bool TryParseAddresses(string text, out RemoteInterfaceAddressConfig[] addresses, out string error)
|
|
|
{
|
|
|
var result = new List<RemoteInterfaceAddressConfig>();
|