AI-optimized code
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}");
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace ServiceLib.Common
|
||||
{
|
||||
private static readonly Lazy<SQLiteHelper> _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";
|
||||
|
||||
@@ -22,7 +22,9 @@ namespace ServiceLib.Common
|
||||
public static bool BeginWithAny(this string s, IEnumerable<char> 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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)));
|
||||
|
||||
Reference in New Issue
Block a user