pull/4711/head
2dust 2024-01-30 17:18:00 +08:00
parent 4054369611
commit c466ea100a
7 changed files with 51 additions and 101 deletions

View File

@ -1089,8 +1089,8 @@ namespace v2rayN.Handler
}
continue;
}
ProfileItem profileItem = ShareHandler.ImportFromClipboardConfig(str, out string msg);
if (profileItem == null)
var profileItem = ShareHandler.ImportFromClipboardConfig(str, out string msg);
if (profileItem is null)
{
continue;
}
@ -1127,40 +1127,19 @@ namespace v2rayN.Handler
}
profileItem.subid = subid;
profileItem.isSub = isSub;
var addStatus = -1;
if (profileItem.configType == EConfigType.VMess)
var addStatus = profileItem.configType switch
{
addStatus = AddServer(config, profileItem, false);
}
else if (profileItem.configType == EConfigType.Shadowsocks)
{
addStatus = AddShadowsocksServer(config, profileItem, false);
}
else if (profileItem.configType == EConfigType.Socks)
{
addStatus = AddSocksServer(config, profileItem, false);
}
else if (profileItem.configType == EConfigType.Trojan)
{
addStatus = AddTrojanServer(config, profileItem, false);
}
else if (profileItem.configType == EConfigType.VLESS)
{
addStatus = AddVlessServer(config, profileItem, false);
}
else if (profileItem.configType == EConfigType.Hysteria2)
{
addStatus = AddHysteria2Server(config, profileItem, false);
}
else if (profileItem.configType == EConfigType.Tuic)
{
addStatus = AddTuicServer(config, profileItem, false);
}
else if (profileItem.configType == EConfigType.Wireguard)
{
addStatus = AddWireguardServer(config, profileItem, false);
}
EConfigType.VMess => AddServer(config, profileItem, false),
EConfigType.Shadowsocks => AddShadowsocksServer(config, profileItem, false),
EConfigType.Socks => AddSocksServer(config, profileItem, false),
EConfigType.Trojan => AddTrojanServer(config, profileItem, false),
EConfigType.VLESS => AddVlessServer(config, profileItem, false),
EConfigType.Hysteria2 => AddHysteria2Server(config, profileItem, false),
EConfigType.Tuic => AddTuicServer(config, profileItem, false),
EConfigType.Wireguard => AddWireguardServer(config, profileItem, false),
_ => -1,
};
if (addStatus == 0)
{

View File

@ -385,14 +385,12 @@ namespace v2rayN.Handler
/// <returns></returns>
public static ProfileItem? ImportFromClipboardConfig(string clipboardData, out string msg)
{
msg = string.Empty;
msg = ResUI.ConfigurationFormatIncorrect;
ProfileItem? profileItem;
try
{
//载入配置文件
string result = clipboardData.TrimEx();// Utils.GetClipboardData();
string result = clipboardData.TrimEx();
if (Utils.IsNullOrEmpty(result))
{
msg = ResUI.FailedReadConfiguration;
@ -413,8 +411,6 @@ namespace v2rayN.Handler
}
else if (result.StartsWith(Global.ProtocolShares[EConfigType.Shadowsocks]))
{
msg = ResUI.ConfigurationFormatIncorrect;
profileItem = ResolveSSLegacy(result) ?? ResolveSip002(result);
if (profileItem == null)
{
@ -429,8 +425,6 @@ namespace v2rayN.Handler
}
else if (result.StartsWith(Global.ProtocolShares[EConfigType.Socks]))
{
msg = ResUI.ConfigurationFormatIncorrect;
profileItem = ResolveSocksNew(result) ?? ResolveSocks(result);
if (profileItem == null)
{
@ -445,8 +439,6 @@ namespace v2rayN.Handler
}
else if (result.StartsWith(Global.ProtocolShares[EConfigType.Trojan]))
{
msg = ResUI.ConfigurationFormatIncorrect;
profileItem = ResolveTrojan(result);
}
else if (result.StartsWith(Global.ProtocolShares[EConfigType.VLESS]))
@ -455,8 +447,6 @@ namespace v2rayN.Handler
}
else if (result.StartsWith(Global.ProtocolShares[EConfigType.Hysteria2]) || result.StartsWith(Global.Hysteria2ProtocolShare))
{
msg = ResUI.ConfigurationFormatIncorrect;
profileItem = ResolveHysteria2(result);
}
else if (result.StartsWith(Global.ProtocolShares[EConfigType.Tuic]))

View File

@ -86,7 +86,10 @@ namespace v2rayN.Handler
_updateFunc(false, args.Msg);
url = args.Url;
_ = askToDownload(downloadHandle, url, true);
AskToDownload(downloadHandle, url, true).ContinueWith(task =>
{
_updateFunc(false, url);
});
}
else
{
@ -139,7 +142,10 @@ namespace v2rayN.Handler
_updateFunc(false, args.Msg);
url = args.Url;
_ = askToDownload(downloadHandle, url, true);
AskToDownload(downloadHandle, url, true).ContinueWith(task =>
{
_updateFunc(false, url);
});
}
else
{
@ -527,7 +533,7 @@ namespace v2rayN.Handler
}
}
private async Task askToDownload(DownloadHandle downloadHandle, string url, bool blAsk)
private async Task AskToDownload(DownloadHandle downloadHandle, string url, bool blAsk)
{
bool blDownload = false;
if (blAsk)
@ -591,7 +597,7 @@ namespace v2rayN.Handler
{
_updateFunc(false, args.GetException().Message);
};
await askToDownload(downloadHandle, url, false);
await AskToDownload(downloadHandle, url, false);
}
private async Task UpdateGeoFile4Singbox(string geoName, Config config, bool needStop, Action<bool, string> update)
@ -639,7 +645,7 @@ namespace v2rayN.Handler
{
_updateFunc(false, args.GetException().Message);
};
await askToDownload(downloadHandle, url, false);
await AskToDownload(downloadHandle, url, false);
}
#endregion private

View File

@ -122,41 +122,18 @@ namespace v2rayN.ViewModels
item.spiderX = SelectedSource.spiderX;
}
int ret = -1;
switch (item.configType)
var ret = item.configType switch
{
case EConfigType.VMess:
ret = ConfigHandler.AddServer(_config, item);
break;
case EConfigType.Shadowsocks:
ret = ConfigHandler.AddShadowsocksServer(_config, item);
break;
case EConfigType.Socks:
ret = ConfigHandler.AddSocksServer(_config, item);
break;
case EConfigType.VLESS:
ret = ConfigHandler.AddVlessServer(_config, item);
break;
case EConfigType.Trojan:
ret = ConfigHandler.AddTrojanServer(_config, item);
break;
case EConfigType.Hysteria2:
ret = ConfigHandler.AddHysteria2Server(_config, item);
break;
case EConfigType.Tuic:
ret = ConfigHandler.AddTuicServer(_config, item);
break;
case EConfigType.Wireguard:
ret = ConfigHandler.AddWireguardServer(_config, item);
break;
}
EConfigType.VMess => ConfigHandler.AddServer(_config, item),
EConfigType.Shadowsocks => ConfigHandler.AddShadowsocksServer(_config, item),
EConfigType.Socks => ConfigHandler.AddSocksServer(_config, item),
EConfigType.Trojan => ConfigHandler.AddTrojanServer(_config, item),
EConfigType.VLESS => ConfigHandler.AddVlessServer(_config, item),
EConfigType.Hysteria2 => ConfigHandler.AddHysteria2Server(_config, item),
EConfigType.Tuic => ConfigHandler.AddTuicServer(_config, item),
EConfigType.Wireguard => ConfigHandler.AddWireguardServer(_config, item),
_ => -1,
};
if (ret == 0)
{

View File

@ -1482,16 +1482,21 @@ namespace v2rayN.ViewModels
public void Reload()
{
_ = LoadV2ray();
BlReloadEnabled = false;
LoadV2ray().ContinueWith(task =>
{
TestServerAvailability();
Application.Current.Dispatcher.Invoke((Action)(() =>
{
BlReloadEnabled = true;
}));
});
}
private async Task LoadV2ray()
{
Application.Current.Dispatcher.Invoke((Action)(() =>
{
BlReloadEnabled = false;
}));
await Task.Run(() =>
{
_coreHandler.LoadCore();
@ -1500,13 +1505,6 @@ namespace v2rayN.ViewModels
ChangeSystemProxyStatus(_config.sysProxyType, false);
});
TestServerAvailability();
Application.Current.Dispatcher.Invoke((Action)(() =>
{
BlReloadEnabled = true;
}));
}
private void CloseV2ray()

View File

@ -306,7 +306,7 @@ namespace v2rayN.ViewModels
}
DownloadHandle downloadHandle = new DownloadHandle();
string result = await downloadHandle.TryDownloadString(url, true, "");
var result = await downloadHandle.TryDownloadString(url, true, "");
if (AddBatchRoutingRules(SelectedRouting, result) == 0)
{
Application.Current.Dispatcher.Invoke((Action)(() =>
@ -317,7 +317,7 @@ namespace v2rayN.ViewModels
}
}
private int AddBatchRoutingRules(RoutingItem routingItem, string clipboardData)
private int AddBatchRoutingRules(RoutingItem routingItem, string? clipboardData)
{
bool blReplace = false;
if (UI.ShowYesNo(ResUI.AddBatchRoutingRulesYesNo) == MessageBoxResult.No)

View File

@ -342,7 +342,7 @@ namespace v2rayN.Views
break;
case Key.S:
_ = ViewModel?.ScanScreenTaskAsync();
ViewModel?.ScanScreenTaskAsync().ContinueWith(_ => { });
break;
case Key.T: