Skip to content

Commit

Permalink
Add linux download url
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Aug 27, 2024
1 parent 6f3e4b3 commit 43753b1
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 98 deletions.
17 changes: 17 additions & 0 deletions v2rayN/ServiceLib/Common/FileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -99,5 +115,6 @@ public static bool CreateFromDirectory(string sourceDirectoryName, string destin
}
return true;
}

}
}
8 changes: 5 additions & 3 deletions v2rayN/ServiceLib/Common/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
1 change: 1 addition & 0 deletions v2rayN/ServiceLib/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
41 changes: 16 additions & 25 deletions v2rayN/ServiceLib/Handler/CoreInfoHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
});

Expand Down Expand Up @@ -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",
});
Expand All @@ -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,
});
}
Expand Down
97 changes: 32 additions & 65 deletions v2rayN/ServiceLib/Handler/UpdateHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ private async void CheckUpdateAsync(ECoreType type, bool preRelease)
}

/// <summary>
/// 获取V2RayCore版本
/// 获取Core版本
/// </summary>
private SemanticVersion GetCoreVersion(ECoreType type)
{
Expand All @@ -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))
{
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions v2rayN/ServiceLib/Models/CoreInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
6 changes: 3 additions & 3 deletions v2rayN/ServiceLib/ServiceLib.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down
13 changes: 12 additions & 1 deletion v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion v2rayN/v2rayN/Common/UI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit 43753b1

Please sign in to comment.