From 700f98193ac5bc197a20ebf381afed8ea6db8a56 Mon Sep 17 00:00:00 2001 From: DHR60 Date: Mon, 11 May 2026 01:57:16 +0000 Subject: [PATCH 01/61] Fix (#9274) --- v2rayN/ServiceLib/Handler/ConfigHandler.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/v2rayN/ServiceLib/Handler/ConfigHandler.cs b/v2rayN/ServiceLib/Handler/ConfigHandler.cs index 29223c547f3..8f04f0f9b21 100644 --- a/v2rayN/ServiceLib/Handler/ConfigHandler.cs +++ b/v2rayN/ServiceLib/Handler/ConfigHandler.cs @@ -1847,7 +1847,19 @@ public static async Task AddBatchServers(Config config, string strData, str } //May be standard uri mixed with internal uri - var innerUriCount = await AddBatchServers4InnerUri(config, strData, subid, isSub); + var innerUriCount = 0; + if (Utils.IsBase64String(strData)) + { + innerUriCount = await AddBatchServers4InnerUri(config, Utils.Base64Decode(strData), subid, isSub); + } + if (innerUriCount < 1) + { + innerUriCount = await AddBatchServers4InnerUri(config, strData, subid, isSub); + } + if (innerUriCount < 1) + { + innerUriCount = await AddBatchServers4InnerUri(config, Utils.Base64Decode(strData), subid, isSub); + } if (innerUriCount > 0) { if (counter > 0) From 8090799ccc7c175cb04efe7e4960f38b74c19dad Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Mon, 11 May 2026 11:00:19 +0800 Subject: [PATCH 02/61] Refactor models into sub-namespaces Move many model classes into new sub-namespaces (ServiceLib.Models.CoreConfigs, ServiceLib.Models.Configs, ServiceLib.Models.Dto, ServiceLib.Models.Entities). Update GlobalUsings in ServiceLib, v2rayN.Desktop, v2rayN and add a tests GlobalUsings file to reference the new namespaces. Adjust static using directives in ClashApiManager and ClashProxiesViewModel to use ServiceLib.Models.Dto. This is a reorganization/rename of files and namespaces with no functional changes. --- v2rayN/ServiceLib.Tests/GlobalUsings.cs | 40 +++++++++++++++++++ v2rayN/ServiceLib/GlobalUsings.cs | 5 ++- v2rayN/ServiceLib/Manager/ClashApiManager.cs | 2 +- .../ServiceLib/Models/{ => Configs}/Config.cs | 2 +- .../Models/{ => Configs}/ConfigItems.cs | 2 +- .../{ => CoreConfigs}/CoreConfigContext.cs | 2 +- .../Models/{ => CoreConfigs}/CoreInfo.cs | 2 +- .../Models/{ => CoreConfigs}/SingboxConfig.cs | 2 +- .../Models/{ => CoreConfigs}/V2rayConfig.cs | 2 +- .../{ => CoreConfigs}/V2rayMetricsVars.cs | 2 +- .../{ => CoreConfigs}/V2rayTcpRequest.cs | 2 +- .../Models/{ => Dto}/CheckUpdateModel.cs | 2 +- .../Models/{ => Dto}/ClashConnectionModel.cs | 2 +- .../Models/{ => Dto}/ClashConnections.cs | 2 +- .../Models/{ => Dto}/ClashProviders.cs | 4 +- .../Models/{ => Dto}/ClashProxies.cs | 2 +- .../Models/{ => Dto}/ClashProxyModel.cs | 2 +- v2rayN/ServiceLib/Models/{ => Dto}/CmdItem.cs | 2 +- .../ServiceLib/Models/{ => Dto}/ComboItem.cs | 2 +- .../Models/{ => Dto}/GitHubRelease.cs | 2 +- .../ServiceLib/Models/{ => Dto}/IPAPIInfo.cs | 2 +- .../Models/{ => Dto}/ProfileItemModel.cs | 2 +- .../ServiceLib/Models/{ => Dto}/RetResult.cs | 2 +- .../Models/{ => Dto}/RoutingItemModel.cs | 2 +- .../Models/{ => Dto}/RoutingTemplate.cs | 2 +- .../Models/{ => Dto}/RulesItemModel.cs | 2 +- .../Models/{ => Dto}/SemanticVersion.cs | 2 +- .../Models/{ => Dto}/ServerSpeedItem.cs | 2 +- .../Models/{ => Dto}/ServerTestItem.cs | 2 +- .../Models/{ => Dto}/SpeedTestResult.cs | 2 +- .../ServiceLib/Models/{ => Dto}/SsSIP008.cs | 2 +- .../Models/{ => Dto}/UpdateResult.cs | 2 +- .../Models/{ => Dto}/VmessQRCode.cs | 2 +- .../Models/{ => Entities}/DNSItem.cs | 2 +- .../{ => Entities}/FullConfigTemplateItem.cs | 2 +- .../Models/{ => Entities}/ProfileExItem.cs | 2 +- .../Models/{ => Entities}/ProfileGroupItem.cs | 2 +- .../Models/{ => Entities}/ProfileItem.cs | 2 +- .../{ => Entities}/ProtocolExtraItem.cs | 2 +- .../Models/{ => Entities}/RoutingItem.cs | 2 +- .../Models/{ => Entities}/RulesItem.cs | 2 +- .../Models/{ => Entities}/ServerStatItem.cs | 2 +- .../Models/{ => Entities}/SubItem.cs | 2 +- .../{ => Entities}/TransportExtraItem.cs | 2 +- .../ViewModels/ClashProxiesViewModel.cs | 4 +- v2rayN/v2rayN.Desktop/GlobalUsings.cs | 5 ++- v2rayN/v2rayN/GlobalUsings.cs | 5 ++- 47 files changed, 97 insertions(+), 48 deletions(-) create mode 100644 v2rayN/ServiceLib.Tests/GlobalUsings.cs rename v2rayN/ServiceLib/Models/{ => Configs}/Config.cs (97%) rename v2rayN/ServiceLib/Models/{ => Configs}/ConfigItems.cs (99%) rename v2rayN/ServiceLib/Models/{ => CoreConfigs}/CoreConfigContext.cs (95%) rename v2rayN/ServiceLib/Models/{ => CoreConfigs}/CoreInfo.cs (95%) rename v2rayN/ServiceLib/Models/{ => CoreConfigs}/SingboxConfig.cs (99%) rename v2rayN/ServiceLib/Models/{ => CoreConfigs}/V2rayConfig.cs (99%) rename v2rayN/ServiceLib/Models/{ => CoreConfigs}/V2rayMetricsVars.cs (88%) rename v2rayN/ServiceLib/Models/{ => CoreConfigs}/V2rayTcpRequest.cs (85%) rename v2rayN/ServiceLib/Models/{ => Dto}/CheckUpdateModel.cs (89%) rename v2rayN/ServiceLib/Models/{ => Dto}/ClashConnectionModel.cs (93%) rename v2rayN/ServiceLib/Models/{ => Dto}/ClashConnections.cs (97%) rename v2rayN/ServiceLib/Models/{ => Dto}/ClashProviders.cs (80%) rename v2rayN/ServiceLib/Models/{ => Dto}/ClashProxies.cs (94%) rename v2rayN/ServiceLib/Models/{ => Dto}/ClashProxyModel.cs (90%) rename v2rayN/ServiceLib/Models/{ => Dto}/CmdItem.cs (77%) rename v2rayN/ServiceLib/Models/{ => Dto}/ComboItem.cs (80%) rename v2rayN/ServiceLib/Models/{ => Dto}/GitHubRelease.cs (98%) rename v2rayN/ServiceLib/Models/{ => Dto}/IPAPIInfo.cs (93%) rename v2rayN/ServiceLib/Models/{ => Dto}/ProfileItemModel.cs (97%) rename v2rayN/ServiceLib/Models/{ => Dto}/RetResult.cs (93%) rename v2rayN/ServiceLib/Models/{ => Dto}/RoutingItemModel.cs (65%) rename v2rayN/ServiceLib/Models/{ => Dto}/RoutingTemplate.cs (81%) rename v2rayN/ServiceLib/Models/{ => Dto}/RulesItemModel.cs (89%) rename v2rayN/ServiceLib/Models/{ => Dto}/SemanticVersion.cs (99%) rename v2rayN/ServiceLib/Models/{ => Dto}/ServerSpeedItem.cs (91%) rename v2rayN/ServiceLib/Models/{ => Dto}/ServerTestItem.cs (91%) rename v2rayN/ServiceLib/Models/{ => Dto}/SpeedTestResult.cs (83%) rename v2rayN/ServiceLib/Models/{ => Dto}/SsSIP008.cs (91%) rename v2rayN/ServiceLib/Models/{ => Dto}/UpdateResult.cs (92%) rename v2rayN/ServiceLib/Models/{ => Dto}/VmessQRCode.cs (97%) rename v2rayN/ServiceLib/Models/{ => Entities}/DNSItem.cs (92%) rename v2rayN/ServiceLib/Models/{ => Entities}/FullConfigTemplateItem.cs (91%) rename v2rayN/ServiceLib/Models/{ => Entities}/ProfileExItem.cs (86%) rename v2rayN/ServiceLib/Models/{ => Entities}/ProfileGroupItem.cs (93%) rename v2rayN/ServiceLib/Models/{ => Entities}/ProfileItem.cs (99%) rename v2rayN/ServiceLib/Models/{ => Entities}/ProtocolExtraItem.cs (97%) rename v2rayN/ServiceLib/Models/{ => Entities}/RoutingItem.cs (94%) rename v2rayN/ServiceLib/Models/{ => Entities}/RulesItem.cs (94%) rename v2rayN/ServiceLib/Models/{ => Entities}/ServerStatItem.cs (88%) rename v2rayN/ServiceLib/Models/{ => Entities}/SubItem.cs (94%) rename v2rayN/ServiceLib/Models/{ => Entities}/TransportExtraItem.cs (93%) diff --git a/v2rayN/ServiceLib.Tests/GlobalUsings.cs b/v2rayN/ServiceLib.Tests/GlobalUsings.cs new file mode 100644 index 00000000000..9d311324264 --- /dev/null +++ b/v2rayN/ServiceLib.Tests/GlobalUsings.cs @@ -0,0 +1,40 @@ +global using System.Collections.Concurrent; +global using System.Diagnostics; +global using System.Net; +global using System.Net.NetworkInformation; +global using System.Net.Sockets; +global using System.Reactive; +global using System.Reactive.Disposables; +global using System.Reactive.Linq; +global using System.Reflection; +global using System.Runtime.InteropServices; +global using System.Security.Cryptography; +global using System.Text; +global using System.Text.Encodings.Web; +global using System.Text.Json; +global using System.Text.Json.Nodes; +global using System.Text.Json.Serialization; +global using System.Text.RegularExpressions; +global using DynamicData; +global using DynamicData.Binding; +global using ReactiveUI; +global using ReactiveUI.Fody.Helpers; +global using ServiceLib.Base; +global using ServiceLib.Common; +global using ServiceLib.Enums; +global using ServiceLib.Events; +global using ServiceLib.Handler; +global using ServiceLib.Handler.Builder; +global using ServiceLib.Handler.Fmt; +global using ServiceLib.Handler.SysProxy; +global using ServiceLib.Helper; +global using ServiceLib.Manager; +global using ServiceLib.Models.CoreConfigs; +global using ServiceLib.Models.Configs; +global using ServiceLib.Models.Dto; +global using ServiceLib.Models.Entities; +global using ServiceLib.Resx; +global using ServiceLib.Services; +global using ServiceLib.Services.CoreConfig; +global using ServiceLib.Services.Statistics; +global using SQLite; diff --git a/v2rayN/ServiceLib/GlobalUsings.cs b/v2rayN/ServiceLib/GlobalUsings.cs index 4553cbc4141..9d311324264 100644 --- a/v2rayN/ServiceLib/GlobalUsings.cs +++ b/v2rayN/ServiceLib/GlobalUsings.cs @@ -29,7 +29,10 @@ global using ServiceLib.Handler.SysProxy; global using ServiceLib.Helper; global using ServiceLib.Manager; -global using ServiceLib.Models; +global using ServiceLib.Models.CoreConfigs; +global using ServiceLib.Models.Configs; +global using ServiceLib.Models.Dto; +global using ServiceLib.Models.Entities; global using ServiceLib.Resx; global using ServiceLib.Services; global using ServiceLib.Services.CoreConfig; diff --git a/v2rayN/ServiceLib/Manager/ClashApiManager.cs b/v2rayN/ServiceLib/Manager/ClashApiManager.cs index e34f838dacd..313060dbeb4 100644 --- a/v2rayN/ServiceLib/Manager/ClashApiManager.cs +++ b/v2rayN/ServiceLib/Manager/ClashApiManager.cs @@ -1,4 +1,4 @@ -using static ServiceLib.Models.ClashProxies; +using static ServiceLib.Models.Dto.ClashProxies; namespace ServiceLib.Manager; diff --git a/v2rayN/ServiceLib/Models/Config.cs b/v2rayN/ServiceLib/Models/Configs/Config.cs similarity index 97% rename from v2rayN/ServiceLib/Models/Config.cs rename to v2rayN/ServiceLib/Models/Configs/Config.cs index 738ee286202..69770d3cb1d 100644 --- a/v2rayN/ServiceLib/Models/Config.cs +++ b/v2rayN/ServiceLib/Models/Configs/Config.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models; +namespace ServiceLib.Models.Configs; [Serializable] public class Config diff --git a/v2rayN/ServiceLib/Models/ConfigItems.cs b/v2rayN/ServiceLib/Models/Configs/ConfigItems.cs similarity index 99% rename from v2rayN/ServiceLib/Models/ConfigItems.cs rename to v2rayN/ServiceLib/Models/Configs/ConfigItems.cs index b23a8fc3594..e9e7f5f8577 100644 --- a/v2rayN/ServiceLib/Models/ConfigItems.cs +++ b/v2rayN/ServiceLib/Models/Configs/ConfigItems.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models; +namespace ServiceLib.Models.Configs; [Serializable] public class CoreBasicItem diff --git a/v2rayN/ServiceLib/Models/CoreConfigContext.cs b/v2rayN/ServiceLib/Models/CoreConfigs/CoreConfigContext.cs similarity index 95% rename from v2rayN/ServiceLib/Models/CoreConfigContext.cs rename to v2rayN/ServiceLib/Models/CoreConfigs/CoreConfigContext.cs index 4b64efca867..e1100868d86 100644 --- a/v2rayN/ServiceLib/Models/CoreConfigContext.cs +++ b/v2rayN/ServiceLib/Models/CoreConfigs/CoreConfigContext.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models; +namespace ServiceLib.Models.CoreConfigs; public record CoreConfigContext { diff --git a/v2rayN/ServiceLib/Models/CoreInfo.cs b/v2rayN/ServiceLib/Models/CoreConfigs/CoreInfo.cs similarity index 95% rename from v2rayN/ServiceLib/Models/CoreInfo.cs rename to v2rayN/ServiceLib/Models/CoreConfigs/CoreInfo.cs index 087f57fe041..dc55db91840 100644 --- a/v2rayN/ServiceLib/Models/CoreInfo.cs +++ b/v2rayN/ServiceLib/Models/CoreConfigs/CoreInfo.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models; +namespace ServiceLib.Models.CoreConfigs; [Serializable] public class CoreInfo diff --git a/v2rayN/ServiceLib/Models/SingboxConfig.cs b/v2rayN/ServiceLib/Models/CoreConfigs/SingboxConfig.cs similarity index 99% rename from v2rayN/ServiceLib/Models/SingboxConfig.cs rename to v2rayN/ServiceLib/Models/CoreConfigs/SingboxConfig.cs index 0e2bb530dcc..1514cae4524 100644 --- a/v2rayN/ServiceLib/Models/SingboxConfig.cs +++ b/v2rayN/ServiceLib/Models/CoreConfigs/SingboxConfig.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models; +namespace ServiceLib.Models.CoreConfigs; public class SingboxConfig { diff --git a/v2rayN/ServiceLib/Models/V2rayConfig.cs b/v2rayN/ServiceLib/Models/CoreConfigs/V2rayConfig.cs similarity index 99% rename from v2rayN/ServiceLib/Models/V2rayConfig.cs rename to v2rayN/ServiceLib/Models/CoreConfigs/V2rayConfig.cs index 10420dade79..4daac3c68f2 100644 --- a/v2rayN/ServiceLib/Models/V2rayConfig.cs +++ b/v2rayN/ServiceLib/Models/CoreConfigs/V2rayConfig.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models; +namespace ServiceLib.Models.CoreConfigs; public class V2rayConfig { diff --git a/v2rayN/ServiceLib/Models/V2rayMetricsVars.cs b/v2rayN/ServiceLib/Models/CoreConfigs/V2rayMetricsVars.cs similarity index 88% rename from v2rayN/ServiceLib/Models/V2rayMetricsVars.cs rename to v2rayN/ServiceLib/Models/CoreConfigs/V2rayMetricsVars.cs index cc8d64bd9c6..ed963f42814 100644 --- a/v2rayN/ServiceLib/Models/V2rayMetricsVars.cs +++ b/v2rayN/ServiceLib/Models/CoreConfigs/V2rayMetricsVars.cs @@ -1,6 +1,6 @@ using System.Collections; -namespace ServiceLib.Models; +namespace ServiceLib.Models.CoreConfigs; internal class V2rayMetricsVars { diff --git a/v2rayN/ServiceLib/Models/V2rayTcpRequest.cs b/v2rayN/ServiceLib/Models/CoreConfigs/V2rayTcpRequest.cs similarity index 85% rename from v2rayN/ServiceLib/Models/V2rayTcpRequest.cs rename to v2rayN/ServiceLib/Models/CoreConfigs/V2rayTcpRequest.cs index c08284b45f6..7b231a1385f 100644 --- a/v2rayN/ServiceLib/Models/V2rayTcpRequest.cs +++ b/v2rayN/ServiceLib/Models/CoreConfigs/V2rayTcpRequest.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models; +namespace ServiceLib.Models.CoreConfigs; public class V2rayTcpRequest { diff --git a/v2rayN/ServiceLib/Models/CheckUpdateModel.cs b/v2rayN/ServiceLib/Models/Dto/CheckUpdateModel.cs similarity index 89% rename from v2rayN/ServiceLib/Models/CheckUpdateModel.cs rename to v2rayN/ServiceLib/Models/Dto/CheckUpdateModel.cs index 2707cc6e4ce..8ccb8a39d47 100644 --- a/v2rayN/ServiceLib/Models/CheckUpdateModel.cs +++ b/v2rayN/ServiceLib/Models/Dto/CheckUpdateModel.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models; +namespace ServiceLib.Models.Dto; public class CheckUpdateModel : ReactiveObject { diff --git a/v2rayN/ServiceLib/Models/ClashConnectionModel.cs b/v2rayN/ServiceLib/Models/Dto/ClashConnectionModel.cs similarity index 93% rename from v2rayN/ServiceLib/Models/ClashConnectionModel.cs rename to v2rayN/ServiceLib/Models/Dto/ClashConnectionModel.cs index 124118520e6..943f1fd66cf 100644 --- a/v2rayN/ServiceLib/Models/ClashConnectionModel.cs +++ b/v2rayN/ServiceLib/Models/Dto/ClashConnectionModel.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models; +namespace ServiceLib.Models.Dto; public class ClashConnectionModel { diff --git a/v2rayN/ServiceLib/Models/ClashConnections.cs b/v2rayN/ServiceLib/Models/Dto/ClashConnections.cs similarity index 97% rename from v2rayN/ServiceLib/Models/ClashConnections.cs rename to v2rayN/ServiceLib/Models/Dto/ClashConnections.cs index 7ac2bbd2b64..236e2668d81 100644 --- a/v2rayN/ServiceLib/Models/ClashConnections.cs +++ b/v2rayN/ServiceLib/Models/Dto/ClashConnections.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models; +namespace ServiceLib.Models.Dto; public class ClashConnections { diff --git a/v2rayN/ServiceLib/Models/ClashProviders.cs b/v2rayN/ServiceLib/Models/Dto/ClashProviders.cs similarity index 80% rename from v2rayN/ServiceLib/Models/ClashProviders.cs rename to v2rayN/ServiceLib/Models/Dto/ClashProviders.cs index 402add5d0e8..830409062ed 100644 --- a/v2rayN/ServiceLib/Models/ClashProviders.cs +++ b/v2rayN/ServiceLib/Models/Dto/ClashProviders.cs @@ -1,6 +1,6 @@ -using static ServiceLib.Models.ClashProxies; +using static ServiceLib.Models.Dto.ClashProxies; -namespace ServiceLib.Models; +namespace ServiceLib.Models.Dto; public class ClashProviders { diff --git a/v2rayN/ServiceLib/Models/ClashProxies.cs b/v2rayN/ServiceLib/Models/Dto/ClashProxies.cs similarity index 94% rename from v2rayN/ServiceLib/Models/ClashProxies.cs rename to v2rayN/ServiceLib/Models/Dto/ClashProxies.cs index 97028b7086f..94986e50297 100644 --- a/v2rayN/ServiceLib/Models/ClashProxies.cs +++ b/v2rayN/ServiceLib/Models/Dto/ClashProxies.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models; +namespace ServiceLib.Models.Dto; public class ClashProxies { diff --git a/v2rayN/ServiceLib/Models/ClashProxyModel.cs b/v2rayN/ServiceLib/Models/Dto/ClashProxyModel.cs similarity index 90% rename from v2rayN/ServiceLib/Models/ClashProxyModel.cs rename to v2rayN/ServiceLib/Models/Dto/ClashProxyModel.cs index 10d68e14b90..5e460d9fb80 100644 --- a/v2rayN/ServiceLib/Models/ClashProxyModel.cs +++ b/v2rayN/ServiceLib/Models/Dto/ClashProxyModel.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models; +namespace ServiceLib.Models.Dto; [Serializable] public class ClashProxyModel : ReactiveObject diff --git a/v2rayN/ServiceLib/Models/CmdItem.cs b/v2rayN/ServiceLib/Models/Dto/CmdItem.cs similarity index 77% rename from v2rayN/ServiceLib/Models/CmdItem.cs rename to v2rayN/ServiceLib/Models/Dto/CmdItem.cs index a660208e739..7b9813af4a0 100644 --- a/v2rayN/ServiceLib/Models/CmdItem.cs +++ b/v2rayN/ServiceLib/Models/Dto/CmdItem.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models; +namespace ServiceLib.Models.Dto; public class CmdItem { diff --git a/v2rayN/ServiceLib/Models/ComboItem.cs b/v2rayN/ServiceLib/Models/Dto/ComboItem.cs similarity index 80% rename from v2rayN/ServiceLib/Models/ComboItem.cs rename to v2rayN/ServiceLib/Models/Dto/ComboItem.cs index c092f437f71..fec6fd9d89f 100644 --- a/v2rayN/ServiceLib/Models/ComboItem.cs +++ b/v2rayN/ServiceLib/Models/Dto/ComboItem.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models; +namespace ServiceLib.Models.Dto; public class ComboItem { diff --git a/v2rayN/ServiceLib/Models/GitHubRelease.cs b/v2rayN/ServiceLib/Models/Dto/GitHubRelease.cs similarity index 98% rename from v2rayN/ServiceLib/Models/GitHubRelease.cs rename to v2rayN/ServiceLib/Models/Dto/GitHubRelease.cs index f6549467385..ed2f48c8c8c 100644 --- a/v2rayN/ServiceLib/Models/GitHubRelease.cs +++ b/v2rayN/ServiceLib/Models/Dto/GitHubRelease.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models; +namespace ServiceLib.Models.Dto; public class GitHubReleaseAsset { diff --git a/v2rayN/ServiceLib/Models/IPAPIInfo.cs b/v2rayN/ServiceLib/Models/Dto/IPAPIInfo.cs similarity index 93% rename from v2rayN/ServiceLib/Models/IPAPIInfo.cs rename to v2rayN/ServiceLib/Models/Dto/IPAPIInfo.cs index 86cfe1112e0..e1e14363fbb 100644 --- a/v2rayN/ServiceLib/Models/IPAPIInfo.cs +++ b/v2rayN/ServiceLib/Models/Dto/IPAPIInfo.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models; +namespace ServiceLib.Models.Dto; internal class IPAPIInfo { diff --git a/v2rayN/ServiceLib/Models/ProfileItemModel.cs b/v2rayN/ServiceLib/Models/Dto/ProfileItemModel.cs similarity index 97% rename from v2rayN/ServiceLib/Models/ProfileItemModel.cs rename to v2rayN/ServiceLib/Models/Dto/ProfileItemModel.cs index 53170f174dd..b75835a4fea 100644 --- a/v2rayN/ServiceLib/Models/ProfileItemModel.cs +++ b/v2rayN/ServiceLib/Models/Dto/ProfileItemModel.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models; +namespace ServiceLib.Models.Dto; [Serializable] public class ProfileItemModel : ReactiveObject diff --git a/v2rayN/ServiceLib/Models/RetResult.cs b/v2rayN/ServiceLib/Models/Dto/RetResult.cs similarity index 93% rename from v2rayN/ServiceLib/Models/RetResult.cs rename to v2rayN/ServiceLib/Models/Dto/RetResult.cs index 688eca3e0f5..3d6c9345311 100644 --- a/v2rayN/ServiceLib/Models/RetResult.cs +++ b/v2rayN/ServiceLib/Models/Dto/RetResult.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models; +namespace ServiceLib.Models.Dto; public class RetResult { diff --git a/v2rayN/ServiceLib/Models/RoutingItemModel.cs b/v2rayN/ServiceLib/Models/Dto/RoutingItemModel.cs similarity index 65% rename from v2rayN/ServiceLib/Models/RoutingItemModel.cs rename to v2rayN/ServiceLib/Models/Dto/RoutingItemModel.cs index 2326f85bf10..2abde9241ed 100644 --- a/v2rayN/ServiceLib/Models/RoutingItemModel.cs +++ b/v2rayN/ServiceLib/Models/Dto/RoutingItemModel.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models; +namespace ServiceLib.Models.Dto; [Serializable] public class RoutingItemModel : RoutingItem diff --git a/v2rayN/ServiceLib/Models/RoutingTemplate.cs b/v2rayN/ServiceLib/Models/Dto/RoutingTemplate.cs similarity index 81% rename from v2rayN/ServiceLib/Models/RoutingTemplate.cs rename to v2rayN/ServiceLib/Models/Dto/RoutingTemplate.cs index 0cacc1bbe27..0d3fd808e61 100644 --- a/v2rayN/ServiceLib/Models/RoutingTemplate.cs +++ b/v2rayN/ServiceLib/Models/Dto/RoutingTemplate.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models; +namespace ServiceLib.Models.Dto; [Serializable] public class RoutingTemplate diff --git a/v2rayN/ServiceLib/Models/RulesItemModel.cs b/v2rayN/ServiceLib/Models/Dto/RulesItemModel.cs similarity index 89% rename from v2rayN/ServiceLib/Models/RulesItemModel.cs rename to v2rayN/ServiceLib/Models/Dto/RulesItemModel.cs index f3eda16bd11..b056f47c753 100644 --- a/v2rayN/ServiceLib/Models/RulesItemModel.cs +++ b/v2rayN/ServiceLib/Models/Dto/RulesItemModel.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models; +namespace ServiceLib.Models.Dto; [Serializable] public class RulesItemModel : RulesItem diff --git a/v2rayN/ServiceLib/Models/SemanticVersion.cs b/v2rayN/ServiceLib/Models/Dto/SemanticVersion.cs similarity index 99% rename from v2rayN/ServiceLib/Models/SemanticVersion.cs rename to v2rayN/ServiceLib/Models/Dto/SemanticVersion.cs index 78463434b6d..1e66353c07f 100644 --- a/v2rayN/ServiceLib/Models/SemanticVersion.cs +++ b/v2rayN/ServiceLib/Models/Dto/SemanticVersion.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models; +namespace ServiceLib.Models.Dto; public class SemanticVersion { diff --git a/v2rayN/ServiceLib/Models/ServerSpeedItem.cs b/v2rayN/ServiceLib/Models/Dto/ServerSpeedItem.cs similarity index 91% rename from v2rayN/ServiceLib/Models/ServerSpeedItem.cs rename to v2rayN/ServiceLib/Models/Dto/ServerSpeedItem.cs index 0a859af6fef..3d9e75624bf 100644 --- a/v2rayN/ServiceLib/Models/ServerSpeedItem.cs +++ b/v2rayN/ServiceLib/Models/Dto/ServerSpeedItem.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models; +namespace ServiceLib.Models.Dto; [Serializable] public class ServerSpeedItem : ServerStatItem diff --git a/v2rayN/ServiceLib/Models/ServerTestItem.cs b/v2rayN/ServiceLib/Models/Dto/ServerTestItem.cs similarity index 91% rename from v2rayN/ServiceLib/Models/ServerTestItem.cs rename to v2rayN/ServiceLib/Models/Dto/ServerTestItem.cs index 00e26b83c18..66d3325545d 100644 --- a/v2rayN/ServiceLib/Models/ServerTestItem.cs +++ b/v2rayN/ServiceLib/Models/Dto/ServerTestItem.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models; +namespace ServiceLib.Models.Dto; [Serializable] public class ServerTestItem diff --git a/v2rayN/ServiceLib/Models/SpeedTestResult.cs b/v2rayN/ServiceLib/Models/Dto/SpeedTestResult.cs similarity index 83% rename from v2rayN/ServiceLib/Models/SpeedTestResult.cs rename to v2rayN/ServiceLib/Models/Dto/SpeedTestResult.cs index 6e0ce70ffa4..bac7bf0f90d 100644 --- a/v2rayN/ServiceLib/Models/SpeedTestResult.cs +++ b/v2rayN/ServiceLib/Models/Dto/SpeedTestResult.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models; +namespace ServiceLib.Models.Dto; [Serializable] public class SpeedTestResult diff --git a/v2rayN/ServiceLib/Models/SsSIP008.cs b/v2rayN/ServiceLib/Models/Dto/SsSIP008.cs similarity index 91% rename from v2rayN/ServiceLib/Models/SsSIP008.cs rename to v2rayN/ServiceLib/Models/Dto/SsSIP008.cs index 66077471447..d6f05faf205 100644 --- a/v2rayN/ServiceLib/Models/SsSIP008.cs +++ b/v2rayN/ServiceLib/Models/Dto/SsSIP008.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models; +namespace ServiceLib.Models.Dto; public class SsSIP008 { diff --git a/v2rayN/ServiceLib/Models/UpdateResult.cs b/v2rayN/ServiceLib/Models/Dto/UpdateResult.cs similarity index 92% rename from v2rayN/ServiceLib/Models/UpdateResult.cs rename to v2rayN/ServiceLib/Models/Dto/UpdateResult.cs index d8f18dd4211..42a3b352f4f 100644 --- a/v2rayN/ServiceLib/Models/UpdateResult.cs +++ b/v2rayN/ServiceLib/Models/Dto/UpdateResult.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models; +namespace ServiceLib.Models.Dto; public class UpdateResult { diff --git a/v2rayN/ServiceLib/Models/VmessQRCode.cs b/v2rayN/ServiceLib/Models/Dto/VmessQRCode.cs similarity index 97% rename from v2rayN/ServiceLib/Models/VmessQRCode.cs rename to v2rayN/ServiceLib/Models/Dto/VmessQRCode.cs index f182c3283c4..c259cf77478 100644 --- a/v2rayN/ServiceLib/Models/VmessQRCode.cs +++ b/v2rayN/ServiceLib/Models/Dto/VmessQRCode.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models; +namespace ServiceLib.Models.Dto; /// /// https://github.com/2dust/v2rayN/wiki/ diff --git a/v2rayN/ServiceLib/Models/DNSItem.cs b/v2rayN/ServiceLib/Models/Entities/DNSItem.cs similarity index 92% rename from v2rayN/ServiceLib/Models/DNSItem.cs rename to v2rayN/ServiceLib/Models/Entities/DNSItem.cs index 2dea42d0c39..4bb4f65aa25 100644 --- a/v2rayN/ServiceLib/Models/DNSItem.cs +++ b/v2rayN/ServiceLib/Models/Entities/DNSItem.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models; +namespace ServiceLib.Models.Entities; [Serializable] public class DNSItem diff --git a/v2rayN/ServiceLib/Models/FullConfigTemplateItem.cs b/v2rayN/ServiceLib/Models/Entities/FullConfigTemplateItem.cs similarity index 91% rename from v2rayN/ServiceLib/Models/FullConfigTemplateItem.cs rename to v2rayN/ServiceLib/Models/Entities/FullConfigTemplateItem.cs index b3e3b14e574..c51aa55e03f 100644 --- a/v2rayN/ServiceLib/Models/FullConfigTemplateItem.cs +++ b/v2rayN/ServiceLib/Models/Entities/FullConfigTemplateItem.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models; +namespace ServiceLib.Models.Entities; [Serializable] public class FullConfigTemplateItem diff --git a/v2rayN/ServiceLib/Models/ProfileExItem.cs b/v2rayN/ServiceLib/Models/Entities/ProfileExItem.cs similarity index 86% rename from v2rayN/ServiceLib/Models/ProfileExItem.cs rename to v2rayN/ServiceLib/Models/Entities/ProfileExItem.cs index 33b20c57c64..7d2cc7895c2 100644 --- a/v2rayN/ServiceLib/Models/ProfileExItem.cs +++ b/v2rayN/ServiceLib/Models/Entities/ProfileExItem.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models; +namespace ServiceLib.Models.Entities; [Serializable] public class ProfileExItem diff --git a/v2rayN/ServiceLib/Models/ProfileGroupItem.cs b/v2rayN/ServiceLib/Models/Entities/ProfileGroupItem.cs similarity index 93% rename from v2rayN/ServiceLib/Models/ProfileGroupItem.cs rename to v2rayN/ServiceLib/Models/Entities/ProfileGroupItem.cs index 94a9aad2d8f..6a878a5061c 100644 --- a/v2rayN/ServiceLib/Models/ProfileGroupItem.cs +++ b/v2rayN/ServiceLib/Models/Entities/ProfileGroupItem.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models; +namespace ServiceLib.Models.Entities; [Obsolete("Use ProtocolExtraItem instead.")] [Serializable] diff --git a/v2rayN/ServiceLib/Models/ProfileItem.cs b/v2rayN/ServiceLib/Models/Entities/ProfileItem.cs similarity index 99% rename from v2rayN/ServiceLib/Models/ProfileItem.cs rename to v2rayN/ServiceLib/Models/Entities/ProfileItem.cs index ae5f77adafa..cb5deabdcfc 100644 --- a/v2rayN/ServiceLib/Models/ProfileItem.cs +++ b/v2rayN/ServiceLib/Models/Entities/ProfileItem.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models; +namespace ServiceLib.Models.Entities; [Serializable] public class ProfileItem diff --git a/v2rayN/ServiceLib/Models/ProtocolExtraItem.cs b/v2rayN/ServiceLib/Models/Entities/ProtocolExtraItem.cs similarity index 97% rename from v2rayN/ServiceLib/Models/ProtocolExtraItem.cs rename to v2rayN/ServiceLib/Models/Entities/ProtocolExtraItem.cs index 03403f5b85d..e9916e33866 100644 --- a/v2rayN/ServiceLib/Models/ProtocolExtraItem.cs +++ b/v2rayN/ServiceLib/Models/Entities/ProtocolExtraItem.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models; +namespace ServiceLib.Models.Entities; public record ProtocolExtraItem { diff --git a/v2rayN/ServiceLib/Models/RoutingItem.cs b/v2rayN/ServiceLib/Models/Entities/RoutingItem.cs similarity index 94% rename from v2rayN/ServiceLib/Models/RoutingItem.cs rename to v2rayN/ServiceLib/Models/Entities/RoutingItem.cs index ddd27a9b183..fae611e7024 100644 --- a/v2rayN/ServiceLib/Models/RoutingItem.cs +++ b/v2rayN/ServiceLib/Models/Entities/RoutingItem.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models; +namespace ServiceLib.Models.Entities; [Serializable] public class RoutingItem diff --git a/v2rayN/ServiceLib/Models/RulesItem.cs b/v2rayN/ServiceLib/Models/Entities/RulesItem.cs similarity index 94% rename from v2rayN/ServiceLib/Models/RulesItem.cs rename to v2rayN/ServiceLib/Models/Entities/RulesItem.cs index 5a5cf52956d..5c7c07d8ce4 100644 --- a/v2rayN/ServiceLib/Models/RulesItem.cs +++ b/v2rayN/ServiceLib/Models/Entities/RulesItem.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models; +namespace ServiceLib.Models.Entities; [Serializable] public class RulesItem diff --git a/v2rayN/ServiceLib/Models/ServerStatItem.cs b/v2rayN/ServiceLib/Models/Entities/ServerStatItem.cs similarity index 88% rename from v2rayN/ServiceLib/Models/ServerStatItem.cs rename to v2rayN/ServiceLib/Models/Entities/ServerStatItem.cs index 05cd1ee60fd..a693fa4e1eb 100644 --- a/v2rayN/ServiceLib/Models/ServerStatItem.cs +++ b/v2rayN/ServiceLib/Models/Entities/ServerStatItem.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models; +namespace ServiceLib.Models.Entities; [Serializable] public class ServerStatItem diff --git a/v2rayN/ServiceLib/Models/SubItem.cs b/v2rayN/ServiceLib/Models/Entities/SubItem.cs similarity index 94% rename from v2rayN/ServiceLib/Models/SubItem.cs rename to v2rayN/ServiceLib/Models/Entities/SubItem.cs index 612ec15b637..a66eb4ce9ee 100644 --- a/v2rayN/ServiceLib/Models/SubItem.cs +++ b/v2rayN/ServiceLib/Models/Entities/SubItem.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models; +namespace ServiceLib.Models.Entities; [Serializable] public class SubItem diff --git a/v2rayN/ServiceLib/Models/TransportExtraItem.cs b/v2rayN/ServiceLib/Models/Entities/TransportExtraItem.cs similarity index 93% rename from v2rayN/ServiceLib/Models/TransportExtraItem.cs rename to v2rayN/ServiceLib/Models/Entities/TransportExtraItem.cs index 77fbc984773..b454f0228c6 100644 --- a/v2rayN/ServiceLib/Models/TransportExtraItem.cs +++ b/v2rayN/ServiceLib/Models/Entities/TransportExtraItem.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Models; +namespace ServiceLib.Models.Entities; public record TransportExtraItem { diff --git a/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs b/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs index 6220719b39d..7da8ad42321 100644 --- a/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs @@ -1,6 +1,6 @@ using System.Reactive.Concurrency; -using static ServiceLib.Models.ClashProviders; -using static ServiceLib.Models.ClashProxies; +using static ServiceLib.Models.Dto.ClashProviders; +using static ServiceLib.Models.Dto.ClashProxies; namespace ServiceLib.ViewModels; diff --git a/v2rayN/v2rayN.Desktop/GlobalUsings.cs b/v2rayN/v2rayN.Desktop/GlobalUsings.cs index 5b0b215876d..9c28c767011 100644 --- a/v2rayN/v2rayN.Desktop/GlobalUsings.cs +++ b/v2rayN/v2rayN.Desktop/GlobalUsings.cs @@ -30,6 +30,9 @@ global using ServiceLib.Events; global using ServiceLib.Handler; global using ServiceLib.Manager; -global using ServiceLib.Models; +global using ServiceLib.Models.CoreConfigs; +global using ServiceLib.Models.Configs; +global using ServiceLib.Models.Dto; +global using ServiceLib.Models.Entities; global using ServiceLib.Resx; global using ServiceLib.ViewModels; diff --git a/v2rayN/v2rayN/GlobalUsings.cs b/v2rayN/v2rayN/GlobalUsings.cs index fb63f7ebdf8..5bd45390c7b 100644 --- a/v2rayN/v2rayN/GlobalUsings.cs +++ b/v2rayN/v2rayN/GlobalUsings.cs @@ -29,7 +29,10 @@ global using ServiceLib.Events; global using ServiceLib.Handler; global using ServiceLib.Manager; -global using ServiceLib.Models; +global using ServiceLib.Models.CoreConfigs; +global using ServiceLib.Models.Configs; +global using ServiceLib.Models.Dto; +global using ServiceLib.Models.Entities; global using ServiceLib.Resx; global using ServiceLib.ViewModels; global using v2rayN.Common; From cc57f952db24eeba08bc5f50c3e50e0acc3f7fd9 Mon Sep 17 00:00:00 2001 From: DHR60 Date: Mon, 11 May 2026 08:35:26 +0000 Subject: [PATCH 03/61] Update dotnet to 10 (#9179) --- .github/workflows/build.yml | 2 +- package-debian.sh | 10 +++++----- package-rhel-riscv.sh | 2 +- package-rhel.sh | 8 ++++---- v2rayN/Directory.Build.props | 2 +- v2rayN/v2rayN/v2rayN.csproj | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 838a99ec0a1..1e8a7f060aa 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -54,7 +54,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v5.2.0 with: - dotnet-version: '8.0.x' + dotnet-version: '10.0.x' - name: Build v2rayN working-directory: ./v2rayN diff --git a/package-debian.sh b/package-debian.sh index 32e9e6201d6..4515fe6fd66 100644 --- a/package-debian.sh +++ b/package-debian.sh @@ -88,10 +88,10 @@ if command -v apt-get >/dev/null 2>&1; then libc6:arm64 libgcc-s1:arm64 libstdc++6:arm64 zlib1g:arm64 libfontconfig1:arm64 fi - # Install .NET SDK 8 via official script + # Install .NET SDK 10 via official script wget -q https://dot.net/v1/dotnet-install.sh chmod +x dotnet-install.sh - ./dotnet-install.sh --channel 8.0 --install-dir "$HOME/.dotnet" + ./dotnet-install.sh --channel 10.0 --install-dir "$HOME/.dotnet" export PATH="$HOME/.dotnet:$PATH" export DOTNET_ROOT="$HOME/.dotnet" @@ -101,7 +101,7 @@ fi if [[ "$install_ok" -ne 1 ]]; then echo "Could not auto-install dependencies for '$ID'. Make sure these are available:" - echo "dotnet-sdk 8.x, curl, unzip, tar, rsync, git, dpkg-deb, desktop-file-utils, xdg-utils" + echo "dotnet-sdk 10.x, curl, unzip, tar, rsync, git, dpkg-deb, desktop-file-utils, xdg-utils" exit 1 fi @@ -389,7 +389,7 @@ build_for_arch() { echo "[*] Building for target: $short (RID=$rid, DEB arch=$deb_arch)" dotnet clean "$PROJECT" -c Release - rm -rf "$(dirname "$PROJECT")/bin/Release/net8.0" || true + rm -rf "$(dirname "$PROJECT")/bin/Release/net10.0" || true dotnet restore "$PROJECT" dotnet publish "$PROJECT" \ @@ -399,7 +399,7 @@ build_for_arch() { local RID_DIR="$rid" local PUBDIR - PUBDIR="$(dirname "$PROJECT")/bin/Release/net8.0/${RID_DIR}/publish" + PUBDIR="$(dirname "$PROJECT")/bin/Release/net10.0/${RID_DIR}/publish" [[ -d "$PUBDIR" ]] || { echo "Publish directory not found: $PUBDIR"; return 1; } local WORKDIR PKGROOT STAGE DEBIAN_DIR diff --git a/package-rhel-riscv.sh b/package-rhel-riscv.sh index ef22934c383..9136238fb77 100644 --- a/package-rhel-riscv.sh +++ b/package-rhel-riscv.sh @@ -69,7 +69,7 @@ if [[ -n "${VERSION_ARG:-}" && -n "${BUILD_FROM:-}" ]]; then fi apply_riscv_patch() { - # Upgrade net8.0 -> net10.0 + # Ensure all project files target net10.0 find . -type f \( -name "*.csproj" -o -name "*.props" -o -name "*.targets" \) \ -exec sed -i 's/net8\.0/net10.0/g' {} + diff --git a/package-rhel.sh b/package-rhel.sh index 310a7ab9625..753e889fb76 100644 --- a/package-rhel.sh +++ b/package-rhel.sh @@ -71,13 +71,13 @@ host_arch="$(uname -m)" install_ok=0 if command -v dnf >/dev/null 2>&1; then - sudo dnf -y install rpm-build rpmdevtools curl unzip tar jq rsync dotnet-sdk-8.0 \ + sudo dnf -y install rpm-build rpmdevtools curl unzip tar jq rsync dotnet-sdk-10.0 \ && install_ok=1 fi if [[ "$install_ok" -ne 1 ]]; then echo "Could not auto-install dependencies for '$ID'. Make sure these are available:" - echo "dotnet-sdk 8.x, curl, unzip, tar, rsync, rpm, rpmdevtools, rpm-build (on Red Hat branch)" + echo "dotnet-sdk 10.x, curl, unzip, tar, rsync, rpm, rpmdevtools, rpm-build (on Red Hat branch)" fi # Root directory @@ -372,7 +372,7 @@ build_for_arch() { # .NET publish (self-contained) for this RID dotnet clean "$PROJECT" -c Release - rm -rf "$(dirname "$PROJECT")/bin/Release/net8.0" || true + rm -rf "$(dirname "$PROJECT")/bin/Release/net10.0" || true dotnet restore "$PROJECT" dotnet publish "$PROJECT" \ @@ -383,7 +383,7 @@ build_for_arch() { # Per-arch variables (scoped) local RID_DIR="$rid" local PUBDIR - PUBDIR="$(dirname "$PROJECT")/bin/Release/net8.0/${RID_DIR}/publish" + PUBDIR="$(dirname "$PROJECT")/bin/Release/net10.0/${RID_DIR}/publish" [[ -d "$PUBDIR" ]] || { echo "Publish directory not found: $PUBDIR"; return 1; } # Per-arch working area diff --git a/v2rayN/Directory.Build.props b/v2rayN/Directory.Build.props index 31465d57431..9711db8116f 100644 --- a/v2rayN/Directory.Build.props +++ b/v2rayN/Directory.Build.props @@ -5,7 +5,7 @@ - net8.0 + net10.0 true true CA1031;CS1591;NU1507;CA1416;IDE0058;IDE0053;IDE0200 diff --git a/v2rayN/v2rayN/v2rayN.csproj b/v2rayN/v2rayN/v2rayN.csproj index 4b3be3ebe70..871d294057f 100644 --- a/v2rayN/v2rayN/v2rayN.csproj +++ b/v2rayN/v2rayN/v2rayN.csproj @@ -2,7 +2,7 @@ WinExe - net8.0-windows10.0.19041.0 + net10.0-windows10.0.19041.0 true true Resources\v2rayN.ico From d1c9c0b53648498e47bc858be1a7b990a954c4f9 Mon Sep 17 00:00:00 2001 From: JieXu Date: Mon, 11 May 2026 17:56:35 +0800 Subject: [PATCH 04/61] Update .NET 10 (#9239) * Update dotnet to 10 * Update .NET version in build workflow * Update build-osx.yml * Update package-zip.yml * Update package-rhel.sh * Update print statement from 'Hello' to 'Goodbye' * Update package-rhel-riscv.sh * Create package-debian-riscv.sh * Update build-linux.yml * Create update-riscv-depand.yml * Update update-riscv-depand.yml * Update ServiceLib.csproj * Update Directory.Packages.props * Update UpdateService.cs * Update UpdateService.cs * Update Directory.Packages.props * Update ServiceLib.csproj * Replace SourceGear.sqlite3 with Repobot.SQLite.Unofficial * Replace SourceGear.sqlite3 with Repobot.SQLite.Unofficial * Update Repobot.SQLite.Unofficial version to 3.53.1.1 * Update package-zip.yml * Update build-osx.yml Adjust sleep duration to reduce race condition likelihood. * Update Directory.Packages.props * Update Directory.Packages.props * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: DHR60 Co-authored-by: xujie86 <167618598+xujie86@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- .github/workflows/build-linux.yml | 74 ++ .github/workflows/build-osx.yml | 2 +- .github/workflows/build.yml | 4 +- .github/workflows/package-zip.yml | 4 +- .github/workflows/update-riscv-depand.yml | 256 ++++++ package-debian-riscv.sh | 801 ++++++++++++++++++ package-debian.sh | 838 +++++++++++-------- package-rhel-riscv.sh | 858 +++++++++++--------- package-rhel.sh | 731 ++++++++++------- v2rayN/Directory.Packages.props | 6 +- v2rayN/ServiceLib/ServiceLib.csproj | 3 +- v2rayN/ServiceLib/Services/UpdateService.cs | 8 +- 12 files changed, 2518 insertions(+), 1067 deletions(-) create mode 100644 .github/workflows/update-riscv-depand.yml create mode 100644 package-debian-riscv.sh diff --git a/.github/workflows/build-linux.yml b/.github/workflows/build-linux.yml index fe3af4a9743..bb1c8a16939 100644 --- a/.github/workflows/build-linux.yml +++ b/.github/workflows/build-linux.yml @@ -251,3 +251,77 @@ jobs: --data-binary @"$f" \ "${upload_url}?name=${f##*/}" done + + deb-riscv64: + name: build and release deb riscv64 + if: | + (github.event_name == 'workflow_dispatch' && inputs.release_tag != '') || + (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')) + runs-on: ubuntu-24.04-riscv + container: debian:13 + env: + RELEASE_TAG: ${{ case(inputs.release_tag != '', inputs.release_tag, github.ref_name) }} + + steps: + - name: Prepare tools (Debian) + shell: bash + run: | + set -euo pipefail + export DEBIAN_FRONTEND=noninteractive + apt-get update + apt-get install -y sudo git rsync findutils tar gzip unzip which curl jq wget file \ + ca-certificates desktop-file-utils xdg-utils fakeroot dpkg-dev \ + gcc make libc6-dev libgcc-s1 libstdc++6 zlib1g libatomic1 + + - name: Checkout repo (for scripts) + shell: bash + env: + GITHUB_TOKEN: ${{ github.token }} + run: | + set -euo pipefail + rm -rf ./* + git init . + git config --global --add safe.directory "$PWD" + git remote add origin "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" + git fetch --depth=1 origin "${GITHUB_SHA}" + git checkout FETCH_HEAD + git submodule update --init --recursive + + - name: Ensure script permissions + run: chmod 755 package-debian-riscv.sh + + - name: Package DEB (Debian-family) + run: ./package-debian-riscv.sh "${RELEASE_TAG}" + + - name: Collect DEBs into workspace + run: | + mkdir -p "$GITHUB_WORKSPACE/dist/deb-riscv64" + rsync -av "$HOME/debbuild/" "$GITHUB_WORKSPACE/dist/deb-riscv64/" || true + find "$GITHUB_WORKSPACE/dist/deb-riscv64" -name "*.deb" \ + -exec mv {} "$GITHUB_WORKSPACE/dist/deb-riscv64/v2rayN-linux-riscv64.deb" \; || true + echo "==== Dist tree ====" + ls -R "$GITHUB_WORKSPACE/dist/deb-riscv64" || true + + - name: Upload DEBs to release + shell: bash + env: + GITHUB_TOKEN: ${{ github.token }} + run: | + set -euo pipefail + shopt -s globstar nullglob + + files=(dist/deb-riscv64/**/*.deb) + (( ${#files[@]} )) || { echo "No DEBs found."; exit 1; } + + api="${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases/tags/${RELEASE_TAG}" + upload_url="$(curl -fsSL -H "Authorization: Bearer ${GITHUB_TOKEN}" "$api" | jq -r '.upload_url // empty' | sed 's/{?name,label}//')" + [[ "$upload_url" ]] || { echo "Release upload URL not found: ${RELEASE_TAG}"; exit 1; } + + for f in "${files[@]}"; do + echo "Uploading ${f##*/}" + curl -fsSL -X POST \ + -H "Authorization: Bearer ${GITHUB_TOKEN}" \ + -H "Content-Type: application/vnd.debian.binary-package" \ + --data-binary @"$f" \ + "${upload_url}?name=${f##*/}" + done diff --git a/.github/workflows/build-osx.yml b/.github/workflows/build-osx.yml index 3db6f621da3..ddb541cb1b7 100644 --- a/.github/workflows/build-osx.yml +++ b/.github/workflows/build-osx.yml @@ -63,7 +63,7 @@ jobs: run: ./package-osx.sh macos-$Arch v2rayN-macos-$Arch ${{ inputs.release_tag }} - name: Sleep for race condition between matrix jobs - run: sleep $(awk 'BEGIN { srand(); printf "%.3f", rand()*2 }') + run: sleep "$(od -An -N2 -tu2 /dev/urandom | awk 'NR==1{printf "%.2f", $1/5461}')" - name: Upload dmg to release uses: svenstaro/upload-release-action@v2 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1e8a7f060aa..f51965cbc86 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -54,7 +54,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v5.2.0 with: - dotnet-version: '10.0.x' + dotnet-version: '10.0.1xx' - name: Build v2rayN working-directory: ./v2rayN @@ -68,4 +68,4 @@ jobs: uses: actions/upload-artifact@v7.0.1 with: name: ${{ matrix.arch }} - path: ${{ matrix.arch }} + path: ${{ matrix.arch }} \ No newline at end of file diff --git a/.github/workflows/package-zip.yml b/.github/workflows/package-zip.yml index d724841a459..d55c6837d3a 100644 --- a/.github/workflows/package-zip.yml +++ b/.github/workflows/package-zip.yml @@ -56,8 +56,8 @@ jobs: run: mv "v2rayN-$Target-$Arch.zip" "v2rayN-$Target-$Arch-desktop.zip" - name: Sleep for race condition between matrix jobs - run: sleep $(awk 'BEGIN { srand(); printf "%.3f", rand()*2 }') - + run: sleep "$(od -An -N2 -tu2 /dev/urandom | awk 'NR==1{printf "%.2f", $1/5461}')" + - name: Upload zip archive to release uses: svenstaro/upload-release-action@v2 with: diff --git a/.github/workflows/update-riscv-depand.yml b/.github/workflows/update-riscv-depand.yml new file mode 100644 index 00000000000..87600913268 --- /dev/null +++ b/.github/workflows/update-riscv-depand.yml @@ -0,0 +1,256 @@ +name: update riscv dependent versions + +on: + workflow_dispatch: + push: + branches: + - master + +permissions: + contents: write + +concurrency: + group: update-riscv-dependent + cancel-in-progress: false + +jobs: + update: + runs-on: ubuntu-24.04 + + steps: + - uses: actions/checkout@v5 + + - uses: actions/setup-dotnet@v5 + with: + dotnet-version: 10.0.1xx + + - run: sudo apt-get update && sudo apt-get install -y jq + + - name: resolve + id: resolve + shell: bash + run: | + set -euo pipefail + + TARGET_FILES=( + package-rhel-riscv.sh + package-debian-riscv.sh + ) + + echo "==> restore projects" + find . -name '*.csproj' | while read -r p; do + if grep -q '.*-windows' "$p"; then + echo "[skip] $p" + else + echo "[restore] $p" + dotnet restore "$p" -p:EnableWindowsTargeting=true || true + fi + done + + echo "==> collect assets" + mapfile -t ASSETS < <(find . -path '*/obj/project.assets.json') + printf ' %s\n' "${ASSETS[@]}" + + ALL_LIBS=() + for f in "${ASSETS[@]}"; do + mapfile -t libs < <(jq -r '.libraries | keys[]' "$f") + ALL_LIBS+=("${libs[@]}") + done + mapfile -t LIBS < <(printf '%s\n' "${ALL_LIBS[@]}" | sort -u) + + extract() { + local name="$1" + for i in "${LIBS[@]}"; do + [[ "$i" == "$name/"* ]] && echo "${i#*/}" + done | sort -u + } + + norm_version() { echo "${1#v}"; } + is_preview() { [[ "$(norm_version "$1")" == *-* ]]; } + base_version() { local v; v="$(norm_version "$1")"; echo "${v%%-*}"; } + + key() { + local v core pre a b c p1 p2 p3 + v="$(norm_version "$1")" + core="${v%%-*}" + [[ "$v" == *-* ]] && pre="${v#*-}" || pre="" + + IFS='.' read -r a b c <<< "$core" + a=${a//[^0-9]/}; a=${a:-0} + b=${b//[^0-9]/}; b=${b:-0} + c=${c//[^0-9]/}; c=${c:-0} + + if [[ -z "$pre" ]]; then + printf "%05d.%05d.%05d.1\n" "$a" "$b" "$c" + else + pre="${pre#preview.}" + IFS='.' read -ra p <<< "$pre" + p1=${p[0]:-0}; p1=${p1//[^0-9]/}; p1=${p1:-0} + p2=${p[1]:-0}; p2=${p2//[^0-9]/}; p2=${p2:-0} + p3=${p[2]:-0}; p3=${p3//[^0-9]/}; p3=${p3:-0} + printf "%05d.%05d.%05d.0.%05d.%05d.%05d\n" \ + "$a" "$b" "$c" "$p1" "$p2" "$p3" + fi + } + + latest() { + local best="" best_key="" cur cur_key + for cur in "$@"; do + [[ -n "$cur" ]] || continue + cur_key="$(key "$cur")" + echo " candidate: $cur -> $cur_key" >&2 + if [[ -z "$best_key" || "$cur_key" > "$best_key" ]]; then + best="$cur" + best_key="$cur_key" + fi + done + echo "$best" + } + + log_mixed_versions() { + local name="$1"; shift + local versions=("$@") bases=() v b + mapfile -t bases < <( + for v in "${versions[@]}"; do + [[ -n "$v" ]] && base_version "$v" + done | sort -u + ) + + for b in "${bases[@]}"; do + local has_stable=0 has_preview=0 matched=() + for v in "${versions[@]}"; do + [[ -n "$v" ]] || continue + [[ "$(base_version "$v")" == "$b" ]] || continue + matched+=("$v") + if is_preview "$v"; then + has_preview=1 + else + has_stable=1 + fi + done + + if [[ "$has_stable" -eq 1 && "$has_preview" -eq 1 ]]; then + echo "[warn] $name: stable and preview both exist for base $b, prefer stable for this base" >&2 + printf ' %s\n' "${matched[@]}" >&2 + fi + done + } + + filter_mixed_versions() { + local versions=("$@") stable_bases=() v b + mapfile -t stable_bases < <( + for v in "${versions[@]}"; do + if [[ -n "$v" ]] && ! is_preview "$v"; then + base_version "$v" + fi + done | sort -u + ) + + for v in "${versions[@]}"; do + [[ -n "$v" ]] || continue + b="$(base_version "$v")" + if is_preview "$v" && printf '%s\n' "${stable_bases[@]}" | grep -qxF "$b"; then + continue + fi + echo "$v" + done + } + + read_var() { + sed -nE "s/^$2=\"\\\$\\{$2:-([^\"]+)\\}\".*/\\1/p" "$1" | head -n1 + } + + choose_final_version() { + local old="$1" new="$2" + [[ -n "$new" ]] || { echo "$old"; return; } + [[ -n "$old" ]] || { echo "$new"; return; } + if [[ "$(key "$old")" > "$(key "$new")" ]]; then + echo "$old" + else + echo "$new" + fi + } + + update_file() { + local file="$1" + local old_skia old_harf final_skia final_harf changed=0 + + old_skia="$(read_var "$file" SKIA_VER)" + old_harf="$(read_var "$file" HARFBUZZ_VER)" + final_skia="$(choose_final_version "$old_skia" "$NEW_SKIA")" + final_harf="$(choose_final_version "$old_harf" "$NEW_HARF")" + + echo "==> check $file" + echo " SKIA_VER: ${old_skia} -> ${NEW_SKIA} (apply: ${final_skia})" + echo " HARFBUZZ_VER: ${old_harf} -> ${NEW_HARF} (apply: ${final_harf})" + + if [[ "$old_skia" != "$final_skia" ]]; then + sed -i -E "s|^SKIA_VER=.*|SKIA_VER=\"\\\${SKIA_VER:-$final_skia}\"|" "$file" + changed=1 + fi + if [[ "$old_harf" != "$final_harf" ]]; then + sed -i -E "s|^HARFBUZZ_VER=.*|HARFBUZZ_VER=\"\\\${HARFBUZZ_VER:-$final_harf}\"|" "$file" + changed=1 + fi + + grep -qF "SKIA_VER=\"\${SKIA_VER:-$final_skia}\"" "$file" + grep -qF "HARFBUZZ_VER=\"\${HARFBUZZ_VER:-$final_harf}\"" "$file" + bash -n "$file" + + [[ "$changed" -eq 1 ]] + } + + mapfile -t SKIA < <(extract SkiaSharp) + mapfile -t HARF < <(extract HarfBuzzSharp) + + echo "==> SkiaSharp" + printf ' %s\n' "${SKIA[@]}" + echo "==> HarfBuzzSharp" + printf ' %s\n' "${HARF[@]}" + + log_mixed_versions "SkiaSharp" "${SKIA[@]}" + log_mixed_versions "HarfBuzzSharp" "${HARF[@]}" + + mapfile -t SKIA < <(filter_mixed_versions "${SKIA[@]}") + mapfile -t HARF < <(filter_mixed_versions "${HARF[@]}") + + NEW_SKIA="$(latest "${SKIA[@]}")" + NEW_HARF="$(latest "${HARF[@]}")" + + echo "==> selected" + echo " SKIA_VER=$NEW_SKIA" + echo " HARFBUZZ_VER=$NEW_HARF" + + any_changed=0 + changed_files=() + + for file in "${TARGET_FILES[@]}"; do + if update_file "$file"; then + any_changed=1 + changed_files+=("$file") + fi + done + + if [[ "$any_changed" -eq 0 ]]; then + echo "changed=0" >> "$GITHUB_OUTPUT" + exit 0 + fi + + { + echo "changed=1" + echo "changed_files<> "$GITHUB_OUTPUT" + + - name: commit + if: steps.resolve.outputs.changed == '1' + run: | + git config user.name github-actions + git config user.email github-actions@github.com + git add package-rhel-riscv.sh package-debian-riscv.sh + if git diff --cached --quiet; then + exit 0 + fi + git commit -m "chore: update riscv native dependency versions" + git push diff --git a/package-debian-riscv.sh b/package-debian-riscv.sh new file mode 100644 index 00000000000..81cda60761c --- /dev/null +++ b/package-debian-riscv.sh @@ -0,0 +1,801 @@ +#!/usr/bin/env bash +set -euo pipefail + +VERSION_ARG="" +WITH_CORE="both" +FORCE_NETCORE=0 +BUILD_FROM="" +XRAY_VER="${XRAY_VER:-}" +SING_VER="${SING_VER:-}" + +MIN_KERNEL="5.10" +PKGROOT="v2rayN-publish" +PROJECT_HINT="v2rayN.Desktop/v2rayN.Desktop.csproj" +OUTPUT_DIR="${HOME}/debbuild" +DOTNET_TFM="net10.0" +DOTNET_RISCV_VERSION="10.0.107" +DOTNET_RISCV_BASE="https://github.com/xujiegb/dotnet-riscv/releases/download" +DOTNET_RISCV_FILE="dotnet-sdk-${DOTNET_RISCV_VERSION}-linux-riscv64.tar.gz" +DOTNET_SDK_URL="${DOTNET_RISCV_BASE}/${DOTNET_RISCV_VERSION}/${DOTNET_RISCV_FILE}" +SKIA_VER="${SKIA_VER:-3.119.2}" +HARFBUZZ_VER="${HARFBUZZ_VER:-8.3.1.3}" + +OS_ID="" +OS_NAME="" +OS_VERSION_ID="" +HOST_ARCH="" +SCRIPT_DIR="" +PROJECT="" +VERSION="" +BUILT_ALL=0 + +declare -a BUILT_DEBS=() + +die() { + echo "$*" >&2 + exit 1 +} + +parse_args() { + local first_arg="${1:-}" + + if [[ -n "$first_arg" && "$first_arg" != --* ]]; then + VERSION_ARG="$first_arg" + shift || true + fi + + while [[ $# -gt 0 ]]; do + case "$1" in + --with-core) WITH_CORE="${2:-both}"; shift 2 ;; + --xray-ver) XRAY_VER="${2:-}"; shift 2 ;; + --singbox-ver) SING_VER="${2:-}"; shift 2 ;; + --netcore) FORCE_NETCORE=1; shift ;; + --buildfrom) BUILD_FROM="${2:-}"; shift 2 ;; + *) + [[ -n "${VERSION_ARG:-}" ]] || VERSION_ARG="$1" + shift + ;; + esac + done + + if [[ -n "${VERSION_ARG:-}" && -n "${BUILD_FROM:-}" ]]; then + die "You cannot specify both an explicit version and --buildfrom at the same time. + Provide either a version (e.g. 7.14.0) OR --buildfrom 1|2|3." + fi +} + +detect_environment() { + local current_kernel="" + local lowest="" + + . /etc/os-release + + OS_ID="${ID:-}" + OS_NAME="${NAME:-$OS_ID}" + OS_VERSION_ID="${VERSION_ID:-}" + HOST_ARCH="$(uname -m)" + + case "$OS_ID" in + debian) + echo "Detected supported system: ${OS_NAME:-$OS_ID} ${OS_VERSION_ID:-}" + ;; + *) + die "Unsupported system: ${OS_NAME:-unknown} (${OS_ID:-unknown}). +This script only supports: Debian." + ;; + esac + + case "$HOST_ARCH" in + riscv64) ;; + *) die "Only supports riscv64" ;; + esac + + current_kernel="$(uname -r)" + lowest="$(printf '%s\n%s\n' "$MIN_KERNEL" "$current_kernel" | sort -V | head -n1)" + + [[ "$lowest" == "$MIN_KERNEL" ]] || die "Kernel $current_kernel is below $MIN_KERNEL" + echo "[OK] Kernel $current_kernel verified." +} + +install_dependencies() { + local install_ok=0 + local tmp_dotnet="" + + mkdir -p "$OUTPUT_DIR" + + if command -v apt-get >/dev/null 2>&1; then + sudo apt-get update + sudo apt-get -y install \ + curl unzip tar jq rsync ca-certificates git dpkg-dev fakeroot file \ + desktop-file-utils xdg-utils wget gcc make pkg-config \ + libicu-dev libssl-dev libfontconfig1 libfreetype6 zlib1g + + mkdir -p "$HOME/.dotnet" + tmp_dotnet="$(mktemp -d)" + curl -fL "$DOTNET_SDK_URL" -o "$tmp_dotnet/$DOTNET_RISCV_FILE" + tar -C "$HOME/.dotnet" -xzf "$tmp_dotnet/$DOTNET_RISCV_FILE" + rm -rf "$tmp_dotnet" + + export PATH="$HOME/.dotnet:$PATH" + export DOTNET_ROOT="$HOME/.dotnet" + + dotnet --info >/dev/null 2>&1 && install_ok=1 + fi + + if [[ "$install_ok" -ne 1 ]]; then + echo "Could not auto-install dependencies for '$OS_ID'. Make sure these are available:" + echo "dotnet-riscv SDK, curl, unzip, tar, rsync, git, gcc, make, dpkg-deb, fakeroot, libicu-dev, libssl-dev" + exit 1 + fi +} + +prepare_workspace() { + SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" + cd "$SCRIPT_DIR" + + if [[ -f .gitmodules ]]; then + git submodule sync --recursive || true + git submodule update --init --recursive || true + fi + + PROJECT="$PROJECT_HINT" + [[ -f "$PROJECT" ]] || PROJECT="$(find . -maxdepth 3 -name 'v2rayN.Desktop.csproj' | head -n1 || true)" + [[ -f "$PROJECT" ]] || die "v2rayN.Desktop.csproj not found" +} + +choose_channel() { + local ch="latest" + local sel="" + + if [[ -n "${BUILD_FROM:-}" ]]; then + case "$BUILD_FROM" in + 1) echo "latest"; return 0 ;; + 2) echo "prerelease"; return 0 ;; + 3) echo "keep"; return 0 ;; + *) die "[ERROR] Invalid --buildfrom value: ${BUILD_FROM}. Use 1|2|3." ;; + esac + fi + + if [[ -t 0 ]]; then + echo "[?] Choose v2rayN release channel:" >&2 + echo " 1) Latest (stable) [default]" >&2 + echo " 2) Pre-release (preview)" >&2 + echo " 3) Keep current (do nothing)" >&2 + printf "Enter 1, 2 or 3 [default 1]: " >&2 + + if read -r sel /dev/null 2>&1; then + git fetch --tags --force --prune --depth=1 || true + git rev-parse "refs/tags/${want}" >/dev/null 2>&1 && ref="$want" + + if [[ -n "$ref" ]]; then + echo "[OK] Found ref '${ref}', checking out..." + git checkout -f "$ref" + sync_submodules + return 0 + fi + fi + + return 1 +} + +apply_channel_or_keep() { + local ch="$1" + local tag="" + + if [[ "$ch" == "keep" ]]; then + echo "[*] Keep current repository state (no checkout)." + VERSION="$(git describe --tags --abbrev=0 2>/dev/null || echo '0.0.0+git')" + VERSION="${VERSION#v}" + return 0 + fi + + echo "[*] Resolving ${ch} tag from GitHub releases..." + + case "$ch" in + latest) tag="$(get_latest_tag_latest || true)" ;; + prerelease) tag="$(get_latest_tag_prerelease || true)" ;; + *) die "Failed to resolve latest tag for channel '${ch}'." ;; + esac + + [[ -n "$tag" ]] || die "Failed to resolve latest tag for channel '${ch}'." + + echo "[*] Latest tag for '${ch}': ${tag}" + git_try_checkout "$tag" || die "Failed to checkout '${tag}'." + VERSION="${tag#v}" +} + +resolve_version() { + if git rev-parse --git-dir >/dev/null 2>&1; then + if [[ -n "${VERSION_ARG:-}" ]]; then + local clean_ver="${VERSION_ARG#v}" + + if git_try_checkout "$clean_ver"; then + VERSION="$clean_ver" + else + echo "[WARN] Tag '${VERSION_ARG}' not found." + apply_channel_or_keep "$(choose_channel)" + fi + else + apply_channel_or_keep "$(choose_channel)" + fi + else + echo "Current directory is not a git repo; proceeding on current tree." + VERSION="${VERSION_ARG:-0.0.0}" + fi + + VERSION="${VERSION#v}" + echo "[*] GUI version resolved as: ${VERSION}" +} + +apply_riscv_patch() { + local f="" + + find . -type f \( -name "*.csproj" -o -name "*.props" -o -name "*.targets" \) \ + -exec sed -Ei 's#[^<]+#'"$DOTNET_TFM"'#g' {} + + + while IFS= read -r -d '' f; do + sed -i \ + -e "s###g" \ + -e "s###g" \ + -e "s###g" \ + -e "s###g" \ + "$f" + + grep -q 'PackageVersion Include="SkiaSharp"' "$f" || \ + sed -i "/<\/ItemGroup>/i\ " "$f" + + grep -q 'PackageVersion Include="SkiaSharp.NativeAssets.Linux"' "$f" || \ + sed -i "/<\/ItemGroup>/i\ " "$f" + + grep -q 'PackageVersion Include="HarfBuzzSharp"' "$f" || \ + sed -i "/<\/ItemGroup>/i\ " "$f" + + grep -q 'PackageVersion Include="HarfBuzzSharp.NativeAssets.Linux"' "$f" || \ + sed -i "/<\/ItemGroup>/i\ " "$f" + done < <(find . -type f -name 'Directory.Packages.props' -print0) + + f="$(find "$DOTNET_ROOT/sdk/$(dotnet --version)" -type f -name 'Microsoft.NETCoreSdk.BundledVersions.props' | head -n1 || true)" + if [[ -f "$f" ]] && ! grep -q 'linux-riscv64' "$f"; then + sed -i \ + -e 's/linux-arm64/&;linux-riscv64/g' \ + -e 's/linux-musl-arm64/&;linux-musl-riscv64/g' \ + "$f" + fi +} + +copy_skiasharp_native_riscv64() { + local outdir="$1" + local skia_so="" + local harfbuzz_so="" + + mkdir -p "$outdir" + + skia_so="$(find "$HOME/.nuget/packages" -path "*/skiasharp.nativeassets.linux/${SKIA_VER}/runtimes/linux-riscv64/native/libSkiaSharp.so" | head -n1 || true)" + [[ -n "$skia_so" ]] || skia_so="$(find "$HOME/.nuget/packages" -path "*/runtimes/linux-riscv64/native/libSkiaSharp.so" | head -n1 || true)" + + harfbuzz_so="$(find "$HOME/.nuget/packages" -path "*/harfbuzzsharp.nativeassets.linux/${HARFBUZZ_VER}/runtimes/linux-riscv64/native/libHarfBuzzSharp.so" | head -n1 || true)" + [[ -n "$harfbuzz_so" ]] || harfbuzz_so="$(find "$HOME/.nuget/packages" -path "*/runtimes/linux-riscv64/native/libHarfBuzzSharp.so" | head -n1 || true)" + + if [[ -n "$skia_so" && -f "$skia_so" ]]; then + echo "[+] Copy libSkiaSharp.so from NuGet cache" + install -m 755 "$skia_so" "$outdir/libSkiaSharp.so" + else + echo "[WARN] libSkiaSharp.so for linux-riscv64 not found in NuGet cache" + fi + + if [[ -n "$harfbuzz_so" && -f "$harfbuzz_so" ]]; then + echo "[+] Copy libHarfBuzzSharp.so from NuGet cache" + install -m 755 "$harfbuzz_so" "$outdir/libHarfBuzzSharp.so" + else + echo "[WARN] libHarfBuzzSharp.so for linux-riscv64 not found in NuGet cache" + fi +} + +xray_url_for_rid() { + local rid="$1" + local ver="$2" + + case "$rid" in + linux-riscv64) echo "https://github.com/XTLS/Xray-core/releases/download/v${ver}/Xray-linux-riscv64.zip" ;; + *) return 1 ;; + esac +} + +singbox_url_for_rid() { + local rid="$1" + local ver="$2" + + case "$rid" in + linux-riscv64) echo "https://github.com/SagerNet/sing-box/releases/download/v${ver}/sing-box-${ver}-linux-riscv64.tar.gz" ;; + *) return 1 ;; + esac +} + +bundle_url_for_rid() { + local rid="$1" + + case "$rid" in + linux-riscv64) echo "https://raw.githubusercontent.com/2dust/v2rayN-core-bin/refs/heads/master/v2rayN-linux-riscv64.zip" ;; + *) return 1 ;; + esac +} + +download_xray() { + local outdir="$1" + local rid="$2" + local ver="${XRAY_VER:-}" + local url="" + local tmp="" + + mkdir -p "$outdir" + + if [[ -z "$ver" ]]; then + ver="$(curl -fsSL https://api.github.com/repos/XTLS/Xray-core/releases/latest \ + | grep -Eo '"tag_name":\s*"v[^"]+"' \ + | sed -E 's/.*"v([^"]+)".*/\1/' \ + | head -n1)" || true + fi + + [[ -n "$ver" ]] || { echo "[xray] Failed to get version"; return 1; } + url="$(xray_url_for_rid "$rid" "$ver")" || { echo "[xray] Unsupported RID: $rid"; return 1; } + + echo "[+] Download xray: $url" + + tmp="$(mktemp -d)" + curl -fL "$url" -o "$tmp/xray.zip" || { rm -rf "$tmp"; return 1; } + unzip -q "$tmp/xray.zip" -d "$tmp" || { rm -rf "$tmp"; return 1; } + install -m 755 "$tmp/xray" "$outdir/xray" || { rm -rf "$tmp"; return 1; } + rm -rf "$tmp" +} + +download_singbox() { + local outdir="$1" + local rid="$2" + local ver="${SING_VER:-}" + local url="" + local tmp="" + local bin="" + local cronet="" + + mkdir -p "$outdir" + + if [[ -z "$ver" ]]; then + ver="$(curl -fsSL https://api.github.com/repos/SagerNet/sing-box/releases/latest \ + | grep -Eo '"tag_name":\s*"v[^"]+"' \ + | sed -E 's/.*"v([^"]+)".*/\1/' \ + | head -n1)" || true + fi + + [[ -n "$ver" ]] || { echo "[sing-box] Failed to get version"; return 1; } + url="$(singbox_url_for_rid "$rid" "$ver")" || { echo "[sing-box] Unsupported RID: $rid"; return 1; } + + echo "[+] Download sing-box: $url" + + tmp="$(mktemp -d)" + curl -fL "$url" -o "$tmp/singbox.tar.gz" || { rm -rf "$tmp"; return 1; } + tar -C "$tmp" -xzf "$tmp/singbox.tar.gz" || { rm -rf "$tmp"; return 1; } + + bin="$(find "$tmp" -type f -name 'sing-box' | head -n1 || true)" + [[ -n "$bin" ]] || { echo "[!] sing-box unpack failed"; rm -rf "$tmp"; return 1; } + + install -m 755 "$bin" "$outdir/sing-box" || { rm -rf "$tmp"; return 1; } + + cronet="$(find "$tmp" -type f -name 'libcronet*.so*' | head -n1 || true)" + [[ -n "$cronet" ]] && install -m 644 "$cronet" "$outdir/libcronet.so" || true + + rm -rf "$tmp" +} + +unify_geo_layout() { + local outroot="$1" + local n + local names=( + geosite.dat + geoip.dat + geoip-only-cn-private.dat + Country.mmdb + geoip.metadb + ) + + mkdir -p "$outroot/bin" + + for n in "${names[@]}"; do + if [[ -f "$outroot/bin/xray/$n" ]]; then + mv -f "$outroot/bin/xray/$n" "$outroot/bin/$n" + fi + done +} + +download_geo_assets() { + local outroot="$1" + local bin_dir="$outroot/bin" + local srss_dir="$bin_dir/srss" + local f="" + + mkdir -p "$bin_dir" "$srss_dir" + + echo "[+] Download Xray Geo to ${bin_dir}" + curl -fsSL -o "$bin_dir/geosite.dat" "https://github.com/Loyalsoldier/V2ray-rules-dat/releases/latest/download/geosite.dat" + curl -fsSL -o "$bin_dir/geoip.dat" "https://github.com/Loyalsoldier/V2ray-rules-dat/releases/latest/download/geoip.dat" + curl -fsSL -o "$bin_dir/geoip-only-cn-private.dat" "https://raw.githubusercontent.com/Loyalsoldier/geoip/release/geoip-only-cn-private.dat" + curl -fsSL -o "$bin_dir/Country.mmdb" "https://raw.githubusercontent.com/Loyalsoldier/geoip/release/Country.mmdb" + + echo "[+] Download sing-box rule DB & rule-sets" + curl -fsSL -o "$bin_dir/geoip.metadb" "https://github.com/MetaCubeX/meta-rules-dat/releases/latest/download/geoip.metadb" + + for f in geoip-private.srs geoip-cn.srs geoip-facebook.srs geoip-fastly.srs geoip-google.srs geoip-netflix.srs geoip-telegram.srs geoip-twitter.srs; do + curl -fsSL -o "$srss_dir/$f" "https://raw.githubusercontent.com/2dust/sing-box-rules/refs/heads/rule-set-geoip/$f" + done + + for f in geosite-cn.srs geosite-gfw.srs geosite-google.srs geosite-greatfire.srs geosite-geolocation-cn.srs geosite-category-ads-all.srs geosite-private.srs; do + curl -fsSL -o "$srss_dir/$f" "https://raw.githubusercontent.com/2dust/sing-box-rules/refs/heads/rule-set-geosite/$f" + done + + unify_geo_layout "$outroot" +} + +populate_assets_zip_mode() { + local outroot="$1" + local rid="$2" + local url="" + local tmp="" + local nested_dir="" + + url="$(bundle_url_for_rid "$rid")" || { echo "[!] Bundle unsupported RID: $rid"; return 1; } + + echo "[+] Try v2rayN bundle archive: $url" + + tmp="$(mktemp -d)" + curl -fL "$url" -o "$tmp/v2rayn.zip" || { echo "[!] Bundle download failed"; rm -rf "$tmp"; return 1; } + unzip -q "$tmp/v2rayn.zip" -d "$tmp" || { echo "[!] Bundle unzip failed"; rm -rf "$tmp"; return 1; } + + if [[ -d "$tmp/bin" ]]; then + mkdir -p "$outroot/bin" + rsync -a "$tmp/bin/" "$outroot/bin/" + else + rsync -a "$tmp/" "$outroot/" + fi + + rm -f "$outroot/v2rayn.zip" 2>/dev/null || true + find "$outroot" -type d -name "mihomo" -prune -exec rm -rf {} + 2>/dev/null || true + + nested_dir="$(find "$outroot" -maxdepth 1 -type d -name 'v2rayN-linux-*' | head -n1 || true)" + if [[ -n "$nested_dir" && -d "$nested_dir/bin" ]]; then + mkdir -p "$outroot/bin" + rsync -a "$nested_dir/bin/" "$outroot/bin/" + rm -rf "$nested_dir" + fi + + unify_geo_layout "$outroot" + rm -rf "$tmp" + + echo "[+] Bundle extracted to $outroot" +} + +populate_assets_netcore_mode() { + local outroot="$1" + local rid="$2" + + mkdir -p "$outroot/bin/xray" "$outroot/bin/sing_box" + + if [[ "$WITH_CORE" == "xray" || "$WITH_CORE" == "both" ]]; then + download_xray "$outroot/bin/xray" "$rid" || echo "[!] xray download failed (skipped)" + fi + + if [[ "$WITH_CORE" == "sing-box" || "$WITH_CORE" == "both" ]]; then + download_singbox "$outroot/bin/sing_box" "$rid" || echo "[!] sing-box download failed (skipped)" + fi + + download_geo_assets "$outroot" || echo "[!] Geo rules download failed (skipped)" +} + +stage_runtime_assets() { + local outroot="$1" + local rid="$2" + + mkdir -p "$outroot/bin/xray" "$outroot/bin/sing_box" + + if [[ "$FORCE_NETCORE" -eq 0 ]]; then + if populate_assets_zip_mode "$outroot" "$rid"; then + echo "[*] Using v2rayN bundle archive." + else + echo "[*] Bundle failed, fallback to separate core + rules." + populate_assets_netcore_mode "$outroot" "$rid" + fi + else + echo "[*] --netcore specified: use separate core + rules." + populate_assets_netcore_mode "$outroot" "$rid" + fi +} + +describe_target() { + local short="$1" + + case "$short" in + riscv64) printf '%s\n%s\n' "linux-riscv64" "riscv64" ;; + *) echo "Unknown arch '$short' (use riscv64)" >&2; return 1 ;; + esac +} + +publish_binary() { + local rid="$1" + + dotnet clean "$PROJECT" -c Release -p:TargetFramework="$DOTNET_TFM" + rm -rf "$(dirname "$PROJECT")/bin/Release/${DOTNET_TFM}" || true + dotnet restore "$PROJECT" -r "$rid" -p:TargetFramework="$DOTNET_TFM" + dotnet publish "$PROJECT" -c Release -r "$rid" -p:TargetFramework="$DOTNET_TFM" -p:PublishSingleFile=false -p:SelfContained=true +} + +write_launcher_file() { + local stage="$1" + + install -m 755 /dev/stdin "$stage/usr/bin/v2rayn" <<'EOF' +#!/usr/bin/env bash +set -euo pipefail +DIR="/opt/v2rayN" +export LD_LIBRARY_PATH="$DIR:${LD_LIBRARY_PATH:-}" +cd "$DIR" + +if [[ -x "$DIR/v2rayN" ]]; then + exec "$DIR/v2rayN" "$@" +fi + +for dll in v2rayN.Desktop.dll v2rayN.dll; do + if [[ -f "$DIR/$dll" ]]; then + exec /usr/bin/dotnet "$DIR/$dll" "$@" + fi +done + +echo "v2rayN launcher: no executable found in $DIR" >&2 +ls -l "$DIR" >&2 || true +exit 1 +EOF +} + +write_desktop_file() { + local stage="$1" + + install -m 644 /dev/stdin "$stage/usr/share/applications/v2rayn.desktop" <<'EOF' +[Desktop Entry] +Type=Application +Name=v2rayN +Comment=v2rayN for Debian GNU Linux +Exec=v2rayn +Icon=v2rayn +Terminal=false +Categories=Network; +EOF +} + +write_maintainer_scripts() { + local debian_dir="$1" + + install -m 755 /dev/stdin "$debian_dir/postinst" <<'EOF' +#!/bin/sh +set -e +update-desktop-database /usr/share/applications >/dev/null 2>&1 || true +if command -v gtk-update-icon-cache >/dev/null 2>&1; then + gtk-update-icon-cache -f /usr/share/icons/hicolor >/dev/null 2>&1 || true +fi +exit 0 +EOF + + install -m 755 /dev/stdin "$debian_dir/postrm" <<'EOF' +#!/bin/sh +set -e +update-desktop-database /usr/share/applications >/dev/null 2>&1 || true +if command -v gtk-update-icon-cache >/dev/null 2>&1; then + gtk-update-icon-cache -f /usr/share/icons/hicolor >/dev/null 2>&1 || true +fi +exit 0 +EOF +} + +package_binary() { + local short="$1" + local rid="$2" + local deb_arch="$3" + local pubdir="" + local workdir="" + local stage="" + local debian_dir="" + local project_dir="" + local icon_candidate="" + local shlibs_depends="" + local extra_depends="" + local final_depends="" + local multiarch="" + local sys_libdir="" + local sys_usrlibdir="" + local deb_out="" + + pubdir="$(dirname "$PROJECT")/bin/Release/${DOTNET_TFM}/${rid}/publish" + [[ -d "$pubdir" ]] || { echo "Publish directory not found: $pubdir"; return 1; } + + workdir="$(mktemp -d)" + trap '[[ -n "${workdir:-}" ]] && rm -rf "$workdir"' RETURN + + stage="$workdir/${PKGROOT}_${VERSION}_${deb_arch}" + debian_dir="$stage/DEBIAN" + + mkdir -p "$stage/opt/v2rayN" "$stage/usr/bin" "$stage/usr/share/applications" "$stage/usr/share/icons/hicolor/256x256/apps" "$debian_dir" + cp -a "$pubdir/." "$stage/opt/v2rayN/" + + copy_skiasharp_native_riscv64 "$stage/opt/v2rayN" || echo "[!] SkiaSharp native copy failed (skipped)" + + project_dir="$(cd "$(dirname "$PROJECT")" && pwd)" + icon_candidate="$project_dir/v2rayN.png" + [[ -f "$icon_candidate" ]] && cp "$icon_candidate" "$stage/usr/share/icons/hicolor/256x256/apps/v2rayn.png" || true + + stage_runtime_assets "$stage/opt/v2rayN" "$rid" + write_launcher_file "$stage" + write_desktop_file "$stage" + write_maintainer_scripts "$debian_dir" + + extra_depends="libc6 (>= 2.34), fontconfig (>= 2.13.1), desktop-file-utils (>= 0.26), xdg-utils (>= 1.1.3), coreutils (>= 8.32), bash (>= 5.1), libfreetype6 (>= 2.11)" + + mkdir -p "$workdir/debian" + cat > "$workdir/debian/control" < +Standards-Version: 4.7.0 + +Package: v2rayn +Architecture: ${deb_arch} +Description: v2rayN +EOF + + multiarch="$(dpkg-architecture -a"$deb_arch" -qDEB_HOST_MULTIARCH)" + sys_libdir="/lib/$multiarch" + sys_usrlibdir="/usr/lib/$multiarch" + + : > "$debian_dir/substvars" + + mapfile -t ELF_FILES < <( + find "$stage/opt/v2rayN" -type f \( -name "*.so*" -o -perm -111 \) ! -name 'libcoreclrtraceptprovider.so' + ) + + if [[ "${#ELF_FILES[@]}" -gt 0 ]]; then + ( + cd "$workdir" + dpkg-shlibdeps \ + -l"$stage/opt/v2rayN" \ + -l"$sys_libdir" \ + -l"$sys_usrlibdir" \ + -T"$debian_dir/substvars" \ + "${ELF_FILES[@]}" + ) >/dev/null 2>&1 || true + fi + + shlibs_depends="$(sed -n 's/^shlibs:Depends=//p' "$debian_dir/substvars" | head -n1 || true)" + + if [[ -n "$shlibs_depends" ]]; then + shlibs_depends="$(echo "$shlibs_depends" \ + | sed -E 's/ *\([^)]*\)//g' \ + | sed -E 's/ *, */, /g' \ + | sed -E 's/^, *//; s/, *$//')" + final_depends="${shlibs_depends}, ${extra_depends}" + else + final_depends="${extra_depends}" + fi + + cat > "$debian_dir/control" < +Homepage: https://github.com/2dust/v2rayN +Section: net +Priority: optional +Depends: ${final_depends} +Description: v2rayN (Avalonia) GUI client for Linux + Support vless / vmess / Trojan / http / socks / Anytls / Hysteria2 / + Shadowsocks / tuic / WireGuard. +EOF + + find "$stage/opt/v2rayN" -type d -exec chmod 0755 {} + + find "$stage/opt/v2rayN" -type f -exec chmod 0644 {} + + [[ -f "$stage/opt/v2rayN/v2rayN" ]] && chmod 0755 "$stage/opt/v2rayN/v2rayN" || true + [[ -f "$stage/opt/v2rayN/libSkiaSharp.so" ]] && chmod 0755 "$stage/opt/v2rayN/libSkiaSharp.so" || true + [[ -f "$stage/opt/v2rayN/libHarfBuzzSharp.so" ]] && chmod 0755 "$stage/opt/v2rayN/libHarfBuzzSharp.so" || true + + deb_out="$OUTPUT_DIR/v2rayn_${VERSION}_${deb_arch}.deb" + dpkg-deb --root-owner-group --build "$stage" "$deb_out" + + echo "Build done for $short. DEB at:" + echo " $deb_out" + BUILT_DEBS+=("$deb_out") +} + +select_targets() { + printf '%s\n' riscv64 +} + +build_one_target() { + local short="$1" + local meta=() + local rid="" + local deb_arch="" + + mapfile -t meta < <(describe_target "$short") || return 1 + rid="${meta[0]}" + deb_arch="${meta[1]}" + + echo "[*] Building for target: $short (RID=$rid, DEB arch=$deb_arch)" + publish_binary "$rid" + package_binary "$short" "$rid" "$deb_arch" +} + +print_summary() { + local pkg="" + + echo "" + echo "================ Build Summary =================" + if [[ "${#BUILT_DEBS[@]}" -gt 0 ]]; then + echo "Output directory: $OUTPUT_DIR" + for pkg in "${BUILT_DEBS[@]}"; do + echo "$pkg" + done + else + echo "No DEBs detected in summary (check build logs above)." + fi + echo "===============================================" +} + +main() { + local targets=() + local arch="" + + parse_args "$@" + detect_environment + install_dependencies + prepare_workspace + resolve_version + apply_riscv_patch + + mapfile -t targets < <(select_targets) + + for arch in "${targets[@]}"; do + build_one_target "$arch" + done + + print_summary +} + +main "$@" diff --git a/package-debian.sh b/package-debian.sh index 4515fe6fd66..0c10a548492 100644 --- a/package-debian.sh +++ b/package-debian.sh @@ -1,141 +1,167 @@ #!/usr/bin/env bash set -euo pipefail -# Require Debian base branch -. /etc/os-release - -case "${ID:-}" in - debian) - echo "Detected supported system: ${NAME:-$ID} ${VERSION_ID:-}" - ;; - *) - echo "Unsupported system: ${NAME:-unknown} (${ID:-unknown})." - echo "This script only supports: Debian." - exit 1 - ;; -esac +VERSION_ARG="" +WITH_CORE="both" +FORCE_NETCORE=0 +ARCH_OVERRIDE="" +BUILD_FROM="" +XRAY_VER="${XRAY_VER:-}" +SING_VER="${SING_VER:-}" + +MIN_KERNEL="6.12" +PKGROOT="v2rayN-publish" +PROJECT_HINT="v2rayN.Desktop/v2rayN.Desktop.csproj" +OUTPUT_DIR="${HOME}/debbuild" + +OS_ID="" +OS_NAME="" +OS_VERSION_ID="" +HOST_ARCH="" +SCRIPT_DIR="" +PROJECT="" +VERSION="" + +declare -a BUILT_DEBS=() + +die() { + echo "$*" >&2 + exit 1 +} -# Kernel version -MIN_KERNEL="6.11" -CURRENT_KERNEL="$(uname -r)" +parse_args() { + local first_arg="${1:-}" -lowest="$(printf '%s\n%s\n' "$MIN_KERNEL" "$CURRENT_KERNEL" | sort -V | head -n1)" + if [[ -n "$first_arg" && "$first_arg" != --* ]]; then + VERSION_ARG="$first_arg" + shift || true + fi -if [[ "$lowest" != "$MIN_KERNEL" ]]; then - echo "Kernel $CURRENT_KERNEL is below $MIN_KERNEL" - exit 1 -fi + while [[ $# -gt 0 ]]; do + case "$1" in + --with-core) WITH_CORE="${2:-both}"; shift 2 ;; + --xray-ver) XRAY_VER="${2:-}"; shift 2 ;; + --singbox-ver) SING_VER="${2:-}"; shift 2 ;; + --netcore) FORCE_NETCORE=1; shift ;; + --arch) ARCH_OVERRIDE="${2:-}"; shift 2 ;; + --buildfrom) BUILD_FROM="${2:-}"; shift 2 ;; + *) + [[ -n "${VERSION_ARG:-}" ]] || VERSION_ARG="$1" + shift + ;; + esac + done -echo "[OK] Kernel $CURRENT_KERNEL verified." + if [[ -n "${VERSION_ARG:-}" && -n "${BUILD_FROM:-}" ]]; then + die "You cannot specify both an explicit version and --buildfrom at the same time. + Provide either a version (e.g. 7.14.0) OR --buildfrom 1|2|3." + fi +} -# Config & Parse arguments -VERSION_ARG="${1:-}" # Pass version number like 7.13.8, or leave empty -WITH_CORE="both" # Default: bundle both xray+sing-box -FORCE_NETCORE=0 # --netcore => skip archive bundle, use separate downloads -ARCH_OVERRIDE="" # --arch x64|arm64|all (optional compile target) -BUILD_FROM="" # --buildfrom 1|2|3 to select channel non-interactively +detect_environment() { + local current_kernel="" + local lowest="" -# If the first argument starts with --, do not treat it as a version number -if [[ "${VERSION_ARG:-}" == --* ]]; then - VERSION_ARG="" -fi -# Take the first non --* argument as version, discard it -if [[ -n "${VERSION_ARG:-}" ]]; then shift || true; fi - -# Parse remaining optional arguments -while [[ $# -gt 0 ]]; do - case "$1" in - --with-core) WITH_CORE="${2:-both}"; shift 2;; - --xray-ver) XRAY_VER="${2:-}"; shift 2;; - --singbox-ver) SING_VER="${2:-}"; shift 2;; - --netcore) FORCE_NETCORE=1; shift;; - --arch) ARCH_OVERRIDE="${2:-}"; shift 2;; - --buildfrom) BUILD_FROM="${2:-}"; shift 2;; + . /etc/os-release + + OS_ID="${ID:-}" + OS_NAME="${NAME:-$OS_ID}" + OS_VERSION_ID="${VERSION_ID:-}" + HOST_ARCH="$(uname -m)" + + case "$OS_ID" in + debian) + echo "Detected supported system: ${OS_NAME:-$OS_ID} ${OS_VERSION_ID:-}" + ;; *) - if [[ -z "${VERSION_ARG:-}" ]]; then VERSION_ARG="$1"; fi - shift;; + die "Unsupported system: ${OS_NAME:-unknown} (${OS_ID:-unknown}). +This script only supports: Debian." + ;; esac -done -# Conflict: version number AND --buildfrom cannot be used together -if [[ -n "${VERSION_ARG:-}" && -n "${BUILD_FROM:-}" ]]; then - echo "You cannot specify both an explicit version and --buildfrom at the same time." - echo " Provide either a version (e.g. 7.14.0) OR --buildfrom 1|2|3." - exit 1 -fi + case "$HOST_ARCH" in + x86_64|aarch64) ;; + *) die "Only supports aarch64 / x86_64" ;; + esac -# Check and install dependencies -host_arch="$(uname -m)" -[[ "$host_arch" == "aarch64" || "$host_arch" == "x86_64" ]] || { echo "Only supports aarch64 / x86_64"; exit 1; } + current_kernel="$(uname -r)" + lowest="$(printf '%s\n%s\n' "$MIN_KERNEL" "$current_kernel" | sort -V | head -n1)" -install_ok=0 + [[ "$lowest" == "$MIN_KERNEL" ]] || die "Kernel $current_kernel is below $MIN_KERNEL" + echo "[OK] Kernel $current_kernel verified." +} -if command -v apt-get >/dev/null 2>&1; then - sudo apt-get update - sudo apt-get -y install \ - curl unzip tar jq rsync ca-certificates git dpkg-dev fakeroot file \ - desktop-file-utils xdg-utils wget +install_dependencies() { + local install_ok=0 + local foreign_arch="" - if [[ "$host_arch" == "aarch64" ]]; then - sudo dpkg --add-architecture amd64 || true + mkdir -p "$OUTPUT_DIR" + + if command -v apt-get >/dev/null 2>&1; then sudo apt-get update sudo apt-get -y install \ - libc6:amd64 libgcc-s1:amd64 libstdc++6:amd64 zlib1g:amd64 libfontconfig1:amd64 - elif [[ "$host_arch" == "x86_64" ]]; then - sudo dpkg --add-architecture arm64 || true + curl unzip tar jq rsync ca-certificates git dpkg-dev fakeroot file \ + desktop-file-utils xdg-utils wget + + case "$HOST_ARCH" in + aarch64) foreign_arch="amd64" ;; + x86_64) foreign_arch="arm64" ;; + *) die "Only supports aarch64 / x86_64" ;; + esac + + sudo dpkg --add-architecture "$foreign_arch" || true sudo apt-get update sudo apt-get -y install \ - libc6:arm64 libgcc-s1:arm64 libstdc++6:arm64 zlib1g:arm64 libfontconfig1:arm64 - fi + "libc6:${foreign_arch}" \ + "libgcc-s1:${foreign_arch}" \ + "libstdc++6:${foreign_arch}" \ + "zlib1g:${foreign_arch}" \ + "libfontconfig1:${foreign_arch}" - # Install .NET SDK 10 via official script - wget -q https://dot.net/v1/dotnet-install.sh - chmod +x dotnet-install.sh - ./dotnet-install.sh --channel 10.0 --install-dir "$HOME/.dotnet" + wget -q https://dot.net/v1/dotnet-install.sh + chmod +x dotnet-install.sh + ./dotnet-install.sh --channel 10.0.1xx --install-dir "$HOME/.dotnet" - export PATH="$HOME/.dotnet:$PATH" - export DOTNET_ROOT="$HOME/.dotnet" + export PATH="$HOME/.dotnet:$PATH" + export DOTNET_ROOT="$HOME/.dotnet" - dotnet --info >/dev/null 2>&1 && install_ok=1 -fi + dotnet --info >/dev/null 2>&1 && install_ok=1 + fi -if [[ "$install_ok" -ne 1 ]]; then - echo "Could not auto-install dependencies for '$ID'. Make sure these are available:" - echo "dotnet-sdk 10.x, curl, unzip, tar, rsync, git, dpkg-deb, desktop-file-utils, xdg-utils" - exit 1 -fi + if [[ "$install_ok" -ne 1 ]]; then + echo "Could not auto-install dependencies for '$OS_ID'. Make sure these are available:" + echo "dotnet-sdk 10.x, curl, unzip, tar, rsync, git, dpkg-deb, desktop-file-utils, xdg-utils" + exit 1 + fi +} -# Root directory -SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" -cd "$SCRIPT_DIR" +prepare_workspace() { + SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" + cd "$SCRIPT_DIR" -# Git submodules (best effort) -if [[ -f .gitmodules ]]; then - git submodule sync --recursive || true - git submodule update --init --recursive || true -fi + if [[ -f .gitmodules ]]; then + git submodule sync --recursive || true + git submodule update --init --recursive || true + fi -# Locate project -PROJECT="v2rayN.Desktop/v2rayN.Desktop.csproj" -if [[ ! -f "$PROJECT" ]]; then - PROJECT="$(find . -maxdepth 3 -name 'v2rayN.Desktop.csproj' | head -n1 || true)" -fi -[[ -f "$PROJECT" ]] || { echo "v2rayN.Desktop.csproj not found"; exit 1; } + PROJECT="$PROJECT_HINT" + [[ -f "$PROJECT" ]] || PROJECT="$(find . -maxdepth 3 -name 'v2rayN.Desktop.csproj' | head -n1 || true)" + [[ -f "$PROJECT" ]] || die "v2rayN.Desktop.csproj not found" +} choose_channel() { - # If --buildfrom provided, map it directly and skip interaction. + local ch="latest" + local sel="" + if [[ -n "${BUILD_FROM:-}" ]]; then case "$BUILD_FROM" in - 1) echo "latest"; return 0;; - 2) echo "prerelease"; return 0;; - 3) echo "keep"; return 0;; - *) echo "[ERROR] Invalid --buildfrom value: ${BUILD_FROM}. Use 1|2|3." >&2; exit 1;; + 1) echo "latest"; return 0 ;; + 2) echo "prerelease"; return 0 ;; + 3) echo "keep"; return 0 ;; + *) die "[ERROR] Invalid --buildfrom value: ${BUILD_FROM}. Use 1|2|3." ;; esac fi - # Print menu to stderr and read from /dev/tty so stdout only carries the token. - local ch="latest" sel="" - if [[ -t 0 ]]; then echo "[?] Choose v2rayN release channel:" >&2 echo " 1) Latest (stable) [default]" >&2 @@ -166,28 +192,35 @@ get_latest_tag_prerelease() { | sed 's/^v//' } +sync_submodules() { + if [[ -f .gitmodules ]]; then + git submodule sync --recursive || true + git submodule update --init --recursive || true + fi +} + git_try_checkout() { - local want="$1" ref="" + local want="$1" + local ref="" + if git rev-parse --git-dir >/dev/null 2>&1; then git fetch --tags --force --prune --depth=1 || true - if git rev-parse "refs/tags/${want}" >/dev/null 2>&1; then - ref="${want}" - fi + git rev-parse "refs/tags/${want}" >/dev/null 2>&1 && ref="$want" + if [[ -n "$ref" ]]; then echo "[OK] Found ref '${ref}', checking out..." - git checkout -f "${ref}" - if [[ -f .gitmodules ]]; then - git submodule sync --recursive || true - git submodule update --init --recursive || true - fi + git checkout -f "$ref" + sync_submodules return 0 fi fi + return 1 } apply_channel_or_keep() { - local ch="$1" tag + local ch="$1" + local tag="" if [[ "$ch" == "keep" ]]; then echo "[*] Keep current repository state (no checkout)." @@ -197,99 +230,154 @@ apply_channel_or_keep() { fi echo "[*] Resolving ${ch} tag from GitHub releases..." - if [[ "$ch" == "prerelease" ]]; then - tag="$(get_latest_tag_prerelease || true)" - else - tag="$(get_latest_tag_latest || true)" - fi - [[ -n "$tag" ]] || { echo "Failed to resolve latest tag for channel '${ch}'."; exit 1; } + case "$ch" in + latest) tag="$(get_latest_tag_latest || true)" ;; + prerelease) tag="$(get_latest_tag_prerelease || true)" ;; + *) die "Failed to resolve latest tag for channel '${ch}'." ;; + esac + + [[ -n "$tag" ]] || die "Failed to resolve latest tag for channel '${ch}'." + echo "[*] Latest tag for '${ch}': ${tag}" - git_try_checkout "$tag" || { echo "Failed to checkout '${tag}'."; exit 1; } + git_try_checkout "$tag" || die "Failed to checkout '${tag}'." VERSION="${tag#v}" } -if git rev-parse --git-dir >/dev/null 2>&1; then - if [[ -n "${VERSION_ARG:-}" ]]; then - clean_ver="${VERSION_ARG#v}" - if git_try_checkout "$clean_ver"; then - VERSION="$clean_ver" +resolve_version() { + if git rev-parse --git-dir >/dev/null 2>&1; then + if [[ -n "${VERSION_ARG:-}" ]]; then + local clean_ver="${VERSION_ARG#v}" + + if git_try_checkout "$clean_ver"; then + VERSION="$clean_ver" + else + echo "[WARN] Tag '${VERSION_ARG}' not found." + apply_channel_or_keep "$(choose_channel)" + fi else - echo "[WARN] Tag '${VERSION_ARG}' not found." - ch="$(choose_channel)" - apply_channel_or_keep "$ch" + apply_channel_or_keep "$(choose_channel)" fi else - ch="$(choose_channel)" - apply_channel_or_keep "$ch" + echo "Current directory is not a git repo; proceeding on current tree." + VERSION="${VERSION_ARG:-0.0.0}" fi -else - echo "Current directory is not a git repo; proceeding on current tree." - VERSION="${VERSION_ARG:-0.0.0}" -fi -VERSION="${VERSION#v}" -echo "[*] GUI version resolved as: ${VERSION}" + VERSION="${VERSION#v}" + echo "[*] GUI version resolved as: ${VERSION}" +} + +xray_url_for_rid() { + local rid="$1" + local ver="$2" + + case "$rid" in + linux-x64) echo "https://github.com/XTLS/Xray-core/releases/download/v${ver}/Xray-linux-64.zip" ;; + linux-arm64) echo "https://github.com/XTLS/Xray-core/releases/download/v${ver}/Xray-linux-arm64-v8a.zip" ;; + *) return 1 ;; + esac +} + +singbox_url_for_rid() { + local rid="$1" + local ver="$2" + + case "$rid" in + linux-x64) echo "https://github.com/SagerNet/sing-box/releases/download/v${ver}/sing-box-${ver}-linux-amd64.tar.gz" ;; + linux-arm64) echo "https://github.com/SagerNet/sing-box/releases/download/v${ver}/sing-box-${ver}-linux-arm64.tar.gz" ;; + *) return 1 ;; + esac +} + +bundle_url_for_rid() { + local rid="$1" + + case "$rid" in + linux-x64) echo "https://raw.githubusercontent.com/2dust/v2rayN-core-bin/refs/heads/master/v2rayN-linux-64.zip" ;; + linux-arm64) echo "https://raw.githubusercontent.com/2dust/v2rayN-core-bin/refs/heads/master/v2rayN-linux-arm64.zip" ;; + *) return 1 ;; + esac +} download_xray() { - local outdir="$1" rid="$2" ver="${XRAY_VER:-}" url tmp zipname="xray.zip" + local outdir="$1" + local rid="$2" + local ver="${XRAY_VER:-}" + local url="" + local tmp="" + mkdir -p "$outdir" + if [[ -z "$ver" ]]; then ver="$(curl -fsSL https://api.github.com/repos/XTLS/Xray-core/releases/latest \ - | grep -Eo '"tag_name":\s*"v[^"]+"' | sed -E 's/.*"v([^"]+)".*/\1/' | head -n1)" || true + | grep -Eo '"tag_name":\s*"v[^"]+"' \ + | sed -E 's/.*"v([^"]+)".*/\1/' \ + | head -n1)" || true fi + [[ -n "$ver" ]] || { echo "[xray] Failed to get version"; return 1; } - if [[ "$rid" == "linux-arm64" ]]; then - url="https://github.com/XTLS/Xray-core/releases/download/v${ver}/Xray-linux-arm64-v8a.zip" - else - url="https://github.com/XTLS/Xray-core/releases/download/v${ver}/Xray-linux-64.zip" - fi + url="$(xray_url_for_rid "$rid" "$ver")" || { echo "[xray] Unsupported RID: $rid"; return 1; } + echo "[+] Download xray: $url" + tmp="$(mktemp -d)" - curl -fL "$url" -o "$tmp/$zipname" - unzip -q "$tmp/$zipname" -d "$tmp" - install -m 755 "$tmp/xray" "$outdir/xray" + curl -fL "$url" -o "$tmp/xray.zip" || { rm -rf "$tmp"; return 1; } + unzip -q "$tmp/xray.zip" -d "$tmp" || { rm -rf "$tmp"; return 1; } + install -m 755 "$tmp/xray" "$outdir/xray" || { rm -rf "$tmp"; return 1; } rm -rf "$tmp" } download_singbox() { - # Download sing-box - local outdir="$1" rid="$2" ver="${SING_VER:-}" url tmp tarname="singbox.tar.gz" bin cronet + local outdir="$1" + local rid="$2" + local ver="${SING_VER:-}" + local url="" + local tmp="" + local bin="" + local cronet="" + mkdir -p "$outdir" + if [[ -z "$ver" ]]; then ver="$(curl -fsSL https://api.github.com/repos/SagerNet/sing-box/releases/latest \ | grep -Eo '"tag_name":\s*"v[^"]+"' \ | sed -E 's/.*"v([^"]+)".*/\1/' \ | head -n1)" || true fi + [[ -n "$ver" ]] || { echo "[sing-box] Failed to get version"; return 1; } - if [[ "$rid" == "linux-arm64" ]]; then - url="https://github.com/SagerNet/sing-box/releases/download/v${ver}/sing-box-${ver}-linux-arm64.tar.gz" - else - url="https://github.com/SagerNet/sing-box/releases/download/v${ver}/sing-box-${ver}-linux-amd64.tar.gz" - fi + url="$(singbox_url_for_rid "$rid" "$ver")" || { echo "[sing-box] Unsupported RID: $rid"; return 1; } + echo "[+] Download sing-box: $url" + tmp="$(mktemp -d)" - curl -fL "$url" -o "$tmp/$tarname" - tar -C "$tmp" -xzf "$tmp/$tarname" + curl -fL "$url" -o "$tmp/singbox.tar.gz" || { rm -rf "$tmp"; return 1; } + tar -C "$tmp" -xzf "$tmp/singbox.tar.gz" || { rm -rf "$tmp"; return 1; } + bin="$(find "$tmp" -type f -name 'sing-box' | head -n1 || true)" [[ -n "$bin" ]] || { echo "[!] sing-box unpack failed"; rm -rf "$tmp"; return 1; } - install -m 755 "$bin" "$outdir/sing-box" + + install -m 755 "$bin" "$outdir/sing-box" || { rm -rf "$tmp"; return 1; } + cronet="$(find "$tmp" -type f -name 'libcronet*.so*' | head -n1 || true)" - [[ -n "$cronet" ]] && install -m 644 "$cronet" "$outdir/libcronet.so" + [[ -n "$cronet" ]] && install -m 644 "$cronet" "$outdir/libcronet.so" || true + rm -rf "$tmp" } unify_geo_layout() { local outroot="$1" - mkdir -p "$outroot/bin" + local n local names=( - "geosite.dat" - "geoip.dat" - "geoip-only-cn-private.dat" - "Country.mmdb" - "geoip.metadb" + geosite.dat + geoip.dat + geoip-only-cn-private.dat + Country.mmdb + geoip.metadb ) + + mkdir -p "$outroot/bin" + for n in "${names[@]}"; do if [[ -f "$outroot/bin/xray/$n" ]]; then mv -f "$outroot/bin/xray/$n" "$outroot/bin/$n" @@ -301,52 +389,44 @@ download_geo_assets() { local outroot="$1" local bin_dir="$outroot/bin" local srss_dir="$bin_dir/srss" + local f="" + mkdir -p "$bin_dir" "$srss_dir" echo "[+] Download Xray Geo to ${bin_dir}" - curl -fsSL -o "$bin_dir/geosite.dat" \ - "https://github.com/Loyalsoldier/V2ray-rules-dat/releases/latest/download/geosite.dat" - curl -fsSL -o "$bin_dir/geoip.dat" \ - "https://github.com/Loyalsoldier/V2ray-rules-dat/releases/latest/download/geoip.dat" - curl -fsSL -o "$bin_dir/geoip-only-cn-private.dat" \ - "https://raw.githubusercontent.com/Loyalsoldier/geoip/release/geoip-only-cn-private.dat" - curl -fsSL -o "$bin_dir/Country.mmdb" \ - "https://raw.githubusercontent.com/Loyalsoldier/geoip/release/Country.mmdb" + curl -fsSL -o "$bin_dir/geosite.dat" "https://github.com/Loyalsoldier/V2ray-rules-dat/releases/latest/download/geosite.dat" + curl -fsSL -o "$bin_dir/geoip.dat" "https://github.com/Loyalsoldier/V2ray-rules-dat/releases/latest/download/geoip.dat" + curl -fsSL -o "$bin_dir/geoip-only-cn-private.dat" "https://raw.githubusercontent.com/Loyalsoldier/geoip/release/geoip-only-cn-private.dat" + curl -fsSL -o "$bin_dir/Country.mmdb" "https://raw.githubusercontent.com/Loyalsoldier/geoip/release/Country.mmdb" echo "[+] Download sing-box rule DB & rule-sets" - curl -fsSL -o "$bin_dir/geoip.metadb" \ - "https://github.com/MetaCubeX/meta-rules-dat/releases/latest/download/geoip.metadb" || true - - for f in \ - geoip-private.srs geoip-cn.srs geoip-facebook.srs geoip-fastly.srs \ - geoip-google.srs geoip-netflix.srs geoip-telegram.srs geoip-twitter.srs; do - curl -fsSL -o "$srss_dir/$f" \ - "https://raw.githubusercontent.com/2dust/sing-box-rules/rule-set-geoip/$f" || true + curl -fsSL -o "$bin_dir/geoip.metadb" "https://github.com/MetaCubeX/meta-rules-dat/releases/latest/download/geoip.metadb" + + for f in geoip-private.srs geoip-cn.srs geoip-facebook.srs geoip-fastly.srs geoip-google.srs geoip-netflix.srs geoip-telegram.srs geoip-twitter.srs; do + curl -fsSL -o "$srss_dir/$f" "https://raw.githubusercontent.com/2dust/sing-box-rules/refs/heads/rule-set-geoip/$f" done - for f in \ - geosite-cn.srs geosite-gfw.srs geosite-google.srs geosite-greatfire.srs \ - geosite-geolocation-cn.srs geosite-category-ads-all.srs geosite-private.srs; do - curl -fsSL -o "$srss_dir/$f" \ - "https://raw.githubusercontent.com/2dust/sing-box-rules/rule-set-geosite/$f" || true + for f in geosite-cn.srs geosite-gfw.srs geosite-google.srs geosite-greatfire.srs geosite-geolocation-cn.srs geosite-category-ads-all.srs geosite-private.srs; do + curl -fsSL -o "$srss_dir/$f" "https://raw.githubusercontent.com/2dust/sing-box-rules/refs/heads/rule-set-geosite/$f" done unify_geo_layout "$outroot" } -download_v2rayn_bundle() { - local outroot="$1" rid="$2" +populate_assets_zip_mode() { + local outroot="$1" + local rid="$2" local url="" - if [[ "$rid" == "linux-arm64" ]]; then - url="https://raw.githubusercontent.com/2dust/v2rayN-core-bin/refs/heads/master/v2rayN-linux-arm64.zip" - else - url="https://raw.githubusercontent.com/2dust/v2rayN-core-bin/refs/heads/master/v2rayN-linux-64.zip" - fi + local tmp="" + local nested_dir="" + + url="$(bundle_url_for_rid "$rid")" || { echo "[!] Bundle unsupported RID: $rid"; return 1; } + echo "[+] Try v2rayN bundle archive: $url" - local tmp zipname - tmp="$(mktemp -d)"; zipname="$tmp/v2rayn.zip" - curl -fL "$url" -o "$zipname" || { echo "[!] Bundle download failed"; return 1; } - unzip -q "$zipname" -d "$tmp" || { echo "[!] Bundle unzip failed"; return 1; } + + tmp="$(mktemp -d)" + curl -fL "$url" -o "$tmp/v2rayn.zip" || { echo "[!] Bundle download failed"; rm -rf "$tmp"; return 1; } + unzip -q "$tmp/v2rayn.zip" -d "$tmp" || { echo "[!] Bundle unzip failed"; rm -rf "$tmp"; return 1; } if [[ -d "$tmp/bin" ]]; then mkdir -p "$outroot/bin" @@ -358,7 +438,6 @@ download_v2rayn_bundle() { rm -f "$outroot/v2rayn.zip" 2>/dev/null || true find "$outroot" -type d -name "mihomo" -prune -exec rm -rf {} + 2>/dev/null || true - local nested_dir nested_dir="$(find "$outroot" -maxdepth 1 -type d -name 'v2rayN-linux-*' | head -n1 || true)" if [[ -n "$nested_dir" && -d "$nested_dir/bin" ]]; then mkdir -p "$outroot/bin" @@ -366,90 +445,71 @@ download_v2rayn_bundle() { rm -rf "$nested_dir" fi - # Unify to bin/ unify_geo_layout "$outroot" + rm -rf "$tmp" echo "[+] Bundle extracted to $outroot" } -BUILT_DEBS=() -BUILT_ALL=0 -OUTPUT_DIR="$HOME/debbuild" -mkdir -p "$OUTPUT_DIR" +populate_assets_netcore_mode() { + local outroot="$1" + local rid="$2" -build_for_arch() { - local short="$1" - local rid deb_arch outdir_name - case "$short" in - x64) rid="linux-x64"; deb_arch="amd64"; outdir_name="amd64" ;; - arm64) rid="linux-arm64"; deb_arch="arm64"; outdir_name="arm64" ;; - *) echo "Unknown arch '$short' (use x64|arm64)"; return 1 ;; - esac + mkdir -p "$outroot/bin/xray" "$outroot/bin/sing_box" - echo "[*] Building for target: $short (RID=$rid, DEB arch=$deb_arch)" + if [[ "$WITH_CORE" == "xray" || "$WITH_CORE" == "both" ]]; then + download_xray "$outroot/bin/xray" "$rid" || echo "[!] xray download failed (skipped)" + fi - dotnet clean "$PROJECT" -c Release - rm -rf "$(dirname "$PROJECT")/bin/Release/net10.0" || true + if [[ "$WITH_CORE" == "sing-box" || "$WITH_CORE" == "both" ]]; then + download_singbox "$outroot/bin/sing_box" "$rid" || echo "[!] sing-box download failed (skipped)" + fi - dotnet restore "$PROJECT" - dotnet publish "$PROJECT" \ - -c Release -r "$rid" \ - -p:PublishSingleFile=false \ - -p:SelfContained=true - - local RID_DIR="$rid" - local PUBDIR - PUBDIR="$(dirname "$PROJECT")/bin/Release/net10.0/${RID_DIR}/publish" - [[ -d "$PUBDIR" ]] || { echo "Publish directory not found: $PUBDIR"; return 1; } - - local WORKDIR PKGROOT STAGE DEBIAN_DIR - WORKDIR="$(mktemp -d)" - PKGROOT="v2rayN-publish" - STAGE="$WORKDIR/${PKGROOT}_${VERSION}_${deb_arch}" - DEBIAN_DIR="$STAGE/DEBIAN" - - mkdir -p "$STAGE/opt/v2rayN" - mkdir -p "$STAGE/usr/bin" - mkdir -p "$STAGE/usr/share/applications" - mkdir -p "$STAGE/usr/share/icons/hicolor/256x256/apps" - mkdir -p "$DEBIAN_DIR" - - # Stage publish content from source build - cp -a "$PUBDIR/." "$STAGE/opt/v2rayN/" - - local ICON_CANDIDATE - PROJECT_DIR="$(cd "$(dirname "$PROJECT")" && pwd)" - ICON_CANDIDATE="$PROJECT_DIR/v2rayN.png" - [[ -f "$ICON_CANDIDATE" ]] && cp "$ICON_CANDIDATE" "$STAGE/usr/share/icons/hicolor/256x256/apps/v2rayn.png" || true - - mkdir -p "$STAGE/opt/v2rayN/bin/xray" "$STAGE/opt/v2rayN/bin/sing_box" - - fetch_separate_cores_and_rules() { - local outroot="$1" - - if [[ "$WITH_CORE" == "xray" || "$WITH_CORE" == "both" ]]; then - download_xray "$outroot/bin/xray" "$RID_DIR" || echo "[!] xray download failed (skipped)" - fi - if [[ "$WITH_CORE" == "sing-box" || "$WITH_CORE" == "both" ]]; then - download_singbox "$outroot/bin/sing_box" "$RID_DIR" || echo "[!] sing-box download failed (skipped)" - fi - download_geo_assets "$outroot" || echo "[!] Geo rules download failed (skipped)" - } + download_geo_assets "$outroot" || echo "[!] Geo rules download failed (skipped)" +} + +stage_runtime_assets() { + local outroot="$1" + local rid="$2" + + mkdir -p "$outroot/bin/xray" "$outroot/bin/sing_box" if [[ "$FORCE_NETCORE" -eq 0 ]]; then - if download_v2rayn_bundle "$STAGE/opt/v2rayN" "$RID_DIR"; then + if populate_assets_zip_mode "$outroot" "$rid"; then echo "[*] Using v2rayN bundle bin assets." else echo "[*] Bundle failed, fallback to separate core + rules." - fetch_separate_cores_and_rules "$STAGE/opt/v2rayN" + populate_assets_netcore_mode "$outroot" "$rid" fi else echo "[*] --netcore specified: use separate core + rules." - fetch_separate_cores_and_rules "$STAGE/opt/v2rayN" + populate_assets_netcore_mode "$outroot" "$rid" fi +} - # Wrapper - install -m 755 /dev/stdin "$STAGE/usr/bin/v2rayn" <<'EOF' +describe_target() { + local short="$1" + + case "$short" in + x64) printf '%s\n%s\n' "linux-x64" "amd64" ;; + arm64) printf '%s\n%s\n' "linux-arm64" "arm64" ;; + *) echo "Unknown arch '$short' (use x64|arm64)" >&2; return 1 ;; + esac +} + +publish_binary() { + local rid="$1" + + dotnet clean "$PROJECT" -c Release + rm -rf "$(dirname "$PROJECT")/bin/Release/net10.0" || true + dotnet restore "$PROJECT" + dotnet publish "$PROJECT" -c Release -r "$rid" -p:PublishSingleFile=false -p:SelfContained=true +} + +write_launcher_file() { + local stage="$1" + + install -m 755 /dev/stdin "$stage/usr/bin/v2rayn" <<'EOF' #!/usr/bin/env bash set -euo pipefail DIR="/opt/v2rayN" @@ -469,12 +529,90 @@ echo "v2rayN launcher: no executable found in $DIR" >&2 ls -l "$DIR" >&2 || true exit 1 EOF +} + +write_desktop_file() { + local stage="$1" + + install -m 644 /dev/stdin "$stage/usr/share/applications/v2rayn.desktop" <<'EOF' +[Desktop Entry] +Type=Application +Name=v2rayN +Comment=v2rayN for Debian GNU Linux +Exec=v2rayn +Icon=v2rayn +Terminal=false +Categories=Network; +EOF +} - SHLIBS_DEPENDS="" - EXTRA_DEPENDS="libc6 (>= 2.34), fontconfig (>= 2.13.1), desktop-file-utils (>= 0.26), xdg-utils (>= 1.1.3), coreutils (>= 8.32), bash (>= 5.1), libfreetype6 (>= 2.11)" +write_maintainer_scripts() { + local debian_dir="$1" - mkdir -p "$WORKDIR/debian" - cat > "$WORKDIR/debian/control" </dev/null 2>&1 || true +if command -v gtk-update-icon-cache >/dev/null 2>&1; then + gtk-update-icon-cache -f /usr/share/icons/hicolor >/dev/null 2>&1 || true +fi +exit 0 +EOF + + install -m 755 /dev/stdin "$debian_dir/postrm" <<'EOF' +#!/bin/sh +set -e +update-desktop-database /usr/share/applications >/dev/null 2>&1 || true +if command -v gtk-update-icon-cache >/dev/null 2>&1; then + gtk-update-icon-cache -f /usr/share/icons/hicolor >/dev/null 2>&1 || true +fi +exit 0 +EOF +} + +package_binary() { + local short="$1" + local rid="$2" + local deb_arch="$3" + local pubdir="" + local workdir="" + local stage="" + local debian_dir="" + local project_dir="" + local icon_candidate="" + local shlibs_depends="" + local extra_depends="" + local final_depends="" + local multiarch="" + local sys_libdir="" + local sys_usrlibdir="" + local deb_out="" + + pubdir="$(dirname "$PROJECT")/bin/Release/net10.0/${rid}/publish" + [[ -d "$pubdir" ]] || { echo "Publish directory not found: $pubdir"; return 1; } + + workdir="$(mktemp -d)" + trap '[[ -n "${workdir:-}" ]] && rm -rf "$workdir"' RETURN + + stage="$workdir/${PKGROOT}_${VERSION}_${deb_arch}" + debian_dir="$stage/DEBIAN" + + mkdir -p "$stage/opt/v2rayN" "$stage/usr/bin" "$stage/usr/share/applications" "$stage/usr/share/icons/hicolor/256x256/apps" "$debian_dir" + cp -a "$pubdir/." "$stage/opt/v2rayN/" + + project_dir="$(cd "$(dirname "$PROJECT")" && pwd)" + icon_candidate="$project_dir/v2rayN.png" + [[ -f "$icon_candidate" ]] && cp "$icon_candidate" "$stage/usr/share/icons/hicolor/256x256/apps/v2rayn.png" || true + + stage_runtime_assets "$stage/opt/v2rayN" "$rid" + write_launcher_file "$stage" + write_desktop_file "$stage" + write_maintainer_scripts "$debian_dir" + + extra_depends="libc6 (>= 2.34), fontconfig (>= 2.13.1), desktop-file-utils (>= 0.26), xdg-utils (>= 1.1.3), coreutils (>= 8.32), bash (>= 5.1), libfreetype6 (>= 2.11)" + + mkdir -p "$workdir/debian" + cat > "$workdir/debian/control" < "$debian_dir/substvars" - : > "$DEBIAN_DIR/substvars" mapfile -t ELF_FILES < <( - find "$STAGE/opt/v2rayN" -type f \( -name "*.so*" -o -perm -111 \) ! -name 'libcoreclrtraceptprovider.so' + find "$stage/opt/v2rayN" -type f \( -name "*.so*" -o -perm -111 \) ! -name 'libcoreclrtraceptprovider.so' ) + if [[ "${#ELF_FILES[@]}" -gt 0 ]]; then ( - cd "$WORKDIR" + cd "$workdir" dpkg-shlibdeps \ - -l"$STAGE/opt/v2rayN" \ - -l"$SYS_LIBDIR" \ - -l"$SYS_USRLIBDIR" \ - -T"$DEBIAN_DIR/substvars" \ + -l"$stage/opt/v2rayN" \ + -l"$sys_libdir" \ + -l"$sys_usrlibdir" \ + -T"$debian_dir/substvars" \ "${ELF_FILES[@]}" ) >/dev/null 2>&1 || true fi - SHLIBS_DEPENDS="$(sed -n 's/^shlibs:Depends=//p' "$DEBIAN_DIR/substvars" | head -n1 || true)" + shlibs_depends="$(sed -n 's/^shlibs:Depends=//p' "$debian_dir/substvars" | head -n1 || true)" - if [[ -n "$SHLIBS_DEPENDS" ]]; then - SHLIBS_DEPENDS="$(echo "$SHLIBS_DEPENDS" \ + if [[ -n "$shlibs_depends" ]]; then + shlibs_depends="$(echo "$shlibs_depends" \ | sed -E 's/ *\([^)]*\)//g' \ | sed -E 's/ *, */, /g' \ | sed -E 's/^, *//; s/, *$//')" - FINAL_DEPENDS="${SHLIBS_DEPENDS}, ${EXTRA_DEPENDS}" + final_depends="${shlibs_depends}, ${extra_depends}" else - FINAL_DEPENDS="${EXTRA_DEPENDS}" + final_depends="${extra_depends}" fi - # Desktop file - install -m 644 /dev/stdin "$STAGE/usr/share/applications/v2rayn.desktop" <<'EOF' -[Desktop Entry] -Type=Application -Name=v2rayN -Comment=v2rayN for Debian GNU Linux -Exec=v2rayn -Icon=v2rayn -Terminal=false -Categories=Network; -EOF - - # Control file - cat > "$DEBIAN_DIR/control" < "$debian_dir/control" < Homepage: https://github.com/2dust/v2rayN Section: net Priority: optional -Depends: ${FINAL_DEPENDS} +Depends: ${final_depends} Description: v2rayN (Avalonia) GUI client for Linux Support vless / vmess / Trojan / http / socks / Anytls / Hysteria2 / Shadowsocks / tuic / WireGuard. EOF - # postinst - install -m 755 /dev/stdin "$DEBIAN_DIR/postinst" <<'EOF' -#!/bin/sh -set -e -update-desktop-database /usr/share/applications >/dev/null 2>&1 || true -if command -v gtk-update-icon-cache >/dev/null 2>&1; then - gtk-update-icon-cache -f /usr/share/icons/hicolor >/dev/null 2>&1 || true -fi -exit 0 -EOF + find "$stage/opt/v2rayN" -type d -exec chmod 0755 {} + + find "$stage/opt/v2rayN" -type f -exec chmod 0644 {} + + [[ -f "$stage/opt/v2rayN/v2rayN" ]] && chmod 0755 "$stage/opt/v2rayN/v2rayN" || true - # postrm - install -m 755 /dev/stdin "$DEBIAN_DIR/postrm" <<'EOF' -#!/bin/sh -set -e -update-desktop-database /usr/share/applications >/dev/null 2>&1 || true -if command -v gtk-update-icon-cache >/dev/null 2>&1; then - gtk-update-icon-cache -f /usr/share/icons/hicolor >/dev/null 2>&1 || true -fi -exit 0 -EOF - - # Normalize permissions - find "$STAGE/opt/v2rayN" -type d -exec chmod 0755 {} + - find "$STAGE/opt/v2rayN" -type f -exec chmod 0644 {} + - [[ -f "$STAGE/opt/v2rayN/v2rayN" ]] && chmod 0755 "$STAGE/opt/v2rayN/v2rayN" || true - - local deb_out deb_out="$OUTPUT_DIR/v2rayn_${VERSION}_${deb_arch}.deb" - - dpkg-deb --root-owner-group --build "$STAGE" "$deb_out" + dpkg-deb --root-owner-group --build "$stage" "$deb_out" echo "Build done for $short. DEB at:" echo " $deb_out" BUILT_DEBS+=("$deb_out") +} - rm -rf "$WORKDIR" +select_targets() { + case "${ARCH_OVERRIDE:-}" in + all) printf '%s\n' x64 arm64 ;; + x64|amd64) printf '%s\n' x64 ;; + arm64|aarch64) printf '%s\n' arm64 ;; + "") + case "$HOST_ARCH" in + x86_64) printf '%s\n' x64 ;; + aarch64) printf '%s\n' arm64 ;; + *) return 1 ;; + esac + ;; + *) + echo "Unknown --arch '${ARCH_OVERRIDE}'. Use x64|arm64|all." >&2 + return 1 + ;; + esac } -case "${ARCH_OVERRIDE:-}" in - all) targets=(x64 arm64); BUILT_ALL=1 ;; - x64|amd64) targets=(x64) ;; - arm64|aarch64) targets=(arm64) ;; - "") targets=($([[ "$host_arch" == "aarch64" ]] && echo arm64 || echo x64)) ;; - *) echo "Unknown --arch '${ARCH_OVERRIDE}'. Use x64|arm64|all."; exit 1 ;; -esac +build_one_target() { + local short="$1" + local meta=() + local rid="" + local deb_arch="" + + mapfile -t meta < <(describe_target "$short") || return 1 + rid="${meta[0]}" + deb_arch="${meta[1]}" -for arch in "${targets[@]}"; do - build_for_arch "$arch" -done + echo "[*] Building for target: $short (RID=$rid, DEB arch=$deb_arch)" + publish_binary "$rid" + package_binary "$short" "$rid" "$deb_arch" +} + +print_summary() { + local pkg="" + + echo "" + echo "================ Build Summary =================" + if [[ "${#BUILT_DEBS[@]}" -gt 0 ]]; then + echo "Output directory: $OUTPUT_DIR" + for pkg in "${BUILT_DEBS[@]}"; do + echo "$pkg" + done + else + echo "No DEBs detected in summary (check build logs above)." + fi + echo "===============================================" +} + +main() { + local targets=() + local arch="" -echo "" -echo "================ Build Summary =================" -if [[ "${#BUILT_DEBS[@]}" -gt 0 ]]; then - echo "Output directory: $OUTPUT_DIR" - for pkg in "${BUILT_DEBS[@]}"; do - echo "$pkg" + parse_args "$@" + detect_environment + install_dependencies + prepare_workspace + resolve_version + + mapfile -t targets < <(select_targets) + + for arch in "${targets[@]}"; do + build_one_target "$arch" done -else - echo "No DEBs detected in summary (check build logs above)." -fi -echo "===============================================" + + print_summary +} + +main "$@" \ No newline at end of file diff --git a/package-rhel-riscv.sh b/package-rhel-riscv.sh index 9136238fb77..d716c51be04 100644 --- a/package-rhel-riscv.sh +++ b/package-rhel-riscv.sh @@ -1,232 +1,158 @@ #!/usr/bin/env bash set -euo pipefail -# Require Red Hat base branch -. /etc/os-release - -case "${ID:-}" in - rhel|rocky|almalinux|fedora|centos) - echo "Detected supported system: ${NAME:-$ID} ${VERSION_ID:-}" - ;; - *) - echo "Unsupported system: ${NAME:-unknown} (${ID:-unknown})." - echo "This script only supports: RHEL / Rocky / AlmaLinux / Fedora / CentOS." - exit 1 - ;; -esac +VERSION_ARG="" +WITH_CORE="both" +FORCE_NETCORE=0 +BUILD_FROM="" +XRAY_VER="${XRAY_VER:-}" +SING_VER="${SING_VER:-}" -# Kernel version MIN_KERNEL="5.10" -CURRENT_KERNEL="$(uname -r)" - -lowest="$(printf '%s\n%s\n' "$MIN_KERNEL" "$CURRENT_KERNEL" | sort -V | head -n1)" - -if [[ "$lowest" != "$MIN_KERNEL" ]]; then - echo "Kernel $CURRENT_KERNEL is below $MIN_KERNEL" - exit 1 -fi - -echo "[OK] Kernel $CURRENT_KERNEL verified." - -# Config & Parse arguments -VERSION_ARG="${1:-}" # Pass version number like 7.13.8, or leave empty -WITH_CORE="both" # Default: bundle both xray+sing-box -FORCE_NETCORE=0 # --netcore => skip archive bundle, use separate downloads -BUILD_FROM="" # --buildfrom 1|2|3 to select channel non-interactively -DOTNET_RISCV_VERSION="10.0.105" -DOTNET_RISCV_BASE="https://github.com/filipnavara/dotnet-riscv/releases/download" +PKGROOT="v2rayN-publish" +PROJECT_HINT="v2rayN.Desktop/v2rayN.Desktop.csproj" +RPM_TOPDIR="${HOME}/rpmbuild" +DOTNET_TFM="net10.0" +DOTNET_RISCV_VERSION="10.0.107" +DOTNET_RISCV_BASE="https://github.com/xujiegb/dotnet-riscv/releases/download" DOTNET_RISCV_FILE="dotnet-sdk-${DOTNET_RISCV_VERSION}-linux-riscv64.tar.gz" DOTNET_SDK_URL="${DOTNET_RISCV_BASE}/${DOTNET_RISCV_VERSION}/${DOTNET_RISCV_FILE}" SKIA_VER="${SKIA_VER:-3.119.2}" -HARFBUZZ_VER="${HARFBUZZ_VER:-8.3.1.1}" - -# If the first argument starts with --, do not treat it as a version number -if [[ "${VERSION_ARG:-}" == --* ]]; then - VERSION_ARG="" -fi -# Take the first non --* argument as version, discard it -if [[ -n "${VERSION_ARG:-}" ]]; then shift || true; fi - -# Parse remaining optional arguments -while [[ $# -gt 0 ]]; do - case "$1" in - --with-core) WITH_CORE="${2:-both}"; shift 2;; - --xray-ver) XRAY_VER="${2:-}"; shift 2;; - --singbox-ver) SING_VER="${2:-}"; shift 2;; - --netcore) FORCE_NETCORE=1; shift;; - --buildfrom) BUILD_FROM="${2:-}"; shift 2;; - *) - if [[ -z "${VERSION_ARG:-}" ]]; then VERSION_ARG="$1"; fi - shift;; - esac -done - -# Conflict: version number AND --buildfrom cannot be used together -if [[ -n "${VERSION_ARG:-}" && -n "${BUILD_FROM:-}" ]]; then - echo "You cannot specify both an explicit version and --buildfrom at the same time." - echo " Provide either a version (e.g. 7.14.0) OR --buildfrom 1|2|3." - exit 1 -fi +HARFBUZZ_VER="${HARFBUZZ_VER:-8.3.1.3}" -apply_riscv_patch() { - # Ensure all project files target net10.0 - find . -type f \( -name "*.csproj" -o -name "*.props" -o -name "*.targets" \) \ - -exec sed -i 's/net8\.0/net10.0/g' {} + +OS_ID="" +OS_NAME="" +OS_VERSION_ID="" +HOST_ARCH="" +SCRIPT_DIR="" +PROJECT="" +VERSION="" +BUILT_ALL=0 - # Patch all Directory.Packages.props for SkiaSharp/HarfBuzzSharp - while IFS= read -r -d '' f; do - # replace existing versions if present - sed -i \ - -e "s###g" \ - -e "s###g" \ - -e "s###g" \ - -e "s###g" \ - "$f" +declare -a BUILT_RPMS=() - grep -q 'PackageVersion Include="SkiaSharp"' "$f" || \ - sed -i "/<\/ItemGroup>/i\ " "$f" +die() { + echo "$*" >&2 + exit 1 +} - grep -q 'PackageVersion Include="SkiaSharp.NativeAssets.Linux"' "$f" || \ - sed -i "/<\/ItemGroup>/i\ " "$f" +parse_args() { + local first_arg="${1:-}" - grep -q 'PackageVersion Include="HarfBuzzSharp"' "$f" || \ - sed -i "/<\/ItemGroup>/i\ " "$f" + if [[ -n "$first_arg" && "$first_arg" != --* ]]; then + VERSION_ARG="$first_arg" + shift || true + fi - grep -q 'PackageVersion Include="HarfBuzzSharp.NativeAssets.Linux"' "$f" || \ - sed -i "/<\/ItemGroup>/i\ " "$f" - done < <(find . -type f -name 'Directory.Packages.props' -print0) + while [[ $# -gt 0 ]]; do + case "$1" in + --with-core) WITH_CORE="${2:-both}"; shift 2 ;; + --xray-ver) XRAY_VER="${2:-}"; shift 2 ;; + --singbox-ver) SING_VER="${2:-}"; shift 2 ;; + --netcore) FORCE_NETCORE=1; shift ;; + --buildfrom) BUILD_FROM="${2:-}"; shift 2 ;; + *) + [[ -n "${VERSION_ARG:-}" ]] || VERSION_ARG="$1" + shift + ;; + esac + done - # Patch SDK bundled RIDs - f="$(find "$DOTNET_ROOT/sdk/$(dotnet --version)" -type f -name 'Microsoft.NETCoreSdk.BundledVersions.props' | head -n1 || true)" - [[ -f "$f" ]] && sed -i \ - -e 's/linux-arm64/&;linux-riscv64/g' \ - -e 's/linux-musl-arm64/&;linux-musl-riscv64/g' \ - "$f" + if [[ -n "${VERSION_ARG:-}" && -n "${BUILD_FROM:-}" ]]; then + die "You cannot specify both an explicit version and --buildfrom at the same time. + Provide either a version (e.g. 7.14.0) OR --buildfrom 1|2|3." + fi } -build_sqlite_native_riscv64() { - local outdir="$1" - local workdir sqlite_year sqlite_ver sqlite_zip srcdir +detect_environment() { + local current_kernel="" + local lowest="" - mkdir -p "$outdir" - workdir="$(mktemp -d)" + . /etc/os-release - # SQLite 3.51.3 amalgamation - sqlite_year="2026" - sqlite_ver="3510300" - sqlite_zip="sqlite-amalgamation-${sqlite_ver}.zip" + OS_ID="${ID:-}" + OS_NAME="${NAME:-$OS_ID}" + OS_VERSION_ID="${VERSION_ID:-}" + HOST_ARCH="$(uname -m)" - echo "[+] Download SQLite amalgamation: ${sqlite_zip}" - curl -fL "https://www.sqlite.org/${sqlite_year}/${sqlite_zip}" -o "${workdir}/${sqlite_zip}" + case "$OS_ID" in + rhel|rocky|almalinux|fedora|centos) + echo "Detected supported system: ${OS_NAME:-$OS_ID} ${OS_VERSION_ID:-}" + ;; + *) + die "Unsupported system: ${OS_NAME:-unknown} (${OS_ID:-unknown}). +This script only supports: RHEL / Rocky / AlmaLinux / Fedora / CentOS." + ;; + esac - unzip -q "${workdir}/${sqlite_zip}" -d "$workdir" - srcdir="$(find "$workdir" -maxdepth 1 -type d -name 'sqlite-amalgamation-*' | head -n1 || true)" - [[ -n "$srcdir" ]] || { echo "[!] SQLite source unpack failed"; rm -rf "$workdir"; return 1; } + case "$HOST_ARCH" in + riscv64) ;; + *) die "Only supports riscv64" ;; + esac - echo "[+] Build libe_sqlite3.so for riscv64" - gcc -shared -fPIC -O2 \ - -DSQLITE_THREADSAFE=1 \ - -DSQLITE_ENABLE_FTS5 \ - -DSQLITE_ENABLE_RTREE \ - -DSQLITE_ENABLE_JSON1 \ - -o "${outdir}/libe_sqlite3.so" "${srcdir}/sqlite3.c" -ldl -lpthread + current_kernel="$(uname -r)" + lowest="$(printf '%s\n%s\n' "$MIN_KERNEL" "$current_kernel" | sort -V | head -n1)" - rm -rf "$workdir" + [[ "$lowest" == "$MIN_KERNEL" ]] || die "Kernel $current_kernel is below $MIN_KERNEL" + echo "[OK] Kernel $current_kernel verified." } -copy_skiasharp_native_riscv64() { - local outdir="$1" - local skia_so="" - local harfbuzz_so="" +install_dependencies() { + local install_ok=0 + local tmp_dotnet="" - mkdir -p "$outdir" + if command -v dnf >/dev/null 2>&1; then + sudo dnf -y install \ + rpm-build rpmdevtools curl unzip tar jq rsync git python3 \ + glibc-devel kernel-headers libatomic file ca-certificates libicu \ + && install_ok=1 - skia_so="$(find "$HOME/.nuget/packages" -path "*/skiasharp.nativeassets.linux/${SKIA_VER}/runtimes/linux-riscv64/native/libSkiaSharp.so" | head -n1 || true)" - if [[ -z "$skia_so" ]]; then - skia_so="$(find "$HOME/.nuget/packages" -path "*/runtimes/linux-riscv64/native/libSkiaSharp.so" | head -n1 || true)" - fi + mkdir -p "$HOME/.dotnet" + tmp_dotnet="$(mktemp -d)" + curl -fL "$DOTNET_SDK_URL" -o "$tmp_dotnet/$DOTNET_RISCV_FILE" + tar -C "$HOME/.dotnet" -xzf "$tmp_dotnet/$DOTNET_RISCV_FILE" + rm -rf "$tmp_dotnet" - harfbuzz_so="$(find "$HOME/.nuget/packages" -path "*/harfbuzzsharp.nativeassets.linux/${HARFBUZZ_VER}/runtimes/linux-riscv64/native/libHarfBuzzSharp.so" | head -n1 || true)" - if [[ -z "$harfbuzz_so" ]]; then - harfbuzz_so="$(find "$HOME/.nuget/packages" -path "*/runtimes/linux-riscv64/native/libHarfBuzzSharp.so" | head -n1 || true)" - fi + export PATH="$HOME/.dotnet:$PATH" + export DOTNET_ROOT="$HOME/.dotnet" - if [[ -n "$skia_so" && -f "$skia_so" ]]; then - echo "[+] Copy libSkiaSharp.so from NuGet cache" - install -m 755 "$skia_so" "$outdir/libSkiaSharp.so" - else - echo "[WARN] libSkiaSharp.so for linux-riscv64 not found in NuGet cache" + dotnet --info >/dev/null 2>&1 || install_ok=0 fi - if [[ -n "$harfbuzz_so" && -f "$harfbuzz_so" ]]; then - echo "[+] Copy libHarfBuzzSharp.so from NuGet cache" - install -m 755 "$harfbuzz_so" "$outdir/libHarfBuzzSharp.so" - else - echo "[WARN] libHarfBuzzSharp.so for linux-riscv64 not found in NuGet cache" + if [[ "$install_ok" -ne 1 ]]; then + echo "Could not auto-install dependencies for '$OS_ID'. Make sure these are available:" + echo "dotnet-riscv SDK, curl, unzip, tar, rsync, git, python3, rpm, rpmdevtools, rpm-build (on Red Hat branch)" + exit 1 fi } -# Check and install dependencies -host_arch="$(uname -m)" -[[ "$host_arch" == "riscv64" ]] || { echo "Only supports riscv64"; exit 1; } - -install_ok=0 +prepare_workspace() { + SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" + cd "$SCRIPT_DIR" -if command -v dnf >/dev/null 2>&1; then - sudo dnf -y install \ - rpm-build rpmdevtools curl unzip tar jq rsync git python3 gcc make \ - glibc-devel kernel-headers libatomic file ca-certificates libicu\ - && install_ok=1 - - mkdir -p "$HOME/.dotnet" - tmp_dotnet="$(mktemp -d)" - curl -fL "$DOTNET_SDK_URL" -o "$tmp_dotnet/$DOTNET_RISCV_FILE" - tar -C "$HOME/.dotnet" -xzf "$tmp_dotnet/$DOTNET_RISCV_FILE" - rm -rf "$tmp_dotnet" - - export PATH="$HOME/.dotnet:$PATH" - export DOTNET_ROOT="$HOME/.dotnet" - - dotnet --info >/dev/null 2>&1 || install_ok=0 -fi - -if [[ "$install_ok" -ne 1 ]]; then - echo "Could not auto-install dependencies for '$ID'. Make sure these are available:" - echo "dotnet-riscv SDK, curl, unzip, tar, rsync, git, python3, gcc, rpm, rpmdevtools, rpm-build (on Red Hat branch)" - exit 1 -fi - -# Root directory -SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" -cd "$SCRIPT_DIR" - -# Git submodules (best effort) -if [[ -f .gitmodules ]]; then - git submodule sync --recursive || true - git submodule update --init --recursive || true -fi + if [[ -f .gitmodules ]]; then + git submodule sync --recursive || true + git submodule update --init --recursive || true + fi -# Locate project -PROJECT="v2rayN.Desktop/v2rayN.Desktop.csproj" -if [[ ! -f "$PROJECT" ]]; then - PROJECT="$(find . -maxdepth 3 -name 'v2rayN.Desktop.csproj' | head -n1 || true)" -fi -[[ -f "$PROJECT" ]] || { echo "v2rayN.Desktop.csproj not found"; exit 1; } + PROJECT="$PROJECT_HINT" + [[ -f "$PROJECT" ]] || PROJECT="$(find . -maxdepth 3 -name 'v2rayN.Desktop.csproj' | head -n1 || true)" + [[ -f "$PROJECT" ]] || die "v2rayN.Desktop.csproj not found" +} choose_channel() { - # If --buildfrom provided, map it directly and skip interaction. + local ch="latest" + local sel="" + if [[ -n "${BUILD_FROM:-}" ]]; then case "$BUILD_FROM" in - 1) echo "latest"; return 0;; - 2) echo "prerelease"; return 0;; - 3) echo "keep"; return 0;; - *) echo "[ERROR] Invalid --buildfrom value: ${BUILD_FROM}. Use 1|2|3." >&2; exit 1;; + 1) echo "latest"; return 0 ;; + 2) echo "prerelease"; return 0 ;; + 3) echo "keep"; return 0 ;; + *) die "[ERROR] Invalid --buildfrom value: ${BUILD_FROM}. Use 1|2|3." ;; esac fi - # Print menu to stderr and read from /dev/tty so stdout only carries the token. - local ch="latest" sel="" - if [[ -t 0 ]]; then echo "[?] Choose v2rayN release channel:" >&2 echo " 1) Latest (stable) [default]" >&2 @@ -257,29 +183,35 @@ get_latest_tag_prerelease() { | sed 's/^v//' } +sync_submodules() { + if [[ -f .gitmodules ]]; then + git submodule sync --recursive || true + git submodule update --init --recursive || true + fi +} + git_try_checkout() { - # Try a series of refs and checkout when found. - local want="$1" ref="" + local want="$1" + local ref="" + if git rev-parse --git-dir >/dev/null 2>&1; then git fetch --tags --force --prune --depth=1 || true - if git rev-parse "refs/tags/${want}" >/dev/null 2>&1; then - ref="${want}" - fi + git rev-parse "refs/tags/${want}" >/dev/null 2>&1 && ref="$want" + if [[ -n "$ref" ]]; then echo "[OK] Found ref '${ref}', checking out..." - git checkout -f "${ref}" - if [[ -f .gitmodules ]]; then - git submodule sync --recursive || true - git submodule update --init --recursive || true - fi + git checkout -f "$ref" + sync_submodules return 0 fi fi + return 1 } apply_channel_or_keep() { - local ch="$1" tag + local ch="$1" + local tag="" if [[ "$ch" == "keep" ]]; then echo "[*] Keep current repository state (no checkout)." @@ -289,103 +221,215 @@ apply_channel_or_keep() { fi echo "[*] Resolving ${ch} tag from GitHub releases..." - if [[ "$ch" == "prerelease" ]]; then - tag="$(get_latest_tag_prerelease || true)" - else - tag="$(get_latest_tag_latest || true)" - fi - [[ -n "$tag" ]] || { echo "Failed to resolve latest tag for channel '${ch}'."; exit 1; } + case "$ch" in + latest) tag="$(get_latest_tag_latest || true)" ;; + prerelease) tag="$(get_latest_tag_prerelease || true)" ;; + *) die "Failed to resolve latest tag for channel '${ch}'." ;; + esac + + [[ -n "$tag" ]] || die "Failed to resolve latest tag for channel '${ch}'." + echo "[*] Latest tag for '${ch}': ${tag}" - git_try_checkout "$tag" || { echo "Failed to checkout '${tag}'."; exit 1; } + git_try_checkout "$tag" || die "Failed to checkout '${tag}'." VERSION="${tag#v}" } -if git rev-parse --git-dir >/dev/null 2>&1; then - if [[ -n "${VERSION_ARG:-}" ]]; then - clean_ver="${VERSION_ARG#v}" - if git_try_checkout "$clean_ver"; then - VERSION="$clean_ver" +resolve_version() { + if git rev-parse --git-dir >/dev/null 2>&1; then + if [[ -n "${VERSION_ARG:-}" ]]; then + local clean_ver="${VERSION_ARG#v}" + + if git_try_checkout "$clean_ver"; then + VERSION="$clean_ver" + else + echo "[WARN] Tag '${VERSION_ARG}' not found." + apply_channel_or_keep "$(choose_channel)" + fi else - echo "[WARN] Tag '${VERSION_ARG}' not found." - ch="$(choose_channel)" - apply_channel_or_keep "$ch" + apply_channel_or_keep "$(choose_channel)" fi else - ch="$(choose_channel)" - apply_channel_or_keep "$ch" + echo "Current directory is not a git repo; proceeding on current tree." + VERSION="${VERSION_ARG:-0.0.0}" + fi + + VERSION="${VERSION#v}" + echo "[*] GUI version resolved as: ${VERSION}" +} + +apply_riscv_patch() { + local f="" + + find . -type f \( -name "*.csproj" -o -name "*.props" -o -name "*.targets" \) \ + -exec sed -Ei 's#[^<]+#'"$DOTNET_TFM"'#g' {} + + + while IFS= read -r -d '' f; do + sed -i \ + -e "s###g" \ + -e "s###g" \ + -e "s###g" \ + -e "s###g" \ + "$f" + + grep -q 'PackageVersion Include="SkiaSharp"' "$f" || \ + sed -i "/<\/ItemGroup>/i\ " "$f" + + grep -q 'PackageVersion Include="SkiaSharp.NativeAssets.Linux"' "$f" || \ + sed -i "/<\/ItemGroup>/i\ " "$f" + + grep -q 'PackageVersion Include="HarfBuzzSharp"' "$f" || \ + sed -i "/<\/ItemGroup>/i\ " "$f" + + grep -q 'PackageVersion Include="HarfBuzzSharp.NativeAssets.Linux"' "$f" || \ + sed -i "/<\/ItemGroup>/i\ " "$f" + done < <(find . -type f -name 'Directory.Packages.props' -print0) + + f="$(find "$DOTNET_ROOT/sdk/$(dotnet --version)" -type f -name 'Microsoft.NETCoreSdk.BundledVersions.props' | head -n1 || true)" + if [[ -f "$f" ]] && ! grep -q 'linux-riscv64' "$f"; then + sed -i \ + -e 's/linux-arm64/&;linux-riscv64/g' \ + -e 's/linux-musl-arm64/&;linux-musl-riscv64/g' \ + "$f" + fi +} + +copy_skiasharp_native_riscv64() { + local outdir="$1" + local skia_so="" + local harfbuzz_so="" + + mkdir -p "$outdir" + + skia_so="$(find "$HOME/.nuget/packages" -path "*/skiasharp.nativeassets.linux/${SKIA_VER}/runtimes/linux-riscv64/native/libSkiaSharp.so" | head -n1 || true)" + [[ -n "$skia_so" ]] || skia_so="$(find "$HOME/.nuget/packages" -path "*/runtimes/linux-riscv64/native/libSkiaSharp.so" | head -n1 || true)" + + harfbuzz_so="$(find "$HOME/.nuget/packages" -path "*/harfbuzzsharp.nativeassets.linux/${HARFBUZZ_VER}/runtimes/linux-riscv64/native/libHarfBuzzSharp.so" | head -n1 || true)" + [[ -n "$harfbuzz_so" ]] || harfbuzz_so="$(find "$HOME/.nuget/packages" -path "*/runtimes/linux-riscv64/native/libHarfBuzzSharp.so" | head -n1 || true)" + + if [[ -n "$skia_so" && -f "$skia_so" ]]; then + echo "[+] Copy libSkiaSharp.so from NuGet cache" + install -m 755 "$skia_so" "$outdir/libSkiaSharp.so" + else + echo "[WARN] libSkiaSharp.so for linux-riscv64 not found in NuGet cache" + fi + + if [[ -n "$harfbuzz_so" && -f "$harfbuzz_so" ]]; then + echo "[+] Copy libHarfBuzzSharp.so from NuGet cache" + install -m 755 "$harfbuzz_so" "$outdir/libHarfBuzzSharp.so" + else + echo "[WARN] libHarfBuzzSharp.so for linux-riscv64 not found in NuGet cache" fi -else - echo "Current directory is not a git repo; proceeding on current tree." - VERSION="${VERSION_ARG:-0.0.0}" -fi +} + +xray_url_for_rid() { + local rid="$1" + local ver="$2" -VERSION="${VERSION#v}" -echo "[*] GUI version resolved as: ${VERSION}" + case "$rid" in + linux-riscv64) echo "https://github.com/XTLS/Xray-core/releases/download/v${ver}/Xray-linux-riscv64.zip" ;; + *) return 1 ;; + esac +} + +singbox_url_for_rid() { + local rid="$1" + local ver="$2" + + case "$rid" in + linux-riscv64) echo "https://github.com/SagerNet/sing-box/releases/download/v${ver}/sing-box-${ver}-linux-riscv64.tar.gz" ;; + *) return 1 ;; + esac +} -# riscv64 patch -apply_riscv_patch +bundle_url_for_rid() { + local rid="$1" + + case "$rid" in + linux-riscv64) echo "https://raw.githubusercontent.com/2dust/v2rayN-core-bin/refs/heads/master/v2rayN-linux-riscv64.zip" ;; + *) return 1 ;; + esac +} -# Helpers for core download_xray() { - # Download Xray core - local outdir="$1" rid="$2" ver="${XRAY_VER:-}" url="" tmp zipname="xray.zip" + local outdir="$1" + local rid="$2" + local ver="${XRAY_VER:-}" + local url="" + local tmp="" + mkdir -p "$outdir" + if [[ -z "$ver" ]]; then ver="$(curl -fsSL https://api.github.com/repos/XTLS/Xray-core/releases/latest \ - | grep -Eo '"tag_name":\s*"v[^"]+"' | sed -E 's/.*"v([^"]+)".*/\1/' | head -n1)" || true + | grep -Eo '"tag_name":\s*"v[^"]+"' \ + | sed -E 's/.*"v([^"]+)".*/\1/' \ + | head -n1)" || true fi + [[ -n "$ver" ]] || { echo "[xray] Failed to get version"; return 1; } - if [[ "$rid" == "linux-riscv64" ]]; then - url="https://github.com/XTLS/Xray-core/releases/download/v${ver}/Xray-linux-riscv64.zip" - fi - [[ -n "$url" ]] || { echo "[xray] Unsupported RID: $rid"; return 1; } + url="$(xray_url_for_rid "$rid" "$ver")" || { echo "[xray] Unsupported RID: $rid"; return 1; } + echo "[+] Download xray: $url" + tmp="$(mktemp -d)" - curl -fL "$url" -o "$tmp/$zipname" - unzip -q "$tmp/$zipname" -d "$tmp" - install -m 755 "$tmp/xray" "$outdir/xray" + curl -fL "$url" -o "$tmp/xray.zip" || { rm -rf "$tmp"; return 1; } + unzip -q "$tmp/xray.zip" -d "$tmp" || { rm -rf "$tmp"; return 1; } + install -m 755 "$tmp/xray" "$outdir/xray" || { rm -rf "$tmp"; return 1; } rm -rf "$tmp" } download_singbox() { - # Download sing-box - local outdir="$1" rid="$2" ver="${SING_VER:-}" url="" tmp tarname="singbox.tar.gz" bin cronet + local outdir="$1" + local rid="$2" + local ver="${SING_VER:-}" + local url="" + local tmp="" + local bin="" + local cronet="" + mkdir -p "$outdir" + if [[ -z "$ver" ]]; then ver="$(curl -fsSL https://api.github.com/repos/SagerNet/sing-box/releases/latest \ | grep -Eo '"tag_name":\s*"v[^"]+"' \ | sed -E 's/.*"v([^"]+)".*/\1/' \ | head -n1)" || true fi + [[ -n "$ver" ]] || { echo "[sing-box] Failed to get version"; return 1; } - if [[ "$rid" == "linux-riscv64" ]]; then - url="https://github.com/SagerNet/sing-box/releases/download/v${ver}/sing-box-${ver}-linux-riscv64.tar.gz" - fi - [[ -n "$url" ]] || { echo "[sing-box] Unsupported RID: $rid"; return 1; } + url="$(singbox_url_for_rid "$rid" "$ver")" || { echo "[sing-box] Unsupported RID: $rid"; return 1; } + echo "[+] Download sing-box: $url" + tmp="$(mktemp -d)" - curl -fL "$url" -o "$tmp/$tarname" - tar -C "$tmp" -xzf "$tmp/$tarname" + curl -fL "$url" -o "$tmp/singbox.tar.gz" || { rm -rf "$tmp"; return 1; } + tar -C "$tmp" -xzf "$tmp/singbox.tar.gz" || { rm -rf "$tmp"; return 1; } + bin="$(find "$tmp" -type f -name 'sing-box' | head -n1 || true)" [[ -n "$bin" ]] || { echo "[!] sing-box unpack failed"; rm -rf "$tmp"; return 1; } - install -m 755 "$bin" "$outdir/sing-box" + + install -m 755 "$bin" "$outdir/sing-box" || { rm -rf "$tmp"; return 1; } + cronet="$(find "$tmp" -type f -name 'libcronet*.so*' | head -n1 || true)" - [[ -n "$cronet" ]] && install -m 644 "$cronet" "$outdir/libcronet.so" + [[ -n "$cronet" ]] && install -m 644 "$cronet" "$outdir/libcronet.so" || true + rm -rf "$tmp" } -# Move geo files to outroot/bin unify_geo_layout() { local outroot="$1" - mkdir -p "$outroot/bin" - local names=( \ - "geosite.dat" \ - "geoip.dat" \ - "geoip-only-cn-private.dat" \ - "Country.mmdb" \ - "geoip.metadb" \ + local n + local names=( + geosite.dat + geoip.dat + geoip-only-cn-private.dat + Country.mmdb + geoip.metadb ) + + mkdir -p "$outroot/bin" + for n in "${names[@]}"; do if [[ -f "$outroot/bin/xray/$n" ]]; then mv -f "$outroot/bin/xray/$n" "$outroot/bin/$n" @@ -393,57 +437,48 @@ unify_geo_layout() { done } -# Download geo/rule assets download_geo_assets() { local outroot="$1" local bin_dir="$outroot/bin" local srss_dir="$bin_dir/srss" + local f="" + mkdir -p "$bin_dir" "$srss_dir" echo "[+] Download Xray Geo to ${bin_dir}" - curl -fsSL -o "$bin_dir/geosite.dat" \ - "https://github.com/Loyalsoldier/V2ray-rules-dat/releases/latest/download/geosite.dat" - curl -fsSL -o "$bin_dir/geoip.dat" \ - "https://github.com/Loyalsoldier/V2ray-rules-dat/releases/latest/download/geoip.dat" - curl -fsSL -o "$bin_dir/geoip-only-cn-private.dat" \ - "https://raw.githubusercontent.com/Loyalsoldier/geoip/release/geoip-only-cn-private.dat" - curl -fsSL -o "$bin_dir/Country.mmdb" \ - "https://raw.githubusercontent.com/Loyalsoldier/geoip/release/Country.mmdb" + curl -fsSL -o "$bin_dir/geosite.dat" "https://github.com/Loyalsoldier/V2ray-rules-dat/releases/latest/download/geosite.dat" + curl -fsSL -o "$bin_dir/geoip.dat" "https://github.com/Loyalsoldier/V2ray-rules-dat/releases/latest/download/geoip.dat" + curl -fsSL -o "$bin_dir/geoip-only-cn-private.dat" "https://raw.githubusercontent.com/Loyalsoldier/geoip/release/geoip-only-cn-private.dat" + curl -fsSL -o "$bin_dir/Country.mmdb" "https://raw.githubusercontent.com/Loyalsoldier/geoip/release/Country.mmdb" echo "[+] Download sing-box rule DB & rule-sets" - curl -fsSL -o "$bin_dir/geoip.metadb" \ - "https://github.com/MetaCubeX/meta-rules-dat/releases/latest/download/geoip.metadb" || true - - for f in \ - geoip-private.srs geoip-cn.srs geoip-facebook.srs geoip-fastly.srs \ - geoip-google.srs geoip-netflix.srs geoip-telegram.srs geoip-twitter.srs; do - curl -fsSL -o "$srss_dir/$f" \ - "https://raw.githubusercontent.com/2dust/sing-box-rules/rule-set-geoip/$f" || true + curl -fsSL -o "$bin_dir/geoip.metadb" "https://github.com/MetaCubeX/meta-rules-dat/releases/latest/download/geoip.metadb" + + for f in geoip-private.srs geoip-cn.srs geoip-facebook.srs geoip-fastly.srs geoip-google.srs geoip-netflix.srs geoip-telegram.srs geoip-twitter.srs; do + curl -fsSL -o "$srss_dir/$f" "https://raw.githubusercontent.com/2dust/sing-box-rules/refs/heads/rule-set-geoip/$f" done - for f in \ - geosite-cn.srs geosite-gfw.srs geosite-google.srs geosite-greatfire.srs \ - geosite-geolocation-cn.srs geosite-category-ads-all.srs geosite-private.srs; do - curl -fsSL -o "$srss_dir/$f" \ - "https://raw.githubusercontent.com/2dust/sing-box-rules/rule-set-geosite/$f" || true + + for f in geosite-cn.srs geosite-gfw.srs geosite-google.srs geosite-greatfire.srs geosite-geolocation-cn.srs geosite-category-ads-all.srs geosite-private.srs; do + curl -fsSL -o "$srss_dir/$f" "https://raw.githubusercontent.com/2dust/sing-box-rules/refs/heads/rule-set-geosite/$f" done - # Unify to bin unify_geo_layout "$outroot" } -# Prefer the prebuilt v2rayN core bundle; then unify geo layout -download_v2rayn_bundle() { - local outroot="$1" rid="$2" +populate_assets_zip_mode() { + local outroot="$1" + local rid="$2" local url="" - if [[ "$rid" == "linux-riscv64" ]]; then - url="https://raw.githubusercontent.com/2dust/v2rayN-core-bin/refs/heads/master/v2rayN-linux-riscv64.zip" - fi - [[ -n "$url" ]] || { echo "[!] Bundle unsupported RID: $rid"; return 1; } + local tmp="" + local nested_dir="" + + url="$(bundle_url_for_rid "$rid")" || { echo "[!] Bundle unsupported RID: $rid"; return 1; } + echo "[+] Try v2rayN bundle archive: $url" - local tmp zipname - tmp="$(mktemp -d)"; zipname="$tmp/v2rayn.zip" - curl -fL "$url" -o "$zipname" || { echo "[!] Bundle download failed"; return 1; } - unzip -q "$zipname" -d "$tmp" || { echo "[!] Bundle unzip failed"; return 1; } + + tmp="$(mktemp -d)" + curl -fL "$url" -o "$tmp/v2rayn.zip" || { echo "[!] Bundle download failed"; rm -rf "$tmp"; return 1; } + unzip -q "$tmp/v2rayn.zip" -d "$tmp" || { echo "[!] Bundle unzip failed"; rm -rf "$tmp"; return 1; } if [[ -d "$tmp/bin" ]]; then mkdir -p "$outroot/bin" @@ -455,7 +490,6 @@ download_v2rayn_bundle() { rm -f "$outroot/v2rayn.zip" 2>/dev/null || true find "$outroot" -type d -name "mihomo" -prune -exec rm -rf {} + 2>/dev/null || true - local nested_dir nested_dir="$(find "$outroot" -maxdepth 1 -type d -name 'v2rayN-linux-*' | head -n1 || true)" if [[ -n "$nested_dir" && -d "$nested_dir/bin" ]]; then mkdir -p "$outroot/bin" @@ -463,111 +497,73 @@ download_v2rayn_bundle() { rm -rf "$nested_dir" fi - # Unify to bin/ unify_geo_layout "$outroot" + rm -rf "$tmp" echo "[+] Bundle extracted to $outroot" } -# ===== Build results collection ======================================================== -BUILT_RPMS=() - -# ===== Build (single-arch) function ==================================================== -build_for_arch() { - # $1: target short arch: riscv64 - local short="$1" - local rid rpm_target archdir - case "$short" in - riscv64) rid="linux-riscv64"; rpm_target="riscv64"; archdir="riscv64" ;; - *) echo "Unknown arch '$short' (use riscv64)"; return 1;; - esac - - echo "[*] Building for target: $short (RID=$rid, RPM --target $rpm_target)" - - # .NET publish (self-contained) for this RID - dotnet clean "$PROJECT" -c Release -p:TargetFramework=net10.0 - rm -rf "$(dirname "$PROJECT")/bin/Release/net10.0" || true - - dotnet restore "$PROJECT" -r "$rid" -p:TargetFramework=net10.0 - dotnet publish "$PROJECT" \ - -c Release -r "$rid" \ - -p:TargetFramework=net10.0 \ - -p:PublishSingleFile=false \ - -p:SelfContained=true - - # Per-arch variables (scoped) - local RID_DIR="$rid" - local PUBDIR - PUBDIR="$(dirname "$PROJECT")/bin/Release/net10.0/${RID_DIR}/publish" - [[ -d "$PUBDIR" ]] || { echo "Publish directory not found: $PUBDIR"; return 1; } - - # Per-arch working area - local PKGROOT="v2rayN-publish" - local WORKDIR - WORKDIR="$(mktemp -d)" - trap '[[ -n "${WORKDIR:-}" ]] && rm -rf "$WORKDIR"' RETURN - - # rpmbuild topdir selection - local TOPDIR SPECDIR SOURCEDIR PROJECT_DIR - rpmdev-setuptree - TOPDIR="${HOME}/rpmbuild" - SPECDIR="${TOPDIR}/SPECS" - SOURCEDIR="${TOPDIR}/SOURCES" +populate_assets_netcore_mode() { + local outroot="$1" + local rid="$2" - # Stage publish content - mkdir -p "$WORKDIR/$PKGROOT" - cp -a "$PUBDIR/." "$WORKDIR/$PKGROOT/" + mkdir -p "$outroot/bin/xray" "$outroot/bin/sing_box" - copy_skiasharp_native_riscv64 "$WORKDIR/$PKGROOT" || echo "[!] SkiaSharp native copy failed (skipped)" - build_sqlite_native_riscv64 "$WORKDIR/$PKGROOT" || echo "[!] sqlite native build failed (skipped)" + if [[ "$WITH_CORE" == "xray" || "$WITH_CORE" == "both" ]]; then + download_xray "$outroot/bin/xray" "$rid" || echo "[!] xray download failed (skipped)" + fi - # Required icon - local ICON_CANDIDATE - PROJECT_DIR="$(cd "$(dirname "$PROJECT")" && pwd)" - ICON_CANDIDATE="$PROJECT_DIR/v2rayN.png" - [[ -f "$ICON_CANDIDATE" ]] || { echo "Required icon not found: $ICON_CANDIDATE"; return 1; } - cp "$ICON_CANDIDATE" "$WORKDIR/$PKGROOT/v2rayn.png" + if [[ "$WITH_CORE" == "sing-box" || "$WITH_CORE" == "both" ]]; then + download_singbox "$outroot/bin/sing_box" "$rid" || echo "[!] sing-box download failed (skipped)" + fi - # Prepare bin structure - mkdir -p "$WORKDIR/$PKGROOT/bin/xray" "$WORKDIR/$PKGROOT/bin/sing_box" + download_geo_assets "$outroot" || echo "[!] Geo rules download failed (skipped)" +} - # Bundle / cores per-arch - fetch_separate_cores_and_rules() { - local outroot="$1" +stage_runtime_assets() { + local outroot="$1" + local rid="$2" - if [[ "$WITH_CORE" == "xray" || "$WITH_CORE" == "both" ]]; then - download_xray "$outroot/bin/xray" "$RID_DIR" || echo "[!] xray download failed (skipped)" - fi - if [[ "$WITH_CORE" == "sing-box" || "$WITH_CORE" == "both" ]]; then - download_singbox "$outroot/bin/sing_box" "$RID_DIR" || echo "[!] sing-box download failed (skipped)" - fi - download_geo_assets "$outroot" || echo "[!] Geo rules download failed (skipped)" - } + mkdir -p "$outroot/bin/xray" "$outroot/bin/sing_box" if [[ "$FORCE_NETCORE" -eq 0 ]]; then - if download_v2rayn_bundle "$WORKDIR/$PKGROOT" "$RID_DIR"; then + if populate_assets_zip_mode "$outroot" "$rid"; then echo "[*] Using v2rayN bundle archive." else echo "[*] Bundle failed, fallback to separate core + rules." - fetch_separate_cores_and_rules "$WORKDIR/$PKGROOT" + populate_assets_netcore_mode "$outroot" "$rid" fi else echo "[*] --netcore specified: use separate core + rules." - fetch_separate_cores_and_rules "$WORKDIR/$PKGROOT" + populate_assets_netcore_mode "$outroot" "$rid" fi +} + +describe_target() { + local short="$1" + + case "$short" in + riscv64) printf '%s\n%s\n%s\n' "linux-riscv64" "riscv64" "riscv64" ;; + *) echo "Unknown arch '$short' (use riscv64)" >&2; return 1 ;; + esac +} + +publish_binary() { + local rid="$1" + + dotnet clean "$PROJECT" -c Release -p:TargetFramework="$DOTNET_TFM" + rm -rf "$(dirname "$PROJECT")/bin/Release/${DOTNET_TFM}" || true + dotnet restore "$PROJECT" -r "$rid" -p:TargetFramework="$DOTNET_TFM" + dotnet publish "$PROJECT" -c Release -r "$rid" -p:TargetFramework="$DOTNET_TFM" -p:PublishSingleFile=false -p:SelfContained=true +} - # Tarball - mkdir -p "$SOURCEDIR" - tar -C "$WORKDIR" -czf "$SOURCEDIR/$PKGROOT.tar.gz" "$PKGROOT" +write_spec_file() { + local specfile="$1" - # SPEC - local SPECFILE="$SPECDIR/v2rayN.spec" - mkdir -p "$SPECDIR" - cat > "$SPECFILE" <<'SPEC' + cat > "$specfile" <<'SPEC' %global debug_package %{nil} %undefine _debuginfo_subpackages %undefine _debugsource_packages -# Ignore outdated LTTng dependencies incorrectly reported by the .NET runtime (to avoid installation failures) %global __requires_exclude ^liblttng-ust\.so\..*$ Name: v2rayN @@ -580,7 +576,6 @@ BugURL: https://github.com/2dust/v2rayN/issues ExclusiveArch: riscv64 Source0: __PKGROOT__.tar.gz -# Runtime dependencies (Avalonia / X11 / Fonts / GL) Requires: cairo, pango, openssl, mesa-libEGL, mesa-libGL Requires: glibc >= 2.34 Requires: fontconfig >= 2.13.1 @@ -601,21 +596,17 @@ https://github.com/2dust/v2rayN %setup -q -n __PKGROOT__ %build -# no build %install install -dm0755 %{buildroot}/opt/v2rayN cp -a * %{buildroot}/opt/v2rayN/ -# Normalize permissions find %{buildroot}/opt/v2rayN -type d -exec chmod 0755 {} + find %{buildroot}/opt/v2rayN -type f -exec chmod 0644 {} + [ -f %{buildroot}/opt/v2rayN/v2rayN ] && chmod 0755 %{buildroot}/opt/v2rayN/v2rayN || : [ -f %{buildroot}/opt/v2rayN/libSkiaSharp.so ] && chmod 0755 %{buildroot}/opt/v2rayN/libSkiaSharp.so || : [ -f %{buildroot}/opt/v2rayN/libHarfBuzzSharp.so ] && chmod 0755 %{buildroot}/opt/v2rayN/libHarfBuzzSharp.so || : -[ -f %{buildroot}/opt/v2rayN/libe_sqlite3.so ] && chmod 0755 %{buildroot}/opt/v2rayN/libe_sqlite3.so || : -# Launcher (prefer native ELF first, then DLL fallback) install -dm0755 %{buildroot}%{_bindir} install -m0755 /dev/stdin %{buildroot}%{_bindir}/v2rayn << 'EOF' #!/usr/bin/bash @@ -623,10 +614,8 @@ set -euo pipefail DIR="/opt/v2rayN" export LD_LIBRARY_PATH="$DIR:${LD_LIBRARY_PATH:-}" -# Prefer native apphost if [[ -x "$DIR/v2rayN" ]]; then exec "$DIR/v2rayN" "$@"; fi -# DLL fallback for dll in v2rayN.Desktop.dll v2rayN.dll; do if [[ -f "$DIR/$dll" ]]; then exec /usr/bin/dotnet "$DIR/$dll" "$@"; fi done @@ -636,7 +625,6 @@ ls -l "$DIR" >&2 || true exit 1 EOF -# Desktop file install -dm0755 %{buildroot}%{_datadir}/applications install -m0644 /dev/stdin %{buildroot}%{_datadir}/applications/v2rayn.desktop << 'EOF' [Desktop Entry] @@ -649,7 +637,6 @@ Terminal=false Categories=Network; EOF -# Icon install -dm0755 %{buildroot}%{_datadir}/icons/hicolor/256x256/apps install -m0644 %{_builddir}/__PKGROOT__/v2rayn.png %{buildroot}%{_datadir}/icons/hicolor/256x256/apps/v2rayn.png @@ -668,36 +655,115 @@ install -m0644 %{_builddir}/__PKGROOT__/v2rayn.png %{buildroot}%{_datadir}/icons %{_datadir}/icons/hicolor/256x256/apps/v2rayn.png SPEC - # Replace placeholders - sed -i "s/__VERSION__/${VERSION}/g" "$SPECFILE" - sed -i "s/__PKGROOT__/${PKGROOT}/g" "$SPECFILE" + sed -i "s/__VERSION__/${VERSION}/g" "$specfile" + sed -i "s/__PKGROOT__/${PKGROOT}/g" "$specfile" +} + +package_binary() { + local short="$1" + local rid="$2" + local rpm_target="$3" + local archdir="$4" + local pubdir="" + local workdir="" + local specfile="" + local sourcedir="" + local specdir="" + local project_dir="" + local icon_candidate="" + local f="" + + pubdir="$(dirname "$PROJECT")/bin/Release/${DOTNET_TFM}/${rid}/publish" + [[ -d "$pubdir" ]] || { echo "Publish directory not found: $pubdir"; return 1; } + + workdir="$(mktemp -d)" + trap '[[ -n "${workdir:-}" ]] && rm -rf "$workdir"' RETURN + + mkdir -p "$workdir/$PKGROOT" + cp -a "$pubdir/." "$workdir/$PKGROOT/" + + copy_skiasharp_native_riscv64 "$workdir/$PKGROOT" || echo "[!] SkiaSharp native copy failed (skipped)" - # Build RPM for this arch - rpmbuild -ba "$SPECFILE" --target "$rpm_target" + project_dir="$(cd "$(dirname "$PROJECT")" && pwd)" + icon_candidate="$project_dir/v2rayN.png" + [[ -f "$icon_candidate" ]] || { echo "Required icon not found: $icon_candidate"; return 1; } + cp "$icon_candidate" "$workdir/$PKGROOT/v2rayn.png" + + stage_runtime_assets "$workdir/$PKGROOT" "$rid" + + rpmdev-setuptree + sourcedir="${RPM_TOPDIR}/SOURCES" + specdir="${RPM_TOPDIR}/SPECS" + specfile="${specdir}/v2rayN.spec" + + mkdir -p "$sourcedir" "$specdir" + tar -C "$workdir" -czf "$sourcedir/$PKGROOT.tar.gz" "$PKGROOT" + + write_spec_file "$specfile" + rpmbuild -ba "$specfile" --target "$rpm_target" echo "Build done for $short. RPM at:" - local f - for f in "${TOPDIR}/RPMS/${archdir}/v2rayN-${VERSION}-1"*.rpm; do + for f in "${RPM_TOPDIR}/RPMS/${archdir}/v2rayN-${VERSION}-1"*.rpm; do [[ -e "$f" ]] || continue echo " $f" BUILT_RPMS+=("$f") done } -# ===== Arch selection and build orchestration ========================================= -targets=(riscv64) +select_targets() { + printf '%s\n' riscv64 +} -for arch in "${targets[@]}"; do - build_for_arch "$arch" -done +build_one_target() { + local short="$1" + local meta=() + local rid="" + local rpm_target="" + local archdir="" -echo "" -echo "================ Build Summary ================" -if [[ "${#BUILT_RPMS[@]}" -gt 0 ]]; then - for rp in "${BUILT_RPMS[@]}"; do - echo "$rp" + mapfile -t meta < <(describe_target "$short") || return 1 + rid="${meta[0]}" + rpm_target="${meta[1]}" + archdir="${meta[2]}" + + echo "[*] Building for target: $short (RID=$rid, RPM --target $rpm_target)" + publish_binary "$rid" + package_binary "$short" "$rid" "$rpm_target" "$archdir" +} + +print_summary() { + local rp="" + + echo "" + echo "================ Build Summary ================" + if [[ "${#BUILT_RPMS[@]}" -gt 0 ]]; then + for rp in "${BUILT_RPMS[@]}"; do + echo "$rp" + done + else + echo "No RPMs detected in summary (check build logs above)." + fi + echo "==============================================" +} + +main() { + local targets=() + local arch="" + + parse_args "$@" + detect_environment + install_dependencies + prepare_workspace + resolve_version + apply_riscv_patch + + mapfile -t targets < <(select_targets) + + for arch in "${targets[@]}"; do + build_one_target "$arch" done -else - echo "No RPMs detected in summary (check build logs above)." -fi -echo "==============================================" + + print_summary +} + +main "$@" \ No newline at end of file diff --git a/package-rhel.sh b/package-rhel.sh index 753e889fb76..2b266999684 100644 --- a/package-rhel.sh +++ b/package-rhel.sh @@ -1,116 +1,139 @@ #!/usr/bin/env bash set -euo pipefail -# Require Red Hat base branch -. /etc/os-release - -case "${ID:-}" in - rhel|rocky|almalinux|fedora|centos) - echo "Detected supported system: ${NAME:-$ID} ${VERSION_ID:-}" - ;; - *) - echo "Unsupported system: ${NAME:-unknown} (${ID:-unknown})." - echo "This script only supports: RHEL / Rocky / AlmaLinux / Fedora / CentOS." - exit 1 - ;; -esac +VERSION_ARG="" +WITH_CORE="both" +FORCE_NETCORE=0 +ARCH_OVERRIDE="" +BUILD_FROM="" +XRAY_VER="${XRAY_VER:-}" +SING_VER="${SING_VER:-}" + +MIN_KERNEL="6.12" +PKGROOT="v2rayN-publish" +PROJECT_HINT="v2rayN.Desktop/v2rayN.Desktop.csproj" +RPM_TOPDIR="${HOME}/rpmbuild" + +OS_ID="" +OS_NAME="" +OS_VERSION_ID="" +HOST_ARCH="" +SCRIPT_DIR="" +PROJECT="" +VERSION="" +BUILT_ALL=0 + +declare -a BUILT_RPMS=() + +die() { + echo "$*" >&2 + exit 1 +} -# Kernel version -MIN_KERNEL="6.11" -CURRENT_KERNEL="$(uname -r)" +parse_args() { + local first_arg="${1:-}" -lowest="$(printf '%s\n%s\n' "$MIN_KERNEL" "$CURRENT_KERNEL" | sort -V | head -n1)" + if [[ -n "$first_arg" && "$first_arg" != --* ]]; then + VERSION_ARG="$first_arg" + shift || true + fi -if [[ "$lowest" != "$MIN_KERNEL" ]]; then - echo "Kernel $CURRENT_KERNEL is below $MIN_KERNEL" - exit 1 -fi - -echo "[OK] Kernel $CURRENT_KERNEL verified." - -# Config & Parse arguments -VERSION_ARG="${1:-}" # Pass version number like 7.13.8, or leave empty -WITH_CORE="both" # Default: bundle both xray+sing-box -FORCE_NETCORE=0 # --netcore => skip archive bundle, use separate downloads -ARCH_OVERRIDE="" # --arch x64|arm64|all (optional compile target) -BUILD_FROM="" # --buildfrom 1|2|3 to select channel non-interactively - -# If the first argument starts with --, do not treat it as a version number -if [[ "${VERSION_ARG:-}" == --* ]]; then - VERSION_ARG="" -fi -# Take the first non --* argument as version, discard it -if [[ -n "${VERSION_ARG:-}" ]]; then shift || true; fi - -# Parse remaining optional arguments -while [[ $# -gt 0 ]]; do - case "$1" in - --with-core) WITH_CORE="${2:-both}"; shift 2;; - --xray-ver) XRAY_VER="${2:-}"; shift 2;; - --singbox-ver) SING_VER="${2:-}"; shift 2;; - --netcore) FORCE_NETCORE=1; shift;; - --arch) ARCH_OVERRIDE="${2:-}"; shift 2;; - --buildfrom) BUILD_FROM="${2:-}"; shift 2;; + while [[ $# -gt 0 ]]; do + case "$1" in + --with-core) WITH_CORE="${2:-both}"; shift 2 ;; + --xray-ver) XRAY_VER="${2:-}"; shift 2 ;; + --singbox-ver) SING_VER="${2:-}"; shift 2 ;; + --netcore) FORCE_NETCORE=1; shift ;; + --arch) ARCH_OVERRIDE="${2:-}"; shift 2 ;; + --buildfrom) BUILD_FROM="${2:-}"; shift 2 ;; + *) + [[ -n "${VERSION_ARG:-}" ]] || VERSION_ARG="$1" + shift + ;; + esac + done + + if [[ -n "${VERSION_ARG:-}" && -n "${BUILD_FROM:-}" ]]; then + die "You cannot specify both an explicit version and --buildfrom at the same time. + Provide either a version (e.g. 7.14.0) OR --buildfrom 1|2|3." + fi +} + +detect_environment() { + local current_kernel="" + local lowest="" + + . /etc/os-release + + OS_ID="${ID:-}" + OS_NAME="${NAME:-$OS_ID}" + OS_VERSION_ID="${VERSION_ID:-}" + HOST_ARCH="$(uname -m)" + + case "$OS_ID" in + rhel|rocky|almalinux|fedora|centos) + echo "Detected supported system: ${OS_NAME:-$OS_ID} ${OS_VERSION_ID:-}" + ;; *) - if [[ -z "${VERSION_ARG:-}" ]]; then VERSION_ARG="$1"; fi - shift;; + die "Unsupported system: ${OS_NAME:-unknown} (${OS_ID:-unknown}). +This script only supports: RHEL / Rocky / AlmaLinux / Fedora / CentOS." + ;; esac -done -# Conflict: version number AND --buildfrom cannot be used together -if [[ -n "${VERSION_ARG:-}" && -n "${BUILD_FROM:-}" ]]; then - echo "You cannot specify both an explicit version and --buildfrom at the same time." - echo " Provide either a version (e.g. 7.14.0) OR --buildfrom 1|2|3." - exit 1 -fi + case "$HOST_ARCH" in + x86_64|aarch64) ;; + *) die "Only supports aarch64 / x86_64" ;; + esac -# Check and install dependencies -host_arch="$(uname -m)" -[[ "$host_arch" == "aarch64" || "$host_arch" == "x86_64" ]] || { echo "Only supports aarch64 / x86_64"; exit 1; } + current_kernel="$(uname -r)" + lowest="$(printf '%s\n%s\n' "$MIN_KERNEL" "$current_kernel" | sort -V | head -n1)" + + [[ "$lowest" == "$MIN_KERNEL" ]] || die "Kernel $current_kernel is below $MIN_KERNEL" + echo "[OK] Kernel $current_kernel verified." +} -install_ok=0 +install_dependencies() { + local install_ok=0 -if command -v dnf >/dev/null 2>&1; then - sudo dnf -y install rpm-build rpmdevtools curl unzip tar jq rsync dotnet-sdk-10.0 \ - && install_ok=1 -fi + if command -v dnf >/dev/null 2>&1; then + sudo dnf -y install rpm-build rpmdevtools curl unzip tar jq rsync dotnet-sdk-10.0 \ + && install_ok=1 + fi -if [[ "$install_ok" -ne 1 ]]; then - echo "Could not auto-install dependencies for '$ID'. Make sure these are available:" - echo "dotnet-sdk 10.x, curl, unzip, tar, rsync, rpm, rpmdevtools, rpm-build (on Red Hat branch)" -fi + if [[ "$install_ok" -ne 1 ]]; then + echo "Could not auto-install dependencies for '$OS_ID'. Make sure these are available:" + echo "dotnet-sdk 10.x, curl, unzip, tar, rsync, rpm, rpmdevtools, rpm-build (on Red Hat branch)" + exit 1 + fi +} -# Root directory -SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" -cd "$SCRIPT_DIR" +prepare_workspace() { + SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" + cd "$SCRIPT_DIR" -# Git submodules (best effort) -if [[ -f .gitmodules ]]; then - git submodule sync --recursive || true - git submodule update --init --recursive || true -fi + if [[ -f .gitmodules ]]; then + git submodule sync --recursive || true + git submodule update --init --recursive || true + fi -# Locate project -PROJECT="v2rayN.Desktop/v2rayN.Desktop.csproj" -if [[ ! -f "$PROJECT" ]]; then - PROJECT="$(find . -maxdepth 3 -name 'v2rayN.Desktop.csproj' | head -n1 || true)" -fi -[[ -f "$PROJECT" ]] || { echo "v2rayN.Desktop.csproj not found"; exit 1; } + PROJECT="$PROJECT_HINT" + [[ -f "$PROJECT" ]] || PROJECT="$(find . -maxdepth 3 -name 'v2rayN.Desktop.csproj' | head -n1 || true)" + [[ -f "$PROJECT" ]] || die "v2rayN.Desktop.csproj not found" +} choose_channel() { - # If --buildfrom provided, map it directly and skip interaction. + local ch="latest" + local sel="" + if [[ -n "${BUILD_FROM:-}" ]]; then case "$BUILD_FROM" in - 1) echo "latest"; return 0;; - 2) echo "prerelease"; return 0;; - 3) echo "keep"; return 0;; - *) echo "[ERROR] Invalid --buildfrom value: ${BUILD_FROM}. Use 1|2|3." >&2; exit 1;; + 1) echo "latest"; return 0 ;; + 2) echo "prerelease"; return 0 ;; + 3) echo "keep"; return 0 ;; + *) die "[ERROR] Invalid --buildfrom value: ${BUILD_FROM}. Use 1|2|3." ;; esac fi - # Print menu to stderr and read from /dev/tty so stdout only carries the token. - local ch="latest" sel="" - if [[ -t 0 ]]; then echo "[?] Choose v2rayN release channel:" >&2 echo " 1) Latest (stable) [default]" >&2 @@ -141,29 +164,35 @@ get_latest_tag_prerelease() { | sed 's/^v//' } +sync_submodules() { + if [[ -f .gitmodules ]]; then + git submodule sync --recursive || true + git submodule update --init --recursive || true + fi +} + git_try_checkout() { - # Try a series of refs and checkout when found. - local want="$1" ref="" + local want="$1" + local ref="" + if git rev-parse --git-dir >/dev/null 2>&1; then git fetch --tags --force --prune --depth=1 || true - if git rev-parse "refs/tags/${want}" >/dev/null 2>&1; then - ref="${want}" - fi + git rev-parse "refs/tags/${want}" >/dev/null 2>&1 && ref="$want" + if [[ -n "$ref" ]]; then echo "[OK] Found ref '${ref}', checking out..." - git checkout -f "${ref}" - if [[ -f .gitmodules ]]; then - git submodule sync --recursive || true - git submodule update --init --recursive || true - fi + git checkout -f "$ref" + sync_submodules return 0 fi fi + return 1 } apply_channel_or_keep() { - local ch="$1" tag + local ch="$1" + local tag="" if [[ "$ch" == "keep" ]]; then echo "[*] Keep current repository state (no checkout)." @@ -173,102 +202,154 @@ apply_channel_or_keep() { fi echo "[*] Resolving ${ch} tag from GitHub releases..." - if [[ "$ch" == "prerelease" ]]; then - tag="$(get_latest_tag_prerelease || true)" - else - tag="$(get_latest_tag_latest || true)" - fi - [[ -n "$tag" ]] || { echo "Failed to resolve latest tag for channel '${ch}'."; exit 1; } + case "$ch" in + latest) tag="$(get_latest_tag_latest || true)" ;; + prerelease) tag="$(get_latest_tag_prerelease || true)" ;; + *) die "Failed to resolve latest tag for channel '${ch}'." ;; + esac + + [[ -n "$tag" ]] || die "Failed to resolve latest tag for channel '${ch}'." + echo "[*] Latest tag for '${ch}': ${tag}" - git_try_checkout "$tag" || { echo "Failed to checkout '${tag}'."; exit 1; } + git_try_checkout "$tag" || die "Failed to checkout '${tag}'." VERSION="${tag#v}" } -if git rev-parse --git-dir >/dev/null 2>&1; then - if [[ -n "${VERSION_ARG:-}" ]]; then - clean_ver="${VERSION_ARG#v}" - if git_try_checkout "$clean_ver"; then - VERSION="$clean_ver" +resolve_version() { + if git rev-parse --git-dir >/dev/null 2>&1; then + if [[ -n "${VERSION_ARG:-}" ]]; then + local clean_ver="${VERSION_ARG#v}" + + if git_try_checkout "$clean_ver"; then + VERSION="$clean_ver" + else + echo "[WARN] Tag '${VERSION_ARG}' not found." + apply_channel_or_keep "$(choose_channel)" + fi else - echo "[WARN] Tag '${VERSION_ARG}' not found." - ch="$(choose_channel)" - apply_channel_or_keep "$ch" + apply_channel_or_keep "$(choose_channel)" fi else - ch="$(choose_channel)" - apply_channel_or_keep "$ch" + echo "Current directory is not a git repo; proceeding on current tree." + VERSION="${VERSION_ARG:-0.0.0}" fi -else - echo "Current directory is not a git repo; proceeding on current tree." - VERSION="${VERSION_ARG:-0.0.0}" -fi -VERSION="${VERSION#v}" -echo "[*] GUI version resolved as: ${VERSION}" + VERSION="${VERSION#v}" + echo "[*] GUI version resolved as: ${VERSION}" +} + +xray_url_for_rid() { + local rid="$1" + local ver="$2" + + case "$rid" in + linux-x64) echo "https://github.com/XTLS/Xray-core/releases/download/v${ver}/Xray-linux-64.zip" ;; + linux-arm64) echo "https://github.com/XTLS/Xray-core/releases/download/v${ver}/Xray-linux-arm64-v8a.zip" ;; + *) return 1 ;; + esac +} + +singbox_url_for_rid() { + local rid="$1" + local ver="$2" + + case "$rid" in + linux-x64) echo "https://github.com/SagerNet/sing-box/releases/download/v${ver}/sing-box-${ver}-linux-amd64.tar.gz" ;; + linux-arm64) echo "https://github.com/SagerNet/sing-box/releases/download/v${ver}/sing-box-${ver}-linux-arm64.tar.gz" ;; + *) return 1 ;; + esac +} + +bundle_url_for_rid() { + local rid="$1" + + case "$rid" in + linux-x64) echo "https://raw.githubusercontent.com/2dust/v2rayN-core-bin/refs/heads/master/v2rayN-linux-64.zip" ;; + linux-arm64) echo "https://raw.githubusercontent.com/2dust/v2rayN-core-bin/refs/heads/master/v2rayN-linux-arm64.zip" ;; + *) return 1 ;; + esac +} -# Helpers for core download_xray() { - # Download Xray core - local outdir="$1" rid="$2" ver="${XRAY_VER:-}" url tmp zipname="xray.zip" + local outdir="$1" + local rid="$2" + local ver="${XRAY_VER:-}" + local url="" + local tmp="" + mkdir -p "$outdir" + if [[ -z "$ver" ]]; then ver="$(curl -fsSL https://api.github.com/repos/XTLS/Xray-core/releases/latest \ - | grep -Eo '"tag_name":\s*"v[^"]+"' | sed -E 's/.*"v([^"]+)".*/\1/' | head -n1)" || true + | grep -Eo '"tag_name":\s*"v[^"]+"' \ + | sed -E 's/.*"v([^"]+)".*/\1/' \ + | head -n1)" || true fi + [[ -n "$ver" ]] || { echo "[xray] Failed to get version"; return 1; } - if [[ "$rid" == "linux-arm64" ]]; then - url="https://github.com/XTLS/Xray-core/releases/download/v${ver}/Xray-linux-arm64-v8a.zip" - else - url="https://github.com/XTLS/Xray-core/releases/download/v${ver}/Xray-linux-64.zip" - fi + url="$(xray_url_for_rid "$rid" "$ver")" || { echo "[xray] Unsupported RID: $rid"; return 1; } + echo "[+] Download xray: $url" + tmp="$(mktemp -d)" - curl -fL "$url" -o "$tmp/$zipname" - unzip -q "$tmp/$zipname" -d "$tmp" - install -m 755 "$tmp/xray" "$outdir/xray" + curl -fL "$url" -o "$tmp/xray.zip" || { rm -rf "$tmp"; return 1; } + unzip -q "$tmp/xray.zip" -d "$tmp" || { rm -rf "$tmp"; return 1; } + install -m 755 "$tmp/xray" "$outdir/xray" || { rm -rf "$tmp"; return 1; } rm -rf "$tmp" } download_singbox() { - # Download sing-box - local outdir="$1" rid="$2" ver="${SING_VER:-}" url tmp tarname="singbox.tar.gz" bin cronet + local outdir="$1" + local rid="$2" + local ver="${SING_VER:-}" + local url="" + local tmp="" + local bin="" + local cronet="" + mkdir -p "$outdir" + if [[ -z "$ver" ]]; then ver="$(curl -fsSL https://api.github.com/repos/SagerNet/sing-box/releases/latest \ | grep -Eo '"tag_name":\s*"v[^"]+"' \ | sed -E 's/.*"v([^"]+)".*/\1/' \ | head -n1)" || true fi + [[ -n "$ver" ]] || { echo "[sing-box] Failed to get version"; return 1; } - if [[ "$rid" == "linux-arm64" ]]; then - url="https://github.com/SagerNet/sing-box/releases/download/v${ver}/sing-box-${ver}-linux-arm64.tar.gz" - else - url="https://github.com/SagerNet/sing-box/releases/download/v${ver}/sing-box-${ver}-linux-amd64.tar.gz" - fi + url="$(singbox_url_for_rid "$rid" "$ver")" || { echo "[sing-box] Unsupported RID: $rid"; return 1; } + echo "[+] Download sing-box: $url" + tmp="$(mktemp -d)" - curl -fL "$url" -o "$tmp/$tarname" - tar -C "$tmp" -xzf "$tmp/$tarname" + curl -fL "$url" -o "$tmp/singbox.tar.gz" || { rm -rf "$tmp"; return 1; } + tar -C "$tmp" -xzf "$tmp/singbox.tar.gz" || { rm -rf "$tmp"; return 1; } + bin="$(find "$tmp" -type f -name 'sing-box' | head -n1 || true)" [[ -n "$bin" ]] || { echo "[!] sing-box unpack failed"; rm -rf "$tmp"; return 1; } - install -m 755 "$bin" "$outdir/sing-box" + + install -m 755 "$bin" "$outdir/sing-box" || { rm -rf "$tmp"; return 1; } + cronet="$(find "$tmp" -type f -name 'libcronet*.so*' | head -n1 || true)" - [[ -n "$cronet" ]] && install -m 644 "$cronet" "$outdir/libcronet.so" + [[ -n "$cronet" ]] && install -m 644 "$cronet" "$outdir/libcronet.so" || true + rm -rf "$tmp" } -# Move geo files to outroot/bin unify_geo_layout() { local outroot="$1" - mkdir -p "$outroot/bin" - local names=( \ - "geosite.dat" \ - "geoip.dat" \ - "geoip-only-cn-private.dat" \ - "Country.mmdb" \ - "geoip.metadb" \ + local n + local names=( + geosite.dat + geoip.dat + geoip-only-cn-private.dat + Country.mmdb + geoip.metadb ) + + mkdir -p "$outroot/bin" + for n in "${names[@]}"; do if [[ -f "$outroot/bin/xray/$n" ]]; then mv -f "$outroot/bin/xray/$n" "$outroot/bin/$n" @@ -276,58 +357,48 @@ unify_geo_layout() { done } -# Download geo/rule assets download_geo_assets() { local outroot="$1" local bin_dir="$outroot/bin" local srss_dir="$bin_dir/srss" + local f="" + mkdir -p "$bin_dir" "$srss_dir" echo "[+] Download Xray Geo to ${bin_dir}" - curl -fsSL -o "$bin_dir/geosite.dat" \ - "https://github.com/Loyalsoldier/V2ray-rules-dat/releases/latest/download/geosite.dat" - curl -fsSL -o "$bin_dir/geoip.dat" \ - "https://github.com/Loyalsoldier/V2ray-rules-dat/releases/latest/download/geoip.dat" - curl -fsSL -o "$bin_dir/geoip-only-cn-private.dat" \ - "https://raw.githubusercontent.com/Loyalsoldier/geoip/release/geoip-only-cn-private.dat" - curl -fsSL -o "$bin_dir/Country.mmdb" \ - "https://raw.githubusercontent.com/Loyalsoldier/geoip/release/Country.mmdb" + curl -fsSL -o "$bin_dir/geosite.dat" "https://github.com/Loyalsoldier/V2ray-rules-dat/releases/latest/download/geosite.dat" + curl -fsSL -o "$bin_dir/geoip.dat" "https://github.com/Loyalsoldier/V2ray-rules-dat/releases/latest/download/geoip.dat" + curl -fsSL -o "$bin_dir/geoip-only-cn-private.dat" "https://raw.githubusercontent.com/Loyalsoldier/geoip/release/geoip-only-cn-private.dat" + curl -fsSL -o "$bin_dir/Country.mmdb" "https://raw.githubusercontent.com/Loyalsoldier/geoip/release/Country.mmdb" echo "[+] Download sing-box rule DB & rule-sets" - curl -fsSL -o "$bin_dir/geoip.metadb" \ - "https://github.com/MetaCubeX/meta-rules-dat/releases/latest/download/geoip.metadb" || true - - for f in \ - geoip-private.srs geoip-cn.srs geoip-facebook.srs geoip-fastly.srs \ - geoip-google.srs geoip-netflix.srs geoip-telegram.srs geoip-twitter.srs; do - curl -fsSL -o "$srss_dir/$f" \ - "https://raw.githubusercontent.com/2dust/sing-box-rules/rule-set-geoip/$f" || true + curl -fsSL -o "$bin_dir/geoip.metadb" "https://github.com/MetaCubeX/meta-rules-dat/releases/latest/download/geoip.metadb" + + for f in geoip-private.srs geoip-cn.srs geoip-facebook.srs geoip-fastly.srs geoip-google.srs geoip-netflix.srs geoip-telegram.srs geoip-twitter.srs; do + curl -fsSL -o "$srss_dir/$f" "https://raw.githubusercontent.com/2dust/sing-box-rules/refs/heads/rule-set-geoip/$f" done - for f in \ - geosite-cn.srs geosite-gfw.srs geosite-google.srs geosite-greatfire.srs \ - geosite-geolocation-cn.srs geosite-category-ads-all.srs geosite-private.srs; do - curl -fsSL -o "$srss_dir/$f" \ - "https://raw.githubusercontent.com/2dust/sing-box-rules/rule-set-geosite/$f" || true + + for f in geosite-cn.srs geosite-gfw.srs geosite-google.srs geosite-greatfire.srs geosite-geolocation-cn.srs geosite-category-ads-all.srs geosite-private.srs; do + curl -fsSL -o "$srss_dir/$f" "https://raw.githubusercontent.com/2dust/sing-box-rules/refs/heads/rule-set-geosite/$f" done - # Unify to bin unify_geo_layout "$outroot" } -# Prefer the prebuilt v2rayN core bundle; then unify geo layout -download_v2rayn_bundle() { - local outroot="$1" rid="$2" +populate_assets_zip_mode() { + local outroot="$1" + local rid="$2" local url="" - if [[ "$rid" == "linux-arm64" ]]; then - url="https://raw.githubusercontent.com/2dust/v2rayN-core-bin/refs/heads/master/v2rayN-linux-arm64.zip" - else - url="https://raw.githubusercontent.com/2dust/v2rayN-core-bin/refs/heads/master/v2rayN-linux-64.zip" - fi + local tmp="" + local nested_dir="" + + url="$(bundle_url_for_rid "$rid")" || { echo "[!] Bundle unsupported RID: $rid"; return 1; } + echo "[+] Try v2rayN bundle archive: $url" - local tmp zipname - tmp="$(mktemp -d)"; zipname="$tmp/v2rayn.zip" - curl -fL "$url" -o "$zipname" || { echo "[!] Bundle download failed"; return 1; } - unzip -q "$zipname" -d "$tmp" || { echo "[!] Bundle unzip failed"; return 1; } + + tmp="$(mktemp -d)" + curl -fL "$url" -o "$tmp/v2rayn.zip" || { echo "[!] Bundle download failed"; rm -rf "$tmp"; return 1; } + unzip -q "$tmp/v2rayn.zip" -d "$tmp" || { echo "[!] Bundle unzip failed"; rm -rf "$tmp"; return 1; } if [[ -d "$tmp/bin" ]]; then mkdir -p "$outroot/bin" @@ -339,7 +410,6 @@ download_v2rayn_bundle() { rm -f "$outroot/v2rayn.zip" 2>/dev/null || true find "$outroot" -type d -name "mihomo" -prune -exec rm -rf {} + 2>/dev/null || true - local nested_dir nested_dir="$(find "$outroot" -maxdepth 1 -type d -name 'v2rayN-linux-*' | head -n1 || true)" if [[ -n "$nested_dir" && -d "$nested_dir/bin" ]]; then mkdir -p "$outroot/bin" @@ -347,109 +417,74 @@ download_v2rayn_bundle() { rm -rf "$nested_dir" fi - # Unify to bin/ unify_geo_layout "$outroot" + rm -rf "$tmp" echo "[+] Bundle extracted to $outroot" } -# ===== Build results collection for --arch all ======================================== -BUILT_RPMS=() # Will collect absolute paths of built RPMs -BUILT_ALL=0 # Flag to know if we should print the final summary +populate_assets_netcore_mode() { + local outroot="$1" + local rid="$2" -# ===== Build (single-arch) function ==================================================== -build_for_arch() { - # $1: target short arch: x64 | arm64 - local short="$1" - local rid rpm_target archdir - case "$short" in - x64) rid="linux-x64"; rpm_target="x86_64"; archdir="x86_64" ;; - arm64) rid="linux-arm64"; rpm_target="aarch64"; archdir="aarch64" ;; - *) echo "Unknown arch '$short' (use x64|arm64)"; return 1;; - esac + mkdir -p "$outroot/bin/xray" "$outroot/bin/sing_box" - echo "[*] Building for target: $short (RID=$rid, RPM --target $rpm_target)" + if [[ "$WITH_CORE" == "xray" || "$WITH_CORE" == "both" ]]; then + download_xray "$outroot/bin/xray" "$rid" || echo "[!] xray download failed (skipped)" + fi - # .NET publish (self-contained) for this RID - dotnet clean "$PROJECT" -c Release - rm -rf "$(dirname "$PROJECT")/bin/Release/net10.0" || true + if [[ "$WITH_CORE" == "sing-box" || "$WITH_CORE" == "both" ]]; then + download_singbox "$outroot/bin/sing_box" "$rid" || echo "[!] sing-box download failed (skipped)" + fi - dotnet restore "$PROJECT" - dotnet publish "$PROJECT" \ - -c Release -r "$rid" \ - -p:PublishSingleFile=false \ - -p:SelfContained=true - - # Per-arch variables (scoped) - local RID_DIR="$rid" - local PUBDIR - PUBDIR="$(dirname "$PROJECT")/bin/Release/net10.0/${RID_DIR}/publish" - [[ -d "$PUBDIR" ]] || { echo "Publish directory not found: $PUBDIR"; return 1; } - - # Per-arch working area - local PKGROOT="v2rayN-publish" - local WORKDIR - WORKDIR="$(mktemp -d)" - trap '[[ -n "${WORKDIR:-}" ]] && rm -rf "$WORKDIR"' RETURN - - # rpmbuild topdir selection - local TOPDIR SPECDIR SOURCEDIR - rpmdev-setuptree - TOPDIR="${HOME}/rpmbuild" - SPECDIR="${TOPDIR}/SPECS" - SOURCEDIR="${TOPDIR}/SOURCES" - - # Stage publish content - mkdir -p "$WORKDIR/$PKGROOT" - cp -a "$PUBDIR/." "$WORKDIR/$PKGROOT/" - - # Required icon - local ICON_CANDIDATE - PROJECT_DIR="$(cd "$(dirname "$PROJECT")" && pwd)" - ICON_CANDIDATE="$PROJECT_DIR/v2rayN.png" - [[ -f "$ICON_CANDIDATE" ]] || { echo "Required icon not found: $ICON_CANDIDATE"; return 1; } - cp "$ICON_CANDIDATE" "$WORKDIR/$PKGROOT/v2rayn.png" - - # Prepare bin structure - mkdir -p "$WORKDIR/$PKGROOT/bin/xray" "$WORKDIR/$PKGROOT/bin/sing_box" - - # Bundle / cores per-arch - fetch_separate_cores_and_rules() { - local outroot="$1" - - if [[ "$WITH_CORE" == "xray" || "$WITH_CORE" == "both" ]]; then - download_xray "$outroot/bin/xray" "$RID_DIR" || echo "[!] xray download failed (skipped)" - fi - if [[ "$WITH_CORE" == "sing-box" || "$WITH_CORE" == "both" ]]; then - download_singbox "$outroot/bin/sing_box" "$RID_DIR" || echo "[!] sing-box download failed (skipped)" - fi - download_geo_assets "$outroot" || echo "[!] Geo rules download failed (skipped)" - } + download_geo_assets "$outroot" || echo "[!] Geo rules download failed (skipped)" +} + +stage_runtime_assets() { + local outroot="$1" + local rid="$2" + + mkdir -p "$outroot/bin/xray" "$outroot/bin/sing_box" if [[ "$FORCE_NETCORE" -eq 0 ]]; then - if download_v2rayn_bundle "$WORKDIR/$PKGROOT" "$RID_DIR"; then + if populate_assets_zip_mode "$outroot" "$rid"; then echo "[*] Using v2rayN bundle archive." else echo "[*] Bundle failed, fallback to separate core + rules." - fetch_separate_cores_and_rules "$WORKDIR/$PKGROOT" + populate_assets_netcore_mode "$outroot" "$rid" fi else echo "[*] --netcore specified: use separate core + rules." - fetch_separate_cores_and_rules "$WORKDIR/$PKGROOT" + populate_assets_netcore_mode "$outroot" "$rid" fi +} + +describe_target() { + local short="$1" + + case "$short" in + x64) printf '%s\n%s\n%s\n' "linux-x64" "x86_64" "x86_64" ;; + arm64) printf '%s\n%s\n%s\n' "linux-arm64" "aarch64" "aarch64" ;; + *) echo "Unknown arch '$short' (use x64|arm64)" >&2; return 1 ;; + esac +} + +publish_binary() { + local rid="$1" + + dotnet clean "$PROJECT" -c Release + rm -rf "$(dirname "$PROJECT")/bin/Release/net10.0" || true + dotnet restore "$PROJECT" + dotnet publish "$PROJECT" -c Release -r "$rid" -p:PublishSingleFile=false -p:SelfContained=true +} - # Tarball - mkdir -p "$SOURCEDIR" - tar -C "$WORKDIR" -czf "$SOURCEDIR/$PKGROOT.tar.gz" "$PKGROOT" +write_spec_file() { + local specfile="$1" - # SPEC - local SPECFILE="$SPECDIR/v2rayN.spec" - mkdir -p "$SPECDIR" - cat > "$SPECFILE" <<'SPEC' + cat > "$specfile" <<'SPEC' %global debug_package %{nil} %undefine _debuginfo_subpackages %undefine _debugsource_packages -# Ignore outdated LTTng dependencies incorrectly reported by the .NET runtime (to avoid installation failures) %global __requires_exclude ^liblttng-ust\.so\..*$ Name: v2rayN @@ -462,7 +497,6 @@ BugURL: https://github.com/2dust/v2rayN/issues ExclusiveArch: aarch64 x86_64 Source0: __PKGROOT__.tar.gz -# Runtime dependencies (Avalonia / X11 / Fonts / GL) Requires: cairo, pango, openssl, mesa-libEGL, mesa-libGL Requires: glibc >= 2.34 Requires: fontconfig >= 2.13.1 @@ -483,28 +517,23 @@ https://github.com/2dust/v2rayN %setup -q -n __PKGROOT__ %build -# no build %install install -dm0755 %{buildroot}/opt/v2rayN cp -a * %{buildroot}/opt/v2rayN/ -# Normalize permissions find %{buildroot}/opt/v2rayN -type d -exec chmod 0755 {} + find %{buildroot}/opt/v2rayN -type f -exec chmod 0644 {} + [ -f %{buildroot}/opt/v2rayN/v2rayN ] && chmod 0755 %{buildroot}/opt/v2rayN/v2rayN || : -# Launcher (prefer native ELF first, then DLL fallback) install -dm0755 %{buildroot}%{_bindir} install -m0755 /dev/stdin %{buildroot}%{_bindir}/v2rayn << 'EOF' #!/usr/bin/bash set -euo pipefail DIR="/opt/v2rayN" -# Prefer native apphost if [[ -x "$DIR/v2rayN" ]]; then exec "$DIR/v2rayN" "$@"; fi -# DLL fallback for dll in v2rayN.Desktop.dll v2rayN.dll; do if [[ -f "$DIR/$dll" ]]; then exec /usr/bin/dotnet "$DIR/$dll" "$@"; fi done @@ -514,7 +543,6 @@ ls -l "$DIR" >&2 || true exit 1 EOF -# Desktop file install -dm0755 %{buildroot}%{_datadir}/applications install -m0644 /dev/stdin %{buildroot}%{_datadir}/applications/v2rayn.desktop << 'EOF' [Desktop Entry] @@ -527,7 +555,6 @@ Terminal=false Categories=Network; EOF -# Icon install -dm0755 %{buildroot}%{_datadir}/icons/hicolor/256x256/apps install -m0644 %{_builddir}/__PKGROOT__/v2rayn.png %{buildroot}%{_datadir}/icons/hicolor/256x256/apps/v2rayn.png @@ -546,45 +573,129 @@ install -m0644 %{_builddir}/__PKGROOT__/v2rayn.png %{buildroot}%{_datadir}/icons %{_datadir}/icons/hicolor/256x256/apps/v2rayn.png SPEC - # Replace placeholders - sed -i "s/__VERSION__/${VERSION}/g" "$SPECFILE" - sed -i "s/__PKGROOT__/${PKGROOT}/g" "$SPECFILE" + sed -i "s/__VERSION__/${VERSION}/g" "$specfile" + sed -i "s/__PKGROOT__/${PKGROOT}/g" "$specfile" +} - # Build RPM for this arch - rpmbuild -ba "$SPECFILE" --target "$rpm_target" +package_binary() { + local short="$1" + local rid="$2" + local rpm_target="$3" + local archdir="$4" + local pubdir="" + local workdir="" + local specfile="" + local sourcedir="" + local specdir="" + local project_dir="" + local icon_candidate="" + local f="" + + pubdir="$(dirname "$PROJECT")/bin/Release/net10.0/${rid}/publish" + [[ -d "$pubdir" ]] || { echo "Publish directory not found: $pubdir"; return 1; } + + workdir="$(mktemp -d)" + trap '[[ -n "${workdir:-}" ]] && rm -rf "$workdir"' RETURN + + mkdir -p "$workdir/$PKGROOT" + cp -a "$pubdir/." "$workdir/$PKGROOT/" + + project_dir="$(cd "$(dirname "$PROJECT")" && pwd)" + icon_candidate="$project_dir/v2rayN.png" + [[ -f "$icon_candidate" ]] || { echo "Required icon not found: $icon_candidate"; return 1; } + cp "$icon_candidate" "$workdir/$PKGROOT/v2rayn.png" + + stage_runtime_assets "$workdir/$PKGROOT" "$rid" + + rpmdev-setuptree + sourcedir="${RPM_TOPDIR}/SOURCES" + specdir="${RPM_TOPDIR}/SPECS" + specfile="${specdir}/v2rayN.spec" + + mkdir -p "$sourcedir" "$specdir" + tar -C "$workdir" -czf "$sourcedir/$PKGROOT.tar.gz" "$PKGROOT" + + write_spec_file "$specfile" + rpmbuild -ba "$specfile" --target "$rpm_target" echo "Build done for $short. RPM at:" - local f - for f in "${TOPDIR}/RPMS/${archdir}/v2rayN-${VERSION}-1"*.rpm; do + for f in "${RPM_TOPDIR}/RPMS/${archdir}/v2rayN-${VERSION}-1"*.rpm; do [[ -e "$f" ]] || continue echo " $f" BUILT_RPMS+=("$f") done } -# ===== Arch selection and build orchestration ========================================= -case "${ARCH_OVERRIDE:-}" in - all) targets=(x64 arm64); BUILT_ALL=1 ;; - x64|amd64) targets=(x64) ;; - arm64|aarch64) targets=(arm64) ;; - "") targets=($([[ "$host_arch" == "aarch64" ]] && echo arm64 || echo x64)) ;; - *) echo "Unknown --arch '${ARCH_OVERRIDE}'. Use x64|arm64|all."; exit 1 ;; -esac - -for arch in "${targets[@]}"; do - build_for_arch "$arch" -done +select_targets() { + case "${ARCH_OVERRIDE:-}" in + all) printf '%s\n' x64 arm64 ;; + x64|amd64) printf '%s\n' x64 ;; + arm64|aarch64) printf '%s\n' arm64 ;; + "") + case "$HOST_ARCH" in + x86_64) printf '%s\n' x64 ;; + aarch64) printf '%s\n' arm64 ;; + *) return 1 ;; + esac + ;; + *) + echo "Unknown --arch '${ARCH_OVERRIDE}'. Use x64|arm64|all." >&2 + return 1 + ;; + esac +} -# Print Both arches information -if [[ "$BUILT_ALL" -eq 1 ]]; then - echo "" - echo "================ Build Summary (both architectures) ================" - if [[ "${#BUILT_RPMS[@]}" -gt 0 ]]; then - for rp in "${BUILT_RPMS[@]}"; do - echo "$rp" - done - else - echo "No RPMs detected in summary (check build logs above)." +build_one_target() { + local short="$1" + local meta=() + local rid="" + local rpm_target="" + local archdir="" + + mapfile -t meta < <(describe_target "$short") || return 1 + rid="${meta[0]}" + rpm_target="${meta[1]}" + archdir="${meta[2]}" + + echo "[*] Building for target: $short (RID=$rid, RPM --target $rpm_target)" + publish_binary "$rid" + package_binary "$short" "$rid" "$rpm_target" "$archdir" +} + +print_summary() { + if [[ "$BUILT_ALL" -eq 1 ]]; then + local rp="" + echo "" + echo "================ Build Summary (both architectures) ================" + if [[ "${#BUILT_RPMS[@]}" -gt 0 ]]; then + for rp in "${BUILT_RPMS[@]}"; do + echo "$rp" + done + else + echo "No RPMs detected in summary (check build logs above)." + fi + echo "====================================================================" fi - echo "====================================================================" -fi +} + +main() { + local targets=() + local arch="" + + parse_args "$@" + detect_environment + install_dependencies + prepare_workspace + resolve_version + + mapfile -t targets < <(select_targets) + [[ "${ARCH_OVERRIDE:-}" == "all" ]] && BUILT_ALL=1 || BUILT_ALL=0 + + for arch in "${targets[@]}"; do + build_one_target "$arch" + done + + print_summary +} + +main "$@" \ No newline at end of file diff --git a/v2rayN/Directory.Packages.props b/v2rayN/Directory.Packages.props index 4cdb0ad7006..668fa9725dc 100644 --- a/v2rayN/Directory.Packages.props +++ b/v2rayN/Directory.Packages.props @@ -25,12 +25,14 @@ - + + + - \ No newline at end of file + diff --git a/v2rayN/ServiceLib/ServiceLib.csproj b/v2rayN/ServiceLib/ServiceLib.csproj index 60d9c62276e..6a506e36f95 100644 --- a/v2rayN/ServiceLib/ServiceLib.csproj +++ b/v2rayN/ServiceLib/ServiceLib.csproj @@ -10,7 +10,8 @@ true - + + diff --git a/v2rayN/ServiceLib/Services/UpdateService.cs b/v2rayN/ServiceLib/Services/UpdateService.cs index 57f9d14b348..ee5efc145fd 100644 --- a/v2rayN/ServiceLib/Services/UpdateService.cs +++ b/v2rayN/ServiceLib/Services/UpdateService.cs @@ -301,14 +301,10 @@ private async Task ParseDownloadUrl(ECoreType type, UpdateResult r } else if (Utils.IsLinux()) { - var arch = RuntimeInformation.ProcessArchitecture; - if (arch.ToString().Equals("RiscV64", StringComparison.OrdinalIgnoreCase)) - { - return coreInfo?.DownloadUrlLinuxRiscV64; - } - return arch switch + return RuntimeInformation.ProcessArchitecture switch { Architecture.Arm64 => coreInfo?.DownloadUrlLinuxArm64, + Architecture.RiscV64 => coreInfo?.DownloadUrlLinuxRiscV64, Architecture.X64 => coreInfo?.DownloadUrlLinux64, _ => null, }; From 51b384e119da5fe725fcde7a61d2569f3a4c5d72 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Tue, 12 May 2026 09:10:22 +0800 Subject: [PATCH 05/61] Bug fix https://github.com/2dust/v2rayN/issues/9277 --- .../Services/CoreConfig/V2ray/V2rayOutboundService.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs index f383696090f..0cd35085b83 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayOutboundService.cs @@ -491,7 +491,6 @@ private void FillBoundStreamSettings(Outbounds4Ray outbound) //ws case nameof(ETransport.ws): WsSettings4Ray wsSettings = new(); - wsSettings.headers = new Headers4Ray(); if (host.IsNotEmpty()) { @@ -503,6 +502,7 @@ private void FillBoundStreamSettings(Outbounds4Ray outbound) } if (useragent.IsNotEmpty()) { + wsSettings.headers ??= new Headers4Ray(); wsSettings.headers.UserAgent = useragent; } streamSettings.wsSettings = wsSettings; @@ -522,6 +522,7 @@ private void FillBoundStreamSettings(Outbounds4Ray outbound) } if (useragent.IsNotEmpty()) { + httpupgradeSettings.headers ??= new Headers4Ray(); httpupgradeSettings.headers.UserAgent = useragent; } streamSettings.httpupgradeSettings = httpupgradeSettings; From 5c85598cfad81d7f7a3c26ef0b44362f39533ec6 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Wed, 13 May 2026 09:07:38 +0800 Subject: [PATCH 06/61] Update GlobalHotKeys --- v2rayN/GlobalHotKeys | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/v2rayN/GlobalHotKeys b/v2rayN/GlobalHotKeys index 488f1e69ead..569a95bb0fd 160000 --- a/v2rayN/GlobalHotKeys +++ b/v2rayN/GlobalHotKeys @@ -1 +1 @@ -Subproject commit 488f1e69ead7cce22c8502d889127e4fcc7c5279 +Subproject commit 569a95bb0fd2280d8d5581250aae54ecc2122d10 From 3778d2058ebad89e28b3bf443a0e39c55dc85262 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 13 May 2026 09:08:58 +0800 Subject: [PATCH 07/61] Bump actions/checkout from 5 to 6 (#9288) Bumps [actions/checkout](https://github.com/actions/checkout) from 5 to 6. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v5...v6) --- updated-dependencies: - dependency-name: actions/checkout dependency-version: '6' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/build-linux.yml | 4 ++-- .github/workflows/build-osx.yml | 2 +- .github/workflows/build.yml | 2 +- .github/workflows/package-zip.yml | 2 +- .github/workflows/test.yml | 2 +- .github/workflows/update-riscv-depand.yml | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build-linux.yml b/.github/workflows/build-linux.yml index bb1c8a16939..cccdafa8c90 100644 --- a/.github/workflows/build-linux.yml +++ b/.github/workflows/build-linux.yml @@ -49,7 +49,7 @@ jobs: libc6 libgcc-s1 libstdc++6 zlib1g libicu-dev libssl-dev - name: Checkout repo (for scripts) - uses: actions/checkout@v6.0.2 + uses: actions/checkout@v6 with: submodules: 'recursive' fetch-depth: '0' @@ -151,7 +151,7 @@ jobs: dnf repolist | grep -i epel || true - name: Checkout repo (for scripts) - uses: actions/checkout@v6.0.2 + uses: actions/checkout@v6 with: submodules: 'recursive' fetch-depth: '0' diff --git a/.github/workflows/build-osx.yml b/.github/workflows/build-osx.yml index ddb541cb1b7..340fc32f701 100644 --- a/.github/workflows/build-osx.yml +++ b/.github/workflows/build-osx.yml @@ -45,7 +45,7 @@ jobs: }} steps: - name: Checkout - uses: actions/checkout@v6.0.2 + uses: actions/checkout@v6 - name: Restore build artifacts uses: actions/download-artifact@v8 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f51965cbc86..11ae9ad229e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -46,7 +46,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v6.0.2 + uses: actions/checkout@v6 with: submodules: 'recursive' fetch-depth: '0' diff --git a/.github/workflows/package-zip.yml b/.github/workflows/package-zip.yml index d55c6837d3a..1f9b3613996 100644 --- a/.github/workflows/package-zip.yml +++ b/.github/workflows/package-zip.yml @@ -37,7 +37,7 @@ jobs: }} steps: - name: Checkout - uses: actions/checkout@v6.0.2 + uses: actions/checkout@v6 - name: Restore build artifacts uses: actions/download-artifact@v8 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9364283fd6b..f0f0f872dbf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v6.0.2 + uses: actions/checkout@v6 with: submodules: 'recursive' fetch-depth: '0' diff --git a/.github/workflows/update-riscv-depand.yml b/.github/workflows/update-riscv-depand.yml index 87600913268..9cb57d5e716 100644 --- a/.github/workflows/update-riscv-depand.yml +++ b/.github/workflows/update-riscv-depand.yml @@ -18,7 +18,7 @@ jobs: runs-on: ubuntu-24.04 steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v6 - uses: actions/setup-dotnet@v5 with: From 8446b4df8b508683147d154c2daa37afedf12a22 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Wed, 13 May 2026 09:32:05 +0800 Subject: [PATCH 08/61] Bump package versions in Directory.Packages.props --- v2rayN/Directory.Packages.props | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/v2rayN/Directory.Packages.props b/v2rayN/Directory.Packages.props index 668fa9725dc..37e08fbd17d 100644 --- a/v2rayN/Directory.Packages.props +++ b/v2rayN/Directory.Packages.props @@ -7,24 +7,24 @@ - - + + - - + + - + - + - - + + - + @@ -32,7 +32,7 @@ - + - + \ No newline at end of file From 780777068d0bf264e283d29c675c2d0bd68f5459 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Wed, 13 May 2026 09:34:18 +0800 Subject: [PATCH 09/61] up 7.22.0 --- v2rayN/Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/v2rayN/Directory.Build.props b/v2rayN/Directory.Build.props index 9711db8116f..7d8defbd2f5 100644 --- a/v2rayN/Directory.Build.props +++ b/v2rayN/Directory.Build.props @@ -1,7 +1,7 @@ - 7.21.3 + 7.22.0 From 58d264155987626ab6d6d234052f4b35de550b68 Mon Sep 17 00:00:00 2001 From: Miheichev Aleksandr Sergeevich Date: Thu, 14 May 2026 11:25:07 +0000 Subject: [PATCH 10/61] chore: remove NoWarn and fix .NET 10 build warnings across platforms (#9301) * deps: bump ZXing.Net.Bindings.SkiaSharp from 0.16.14 to 0.16.22 Patch update to the latest stable release on the 0.16.x line. No breaking changes, no public API changes - purely internal fixes. Verified by a full Release build of v2rayN.sln on .NET 10; no new warnings or errors are introduced. * chore: remove NoWarn and fix .NET 10 build warnings Removes the repository-level NoWarn suppression from Directory.Build.props and addresses the warnings that surface on top of the .NET 10 migration in #9179, keeping Debug, Release, and cross-platform publishes warning-free without suppressing warnings globally. Changes: - Removes CA1031;CS1591;NU1507;CA1416;IDE0058;IDE0053;IDE0200 from Directory.Build.props. - Annotates Windows-only APIs with [SupportedOSPlatform] and [SupportedOSPlatformGuard] so CA1416 accepts that the Windows surface is gated behind Utils.IsWindows() / Utils.IsNonWindows(). - Splits Utils.SetUnixFileMode into a cross-platform wrapper and a private [UnsupportedOSPlatform("windows")] implementation so File.SetUnixFileMode never reaches the analyzer on Windows builds. - Adds a parameterless constructor to MessageBoxDialog so Avalonia's runtime XAML loader (AVLN3001) can instantiate the dialog. - Moves the WPF high-DPI configuration from app.manifest to PerMonitorV2 in v2rayN.csproj, fixing WFO0003. - Adds global using System.Runtime.Versioning; to ServiceLib and v2rayN.Desktop so the platform attributes are usable project-wide. * test: make cycle dependency tests locale-independent Accept the localized Russian cycle dependency diagnostic in CoreConfigContextBuilderTests so the assertions pass when tests run under a Russian UI culture. * fix: tighten Unix platform handling Adds Linux and macOS platform guards so the analyzer can narrow calls through Utils.IsLinux() and Utils.IsMacOS(). Marks the Linux/macOS autostart and system proxy helpers with explicit platform attributes. Updates Utils.GetSystemHosts() to read /etc/hosts on Linux and macOS while keeping the existing Windows hosts and hosts.ics merge behavior. --- v2rayN/Directory.Build.props | 1 - v2rayN/Directory.Packages.props | 2 +- .../Context/CoreConfigContextBuilderTests.cs | 3 +- v2rayN/ServiceLib/Common/Utils.cs | 34 ++++++++++++++++--- v2rayN/ServiceLib/Common/WindowsUtils.cs | 1 + v2rayN/ServiceLib/GlobalUsings.cs | 1 + .../ServiceLib/Handler/AutoStartupHandler.cs | 10 ++++++ .../Handler/SysProxy/ProxySettingLinux.cs | 1 + .../Handler/SysProxy/ProxySettingOSX.cs | 1 + .../Handler/SysProxy/ProxySettingWindows.cs | 1 + .../Handler/SysProxy/SysProxyHandler.cs | 1 + v2rayN/ServiceLib/Manager/CoreManager.cs | 1 + .../ServiceLib/Services/WindowsJobService.cs | 1 + .../Common/QRCodeAvaloniaUtils.cs | 1 + v2rayN/v2rayN.Desktop/GlobalUsings.cs | 1 + .../v2rayN.Desktop/Manager/HotkeyManager.cs | 7 ++++ .../Views/MessageBoxDialog.axaml.cs | 5 +++ v2rayN/v2rayN/app.manifest | 7 ---- v2rayN/v2rayN/v2rayN.csproj | 1 + 19 files changed, 65 insertions(+), 15 deletions(-) diff --git a/v2rayN/Directory.Build.props b/v2rayN/Directory.Build.props index 7d8defbd2f5..01ab2f787a0 100644 --- a/v2rayN/Directory.Build.props +++ b/v2rayN/Directory.Build.props @@ -8,7 +8,6 @@ net10.0 true true - CA1031;CS1591;NU1507;CA1416;IDE0058;IDE0053;IDE0200 annotations enable 2dust diff --git a/v2rayN/Directory.Packages.props b/v2rayN/Directory.Packages.props index 37e08fbd17d..521afe14e30 100644 --- a/v2rayN/Directory.Packages.props +++ b/v2rayN/Directory.Packages.props @@ -33,6 +33,6 @@ - + \ No newline at end of file diff --git a/v2rayN/ServiceLib.Tests/CoreConfig/Context/CoreConfigContextBuilderTests.cs b/v2rayN/ServiceLib.Tests/CoreConfig/Context/CoreConfigContextBuilderTests.cs index ee329845007..105310927c1 100644 --- a/v2rayN/ServiceLib.Tests/CoreConfig/Context/CoreConfigContextBuilderTests.cs +++ b/v2rayN/ServiceLib.Tests/CoreConfig/Context/CoreConfigContextBuilderTests.cs @@ -99,7 +99,8 @@ private static bool ContainsCycleDependencyMessage(string message) { return message.Contains("cycle dependency", StringComparison.OrdinalIgnoreCase) || message.Contains("循环依赖", StringComparison.Ordinal) - || message.Contains("循環依賴", StringComparison.Ordinal); + || message.Contains("循環依賴", StringComparison.Ordinal) + || message.Contains("циклическую зависимость", StringComparison.OrdinalIgnoreCase); } private static async Task UpsertProfilesAsync(params ProfileItem[] profiles) diff --git a/v2rayN/ServiceLib/Common/Utils.cs b/v2rayN/ServiceLib/Common/Utils.cs index c0d8816d8be..9c2bd4af43c 100644 --- a/v2rayN/ServiceLib/Common/Utils.cs +++ b/v2rayN/ServiceLib/Common/Utils.cs @@ -864,15 +864,25 @@ private static Dictionary GetSystemHosts(string hostFile) public static Dictionary GetSystemHosts() { - var hosts = GetSystemHosts(@"C:\Windows\System32\drivers\etc\hosts"); - var hostsIcs = GetSystemHosts(@"C:\Windows\System32\drivers\etc\hosts.ics"); + if (IsWindows()) + { + var hosts = GetSystemHosts(@"C:\Windows\System32\drivers\etc\hosts"); + var hostsIcs = GetSystemHosts(@"C:\Windows\System32\drivers\etc\hosts.ics"); + + foreach (var (key, value) in hostsIcs) + { + hosts[key] = value; + } + + return hosts; + } - foreach (var (key, value) in hostsIcs) + if (IsLinux() || IsMacOS()) { - hosts[key] = value; + return GetSystemHosts("/etc/hosts"); } - return hosts; + return new Dictionary(); } public static async Task GetCliWrapOutput(string filePath, string? arg) @@ -1114,12 +1124,16 @@ public static string GetBinConfigPath(string filename = "") #region Platform + [SupportedOSPlatformGuard("windows")] public static bool IsWindows() => OperatingSystem.IsWindows(); + [SupportedOSPlatformGuard("linux")] public static bool IsLinux() => OperatingSystem.IsLinux(); + [SupportedOSPlatformGuard("macos")] public static bool IsMacOS() => OperatingSystem.IsMacOS(); + [UnsupportedOSPlatformGuard("windows")] public static bool IsNonWindows() => !OperatingSystem.IsWindows(); public static string GetExeName(string name) @@ -1214,6 +1228,16 @@ public static bool IsPackagedInstall() } public static bool SetUnixFileMode(string? fileName) + { + if (IsWindows()) + { + return false; + } + return SetUnixFileModeInternal(fileName); + } + + [UnsupportedOSPlatform("windows")] + private static bool SetUnixFileModeInternal(string? fileName) { try { diff --git a/v2rayN/ServiceLib/Common/WindowsUtils.cs b/v2rayN/ServiceLib/Common/WindowsUtils.cs index 6cd47f0a809..5792dcecfaf 100644 --- a/v2rayN/ServiceLib/Common/WindowsUtils.cs +++ b/v2rayN/ServiceLib/Common/WindowsUtils.cs @@ -2,6 +2,7 @@ namespace ServiceLib.Common; +[SupportedOSPlatform("windows")] internal static class WindowsUtils { private static readonly string _tag = "WindowsUtils"; diff --git a/v2rayN/ServiceLib/GlobalUsings.cs b/v2rayN/ServiceLib/GlobalUsings.cs index 9d311324264..6e051d80410 100644 --- a/v2rayN/ServiceLib/GlobalUsings.cs +++ b/v2rayN/ServiceLib/GlobalUsings.cs @@ -8,6 +8,7 @@ global using System.Reactive.Linq; global using System.Reflection; global using System.Runtime.InteropServices; +global using System.Runtime.Versioning; global using System.Security.Cryptography; global using System.Text; global using System.Text.Encodings.Web; diff --git a/v2rayN/ServiceLib/Handler/AutoStartupHandler.cs b/v2rayN/ServiceLib/Handler/AutoStartupHandler.cs index bc86cd7f90c..fd7d7fc9e1c 100644 --- a/v2rayN/ServiceLib/Handler/AutoStartupHandler.cs +++ b/v2rayN/ServiceLib/Handler/AutoStartupHandler.cs @@ -41,6 +41,7 @@ public static async Task UpdateTask(Config config) #region Windows + [SupportedOSPlatform("windows")] private static async Task ClearTaskWindows() { var autoRunName = GetAutoRunNameWindows(); @@ -53,6 +54,7 @@ private static async Task ClearTaskWindows() await Task.CompletedTask; } + [SupportedOSPlatform("windows")] private static async Task SetTaskWindows() { try @@ -82,6 +84,7 @@ private static async Task SetTaskWindows() /// /// /// + [SupportedOSPlatform("windows")] public static void AutoStartTaskService(string taskName, string fileName, string description) { if (taskName.IsNullOrEmpty()) @@ -124,6 +127,7 @@ private static string GetAutoRunNameWindows() #region Linux + [SupportedOSPlatform("linux")] private static async Task ClearTaskLinux() { try @@ -137,6 +141,7 @@ private static async Task ClearTaskLinux() await Task.CompletedTask; } + [SupportedOSPlatform("linux")] private static async Task SetTaskLinux() { try @@ -157,6 +162,7 @@ private static async Task SetTaskLinux() } } + [SupportedOSPlatform("linux")] private static string GetHomePathLinux() { var homePath = Path.Combine(Utils.GetHomePath(), ".config", "autostart", $"{Global.AppName}.desktop"); @@ -168,6 +174,7 @@ private static string GetHomePathLinux() #region macOS + [SupportedOSPlatform("macos")] private static async Task ClearTaskOSX() { try @@ -187,6 +194,7 @@ private static async Task ClearTaskOSX() } } + [SupportedOSPlatform("macos")] private static async Task SetTaskOSX() { try @@ -204,6 +212,7 @@ private static async Task SetTaskOSX() } } + [SupportedOSPlatform("macos")] private static string GetLaunchAgentPathMacOS() { var homePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); @@ -212,6 +221,7 @@ private static string GetLaunchAgentPathMacOS() return launchAgentPath; } + [SupportedOSPlatform("macos")] private static string GenerateLaunchAgentPlist() { var exePath = Utils.GetExePath(); diff --git a/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingLinux.cs b/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingLinux.cs index 4929c72ee33..14d61d9ca19 100644 --- a/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingLinux.cs +++ b/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingLinux.cs @@ -1,5 +1,6 @@ namespace ServiceLib.Handler.SysProxy; +[SupportedOSPlatform("linux")] public static class ProxySettingLinux { private static readonly string _proxySetFileName = $"{Global.ProxySetLinuxShellFileName.Replace(Global.NamespaceSample, "")}.sh"; diff --git a/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingOSX.cs b/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingOSX.cs index 56fbe24d558..b598a06cd9e 100644 --- a/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingOSX.cs +++ b/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingOSX.cs @@ -1,5 +1,6 @@ namespace ServiceLib.Handler.SysProxy; +[SupportedOSPlatform("macos")] public static class ProxySettingOSX { private static readonly string _proxySetFileName = $"{Global.ProxySetOSXShellFileName.Replace(Global.NamespaceSample, "")}.sh"; diff --git a/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingWindows.cs b/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingWindows.cs index 8dc2f335adc..614437d7cb9 100644 --- a/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingWindows.cs +++ b/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingWindows.cs @@ -2,6 +2,7 @@ namespace ServiceLib.Handler.SysProxy; +[SupportedOSPlatform("windows")] public static class ProxySettingWindows { private const string _regPath = @"Software\Microsoft\Windows\CurrentVersion\Internet Settings"; diff --git a/v2rayN/ServiceLib/Handler/SysProxy/SysProxyHandler.cs b/v2rayN/ServiceLib/Handler/SysProxy/SysProxyHandler.cs index 21453591e7b..c525da29be6 100644 --- a/v2rayN/ServiceLib/Handler/SysProxy/SysProxyHandler.cs +++ b/v2rayN/ServiceLib/Handler/SysProxy/SysProxyHandler.cs @@ -88,6 +88,7 @@ private static void GetWindowsProxyString(Config config, int port, out string st } } + [SupportedOSPlatform("windows")] private static async Task SetWindowsProxyPac(int port) { var portPac = AppManager.Instance.GetLocalPort(EInboundProtocol.pac); diff --git a/v2rayN/ServiceLib/Manager/CoreManager.cs b/v2rayN/ServiceLib/Manager/CoreManager.cs index c309680a036..41d2343b25c 100644 --- a/v2rayN/ServiceLib/Manager/CoreManager.cs +++ b/v2rayN/ServiceLib/Manager/CoreManager.cs @@ -8,6 +8,7 @@ public class CoreManager private static readonly Lazy _instance = new(() => new()); public static CoreManager Instance => _instance.Value; private Config _config; + [SupportedOSPlatform("windows")] private WindowsJobService? _processJob; private ProcessService? _processService; private ProcessService? _processPreService; diff --git a/v2rayN/ServiceLib/Services/WindowsJobService.cs b/v2rayN/ServiceLib/Services/WindowsJobService.cs index ffd4a36a822..5bc8f276702 100644 --- a/v2rayN/ServiceLib/Services/WindowsJobService.cs +++ b/v2rayN/ServiceLib/Services/WindowsJobService.cs @@ -3,6 +3,7 @@ namespace ServiceLib.Services; /// /// http://stackoverflow.com/questions/6266820/working-example-of-createjobobject-setinformationjobobject-pinvoke-in-net /// +[SupportedOSPlatform("windows")] public sealed class WindowsJobService : IDisposable { private nint handle = nint.Zero; diff --git a/v2rayN/v2rayN.Desktop/Common/QRCodeAvaloniaUtils.cs b/v2rayN/v2rayN.Desktop/Common/QRCodeAvaloniaUtils.cs index 90f60c7f273..ba416e719f1 100644 --- a/v2rayN/v2rayN.Desktop/Common/QRCodeAvaloniaUtils.cs +++ b/v2rayN/v2rayN.Desktop/Common/QRCodeAvaloniaUtils.cs @@ -23,6 +23,7 @@ public partial class QRCodeAvaloniaUtils } } + [SupportedOSPlatform("windows")] private static byte[]? CaptureScreenWindows() { var hdcScreen = IntPtr.Zero; diff --git a/v2rayN/v2rayN.Desktop/GlobalUsings.cs b/v2rayN/v2rayN.Desktop/GlobalUsings.cs index 9c28c767011..558852d255d 100644 --- a/v2rayN/v2rayN.Desktop/GlobalUsings.cs +++ b/v2rayN/v2rayN.Desktop/GlobalUsings.cs @@ -5,6 +5,7 @@ global using System.Linq; global using System.Reactive.Disposables.Fluent; global using System.Reactive.Linq; +global using System.Runtime.Versioning; global using System.Text; global using System.Threading; global using System.Threading.Tasks; diff --git a/v2rayN/v2rayN.Desktop/Manager/HotkeyManager.cs b/v2rayN/v2rayN.Desktop/Manager/HotkeyManager.cs index f803c538ded..a79573d6f60 100644 --- a/v2rayN/v2rayN.Desktop/Manager/HotkeyManager.cs +++ b/v2rayN/v2rayN.Desktop/Manager/HotkeyManager.cs @@ -8,6 +8,7 @@ public sealed class HotkeyManager private static readonly Lazy _instance = new(() => new()); public static HotkeyManager Instance = _instance.Value; private readonly Dictionary _hotkeyTriggerDic = new(); + [SupportedOSPlatform("windows")] private GlobalHotKeys.HotKeyManager? _hotKeyManager; private Config? _config; @@ -16,6 +17,7 @@ public sealed class HotkeyManager public bool IsPause { get; set; } = false; + [SupportedOSPlatform("windows")] public void Init(Config config, Action updateFunc) { _config = config; @@ -26,9 +28,14 @@ public void Init(Config config, Action updateFunc) public void Dispose() { + if (!Utils.IsWindows()) + { + return; + } _hotKeyManager?.Dispose(); } + [SupportedOSPlatform("windows")] private void Register() { if (_config.GlobalHotkeys.Any(t => t.KeyCode > 0) == false) diff --git a/v2rayN/v2rayN.Desktop/Views/MessageBoxDialog.axaml.cs b/v2rayN/v2rayN.Desktop/Views/MessageBoxDialog.axaml.cs index 12750144fd5..768a8e1d1e2 100644 --- a/v2rayN/v2rayN.Desktop/Views/MessageBoxDialog.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/MessageBoxDialog.axaml.cs @@ -4,6 +4,11 @@ namespace v2rayN.Desktop.Views; public partial class MessageBoxDialog : Window { + public MessageBoxDialog() + : this(string.Empty, string.Empty) + { + } + public MessageBoxDialog(string caption, string message) { InitializeComponent(); diff --git a/v2rayN/v2rayN/app.manifest b/v2rayN/v2rayN/app.manifest index 1246cc30b1d..519db8c6e50 100644 --- a/v2rayN/v2rayN/app.manifest +++ b/v2rayN/v2rayN/app.manifest @@ -1,12 +1,5 @@  - - - true - PerMonitorV2 - - - diff --git a/v2rayN/v2rayN/v2rayN.csproj b/v2rayN/v2rayN/v2rayN.csproj index 871d294057f..9fd0d7886e3 100644 --- a/v2rayN/v2rayN/v2rayN.csproj +++ b/v2rayN/v2rayN/v2rayN.csproj @@ -7,6 +7,7 @@ true Resources\v2rayN.ico app.manifest + PerMonitorV2 7.0 true From 6c06c8a00afe622468b4e438535f0496b0a1da93 Mon Sep 17 00:00:00 2001 From: JieXu Date: Thu, 14 May 2026 19:27:31 +0800 Subject: [PATCH 11/61] Update (#9303) * Update DOTNET_RISCV_VERSION to 10.0.108 * Update DOTNET_RISCV_VERSION to 10.0.108 --- package-debian-riscv.sh | 2 +- package-rhel-riscv.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-debian-riscv.sh b/package-debian-riscv.sh index 81cda60761c..bcdde11f45a 100644 --- a/package-debian-riscv.sh +++ b/package-debian-riscv.sh @@ -13,7 +13,7 @@ PKGROOT="v2rayN-publish" PROJECT_HINT="v2rayN.Desktop/v2rayN.Desktop.csproj" OUTPUT_DIR="${HOME}/debbuild" DOTNET_TFM="net10.0" -DOTNET_RISCV_VERSION="10.0.107" +DOTNET_RISCV_VERSION="10.0.108" DOTNET_RISCV_BASE="https://github.com/xujiegb/dotnet-riscv/releases/download" DOTNET_RISCV_FILE="dotnet-sdk-${DOTNET_RISCV_VERSION}-linux-riscv64.tar.gz" DOTNET_SDK_URL="${DOTNET_RISCV_BASE}/${DOTNET_RISCV_VERSION}/${DOTNET_RISCV_FILE}" diff --git a/package-rhel-riscv.sh b/package-rhel-riscv.sh index d716c51be04..d1137f763b2 100644 --- a/package-rhel-riscv.sh +++ b/package-rhel-riscv.sh @@ -13,7 +13,7 @@ PKGROOT="v2rayN-publish" PROJECT_HINT="v2rayN.Desktop/v2rayN.Desktop.csproj" RPM_TOPDIR="${HOME}/rpmbuild" DOTNET_TFM="net10.0" -DOTNET_RISCV_VERSION="10.0.107" +DOTNET_RISCV_VERSION="10.0.108" DOTNET_RISCV_BASE="https://github.com/xujiegb/dotnet-riscv/releases/download" DOTNET_RISCV_FILE="dotnet-sdk-${DOTNET_RISCV_VERSION}-linux-riscv64.tar.gz" DOTNET_SDK_URL="${DOTNET_RISCV_BASE}/${DOTNET_RISCV_VERSION}/${DOTNET_RISCV_FILE}" @@ -766,4 +766,4 @@ main() { print_summary } -main "$@" \ No newline at end of file +main "$@" From e68842bb78342ed60e883d9d74987cdf6a930fd0 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Thu, 14 May 2026 20:34:42 +0800 Subject: [PATCH 12/61] Add SkiaSharp Linux native assets package Add SkiaSharp.NativeAssets.Linux (v3.119.1) to Directory.Packages.props and add a PackageReference in v2rayN.Desktop.csproj so the Linux native SkiaSharp binaries are included for the desktop build/runtime. --- v2rayN/Directory.Packages.props | 75 +++++++++++---------- v2rayN/v2rayN.Desktop/v2rayN.Desktop.csproj | 1 + 2 files changed, 39 insertions(+), 37 deletions(-) diff --git a/v2rayN/Directory.Packages.props b/v2rayN/Directory.Packages.props index 521afe14e30..ed4c19899b9 100644 --- a/v2rayN/Directory.Packages.props +++ b/v2rayN/Directory.Packages.props @@ -1,38 +1,39 @@ - - true - true - false - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + + true + true + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/v2rayN/v2rayN.Desktop/v2rayN.Desktop.csproj b/v2rayN/v2rayN.Desktop/v2rayN.Desktop.csproj index fc60c249736..abd93e1dc3b 100644 --- a/v2rayN/v2rayN.Desktop/v2rayN.Desktop.csproj +++ b/v2rayN/v2rayN.Desktop/v2rayN.Desktop.csproj @@ -29,6 +29,7 @@ true + From b193c39ad7bf18cdf2f6169e95d77ba345f6eda7 Mon Sep 17 00:00:00 2001 From: JieXu Date: Fri, 15 May 2026 15:09:04 +0800 Subject: [PATCH 13/61] Remove patch for riscv (#9310) * Delete .github/workflows/update-riscv-depand.yml * Update package-rhel-riscv.sh * Update package-debian-riscv.sh * Create package-debian-loong.sh * Update build-linux.yml * Update build-linux.yml * Update package-debian-loong.sh * Update build-linux.yml * Update Directory.Packages.props --- .github/workflows/build-linux.yml | 175 +++++ .github/workflows/update-riscv-depand.yml | 256 -------- package-debian-loong.sh | 742 ++++++++++++++++++++++ package-debian-riscv.sh | 86 +-- package-rhel-riscv.sh | 84 +-- v2rayN/Directory.Packages.props | 2 +- 6 files changed, 929 insertions(+), 416 deletions(-) delete mode 100644 .github/workflows/update-riscv-depand.yml create mode 100644 package-debian-loong.sh diff --git a/.github/workflows/build-linux.yml b/.github/workflows/build-linux.yml index cccdafa8c90..a3cbb55c9bc 100644 --- a/.github/workflows/build-linux.yml +++ b/.github/workflows/build-linux.yml @@ -325,3 +325,178 @@ jobs: --data-binary @"$f" \ "${upload_url}?name=${f##*/}" done + + deb-loong64: + name: build and release deb loong64 + if: | + (github.event_name == 'workflow_dispatch' && inputs.release_tag != '') || + (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')) + runs-on: ubuntu-24.04 + + env: + RELEASE_TAG: ${{ case(inputs.release_tag != '', inputs.release_tag, github.ref_name) }} + QCOW2_URL: https://github.com/xujiegb/debian-loong64-qcow2/releases/download/13.4/debian13-loong64.qcow2 + EFI_CODE_URL: https://github.com/xujiegb/debian-loong64-qcow2/releases/download/13.4/edk2-loongarch64-code.fd + EFI_VARS_URL: https://github.com/xujiegb/debian-loong64-qcow2/releases/download/13.4/edk2-loongarch64-vars.fd + QCOW2_IMAGE: debian13-loong64.qcow2 + EFI_CODE: edk2-loongarch64-code.fd + EFI_VARS: edk2-loongarch64-vars.fd + QEMU_VERSION: 10.2.2 + + steps: + - name: Prepare host tools + shell: bash + run: | + set -euo pipefail + + sudo apt-get update + sudo apt-get install -y rsync qemu-utils expect wget curl ca-certificates libfdt1 libglib2.0-0 libpixman-1-0 libslirp0 + + - name: Checkout repo + uses: actions/checkout@v6 + with: + submodules: recursive + fetch-depth: 0 + + - name: Download QEMU prebuild + run: | + set -euo pipefail + + wget -O qemu-linux-x64.tar.gz \ + "https://github.com/xujiegb/qemu-linux-prebuild/releases/download/${QEMU_VERSION}/qemu-linux-x64.tar.gz" + + tar -xzf qemu-linux-x64.tar.gz + + mkdir -p "$HOME/qemu-install" + + rsync -a qemu-linux-x64/ "$HOME/qemu-install/" + + "$HOME/qemu-install/bin/qemu-system-loongarch64" --version + + - name: Download loong64 qcow2 and EFI firmware + shell: bash + run: | + set -euo pipefail + + wget -O "$QCOW2_IMAGE" "$QCOW2_URL" + wget -O "$EFI_CODE" "$EFI_CODE_URL" + wget -O "$EFI_VARS" "$EFI_VARS_URL" + + qemu-img info "$QCOW2_IMAGE" + + - name: Build loong64 DEB in VM through serial console + shell: bash + timeout-minutes: 180 + env: + RELEASE_TAG: ${{ env.RELEASE_TAG }} + run: | + set -euo pipefail + + mkdir -p "$GITHUB_WORKSPACE/dist/deb-loong64" + + expect <<'EOF' + log_user 1 + set timeout -1 + + set release_tag $env(RELEASE_TAG) + set qemu_bin "$env(HOME)/qemu-install/bin/qemu-system-loongarch64" + set qemu_rom_dir "$env(HOME)/qemu-install/share/qemu" + + set workspace $env(GITHUB_WORKSPACE) + set repo $env(GITHUB_REPOSITORY) + set sha $env(GITHUB_SHA) + + set qcow2 $env(QCOW2_IMAGE) + set efi_code $env(EFI_CODE) + set efi_vars $env(EFI_VARS) + + proc wait_prompt {} { + expect { + -re "__CI_PROMPT__# " {} + timeout { exit 1 } + eof { exit 1 } + } + } + + proc run_cmd {cmd} { + send -- "$cmd\r" + wait_prompt + } + + spawn $qemu_bin \ + -L $qemu_rom_dir \ + -machine virt \ + -accel tcg,thread=multi,tb-size=2048 \ + -cpu la464 \ + -m 9216 \ + -smp 4 \ + -drive if=pflash,format=raw,unit=0,file=$efi_code,readonly=on \ + -drive if=pflash,format=raw,unit=1,file=$efi_vars \ + -device virtio-blk-pci,drive=hd0,bootindex=1 \ + -drive if=none,media=disk,id=hd0,file=$qcow2,format=qcow2 \ + -netdev user,id=net0 \ + -device virtio-net-pci,netdev=net0 \ + -virtfs local,path=$workspace,mount_tag=workspace,security_model=none,id=workspace \ + -display none \ + -serial stdio \ + -monitor none + + expect -re "login:|debian login:" + send -- "root\r" + + expect -re "Password:|密码:|密码:" + send -- "password\r" + + expect { + -re "# " {} + timeout { exit 1 } + eof { exit 1 } + } + + send -- "export TERM=dumb; export PS1='__CI_PROMPT__# '\r" + wait_prompt + + run_cmd "mkdir -p /workspace" + run_cmd "mount -t 9p -o trans=virtio,version=9p2000.L workspace /workspace || mount -t 9p -o trans=virtio workspace /workspace" + run_cmd "IFACE=\$(ip -o link show | awk -F': ' '\$2 != \"lo\" {print \$2; exit}') ; ip link set \$IFACE up || true" + run_cmd "dhclient \$IFACE || true" + run_cmd "printf 'nameserver 10.0.2.3\nnameserver 1.1.1.1\n' >/etc/resolv.conf" + run_cmd "apt-get update || apt-get update || apt-get update" + run_cmd "DEBIAN_FRONTEND=noninteractive apt-get install -y sudo git rsync findutils tar gzip unzip which curl jq wget file ca-certificates desktop-file-utils xdg-utils fakeroot dpkg-dev gcc make libc6-dev libgcc-s1 libstdc++6 zlib1g libatomic1" + run_cmd "rm -rf /root/v2rayN-src" + run_cmd "git clone --recursive https://github.com/$repo.git /root/v2rayN-src" + run_cmd "cd /root/v2rayN-src && git fetch --depth=1 origin $sha && git checkout FETCH_HEAD && git submodule update --init --recursive" + run_cmd "cd /root/v2rayN-src && chmod 755 package-debian-loong.sh" + + send -- "cd /root/v2rayN-src; cat >/tmp/run-loong-build.sh <<'SCRIPT'\nset +e\nset -o pipefail\nbash -x ./package-debian-loong.sh \"\$RELEASE_TAG\" 2>&1 | tee /tmp/build.log\nrc=\$?\nmkdir -p /workspace/dist/deb-loong64\ncp -av /root/debbuild/*.deb /workspace/dist/deb-loong64/ 2>/dev/null || true\necho __BUILD_DONE__\$rc\nSCRIPT\nRELEASE_TAG=\"$release_tag\" bash /tmp/run-loong-build.sh\r" + + expect { + -re "__BUILD_DONE__0" { + send -- "poweroff\r" + } + default { + exit 1 + } + } + EOF + + - name: Collect DEBs + shell: bash + run: | + set -euo pipefail + + mkdir -p "$GITHUB_WORKSPACE/dist/deb-loong64" + + find "$GITHUB_WORKSPACE/dist/deb-loong64" -name "*.deb" \ + -exec mv {} "$GITHUB_WORKSPACE/dist/deb-loong64/v2rayN-linux-loong64.deb" \; || true + + echo "==== Dist tree ====" + ls -R "$GITHUB_WORKSPACE/dist/deb-loong64" + + - name: Upload DEBs to release + uses: svenstaro/upload-release-action@v2 + with: + file: dist/deb-loong64/**/*.deb + tag: ${{ env.RELEASE_TAG }} + file_glob: true + prerelease: true diff --git a/.github/workflows/update-riscv-depand.yml b/.github/workflows/update-riscv-depand.yml deleted file mode 100644 index 9cb57d5e716..00000000000 --- a/.github/workflows/update-riscv-depand.yml +++ /dev/null @@ -1,256 +0,0 @@ -name: update riscv dependent versions - -on: - workflow_dispatch: - push: - branches: - - master - -permissions: - contents: write - -concurrency: - group: update-riscv-dependent - cancel-in-progress: false - -jobs: - update: - runs-on: ubuntu-24.04 - - steps: - - uses: actions/checkout@v6 - - - uses: actions/setup-dotnet@v5 - with: - dotnet-version: 10.0.1xx - - - run: sudo apt-get update && sudo apt-get install -y jq - - - name: resolve - id: resolve - shell: bash - run: | - set -euo pipefail - - TARGET_FILES=( - package-rhel-riscv.sh - package-debian-riscv.sh - ) - - echo "==> restore projects" - find . -name '*.csproj' | while read -r p; do - if grep -q '.*-windows' "$p"; then - echo "[skip] $p" - else - echo "[restore] $p" - dotnet restore "$p" -p:EnableWindowsTargeting=true || true - fi - done - - echo "==> collect assets" - mapfile -t ASSETS < <(find . -path '*/obj/project.assets.json') - printf ' %s\n' "${ASSETS[@]}" - - ALL_LIBS=() - for f in "${ASSETS[@]}"; do - mapfile -t libs < <(jq -r '.libraries | keys[]' "$f") - ALL_LIBS+=("${libs[@]}") - done - mapfile -t LIBS < <(printf '%s\n' "${ALL_LIBS[@]}" | sort -u) - - extract() { - local name="$1" - for i in "${LIBS[@]}"; do - [[ "$i" == "$name/"* ]] && echo "${i#*/}" - done | sort -u - } - - norm_version() { echo "${1#v}"; } - is_preview() { [[ "$(norm_version "$1")" == *-* ]]; } - base_version() { local v; v="$(norm_version "$1")"; echo "${v%%-*}"; } - - key() { - local v core pre a b c p1 p2 p3 - v="$(norm_version "$1")" - core="${v%%-*}" - [[ "$v" == *-* ]] && pre="${v#*-}" || pre="" - - IFS='.' read -r a b c <<< "$core" - a=${a//[^0-9]/}; a=${a:-0} - b=${b//[^0-9]/}; b=${b:-0} - c=${c//[^0-9]/}; c=${c:-0} - - if [[ -z "$pre" ]]; then - printf "%05d.%05d.%05d.1\n" "$a" "$b" "$c" - else - pre="${pre#preview.}" - IFS='.' read -ra p <<< "$pre" - p1=${p[0]:-0}; p1=${p1//[^0-9]/}; p1=${p1:-0} - p2=${p[1]:-0}; p2=${p2//[^0-9]/}; p2=${p2:-0} - p3=${p[2]:-0}; p3=${p3//[^0-9]/}; p3=${p3:-0} - printf "%05d.%05d.%05d.0.%05d.%05d.%05d\n" \ - "$a" "$b" "$c" "$p1" "$p2" "$p3" - fi - } - - latest() { - local best="" best_key="" cur cur_key - for cur in "$@"; do - [[ -n "$cur" ]] || continue - cur_key="$(key "$cur")" - echo " candidate: $cur -> $cur_key" >&2 - if [[ -z "$best_key" || "$cur_key" > "$best_key" ]]; then - best="$cur" - best_key="$cur_key" - fi - done - echo "$best" - } - - log_mixed_versions() { - local name="$1"; shift - local versions=("$@") bases=() v b - mapfile -t bases < <( - for v in "${versions[@]}"; do - [[ -n "$v" ]] && base_version "$v" - done | sort -u - ) - - for b in "${bases[@]}"; do - local has_stable=0 has_preview=0 matched=() - for v in "${versions[@]}"; do - [[ -n "$v" ]] || continue - [[ "$(base_version "$v")" == "$b" ]] || continue - matched+=("$v") - if is_preview "$v"; then - has_preview=1 - else - has_stable=1 - fi - done - - if [[ "$has_stable" -eq 1 && "$has_preview" -eq 1 ]]; then - echo "[warn] $name: stable and preview both exist for base $b, prefer stable for this base" >&2 - printf ' %s\n' "${matched[@]}" >&2 - fi - done - } - - filter_mixed_versions() { - local versions=("$@") stable_bases=() v b - mapfile -t stable_bases < <( - for v in "${versions[@]}"; do - if [[ -n "$v" ]] && ! is_preview "$v"; then - base_version "$v" - fi - done | sort -u - ) - - for v in "${versions[@]}"; do - [[ -n "$v" ]] || continue - b="$(base_version "$v")" - if is_preview "$v" && printf '%s\n' "${stable_bases[@]}" | grep -qxF "$b"; then - continue - fi - echo "$v" - done - } - - read_var() { - sed -nE "s/^$2=\"\\\$\\{$2:-([^\"]+)\\}\".*/\\1/p" "$1" | head -n1 - } - - choose_final_version() { - local old="$1" new="$2" - [[ -n "$new" ]] || { echo "$old"; return; } - [[ -n "$old" ]] || { echo "$new"; return; } - if [[ "$(key "$old")" > "$(key "$new")" ]]; then - echo "$old" - else - echo "$new" - fi - } - - update_file() { - local file="$1" - local old_skia old_harf final_skia final_harf changed=0 - - old_skia="$(read_var "$file" SKIA_VER)" - old_harf="$(read_var "$file" HARFBUZZ_VER)" - final_skia="$(choose_final_version "$old_skia" "$NEW_SKIA")" - final_harf="$(choose_final_version "$old_harf" "$NEW_HARF")" - - echo "==> check $file" - echo " SKIA_VER: ${old_skia} -> ${NEW_SKIA} (apply: ${final_skia})" - echo " HARFBUZZ_VER: ${old_harf} -> ${NEW_HARF} (apply: ${final_harf})" - - if [[ "$old_skia" != "$final_skia" ]]; then - sed -i -E "s|^SKIA_VER=.*|SKIA_VER=\"\\\${SKIA_VER:-$final_skia}\"|" "$file" - changed=1 - fi - if [[ "$old_harf" != "$final_harf" ]]; then - sed -i -E "s|^HARFBUZZ_VER=.*|HARFBUZZ_VER=\"\\\${HARFBUZZ_VER:-$final_harf}\"|" "$file" - changed=1 - fi - - grep -qF "SKIA_VER=\"\${SKIA_VER:-$final_skia}\"" "$file" - grep -qF "HARFBUZZ_VER=\"\${HARFBUZZ_VER:-$final_harf}\"" "$file" - bash -n "$file" - - [[ "$changed" -eq 1 ]] - } - - mapfile -t SKIA < <(extract SkiaSharp) - mapfile -t HARF < <(extract HarfBuzzSharp) - - echo "==> SkiaSharp" - printf ' %s\n' "${SKIA[@]}" - echo "==> HarfBuzzSharp" - printf ' %s\n' "${HARF[@]}" - - log_mixed_versions "SkiaSharp" "${SKIA[@]}" - log_mixed_versions "HarfBuzzSharp" "${HARF[@]}" - - mapfile -t SKIA < <(filter_mixed_versions "${SKIA[@]}") - mapfile -t HARF < <(filter_mixed_versions "${HARF[@]}") - - NEW_SKIA="$(latest "${SKIA[@]}")" - NEW_HARF="$(latest "${HARF[@]}")" - - echo "==> selected" - echo " SKIA_VER=$NEW_SKIA" - echo " HARFBUZZ_VER=$NEW_HARF" - - any_changed=0 - changed_files=() - - for file in "${TARGET_FILES[@]}"; do - if update_file "$file"; then - any_changed=1 - changed_files+=("$file") - fi - done - - if [[ "$any_changed" -eq 0 ]]; then - echo "changed=0" >> "$GITHUB_OUTPUT" - exit 0 - fi - - { - echo "changed=1" - echo "changed_files<> "$GITHUB_OUTPUT" - - - name: commit - if: steps.resolve.outputs.changed == '1' - run: | - git config user.name github-actions - git config user.email github-actions@github.com - git add package-rhel-riscv.sh package-debian-riscv.sh - if git diff --cached --quiet; then - exit 0 - fi - git commit -m "chore: update riscv native dependency versions" - git push diff --git a/package-debian-loong.sh b/package-debian-loong.sh new file mode 100644 index 00000000000..e00b0cbf3a3 --- /dev/null +++ b/package-debian-loong.sh @@ -0,0 +1,742 @@ +#!/usr/bin/env bash +set -euo pipefail + +VERSION_ARG="" +WITH_CORE="both" +FORCE_NETCORE=0 +BUILD_FROM="" +XRAY_VER="${XRAY_VER:-}" +SING_VER="${SING_VER:-}" + +MIN_KERNEL="5.10" +PKGROOT="v2rayN-publish" +PROJECT_HINT="v2rayN.Desktop/v2rayN.Desktop.csproj" +OUTPUT_DIR="${HOME}/debbuild" +DOTNET_TFM="net10.0" +DOTNET_LOONGARCH_VERSION="10.0.108" +DOTNET_LOONGARCH_TAG="v10.0.108-loongarch64" +DOTNET_LOONGARCH_BASE="https://github.com/loongson/dotnet/releases/download" +DOTNET_LOONGARCH_FILE="dotnet-sdk-${DOTNET_LOONGARCH_VERSION}-linux-loongarch64.tar.gz" +DOTNET_SDK_URL="${DOTNET_LOONGARCH_BASE}/${DOTNET_LOONGARCH_TAG}/${DOTNET_LOONGARCH_FILE}" + +OS_ID="" +OS_NAME="" +OS_VERSION_ID="" +HOST_ARCH="" +SCRIPT_DIR="" +PROJECT="" +VERSION="" + +declare -a BUILT_DEBS=() + +die() { + echo "$*" >&2 + exit 1 +} + +parse_args() { + local first_arg="${1:-}" + + if [[ -n "$first_arg" && "$first_arg" != --* ]]; then + VERSION_ARG="$first_arg" + shift || true + fi + + while [[ $# -gt 0 ]]; do + case "$1" in + --with-core) WITH_CORE="${2:-both}"; shift 2 ;; + --xray-ver) XRAY_VER="${2:-}"; shift 2 ;; + --singbox-ver) SING_VER="${2:-}"; shift 2 ;; + --netcore) FORCE_NETCORE=1; shift ;; + --buildfrom) BUILD_FROM="${2:-}"; shift 2 ;; + *) + [[ -n "${VERSION_ARG:-}" ]] || VERSION_ARG="$1" + shift + ;; + esac + done + + if [[ -n "${VERSION_ARG:-}" && -n "${BUILD_FROM:-}" ]]; then + die "You cannot specify both an explicit version and --buildfrom at the same time. + Provide either a version (e.g. 7.14.0) OR --buildfrom 1|2|3." + fi +} + +detect_environment() { + local current_kernel="" + local lowest="" + + . /etc/os-release + + OS_ID="${ID:-}" + OS_NAME="${NAME:-$OS_ID}" + OS_VERSION_ID="${VERSION_ID:-}" + HOST_ARCH="$(uname -m)" + + case "$OS_ID" in + debian) + echo "Detected supported system: ${OS_NAME:-$OS_ID} ${OS_VERSION_ID:-}" + ;; + *) + die "Unsupported system: ${OS_NAME:-unknown} (${OS_ID:-unknown}). +This script only supports: Debian." + ;; + esac + + case "$HOST_ARCH" in + loongarch64) ;; + *) die "Only supports loongarch64" ;; + esac + + current_kernel="$(uname -r)" + lowest="$(printf '%s\n%s\n' "$MIN_KERNEL" "$current_kernel" | sort -V | head -n1)" + + [[ "$lowest" == "$MIN_KERNEL" ]] || die "Kernel $current_kernel is below $MIN_KERNEL" + echo "[OK] Kernel $current_kernel verified." +} + +install_dependencies() { + local install_ok=0 + local tmp_dotnet="" + + mkdir -p "$OUTPUT_DIR" + + if command -v apt-get >/dev/null 2>&1; then + sudo apt-get update + sudo apt-get -y install \ + curl unzip tar jq rsync ca-certificates git dpkg-dev fakeroot file \ + desktop-file-utils xdg-utils wget gcc make pkg-config \ + libicu-dev libssl-dev libfontconfig1 libfreetype6 zlib1g + + mkdir -p "$HOME/.dotnet" + tmp_dotnet="$(mktemp -d)" + curl -fL "$DOTNET_SDK_URL" -o "$tmp_dotnet/$DOTNET_LOONGARCH_FILE" + tar -C "$HOME/.dotnet" -xzf "$tmp_dotnet/$DOTNET_LOONGARCH_FILE" + rm -rf "$tmp_dotnet" + + export PATH="$HOME/.dotnet:$PATH" + export DOTNET_ROOT="$HOME/.dotnet" + + mkdir -p "$HOME/.nuget/NuGet" + + cat > "$HOME/.nuget/NuGet/NuGet.Config" < + + + + + + + +EOF + + dotnet --info >/dev/null 2>&1 && install_ok=1 + fi + + if [[ "$install_ok" -ne 1 ]]; then + echo "Could not auto-install dependencies for '$OS_ID'. Make sure these are available:" + echo "dotnet-loongarch SDK, curl, unzip, tar, rsync, git, gcc, make, dpkg-deb, fakeroot, libicu-dev, libssl-dev" + exit 1 + fi +} + +prepare_workspace() { + SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" + cd "$SCRIPT_DIR" + + if [[ -f .gitmodules ]]; then + git submodule sync --recursive || true + git submodule update --init --recursive || true + fi + + PROJECT="$PROJECT_HINT" + [[ -f "$PROJECT" ]] || PROJECT="$(find . -maxdepth 3 -name 'v2rayN.Desktop.csproj' | head -n1 || true)" + [[ -f "$PROJECT" ]] || die "v2rayN.Desktop.csproj not found" +} + +choose_channel() { + local ch="latest" + local sel="" + + if [[ -n "${BUILD_FROM:-}" ]]; then + case "$BUILD_FROM" in + 1) echo "latest"; return 0 ;; + 2) echo "prerelease"; return 0 ;; + 3) echo "keep"; return 0 ;; + *) die "[ERROR] Invalid --buildfrom value: ${BUILD_FROM}. Use 1|2|3." ;; + esac + fi + + if [[ -t 0 ]]; then + echo "[?] Choose v2rayN release channel:" >&2 + echo " 1) Latest (stable) [default]" >&2 + echo " 2) Pre-release (preview)" >&2 + echo " 3) Keep current (do nothing)" >&2 + printf "Enter 1, 2 or 3 [default 1]: " >&2 + + if read -r sel /dev/null 2>&1; then + git fetch --tags --force --prune --depth=1 || true + git rev-parse "refs/tags/${want}" >/dev/null 2>&1 && ref="$want" + + if [[ -n "$ref" ]]; then + echo "[OK] Found ref '${ref}', checking out..." + git checkout -f "$ref" + sync_submodules + return 0 + fi + fi + + return 1 +} + +apply_channel_or_keep() { + local ch="$1" + local tag="" + + if [[ "$ch" == "keep" ]]; then + echo "[*] Keep current repository state (no checkout)." + VERSION="$(git describe --tags --abbrev=0 2>/dev/null || echo '0.0.0+git')" + VERSION="${VERSION#v}" + return 0 + fi + + echo "[*] Resolving ${ch} tag from GitHub releases..." + + case "$ch" in + latest) tag="$(get_latest_tag_latest || true)" ;; + prerelease) tag="$(get_latest_tag_prerelease || true)" ;; + *) die "Failed to resolve latest tag for channel '${ch}'." ;; + esac + + [[ -n "$tag" ]] || die "Failed to resolve latest tag for channel '${ch}'." + + echo "[*] Latest tag for '${ch}': ${tag}" + git_try_checkout "$tag" || die "Failed to checkout '${tag}'." + VERSION="${tag#v}" +} + +resolve_version() { + if git rev-parse --git-dir >/dev/null 2>&1; then + if [[ -n "${VERSION_ARG:-}" ]]; then + local clean_ver="${VERSION_ARG#v}" + + if git_try_checkout "$clean_ver"; then + VERSION="$clean_ver" + else + echo "[WARN] Tag '${VERSION_ARG}' not found." + apply_channel_or_keep "$(choose_channel)" + fi + else + apply_channel_or_keep "$(choose_channel)" + fi + else + echo "Current directory is not a git repo; proceeding on current tree." + VERSION="${VERSION_ARG:-0.0.0}" + fi + + VERSION="${VERSION#v}" + echo "[*] GUI version resolved as: ${VERSION}" +} + +xray_url_for_rid() { + local rid="$1" + local ver="$2" + + case "$rid" in + linux-loongarch64) echo "https://github.com/XTLS/Xray-core/releases/download/v${ver}/Xray-linux-loong64.zip" ;; + *) return 1 ;; + esac +} + +singbox_url_for_rid() { + local rid="$1" + local ver="$2" + + case "$rid" in + linux-loongarch64) echo "https://github.com/SagerNet/sing-box/releases/download/v${ver}/sing-box-${ver}-linux-loong64.tar.gz" ;; + *) return 1 ;; + esac +} + +bundle_url_for_rid() { + local rid="$1" + + case "$rid" in + linux-loongarch64) echo "https://raw.githubusercontent.com/2dust/v2rayN-core-bin/refs/heads/master/v2rayN-linux-loong64.zip" ;; + *) return 1 ;; + esac +} + +download_xray() { + local outdir="$1" + local rid="$2" + local ver="${XRAY_VER:-}" + local url="" + local tmp="" + + mkdir -p "$outdir" + + if [[ -z "$ver" ]]; then + ver="$(curl -fsSL https://api.github.com/repos/XTLS/Xray-core/releases/latest \ + | grep -Eo '"tag_name":\s*"v[^"]+"' \ + | sed -E 's/.*"v([^"]+)".*/\1/' \ + | head -n1)" || true + fi + + [[ -n "$ver" ]] || { echo "[xray] Failed to get version"; return 1; } + url="$(xray_url_for_rid "$rid" "$ver")" || { echo "[xray] Unsupported RID: $rid"; return 1; } + + echo "[+] Download xray: $url" + + tmp="$(mktemp -d)" + curl -fL "$url" -o "$tmp/xray.zip" || { rm -rf "$tmp"; return 1; } + unzip -q "$tmp/xray.zip" -d "$tmp" || { rm -rf "$tmp"; return 1; } + install -m 755 "$tmp/xray" "$outdir/xray" || { rm -rf "$tmp"; return 1; } + rm -rf "$tmp" +} + +download_singbox() { + local outdir="$1" + local rid="$2" + local ver="${SING_VER:-}" + local url="" + local tmp="" + local bin="" + local cronet="" + + mkdir -p "$outdir" + + if [[ -z "$ver" ]]; then + ver="$(curl -fsSL https://api.github.com/repos/SagerNet/sing-box/releases/latest \ + | grep -Eo '"tag_name":\s*"v[^"]+"' \ + | sed -E 's/.*"v([^"]+)".*/\1/' \ + | head -n1)" || true + fi + + [[ -n "$ver" ]] || { echo "[sing-box] Failed to get version"; return 1; } + url="$(singbox_url_for_rid "$rid" "$ver")" || { echo "[sing-box] Unsupported RID: $rid"; return 1; } + + echo "[+] Download sing-box: $url" + + tmp="$(mktemp -d)" + curl -fL "$url" -o "$tmp/singbox.tar.gz" || { rm -rf "$tmp"; return 1; } + tar -C "$tmp" -xzf "$tmp/singbox.tar.gz" || { rm -rf "$tmp"; return 1; } + + bin="$(find "$tmp" -type f -name 'sing-box' | head -n1 || true)" + [[ -n "$bin" ]] || { echo "[!] sing-box unpack failed"; rm -rf "$tmp"; return 1; } + + install -m 755 "$bin" "$outdir/sing-box" || { rm -rf "$tmp"; return 1; } + + cronet="$(find "$tmp" -type f -name 'libcronet*.so*' | head -n1 || true)" + [[ -n "$cronet" ]] && install -m 644 "$cronet" "$outdir/libcronet.so" || true + + rm -rf "$tmp" +} + +unify_geo_layout() { + local outroot="$1" + local n + local names=( + geosite.dat + geoip.dat + geoip-only-cn-private.dat + Country.mmdb + geoip.metadb + ) + + mkdir -p "$outroot/bin" + + for n in "${names[@]}"; do + if [[ -f "$outroot/bin/xray/$n" ]]; then + mv -f "$outroot/bin/xray/$n" "$outroot/bin/$n" + fi + done +} + +download_geo_assets() { + local outroot="$1" + local bin_dir="$outroot/bin" + local srss_dir="$bin_dir/srss" + local f="" + + mkdir -p "$bin_dir" "$srss_dir" + + echo "[+] Download Xray Geo to ${bin_dir}" + curl -fsSL -o "$bin_dir/geosite.dat" "https://github.com/Loyalsoldier/V2ray-rules-dat/releases/latest/download/geosite.dat" + curl -fsSL -o "$bin_dir/geoip.dat" "https://github.com/Loyalsoldier/V2ray-rules-dat/releases/latest/download/geoip.dat" + curl -fsSL -o "$bin_dir/geoip-only-cn-private.dat" "https://raw.githubusercontent.com/Loyalsoldier/geoip/release/geoip-only-cn-private.dat" + curl -fsSL -o "$bin_dir/Country.mmdb" "https://raw.githubusercontent.com/Loyalsoldier/geoip/release/Country.mmdb" + + echo "[+] Download sing-box rule DB & rule-sets" + curl -fsSL -o "$bin_dir/geoip.metadb" "https://github.com/MetaCubeX/meta-rules-dat/releases/latest/download/geoip.metadb" + + for f in geoip-private.srs geoip-cn.srs geoip-facebook.srs geoip-fastly.srs geoip-google.srs geoip-netflix.srs geoip-telegram.srs geoip-twitter.srs; do + curl -fsSL -o "$srss_dir/$f" "https://raw.githubusercontent.com/2dust/sing-box-rules/refs/heads/rule-set-geoip/$f" + done + + for f in geosite-cn.srs geosite-gfw.srs geosite-google.srs geosite-greatfire.srs geosite-geolocation-cn.srs geosite-category-ads-all.srs geosite-private.srs; do + curl -fsSL -o "$srss_dir/$f" "https://raw.githubusercontent.com/2dust/sing-box-rules/refs/heads/rule-set-geosite/$f" + done + + unify_geo_layout "$outroot" +} + +populate_assets_zip_mode() { + local outroot="$1" + local rid="$2" + local url="" + local tmp="" + local nested_dir="" + + url="$(bundle_url_for_rid "$rid")" || { echo "[!] Bundle unsupported RID: $rid"; return 1; } + + echo "[+] Try v2rayN bundle archive: $url" + + tmp="$(mktemp -d)" + curl -fL "$url" -o "$tmp/v2rayn.zip" || { echo "[!] Bundle download failed"; rm -rf "$tmp"; return 1; } + unzip -q "$tmp/v2rayn.zip" -d "$tmp" || { echo "[!] Bundle unzip failed"; rm -rf "$tmp"; return 1; } + + if [[ -d "$tmp/bin" ]]; then + mkdir -p "$outroot/bin" + rsync -a "$tmp/bin/" "$outroot/bin/" + else + rsync -a "$tmp/" "$outroot/" + fi + + rm -f "$outroot/v2rayn.zip" 2>/dev/null || true + find "$outroot" -type d -name "mihomo" -prune -exec rm -rf {} + 2>/dev/null || true + + nested_dir="$(find "$outroot" -maxdepth 1 -type d -name 'v2rayN-linux-*' | head -n1 || true)" + if [[ -n "$nested_dir" && -d "$nested_dir/bin" ]]; then + mkdir -p "$outroot/bin" + rsync -a "$nested_dir/bin/" "$outroot/bin/" + rm -rf "$nested_dir" + fi + + unify_geo_layout "$outroot" + rm -rf "$tmp" + + echo "[+] Bundle extracted to $outroot" +} + +populate_assets_netcore_mode() { + local outroot="$1" + local rid="$2" + + mkdir -p "$outroot/bin/xray" "$outroot/bin/sing_box" + + if [[ "$WITH_CORE" == "xray" || "$WITH_CORE" == "both" ]]; then + download_xray "$outroot/bin/xray" "$rid" || echo "[!] xray download failed (skipped)" + fi + + if [[ "$WITH_CORE" == "sing-box" || "$WITH_CORE" == "both" ]]; then + download_singbox "$outroot/bin/sing_box" "$rid" || echo "[!] sing-box download failed (skipped)" + fi + + download_geo_assets "$outroot" || echo "[!] Geo rules download failed (skipped)" +} + +stage_runtime_assets() { + local outroot="$1" + local rid="$2" + + mkdir -p "$outroot/bin/xray" "$outroot/bin/sing_box" + + if [[ "$FORCE_NETCORE" -eq 0 ]]; then + if populate_assets_zip_mode "$outroot" "$rid"; then + echo "[*] Using v2rayN bundle archive." + else + echo "[*] Bundle failed, fallback to separate core + rules." + populate_assets_netcore_mode "$outroot" "$rid" + fi + else + echo "[*] --netcore specified: use separate core + rules." + populate_assets_netcore_mode "$outroot" "$rid" + fi +} + +describe_target() { + local short="$1" + + case "$short" in + loongarch64) printf '%s\n%s\n' "linux-loongarch64" "loong64" ;; + *) echo "Unknown arch '$short' (use loongarch64)" >&2; return 1 ;; + esac +} + +publish_binary() { + local rid="$1" + + dotnet clean "$PROJECT" -c Release + rm -rf "$(dirname "$PROJECT")/bin/Release/net10.0" || true + dotnet restore "$PROJECT" + dotnet publish "$PROJECT" -c Release -r "$rid" -p:PublishSingleFile=false -p:SelfContained=true +} + +write_launcher_file() { + local stage="$1" + + install -m 755 /dev/stdin "$stage/usr/bin/v2rayn" <<'EOF' +#!/usr/bin/env bash +set -euo pipefail +DIR="/opt/v2rayN" +cd "$DIR" + +if [[ -x "$DIR/v2rayN" ]]; then + exec "$DIR/v2rayN" "$@" +fi + +for dll in v2rayN.Desktop.dll v2rayN.dll; do + if [[ -f "$DIR/$dll" ]]; then + exec /usr/bin/dotnet "$DIR/$dll" "$@" + fi +done + +echo "v2rayN launcher: no executable found in $DIR" >&2 +ls -l "$DIR" >&2 || true +exit 1 +EOF +} + +write_desktop_file() { + local stage="$1" + + install -m 644 /dev/stdin "$stage/usr/share/applications/v2rayn.desktop" <<'EOF' +[Desktop Entry] +Type=Application +Name=v2rayN +Comment=v2rayN for Debian GNU Linux +Exec=v2rayn +Icon=v2rayn +Terminal=false +Categories=Network; +EOF +} + +write_maintainer_scripts() { + local debian_dir="$1" + + install -m 755 /dev/stdin "$debian_dir/postinst" <<'EOF' +#!/bin/sh +set -e +update-desktop-database /usr/share/applications >/dev/null 2>&1 || true +if command -v gtk-update-icon-cache >/dev/null 2>&1; then + gtk-update-icon-cache -f /usr/share/icons/hicolor >/dev/null 2>&1 || true +fi +exit 0 +EOF + + install -m 755 /dev/stdin "$debian_dir/postrm" <<'EOF' +#!/bin/sh +set -e +update-desktop-database /usr/share/applications >/dev/null 2>&1 || true +if command -v gtk-update-icon-cache >/dev/null 2>&1; then + gtk-update-icon-cache -f /usr/share/icons/hicolor >/dev/null 2>&1 || true +fi +exit 0 +EOF +} + +package_binary() { + local short="$1" + local rid="$2" + local deb_arch="$3" + local pubdir="" + local workdir="" + local stage="" + local debian_dir="" + local project_dir="" + local icon_candidate="" + local shlibs_depends="" + local extra_depends="" + local final_depends="" + local multiarch="" + local sys_libdir="" + local sys_usrlibdir="" + local deb_out="" + + pubdir="$(dirname "$PROJECT")/bin/Release/net10.0/${rid}/publish" + [[ -d "$pubdir" ]] || { echo "Publish directory not found: $pubdir"; return 1; } + + workdir="$(mktemp -d)" + trap '[[ -n "${workdir:-}" ]] && rm -rf "$workdir"' RETURN + + stage="$workdir/${PKGROOT}_${VERSION}_${deb_arch}" + debian_dir="$stage/DEBIAN" + + mkdir -p "$stage/opt/v2rayN" "$stage/usr/bin" "$stage/usr/share/applications" "$stage/usr/share/icons/hicolor/256x256/apps" "$debian_dir" + cp -a "$pubdir/." "$stage/opt/v2rayN/" + + project_dir="$(cd "$(dirname "$PROJECT")" && pwd)" + icon_candidate="$project_dir/v2rayN.png" + [[ -f "$icon_candidate" ]] && cp "$icon_candidate" "$stage/usr/share/icons/hicolor/256x256/apps/v2rayn.png" || true + + stage_runtime_assets "$stage/opt/v2rayN" "$rid" + write_launcher_file "$stage" + write_desktop_file "$stage" + write_maintainer_scripts "$debian_dir" + + extra_depends="libc6 (>= 2.34), fontconfig (>= 2.13.1), desktop-file-utils (>= 0.26), xdg-utils (>= 1.1.3), coreutils (>= 8.32), bash (>= 5.1), libfreetype6 (>= 2.11)" + + mkdir -p "$workdir/debian" + cat > "$workdir/debian/control" < +Standards-Version: 4.7.0 + +Package: v2rayn +Architecture: ${deb_arch} +Description: v2rayN +EOF + + multiarch="$(dpkg-architecture -a"$deb_arch" -qDEB_HOST_MULTIARCH)" + sys_libdir="/lib/$multiarch" + sys_usrlibdir="/usr/lib/$multiarch" + + : > "$debian_dir/substvars" + + mapfile -t ELF_FILES < <( + find "$stage/opt/v2rayN" -type f \( -name "*.so*" -o -perm -111 \) ! -name 'libcoreclrtraceptprovider.so' + ) + + if [[ "${#ELF_FILES[@]}" -gt 0 ]]; then + ( + cd "$workdir" + dpkg-shlibdeps \ + -l"$stage/opt/v2rayN" \ + -l"$sys_libdir" \ + -l"$sys_usrlibdir" \ + -T"$debian_dir/substvars" \ + "${ELF_FILES[@]}" + ) >/dev/null 2>&1 || true + fi + + shlibs_depends="$(sed -n 's/^shlibs:Depends=//p' "$debian_dir/substvars" | head -n1 || true)" + + if [[ -n "$shlibs_depends" ]]; then + shlibs_depends="$(echo "$shlibs_depends" \ + | sed -E 's/ *\([^)]*\)//g' \ + | sed -E 's/ *, */, /g' \ + | sed -E 's/^, *//; s/, *$//')" + final_depends="${shlibs_depends}, ${extra_depends}" + else + final_depends="${extra_depends}" + fi + + cat > "$debian_dir/control" < +Homepage: https://github.com/2dust/v2rayN +Section: net +Priority: optional +Depends: ${final_depends} +Description: v2rayN (Avalonia) GUI client for Linux + Support vless / vmess / Trojan / http / socks / Anytls / Hysteria2 / + Shadowsocks / tuic / WireGuard. +EOF + + find "$stage/opt/v2rayN" -type d -exec chmod 0755 {} + + find "$stage/opt/v2rayN" -type f -exec chmod 0644 {} + + [[ -f "$stage/opt/v2rayN/v2rayN" ]] && chmod 0755 "$stage/opt/v2rayN/v2rayN" || true + + deb_out="$OUTPUT_DIR/v2rayn_${VERSION}_${deb_arch}.deb" + dpkg-deb --root-owner-group --build "$stage" "$deb_out" + + echo "Build done for $short. DEB at:" + echo " $deb_out" + BUILT_DEBS+=("$deb_out") +} + +select_targets() { + printf '%s\n' loongarch64 +} + +build_one_target() { + local short="$1" + local meta=() + local rid="" + local deb_arch="" + + mapfile -t meta < <(describe_target "$short") || return 1 + rid="${meta[0]}" + deb_arch="${meta[1]}" + + echo "[*] Building for target: $short (RID=$rid, DEB arch=$deb_arch)" + publish_binary "$rid" + package_binary "$short" "$rid" "$deb_arch" +} + +print_summary() { + local pkg="" + + echo "" + echo "================ Build Summary =================" + if [[ "${#BUILT_DEBS[@]}" -gt 0 ]]; then + echo "Output directory: $OUTPUT_DIR" + for pkg in "${BUILT_DEBS[@]}"; do + echo "$pkg" + done + else + echo "No DEBs detected in summary (check build logs above)." + fi + echo "===============================================" +} + +main() { + local targets=() + local arch="" + + parse_args "$@" + detect_environment + install_dependencies + prepare_workspace + resolve_version + + mapfile -t targets < <(select_targets) + + for arch in "${targets[@]}"; do + build_one_target "$arch" + done + + print_summary +} + +main "$@" diff --git a/package-debian-riscv.sh b/package-debian-riscv.sh index bcdde11f45a..e9fcb628a6d 100644 --- a/package-debian-riscv.sh +++ b/package-debian-riscv.sh @@ -12,13 +12,10 @@ MIN_KERNEL="5.10" PKGROOT="v2rayN-publish" PROJECT_HINT="v2rayN.Desktop/v2rayN.Desktop.csproj" OUTPUT_DIR="${HOME}/debbuild" -DOTNET_TFM="net10.0" DOTNET_RISCV_VERSION="10.0.108" DOTNET_RISCV_BASE="https://github.com/xujiegb/dotnet-riscv/releases/download" DOTNET_RISCV_FILE="dotnet-sdk-${DOTNET_RISCV_VERSION}-linux-riscv64.tar.gz" DOTNET_SDK_URL="${DOTNET_RISCV_BASE}/${DOTNET_RISCV_VERSION}/${DOTNET_RISCV_FILE}" -SKIA_VER="${SKIA_VER:-3.119.2}" -HARFBUZZ_VER="${HARFBUZZ_VER:-8.3.1.3}" OS_ID="" OS_NAME="" @@ -27,7 +24,6 @@ HOST_ARCH="" SCRIPT_DIR="" PROJECT="" VERSION="" -BUILT_ALL=0 declare -a BUILT_DEBS=() @@ -261,70 +257,6 @@ resolve_version() { echo "[*] GUI version resolved as: ${VERSION}" } -apply_riscv_patch() { - local f="" - - find . -type f \( -name "*.csproj" -o -name "*.props" -o -name "*.targets" \) \ - -exec sed -Ei 's#[^<]+#'"$DOTNET_TFM"'#g' {} + - - while IFS= read -r -d '' f; do - sed -i \ - -e "s###g" \ - -e "s###g" \ - -e "s###g" \ - -e "s###g" \ - "$f" - - grep -q 'PackageVersion Include="SkiaSharp"' "$f" || \ - sed -i "/<\/ItemGroup>/i\ " "$f" - - grep -q 'PackageVersion Include="SkiaSharp.NativeAssets.Linux"' "$f" || \ - sed -i "/<\/ItemGroup>/i\ " "$f" - - grep -q 'PackageVersion Include="HarfBuzzSharp"' "$f" || \ - sed -i "/<\/ItemGroup>/i\ " "$f" - - grep -q 'PackageVersion Include="HarfBuzzSharp.NativeAssets.Linux"' "$f" || \ - sed -i "/<\/ItemGroup>/i\ " "$f" - done < <(find . -type f -name 'Directory.Packages.props' -print0) - - f="$(find "$DOTNET_ROOT/sdk/$(dotnet --version)" -type f -name 'Microsoft.NETCoreSdk.BundledVersions.props' | head -n1 || true)" - if [[ -f "$f" ]] && ! grep -q 'linux-riscv64' "$f"; then - sed -i \ - -e 's/linux-arm64/&;linux-riscv64/g' \ - -e 's/linux-musl-arm64/&;linux-musl-riscv64/g' \ - "$f" - fi -} - -copy_skiasharp_native_riscv64() { - local outdir="$1" - local skia_so="" - local harfbuzz_so="" - - mkdir -p "$outdir" - - skia_so="$(find "$HOME/.nuget/packages" -path "*/skiasharp.nativeassets.linux/${SKIA_VER}/runtimes/linux-riscv64/native/libSkiaSharp.so" | head -n1 || true)" - [[ -n "$skia_so" ]] || skia_so="$(find "$HOME/.nuget/packages" -path "*/runtimes/linux-riscv64/native/libSkiaSharp.so" | head -n1 || true)" - - harfbuzz_so="$(find "$HOME/.nuget/packages" -path "*/harfbuzzsharp.nativeassets.linux/${HARFBUZZ_VER}/runtimes/linux-riscv64/native/libHarfBuzzSharp.so" | head -n1 || true)" - [[ -n "$harfbuzz_so" ]] || harfbuzz_so="$(find "$HOME/.nuget/packages" -path "*/runtimes/linux-riscv64/native/libHarfBuzzSharp.so" | head -n1 || true)" - - if [[ -n "$skia_so" && -f "$skia_so" ]]; then - echo "[+] Copy libSkiaSharp.so from NuGet cache" - install -m 755 "$skia_so" "$outdir/libSkiaSharp.so" - else - echo "[WARN] libSkiaSharp.so for linux-riscv64 not found in NuGet cache" - fi - - if [[ -n "$harfbuzz_so" && -f "$harfbuzz_so" ]]; then - echo "[+] Copy libHarfBuzzSharp.so from NuGet cache" - install -m 755 "$harfbuzz_so" "$outdir/libHarfBuzzSharp.so" - else - echo "[WARN] libHarfBuzzSharp.so for linux-riscv64 not found in NuGet cache" - fi -} - xray_url_for_rid() { local rid="$1" local ver="$2" @@ -554,10 +486,10 @@ describe_target() { publish_binary() { local rid="$1" - dotnet clean "$PROJECT" -c Release -p:TargetFramework="$DOTNET_TFM" - rm -rf "$(dirname "$PROJECT")/bin/Release/${DOTNET_TFM}" || true - dotnet restore "$PROJECT" -r "$rid" -p:TargetFramework="$DOTNET_TFM" - dotnet publish "$PROJECT" -c Release -r "$rid" -p:TargetFramework="$DOTNET_TFM" -p:PublishSingleFile=false -p:SelfContained=true + dotnet clean "$PROJECT" -c Release + rm -rf "$(dirname "$PROJECT")/bin/Release/net10.0" || true + dotnet restore "$PROJECT" + dotnet publish "$PROJECT" -c Release -r "$rid" -p:PublishSingleFile=false -p:SelfContained=true } write_launcher_file() { @@ -567,7 +499,6 @@ write_launcher_file() { #!/usr/bin/env bash set -euo pipefail DIR="/opt/v2rayN" -export LD_LIBRARY_PATH="$DIR:${LD_LIBRARY_PATH:-}" cd "$DIR" if [[ -x "$DIR/v2rayN" ]]; then @@ -643,7 +574,7 @@ package_binary() { local sys_usrlibdir="" local deb_out="" - pubdir="$(dirname "$PROJECT")/bin/Release/${DOTNET_TFM}/${rid}/publish" + pubdir="$(dirname "$PROJECT")/bin/Release/net10.0/${rid}/publish" [[ -d "$pubdir" ]] || { echo "Publish directory not found: $pubdir"; return 1; } workdir="$(mktemp -d)" @@ -655,8 +586,6 @@ package_binary() { mkdir -p "$stage/opt/v2rayN" "$stage/usr/bin" "$stage/usr/share/applications" "$stage/usr/share/icons/hicolor/256x256/apps" "$debian_dir" cp -a "$pubdir/." "$stage/opt/v2rayN/" - copy_skiasharp_native_riscv64 "$stage/opt/v2rayN" || echo "[!] SkiaSharp native copy failed (skipped)" - project_dir="$(cd "$(dirname "$PROJECT")" && pwd)" icon_candidate="$project_dir/v2rayN.png" [[ -f "$icon_candidate" ]] && cp "$icon_candidate" "$stage/usr/share/icons/hicolor/256x256/apps/v2rayn.png" || true @@ -732,9 +661,7 @@ EOF find "$stage/opt/v2rayN" -type d -exec chmod 0755 {} + find "$stage/opt/v2rayN" -type f -exec chmod 0644 {} + [[ -f "$stage/opt/v2rayN/v2rayN" ]] && chmod 0755 "$stage/opt/v2rayN/v2rayN" || true - [[ -f "$stage/opt/v2rayN/libSkiaSharp.so" ]] && chmod 0755 "$stage/opt/v2rayN/libSkiaSharp.so" || true - [[ -f "$stage/opt/v2rayN/libHarfBuzzSharp.so" ]] && chmod 0755 "$stage/opt/v2rayN/libHarfBuzzSharp.so" || true - + deb_out="$OUTPUT_DIR/v2rayn_${VERSION}_${deb_arch}.deb" dpkg-deb --root-owner-group --build "$stage" "$deb_out" @@ -787,7 +714,6 @@ main() { install_dependencies prepare_workspace resolve_version - apply_riscv_patch mapfile -t targets < <(select_targets) diff --git a/package-rhel-riscv.sh b/package-rhel-riscv.sh index d1137f763b2..9c4fa03fb27 100644 --- a/package-rhel-riscv.sh +++ b/package-rhel-riscv.sh @@ -12,13 +12,10 @@ MIN_KERNEL="5.10" PKGROOT="v2rayN-publish" PROJECT_HINT="v2rayN.Desktop/v2rayN.Desktop.csproj" RPM_TOPDIR="${HOME}/rpmbuild" -DOTNET_TFM="net10.0" DOTNET_RISCV_VERSION="10.0.108" DOTNET_RISCV_BASE="https://github.com/xujiegb/dotnet-riscv/releases/download" DOTNET_RISCV_FILE="dotnet-sdk-${DOTNET_RISCV_VERSION}-linux-riscv64.tar.gz" DOTNET_SDK_URL="${DOTNET_RISCV_BASE}/${DOTNET_RISCV_VERSION}/${DOTNET_RISCV_FILE}" -SKIA_VER="${SKIA_VER:-3.119.2}" -HARFBUZZ_VER="${HARFBUZZ_VER:-8.3.1.3}" OS_ID="" OS_NAME="" @@ -27,7 +24,6 @@ HOST_ARCH="" SCRIPT_DIR="" PROJECT="" VERSION="" -BUILT_ALL=0 declare -a BUILT_RPMS=() @@ -258,70 +254,6 @@ resolve_version() { echo "[*] GUI version resolved as: ${VERSION}" } -apply_riscv_patch() { - local f="" - - find . -type f \( -name "*.csproj" -o -name "*.props" -o -name "*.targets" \) \ - -exec sed -Ei 's#[^<]+#'"$DOTNET_TFM"'#g' {} + - - while IFS= read -r -d '' f; do - sed -i \ - -e "s###g" \ - -e "s###g" \ - -e "s###g" \ - -e "s###g" \ - "$f" - - grep -q 'PackageVersion Include="SkiaSharp"' "$f" || \ - sed -i "/<\/ItemGroup>/i\ " "$f" - - grep -q 'PackageVersion Include="SkiaSharp.NativeAssets.Linux"' "$f" || \ - sed -i "/<\/ItemGroup>/i\ " "$f" - - grep -q 'PackageVersion Include="HarfBuzzSharp"' "$f" || \ - sed -i "/<\/ItemGroup>/i\ " "$f" - - grep -q 'PackageVersion Include="HarfBuzzSharp.NativeAssets.Linux"' "$f" || \ - sed -i "/<\/ItemGroup>/i\ " "$f" - done < <(find . -type f -name 'Directory.Packages.props' -print0) - - f="$(find "$DOTNET_ROOT/sdk/$(dotnet --version)" -type f -name 'Microsoft.NETCoreSdk.BundledVersions.props' | head -n1 || true)" - if [[ -f "$f" ]] && ! grep -q 'linux-riscv64' "$f"; then - sed -i \ - -e 's/linux-arm64/&;linux-riscv64/g' \ - -e 's/linux-musl-arm64/&;linux-musl-riscv64/g' \ - "$f" - fi -} - -copy_skiasharp_native_riscv64() { - local outdir="$1" - local skia_so="" - local harfbuzz_so="" - - mkdir -p "$outdir" - - skia_so="$(find "$HOME/.nuget/packages" -path "*/skiasharp.nativeassets.linux/${SKIA_VER}/runtimes/linux-riscv64/native/libSkiaSharp.so" | head -n1 || true)" - [[ -n "$skia_so" ]] || skia_so="$(find "$HOME/.nuget/packages" -path "*/runtimes/linux-riscv64/native/libSkiaSharp.so" | head -n1 || true)" - - harfbuzz_so="$(find "$HOME/.nuget/packages" -path "*/harfbuzzsharp.nativeassets.linux/${HARFBUZZ_VER}/runtimes/linux-riscv64/native/libHarfBuzzSharp.so" | head -n1 || true)" - [[ -n "$harfbuzz_so" ]] || harfbuzz_so="$(find "$HOME/.nuget/packages" -path "*/runtimes/linux-riscv64/native/libHarfBuzzSharp.so" | head -n1 || true)" - - if [[ -n "$skia_so" && -f "$skia_so" ]]; then - echo "[+] Copy libSkiaSharp.so from NuGet cache" - install -m 755 "$skia_so" "$outdir/libSkiaSharp.so" - else - echo "[WARN] libSkiaSharp.so for linux-riscv64 not found in NuGet cache" - fi - - if [[ -n "$harfbuzz_so" && -f "$harfbuzz_so" ]]; then - echo "[+] Copy libHarfBuzzSharp.so from NuGet cache" - install -m 755 "$harfbuzz_so" "$outdir/libHarfBuzzSharp.so" - else - echo "[WARN] libHarfBuzzSharp.so for linux-riscv64 not found in NuGet cache" - fi -} - xray_url_for_rid() { local rid="$1" local ver="$2" @@ -551,10 +483,10 @@ describe_target() { publish_binary() { local rid="$1" - dotnet clean "$PROJECT" -c Release -p:TargetFramework="$DOTNET_TFM" - rm -rf "$(dirname "$PROJECT")/bin/Release/${DOTNET_TFM}" || true - dotnet restore "$PROJECT" -r "$rid" -p:TargetFramework="$DOTNET_TFM" - dotnet publish "$PROJECT" -c Release -r "$rid" -p:TargetFramework="$DOTNET_TFM" -p:PublishSingleFile=false -p:SelfContained=true + dotnet clean "$PROJECT" -c Release + rm -rf "$(dirname "$PROJECT")/bin/Release/net10.0" || true + dotnet restore "$PROJECT" + dotnet publish "$PROJECT" -c Release -r "$rid" -p:PublishSingleFile=false -p:SelfContained=true } write_spec_file() { @@ -604,15 +536,12 @@ cp -a * %{buildroot}/opt/v2rayN/ find %{buildroot}/opt/v2rayN -type d -exec chmod 0755 {} + find %{buildroot}/opt/v2rayN -type f -exec chmod 0644 {} + [ -f %{buildroot}/opt/v2rayN/v2rayN ] && chmod 0755 %{buildroot}/opt/v2rayN/v2rayN || : -[ -f %{buildroot}/opt/v2rayN/libSkiaSharp.so ] && chmod 0755 %{buildroot}/opt/v2rayN/libSkiaSharp.so || : -[ -f %{buildroot}/opt/v2rayN/libHarfBuzzSharp.so ] && chmod 0755 %{buildroot}/opt/v2rayN/libHarfBuzzSharp.so || : install -dm0755 %{buildroot}%{_bindir} install -m0755 /dev/stdin %{buildroot}%{_bindir}/v2rayn << 'EOF' #!/usr/bin/bash set -euo pipefail DIR="/opt/v2rayN" -export LD_LIBRARY_PATH="$DIR:${LD_LIBRARY_PATH:-}" if [[ -x "$DIR/v2rayN" ]]; then exec "$DIR/v2rayN" "$@"; fi @@ -673,7 +602,7 @@ package_binary() { local icon_candidate="" local f="" - pubdir="$(dirname "$PROJECT")/bin/Release/${DOTNET_TFM}/${rid}/publish" + pubdir="$(dirname "$PROJECT")/bin/Release/net10.0/${rid}/publish" [[ -d "$pubdir" ]] || { echo "Publish directory not found: $pubdir"; return 1; } workdir="$(mktemp -d)" @@ -682,8 +611,6 @@ package_binary() { mkdir -p "$workdir/$PKGROOT" cp -a "$pubdir/." "$workdir/$PKGROOT/" - copy_skiasharp_native_riscv64 "$workdir/$PKGROOT" || echo "[!] SkiaSharp native copy failed (skipped)" - project_dir="$(cd "$(dirname "$PROJECT")" && pwd)" icon_candidate="$project_dir/v2rayN.png" [[ -f "$icon_candidate" ]] || { echo "Required icon not found: $icon_candidate"; return 1; } @@ -755,7 +682,6 @@ main() { install_dependencies prepare_workspace resolve_version - apply_riscv_patch mapfile -t targets < <(select_targets) diff --git a/v2rayN/Directory.Packages.props b/v2rayN/Directory.Packages.props index ed4c19899b9..a136d4d7e5f 100644 --- a/v2rayN/Directory.Packages.props +++ b/v2rayN/Directory.Packages.props @@ -34,6 +34,6 @@ - + From 5b47d8ba054e8faad7b195498563eff8b3d314fd Mon Sep 17 00:00:00 2001 From: Miheichev Aleksandr Sergeevich Date: Fri, 15 May 2026 07:09:17 +0000 Subject: [PATCH 14/61] i18n(ru): translate untranslated PreSharedKey label and Export menu (#9309) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two strings in ResUI.ru.resx were left with their English (or identifier) values and surfaced as untranslated text on a Russian UI culture. This commit translates both, keeping the existing translation style and the existing technical vocabulary established earlier in this file. Changes: 1. TbPreSharedKey: 'PreSharedKey' -> 'Общий ключ (PSK)' The label is the WireGuard pre-shared-key field. The sibling WireGuard fields are already translated in the same file (TbPublicKey -> 'Открытый ключ', TbPrivateKey -> 'Приватный ключ'), so leaving this one as the raw identifier was inconsistent. 'Общий ключ' matches the wording used in Russian-localized network UIs for this concept (NetworkManager, MikroTik, OpenVPN GUIs); the '(PSK)' suffix preserves the technical abbreviation so users familiar with the WireGuard documentation immediately recognize the field. 2. menuExport2InnerUri: 'Export v2rayN Internal Share Link to Clipboard' -> 'Экспорт внутренней ссылки v2rayN в буфер обмена' This context-menu item was added recently and the Russian resource kept the English string verbatim. The translation follows the convention of the sibling export-to-clipboard items (menuExport2ShareUrlBase64 uses 'Экспорт ... в буфер обмена'), and 'внутренней ссылки v2rayN' preserves the 'internal' qualifier because this share-link format is specific to v2rayN's own importer and not interchangeable with the standard VMess/VLESS/Trojan/etc. URI schemes. Verified: - Diff scope: only ResUI.ru.resx, only the two elements; the .resx XML schema headers and all other keys are untouched. - Full audit of ResUI.ru.resx vs ResUI.resx: every other key is present and translated; these were the only two strings still surfacing in English on a Russian UI culture. - 'dotnet build v2rayN/v2rayN.sln -c Release' passes with 0 errors and 0 warnings. --- v2rayN/ServiceLib/Resx/ResUI.ru.resx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/v2rayN/ServiceLib/Resx/ResUI.ru.resx b/v2rayN/ServiceLib/Resx/ResUI.ru.resx index 4d02c0a70c9..0eb0cb816aa 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.ru.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.ru.resx @@ -1726,9 +1726,9 @@ Для среды с несколькими сетевыми интерфейсами укажите имя интерфейса для привязки. Работает только в Windows и режиме TUN - PreSharedKey + Общий ключ (PSK) - Export v2rayN Internal Share Link to Clipboard + Экспорт внутренней ссылки v2rayN в буфер обмена \ No newline at end of file From 2291214b6fecdf5ac55f6f3aed6faab6b4bec427 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Sat, 16 May 2026 19:00:46 +0800 Subject: [PATCH 15/61] up 7.22.1 --- v2rayN/Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/v2rayN/Directory.Build.props b/v2rayN/Directory.Build.props index 01ab2f787a0..951c1ae4a12 100644 --- a/v2rayN/Directory.Build.props +++ b/v2rayN/Directory.Build.props @@ -1,7 +1,7 @@ - 7.22.0 + 7.22.1 From ac9d0a019344540036314cc9d16979fdea29490e Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Sun, 17 May 2026 17:09:34 +0800 Subject: [PATCH 16/61] Add periodic update checks and core support --- v2rayN/ServiceLib/Manager/CoreInfoManager.cs | 44 +++++++++++++++++++ v2rayN/ServiceLib/Manager/TaskManager.cs | 26 +++++++++++ v2rayN/ServiceLib/Resx/ResUI.Designer.cs | 9 ++++ v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx | 3 ++ v2rayN/ServiceLib/Resx/ResUI.fr.resx | 3 ++ v2rayN/ServiceLib/Resx/ResUI.hu.resx | 3 ++ v2rayN/ServiceLib/Resx/ResUI.resx | 3 ++ v2rayN/ServiceLib/Resx/ResUI.ru.resx | 3 ++ v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx | 3 ++ v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx | 3 ++ v2rayN/ServiceLib/Services/UpdateService.cs | 26 +++++++++++ .../ViewModels/CheckUpdateViewModel.cs | 12 ++--- 12 files changed, 129 insertions(+), 9 deletions(-) diff --git a/v2rayN/ServiceLib/Manager/CoreInfoManager.cs b/v2rayN/ServiceLib/Manager/CoreInfoManager.cs index e4b5c7f30b0..074342c7513 100644 --- a/v2rayN/ServiceLib/Manager/CoreInfoManager.cs +++ b/v2rayN/ServiceLib/Manager/CoreInfoManager.cs @@ -50,6 +50,50 @@ public string GetCoreExecFile(CoreInfo? coreInfo, out string msg) return fileName; } + public List GetCheckUpdateCoreTypes() + { + var lst = new List(); + + if (RuntimeInformation.ProcessArchitecture != Architecture.X86) + { + if (IsCheckUpdateSupported(ECoreType.v2rayN)) + { + lst.Add(ECoreType.v2rayN); + } + + if (!(Utils.IsWindows() && Environment.OSVersion.Version.Major < 10)) + { + lst.Add(ECoreType.Xray); + lst.Add(ECoreType.mihomo); + lst.Add(ECoreType.sing_box); + } + } + + return lst; + } + + public bool IsCheckUpdateSupported(ECoreType type) + { + return type switch + { + ECoreType.v2rayN => !Utils.IsPackagedInstall(), + ECoreType.Xray => true, + ECoreType.mihomo => true, + ECoreType.sing_box => true, + _ => false, + }; + } + + public bool GetCheckPreRelease(ECoreType type, bool preRelease) + { + return type switch + { + ECoreType.v2rayN => preRelease, + ECoreType.Xray => preRelease, + _ => false, + }; + } + private void InitCoreInfo() { var urlN = GetCoreUrl(ECoreType.v2rayN); diff --git a/v2rayN/ServiceLib/Manager/TaskManager.cs b/v2rayN/ServiceLib/Manager/TaskManager.cs index d1c7315785f..3fc64a2ea99 100644 --- a/v2rayN/ServiceLib/Manager/TaskManager.cs +++ b/v2rayN/ServiceLib/Manager/TaskManager.cs @@ -70,6 +70,18 @@ private async Task ScheduledTasks() } } + //Execute once 24 hour + if (numOfExecuted % 1440 == 1) + { + try + { + await UpdateTaskRunCheckUpdate(); + } + catch (Exception ex) + { + Logging.SaveLog("ScheduledTasks - UpdateTaskRunCheckUpdate", ex); + } + } numOfExecuted++; } } @@ -117,4 +129,18 @@ private async Task UpdateTaskRunGeo(int hours) }).UpdateGeoFileAll(); } } + + private async Task UpdateTaskRunCheckUpdate() + { + Logging.SaveLog("Execute check update"); + + var updateService = new UpdateService(_config, async (success, msg) => await Task.CompletedTask); + + var msgs = await updateService.CheckHasUpdateOnlyAll(_config.CheckUpdateItem.CheckPreReleaseUpdate); + foreach (var msg in msgs) + { + await _updateFunc?.Invoke(false, msg); + } + NoticeManager.Instance.Enqueue(string.Join("\n", msgs)); + } } diff --git a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs index cab76bb5ef5..a763358a3da 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs +++ b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs @@ -1887,6 +1887,15 @@ public static string menuWebsiteItem { } } + /// + /// 查找类似 {0} has a new version available: {1} 的本地化字符串。 + /// + public static string MsgCheckUpdateHasNewVersion { + get { + return ResourceManager.GetString("MsgCheckUpdateHasNewVersion", resourceCulture); + } + } + /// /// 查找类似 Core '{0}' does not support network type '{1}' 的本地化字符串。 /// diff --git a/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx b/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx index 9ac5aaa8bf8..6dd074e9bf7 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx @@ -1731,4 +1731,7 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if Export v2rayN Internal Share Link to Clipboard + + {0} has a new version available: {1} + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.fr.resx b/v2rayN/ServiceLib/Resx/ResUI.fr.resx index bca6c2b7c47..59cff7c8991 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.fr.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.fr.resx @@ -1728,4 +1728,7 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if Export v2rayN Internal Share Link to Clipboard + + {0} has a new version available: {1} + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.hu.resx b/v2rayN/ServiceLib/Resx/ResUI.hu.resx index ab481d0e675..0f25830a648 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.hu.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.hu.resx @@ -1731,4 +1731,7 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if Export v2rayN Internal Share Link to Clipboard + + {0} has a new version available: {1} + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.resx b/v2rayN/ServiceLib/Resx/ResUI.resx index b80c4e56097..92b9c83de50 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.resx @@ -1731,4 +1731,7 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if Export v2rayN Internal Share Link to Clipboard + + {0} has a new version available: {1} + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.ru.resx b/v2rayN/ServiceLib/Resx/ResUI.ru.resx index 0eb0cb816aa..daf33e10eb3 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.ru.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.ru.resx @@ -1731,4 +1731,7 @@ Экспорт внутренней ссылки v2rayN в буфер обмена + + {0} has a new version available: {1} + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx index 4b8e035191a..527d7b6ba2f 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx @@ -1728,4 +1728,7 @@ 导出 v2rayN 内部分享链接至剪贴板 (多选) + + {0} 有新版本可用:{1} + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx b/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx index 1a8d6675f1b..1aad3bfc6da 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx @@ -1728,4 +1728,7 @@ 匯出 v2rayN 內部分享連結至剪貼簿(多選) + + {0} 有新版本可用:{1} + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Services/UpdateService.cs b/v2rayN/ServiceLib/Services/UpdateService.cs index ee5efc145fd..ddc75652125 100644 --- a/v2rayN/ServiceLib/Services/UpdateService.cs +++ b/v2rayN/ServiceLib/Services/UpdateService.cs @@ -100,6 +100,32 @@ public async Task CheckUpdateCore(ECoreType type, bool preRelease) } } + public async Task CheckHasUpdateOnly(ECoreType type, bool preRelease) + { + if (!CoreInfoManager.Instance.IsCheckUpdateSupported(type)) + { + return new UpdateResult(false, "Not Support"); + } + + var downloadHandle = new DownloadService(); + var checkPreRelease = CoreInfoManager.Instance.GetCheckPreRelease(type, preRelease); + return await CheckUpdateAsync(downloadHandle, type, checkPreRelease); + } + + public async Task> CheckHasUpdateOnlyAll(bool preRelease) + { + var msgs = new List(); + foreach (var type in CoreInfoManager.Instance.GetCheckUpdateCoreTypes()) + { + var result = await CheckHasUpdateOnly(type, preRelease); + if (result.Success && result.Version != null) + { + msgs.Add(string.Format(ResUI.MsgCheckUpdateHasNewVersion, type, result.Version)); + } + } + return msgs; + } + public async Task UpdateGeoFileAll() { await UpdateGeoFiles(); diff --git a/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs b/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs index dc31b41ba29..f6f98e1af1b 100644 --- a/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs @@ -37,17 +37,11 @@ private void RefreshCheckUpdateItems() { CheckUpdateModels.Clear(); - if (RuntimeInformation.ProcessArchitecture != Architecture.X86) + foreach (var type in CoreInfoManager.Instance.GetCheckUpdateCoreTypes()) { - CheckUpdateModels.Add(GetCheckUpdateModel(_v2rayN)); - //Not Windows and under Win10 - if (!(Utils.IsWindows() && Environment.OSVersion.Version.Major < 10)) - { - CheckUpdateModels.Add(GetCheckUpdateModel(ECoreType.Xray.ToString())); - CheckUpdateModels.Add(GetCheckUpdateModel(ECoreType.mihomo.ToString())); - CheckUpdateModels.Add(GetCheckUpdateModel(ECoreType.sing_box.ToString())); - } + CheckUpdateModels.Add(GetCheckUpdateModel(type.ToString())); } + CheckUpdateModels.Add(GetCheckUpdateModel(_geo)); } From bc3cbb4277523904189d1ba7b2da7e1288e0c51d Mon Sep 17 00:00:00 2001 From: DHR60 Date: Sun, 17 May 2026 10:52:42 +0000 Subject: [PATCH 17/61] Fix (#9325) * Fix * Rename tun tag --- v2rayN/ServiceLib/Sample/tun_singbox_inbound | 2 +- .../CoreConfig/Singbox/SingboxRoutingService.cs | 12 +++++++++--- .../Services/CoreConfig/V2ray/V2rayRoutingService.cs | 1 + 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/v2rayN/ServiceLib/Sample/tun_singbox_inbound b/v2rayN/ServiceLib/Sample/tun_singbox_inbound index db5b0b32e0e..b23346c161e 100644 --- a/v2rayN/ServiceLib/Sample/tun_singbox_inbound +++ b/v2rayN/ServiceLib/Sample/tun_singbox_inbound @@ -1,6 +1,6 @@ { "type": "tun", - "tag": "tun-in", + "tag": "tun", "interface_name": "singbox_tun", "address": [ "172.18.0.1/30", diff --git a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRoutingService.cs b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRoutingService.cs index 2b6bdf2b647..b39312ebd0c 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRoutingService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRoutingService.cs @@ -87,8 +87,14 @@ private void GenRouting() }); _coreConfig.route.rules.Add(new() { - protocol = ["dns"], - action = "hijack-dns" + type = "logical", + mode = "or", + action = "hijack-dns", + rules = + [ + new() { port = [53] }, + new() { protocol = ["dns"] }, + ], }); } else @@ -96,7 +102,7 @@ private void GenRouting() _coreConfig.route.rules.Add(new() { port = [53], - action = "hijack-dns" + action = "hijack-dns", }); } diff --git a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayRoutingService.cs b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayRoutingService.cs index 4f7431fc71c..c3bcf61643c 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayRoutingService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayRoutingService.cs @@ -27,6 +27,7 @@ private void GenRouting() }); _coreConfig.routing.rules.Add(new() { + inboundTag = ["tun"], port = "53", outboundTag = Global.DnsOutboundTag, }); From e2428f250086b8ceb0ea246da46b0d57380b1344 Mon Sep 17 00:00:00 2001 From: DHR60 Date: Sun, 17 May 2026 10:54:12 +0000 Subject: [PATCH 18/61] Add tun inbound rule (#9327) --- v2rayN/ServiceLib/Global.cs | 1 + v2rayN/ServiceLib/Resx/ResUI.Designer.cs | 2 +- v2rayN/ServiceLib/Resx/ResUI.resx | 2 +- v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx | 2 +- .../Views/RoutingRuleDetailsWindow.axaml | 22 +++++++++++++------ 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/v2rayN/ServiceLib/Global.cs b/v2rayN/ServiceLib/Global.cs index ca167fa3141..0f28daa9eb7 100644 --- a/v2rayN/ServiceLib/Global.cs +++ b/v2rayN/ServiceLib/Global.cs @@ -505,6 +505,7 @@ public class Global public static readonly List InboundTags = [ + "tun", "socks", "socks2", "socks3" diff --git a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs index a763358a3da..98fba5a2c11 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs +++ b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs @@ -3493,7 +3493,7 @@ public static string TbRoundRobin { } /// - /// 查找类似 socks: local port, socks2: second local port, socks3: LAN port 的本地化字符串。 + /// 查找类似 tun: TUN inbound, socks: local port, socks2: second local port, socks3: LAN port 的本地化字符串。 /// public static string TbRoutingInboundTagTips { get { diff --git a/v2rayN/ServiceLib/Resx/ResUI.resx b/v2rayN/ServiceLib/Resx/ResUI.resx index 92b9c83de50..b989f719246 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.resx @@ -1336,7 +1336,7 @@ Enable second mixed port - socks: local port, socks2: second local port, socks3: LAN port + tun: TUN inbound, socks: local port, socks2: second local port, socks3: LAN port Theme diff --git a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx index 527d7b6ba2f..c3cf5da5fca 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx @@ -1333,7 +1333,7 @@ 开启第二个本地监听端口 - Socks:本地端口,Socks2:第二个本地端口,Socks3:局域网端口 + Tun:TUN 入站,Socks:本地端口,Socks2:第二个本地端口,Socks3:局域网端口 主题 diff --git a/v2rayN/v2rayN.Desktop/Views/RoutingRuleDetailsWindow.axaml b/v2rayN/v2rayN.Desktop/Views/RoutingRuleDetailsWindow.axaml index 30f74a14c66..fc2ead4567f 100644 --- a/v2rayN/v2rayN.Desktop/Views/RoutingRuleDetailsWindow.axaml +++ b/v2rayN/v2rayN.Desktop/Views/RoutingRuleDetailsWindow.axaml @@ -16,7 +16,7 @@ + Text="{x:Static resx:ResUI.TbRuleTypeTips}" + TextWrapping="Wrap" /> - + + Text="{x:Static resx:ResUI.TbRuleMatchingTips}" + TextWrapping="Wrap" /> + VerticalAlignment="Center" + TextWrapping="Wrap"> @@ -160,7 +166,8 @@ Margin="{StaticResource Margin4}" HorizontalAlignment="Left" VerticalAlignment="Center" - Text="{x:Static resx:ResUI.TbRoutingInboundTagTips}" /> + Text="{x:Static resx:ResUI.TbRoutingInboundTagTips}" + TextWrapping="Wrap" /> + Text="{x:Static resx:ResUI.TbRoutingTips}" + TextWrapping="Wrap" /> Date: Sun, 17 May 2026 19:15:57 +0800 Subject: [PATCH 19/61] Add 'Check Only' update action Introduce a new "Check Only" feature: add CheckOnlyCmd to CheckUpdateViewModel with CheckOnlyTask that queries updates (via UpdateService.CheckHasUpdateOnly) for selected cores and reports results without performing updates. Wire up a new btnCheckOnly in both Desktop and Avalonia views and bind the command. Add localized menuCheckOnly entries to multiple .resx files and update ResUI.Designer. Also shorten the pre-release label to "Check for pre-release" in resource files. --- v2rayN/ServiceLib/Resx/ResUI.Designer.cs | 11 +++- v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx | 3 ++ v2rayN/ServiceLib/Resx/ResUI.fr.resx | 3 ++ v2rayN/ServiceLib/Resx/ResUI.hu.resx | 3 ++ v2rayN/ServiceLib/Resx/ResUI.resx | 5 +- v2rayN/ServiceLib/Resx/ResUI.ru.resx | 3 ++ v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx | 5 +- v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx | 5 +- .../ViewModels/CheckUpdateViewModel.cs | 51 +++++++++++++++++++ .../Views/CheckUpdateView.axaml | 6 +++ .../Views/CheckUpdateView.axaml.cs | 1 + v2rayN/v2rayN/Views/CheckUpdateView.xaml | 7 +++ v2rayN/v2rayN/Views/CheckUpdateView.xaml.cs | 1 + 13 files changed, 100 insertions(+), 4 deletions(-) diff --git a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs index 98fba5a2c11..f9203dfdc74 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs +++ b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs @@ -870,6 +870,15 @@ public static string menuBackupAndRestore { } } + /// + /// 查找类似 Only Check 的本地化字符串。 + /// + public static string menuCheckOnly { + get { + return ResourceManager.GetString("menuCheckOnly", resourceCulture); + } + } + /// /// 查找类似 Check Update 的本地化字符串。 /// @@ -3934,7 +3943,7 @@ public static string TbSettingsEnableCacheFile4Sbox { } /// - /// 查找类似 Check for pre-release updates 的本地化字符串。 + /// 查找类似 Check for pre-release 的本地化字符串。 /// public static string TbSettingsEnableCheckPreReleaseUpdate { get { diff --git a/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx b/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx index 6dd074e9bf7..61fe7743b13 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx @@ -1734,4 +1734,7 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if {0} has a new version available: {1} + + Only Check + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.fr.resx b/v2rayN/ServiceLib/Resx/ResUI.fr.resx index 59cff7c8991..69c46098ec2 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.fr.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.fr.resx @@ -1731,4 +1731,7 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if {0} has a new version available: {1} + + Only Check + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.hu.resx b/v2rayN/ServiceLib/Resx/ResUI.hu.resx index 0f25830a648..0942419af3a 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.hu.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.hu.resx @@ -1734,4 +1734,7 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if {0} has a new version available: {1} + + Only Check + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.resx b/v2rayN/ServiceLib/Resx/ResUI.resx index b989f719246..b98f9625f8f 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.resx @@ -691,7 +691,7 @@ Automatically adjust column width after subscription update - Check for pre-release updates + Check for pre-release Exception @@ -1734,4 +1734,7 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if {0} has a new version available: {1} + + Only Check + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.ru.resx b/v2rayN/ServiceLib/Resx/ResUI.ru.resx index daf33e10eb3..30dd55d57a3 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.ru.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.ru.resx @@ -1734,4 +1734,7 @@ {0} has a new version available: {1} + + Only Check + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx index c3cf5da5fca..328ecd9965d 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx @@ -691,7 +691,7 @@ 自动调整配置列宽在更新订阅后 - 检查 Pre-Release 更新 (请谨慎启用) + 检查 Pre-Release 例外 @@ -1731,4 +1731,7 @@ {0} 有新版本可用:{1} + + 仅检查 + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx b/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx index 1aad3bfc6da..09e01d16ffd 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx @@ -691,7 +691,7 @@ 在更新訂閱後自動調整列寬 - 檢查 Pre-Release 更新 (請謹慎啟用) + 檢查 Pre-Release 例外 @@ -1731,4 +1731,7 @@ {0} 有新版本可用:{1} + + 僅檢查 + \ No newline at end of file diff --git a/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs b/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs index f6f98e1af1b..7aea70c9311 100644 --- a/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs @@ -9,6 +9,7 @@ public class CheckUpdateViewModel : MyReactiveObject public IObservableCollection CheckUpdateModels { get; } = new ObservableCollectionExtended(); public ReactiveCommand CheckUpdateCmd { get; } + public ReactiveCommand CheckOnlyCmd { get; } [Reactive] public bool EnableCheckPreReleaseUpdate { get; set; } public CheckUpdateViewModel(Func>? updateView) @@ -23,6 +24,13 @@ public CheckUpdateViewModel(Func>? updateView) _ = UpdateView(_v2rayN, ex.Message); }); + CheckOnlyCmd = ReactiveCommand.CreateFromTask(CheckOnly); + CheckOnlyCmd.ThrownExceptions.Subscribe(ex => + { + Logging.SaveLog(_tag, ex); + _ = UpdateView(_v2rayN, ex.Message); + }); + EnableCheckPreReleaseUpdate = _config.CheckUpdateItem.CheckPreReleaseUpdate; this.WhenAnyValue( @@ -71,11 +79,54 @@ private async Task SaveSelectedCoreTypes() await ConfigHandler.SaveConfig(_config); } + private async Task CheckOnly() + { + await Task.Run(CheckOnlyTask); + } + private async Task CheckUpdate() { await Task.Run(CheckUpdateTask); } + private async Task CheckOnlyTask() + { + await SaveSelectedCoreTypes(); + + for (var k = CheckUpdateModels.Count - 1; k >= 0; k--) + { + var item = CheckUpdateModels[k]; + if (item.IsSelected != true) + { + continue; + } + + await UpdateView(item.CoreType, "..."); + if (item.CoreType == _geo) + { + await UpdateView(item.CoreType, ResUI.menuCheckOnly + " (Not Support)"); + continue; + } + + if (!Enum.TryParse(item.CoreType, out var type)) + { + await UpdateView(item.CoreType, "Not Support"); + continue; + } + + var updateService = new UpdateService(_config, async (success, msg) => await Task.CompletedTask); + var result = await updateService.CheckHasUpdateOnly(type, EnableCheckPreReleaseUpdate); + if (result.Success && result.Version != null) + { + await UpdateView(item.CoreType, string.Format(ResUI.MsgCheckUpdateHasNewVersion, type, result.Version)); + } + else + { + await UpdateView(item.CoreType, result.Msg); + } + } + } + private async Task CheckUpdateTask() { _lstUpdated.Clear(); diff --git a/v2rayN/v2rayN.Desktop/Views/CheckUpdateView.axaml b/v2rayN/v2rayN.Desktop/Views/CheckUpdateView.axaml index 0055f9adc05..e7b1a2f701e 100644 --- a/v2rayN/v2rayN.Desktop/Views/CheckUpdateView.axaml +++ b/v2rayN/v2rayN.Desktop/Views/CheckUpdateView.axaml @@ -33,6 +33,12 @@ Margin="{StaticResource Margin4}" HorizontalAlignment="Left" /> +