From 43753b1b7a9b777031a669d4db6520718ed20ffe Mon Sep 17 00:00:00 2001
From: 2dust <31833384+2dust@users.noreply.github.com>
Date: Tue, 27 Aug 2024 13:06:39 +0800
Subject: [PATCH] Add linux download url
---
v2rayN/ServiceLib/Common/FileManager.cs | 17 ++++
v2rayN/ServiceLib/Common/Utils.cs | 8 +-
v2rayN/ServiceLib/Global.cs | 1 +
v2rayN/ServiceLib/Handler/CoreInfoHandler.cs | 41 +++-----
v2rayN/ServiceLib/Handler/UpdateHandler.cs | 97 ++++++-------------
v2rayN/ServiceLib/Models/CoreInfo.cs | 3 +
v2rayN/ServiceLib/ServiceLib.csproj | 6 +-
.../ViewModels/MainWindowViewModel.cs | 13 ++-
v2rayN/v2rayN/Common/UI.cs | 2 +-
9 files changed, 90 insertions(+), 98 deletions(-)
diff --git a/v2rayN/ServiceLib/Common/FileManager.cs b/v2rayN/ServiceLib/Common/FileManager.cs
index 39cfeb59e8..ee0eaa98e3 100644
--- a/v2rayN/ServiceLib/Common/FileManager.cs
+++ b/v2rayN/ServiceLib/Common/FileManager.cs
@@ -33,6 +33,22 @@ public static void UncompressedFile(string fileName, byte[] content)
}
}
+ public static void UncompressedFile(string fileName, string toPath, string? toName)
+ {
+ try
+ {
+ FileInfo fileInfo = new(fileName);
+ using FileStream originalFileStream = fileInfo.OpenRead();
+ using FileStream decompressedFileStream = File.Create(toName != null ? Path.Combine(toPath, toName) : toPath);
+ using GZipStream decompressionStream = new(originalFileStream, CompressionMode.Decompress);
+ decompressionStream.CopyTo(decompressedFileStream);
+ }
+ catch (Exception ex)
+ {
+ Logging.SaveLog(ex.Message, ex);
+ }
+ }
+
public static string NonExclusiveReadAllText(string path)
{
return NonExclusiveReadAllText(path, Encoding.Default);
@@ -99,5 +115,6 @@ public static bool CreateFromDirectory(string sourceDirectoryName, string destin
}
return true;
}
+
}
}
\ No newline at end of file
diff --git a/v2rayN/ServiceLib/Common/Utils.cs b/v2rayN/ServiceLib/Common/Utils.cs
index 968de934ca..a0b5b790af 100644
--- a/v2rayN/ServiceLib/Common/Utils.cs
+++ b/v2rayN/ServiceLib/Common/Utils.cs
@@ -593,20 +593,22 @@ public static string GetVersion(bool blFull = true)
string location = GetExePath();
if (blFull)
{
- return string.Format("v2rayN - V{0} - {1}",
+ return string.Format("{0} - V{1} - {2}",
+ Global.AppName,
FileVersionInfo.GetVersionInfo(location).FileVersion?.ToString(),
File.GetLastWriteTime(location).ToString("yyyy/MM/dd"));
}
else
{
- return string.Format("v2rayN/{0}",
+ return string.Format("{0}/{1}",
+ Global.AppName,
FileVersionInfo.GetVersionInfo(location).FileVersion?.ToString());
}
}
catch (Exception ex)
{
Logging.SaveLog(ex.Message, ex);
- return string.Empty;
+ return Global.AppName;
}
}
diff --git a/v2rayN/ServiceLib/Global.cs b/v2rayN/ServiceLib/Global.cs
index 53b97a50da..971d674307 100644
--- a/v2rayN/ServiceLib/Global.cs
+++ b/v2rayN/ServiceLib/Global.cs
@@ -4,6 +4,7 @@ public class Global
{
#region const
+ public const string AppName = "v2rayN";
public const string GithubUrl = "https://github.com";
public const string GithubApiUrl = "https://api.github.com/repos";
public const string V2flyCoreUrl = "https://github.com/v2fly/v2ray-core/releases";
diff --git a/v2rayN/ServiceLib/Handler/CoreInfoHandler.cs b/v2rayN/ServiceLib/Handler/CoreInfoHandler.cs
index 09e2d3212d..1cd581268f 100644
--- a/v2rayN/ServiceLib/Handler/CoreInfoHandler.cs
+++ b/v2rayN/ServiceLib/Handler/CoreInfoHandler.cs
@@ -42,7 +42,10 @@ private void InitCoreInfo()
coreReleaseApiUrl = Global.NUrl.Replace(Global.GithubUrl, Global.GithubApiUrl),
coreDownloadUrl32 = Global.NUrl + "/download/{0}/v2rayN-32.zip",
coreDownloadUrl64 = Global.NUrl + "/download/{0}/v2rayN.zip",
- coreDownloadUrlArm64 = Global.NUrl + "/download/{0}/v2rayN-arm64.zip"
+ coreDownloadUrlArm64 = Global.NUrl + "/download/{0}/v2rayN-arm64.zip",
+ coreDownloadUrlLinux32 = Global.NUrl + "/download/{0}/v2rayN-linux-32.zip",
+ coreDownloadUrlLinux64 = Global.NUrl + "/download/{0}/v2rayN-linux-64.zip",
+ coreDownloadUrlLinuxArm64 = Global.NUrl + "/download/{0}/v2rayN-linux-arm64.zip",
});
_coreInfo.Add(new CoreInfo
@@ -52,9 +55,6 @@ private void InitCoreInfo()
arguments = "",
coreUrl = Global.V2flyCoreUrl,
coreReleaseApiUrl = Global.V2flyCoreUrl.Replace(Global.GithubUrl, Global.GithubApiUrl),
- coreDownloadUrl32 = Global.V2flyCoreUrl + "/download/{0}/v2ray-windows-{1}.zip",
- coreDownloadUrl64 = Global.V2flyCoreUrl + "/download/{0}/v2ray-windows-{1}.zip",
- coreDownloadUrlArm64 = Global.V2flyCoreUrl + "/download/{0}/v2ray-windows-{1}.zip",
match = "V2Ray",
versionArg = "-version",
redirectInfo = true,
@@ -67,9 +67,6 @@ private void InitCoreInfo()
arguments = "run",
coreUrl = Global.SagerNetCoreUrl,
coreReleaseApiUrl = Global.SagerNetCoreUrl.Replace(Global.GithubUrl, Global.GithubApiUrl),
- coreDownloadUrl32 = Global.SagerNetCoreUrl + "/download/{0}/v2ray-windows-{1}.zip",
- coreDownloadUrl64 = Global.SagerNetCoreUrl + "/download/{0}/v2ray-windows-{1}.zip",
- coreDownloadUrlArm64 = Global.SagerNetCoreUrl + "/download/{0}/v2ray-windows-{1}.zip",
match = "V2Ray",
versionArg = "version",
redirectInfo = true,
@@ -82,9 +79,6 @@ private void InitCoreInfo()
arguments = "run -c config.json -format jsonv5",
coreUrl = Global.V2flyCoreUrl,
coreReleaseApiUrl = Global.V2flyCoreUrl.Replace(Global.GithubUrl, Global.GithubApiUrl),
- coreDownloadUrl32 = Global.V2flyCoreUrl + "/download/{0}/v2ray-windows-{1}.zip",
- coreDownloadUrl64 = Global.V2flyCoreUrl + "/download/{0}/v2ray-windows-{1}.zip",
- coreDownloadUrlArm64 = Global.V2flyCoreUrl + "/download/{0}/v2ray-windows-{1}.zip",
match = "V2Ray",
versionArg = "version",
redirectInfo = true,
@@ -97,9 +91,12 @@ private void InitCoreInfo()
arguments = "run {0}",
coreUrl = Global.XrayCoreUrl,
coreReleaseApiUrl = Global.XrayCoreUrl.Replace(Global.GithubUrl, Global.GithubApiUrl),
- coreDownloadUrl32 = Global.XrayCoreUrl + "/download/{0}/Xray-windows-{1}.zip",
- coreDownloadUrl64 = Global.XrayCoreUrl + "/download/{0}/Xray-windows-{1}.zip",
- coreDownloadUrlArm64 = Global.XrayCoreUrl + "/download/{0}/Xray-windows-{1}.zip",
+ coreDownloadUrl32 = Global.XrayCoreUrl + "/download/{0}/Xray-windows-32.zip",
+ coreDownloadUrl64 = Global.XrayCoreUrl + "/download/{0}/Xray-windows-64.zip",
+ coreDownloadUrlArm64 = Global.XrayCoreUrl + "/download/{0}/Xray-windows-arm64-v8a.zip",
+ coreDownloadUrlLinux32 = Global.XrayCoreUrl + "/download/{0}/Xray-linux-32.zip",
+ coreDownloadUrlLinux64 = Global.XrayCoreUrl + "/download/{0}/Xray-linux-64.zip",
+ coreDownloadUrlLinuxArm64 = Global.XrayCoreUrl + "/download/{0}/Xray-linux-arm64-v8a.zip",
match = "Xray",
versionArg = "-version",
redirectInfo = true,
@@ -112,9 +109,6 @@ private void InitCoreInfo()
arguments = "-f config.json",
coreUrl = Global.ClashCoreUrl,
coreReleaseApiUrl = Global.ClashCoreUrl.Replace(Global.GithubUrl, Global.GithubApiUrl),
- coreDownloadUrl32 = Global.ClashCoreUrl + "/download/{0}/clash-windows-386-{0}.zip",
- coreDownloadUrl64 = Global.ClashCoreUrl + "/download/{0}/clash-windows-amd64-{0}.zip",
- coreDownloadUrlArm64 = Global.ClashCoreUrl + "/download/{0}/clash-windows-arm64-{0}.zip",
match = "v",
versionArg = "-v",
redirectInfo = true,
@@ -127,9 +121,6 @@ private void InitCoreInfo()
arguments = "-f config.json",
coreUrl = Global.ClashMetaCoreUrl,
coreReleaseApiUrl = Global.ClashMetaCoreUrl.Replace(Global.GithubUrl, Global.GithubApiUrl),
- coreDownloadUrl32 = Global.ClashMetaCoreUrl + "/download/{0}/Clash.Meta-windows-386-{0}.zip",
- coreDownloadUrl64 = Global.ClashMetaCoreUrl + "/download/{0}/Clash.Meta-windows-amd64-compatible-{0}.zip",
- coreDownloadUrlArm64 = Global.ClashMetaCoreUrl + "/download/{0}/Clash.Meta-windows-arm64-{0}.zip",
match = "v",
versionArg = "-v",
redirectInfo = true,
@@ -145,6 +136,9 @@ private void InitCoreInfo()
coreDownloadUrl32 = Global.ClashMetaCoreUrl + "/download/{0}/mihomo-windows-386-{0}.zip",
coreDownloadUrl64 = Global.ClashMetaCoreUrl + "/download/{0}/mihomo-windows-amd64-compatible-{0}.zip",
coreDownloadUrlArm64 = Global.ClashMetaCoreUrl + "/download/{0}/mihomo-windows-arm64-{0}.zip",
+ coreDownloadUrlLinux32 = Global.ClashMetaCoreUrl + "/download/{0}/mihomo-linux-386-{0}.gz",
+ coreDownloadUrlLinux64 = Global.ClashMetaCoreUrl + "/download/{0}/mihomo-linux-amd64-compatible-{0}.gz",
+ coreDownloadUrlLinuxArm64 = Global.ClashMetaCoreUrl + "/download/{0}/mihomo-linux-arm64-{0}.gz",
match = "Mihomo",
versionArg = "-v",
redirectInfo = true,
@@ -157,9 +151,6 @@ private void InitCoreInfo()
arguments = "",
coreUrl = Global.HysteriaCoreUrl,
coreReleaseApiUrl = Global.HysteriaCoreUrl.Replace(Global.GithubUrl, Global.GithubApiUrl),
- coreDownloadUrl32 = Global.HysteriaCoreUrl + "/download/{0}/hysteria-windows-386.exe",
- coreDownloadUrl64 = Global.HysteriaCoreUrl + "/download/{0}/hysteria-windows-amd64.exe",
- coreDownloadUrlArm64 = Global.HysteriaCoreUrl + "/download/{0}/hysteria-windows-arm64.exe",
redirectInfo = true,
});
@@ -192,6 +183,9 @@ private void InitCoreInfo()
coreDownloadUrl32 = Global.SingboxCoreUrl + "/download/{0}/sing-box-{1}-windows-386.zip",
coreDownloadUrl64 = Global.SingboxCoreUrl + "/download/{0}/sing-box-{1}-windows-amd64.zip",
coreDownloadUrlArm64 = Global.SingboxCoreUrl + "/download/{0}/sing-box-{1}-windows-arm64.zip",
+ coreDownloadUrlLinux32 = Global.SingboxCoreUrl + "/download/{0}/sing-box-{1}-linux-386.tar.gz",
+ coreDownloadUrlLinux64 = Global.SingboxCoreUrl + "/download/{0}/sing-box-{1}-linux-amd64.tar.gz",
+ coreDownloadUrlLinuxArm64 = Global.SingboxCoreUrl + "/download/{0}/sing-box-{1}-linux-arm64.tar.gz",
match = "sing-box",
versionArg = "version",
});
@@ -211,9 +205,6 @@ private void InitCoreInfo()
arguments = "",
coreUrl = Global.HysteriaCoreUrl,
coreReleaseApiUrl = Global.HysteriaCoreUrl.Replace(Global.GithubUrl, Global.GithubApiUrl),
- coreDownloadUrl32 = Global.HysteriaCoreUrl + "/download/{0}/hysteria-windows-386.exe",
- coreDownloadUrl64 = Global.HysteriaCoreUrl + "/download/{0}/hysteria-windows-amd64.exe",
- coreDownloadUrlArm64 = Global.HysteriaCoreUrl + "/download/{0}/hysteria-windows-arm64.exe",
redirectInfo = true,
});
}
diff --git a/v2rayN/ServiceLib/Handler/UpdateHandler.cs b/v2rayN/ServiceLib/Handler/UpdateHandler.cs
index 2a459daf3f..e517e17c60 100644
--- a/v2rayN/ServiceLib/Handler/UpdateHandler.cs
+++ b/v2rayN/ServiceLib/Handler/UpdateHandler.cs
@@ -308,7 +308,7 @@ private async void CheckUpdateAsync(ECoreType type, bool preRelease)
}
///
- /// 获取V2RayCore版本
+ /// 获取Core版本
///
private SemanticVersion GetCoreVersion(ECoreType type)
{
@@ -318,7 +318,7 @@ private SemanticVersion GetCoreVersion(ECoreType type)
string filePath = string.Empty;
foreach (string name in coreInfo.coreExes)
{
- string vName = $"{name}.exe";
+ string vName = Utils.GetExeName(name);
vName = Utils.GetBinPath(vName, coreInfo.coreType.ToString());
if (File.Exists(vName))
{
@@ -385,10 +385,9 @@ private void ResponseHandler(ECoreType type, string gitHubReleaseApi, bool preRe
var body = gitHubRelease?.Body;
var coreInfo = CoreInfoHandler.Instance.GetCoreInfo(type);
-
SemanticVersion curVersion;
string message;
- string url;
+ string? url;
switch (type)
{
case ECoreType.v2fly:
@@ -398,23 +397,7 @@ private void ResponseHandler(ECoreType type, string gitHubReleaseApi, bool preRe
{
curVersion = GetCoreVersion(type);
message = string.Format(ResUI.IsLatestCore, type, curVersion.ToVersionString("v"));
- string osBit = "64";
- switch (RuntimeInformation.ProcessArchitecture)
- {
- case Architecture.Arm64:
- osBit = "arm64-v8a";
- break;
-
- case Architecture.X86:
- osBit = "32";
- break;
-
- default:
- osBit = "64";
- break;
- }
-
- url = string.Format(coreInfo.coreDownloadUrl64, version.ToVersionString("v"), osBit);
+ url = string.Format(GetUrlFromCore(coreInfo), version.ToVersionString("v"));
break;
}
case ECoreType.clash:
@@ -423,62 +406,21 @@ private void ResponseHandler(ECoreType type, string gitHubReleaseApi, bool preRe
{
curVersion = GetCoreVersion(type);
message = string.Format(ResUI.IsLatestCore, type, curVersion);
- switch (RuntimeInformation.ProcessArchitecture)
- {
- case Architecture.Arm64:
- url = coreInfo.coreDownloadUrlArm64;
- break;
-
- case Architecture.X86:
- url = coreInfo.coreDownloadUrl32;
- break;
-
- default:
- url = coreInfo.coreDownloadUrl64;
- break;
- }
- url = string.Format(url, version.ToVersionString("v"));
+ url = string.Format(GetUrlFromCore(coreInfo), version.ToVersionString("v"));
break;
}
case ECoreType.sing_box:
{
curVersion = GetCoreVersion(type);
message = string.Format(ResUI.IsLatestCore, type, curVersion.ToVersionString("v"));
- switch (RuntimeInformation.ProcessArchitecture)
- {
- case Architecture.Arm64:
- url = coreInfo.coreDownloadUrlArm64;
- break;
-
- case Architecture.X86:
- url = coreInfo.coreDownloadUrl32;
- break;
-
- default:
- url = coreInfo.coreDownloadUrl64;
- break;
- }
- url = string.Format(url, version.ToVersionString("v"), version);
+ url = string.Format(GetUrlFromCore(coreInfo), version.ToVersionString("v"), version);
break;
}
case ECoreType.v2rayN:
{
curVersion = new SemanticVersion(FileVersionInfo.GetVersionInfo(Utils.GetExePath()).FileVersion.ToString());
message = string.Format(ResUI.IsLatestN, type, curVersion);
- switch (RuntimeInformation.ProcessArchitecture)
- {
- case Architecture.Arm64:
- url = string.Format(coreInfo.coreDownloadUrlArm64, version);
- break;
-
- case Architecture.X86:
- url = string.Format(coreInfo.coreDownloadUrl32, version);
- break;
-
- default:
- url = string.Format(coreInfo.coreDownloadUrl64, version);
- break;
- }
+ url = string.Format(GetUrlFromCore(coreInfo), version);
break;
}
default:
@@ -500,6 +442,31 @@ private void ResponseHandler(ECoreType type, string gitHubReleaseApi, bool preRe
}
}
+ private string? GetUrlFromCore(CoreInfo? coreInfo)
+ {
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ {
+ return RuntimeInformation.ProcessArchitecture switch
+ {
+ Architecture.Arm64 => coreInfo?.coreDownloadUrlArm64,
+ Architecture.X86 => coreInfo?.coreDownloadUrl32,
+ Architecture.X64 => coreInfo?.coreDownloadUrl64,
+ _ => null,
+ };
+ }
+ else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
+ {
+ return RuntimeInformation.ProcessArchitecture switch
+ {
+ Architecture.Arm64 => coreInfo?.coreDownloadUrlLinuxArm64,
+ Architecture.X86 => coreInfo?.coreDownloadUrlLinux32,
+ Architecture.X64 => coreInfo?.coreDownloadUrlLinux64,
+ _ => null,
+ };
+ }
+ return null;
+ }
+
private async Task AskToDownload(DownloadHandler downloadHandle, string url, bool blAsk)
{
//bool blDownload = false;
diff --git a/v2rayN/ServiceLib/Models/CoreInfo.cs b/v2rayN/ServiceLib/Models/CoreInfo.cs
index e1620953c9..077060cc39 100644
--- a/v2rayN/ServiceLib/Models/CoreInfo.cs
+++ b/v2rayN/ServiceLib/Models/CoreInfo.cs
@@ -18,6 +18,9 @@ public class CoreInfo
public string coreDownloadUrl64 { get; set; }
public string coreDownloadUrlArm64 { get; set; }
+ public string? coreDownloadUrlLinux32 { get; set; }
+ public string? coreDownloadUrlLinux64 { get; set; }
+ public string? coreDownloadUrlLinuxArm64 { get; set; }
public string match { get; set; }
public string versionArg { get; set; }
diff --git a/v2rayN/ServiceLib/ServiceLib.csproj b/v2rayN/ServiceLib/ServiceLib.csproj
index e176383f2c..7cb089c39d 100644
--- a/v2rayN/ServiceLib/ServiceLib.csproj
+++ b/v2rayN/ServiceLib/ServiceLib.csproj
@@ -1,9 +1,9 @@
- net8.0
- enable
- enable
+ net8.0
+ enable
+ enable
diff --git a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs
index b80db10308..9bae9d016c 100644
--- a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs
+++ b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs
@@ -766,7 +766,18 @@ void _updateUI(bool success, string msg)
string fileName = Utils.GetTempPath(Utils.GetDownloadFileName(msg));
string toPath = Utils.GetBinPath("", type.ToString());
- FileManager.ZipExtractToFile(fileName, toPath, _config.guiItem.ignoreGeoUpdateCore ? "geo" : "");
+ if (fileName.Contains(".tar.gz"))
+ {
+ //It's too complicated to unzip. TODO
+ }
+ else if (fileName.Contains(".gz"))
+ {
+ FileManager.UncompressedFile(fileName, toPath, type.ToString());
+ }
+ else
+ {
+ FileManager.ZipExtractToFile(fileName, toPath, _config.guiItem.ignoreGeoUpdateCore ? "geo" : "");
+ }
_noticeHandler?.SendMessage(ResUI.MsgUpdateV2rayCoreSuccessfullyMore);
diff --git a/v2rayN/v2rayN/Common/UI.cs b/v2rayN/v2rayN/Common/UI.cs
index 7b608e96ae..b89cdf79f5 100644
--- a/v2rayN/v2rayN/Common/UI.cs
+++ b/v2rayN/v2rayN/Common/UI.cs
@@ -5,7 +5,7 @@ namespace v2rayN
{
internal class UI
{
- private static readonly string caption = "v2rayN";
+ private static readonly string caption = Global.AppName;
public static void Show(string msg)
{