From d6688fd0c49d9ecf5c7176eeac7c79536dd50720 Mon Sep 17 00:00:00 2001 From: 13xforever Date: Thu, 20 Jun 2024 12:33:31 +0500 Subject: [PATCH] clean up compiler warnings --- CompatBot/Commands/Sudo.Bot.cs | 3 ++- CompatBot/Commands/Sudo.cs | 3 ++- CompatBot/Database/DbImporter.cs | 2 ++ .../EventHandlers/LogParsing/ArchiveHandlers/RarHandler.cs | 2 +- .../LogParsing/ArchiveHandlers/SevenZipHandler.cs | 2 +- .../EventHandlers/LogParsing/ArchiveHandlers/ZipHandler.cs | 2 +- CompatBot/Utils/ColorGetter.cs | 2 +- CompatBot/Utils/Extensions/AzureDevOpsClientExtensions.cs | 6 +++--- 8 files changed, 13 insertions(+), 9 deletions(-) diff --git a/CompatBot/Commands/Sudo.Bot.cs b/CompatBot/Commands/Sudo.Bot.cs index a463d5a1..cee79003 100644 --- a/CompatBot/Commands/Sudo.Bot.cs +++ b/CompatBot/Commands/Sudo.Bot.cs @@ -12,6 +12,7 @@ using DSharpPlus.CommandsNext; using DSharpPlus.CommandsNext.Attributes; using DSharpPlus.Entities; using Microsoft.EntityFrameworkCore; +using NLog; namespace CompatBot.Commands; @@ -248,7 +249,7 @@ internal partial class Sudo if (SandboxDetector.Detect() != SandboxType.Docker) { Config.Log.Info("Restarting..."); - Config.Log.Factory.Flush(); + LogManager.LogFactory.Flush(); using var self = new Process {StartInfo = RestartInfo}; self.Start(); Config.InMemorySettings["shutdown"] = "true"; diff --git a/CompatBot/Commands/Sudo.cs b/CompatBot/Commands/Sudo.cs index c6c94a94..29a63dff 100644 --- a/CompatBot/Commands/Sudo.cs +++ b/CompatBot/Commands/Sudo.cs @@ -16,6 +16,7 @@ using DSharpPlus.CommandsNext.Attributes; using DSharpPlus.Entities; using DSharpPlus.Interactivity.Extensions; using Microsoft.EntityFrameworkCore; +using NLog; using SharpCompress.Common; using SharpCompress.Compressors; using SharpCompress.Compressors.Deflate; @@ -134,7 +135,7 @@ internal sealed partial class Sudo : BaseCommandModuleCustom { try { - Config.Log.Factory.Flush(); + LogManager.LogFactory.Flush(); string[] logPaths = [Config.CurrentLogPath]; if (DateTime.TryParse(date, CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out var logDate)) { diff --git a/CompatBot/Database/DbImporter.cs b/CompatBot/Database/DbImporter.cs index 260cf61c..33812ee5 100644 --- a/CompatBot/Database/DbImporter.cs +++ b/CompatBot/Database/DbImporter.cs @@ -75,8 +75,10 @@ public static class DbImporter { // __EFMigrationsHistory table will be already created by the failed migration attempt #pragma warning disable EF1001 // Internal EF Core API usage. +#pragma warning disable EF1002 // Using raw sql await db.ExecuteSqlRawAsync($"INSERT INTO `__EFMigrationsHistory`(`MigrationId`,`ProductVersion`) VALUES ({new InitialCreate().GetId()},'manual')", cancellationToken); await db.ExecuteSqlRawAsync($"INSERT INTO `__EFMigrationsHistory`(`MigrationId`,`ProductVersion`) VALUES ({new Explanations().GetId()},'manual')", cancellationToken); +#pragma warning restore EF1002 #pragma warning restore EF1001 // Internal EF Core API usage. // create constraints on moderator await db.ExecuteSqlRawAsync(@"CREATE TABLE `temp_new_moderator` ( diff --git a/CompatBot/EventHandlers/LogParsing/ArchiveHandlers/RarHandler.cs b/CompatBot/EventHandlers/LogParsing/ArchiveHandlers/RarHandler.cs index a1d4eaeb..6dac4232 100644 --- a/CompatBot/EventHandlers/LogParsing/ArchiveHandlers/RarHandler.cs +++ b/CompatBot/EventHandlers/LogParsing/ArchiveHandlers/RarHandler.cs @@ -40,7 +40,7 @@ internal sealed class RarHandler: IArchiveHandler while (rarReader.MoveToNextEntry()) { if (!rarReader.Entry.IsDirectory - && rarReader.Entry.Key.EndsWith(".log", StringComparison.InvariantCultureIgnoreCase) + && rarReader.Entry.Key!.EndsWith(".log", StringComparison.InvariantCultureIgnoreCase) && !rarReader.Entry.Key.Contains("tty.log", StringComparison.InvariantCultureIgnoreCase)) { LogSize = rarReader.Entry.Size; diff --git a/CompatBot/EventHandlers/LogParsing/ArchiveHandlers/SevenZipHandler.cs b/CompatBot/EventHandlers/LogParsing/ArchiveHandlers/SevenZipHandler.cs index a1605c00..f8b2188c 100644 --- a/CompatBot/EventHandlers/LogParsing/ArchiveHandlers/SevenZipHandler.cs +++ b/CompatBot/EventHandlers/LogParsing/ArchiveHandlers/SevenZipHandler.cs @@ -40,7 +40,7 @@ internal sealed class SevenZipHandler: IArchiveHandler using var zipReader = zipArchive.ExtractAllEntries(); while (zipReader.MoveToNextEntry()) if (!zipReader.Entry.IsDirectory - && zipReader.Entry.Key.EndsWith(".log", StringComparison.InvariantCultureIgnoreCase) + && zipReader.Entry.Key!.EndsWith(".log", StringComparison.InvariantCultureIgnoreCase) && !zipReader.Entry.Key.Contains("tty.log", StringComparison.InvariantCultureIgnoreCase)) { LogSize = zipReader.Entry.Size; diff --git a/CompatBot/EventHandlers/LogParsing/ArchiveHandlers/ZipHandler.cs b/CompatBot/EventHandlers/LogParsing/ArchiveHandlers/ZipHandler.cs index 9501f7b2..7bf9af75 100644 --- a/CompatBot/EventHandlers/LogParsing/ArchiveHandlers/ZipHandler.cs +++ b/CompatBot/EventHandlers/LogParsing/ArchiveHandlers/ZipHandler.cs @@ -41,7 +41,7 @@ internal sealed class ZipHandler: IArchiveHandler while (zipReader.MoveToNextEntry()) { if (!zipReader.Entry.IsDirectory - && zipReader.Entry.Key.EndsWith(".log", StringComparison.InvariantCultureIgnoreCase) + && zipReader.Entry.Key!.EndsWith(".log", StringComparison.InvariantCultureIgnoreCase) && !zipReader.Entry.Key.Contains("tty.log", StringComparison.InvariantCultureIgnoreCase)) { LogSize = zipReader.Entry.Size; diff --git a/CompatBot/Utils/ColorGetter.cs b/CompatBot/Utils/ColorGetter.cs index a8831663..24df3f3a 100644 --- a/CompatBot/Utils/ColorGetter.cs +++ b/CompatBot/Utils/ColorGetter.cs @@ -50,7 +50,7 @@ internal static class ColorGetter return defaultColor; // TODO .net6 breaks this for linux - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (!OperatingSystem.IsWindowsVersionAtLeast(6, 1)) return defaultColor; var analyzer = new ColorThief(); diff --git a/CompatBot/Utils/Extensions/AzureDevOpsClientExtensions.cs b/CompatBot/Utils/Extensions/AzureDevOpsClientExtensions.cs index 34dac23f..0ad9c1c6 100644 --- a/CompatBot/Utils/Extensions/AzureDevOpsClientExtensions.cs +++ b/CompatBot/Utils/Extensions/AzureDevOpsClientExtensions.cs @@ -218,7 +218,7 @@ internal static class AzureDevOpsClientExtensions using var zipStream = ReaderFactory.Open(stream); while (zipStream.MoveToNextEntry() && !cancellationToken.IsCancellationRequested) { - if (zipStream.Entry.Key.EndsWith(".7z", StringComparison.InvariantCultureIgnoreCase)) + if (zipStream.Entry.Key?.EndsWith(".7z", StringComparison.InvariantCultureIgnoreCase) is true) { result = result with {WindowsFilename = Path.GetFileName(zipStream.Entry.Key)}; break; @@ -248,7 +248,7 @@ internal static class AzureDevOpsClientExtensions using var zipStream = ReaderFactory.Open(stream); while (zipStream.MoveToNextEntry() && !cancellationToken.IsCancellationRequested) { - if (zipStream.Entry.Key.EndsWith(".AppImage", StringComparison.InvariantCultureIgnoreCase)) + if (zipStream.Entry.Key?.EndsWith(".AppImage", StringComparison.InvariantCultureIgnoreCase) is true) { result = result with {LinuxFilename = Path.GetFileName(zipStream.Entry.Key)}; break; @@ -275,7 +275,7 @@ internal static class AzureDevOpsClientExtensions using var zipStream = ReaderFactory.Open(stream); while (zipStream.MoveToNextEntry() && !cancellationToken.IsCancellationRequested) { - if (zipStream.Entry.Key.EndsWith(".dmg", StringComparison.InvariantCultureIgnoreCase)) + if (zipStream.Entry.Key?.EndsWith(".dmg", StringComparison.InvariantCultureIgnoreCase) is true) { result = result with { MacFilename = Path.GetFileName(zipStream.Entry.Key) }; break;