mirror of
https://github.com/2dust/v2rayN.git
synced 2025-08-30 06:46:19 +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 杂项
|
||||
|
||||
public static bool UpgradeAppExists(out string fileName)
|
||||
{
|
||||
fileName = Path.Combine(Utils.StartupPath(), GetExeName("AmazTool"));
|
||||
return File.Exists(fileName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 取得版本
|
||||
/// </summary>
|
||||
|
|
|
@ -201,5 +201,14 @@ namespace ServiceLib.Handler.Fmt
|
|||
File.WriteAllText(fileName, strData);
|
||||
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");
|
||||
|
||||
string query = "?" + string.Join("&", dicQuery.Select(x => x.Key + "=" + x.Value).ToArray());
|
||||
|
||||
url = string.Format("{0}@{1}:{2}",
|
||||
item.id,
|
||||
GetIpv6(item.address),
|
||||
item.port);
|
||||
url = $"{Global.ProtocolShares[EConfigType.Hysteria2]}{url}/{query}{remark}";
|
||||
return url;
|
||||
return ToUri(EConfigType.Hysteria2, item.address, item.port, item.id, dicQuery, remark);
|
||||
}
|
||||
|
||||
public static ProfileItem? ResolveFull(string strData, string? subRemarks)
|
||||
|
|
|
@ -42,9 +42,7 @@ namespace ServiceLib.Handler.Fmt
|
|||
//url = Utile.Base64Encode(url);
|
||||
//new Sip002
|
||||
var pw = Utils.Base64Encode($"{item.security}:{item.id}");
|
||||
url = $"{pw}@{GetIpv6(item.address)}:{item.port}";
|
||||
url = $"{Global.ProtocolShares[EConfigType.Shadowsocks]}{url}{remark}";
|
||||
return url;
|
||||
return ToUri(EConfigType.Shadowsocks, item.address, item.port, pw, null, remark);
|
||||
}
|
||||
|
||||
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,
|
||||
port = parsedUrl.Port,
|
||||
};
|
||||
string rawUserInfo = parsedUrl.GetComponents(UriComponents.UserInfo, UriFormat.UriEscaped);
|
||||
var rawUserInfo = Utils.UrlDecode(parsedUrl.UserInfo);
|
||||
//2022-blake3
|
||||
if (rawUserInfo.Contains(':'))
|
||||
{
|
||||
|
|
|
@ -40,9 +40,7 @@
|
|||
//url = Utile.Base64Encode(url);
|
||||
//new
|
||||
var pw = Utils.Base64Encode($"{item.security}:{item.id}");
|
||||
url = $"{pw}@{GetIpv6(item.address)}:{item.port}";
|
||||
url = $"{Global.ProtocolShares[EConfigType.SOCKS]}{url}{remark}";
|
||||
return url;
|
||||
return ToUri(EConfigType.SOCKS, item.address, item.port, pw, null, remark);
|
||||
}
|
||||
|
||||
private static ProfileItem? ResolveSocks(string result)
|
||||
|
@ -112,9 +110,9 @@
|
|||
};
|
||||
|
||||
// parse base64 UserInfo
|
||||
string rawUserInfo = parsedUrl.GetComponents(UriComponents.UserInfo, UriFormat.Unescaped);
|
||||
string userInfo = Utils.Base64Decode(rawUserInfo);
|
||||
string[] userInfoParts = userInfo.Split(new[] { ':' }, 2);
|
||||
var rawUserInfo = Utils.UrlDecode(parsedUrl.UserInfo);
|
||||
var userInfo = Utils.Base64Decode(rawUserInfo);
|
||||
var userInfoParts = userInfo.Split(new[] { ':' }, 2);
|
||||
if (userInfoParts.Length == 2)
|
||||
{
|
||||
item.security = userInfoParts[0];
|
||||
|
|
|
@ -36,14 +36,8 @@
|
|||
}
|
||||
var dicQuery = new Dictionary<string, string>();
|
||||
GetStdTransport(item, null, ref dicQuery);
|
||||
string query = "?" + string.Join("&", dicQuery.Select(x => x.Key + "=" + x.Value).ToArray());
|
||||
|
||||
url = string.Format("{0}@{1}:{2}",
|
||||
item.id,
|
||||
GetIpv6(item.address),
|
||||
item.port);
|
||||
url = $"{Global.ProtocolShares[EConfigType.Trojan]}{url}{query}{remark}";
|
||||
return url;
|
||||
return ToUri(EConfigType.Trojan, item.address, item.port, item.id, dicQuery, remark);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,7 +16,8 @@
|
|||
item.address = url.IdnHost;
|
||||
item.port = url.Port;
|
||||
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)
|
||||
{
|
||||
item.id = userInfoParts[0];
|
||||
|
@ -51,14 +52,7 @@
|
|||
}
|
||||
dicQuery.Add("congestion_control", item.headerType);
|
||||
|
||||
string query = "?" + string.Join("&", dicQuery.Select(x => x.Key + "=" + x.Value).ToArray());
|
||||
|
||||
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;
|
||||
return ToUri(EConfigType.TUIC, item.address, item.port, $"{item.id}:{item.security}", dicQuery, remark);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -47,14 +47,8 @@
|
|||
dicQuery.Add("encryption", Global.None);
|
||||
}
|
||||
GetStdTransport(item, Global.None, ref dicQuery);
|
||||
string query = "?" + string.Join("&", dicQuery.Select(x => x.Key + "=" + x.Value).ToArray());
|
||||
|
||||
url = string.Format("{0}@{1}:{2}",
|
||||
item.id,
|
||||
GetIpv6(item.address),
|
||||
item.port);
|
||||
url = $"{Global.ProtocolShares[EConfigType.VLESS]}{url}{query}{remark}";
|
||||
return url;
|
||||
return ToUri(EConfigType.VLESS, item.address, item.port, item.id, dicQuery, remark);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -56,14 +56,7 @@
|
|||
{
|
||||
dicQuery.Add("mtu", Utils.UrlEncode(item.shortId));
|
||||
}
|
||||
string query = "?" + string.Join("&", dicQuery.Select(x => x.Key + "=" + x.Value).ToArray());
|
||||
|
||||
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;
|
||||
return ToUri(EConfigType.WireGuard, item.address, item.port, item.id, dicQuery, remark);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -12,7 +12,7 @@ namespace ServiceLib.Handler
|
|||
private WebDavClient? _client;
|
||||
private string? _lastDescription;
|
||||
private string _webDir = Global.AppName + "_backup";
|
||||
private string _webFileName = "backup.zip";
|
||||
private readonly string _webFileName = "backup.zip";
|
||||
private string _logTitle = "WebDav--";
|
||||
|
||||
public WebDavHandler()
|
||||
|
@ -130,7 +130,7 @@ namespace ServiceLib.Handler
|
|||
|
||||
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
|
||||
if (result.IsSuccessful)
|
||||
{
|
||||
|
@ -162,8 +162,9 @@ namespace ServiceLib.Handler
|
|||
SaveLog(response.Description);
|
||||
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;
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 UpgradeApp does not exist 的本地化字符串。
|
||||
/// </summary>
|
||||
public static string UpgradeAppNotExistTip {
|
||||
get {
|
||||
return ResourceManager.GetString("UpgradeAppNotExistTip", resourceCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1332,5 +1332,7 @@
|
|||
</data>
|
||||
<data name="TbSettingsSrsFilesSource" xml:space="preserve">
|
||||
<value>Sing-box srs files source (optional)</value>
|
||||
<data name="UpgradeAppNotExistTip" xml:space="preserve">
|
||||
<value>UpgradeApp does not exist</value>
|
||||
</data>
|
||||
</root>
|
|
@ -1327,4 +1327,7 @@
|
|||
<data name="TbSettingsGeoFilesSource" xml:space="preserve">
|
||||
<value>Geo文件来源(可选)</value>
|
||||
</data>
|
||||
<data name="UpgradeAppNotExistTip" xml:space="preserve">
|
||||
<value>升级工具App不存在</value>
|
||||
</data>
|
||||
</root>
|
|
@ -1207,4 +1207,7 @@
|
|||
<data name="TbSettingsGeoFilesSource" xml:space="preserve">
|
||||
<value>Geo文件來源(可選)</value>
|
||||
</data>
|
||||
<data name="UpgradeAppNotExistTip" xml:space="preserve">
|
||||
<value>升级工具App不存在</value>
|
||||
</data>
|
||||
</root>
|
|
@ -4,7 +4,7 @@
|
|||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>6.60.0</Version>
|
||||
<Version>6.10.0</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -100,7 +100,7 @@ namespace ServiceLib.Services
|
|||
};
|
||||
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)
|
||||
{
|
||||
return response.Headers.Location.ToString();
|
||||
|
@ -253,15 +253,12 @@ namespace ServiceLib.Services
|
|||
{
|
||||
try
|
||||
{
|
||||
if (webProxy == null)
|
||||
{
|
||||
webProxy = GetWebProxy(true);
|
||||
}
|
||||
webProxy ??= GetWebProxy(true);
|
||||
|
||||
try
|
||||
{
|
||||
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;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -279,7 +276,7 @@ namespace ServiceLib.Services
|
|||
|
||||
public async Task<int> GetRealPingTime(string url, IWebProxy? webProxy, int downloadTimeout)
|
||||
{
|
||||
int responseTime = -1;
|
||||
var responseTime = -1;
|
||||
try
|
||||
{
|
||||
using var cts = new CancellationTokenSource();
|
||||
|
@ -290,8 +287,8 @@ namespace ServiceLib.Services
|
|||
UseProxy = webProxy != null
|
||||
});
|
||||
|
||||
List<int> oneTime = [];
|
||||
for (int i = 0; i < 2; i++)
|
||||
List<int> oneTime = new();
|
||||
for (var i = 0; i < 2; i++)
|
||||
{
|
||||
var timer = Stopwatch.StartNew();
|
||||
await client.GetAsync(url, cts.Token);
|
||||
|
|
|
@ -423,7 +423,7 @@ namespace ServiceLib.Services
|
|||
&& 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
|
||||
|
|
|
@ -126,11 +126,16 @@ namespace ServiceLib.ViewModels
|
|||
}
|
||||
//check
|
||||
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);
|
||||
return;
|
||||
}
|
||||
if (!Utils.UpgradeAppExists(out _))
|
||||
{
|
||||
DisplayOperationMsg(ResUI.UpgradeAppNotExistTip);
|
||||
return;
|
||||
}
|
||||
|
||||
//backup first
|
||||
var fileBackup = Utils.GetBackupPath(BackupFileName);
|
||||
|
|
|
@ -235,6 +235,11 @@ namespace ServiceLib.ViewModels
|
|||
{
|
||||
return;
|
||||
}
|
||||
if (!Utils.UpgradeAppExists(out _))
|
||||
{
|
||||
UpdateView(_v2rayN, ResUI.UpgradeAppNotExistTip);
|
||||
return;
|
||||
}
|
||||
Locator.Current.GetService<MainWindowViewModel>()?.UpgradeApp(fileName);
|
||||
}
|
||||
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()
|
||||
{
|
||||
StartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = "AmazTool",
|
||||
Arguments = fileName.AppendQuotes(),
|
||||
FileName = fileName,
|
||||
Arguments = arg.AppendQuotes(),
|
||||
WorkingDirectory = Utils.StartupPath()
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue