diff --git a/v2rayN/ServiceLib/Common/DownloaderHelper.cs b/v2rayN/ServiceLib/Common/DownloaderHelper.cs index 570a95f5..03dcf8e3 100644 --- a/v2rayN/ServiceLib/Common/DownloaderHelper.cs +++ b/v2rayN/ServiceLib/Common/DownloaderHelper.cs @@ -86,7 +86,7 @@ namespace ServiceLib.Common //}; downloader.DownloadProgressChanged += (sender, value) => { - var ts = (DateTime.Now - totalDatetime); + var ts = DateTime.Now - totalDatetime; if (progress != null && ts.Seconds > totalSecond) { hasValue = true; @@ -146,10 +146,7 @@ namespace ServiceLib.Common var progressPercentage = 0; var hasValue = false; await using var downloader = new Downloader.DownloadService(downloadOpt); - downloader.DownloadStarted += (sender, value) => - { - progress?.Report(0); - }; + downloader.DownloadStarted += (sender, value) => progress?.Report(0); downloader.DownloadProgressChanged += (sender, value) => { hasValue = true; diff --git a/v2rayN/ServiceLib/Common/FileManager.cs b/v2rayN/ServiceLib/Common/FileManager.cs index c5e80794..2f452899 100644 --- a/v2rayN/ServiceLib/Common/FileManager.cs +++ b/v2rayN/ServiceLib/Common/FileManager.cs @@ -1,4 +1,4 @@ -using System.Formats.Tar; +using System.Formats.Tar; using System.IO.Compression; using System.Text; @@ -163,13 +163,15 @@ namespace ServiceLib.Common // Check if the source directory exists if (!dir.Exists) + { throw new DirectoryNotFoundException($"Source directory not found: {dir.FullName}"); + } // Cache directories before we start copying var dirs = dir.GetDirectories(); // Create the destination directory - Directory.CreateDirectory(destinationDir); + _ = Directory.CreateDirectory(destinationDir); // Get the files in the source directory and copy to the destination directory foreach (var file in dir.GetFiles()) @@ -187,7 +189,7 @@ namespace ServiceLib.Common { continue; } - file.CopyTo(targetFilePath, overwrite); + _ = file.CopyTo(targetFilePath, overwrite); } // If recursive and copying subdirectories, recursively call this method @@ -222,4 +224,4 @@ namespace ServiceLib.Common } } } -} \ No newline at end of file +} diff --git a/v2rayN/ServiceLib/Common/Logging.cs b/v2rayN/ServiceLib/Common/Logging.cs index 16c9228a..7f7089b7 100644 --- a/v2rayN/ServiceLib/Common/Logging.cs +++ b/v2rayN/ServiceLib/Common/Logging.cs @@ -28,7 +28,9 @@ namespace ServiceLib.Common public static void SaveLog(string strContent) { if (!LogManager.IsLoggingEnabled()) + { return; + } LogManager.GetLogger("Log1").Info(strContent); } @@ -36,7 +38,9 @@ namespace ServiceLib.Common public static void SaveLog(string strTitle, Exception ex) { if (!LogManager.IsLoggingEnabled()) + { return; + } var logger = LogManager.GetLogger("Log2"); logger.Debug($"{strTitle},{ex.Message}"); diff --git a/v2rayN/ServiceLib/Common/ProcUtils.cs b/v2rayN/ServiceLib/Common/ProcUtils.cs index 70b6f3c6..561278ce 100644 --- a/v2rayN/ServiceLib/Common/ProcUtils.cs +++ b/v2rayN/ServiceLib/Common/ProcUtils.cs @@ -8,7 +8,7 @@ public static class ProcUtils public static void ProcessStart(string? fileName, string arguments = "") { - ProcessStart(fileName, arguments, null); + _ = ProcessStart(fileName, arguments, null); } public static int? ProcessStart(string? fileName, string arguments, string? dir) @@ -38,7 +38,7 @@ public static class ProcUtils WorkingDirectory = dir ?? string.Empty } }; - proc.Start(); + _ = proc.Start(); return dir is null ? null : proc.Id; } catch (Exception ex) @@ -60,7 +60,7 @@ public static class ProcUtils FileName = Utils.GetExePath().AppendQuotes(), Verb = blAdmin ? "runas" : null, }; - Process.Start(startInfo); + _ = Process.Start(startInfo); } catch (Exception ex) { @@ -138,7 +138,9 @@ public static class ProcUtils fileName = null; processName = null; if (!review) + { return; + } try { procId = proc?.Id; diff --git a/v2rayN/ServiceLib/Common/SqliteHelper.cs b/v2rayN/ServiceLib/Common/SqliteHelper.cs index 10a7793b..dca10c57 100644 --- a/v2rayN/ServiceLib/Common/SqliteHelper.cs +++ b/v2rayN/ServiceLib/Common/SqliteHelper.cs @@ -7,7 +7,7 @@ namespace ServiceLib.Common { private static readonly Lazy _instance = new(() => new()); public static SQLiteHelper Instance => _instance.Value; - private string _connstr; + private readonly string _connstr; private SQLiteConnection _db; private SQLiteAsyncConnection _dbAsync; private readonly string _configDB = "guiNDB.db"; diff --git a/v2rayN/ServiceLib/Common/StringEx.cs b/v2rayN/ServiceLib/Common/StringEx.cs index 12613a2e..ab5b808a 100644 --- a/v2rayN/ServiceLib/Common/StringEx.cs +++ b/v2rayN/ServiceLib/Common/StringEx.cs @@ -22,7 +22,9 @@ namespace ServiceLib.Common public static bool BeginWithAny(this string s, IEnumerable chars) { if (s.IsNullOrEmpty()) + { return false; + } return chars.Contains(s.First()); } @@ -36,7 +38,9 @@ namespace ServiceLib.Common while (reader.ReadLine() is { } line) { if (line.IsWhiteSpace()) + { continue; + } yield return line; } } diff --git a/v2rayN/ServiceLib/Common/WindowsUtils.cs b/v2rayN/ServiceLib/Common/WindowsUtils.cs index bead7899..1d4740c3 100644 --- a/v2rayN/ServiceLib/Common/WindowsUtils.cs +++ b/v2rayN/ServiceLib/Common/WindowsUtils.cs @@ -63,7 +63,7 @@ namespace ServiceLib.Common var arg = $$""" /remove-device "SWD\Wintun\{{{guid}}}" """; // Try to remove the device - await Utils.GetCliWrapOutput(pnpUtilPath, arg); + _ = await Utils.GetCliWrapOutput(pnpUtilPath, arg); } catch (Exception ex) { diff --git a/v2rayN/ServiceLib/Common/YamlUtils.cs b/v2rayN/ServiceLib/Common/YamlUtils.cs index 13ad2d78..511e41e5 100644 --- a/v2rayN/ServiceLib/Common/YamlUtils.cs +++ b/v2rayN/ServiceLib/Common/YamlUtils.cs @@ -1,4 +1,4 @@ -using YamlDotNet.Core; +using YamlDotNet.Core; using YamlDotNet.Serialization; using YamlDotNet.Serialization.NamingConventions; @@ -62,9 +62,6 @@ namespace ServiceLib.Common public static string? PreprocessYaml(string str) { - var deserializer = new DeserializerBuilder() - .WithNamingConvention(PascalCaseNamingConvention.Instance) - .Build(); try { var mergingParser = new MergingParser(new Parser(new StringReader(str))); @@ -80,4 +77,4 @@ namespace ServiceLib.Common #endregion YAML } -} \ No newline at end of file +}