Update RetResult

This commit is contained in:
2dust
2024-10-21 18:18:41 +08:00
parent 3dd54312e7
commit 5ea6b1e08a
10 changed files with 64 additions and 77 deletions
+6 -6
View File
@@ -1009,7 +1009,7 @@ namespace ServiceLib.Handler
var configPath = Utils.GetConfigPath(Global.CoreMultipleLoadConfigFileName);
var result = await CoreConfigHandler.GenerateClientMultipleLoadConfig(config, configPath, selecteds, coreType);
if (result.Code != 0)
if (result.Success != true)
{
return result;
}
@@ -1642,7 +1642,7 @@ namespace ServiceLib.Handler
public static async Task<int> InitExternalRouting(Config config, bool blImportAdvancedRules = false)
{
var downloadHandle = new DownloadService();
var templateContent = Task.Run(() => downloadHandle.TryDownloadString(config.constItem.routeRulesTemplateSourceUrl, false, "")).Result;
var templateContent = await downloadHandle.TryDownloadString(config.constItem.routeRulesTemplateSourceUrl, true, "");
if (string.IsNullOrEmpty(templateContent))
return await InitBuiltinRouting(config, blImportAdvancedRules); // fallback
@@ -1665,7 +1665,7 @@ namespace ServiceLib.Handler
var ruleSetsString = !string.IsNullOrEmpty(item.ruleSet)
? item.ruleSet
: Task.Run(() => downloadHandle.TryDownloadString(item.url, false, "")).Result;
: await downloadHandle.TryDownloadString(item.url, true, "");
if (string.IsNullOrEmpty(ruleSetsString))
continue;
@@ -1795,7 +1795,7 @@ namespace ServiceLib.Handler
var currentItem = await AppHandler.Instance.GetDNSItem(type);
var downloadHandle = new DownloadService();
var templateContent = Task.Run(() => downloadHandle.TryDownloadString(url, true, "")).Result;
var templateContent = await downloadHandle.TryDownloadString(url, true, "");
if (string.IsNullOrEmpty(templateContent))
return currentItem;
@@ -1804,10 +1804,10 @@ namespace ServiceLib.Handler
return currentItem;
if (!string.IsNullOrEmpty(template.normalDNS))
template.normalDNS = Task.Run(() => downloadHandle.TryDownloadString(template.normalDNS, true, "")).Result;
template.normalDNS = await downloadHandle.TryDownloadString(template.normalDNS, true, "");
if (!string.IsNullOrEmpty(template.tunDNS))
template.tunDNS = Task.Run(() => downloadHandle.TryDownloadString(template.tunDNS, true, "")).Result;
template.tunDNS = await downloadHandle.TryDownloadString(template.tunDNS, true, "");
template.id = currentItem.id;
template.enabled = currentItem.enabled;
@@ -8,7 +8,7 @@
public static async Task<RetResult> GenerateClientConfig(ProfileItem node, string? fileName)
{
var config = AppHandler.Instance.Config;
var result = new RetResult(-1);
var result = new RetResult();
if (node.configType == EConfigType.Custom)
{
@@ -33,7 +33,7 @@
{
result = await new CoreConfigV2rayService(config).GenerateClientConfigContent(node);
}
if (result.Code != 0)
if (result.Success != true)
{
return result;
}
@@ -47,7 +47,7 @@
private static async Task<RetResult> GenerateClientCustomConfig(ProfileItem node, string? fileName)
{
var ret = new RetResult(-1);
var ret = new RetResult();
try
{
if (node == null || fileName is null)
@@ -83,7 +83,7 @@
}
ret.Msg = string.Format(ResUI.SuccessfulConfiguration, "");
ret.Code = 0;
ret.Success = true;
return ret;
}
catch (Exception ex)
@@ -96,7 +96,7 @@
public static async Task<RetResult> GenerateClientSpeedtestConfig(Config config, string fileName, List<ServerTestItem> selecteds, ECoreType coreType)
{
var result = new RetResult(-1);
var result = new RetResult();
if (coreType == ECoreType.sing_box)
{
result = await new CoreConfigSingboxService(config).GenerateClientSpeedtestConfig(selecteds);
@@ -105,7 +105,7 @@
{
result = await new CoreConfigV2rayService(config).GenerateClientSpeedtestConfig(selecteds);
}
if (result.Code != 0)
if (result.Success != true)
{
return result;
}
@@ -115,7 +115,7 @@
public static async Task<RetResult> GenerateClientMultipleLoadConfig(Config config, string fileName, List<ProfileItem> selecteds, ECoreType coreType)
{
var result = new RetResult(-1);
var result = new RetResult();
if (coreType == ECoreType.sing_box)
{
result = await new CoreConfigSingboxService(config).GenerateClientMultipleLoadConfig(selecteds);
@@ -125,7 +125,7 @@
result = await new CoreConfigV2rayService(config).GenerateClientMultipleLoadConfig(selecteds);
}
if (result.Code != 0)
if (result.Success != true)
{
return result;
}
+3 -3
View File
@@ -35,7 +35,7 @@ namespace ServiceLib.Handler
var fileName = Utils.GetConfigPath(Global.CoreConfigFileName);
var result = await CoreConfigHandler.GenerateClientConfig(node, fileName);
ShowMsg(false, result.Msg);
if (result.Code != 0)
if (result.Success != true)
{
return;
}
@@ -72,7 +72,7 @@ namespace ServiceLib.Handler
var configPath = Utils.GetConfigPath(Global.CoreSpeedtestConfigFileName);
var result = await CoreConfigHandler.GenerateClientSpeedtestConfig(_config, configPath, selecteds, coreType);
ShowMsg(false, result.Msg);
if (result.Code == 0)
if (result.Success)
{
pid = CoreStartSpeedtest(configPath, coreType);
}
@@ -225,7 +225,7 @@ namespace ServiceLib.Handler
{
string fileName2 = Utils.GetConfigPath(Global.CorePreConfigFileName);
var result = await CoreConfigHandler.GenerateClientConfig(itemSocks, fileName2);
if (result.Code == 0)
if (result.Success)
{
var coreInfo2 = CoreInfoHandler.Instance.GetCoreInfo(preCoreType);
var proc2 = RunProcess(node, coreInfo2, $" -c {Global.CorePreConfigFileName}", true);