mirror of
https://github.com/2dust/v2rayN.git
synced 2025-08-30 23:06:20 +00:00
Merge branch 'master' into master
This commit is contained in:
commit
7ebff7f4ec
20 changed files with 79 additions and 68 deletions
|
@ -479,6 +479,12 @@ namespace ServiceLib.Common
|
||||||
|
|
||||||
#region 杂项
|
#region 杂项
|
||||||
|
|
||||||
|
public static bool UpgradeAppExists(out string fileName)
|
||||||
|
{
|
||||||
|
fileName = Path.Combine(Utils.StartupPath(), GetExeName("AmazTool"));
|
||||||
|
return File.Exists(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 取得版本
|
/// 取得版本
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -201,5 +201,14 @@ namespace ServiceLib.Handler.Fmt
|
||||||
File.WriteAllText(fileName, strData);
|
File.WriteAllText(fileName, strData);
|
||||||
return fileName;
|
return fileName;
|
||||||
}
|
}
|
||||||
|
protected static string ToUri(EConfigType eConfigType, string address, object port, string userInfo, Dictionary<string, string>? dicQuery, string? remark)
|
||||||
|
{
|
||||||
|
var query = dicQuery != null
|
||||||
|
? ("?" + string.Join("&", dicQuery.Select(x => x.Key + "=" + x.Value).ToArray()))
|
||||||
|
: string.Empty;
|
||||||
|
|
||||||
|
var url = $"{Utils.UrlEncode(userInfo)}@{GetIpv6(address)}:{port}";
|
||||||
|
return $"{Global.ProtocolShares[eConfigType]}{url}{query}{remark}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -51,14 +51,7 @@
|
||||||
}
|
}
|
||||||
dicQuery.Add("insecure", item.allowInsecure.ToLower() == "true" ? "1" : "0");
|
dicQuery.Add("insecure", item.allowInsecure.ToLower() == "true" ? "1" : "0");
|
||||||
|
|
||||||
string query = "?" + string.Join("&", dicQuery.Select(x => x.Key + "=" + x.Value).ToArray());
|
return ToUri(EConfigType.Hysteria2, item.address, item.port, item.id, dicQuery, remark);
|
||||||
|
|
||||||
url = string.Format("{0}@{1}:{2}",
|
|
||||||
item.id,
|
|
||||||
GetIpv6(item.address),
|
|
||||||
item.port);
|
|
||||||
url = $"{Global.ProtocolShares[EConfigType.Hysteria2]}{url}/{query}{remark}";
|
|
||||||
return url;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ProfileItem? ResolveFull(string strData, string? subRemarks)
|
public static ProfileItem? ResolveFull(string strData, string? subRemarks)
|
||||||
|
|
|
@ -42,9 +42,7 @@ namespace ServiceLib.Handler.Fmt
|
||||||
//url = Utile.Base64Encode(url);
|
//url = Utile.Base64Encode(url);
|
||||||
//new Sip002
|
//new Sip002
|
||||||
var pw = Utils.Base64Encode($"{item.security}:{item.id}");
|
var pw = Utils.Base64Encode($"{item.security}:{item.id}");
|
||||||
url = $"{pw}@{GetIpv6(item.address)}:{item.port}";
|
return ToUri(EConfigType.Shadowsocks, item.address, item.port, pw, null, remark);
|
||||||
url = $"{Global.ProtocolShares[EConfigType.Shadowsocks]}{url}{remark}";
|
|
||||||
return url;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static readonly Regex UrlFinder = new(@"ss://(?<base64>[A-Za-z0-9+-/=_]+)(?:#(?<tag>\S+))?", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
private static readonly Regex UrlFinder = new(@"ss://(?<base64>[A-Za-z0-9+-/=_]+)(?:#(?<tag>\S+))?", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||||
|
@ -98,7 +96,7 @@ namespace ServiceLib.Handler.Fmt
|
||||||
address = parsedUrl.IdnHost,
|
address = parsedUrl.IdnHost,
|
||||||
port = parsedUrl.Port,
|
port = parsedUrl.Port,
|
||||||
};
|
};
|
||||||
string rawUserInfo = parsedUrl.GetComponents(UriComponents.UserInfo, UriFormat.UriEscaped);
|
var rawUserInfo = Utils.UrlDecode(parsedUrl.UserInfo);
|
||||||
//2022-blake3
|
//2022-blake3
|
||||||
if (rawUserInfo.Contains(':'))
|
if (rawUserInfo.Contains(':'))
|
||||||
{
|
{
|
||||||
|
|
|
@ -40,9 +40,7 @@
|
||||||
//url = Utile.Base64Encode(url);
|
//url = Utile.Base64Encode(url);
|
||||||
//new
|
//new
|
||||||
var pw = Utils.Base64Encode($"{item.security}:{item.id}");
|
var pw = Utils.Base64Encode($"{item.security}:{item.id}");
|
||||||
url = $"{pw}@{GetIpv6(item.address)}:{item.port}";
|
return ToUri(EConfigType.SOCKS, item.address, item.port, pw, null, remark);
|
||||||
url = $"{Global.ProtocolShares[EConfigType.SOCKS]}{url}{remark}";
|
|
||||||
return url;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ProfileItem? ResolveSocks(string result)
|
private static ProfileItem? ResolveSocks(string result)
|
||||||
|
@ -112,9 +110,9 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
// parse base64 UserInfo
|
// parse base64 UserInfo
|
||||||
string rawUserInfo = parsedUrl.GetComponents(UriComponents.UserInfo, UriFormat.Unescaped);
|
var rawUserInfo = Utils.UrlDecode(parsedUrl.UserInfo);
|
||||||
string userInfo = Utils.Base64Decode(rawUserInfo);
|
var userInfo = Utils.Base64Decode(rawUserInfo);
|
||||||
string[] userInfoParts = userInfo.Split(new[] { ':' }, 2);
|
var userInfoParts = userInfo.Split(new[] { ':' }, 2);
|
||||||
if (userInfoParts.Length == 2)
|
if (userInfoParts.Length == 2)
|
||||||
{
|
{
|
||||||
item.security = userInfoParts[0];
|
item.security = userInfoParts[0];
|
||||||
|
|
|
@ -36,14 +36,8 @@
|
||||||
}
|
}
|
||||||
var dicQuery = new Dictionary<string, string>();
|
var dicQuery = new Dictionary<string, string>();
|
||||||
GetStdTransport(item, null, ref dicQuery);
|
GetStdTransport(item, null, ref dicQuery);
|
||||||
string query = "?" + string.Join("&", dicQuery.Select(x => x.Key + "=" + x.Value).ToArray());
|
|
||||||
|
|
||||||
url = string.Format("{0}@{1}:{2}",
|
return ToUri(EConfigType.Trojan, item.address, item.port, item.id, dicQuery, remark);
|
||||||
item.id,
|
|
||||||
GetIpv6(item.address),
|
|
||||||
item.port);
|
|
||||||
url = $"{Global.ProtocolShares[EConfigType.Trojan]}{url}{query}{remark}";
|
|
||||||
return url;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -16,7 +16,8 @@
|
||||||
item.address = url.IdnHost;
|
item.address = url.IdnHost;
|
||||||
item.port = url.Port;
|
item.port = url.Port;
|
||||||
item.remarks = url.GetComponents(UriComponents.Fragment, UriFormat.Unescaped);
|
item.remarks = url.GetComponents(UriComponents.Fragment, UriFormat.Unescaped);
|
||||||
var userInfoParts = url.UserInfo.Split(new[] { ':' }, 2);
|
var rawUserInfo = Utils.UrlDecode(url.UserInfo);
|
||||||
|
var userInfoParts = rawUserInfo.Split(new[] { ':' }, 2);
|
||||||
if (userInfoParts.Length == 2)
|
if (userInfoParts.Length == 2)
|
||||||
{
|
{
|
||||||
item.id = userInfoParts[0];
|
item.id = userInfoParts[0];
|
||||||
|
@ -51,14 +52,7 @@
|
||||||
}
|
}
|
||||||
dicQuery.Add("congestion_control", item.headerType);
|
dicQuery.Add("congestion_control", item.headerType);
|
||||||
|
|
||||||
string query = "?" + string.Join("&", dicQuery.Select(x => x.Key + "=" + x.Value).ToArray());
|
return ToUri(EConfigType.TUIC, item.address, item.port, $"{item.id}:{item.security}", dicQuery, remark);
|
||||||
|
|
||||||
url = string.Format("{0}@{1}:{2}",
|
|
||||||
$"{item.id}:{item.security}",
|
|
||||||
GetIpv6(item.address),
|
|
||||||
item.port);
|
|
||||||
url = $"{Global.ProtocolShares[EConfigType.TUIC]}{url}{query}{remark}";
|
|
||||||
return url;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -47,14 +47,8 @@
|
||||||
dicQuery.Add("encryption", Global.None);
|
dicQuery.Add("encryption", Global.None);
|
||||||
}
|
}
|
||||||
GetStdTransport(item, Global.None, ref dicQuery);
|
GetStdTransport(item, Global.None, ref dicQuery);
|
||||||
string query = "?" + string.Join("&", dicQuery.Select(x => x.Key + "=" + x.Value).ToArray());
|
|
||||||
|
|
||||||
url = string.Format("{0}@{1}:{2}",
|
return ToUri(EConfigType.VLESS, item.address, item.port, item.id, dicQuery, remark);
|
||||||
item.id,
|
|
||||||
GetIpv6(item.address),
|
|
||||||
item.port);
|
|
||||||
url = $"{Global.ProtocolShares[EConfigType.VLESS]}{url}{query}{remark}";
|
|
||||||
return url;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -56,14 +56,7 @@
|
||||||
{
|
{
|
||||||
dicQuery.Add("mtu", Utils.UrlEncode(item.shortId));
|
dicQuery.Add("mtu", Utils.UrlEncode(item.shortId));
|
||||||
}
|
}
|
||||||
string query = "?" + string.Join("&", dicQuery.Select(x => x.Key + "=" + x.Value).ToArray());
|
return ToUri(EConfigType.WireGuard, item.address, item.port, item.id, dicQuery, remark);
|
||||||
|
|
||||||
url = string.Format("{0}@{1}:{2}",
|
|
||||||
Utils.UrlEncode(item.id),
|
|
||||||
GetIpv6(item.address),
|
|
||||||
item.port);
|
|
||||||
url = $"{Global.ProtocolShares[EConfigType.WireGuard]}{url}/{query}{remark}";
|
|
||||||
return url;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -12,7 +12,7 @@ namespace ServiceLib.Handler
|
||||||
private WebDavClient? _client;
|
private WebDavClient? _client;
|
||||||
private string? _lastDescription;
|
private string? _lastDescription;
|
||||||
private string _webDir = Global.AppName + "_backup";
|
private string _webDir = Global.AppName + "_backup";
|
||||||
private string _webFileName = "backup.zip";
|
private readonly string _webFileName = "backup.zip";
|
||||||
private string _logTitle = "WebDav--";
|
private string _logTitle = "WebDav--";
|
||||||
|
|
||||||
public WebDavHandler()
|
public WebDavHandler()
|
||||||
|
@ -130,7 +130,7 @@ namespace ServiceLib.Handler
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var fs = File.OpenRead(fileName);
|
await using var fs = File.OpenRead(fileName);
|
||||||
var result = await _client.PutFile($"{_webDir}/{_webFileName}", fs); // upload a resource
|
var result = await _client.PutFile($"{_webDir}/{_webFileName}", fs); // upload a resource
|
||||||
if (result.IsSuccessful)
|
if (result.IsSuccessful)
|
||||||
{
|
{
|
||||||
|
@ -162,8 +162,9 @@ namespace ServiceLib.Handler
|
||||||
SaveLog(response.Description);
|
SaveLog(response.Description);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
using var outputFileStream = new FileStream(fileName, FileMode.Create);
|
|
||||||
response.Stream.CopyTo(outputFileStream);
|
await using var outputFileStream = new FileStream(fileName, FileMode.Create);
|
||||||
|
await response.Stream.CopyToAsync(outputFileStream);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
9
v2rayN/ServiceLib/Resx/ResUI.Designer.cs
generated
9
v2rayN/ServiceLib/Resx/ResUI.Designer.cs
generated
|
@ -3707,5 +3707,14 @@ namespace ServiceLib.Resx {
|
||||||
return ResourceManager.GetString("UpdateStandalonePackageTip", resourceCulture);
|
return ResourceManager.GetString("UpdateStandalonePackageTip", resourceCulture);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查找类似 UpgradeApp does not exist 的本地化字符串。
|
||||||
|
/// </summary>
|
||||||
|
public static string UpgradeAppNotExistTip {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("UpgradeAppNotExistTip", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1332,5 +1332,7 @@
|
||||||
</data>
|
</data>
|
||||||
<data name="TbSettingsSrsFilesSource" xml:space="preserve">
|
<data name="TbSettingsSrsFilesSource" xml:space="preserve">
|
||||||
<value>Sing-box srs files source (optional)</value>
|
<value>Sing-box srs files source (optional)</value>
|
||||||
|
<data name="UpgradeAppNotExistTip" xml:space="preserve">
|
||||||
|
<value>UpgradeApp does not exist</value>
|
||||||
</data>
|
</data>
|
||||||
</root>
|
</root>
|
|
@ -1327,4 +1327,7 @@
|
||||||
<data name="TbSettingsGeoFilesSource" xml:space="preserve">
|
<data name="TbSettingsGeoFilesSource" xml:space="preserve">
|
||||||
<value>Geo文件来源(可选)</value>
|
<value>Geo文件来源(可选)</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="UpgradeAppNotExistTip" xml:space="preserve">
|
||||||
|
<value>升级工具App不存在</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
|
@ -1207,4 +1207,7 @@
|
||||||
<data name="TbSettingsGeoFilesSource" xml:space="preserve">
|
<data name="TbSettingsGeoFilesSource" xml:space="preserve">
|
||||||
<value>Geo文件來源(可選)</value>
|
<value>Geo文件來源(可選)</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="UpgradeAppNotExistTip" xml:space="preserve">
|
||||||
|
<value>升级工具App不存在</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
|
@ -4,7 +4,7 @@
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<Version>6.60.0</Version>
|
<Version>6.10.0</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -100,7 +100,7 @@ namespace ServiceLib.Services
|
||||||
};
|
};
|
||||||
HttpClient client = new(webRequestHandler);
|
HttpClient client = new(webRequestHandler);
|
||||||
|
|
||||||
HttpResponseMessage response = await client.GetAsync(url);
|
var response = await client.GetAsync(url);
|
||||||
if (response.StatusCode == HttpStatusCode.Redirect && response.Headers.Location is not null)
|
if (response.StatusCode == HttpStatusCode.Redirect && response.Headers.Location is not null)
|
||||||
{
|
{
|
||||||
return response.Headers.Location.ToString();
|
return response.Headers.Location.ToString();
|
||||||
|
@ -253,15 +253,12 @@ namespace ServiceLib.Services
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (webProxy == null)
|
webProxy ??= GetWebProxy(true);
|
||||||
{
|
|
||||||
webProxy = GetWebProxy(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var config = AppHandler.Instance.Config;
|
var config = AppHandler.Instance.Config;
|
||||||
int responseTime = await GetRealPingTime(config.speedTestItem.speedPingTestUrl, webProxy, 10);
|
var responseTime = await GetRealPingTime(config.speedTestItem.speedPingTestUrl, webProxy, 10);
|
||||||
return responseTime;
|
return responseTime;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -279,7 +276,7 @@ namespace ServiceLib.Services
|
||||||
|
|
||||||
public async Task<int> GetRealPingTime(string url, IWebProxy? webProxy, int downloadTimeout)
|
public async Task<int> GetRealPingTime(string url, IWebProxy? webProxy, int downloadTimeout)
|
||||||
{
|
{
|
||||||
int responseTime = -1;
|
var responseTime = -1;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var cts = new CancellationTokenSource();
|
using var cts = new CancellationTokenSource();
|
||||||
|
@ -290,8 +287,8 @@ namespace ServiceLib.Services
|
||||||
UseProxy = webProxy != null
|
UseProxy = webProxy != null
|
||||||
});
|
});
|
||||||
|
|
||||||
List<int> oneTime = [];
|
List<int> oneTime = new();
|
||||||
for (int i = 0; i < 2; i++)
|
for (var i = 0; i < 2; i++)
|
||||||
{
|
{
|
||||||
var timer = Stopwatch.StartNew();
|
var timer = Stopwatch.StartNew();
|
||||||
await client.GetAsync(url, cts.Token);
|
await client.GetAsync(url, cts.Token);
|
||||||
|
|
|
@ -423,7 +423,7 @@ namespace ServiceLib.Services
|
||||||
&& File.Exists(Path.Combine(Utils.StartupPath(), "D3DCompiler_47_cor3.dll"))
|
&& File.Exists(Path.Combine(Utils.StartupPath(), "D3DCompiler_47_cor3.dll"))
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return coreInfo?.DownloadUrlWin64?.Replace("v2rayN.zip", "zz_v2rayN-SelfContained.zip");
|
return coreInfo?.DownloadUrlWin64?.Replace(".zip", "-SelfContained.zip");
|
||||||
}
|
}
|
||||||
|
|
||||||
return RuntimeInformation.ProcessArchitecture switch
|
return RuntimeInformation.ProcessArchitecture switch
|
||||||
|
|
|
@ -126,11 +126,16 @@ namespace ServiceLib.ViewModels
|
||||||
}
|
}
|
||||||
//check
|
//check
|
||||||
var lstFiles = FileManager.GetFilesFromZip(fileName);
|
var lstFiles = FileManager.GetFilesFromZip(fileName);
|
||||||
if (lstFiles is null || !lstFiles.Where(t => t.Contains(_guiConfigs)).Any())
|
if (lstFiles is null || !lstFiles.Any(t => t.Contains(_guiConfigs)))
|
||||||
{
|
{
|
||||||
DisplayOperationMsg(ResUI.LocalRestoreInvalidZipTips);
|
DisplayOperationMsg(ResUI.LocalRestoreInvalidZipTips);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!Utils.UpgradeAppExists(out _))
|
||||||
|
{
|
||||||
|
DisplayOperationMsg(ResUI.UpgradeAppNotExistTip);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//backup first
|
//backup first
|
||||||
var fileBackup = Utils.GetBackupPath(BackupFileName);
|
var fileBackup = Utils.GetBackupPath(BackupFileName);
|
||||||
|
|
|
@ -235,6 +235,11 @@ namespace ServiceLib.ViewModels
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!Utils.UpgradeAppExists(out _))
|
||||||
|
{
|
||||||
|
UpdateView(_v2rayN, ResUI.UpgradeAppNotExistTip);
|
||||||
|
return;
|
||||||
|
}
|
||||||
Locator.Current.GetService<MainWindowViewModel>()?.UpgradeApp(fileName);
|
Locator.Current.GetService<MainWindowViewModel>()?.UpgradeApp(fileName);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
|
@ -280,14 +280,21 @@ namespace ServiceLib.ViewModels
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task UpgradeApp(string fileName)
|
public async Task UpgradeApp(string arg)
|
||||||
{
|
{
|
||||||
|
if (!Utils.UpgradeAppExists(out var fileName))
|
||||||
|
{
|
||||||
|
NoticeHandler.Instance.SendMessageAndEnqueue(ResUI.UpgradeAppNotExistTip);
|
||||||
|
Logging.SaveLog("UpgradeApp does not exist");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Process process = new()
|
Process process = new()
|
||||||
{
|
{
|
||||||
StartInfo = new ProcessStartInfo
|
StartInfo = new ProcessStartInfo
|
||||||
{
|
{
|
||||||
FileName = "AmazTool",
|
FileName = fileName,
|
||||||
Arguments = fileName.AppendQuotes(),
|
Arguments = arg.AppendQuotes(),
|
||||||
WorkingDirectory = Utils.StartupPath()
|
WorkingDirectory = Utils.StartupPath()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue