From c4b490e46d5af511e8d97f0b1137968994e5addf Mon Sep 17 00:00:00 2001
From: DecorativeFamily <185765765+decorativefamily@users.noreply.github.com>
Date: Thu, 7 Nov 2024 10:16:27 +0330
Subject: [PATCH] [CodeFactor] Apply fixes (#6005)

Co-authored-by: codefactor-io <support@codefactor.io>
---
 v2rayN/ServiceLib/Common/HttpClientHelper.cs              | 4 ++--
 v2rayN/ServiceLib/Common/Utils.cs                         | 4 ++--
 v2rayN/ServiceLib/Handler/ConfigHandler.cs                | 4 ++--
 v2rayN/ServiceLib/Handler/SysProxy/ProxySettingWindows.cs | 8 ++++----
 v2rayN/ServiceLib/Models/V2rayConfig.cs                   | 4 ++--
 .../Services/CoreConfig/CoreConfigClashService.cs         | 4 ++--
 .../Services/CoreConfig/CoreConfigSingboxService.cs       | 4 ++--
 v2rayN/ServiceLib/Services/UpdateService.cs               | 4 ++--
 v2rayN/ServiceLib/ViewModels/DNSSettingViewModel.cs       | 4 ++--
 v2rayN/v2rayN.Desktop/Program.cs                          | 4 ++--
 v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs         | 2 +-
 v2rayN/v2rayN/App.xaml.cs                                 | 4 ++--
 12 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/v2rayN/ServiceLib/Common/HttpClientHelper.cs b/v2rayN/ServiceLib/Common/HttpClientHelper.cs
index cabc3f85..97df3af3 100644
--- a/v2rayN/ServiceLib/Common/HttpClientHelper.cs
+++ b/v2rayN/ServiceLib/Common/HttpClientHelper.cs
@@ -1,4 +1,4 @@
-using System.Net.Http.Headers;
+using System.Net.Http.Headers;
 using System.Net.Mime;
 using System.Text;
 
@@ -98,7 +98,7 @@ namespace ServiceLib.Common
                 totalRead += read;
 
                 if (read == 0) break;
-                await file.WriteAsync(buffer, 0, read, token);
+                await file.WriteAsync(buffer.AsMemory(0, read), token);
 
                 if (canReportProgress)
                 {
diff --git a/v2rayN/ServiceLib/Common/Utils.cs b/v2rayN/ServiceLib/Common/Utils.cs
index 54183cc0..c5bf085a 100644
--- a/v2rayN/ServiceLib/Common/Utils.cs
+++ b/v2rayN/ServiceLib/Common/Utils.cs
@@ -1,4 +1,4 @@
-using CliWrap;
+using CliWrap;
 using CliWrap.Buffered;
 using System.Collections.Specialized;
 using System.Diagnostics;
@@ -185,7 +185,7 @@ namespace ServiceLib.Common
 
                 if (plainText.Length % 4 > 0)
                 {
-                    plainText = plainText.PadRight(plainText.Length + 4 - plainText.Length % 4, '=');
+                    plainText = plainText.PadRight(plainText.Length + 4 - (plainText.Length % 4), '=');
                 }
 
                 var data = Convert.FromBase64String(plainText);
diff --git a/v2rayN/ServiceLib/Handler/ConfigHandler.cs b/v2rayN/ServiceLib/Handler/ConfigHandler.cs
index 87030e41..17271c57 100644
--- a/v2rayN/ServiceLib/Handler/ConfigHandler.cs
+++ b/v2rayN/ServiceLib/Handler/ConfigHandler.cs
@@ -1,4 +1,4 @@
-using System.Data;
+using System.Data;
 using System.Text.RegularExpressions;
 
 namespace ServiceLib.Handler
@@ -466,7 +466,7 @@ namespace ServiceLib.Handler
                         break;
                     }
                 case EMove.Position:
-                    sort = pos * 10 + 1;
+                    sort = (pos * 10) + 1;
                     break;
             }
 
diff --git a/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingWindows.cs b/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingWindows.cs
index 8ddd703f..2662f959 100644
--- a/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingWindows.cs
+++ b/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingWindows.cs
@@ -1,4 +1,4 @@
-using System.Runtime.InteropServices;
+using System.Runtime.InteropServices;
 using static ServiceLib.Handler.SysProxy.ProxySettingWindows.InternetConnectionOption;
 
 namespace ServiceLib.Handler.SysProxy
@@ -144,12 +144,12 @@ namespace ServiceLib.Handler.SysProxy
             {
                 if (Environment.Is64BitOperatingSystem)
                 {
-                    nint opt = new(optionsPtr.ToInt64() + i * optSize);
+                    nint opt = new(optionsPtr.ToInt64() + (i * optSize));
                     Marshal.StructureToPtr(options[i], opt, false);
                 }
                 else
                 {
-                    nint opt = new(optionsPtr.ToInt32() + i * optSize);
+                    nint opt = new(optionsPtr.ToInt32() + (i * optSize));
                     Marshal.StructureToPtr(options[i], opt, false);
                 }
             }
@@ -247,7 +247,7 @@ namespace ServiceLib.Handler.SysProxy
 
             //[MarshalAs(UnmanagedType.)]
             public nint options;
-        };
+        }
 
         [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
         public struct InternetConnectionOption
diff --git a/v2rayN/ServiceLib/Models/V2rayConfig.cs b/v2rayN/ServiceLib/Models/V2rayConfig.cs
index 4ea3c651..593e3710 100644
--- a/v2rayN/ServiceLib/Models/V2rayConfig.cs
+++ b/v2rayN/ServiceLib/Models/V2rayConfig.cs
@@ -1,4 +1,4 @@
-using System.Text.Json.Serialization;
+using System.Text.Json.Serialization;
 
 namespace ServiceLib.Models
 {
@@ -50,7 +50,7 @@ namespace ServiceLib.Models
     }
 
     public class Stats4Ray
-    { };
+    { }
 
     public class API4Ray
     {
diff --git a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigClashService.cs b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigClashService.cs
index 109f1cc1..bb9e81d4 100644
--- a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigClashService.cs
+++ b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigClashService.cs
@@ -1,4 +1,4 @@
-namespace ServiceLib.Services.CoreConfig
+namespace ServiceLib.Services.CoreConfig
 {
     /// <summary>
     /// Core configuration file processing class
@@ -66,7 +66,7 @@
                 txtFile = txtFile.Replace(tagYamlStr1, tagYamlStr2);
 
                 //YAML anchors
-                if (txtFile.Contains("<<:") && txtFile.Contains("*") && txtFile.Contains("&"))
+                if (txtFile.Contains("<<:") && txtFile.Contains('*') && txtFile.Contains('&'))
                 {
                     txtFile = YamlUtils.PreprocessYaml(txtFile);
                 }
diff --git a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs
index b710ca25..58f913e5 100644
--- a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs
+++ b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs
@@ -1,4 +1,4 @@
-using System.Data;
+using System.Data;
 using System.Net;
 using System.Net.NetworkInformation;
 
@@ -484,7 +484,7 @@ namespace ServiceLib.Services.CoreConfig
                 singboxConfig.inbounds = [];
 
                 if (!_config.TunModeItem.EnableTun
-                    || _config.TunModeItem.EnableTun && _config.TunModeItem.EnableExInbound && _config.RunningCoreType == ECoreType.sing_box)
+                    || (_config.TunModeItem.EnableTun && _config.TunModeItem.EnableExInbound && _config.RunningCoreType == ECoreType.sing_box))
                 {
                     var inbound = new Inbound4Sbox()
                     {
diff --git a/v2rayN/ServiceLib/Services/UpdateService.cs b/v2rayN/ServiceLib/Services/UpdateService.cs
index c0266614..4eafc5c4 100644
--- a/v2rayN/ServiceLib/Services/UpdateService.cs
+++ b/v2rayN/ServiceLib/Services/UpdateService.cs
@@ -1,4 +1,4 @@
-using System.Runtime.InteropServices;
+using System.Runtime.InteropServices;
 using System.Text.RegularExpressions;
 
 namespace ServiceLib.Services
@@ -122,7 +122,7 @@ namespace ServiceLib.Services
                 var url = item.Url.TrimEx();
                 var userAgent = item.UserAgent.TrimEx();
                 var hashCode = $"{item.Remarks}->";
-                if (Utils.IsNullOrEmpty(id) || Utils.IsNullOrEmpty(url) || Utils.IsNotEmpty(subId) && item.Id != subId)
+                if (Utils.IsNullOrEmpty(id) || Utils.IsNullOrEmpty(url) || (Utils.IsNotEmpty(subId) && item.Id != subId))
                 {
                     //_updateFunc?.Invoke(false, $"{hashCode}{ResUI.MsgNoValidSubscription}");
                     continue;
diff --git a/v2rayN/ServiceLib/ViewModels/DNSSettingViewModel.cs b/v2rayN/ServiceLib/ViewModels/DNSSettingViewModel.cs
index cef99002..703ee49b 100644
--- a/v2rayN/ServiceLib/ViewModels/DNSSettingViewModel.cs
+++ b/v2rayN/ServiceLib/ViewModels/DNSSettingViewModel.cs
@@ -1,4 +1,4 @@
-using ReactiveUI;
+using ReactiveUI;
 using ReactiveUI.Fody.Helpers;
 using System.Reactive;
 
@@ -105,7 +105,7 @@ namespace ServiceLib.ViewModels
             item2.DomainStrategy4Freedom = domainStrategy4Freedom2;
             item2.DomainDNSAddress = domainDNSAddress2;
             item2.NormalDNS = JsonUtils.Serialize(JsonUtils.ParseJson(normalDNS2));
-            item2.TunDNS = JsonUtils.Serialize(JsonUtils.ParseJson(tunDNS2)); ;
+            item2.TunDNS = JsonUtils.Serialize(JsonUtils.ParseJson(tunDNS2));
             await ConfigHandler.SaveDNSItems(_config, item2);
 
             NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
diff --git a/v2rayN/v2rayN.Desktop/Program.cs b/v2rayN/v2rayN.Desktop/Program.cs
index 8d863192..5d1c6493 100644
--- a/v2rayN/v2rayN.Desktop/Program.cs
+++ b/v2rayN/v2rayN.Desktop/Program.cs
@@ -1,4 +1,4 @@
-using Avalonia;
+using Avalonia;
 using Avalonia.ReactiveUI;
 using v2rayN.Desktop.Common;
 
@@ -25,7 +25,7 @@ internal class Program
         if (Utils.IsWindows())
         {
             var exePathKey = Utils.GetMd5(Utils.GetExePath());
-            var rebootas = (Args ?? new string[] { }).Any(t => t == Global.RebootAs);
+            var rebootas = (Args ?? Array.Empty<string>()).Any(t => t == Global.RebootAs);
             ProgramStarted = new EventWaitHandle(false, EventResetMode.AutoReset, exePathKey, out bool bCreatedNew);
             if (!rebootas && !bCreatedNew)
             {
diff --git a/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs b/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs
index 83a5e32a..1ac0cad3 100644
--- a/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs
+++ b/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs
@@ -345,7 +345,7 @@ namespace v2rayN.Desktop.Views
                         }
                         else
                         {
-                            item2.Width = new DataGridLength(item.Width, DataGridLengthUnitType.Pixel); ;
+                            item2.Width = new DataGridLength(item.Width, DataGridLengthUnitType.Pixel);
                             item2.DisplayIndex = displayIndex++;
                         }
                         if (item.Name.StartsWith("to"))
diff --git a/v2rayN/v2rayN/App.xaml.cs b/v2rayN/v2rayN/App.xaml.cs
index 89cd3467..5b7377d8 100644
--- a/v2rayN/v2rayN/App.xaml.cs
+++ b/v2rayN/v2rayN/App.xaml.cs
@@ -1,4 +1,4 @@
-using System.Diagnostics;
+using System.Diagnostics;
 using System.Windows;
 using System.Windows.Threading;
 
@@ -28,7 +28,7 @@ namespace v2rayN
         {
             var exePathKey = Utils.GetMd5(Utils.GetExePath());
 
-            var rebootas = (e.Args ?? new string[] { }).Any(t => t == Global.RebootAs);
+            var rebootas = (e.Args ?? Array.Empty<string>()).Any(t => t == Global.RebootAs);
             ProgramStarted = new EventWaitHandle(false, EventResetMode.AutoReset, exePathKey, out bool bCreatedNew);
             if (!rebootas && !bCreatedNew)
             {