From 59c0de7702a7b976dccbe3f2930ece6517f2aff0 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 30 Jan 2024 14:54:01 +0000 Subject: [PATCH] First pass cleanup and code conversion to net8.0 --- GCHandler.cs | 2 +- Logger/QueueLogger.cs | 35 ++++++++----------- LootDumpProcessorContext.cs | 16 ++++----- Model/ComposedKey.cs | 2 +- Model/Config/IntakeReaderConfig.cs | 3 +- Model/Config/ReaderConfig.cs | 2 +- Model/FireMode.cs | 2 +- Model/Foldable.cs | 2 +- Model/GroupPosition.cs | 10 +++--- Model/Item.cs | 18 +++++----- Model/Processing/ParsedDump.cs | 6 ++-- Model/Processing/PartialData.cs | 4 +-- Model/Repairable.cs | 4 +-- Model/Template.cs | 24 ++++++------- Model/Upd.cs | 9 ++--- Model/Vector3.cs | 6 ++-- Process/Collector/HashSetCollector.cs | 4 +-- Process/Collector/ICollector.cs | 3 +- Process/FilesGatherer.cs | 6 ---- .../MultithreadSteppedDumpProcessor.cs | 1 + .../Processor/FileProcessor/FileProcessor.cs | 3 +- .../FileProcessor/FileProcessorFactory.cs | 4 +-- .../Processor/FileProcessor/IFileProcessor.cs | 2 +- Process/Processor/LooseLootProcessor.cs | 3 +- Process/Processor/StaticLootProcessor.cs | 19 +++++----- Process/QueuePipeline.cs | 3 ++ Process/Reader/Filters/JsonDumpFileFilter.cs | 12 +++---- Process/Reader/Intake/IIntakeReader.cs | 2 +- Process/Reader/Intake/IntakeReaderFactory.cs | 6 ++-- Process/Reader/Intake/IntakeReaderTypes.cs | 2 +- Process/Reader/Intake/JsonFileIntakeReader.cs | 9 +++-- .../PreProcess/AbstractPreProcessReader.cs | 4 +-- .../PreProcess/PreProcessReaderFactory.cs | 1 - .../PreProcess/SevenZipPreProcessReader.cs | 4 +-- Process/TarkovItems.cs | 17 +++++---- Process/Writer/FileWriter.cs | 16 ++++----- Process/Writer/IWriter.cs | 2 +- Process/Writer/WriterFactory.cs | 4 +-- Program.cs | 4 +-- Serializers/ISerializer.cs | 2 +- .../Json/Converters/NetDateTimeConverter.cs | 9 ++--- .../Json/Converters/NetJsonKeyConverter.cs | 16 +++------ .../Converters/NewtonsoftDateTimeConverter.cs | 10 +++--- .../Converters/NewtonsoftJsonKeyConverter.cs | 16 +++------ Serializers/Json/JsonSerializerFactory.cs | 21 ++++------- Serializers/Json/NetJsonSerializer.cs | 2 +- Serializers/Json/NewtonsoftJsonSerializer.cs | 4 +-- Storage/AbstractKey.cs | 15 +++----- Storage/DataStorageFactory.cs | 22 +++++------- Storage/FlatUniqueKey.cs | 6 +--- .../Implementations/File/FileDataStorage.cs | 2 +- .../File/Handlers/AbstractStoreHandler.cs | 21 +++++------ .../File/Handlers/FlatStoreHandler.cs | 2 +- .../Handlers/SubdivisionedStoreHandler.cs | 2 +- Storage/Implementations/File/IStoreHandler.cs | 2 +- .../DataStorageFileSerializerFactory.cs | 2 +- .../Serializers/IDataStorageFileSerializer.cs | 2 +- .../JsonDataStorageFileSerializer.cs | 2 +- .../YamlDataStorageFileSerializer.cs | 2 +- .../File/StoreHandlerFactory.cs | 8 ++--- .../Memory/MemoryDataStorage.cs | 4 +-- Storage/SubdivisionedUniqueKey.cs | 6 +--- Utils/FileDateParser.cs | 2 +- Utils/ProcessorUtil.cs | 13 ++----- 64 files changed, 201 insertions(+), 268 deletions(-) delete mode 100644 Process/FilesGatherer.cs diff --git a/GCHandler.cs b/GCHandler.cs index 87a3f35..e25f524 100644 --- a/GCHandler.cs +++ b/GCHandler.cs @@ -1,6 +1,6 @@ namespace LootDumpProcessor; -public class GCHandler +public static class GCHandler { public static void Collect() { diff --git a/Logger/QueueLogger.cs b/Logger/QueueLogger.cs index 6511201..31dca7e 100644 --- a/Logger/QueueLogger.cs +++ b/Logger/QueueLogger.cs @@ -4,12 +4,12 @@ namespace LootDumpProcessor.Logger; public class QueueLogger : ILogger { - private BlockingCollection queuedMessages = new BlockingCollection(); + private readonly BlockingCollection queuedMessages = new(); private Task? loggerThread; private bool isRunning; private int logLevel; - private static readonly int _logTerminationTimeoutMs = 1000; - private static readonly int _logTerminationRetryCount = 3; + private const int LogTerminationTimeoutMs = 1000; + private const int LogTerminationRetryCount = 3; public void Setup() { @@ -56,19 +56,14 @@ public class QueueLogger : ILogger private int GetLogLevel(LogLevel level) { - switch (level) + return level switch { - case LogLevel.Error: - return 1; - case LogLevel.Warning: - return 2; - case LogLevel.Info: - return 3; - case LogLevel.Debug: - return 4; - default: - throw new ArgumentOutOfRangeException(); - } + LogLevel.Error => 1, + LogLevel.Warning => 2, + LogLevel.Info => 3, + LogLevel.Debug => 4, + _ => throw new ArgumentOutOfRangeException() + }; } public void Log(string message, LogLevel level) @@ -84,24 +79,24 @@ public class QueueLogger : ILogger if (loggerThread != null) { Console.ResetColor(); - int retryCount = 0; + var retryCount = 0; while (!loggerThread.IsCompleted) { - if (retryCount == _logTerminationRetryCount) + if (retryCount == LogTerminationRetryCount) { Console.WriteLine( $"Logger thread did not terminate by itself after {retryCount} retries. Some log messages may be lost."); break; } - Console.WriteLine($"Waiting {_logTerminationTimeoutMs}ms for logger termination"); - Thread.Sleep(_logTerminationTimeoutMs); + Console.WriteLine($"Waiting {LogTerminationTimeoutMs}ms for logger termination"); + Thread.Sleep(LogTerminationTimeoutMs); retryCount++; } } } - class LoggedMessage + private class LoggedMessage { public string Message { get; init; } public LogLevel LogLevel { get; init; } diff --git a/LootDumpProcessorContext.cs b/LootDumpProcessorContext.cs index 01e5538..f3b77a5 100644 --- a/LootDumpProcessorContext.cs +++ b/LootDumpProcessorContext.cs @@ -6,22 +6,22 @@ using LootDumpProcessor.Serializers.Yaml; namespace LootDumpProcessor; -public class LootDumpProcessorContext +public static class LootDumpProcessorContext { private static Config? _config; - private static readonly object _configLock = new object(); + private static readonly object _configLock = new(); private static ForcedStatic? _forcedStatic; - private static readonly object _forcedStaticLock = new object(); + private static readonly object _forcedStaticLock = new(); private static Dictionary? _mapDirectoryMappings; - private static readonly object _mapDirectoryMappingsLock = new object(); + private static readonly object _mapDirectoryMappingsLock = new(); private static HashSet? _staticWeaponIds; - private static readonly object _staticWeaponIdsLock = new object(); + private static readonly object _staticWeaponIdsLock = new(); private static Dictionary>? _forcedItems; - private static readonly object _forcedItemsLock = new object(); + private static readonly object _forcedItemsLock = new(); private static Dictionary>? _forcedLoose; - private static readonly object _forcedLooseLock = new object(); + private static readonly object _forcedLooseLock = new(); private static TarkovItems? _tarkovItems; - private static readonly object _tarkovItemsLock = new object(); + private static readonly object _tarkovItemsLock = new(); public static Config GetConfig() { diff --git a/Model/ComposedKey.cs b/Model/ComposedKey.cs index 3ed052e..432b40a 100644 --- a/Model/ComposedKey.cs +++ b/Model/ComposedKey.cs @@ -34,7 +34,7 @@ public class ComposedKey { if (obj is not ComposedKey key) return false; - return this.Key == key.Key; + return Key == key.Key; } public override int GetHashCode() => Key.GetHashCode(); diff --git a/Model/Config/IntakeReaderConfig.cs b/Model/Config/IntakeReaderConfig.cs index 9522bed..86b20e0 100644 --- a/Model/Config/IntakeReaderConfig.cs +++ b/Model/Config/IntakeReaderConfig.cs @@ -1,5 +1,6 @@ using System.Text.Json.Serialization; using LootDumpProcessor.Process.Reader; +using LootDumpProcessor.Process.Reader.Intake; using Newtonsoft.Json; namespace LootDumpProcessor.Model.Config; @@ -17,5 +18,5 @@ public class IntakeReaderConfig [JsonProperty("ignoredDumpLocations")] [JsonPropertyName("ignoredDumpLocations")] - public List IgnoredDumpLocations { get; set; } = new List(); + public List IgnoredDumpLocations { get; set; } = new(); } \ No newline at end of file diff --git a/Model/Config/ReaderConfig.cs b/Model/Config/ReaderConfig.cs index d37f157..ae16f97 100644 --- a/Model/Config/ReaderConfig.cs +++ b/Model/Config/ReaderConfig.cs @@ -24,7 +24,7 @@ public class ReaderConfig [JsonProperty("acceptedFileExtensions")] [JsonPropertyName("acceptedFileExtensions")] - public List AcceptedFileExtensions { get; set; } = new List(); + public List AcceptedFileExtensions { get; set; } = new(); [JsonProperty("processSubFolders")] [JsonPropertyName("processSubFolders")] diff --git a/Model/FireMode.cs b/Model/FireMode.cs index ba76a80..11dae0b 100644 --- a/Model/FireMode.cs +++ b/Model/FireMode.cs @@ -13,7 +13,7 @@ namespace LootDumpProcessor.Model { return new FireMode { - FireModeType = this.FireModeType + FireModeType = FireModeType }; } } diff --git a/Model/Foldable.cs b/Model/Foldable.cs index 848faf2..a071efe 100644 --- a/Model/Foldable.cs +++ b/Model/Foldable.cs @@ -13,7 +13,7 @@ namespace LootDumpProcessor.Model { return new Foldable { - Folded = this.Folded + Folded = Folded }; } } diff --git a/Model/GroupPosition.cs b/Model/GroupPosition.cs index 07ef0f5..74be2e5 100644 --- a/Model/GroupPosition.cs +++ b/Model/GroupPosition.cs @@ -1,5 +1,5 @@ using System.Text.Json.Serialization; -using LootDumpProcessor.Process.Processor; +using LootDumpProcessor.Utils; using Newtonsoft.Json; namespace LootDumpProcessor.Model @@ -26,10 +26,10 @@ namespace LootDumpProcessor.Model { return new GroupPosition { - Name = this.Name, - Weight = this.Weight, - Position = ProcessorUtil.Copy(this.Position), - Rotation = ProcessorUtil.Copy(this.Rotation) + Name = Name, + Weight = Weight, + Position = ProcessorUtil.Copy(Position), + Rotation = ProcessorUtil.Copy(Rotation) }; } } diff --git a/Model/Item.cs b/Model/Item.cs index 14c939d..554e46c 100644 --- a/Model/Item.cs +++ b/Model/Item.cs @@ -1,5 +1,5 @@ using System.Text.Json.Serialization; -using LootDumpProcessor.Process.Processor; +using LootDumpProcessor.Utils; using Newtonsoft.Json; namespace LootDumpProcessor.Model @@ -34,24 +34,24 @@ namespace LootDumpProcessor.Model { if (obj is not Item parsed) return false; - return parsed.Tpl == this.Tpl && parsed.ParentId == this.ParentId; + return parsed.Tpl == Tpl && parsed.ParentId == ParentId; } public override int GetHashCode() { - return (this.Tpl?.GetHashCode() + this.ParentId?.GetHashCode()) ?? base.GetHashCode(); + return (Tpl?.GetHashCode() + ParentId?.GetHashCode()) ?? base.GetHashCode(); } public object Clone() { return new Item { - Id = this.Id, - Tpl = this.Tpl, - ParentId = this.ParentId, - SlotId = this.SlotId, - Location = this.Location, - Upd = ProcessorUtil.Copy(this.Upd) + Id = Id, + Tpl = Tpl, + ParentId = ParentId, + SlotId = SlotId, + Location = Location, + Upd = ProcessorUtil.Copy(Upd) }; } } diff --git a/Model/Processing/ParsedDump.cs b/Model/Processing/ParsedDump.cs index d407bf0..21f6b38 100644 --- a/Model/Processing/ParsedDump.cs +++ b/Model/Processing/ParsedDump.cs @@ -5,7 +5,7 @@ namespace LootDumpProcessor.Model.Processing; public class ParsedDump : IKeyable { - private static readonly Regex _hashRegex = new Regex("([^a-zA-Z0-9])"); + private static readonly Regex _hashRegex = new("([^a-zA-Z0-9])"); public BasicInfo BasicInfo { get; set; } public PreProcessedLooseLoot LooseLoot { get; set; } public List Containers { get; set; } @@ -13,13 +13,13 @@ public class ParsedDump : IKeyable public override bool Equals(object? obj) { if (obj is ParsedDump dump) - return dump.BasicInfo.Equals(this.BasicInfo); + return dump.BasicInfo.Equals(BasicInfo); return false; } public override int GetHashCode() { - return this.BasicInfo.GetHashCode(); + return BasicInfo.GetHashCode(); } public IKey GetKey() diff --git a/Model/Processing/PartialData.cs b/Model/Processing/PartialData.cs index 7f4bd15..b189a50 100644 --- a/Model/Processing/PartialData.cs +++ b/Model/Processing/PartialData.cs @@ -10,12 +10,12 @@ public class PartialData public override bool Equals(object? obj) { if (obj is ParsedDump dump) - return dump.BasicInfo.Equals(this.BasicInfo); + return dump.BasicInfo.Equals(BasicInfo); return false; } public override int GetHashCode() { - return this.BasicInfo.GetHashCode(); + return BasicInfo.GetHashCode(); } } \ No newline at end of file diff --git a/Model/Repairable.cs b/Model/Repairable.cs index b2d7b9c..5e969d0 100644 --- a/Model/Repairable.cs +++ b/Model/Repairable.cs @@ -17,8 +17,8 @@ namespace LootDumpProcessor.Model { return new Repairable { - Durability = this.Durability, - MaxDurability = this.MaxDurability + Durability = Durability, + MaxDurability = MaxDurability }; } } diff --git a/Model/Template.cs b/Model/Template.cs index 7047115..d3d55ba 100644 --- a/Model/Template.cs +++ b/Model/Template.cs @@ -1,6 +1,6 @@ using System.Text.Json.Serialization; -using LootDumpProcessor.Process.Processor; using LootDumpProcessor.Storage; +using LootDumpProcessor.Utils; using Newtonsoft.Json; namespace LootDumpProcessor.Model @@ -82,17 +82,17 @@ namespace LootDumpProcessor.Model { return new Template { - Id = this.Id, - IsContainer = this.IsContainer, - UseGravity = this.UseGravity, - RandomRotation = this.RandomRotation, - Position = ProcessorUtil.Copy(this.Position), - Rotation = ProcessorUtil.Copy(this.Rotation), - IsGroupPosition = this.IsGroupPosition, - GroupPositions = ProcessorUtil.Copy(this.GroupPositions), - IsAlwaysSpawn = this.IsAlwaysSpawn, - Root = this.Root, - Items = ProcessorUtil.Copy(this.Items) + Id = Id, + IsContainer = IsContainer, + UseGravity = UseGravity, + RandomRotation = RandomRotation, + Position = ProcessorUtil.Copy(Position), + Rotation = ProcessorUtil.Copy(Rotation), + IsGroupPosition = IsGroupPosition, + GroupPositions = ProcessorUtil.Copy(GroupPositions), + IsAlwaysSpawn = IsAlwaysSpawn, + Root = Root, + Items = ProcessorUtil.Copy(Items) }; } } diff --git a/Model/Upd.cs b/Model/Upd.cs index 88a1cfe..23f2359 100644 --- a/Model/Upd.cs +++ b/Model/Upd.cs @@ -1,5 +1,6 @@ using System.Text.Json.Serialization; using LootDumpProcessor.Process.Processor; +using LootDumpProcessor.Utils; using Newtonsoft.Json; namespace LootDumpProcessor.Model @@ -26,10 +27,10 @@ namespace LootDumpProcessor.Model { return new Upd { - StackObjectsCount = this.StackObjectsCount, - FireMode = ProcessorUtil.Copy(this.FireMode), - Foldable = ProcessorUtil.Copy(this.Foldable), - Repairable = ProcessorUtil.Copy(this.Repairable) + StackObjectsCount = StackObjectsCount, + FireMode = ProcessorUtil.Copy(FireMode), + Foldable = ProcessorUtil.Copy(Foldable), + Repairable = ProcessorUtil.Copy(Repairable) }; } } diff --git a/Model/Vector3.cs b/Model/Vector3.cs index 71e075e..7055f16 100644 --- a/Model/Vector3.cs +++ b/Model/Vector3.cs @@ -21,9 +21,9 @@ namespace LootDumpProcessor.Model { return new Vector3 { - X = this.X, - Y = this.Y, - Z = this.Z + X = X, + Y = Y, + Z = Z }; } } diff --git a/Process/Collector/HashSetCollector.cs b/Process/Collector/HashSetCollector.cs index 6a14fb2..1739dc4 100644 --- a/Process/Collector/HashSetCollector.cs +++ b/Process/Collector/HashSetCollector.cs @@ -4,9 +4,9 @@ namespace LootDumpProcessor.Process.Collector; public class HashSetCollector : ICollector { - private HashSet processedDumps = new HashSet(); + private readonly HashSet processedDumps = new(); - private object lockObject = new object(); + private readonly object lockObject = new(); public void Setup() diff --git a/Process/Collector/ICollector.cs b/Process/Collector/ICollector.cs index 9f22567..1ca600e 100644 --- a/Process/Collector/ICollector.cs +++ b/Process/Collector/ICollector.cs @@ -1,5 +1,4 @@ -using LootDumpProcessor.Model.Config; -using LootDumpProcessor.Model.Processing; +using LootDumpProcessor.Model.Processing; namespace LootDumpProcessor.Process.Collector; diff --git a/Process/FilesGatherer.cs b/Process/FilesGatherer.cs deleted file mode 100644 index bc6af3d..0000000 --- a/Process/FilesGatherer.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace LootDumpProcessor.Process; - -public class FilesGatherer -{ - -} \ No newline at end of file diff --git a/Process/Processor/DumpProcessor/MultithreadSteppedDumpProcessor.cs b/Process/Processor/DumpProcessor/MultithreadSteppedDumpProcessor.cs index c4af432..1d968d2 100644 --- a/Process/Processor/DumpProcessor/MultithreadSteppedDumpProcessor.cs +++ b/Process/Processor/DumpProcessor/MultithreadSteppedDumpProcessor.cs @@ -7,6 +7,7 @@ using LootDumpProcessor.Model.Processing; using LootDumpProcessor.Serializers.Json; using LootDumpProcessor.Storage; using LootDumpProcessor.Storage.Collections; +using LootDumpProcessor.Utils; namespace LootDumpProcessor.Process.Processor.DumpProcessor; diff --git a/Process/Processor/FileProcessor/FileProcessor.cs b/Process/Processor/FileProcessor/FileProcessor.cs index b90b36a..ba02cdb 100644 --- a/Process/Processor/FileProcessor/FileProcessor.cs +++ b/Process/Processor/FileProcessor/FileProcessor.cs @@ -1,10 +1,9 @@ using LootDumpProcessor.Logger; using LootDumpProcessor.Model; using LootDumpProcessor.Model.Processing; -using LootDumpProcessor.Process.Processor; using LootDumpProcessor.Storage; -namespace LootDumpProcessor.Process.Impl; +namespace LootDumpProcessor.Process.Processor.FileProcessor; public class FileProcessor : IFileProcessor { diff --git a/Process/Processor/FileProcessor/FileProcessorFactory.cs b/Process/Processor/FileProcessor/FileProcessorFactory.cs index f0f4fbc..567e31a 100644 --- a/Process/Processor/FileProcessor/FileProcessorFactory.cs +++ b/Process/Processor/FileProcessor/FileProcessorFactory.cs @@ -1,6 +1,4 @@ -using LootDumpProcessor.Process.Impl; - -namespace LootDumpProcessor.Process.Processor; +namespace LootDumpProcessor.Process.Processor.FileProcessor; public static class FileProcessorFactory { diff --git a/Process/Processor/FileProcessor/IFileProcessor.cs b/Process/Processor/FileProcessor/IFileProcessor.cs index 1148992..30f4d8a 100644 --- a/Process/Processor/FileProcessor/IFileProcessor.cs +++ b/Process/Processor/FileProcessor/IFileProcessor.cs @@ -1,6 +1,6 @@ using LootDumpProcessor.Model.Processing; -namespace LootDumpProcessor.Process; +namespace LootDumpProcessor.Process.Processor.FileProcessor; public interface IFileProcessor { diff --git a/Process/Processor/LooseLootProcessor.cs b/Process/Processor/LooseLootProcessor.cs index 99ccf4a..5edc6eb 100644 --- a/Process/Processor/LooseLootProcessor.cs +++ b/Process/Processor/LooseLootProcessor.cs @@ -5,11 +5,12 @@ using LootDumpProcessor.Model.Output.LooseLoot; using LootDumpProcessor.Model.Processing; using LootDumpProcessor.Storage; using LootDumpProcessor.Storage.Collections; +using LootDumpProcessor.Utils; using NumSharp; namespace LootDumpProcessor.Process.Processor; -public class LooseLootProcessor +public static class LooseLootProcessor { public static PreProcessedLooseLoot PreProcessLooseLoot(List