mirror of https://github.com/2dust/v2rayN
Refactor
parent
4054369611
commit
c466ea100a
|
@ -1089,8 +1089,8 @@ namespace v2rayN.Handler
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ProfileItem profileItem = ShareHandler.ImportFromClipboardConfig(str, out string msg);
|
var profileItem = ShareHandler.ImportFromClipboardConfig(str, out string msg);
|
||||||
if (profileItem == null)
|
if (profileItem is null)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1127,40 +1127,19 @@ namespace v2rayN.Handler
|
||||||
}
|
}
|
||||||
profileItem.subid = subid;
|
profileItem.subid = subid;
|
||||||
profileItem.isSub = isSub;
|
profileItem.isSub = isSub;
|
||||||
var addStatus = -1;
|
|
||||||
|
|
||||||
if (profileItem.configType == EConfigType.VMess)
|
var addStatus = profileItem.configType switch
|
||||||
{
|
{
|
||||||
addStatus = AddServer(config, profileItem, false);
|
EConfigType.VMess => AddServer(config, profileItem, false),
|
||||||
}
|
EConfigType.Shadowsocks => AddShadowsocksServer(config, profileItem, false),
|
||||||
else if (profileItem.configType == EConfigType.Shadowsocks)
|
EConfigType.Socks => AddSocksServer(config, profileItem, false),
|
||||||
{
|
EConfigType.Trojan => AddTrojanServer(config, profileItem, false),
|
||||||
addStatus = AddShadowsocksServer(config, profileItem, false);
|
EConfigType.VLESS => AddVlessServer(config, profileItem, false),
|
||||||
}
|
EConfigType.Hysteria2 => AddHysteria2Server(config, profileItem, false),
|
||||||
else if (profileItem.configType == EConfigType.Socks)
|
EConfigType.Tuic => AddTuicServer(config, profileItem, false),
|
||||||
{
|
EConfigType.Wireguard => AddWireguardServer(config, profileItem, false),
|
||||||
addStatus = AddSocksServer(config, profileItem, false);
|
_ => -1,
|
||||||
}
|
};
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (addStatus == 0)
|
if (addStatus == 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -385,14 +385,12 @@ namespace v2rayN.Handler
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static ProfileItem? ImportFromClipboardConfig(string clipboardData, out string msg)
|
public static ProfileItem? ImportFromClipboardConfig(string clipboardData, out string msg)
|
||||||
{
|
{
|
||||||
msg = string.Empty;
|
msg = ResUI.ConfigurationFormatIncorrect;
|
||||||
|
|
||||||
ProfileItem? profileItem;
|
ProfileItem? profileItem;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//载入配置文件
|
string result = clipboardData.TrimEx();
|
||||||
string result = clipboardData.TrimEx();// Utils.GetClipboardData();
|
|
||||||
if (Utils.IsNullOrEmpty(result))
|
if (Utils.IsNullOrEmpty(result))
|
||||||
{
|
{
|
||||||
msg = ResUI.FailedReadConfiguration;
|
msg = ResUI.FailedReadConfiguration;
|
||||||
|
@ -413,8 +411,6 @@ namespace v2rayN.Handler
|
||||||
}
|
}
|
||||||
else if (result.StartsWith(Global.ProtocolShares[EConfigType.Shadowsocks]))
|
else if (result.StartsWith(Global.ProtocolShares[EConfigType.Shadowsocks]))
|
||||||
{
|
{
|
||||||
msg = ResUI.ConfigurationFormatIncorrect;
|
|
||||||
|
|
||||||
profileItem = ResolveSSLegacy(result) ?? ResolveSip002(result);
|
profileItem = ResolveSSLegacy(result) ?? ResolveSip002(result);
|
||||||
if (profileItem == null)
|
if (profileItem == null)
|
||||||
{
|
{
|
||||||
|
@ -429,8 +425,6 @@ namespace v2rayN.Handler
|
||||||
}
|
}
|
||||||
else if (result.StartsWith(Global.ProtocolShares[EConfigType.Socks]))
|
else if (result.StartsWith(Global.ProtocolShares[EConfigType.Socks]))
|
||||||
{
|
{
|
||||||
msg = ResUI.ConfigurationFormatIncorrect;
|
|
||||||
|
|
||||||
profileItem = ResolveSocksNew(result) ?? ResolveSocks(result);
|
profileItem = ResolveSocksNew(result) ?? ResolveSocks(result);
|
||||||
if (profileItem == null)
|
if (profileItem == null)
|
||||||
{
|
{
|
||||||
|
@ -445,8 +439,6 @@ namespace v2rayN.Handler
|
||||||
}
|
}
|
||||||
else if (result.StartsWith(Global.ProtocolShares[EConfigType.Trojan]))
|
else if (result.StartsWith(Global.ProtocolShares[EConfigType.Trojan]))
|
||||||
{
|
{
|
||||||
msg = ResUI.ConfigurationFormatIncorrect;
|
|
||||||
|
|
||||||
profileItem = ResolveTrojan(result);
|
profileItem = ResolveTrojan(result);
|
||||||
}
|
}
|
||||||
else if (result.StartsWith(Global.ProtocolShares[EConfigType.VLESS]))
|
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))
|
else if (result.StartsWith(Global.ProtocolShares[EConfigType.Hysteria2]) || result.StartsWith(Global.Hysteria2ProtocolShare))
|
||||||
{
|
{
|
||||||
msg = ResUI.ConfigurationFormatIncorrect;
|
|
||||||
|
|
||||||
profileItem = ResolveHysteria2(result);
|
profileItem = ResolveHysteria2(result);
|
||||||
}
|
}
|
||||||
else if (result.StartsWith(Global.ProtocolShares[EConfigType.Tuic]))
|
else if (result.StartsWith(Global.ProtocolShares[EConfigType.Tuic]))
|
||||||
|
|
|
@ -86,7 +86,10 @@ namespace v2rayN.Handler
|
||||||
_updateFunc(false, args.Msg);
|
_updateFunc(false, args.Msg);
|
||||||
|
|
||||||
url = args.Url;
|
url = args.Url;
|
||||||
_ = askToDownload(downloadHandle, url, true);
|
AskToDownload(downloadHandle, url, true).ContinueWith(task =>
|
||||||
|
{
|
||||||
|
_updateFunc(false, url);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -139,7 +142,10 @@ namespace v2rayN.Handler
|
||||||
_updateFunc(false, args.Msg);
|
_updateFunc(false, args.Msg);
|
||||||
|
|
||||||
url = args.Url;
|
url = args.Url;
|
||||||
_ = askToDownload(downloadHandle, url, true);
|
AskToDownload(downloadHandle, url, true).ContinueWith(task =>
|
||||||
|
{
|
||||||
|
_updateFunc(false, url);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else
|
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;
|
bool blDownload = false;
|
||||||
if (blAsk)
|
if (blAsk)
|
||||||
|
@ -591,7 +597,7 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
_updateFunc(false, args.GetException().Message);
|
_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)
|
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);
|
_updateFunc(false, args.GetException().Message);
|
||||||
};
|
};
|
||||||
await askToDownload(downloadHandle, url, false);
|
await AskToDownload(downloadHandle, url, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion private
|
#endregion private
|
||||||
|
|
|
@ -122,41 +122,18 @@ namespace v2rayN.ViewModels
|
||||||
item.spiderX = SelectedSource.spiderX;
|
item.spiderX = SelectedSource.spiderX;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ret = -1;
|
var ret = item.configType switch
|
||||||
switch (item.configType)
|
|
||||||
{
|
{
|
||||||
case EConfigType.VMess:
|
EConfigType.VMess => ConfigHandler.AddServer(_config, item),
|
||||||
ret = ConfigHandler.AddServer(_config, item);
|
EConfigType.Shadowsocks => ConfigHandler.AddShadowsocksServer(_config, item),
|
||||||
break;
|
EConfigType.Socks => ConfigHandler.AddSocksServer(_config, item),
|
||||||
|
EConfigType.Trojan => ConfigHandler.AddTrojanServer(_config, item),
|
||||||
case EConfigType.Shadowsocks:
|
EConfigType.VLESS => ConfigHandler.AddVlessServer(_config, item),
|
||||||
ret = ConfigHandler.AddShadowsocksServer(_config, item);
|
EConfigType.Hysteria2 => ConfigHandler.AddHysteria2Server(_config, item),
|
||||||
break;
|
EConfigType.Tuic => ConfigHandler.AddTuicServer(_config, item),
|
||||||
|
EConfigType.Wireguard => ConfigHandler.AddWireguardServer(_config, item),
|
||||||
case EConfigType.Socks:
|
_ => -1,
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1482,16 +1482,21 @@ namespace v2rayN.ViewModels
|
||||||
|
|
||||||
public void Reload()
|
public void Reload()
|
||||||
{
|
{
|
||||||
_ = LoadV2ray();
|
BlReloadEnabled = false;
|
||||||
|
|
||||||
|
LoadV2ray().ContinueWith(task =>
|
||||||
|
{
|
||||||
|
TestServerAvailability();
|
||||||
|
|
||||||
|
Application.Current.Dispatcher.Invoke((Action)(() =>
|
||||||
|
{
|
||||||
|
BlReloadEnabled = true;
|
||||||
|
}));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task LoadV2ray()
|
private async Task LoadV2ray()
|
||||||
{
|
{
|
||||||
Application.Current.Dispatcher.Invoke((Action)(() =>
|
|
||||||
{
|
|
||||||
BlReloadEnabled = false;
|
|
||||||
}));
|
|
||||||
|
|
||||||
await Task.Run(() =>
|
await Task.Run(() =>
|
||||||
{
|
{
|
||||||
_coreHandler.LoadCore();
|
_coreHandler.LoadCore();
|
||||||
|
@ -1500,13 +1505,6 @@ namespace v2rayN.ViewModels
|
||||||
|
|
||||||
ChangeSystemProxyStatus(_config.sysProxyType, false);
|
ChangeSystemProxyStatus(_config.sysProxyType, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
TestServerAvailability();
|
|
||||||
|
|
||||||
Application.Current.Dispatcher.Invoke((Action)(() =>
|
|
||||||
{
|
|
||||||
BlReloadEnabled = true;
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CloseV2ray()
|
private void CloseV2ray()
|
||||||
|
|
|
@ -306,7 +306,7 @@ namespace v2rayN.ViewModels
|
||||||
}
|
}
|
||||||
|
|
||||||
DownloadHandle downloadHandle = new DownloadHandle();
|
DownloadHandle downloadHandle = new DownloadHandle();
|
||||||
string result = await downloadHandle.TryDownloadString(url, true, "");
|
var result = await downloadHandle.TryDownloadString(url, true, "");
|
||||||
if (AddBatchRoutingRules(SelectedRouting, result) == 0)
|
if (AddBatchRoutingRules(SelectedRouting, result) == 0)
|
||||||
{
|
{
|
||||||
Application.Current.Dispatcher.Invoke((Action)(() =>
|
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;
|
bool blReplace = false;
|
||||||
if (UI.ShowYesNo(ResUI.AddBatchRoutingRulesYesNo) == MessageBoxResult.No)
|
if (UI.ShowYesNo(ResUI.AddBatchRoutingRulesYesNo) == MessageBoxResult.No)
|
||||||
|
|
|
@ -342,7 +342,7 @@ namespace v2rayN.Views
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Key.S:
|
case Key.S:
|
||||||
_ = ViewModel?.ScanScreenTaskAsync();
|
ViewModel?.ScanScreenTaskAsync().ContinueWith(_ => { });
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Key.T:
|
case Key.T:
|
||||||
|
|
Loading…
Reference in New Issue