diff --git a/v2rayN/Directory.Build.props b/v2rayN/Directory.Build.props index 7d8defbd..01ab2f78 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/ServiceLib/Common/Utils.cs b/v2rayN/ServiceLib/Common/Utils.cs index c0d8816d..2824bd83 100644 --- a/v2rayN/ServiceLib/Common/Utils.cs +++ b/v2rayN/ServiceLib/Common/Utils.cs @@ -1114,12 +1114,14 @@ public class Utils #region Platform + [SupportedOSPlatformGuard("windows")] public static bool IsWindows() => OperatingSystem.IsWindows(); public static bool IsLinux() => OperatingSystem.IsLinux(); public static bool IsMacOS() => OperatingSystem.IsMacOS(); + [UnsupportedOSPlatformGuard("windows")] public static bool IsNonWindows() => !OperatingSystem.IsWindows(); public static string GetExeName(string name) @@ -1214,6 +1216,16 @@ public class Utils } 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 6cd47f0a..5792dcec 100644 --- a/v2rayN/ServiceLib/Common/WindowsUtils.cs +++ b/v2rayN/ServiceLib/Common/WindowsUtils.cs @@ -2,6 +2,7 @@ using Microsoft.Win32; 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 9d311324..6e051d80 100644 --- a/v2rayN/ServiceLib/GlobalUsings.cs +++ b/v2rayN/ServiceLib/GlobalUsings.cs @@ -8,6 +8,7 @@ global using System.Reactive.Disposables; 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 bc86cd7f..e40af63f 100644 --- a/v2rayN/ServiceLib/Handler/AutoStartupHandler.cs +++ b/v2rayN/ServiceLib/Handler/AutoStartupHandler.cs @@ -41,6 +41,7 @@ public static class AutoStartupHandler #region Windows + [SupportedOSPlatform("windows")] private static async Task ClearTaskWindows() { var autoRunName = GetAutoRunNameWindows(); @@ -53,6 +54,7 @@ public static class AutoStartupHandler await Task.CompletedTask; } + [SupportedOSPlatform("windows")] private static async Task SetTaskWindows() { try @@ -82,6 +84,7 @@ public static class AutoStartupHandler /// /// /// + [SupportedOSPlatform("windows")] public static void AutoStartTaskService(string taskName, string fileName, string description) { if (taskName.IsNullOrEmpty()) diff --git a/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingWindows.cs b/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingWindows.cs index 8dc2f335..614437d7 100644 --- a/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingWindows.cs +++ b/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingWindows.cs @@ -2,6 +2,7 @@ using static ServiceLib.Handler.SysProxy.ProxySettingWindows.InternetConnectionO 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 21453591..c525da29 100644 --- a/v2rayN/ServiceLib/Handler/SysProxy/SysProxyHandler.cs +++ b/v2rayN/ServiceLib/Handler/SysProxy/SysProxyHandler.cs @@ -88,6 +88,7 @@ public static class SysProxyHandler } } + [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 c309680a..41d2343b 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 ffd4a36a..5bc8f276 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 90f60c7f..ba416e71 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 9c28c767..558852d2 100644 --- a/v2rayN/v2rayN.Desktop/GlobalUsings.cs +++ b/v2rayN/v2rayN.Desktop/GlobalUsings.cs @@ -5,6 +5,7 @@ global using System.IO; 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 f803c538..a79573d6 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 sealed class HotkeyManager 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 12750144..768a8e1d 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 1246cc30..519db8c6 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 871d2940..9fd0d788 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