Improved models

pull/5829/head
2dust 2024-10-08 09:50:03 +08:00
parent f60575b77c
commit 3e74bb65bd
17 changed files with 176 additions and 344 deletions

View File

@ -9,8 +9,8 @@ namespace ServiceLib.Handler
/// </summary> /// </summary>
public class ConfigHandler public class ConfigHandler
{ {
private static string configRes = Global.ConfigFileName; private static readonly string _configRes = Global.ConfigFileName;
private static readonly object objLock = new(); private static readonly object _objLock = new();
#region ConfigHandler #region ConfigHandler
@ -21,39 +21,29 @@ namespace ServiceLib.Handler
/// <returns></returns> /// <returns></returns>
public static int LoadConfig(ref Config? config) public static int LoadConfig(ref Config? config)
{ {
//载入配置文件 var result = Utils.LoadResource(Utils.GetConfigPath(_configRes));
var result = Utils.LoadResource(Utils.GetConfigPath(configRes));
if (Utils.IsNotEmpty(result)) if (Utils.IsNotEmpty(result))
{ {
//转成Json
config = JsonUtils.Deserialize<Config>(result); config = JsonUtils.Deserialize<Config>(result);
} }
else else
{ {
if (File.Exists(Utils.GetConfigPath(configRes))) if (File.Exists(Utils.GetConfigPath(_configRes)))
{ {
Logging.SaveLog("LoadConfig Exception"); Logging.SaveLog("LoadConfig Exception");
return -1; return -1;
} }
} }
if (config == null) config ??= new Config();
{
config = new Config config.coreBasicItem ??= new()
{ {
}; logEnabled = false,
} loglevel = "warning",
if (config.coreBasicItem == null) muxEnabled = false,
{ };
config.coreBasicItem = new()
{
logEnabled = false,
loglevel = "warning",
muxEnabled = false,
};
}
//本地监听
if (config.inbound == null) if (config.inbound == null)
{ {
config.inbound = new List<InItem>(); config.inbound = new List<InItem>();
@ -75,55 +65,38 @@ namespace ServiceLib.Handler
config.inbound[0].protocol = EInboundProtocol.socks.ToString(); config.inbound[0].protocol = EInboundProtocol.socks.ToString();
} }
} }
if (config.routingBasicItem == null) config.routingBasicItem ??= new()
{ {
config.routingBasicItem = new() enableRoutingAdvanced = true
{ };
enableRoutingAdvanced = true
};
}
//路由规则
if (Utils.IsNullOrEmpty(config.routingBasicItem.domainStrategy)) if (Utils.IsNullOrEmpty(config.routingBasicItem.domainStrategy))
{ {
config.routingBasicItem.domainStrategy = Global.DomainStrategies[0];//"IPIfNonMatch"; config.routingBasicItem.domainStrategy = Global.DomainStrategies[0];//"IPIfNonMatch";
} }
//if (Utile.IsNullOrEmpty(config.domainMatcher))
//{
// config.domainMatcher = "linear";
//}
//kcp config.kcpItem ??= new KcpItem
if (config.kcpItem == null)
{ {
config.kcpItem = new KcpItem mtu = 1350,
{ tti = 50,
mtu = 1350, uplinkCapacity = 12,
tti = 50, downlinkCapacity = 100,
uplinkCapacity = 12, readBufferSize = 2,
downlinkCapacity = 100, writeBufferSize = 2,
readBufferSize = 2, congestion = false
writeBufferSize = 2, };
congestion = false config.grpcItem ??= new GrpcItem
};
}
if (config.grpcItem == null)
{ {
config.grpcItem = new GrpcItem idle_timeout = 60,
{ health_check_timeout = 20,
idle_timeout = 60, permit_without_stream = false,
health_check_timeout = 20, initial_windows_size = 0,
permit_without_stream = false, };
initial_windows_size = 0, config.tunModeItem ??= new TunModeItem
};
}
if (config.tunModeItem == null)
{ {
config.tunModeItem = new TunModeItem enableTun = false,
{ mtu = 9000,
enableTun = false, };
mtu = 9000,
};
}
config.guiItem ??= new() config.guiItem ??= new()
{ {
enableStatistics = false, enableStatistics = false,
@ -150,19 +123,13 @@ namespace ServiceLib.Handler
} }
} }
if (config.constItem == null) config.constItem ??= new ConstItem();
{
config.constItem = new ConstItem();
}
if (Utils.IsNullOrEmpty(config.constItem.defIEProxyExceptions)) if (Utils.IsNullOrEmpty(config.constItem.defIEProxyExceptions))
{ {
config.constItem.defIEProxyExceptions = Global.IEProxyExceptions; config.constItem.defIEProxyExceptions = Global.IEProxyExceptions;
} }
if (config.speedTestItem == null) config.speedTestItem ??= new();
{
config.speedTestItem = new();
}
if (config.speedTestItem.speedTestTimeout < 10) if (config.speedTestItem.speedTestTimeout < 10)
{ {
config.speedTestItem.speedTestTimeout = 10; config.speedTestItem.speedTestTimeout = 10;
@ -183,34 +150,19 @@ namespace ServiceLib.Handler
xudpProxyUDP443 = "reject" xudpProxyUDP443 = "reject"
}; };
if (config.mux4SboxItem == null) config.mux4SboxItem ??= new()
{ {
config.mux4SboxItem = new() protocol = Global.SingboxMuxs[0],
{ max_connections = 8
protocol = Global.SingboxMuxs[0], };
max_connections = 8
};
}
if (config.hysteriaItem == null) config.hysteriaItem ??= new()
{ {
config.hysteriaItem = new() up_mbps = 100,
{ down_mbps = 100
up_mbps = 100, };
down_mbps = 100
};
}
config.clashUIItem ??= new(); config.clashUIItem ??= new();
config.systemProxyItem ??= new();
if (config.systemProxyItem == null)
{
config.systemProxyItem = new()
{
systemProxyExceptions = config.systemProxyExceptions,
systemProxyAdvancedProtocol = config.systemProxyAdvancedProtocol,
};
}
config.webDavItem ??= new(); config.webDavItem ??= new();
return 0; return 0;
@ -234,12 +186,12 @@ namespace ServiceLib.Handler
/// <param name="config"></param> /// <param name="config"></param>
private static void ToJsonFile(Config config) private static void ToJsonFile(Config config)
{ {
lock (objLock) lock (_objLock)
{ {
try try
{ {
//save temp file //save temp file
var resPath = Utils.GetConfigPath(configRes); var resPath = Utils.GetConfigPath(_configRes);
var tempPath = $"{resPath}_temp"; var tempPath = $"{resPath}_temp";
if (JsonUtils.ToFile(config, tempPath) != 0) if (JsonUtils.ToFile(config, tempPath) != 0)
{ {
@ -260,104 +212,6 @@ namespace ServiceLib.Handler
} }
} }
//public static int ImportOldGuiConfig(Config config, string fileName)
//{
// var result = Utils.LoadResource(fileName);
// if (Utils.IsNullOrEmpty(result))
// {
// return -1;
// }
// var configOld = JsonUtils.Deserialize<ConfigOld>(result);
// if (configOld == null)
// {
// return -1;
// }
// var subItem = JsonUtils.Deserialize<List<SubItem>>(JsonUtils.Serialize(configOld.subItem));
// foreach (var it in subItem)
// {
// if (Utils.IsNullOrEmpty(it.id))
// {
// it.id = Utils.GetGUID(false);
// }
// SQLiteHelper.Instance.Replace(it);
// }
// var profileItems = JsonUtils.Deserialize<List<ProfileItem>>(JsonUtils.Serialize(configOld.vmess));
// foreach (var it in profileItems)
// {
// if (Utils.IsNullOrEmpty(it.indexId))
// {
// it.indexId = Utils.GetGUID(false);
// }
// SQLiteHelper.Instance.Replace(it);
// }
// foreach (var it in configOld.routings)
// {
// if (it.locked)
// {
// continue;
// }
// var routing = JsonUtils.Deserialize<RoutingItem>(JsonUtils.Serialize(it));
// foreach (var it2 in it.rules)
// {
// it2.id = Utils.GetGUID(false);
// }
// routing.ruleNum = it.rules.Count;
// routing.ruleSet = JsonUtils.Serialize(it.rules, false);
// if (Utils.IsNullOrEmpty(routing.id))
// {
// routing.id = Utils.GetGUID(false);
// }
// SQLiteHelper.Instance.Replace(routing);
// }
// config = JsonUtils.Deserialize<Config>(JsonUtils.Serialize(configOld));
// if (config.coreBasicItem == null)
// {
// config.coreBasicItem = new()
// {
// logEnabled = configOld.logEnabled,
// loglevel = configOld.loglevel,
// muxEnabled = configOld.muxEnabled,
// };
// }
// if (config.routingBasicItem == null)
// {
// config.routingBasicItem = new()
// {
// enableRoutingAdvanced = configOld.enableRoutingAdvanced,
// domainStrategy = configOld.domainStrategy
// };
// }
// if (config.guiItem == null)
// {
// config.guiItem = new()
// {
// enableStatistics = configOld.enableStatistics,
// keepOlderDedupl = configOld.keepOlderDedupl,
// ignoreGeoUpdateCore = configOld.ignoreGeoUpdateCore,
// autoUpdateInterval = configOld.autoUpdateInterval,
// checkPreReleaseUpdate = configOld.checkPreReleaseUpdate,
// enableSecurityProtocolTls13 = configOld.enableSecurityProtocolTls13,
// trayMenuServersLimit = configOld.trayMenuServersLimit,
// };
// }
// GetDefaultServer(config);
// GetDefaultRouting(config);
// SaveConfig(config);
// LoadConfig(ref config);
// return 0;
//}
#endregion ConfigHandler #endregion ConfigHandler
#region Server #region Server

View File

@ -68,7 +68,7 @@ namespace ServiceLib.Handler
public int LoadCoreConfigSpeedtest(List<ServerTestItem> selecteds) public int LoadCoreConfigSpeedtest(List<ServerTestItem> selecteds)
{ {
int pid = -1; int pid = -1;
var coreType = selecteds.Exists(t => t.configType == EConfigType.Hysteria2 || t.configType == EConfigType.TUIC || t.configType == EConfigType.WireGuard) ? ECoreType.sing_box : ECoreType.Xray; var coreType = selecteds.Exists(t => t.ConfigType == EConfigType.Hysteria2 || t.ConfigType == EConfigType.TUIC || t.ConfigType == EConfigType.WireGuard) ? ECoreType.sing_box : ECoreType.Xray;
string configPath = Utils.GetConfigPath(Global.CoreSpeedtestConfigFileName); string configPath = Utils.GetConfigPath(Global.CoreSpeedtestConfigFileName);
if (CoreConfigHandler.GenerateClientSpeedtestConfig(_config, configPath, selecteds, coreType, out string msg) != 0) if (CoreConfigHandler.GenerateClientSpeedtestConfig(_config, configPath, selecteds, coreType, out string msg) != 0)
{ {

View File

@ -59,7 +59,7 @@
result = result[Global.ProtocolShares[EConfigType.VMess].Length..]; result = result[Global.ProtocolShares[EConfigType.VMess].Length..];
result = Utils.Base64Decode(result); result = Utils.Base64Decode(result);
//转成Json
VmessQRCode? vmessQRCode = JsonUtils.Deserialize<VmessQRCode>(result); VmessQRCode? vmessQRCode = JsonUtils.Deserialize<VmessQRCode>(result);
if (vmessQRCode == null) if (vmessQRCode == null)
{ {

View File

@ -2,16 +2,16 @@
{ {
public class ClashConnectionModel public class ClashConnectionModel
{ {
public string id { get; set; } public string? id { get; set; }
public string network { get; set; } public string? network { get; set; }
public string type { get; set; } public string? type { get; set; }
public string host { get; set; } public string? host { get; set; }
public ulong upload { get; set; } public ulong upload { get; set; }
public ulong download { get; set; } public ulong download { get; set; }
public string uploadTraffic { get; set; } public string? uploadTraffic { get; set; }
public string downloadTraffic { get; set; } public string? downloadTraffic { get; set; }
public double time { get; set; } public double time { get; set; }
public string elapsed { get; set; } public string? elapsed { get; set; }
public string chain { get; set; } public string? chain { get; set; }
} }
} }

View File

@ -9,29 +9,29 @@
public class ConnectionItem public class ConnectionItem
{ {
public string id { get; set; } = string.Empty; public string? id { get; set; }
public MetadataItem metadata { get; set; } public MetadataItem? metadata { get; set; }
public ulong upload { get; set; } public ulong upload { get; set; }
public ulong download { get; set; } public ulong download { get; set; }
public DateTime start { get; set; } public DateTime start { get; set; }
public List<string>? chains { get; set; } public List<string>? chains { get; set; }
public string rule { get; set; } public string? rule { get; set; }
public string rulePayload { get; set; } public string? rulePayload { get; set; }
} }
public class MetadataItem public class MetadataItem
{ {
public string network { get; set; } public string? network { get; set; }
public string type { get; set; } public string? type { get; set; }
public string sourceIP { get; set; } public string? sourceIP { get; set; }
public string destinationIP { get; set; } public string? destinationIP { get; set; }
public string sourcePort { get; set; } public string? sourcePort { get; set; }
public string destinationPort { get; set; } public string? destinationPort { get; set; }
public string host { get; set; } public string? host { get; set; }
public string nsMode { get; set; } public string? nsMode { get; set; }
public object uid { get; set; } public object uid { get; set; }
public string process { get; set; } public string? process { get; set; }
public string processPath { get; set; } public string? processPath { get; set; }
public string remoteDestination { get; set; } public string? remoteDestination { get; set; }
} }
} }

View File

@ -4,14 +4,14 @@ namespace ServiceLib.Models
{ {
public class ClashProviders public class ClashProviders
{ {
public Dictionary<String, ProvidersItem> providers { get; set; } public Dictionary<string, ProvidersItem>? providers { get; set; }
public class ProvidersItem public class ProvidersItem
{ {
public string name { get; set; } public string? name { get; set; }
public ProxiesItem[] proxies { get; set; } public List<ProxiesItem>? proxies { get; set; }
public string type { get; set; } public string? type { get; set; }
public string vehicleType { get; set; } public string? vehicleType { get; set; }
} }
} }
} }

View File

@ -2,22 +2,22 @@
{ {
public class ClashProxies public class ClashProxies
{ {
public Dictionary<String, ProxiesItem> proxies { get; set; } public Dictionary<string, ProxiesItem>? proxies { get; set; }
public class ProxiesItem public class ProxiesItem
{ {
public string[] all { get; set; } public List<string>? all { get; set; }
public List<HistoryItem> history { get; set; } public List<HistoryItem>? history { get; set; }
public string name { get; set; } public string? name { get; set; }
public string type { get; set; } public string? type { get; set; }
public bool udp { get; set; } public bool udp { get; set; }
public string now { get; set; } public string? now { get; set; }
public int delay { get; set; } public int delay { get; set; }
} }
public class HistoryItem public class HistoryItem
{ {
public string time { get; set; } public string? time { get; set; }
public int delay { get; set; } public int delay { get; set; }
} }
} }

View File

@ -3,15 +3,15 @@
[Serializable] [Serializable]
public class ClashProxyModel public class ClashProxyModel
{ {
public string name { get; set; } public string? name { get; set; }
public string type { get; set; } public string? type { get; set; }
public string now { get; set; } public string? now { get; set; }
public int delay { get; set; } public int delay { get; set; }
public string delayName { get; set; } public string? delayName { get; set; }
public bool isActive { get; set; } public bool isActive { get; set; }
} }

View File

@ -2,12 +2,12 @@
{ {
public class ComboItem public class ComboItem
{ {
public string ID public string? ID
{ {
get; set; get; set;
} }
public string Text public string? Text
{ {
get; set; get; set;
} }

View File

@ -10,8 +10,6 @@
public string indexId { get; set; } public string indexId { get; set; }
public string subIndexId { get; set; } public string subIndexId { get; set; }
public string systemProxyExceptions { get; set; }
public string systemProxyAdvancedProtocol { get; set; }
public ECoreType runningCoreType { get; set; } public ECoreType runningCoreType { get; set; }

View File

@ -4,19 +4,19 @@ namespace ServiceLib.Models
{ {
public class GitHubReleaseAsset public class GitHubReleaseAsset
{ {
[JsonPropertyName("url")] public string Url { get; set; } [JsonPropertyName("url")] public string? Url { get; set; }
[JsonPropertyName("id")] public int Id { get; set; } [JsonPropertyName("id")] public int Id { get; set; }
[JsonPropertyName("node_id")] public string NodeId { get; set; } [JsonPropertyName("node_id")] public string? NodeId { get; set; }
[JsonPropertyName("name")] public string Name { get; set; } [JsonPropertyName("name")] public string? Name { get; set; }
[JsonPropertyName("label")] public object Label { get; set; } [JsonPropertyName("label")] public object Label { get; set; }
[JsonPropertyName("content_type")] public string ContentType { get; set; } [JsonPropertyName("content_type")] public string? ContentType { get; set; }
[JsonPropertyName("state")] public string State { get; set; } [JsonPropertyName("state")] public string? State { get; set; }
[JsonPropertyName("size")] public int Size { get; set; } [JsonPropertyName("size")] public int Size { get; set; }
@ -26,28 +26,28 @@ namespace ServiceLib.Models
[JsonPropertyName("updated_at")] public DateTime UpdatedAt { get; set; } [JsonPropertyName("updated_at")] public DateTime UpdatedAt { get; set; }
[JsonPropertyName("browser_download_url")] public string BrowserDownloadUrl { get; set; } [JsonPropertyName("browser_download_url")] public string? BrowserDownloadUrl { get; set; }
} }
public class GitHubRelease public class GitHubRelease
{ {
[JsonPropertyName("url")] public string Url { get; set; } [JsonPropertyName("url")] public string? Url { get; set; }
[JsonPropertyName("assets_url")] public string AssetsUrl { get; set; } [JsonPropertyName("assets_url")] public string? AssetsUrl { get; set; }
[JsonPropertyName("upload_url")] public string UploadUrl { get; set; } [JsonPropertyName("upload_url")] public string? UploadUrl { get; set; }
[JsonPropertyName("html_url")] public string HtmlUrl { get; set; } [JsonPropertyName("html_url")] public string? HtmlUrl { get; set; }
[JsonPropertyName("id")] public int Id { get; set; } [JsonPropertyName("id")] public int Id { get; set; }
[JsonPropertyName("node_id")] public string NodeId { get; set; } [JsonPropertyName("node_id")] public string? NodeId { get; set; }
[JsonPropertyName("tag_name")] public string TagName { get; set; } [JsonPropertyName("tag_name")] public string? TagName { get; set; }
[JsonPropertyName("target_commitish")] public string TargetCommitish { get; set; } [JsonPropertyName("target_commitish")] public string? TargetCommitish { get; set; }
[JsonPropertyName("name")] public string Name { get; set; } [JsonPropertyName("name")] public string? Name { get; set; }
[JsonPropertyName("draft")] public bool Draft { get; set; } [JsonPropertyName("draft")] public bool Draft { get; set; }
@ -59,10 +59,10 @@ namespace ServiceLib.Models
[JsonPropertyName("assets")] public List<GitHubReleaseAsset> Assets { get; set; } [JsonPropertyName("assets")] public List<GitHubReleaseAsset> Assets { get; set; }
[JsonPropertyName("tarball_url")] public string TarballUrl { get; set; } [JsonPropertyName("tarball_url")] public string? TarballUrl { get; set; }
[JsonPropertyName("zipball_url")] public string ZipballUrl { get; set; } [JsonPropertyName("zipball_url")] public string? ZipballUrl { get; set; }
[JsonPropertyName("body")] public string Body { get; set; } [JsonPropertyName("body")] public string? Body { get; set; }
} }
} }

View File

@ -3,11 +3,11 @@
[Serializable] [Serializable]
public class ServerTestItem public class ServerTestItem
{ {
public string indexId { get; set; } public string? IndexId { get; set; }
public string address { get; set; } public string? Address { get; set; }
public int port { get; set; } public int Port { get; set; }
public EConfigType configType { get; set; } public EConfigType ConfigType { get; set; }
public bool allowTest { get; set; } public bool AllowTest { get; set; }
public int delay { get; set; } public int Delay { get; set; }
} }
} }

View File

@ -2,17 +2,17 @@
{ {
public class SsSIP008 public class SsSIP008
{ {
public List<SsServer> servers { get; set; } public List<SsServer>? servers { get; set; }
} }
[Serializable] [Serializable]
public class SsServer public class SsServer
{ {
public string remarks { get; set; } public string? remarks { get; set; }
public string server { get; set; } public string? server { get; set; }
public string server_port { get; set; } public string? server_port { get; set; }
public string method { get; set; } public string? method { get; set; }
public string password { get; set; } public string? password { get; set; }
public string plugin { get; set; } public string? plugin { get; set; }
} }
} }

View File

@ -1,20 +0,0 @@
namespace ServiceLib.Models
{
public class SysProxyConfig
{
public bool UserSettingsRecorded;
public string Flags;
public string ProxyServer;
public string BypassList;
public string PacUrl;
public SysProxyConfig()
{
UserSettingsRecorded = false;
Flags = "1";
ProxyServer = "";
BypassList = "";
PacUrl = "";
}
}
}

View File

@ -124,16 +124,16 @@ namespace ServiceLib.Services.CoreConfig
foreach (var it in selecteds) foreach (var it in selecteds)
{ {
if (it.configType == EConfigType.Custom) if (it.ConfigType == EConfigType.Custom)
{ {
continue; continue;
} }
if (it.port <= 0) if (it.Port <= 0)
{ {
continue; continue;
} }
var item = AppHandler.Instance.GetProfileItem(it.indexId); var item = AppHandler.Instance.GetProfileItem(it.IndexId);
if (it.configType is EConfigType.VMess or EConfigType.VLESS) if (it.ConfigType is EConfigType.VMess or EConfigType.VLESS)
{ {
if (item is null || Utils.IsNullOrEmpty(item.id) || !Utils.IsGuidByParse(item.id)) if (item is null || Utils.IsNullOrEmpty(item.id) || !Utils.IsGuidByParse(item.id))
{ {
@ -164,8 +164,8 @@ namespace ServiceLib.Services.CoreConfig
{ {
continue; continue;
} }
it.port = port; it.Port = port;
it.allowTest = true; it.AllowTest = true;
//inbound //inbound
Inbound4Sbox inbound = new() Inbound4Sbox inbound = new()
@ -192,7 +192,7 @@ namespace ServiceLib.Services.CoreConfig
{ {
continue; continue;
} }
if (it.configType is EConfigType.VLESS or EConfigType.Trojan if (it.ConfigType is EConfigType.VLESS or EConfigType.Trojan
&& item.streamSecurity == Global.StreamSecurityReality && item.streamSecurity == Global.StreamSecurityReality
&& item.publicKey.IsNullOrEmpty()) && item.publicKey.IsNullOrEmpty())
{ {

View File

@ -240,16 +240,16 @@ namespace ServiceLib.Services.CoreConfig
foreach (var it in selecteds) foreach (var it in selecteds)
{ {
if (it.configType == EConfigType.Custom) if (it.ConfigType == EConfigType.Custom)
{ {
continue; continue;
} }
if (it.port <= 0) if (it.Port <= 0)
{ {
continue; continue;
} }
var item = AppHandler.Instance.GetProfileItem(it.indexId); var item = AppHandler.Instance.GetProfileItem(it.IndexId);
if (it.configType is EConfigType.VMess or EConfigType.VLESS) if (it.ConfigType is EConfigType.VMess or EConfigType.VLESS)
{ {
if (item is null || Utils.IsNullOrEmpty(item.id) || !Utils.IsGuidByParse(item.id)) if (item is null || Utils.IsNullOrEmpty(item.id) || !Utils.IsGuidByParse(item.id))
{ {
@ -280,8 +280,8 @@ namespace ServiceLib.Services.CoreConfig
{ {
continue; continue;
} }
it.port = port; it.Port = port;
it.allowTest = true; it.AllowTest = true;
//inbound //inbound
Inbounds4Ray inbound = new() Inbounds4Ray inbound = new()
@ -308,7 +308,7 @@ namespace ServiceLib.Services.CoreConfig
{ {
continue; continue;
} }
if (it.configType is EConfigType.VLESS or EConfigType.Trojan if (it.ConfigType is EConfigType.VLESS or EConfigType.Trojan
&& item.streamSecurity == Global.StreamSecurityReality && item.streamSecurity == Global.StreamSecurityReality
&& item.publicKey.IsNullOrEmpty()) && item.publicKey.IsNullOrEmpty())
{ {

View File

@ -32,10 +32,10 @@ namespace ServiceLib.Services
} }
_selecteds.Add(new ServerTestItem() _selecteds.Add(new ServerTestItem()
{ {
indexId = it.indexId, IndexId = it.indexId,
address = it.address, Address = it.address,
port = it.port, Port = it.port,
configType = it.configType ConfigType = it.configType
}); });
} }
//clear test result //clear test result
@ -45,19 +45,19 @@ namespace ServiceLib.Services
{ {
case ESpeedActionType.Tcping: case ESpeedActionType.Tcping:
case ESpeedActionType.Realping: case ESpeedActionType.Realping:
UpdateFunc(it.indexId, ResUI.Speedtesting, ""); UpdateFunc(it.IndexId, ResUI.Speedtesting, "");
ProfileExHandler.Instance.SetTestDelay(it.indexId, "0"); ProfileExHandler.Instance.SetTestDelay(it.IndexId, "0");
break; break;
case ESpeedActionType.Speedtest: case ESpeedActionType.Speedtest:
UpdateFunc(it.indexId, "", ResUI.SpeedtestingWait); UpdateFunc(it.IndexId, "", ResUI.SpeedtestingWait);
ProfileExHandler.Instance.SetTestSpeed(it.indexId, "0"); ProfileExHandler.Instance.SetTestSpeed(it.IndexId, "0");
break; break;
case ESpeedActionType.Mixedtest: case ESpeedActionType.Mixedtest:
UpdateFunc(it.indexId, ResUI.Speedtesting, ResUI.SpeedtestingWait); UpdateFunc(it.IndexId, ResUI.Speedtesting, ResUI.SpeedtestingWait);
ProfileExHandler.Instance.SetTestDelay(it.indexId, "0"); ProfileExHandler.Instance.SetTestDelay(it.IndexId, "0");
ProfileExHandler.Instance.SetTestSpeed(it.indexId, "0"); ProfileExHandler.Instance.SetTestSpeed(it.IndexId, "0");
break; break;
} }
} }
@ -95,7 +95,7 @@ namespace ServiceLib.Services
List<Task> tasks = []; List<Task> tasks = [];
foreach (var it in _selecteds) foreach (var it in _selecteds)
{ {
if (it.configType == EConfigType.Custom) if (it.ConfigType == EConfigType.Custom)
{ {
continue; continue;
} }
@ -103,11 +103,11 @@ namespace ServiceLib.Services
{ {
try try
{ {
int time = GetTcpingTime(it.address, it.port); int time = GetTcpingTime(it.Address, it.Port);
var output = FormatOut(time, Global.DelayUnit); var output = FormatOut(time, Global.DelayUnit);
ProfileExHandler.Instance.SetTestDelay(it.indexId, output); ProfileExHandler.Instance.SetTestDelay(it.IndexId, output);
UpdateFunc(it.indexId, output); UpdateFunc(it.IndexId, output);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -148,11 +148,11 @@ namespace ServiceLib.Services
List<Task> tasks = new(); List<Task> tasks = new();
foreach (var it in _selecteds) foreach (var it in _selecteds)
{ {
if (!it.allowTest) if (!it.AllowTest)
{ {
continue; continue;
} }
if (it.configType == EConfigType.Custom) if (it.ConfigType == EConfigType.Custom)
{ {
continue; continue;
} }
@ -160,13 +160,13 @@ namespace ServiceLib.Services
{ {
try try
{ {
WebProxy webProxy = new(Global.Loopback, it.port); WebProxy webProxy = new(Global.Loopback, it.Port);
string output = await GetRealPingTime(downloadHandle, webProxy); string output = await GetRealPingTime(downloadHandle, webProxy);
ProfileExHandler.Instance.SetTestDelay(it.indexId, output); ProfileExHandler.Instance.SetTestDelay(it.IndexId, output);
UpdateFunc(it.indexId, output); UpdateFunc(it.IndexId, output);
int.TryParse(output, out int delay); int.TryParse(output, out int delay);
it.delay = delay; it.Delay = delay;
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -216,14 +216,14 @@ namespace ServiceLib.Services
{ {
if (_exitLoop) if (_exitLoop)
{ {
UpdateFunc(it.indexId, "", ResUI.SpeedtestingSkip); UpdateFunc(it.IndexId, "", ResUI.SpeedtestingSkip);
continue; continue;
} }
if (!it.allowTest) if (!it.AllowTest)
{ {
continue; continue;
} }
if (it.configType == EConfigType.Custom) if (it.ConfigType == EConfigType.Custom)
{ {
continue; continue;
} }
@ -232,22 +232,22 @@ namespace ServiceLib.Services
// UpdateFunc(it.indexId, "", ResUI.SpeedtestingSkip); // UpdateFunc(it.indexId, "", ResUI.SpeedtestingSkip);
// continue; // continue;
//} //}
ProfileExHandler.Instance.SetTestSpeed(it.indexId, "-1"); ProfileExHandler.Instance.SetTestSpeed(it.IndexId, "-1");
UpdateFunc(it.indexId, "", ResUI.Speedtesting); UpdateFunc(it.IndexId, "", ResUI.Speedtesting);
var item = AppHandler.Instance.GetProfileItem(it.indexId); var item = AppHandler.Instance.GetProfileItem(it.IndexId);
if (item is null) continue; if (item is null) continue;
WebProxy webProxy = new(Global.Loopback, it.port); WebProxy webProxy = new(Global.Loopback, it.Port);
await downloadHandle.DownloadDataAsync(url, webProxy, timeout, (success, msg) => await downloadHandle.DownloadDataAsync(url, webProxy, timeout, (success, msg) =>
{ {
decimal.TryParse(msg, out decimal dec); decimal.TryParse(msg, out decimal dec);
if (dec > 0) if (dec > 0)
{ {
ProfileExHandler.Instance.SetTestSpeed(it.indexId, msg); ProfileExHandler.Instance.SetTestSpeed(it.IndexId, msg);
} }
UpdateFunc(it.indexId, "", msg); UpdateFunc(it.IndexId, "", msg);
}); });
} }
@ -278,38 +278,38 @@ namespace ServiceLib.Services
{ {
if (_exitLoop) if (_exitLoop)
{ {
UpdateFunc(it.indexId, "", ResUI.SpeedtestingSkip); UpdateFunc(it.IndexId, "", ResUI.SpeedtestingSkip);
continue; continue;
} }
if (!it.allowTest) if (!it.AllowTest)
{ {
continue; continue;
} }
if (it.configType == EConfigType.Custom) if (it.ConfigType == EConfigType.Custom)
{ {
continue; continue;
} }
if (it.delay < 0) if (it.Delay < 0)
{ {
UpdateFunc(it.indexId, "", ResUI.SpeedtestingSkip); UpdateFunc(it.IndexId, "", ResUI.SpeedtestingSkip);
continue; continue;
} }
ProfileExHandler.Instance.SetTestSpeed(it.indexId, "-1"); ProfileExHandler.Instance.SetTestSpeed(it.IndexId, "-1");
UpdateFunc(it.indexId, "", ResUI.Speedtesting); UpdateFunc(it.IndexId, "", ResUI.Speedtesting);
var item = AppHandler.Instance.GetProfileItem(it.indexId); var item = AppHandler.Instance.GetProfileItem(it.IndexId);
if (item is null) continue; if (item is null) continue;
WebProxy webProxy = new(Global.Loopback, it.port); WebProxy webProxy = new(Global.Loopback, it.Port);
_ = downloadHandle.DownloadDataAsync(url, webProxy, timeout, (success, msg) => _ = downloadHandle.DownloadDataAsync(url, webProxy, timeout, (success, msg) =>
{ {
decimal.TryParse(msg, out decimal dec); decimal.TryParse(msg, out decimal dec);
if (dec > 0) if (dec > 0)
{ {
ProfileExHandler.Instance.SetTestSpeed(it.indexId, msg); ProfileExHandler.Instance.SetTestSpeed(it.IndexId, msg);
} }
UpdateFunc(it.indexId, "", msg); UpdateFunc(it.IndexId, "", msg);
}); });
await Task.Delay(2000); await Task.Delay(2000);
} }