First pass cleanup and code conversion to net8.0

This commit is contained in:
Alex 2024-01-30 14:54:01 +00:00
parent f95664961d
commit 59c0de7702
64 changed files with 201 additions and 268 deletions

View File

@ -1,6 +1,6 @@
namespace LootDumpProcessor; namespace LootDumpProcessor;
public class GCHandler public static class GCHandler
{ {
public static void Collect() public static void Collect()
{ {

View File

@ -4,12 +4,12 @@ namespace LootDumpProcessor.Logger;
public class QueueLogger : ILogger public class QueueLogger : ILogger
{ {
private BlockingCollection<LoggedMessage> queuedMessages = new BlockingCollection<LoggedMessage>(); private readonly BlockingCollection<LoggedMessage> queuedMessages = new();
private Task? loggerThread; private Task? loggerThread;
private bool isRunning; private bool isRunning;
private int logLevel; private int logLevel;
private static readonly int _logTerminationTimeoutMs = 1000; private const int LogTerminationTimeoutMs = 1000;
private static readonly int _logTerminationRetryCount = 3; private const int LogTerminationRetryCount = 3;
public void Setup() public void Setup()
{ {
@ -56,19 +56,14 @@ public class QueueLogger : ILogger
private int GetLogLevel(LogLevel level) private int GetLogLevel(LogLevel level)
{ {
switch (level) return level switch
{ {
case LogLevel.Error: LogLevel.Error => 1,
return 1; LogLevel.Warning => 2,
case LogLevel.Warning: LogLevel.Info => 3,
return 2; LogLevel.Debug => 4,
case LogLevel.Info: _ => throw new ArgumentOutOfRangeException()
return 3; };
case LogLevel.Debug:
return 4;
default:
throw new ArgumentOutOfRangeException();
}
} }
public void Log(string message, LogLevel level) public void Log(string message, LogLevel level)
@ -84,24 +79,24 @@ public class QueueLogger : ILogger
if (loggerThread != null) if (loggerThread != null)
{ {
Console.ResetColor(); Console.ResetColor();
int retryCount = 0; var retryCount = 0;
while (!loggerThread.IsCompleted) while (!loggerThread.IsCompleted)
{ {
if (retryCount == _logTerminationRetryCount) if (retryCount == LogTerminationRetryCount)
{ {
Console.WriteLine( Console.WriteLine(
$"Logger thread did not terminate by itself after {retryCount} retries. Some log messages may be lost."); $"Logger thread did not terminate by itself after {retryCount} retries. Some log messages may be lost.");
break; break;
} }
Console.WriteLine($"Waiting {_logTerminationTimeoutMs}ms for logger termination"); Console.WriteLine($"Waiting {LogTerminationTimeoutMs}ms for logger termination");
Thread.Sleep(_logTerminationTimeoutMs); Thread.Sleep(LogTerminationTimeoutMs);
retryCount++; retryCount++;
} }
} }
} }
class LoggedMessage private class LoggedMessage
{ {
public string Message { get; init; } public string Message { get; init; }
public LogLevel LogLevel { get; init; } public LogLevel LogLevel { get; init; }

View File

@ -6,22 +6,22 @@ using LootDumpProcessor.Serializers.Yaml;
namespace LootDumpProcessor; namespace LootDumpProcessor;
public class LootDumpProcessorContext public static class LootDumpProcessorContext
{ {
private static Config? _config; private static Config? _config;
private static readonly object _configLock = new object(); private static readonly object _configLock = new();
private static ForcedStatic? _forcedStatic; private static ForcedStatic? _forcedStatic;
private static readonly object _forcedStaticLock = new object(); private static readonly object _forcedStaticLock = new();
private static Dictionary<string, MapDirectoryMapping>? _mapDirectoryMappings; private static Dictionary<string, MapDirectoryMapping>? _mapDirectoryMappings;
private static readonly object _mapDirectoryMappingsLock = new object(); private static readonly object _mapDirectoryMappingsLock = new();
private static HashSet<string>? _staticWeaponIds; private static HashSet<string>? _staticWeaponIds;
private static readonly object _staticWeaponIdsLock = new object(); private static readonly object _staticWeaponIdsLock = new();
private static Dictionary<string, List<StaticForced>>? _forcedItems; private static Dictionary<string, List<StaticForced>>? _forcedItems;
private static readonly object _forcedItemsLock = new object(); private static readonly object _forcedItemsLock = new();
private static Dictionary<string, HashSet<string>>? _forcedLoose; private static Dictionary<string, HashSet<string>>? _forcedLoose;
private static readonly object _forcedLooseLock = new object(); private static readonly object _forcedLooseLock = new();
private static TarkovItems? _tarkovItems; private static TarkovItems? _tarkovItems;
private static readonly object _tarkovItemsLock = new object(); private static readonly object _tarkovItemsLock = new();
public static Config GetConfig() public static Config GetConfig()
{ {

View File

@ -34,7 +34,7 @@ public class ComposedKey
{ {
if (obj is not ComposedKey key) if (obj is not ComposedKey key)
return false; return false;
return this.Key == key.Key; return Key == key.Key;
} }
public override int GetHashCode() => Key.GetHashCode(); public override int GetHashCode() => Key.GetHashCode();

View File

@ -1,5 +1,6 @@
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using LootDumpProcessor.Process.Reader; using LootDumpProcessor.Process.Reader;
using LootDumpProcessor.Process.Reader.Intake;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace LootDumpProcessor.Model.Config; namespace LootDumpProcessor.Model.Config;
@ -17,5 +18,5 @@ public class IntakeReaderConfig
[JsonProperty("ignoredDumpLocations")] [JsonProperty("ignoredDumpLocations")]
[JsonPropertyName("ignoredDumpLocations")] [JsonPropertyName("ignoredDumpLocations")]
public List<string> IgnoredDumpLocations { get; set; } = new List<string>(); public List<string> IgnoredDumpLocations { get; set; } = new();
} }

View File

@ -24,7 +24,7 @@ public class ReaderConfig
[JsonProperty("acceptedFileExtensions")] [JsonProperty("acceptedFileExtensions")]
[JsonPropertyName("acceptedFileExtensions")] [JsonPropertyName("acceptedFileExtensions")]
public List<string> AcceptedFileExtensions { get; set; } = new List<string>(); public List<string> AcceptedFileExtensions { get; set; } = new();
[JsonProperty("processSubFolders")] [JsonProperty("processSubFolders")]
[JsonPropertyName("processSubFolders")] [JsonPropertyName("processSubFolders")]

View File

@ -13,7 +13,7 @@ namespace LootDumpProcessor.Model
{ {
return new FireMode return new FireMode
{ {
FireModeType = this.FireModeType FireModeType = FireModeType
}; };
} }
} }

View File

@ -13,7 +13,7 @@ namespace LootDumpProcessor.Model
{ {
return new Foldable return new Foldable
{ {
Folded = this.Folded Folded = Folded
}; };
} }
} }

View File

@ -1,5 +1,5 @@
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using LootDumpProcessor.Process.Processor; using LootDumpProcessor.Utils;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace LootDumpProcessor.Model namespace LootDumpProcessor.Model
@ -26,10 +26,10 @@ namespace LootDumpProcessor.Model
{ {
return new GroupPosition return new GroupPosition
{ {
Name = this.Name, Name = Name,
Weight = this.Weight, Weight = Weight,
Position = ProcessorUtil.Copy(this.Position), Position = ProcessorUtil.Copy(Position),
Rotation = ProcessorUtil.Copy(this.Rotation) Rotation = ProcessorUtil.Copy(Rotation)
}; };
} }
} }

View File

@ -1,5 +1,5 @@
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using LootDumpProcessor.Process.Processor; using LootDumpProcessor.Utils;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace LootDumpProcessor.Model namespace LootDumpProcessor.Model
@ -34,24 +34,24 @@ namespace LootDumpProcessor.Model
{ {
if (obj is not Item parsed) if (obj is not Item parsed)
return false; return false;
return parsed.Tpl == this.Tpl && parsed.ParentId == this.ParentId; return parsed.Tpl == Tpl && parsed.ParentId == ParentId;
} }
public override int GetHashCode() public override int GetHashCode()
{ {
return (this.Tpl?.GetHashCode() + this.ParentId?.GetHashCode()) ?? base.GetHashCode(); return (Tpl?.GetHashCode() + ParentId?.GetHashCode()) ?? base.GetHashCode();
} }
public object Clone() public object Clone()
{ {
return new Item return new Item
{ {
Id = this.Id, Id = Id,
Tpl = this.Tpl, Tpl = Tpl,
ParentId = this.ParentId, ParentId = ParentId,
SlotId = this.SlotId, SlotId = SlotId,
Location = this.Location, Location = Location,
Upd = ProcessorUtil.Copy(this.Upd) Upd = ProcessorUtil.Copy(Upd)
}; };
} }
} }

View File

@ -5,7 +5,7 @@ namespace LootDumpProcessor.Model.Processing;
public class ParsedDump : IKeyable 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 BasicInfo BasicInfo { get; set; }
public PreProcessedLooseLoot LooseLoot { get; set; } public PreProcessedLooseLoot LooseLoot { get; set; }
public List<PreProcessedStaticLoot> Containers { get; set; } public List<PreProcessedStaticLoot> Containers { get; set; }
@ -13,13 +13,13 @@ public class ParsedDump : IKeyable
public override bool Equals(object? obj) public override bool Equals(object? obj)
{ {
if (obj is ParsedDump dump) if (obj is ParsedDump dump)
return dump.BasicInfo.Equals(this.BasicInfo); return dump.BasicInfo.Equals(BasicInfo);
return false; return false;
} }
public override int GetHashCode() public override int GetHashCode()
{ {
return this.BasicInfo.GetHashCode(); return BasicInfo.GetHashCode();
} }
public IKey GetKey() public IKey GetKey()

View File

@ -10,12 +10,12 @@ public class PartialData
public override bool Equals(object? obj) public override bool Equals(object? obj)
{ {
if (obj is ParsedDump dump) if (obj is ParsedDump dump)
return dump.BasicInfo.Equals(this.BasicInfo); return dump.BasicInfo.Equals(BasicInfo);
return false; return false;
} }
public override int GetHashCode() public override int GetHashCode()
{ {
return this.BasicInfo.GetHashCode(); return BasicInfo.GetHashCode();
} }
} }

View File

@ -17,8 +17,8 @@ namespace LootDumpProcessor.Model
{ {
return new Repairable return new Repairable
{ {
Durability = this.Durability, Durability = Durability,
MaxDurability = this.MaxDurability MaxDurability = MaxDurability
}; };
} }
} }

View File

@ -1,6 +1,6 @@
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using LootDumpProcessor.Process.Processor;
using LootDumpProcessor.Storage; using LootDumpProcessor.Storage;
using LootDumpProcessor.Utils;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace LootDumpProcessor.Model namespace LootDumpProcessor.Model
@ -82,17 +82,17 @@ namespace LootDumpProcessor.Model
{ {
return new Template return new Template
{ {
Id = this.Id, Id = Id,
IsContainer = this.IsContainer, IsContainer = IsContainer,
UseGravity = this.UseGravity, UseGravity = UseGravity,
RandomRotation = this.RandomRotation, RandomRotation = RandomRotation,
Position = ProcessorUtil.Copy(this.Position), Position = ProcessorUtil.Copy(Position),
Rotation = ProcessorUtil.Copy(this.Rotation), Rotation = ProcessorUtil.Copy(Rotation),
IsGroupPosition = this.IsGroupPosition, IsGroupPosition = IsGroupPosition,
GroupPositions = ProcessorUtil.Copy(this.GroupPositions), GroupPositions = ProcessorUtil.Copy(GroupPositions),
IsAlwaysSpawn = this.IsAlwaysSpawn, IsAlwaysSpawn = IsAlwaysSpawn,
Root = this.Root, Root = Root,
Items = ProcessorUtil.Copy(this.Items) Items = ProcessorUtil.Copy(Items)
}; };
} }
} }

View File

@ -1,5 +1,6 @@
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using LootDumpProcessor.Process.Processor; using LootDumpProcessor.Process.Processor;
using LootDumpProcessor.Utils;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace LootDumpProcessor.Model namespace LootDumpProcessor.Model
@ -26,10 +27,10 @@ namespace LootDumpProcessor.Model
{ {
return new Upd return new Upd
{ {
StackObjectsCount = this.StackObjectsCount, StackObjectsCount = StackObjectsCount,
FireMode = ProcessorUtil.Copy(this.FireMode), FireMode = ProcessorUtil.Copy(FireMode),
Foldable = ProcessorUtil.Copy(this.Foldable), Foldable = ProcessorUtil.Copy(Foldable),
Repairable = ProcessorUtil.Copy(this.Repairable) Repairable = ProcessorUtil.Copy(Repairable)
}; };
} }
} }

View File

@ -21,9 +21,9 @@ namespace LootDumpProcessor.Model
{ {
return new Vector3 return new Vector3
{ {
X = this.X, X = X,
Y = this.Y, Y = Y,
Z = this.Z Z = Z
}; };
} }
} }

View File

@ -4,9 +4,9 @@ namespace LootDumpProcessor.Process.Collector;
public class HashSetCollector : ICollector public class HashSetCollector : ICollector
{ {
private HashSet<PartialData> processedDumps = new HashSet<PartialData>(); private readonly HashSet<PartialData> processedDumps = new();
private object lockObject = new object(); private readonly object lockObject = new();
public void Setup() public void Setup()

View File

@ -1,5 +1,4 @@
using LootDumpProcessor.Model.Config; using LootDumpProcessor.Model.Processing;
using LootDumpProcessor.Model.Processing;
namespace LootDumpProcessor.Process.Collector; namespace LootDumpProcessor.Process.Collector;

View File

@ -1,6 +0,0 @@
namespace LootDumpProcessor.Process;
public class FilesGatherer
{
}

View File

@ -7,6 +7,7 @@ using LootDumpProcessor.Model.Processing;
using LootDumpProcessor.Serializers.Json; using LootDumpProcessor.Serializers.Json;
using LootDumpProcessor.Storage; using LootDumpProcessor.Storage;
using LootDumpProcessor.Storage.Collections; using LootDumpProcessor.Storage.Collections;
using LootDumpProcessor.Utils;
namespace LootDumpProcessor.Process.Processor.DumpProcessor; namespace LootDumpProcessor.Process.Processor.DumpProcessor;

View File

@ -1,10 +1,9 @@
using LootDumpProcessor.Logger; using LootDumpProcessor.Logger;
using LootDumpProcessor.Model; using LootDumpProcessor.Model;
using LootDumpProcessor.Model.Processing; using LootDumpProcessor.Model.Processing;
using LootDumpProcessor.Process.Processor;
using LootDumpProcessor.Storage; using LootDumpProcessor.Storage;
namespace LootDumpProcessor.Process.Impl; namespace LootDumpProcessor.Process.Processor.FileProcessor;
public class FileProcessor : IFileProcessor public class FileProcessor : IFileProcessor
{ {

View File

@ -1,6 +1,4 @@
using LootDumpProcessor.Process.Impl; namespace LootDumpProcessor.Process.Processor.FileProcessor;
namespace LootDumpProcessor.Process.Processor;
public static class FileProcessorFactory public static class FileProcessorFactory
{ {

View File

@ -1,6 +1,6 @@
using LootDumpProcessor.Model.Processing; using LootDumpProcessor.Model.Processing;
namespace LootDumpProcessor.Process; namespace LootDumpProcessor.Process.Processor.FileProcessor;
public interface IFileProcessor public interface IFileProcessor
{ {

View File

@ -5,11 +5,12 @@ using LootDumpProcessor.Model.Output.LooseLoot;
using LootDumpProcessor.Model.Processing; using LootDumpProcessor.Model.Processing;
using LootDumpProcessor.Storage; using LootDumpProcessor.Storage;
using LootDumpProcessor.Storage.Collections; using LootDumpProcessor.Storage.Collections;
using LootDumpProcessor.Utils;
using NumSharp; using NumSharp;
namespace LootDumpProcessor.Process.Processor; namespace LootDumpProcessor.Process.Processor;
public class LooseLootProcessor public static class LooseLootProcessor
{ {
public static PreProcessedLooseLoot PreProcessLooseLoot(List<Template> looseloot) public static PreProcessedLooseLoot PreProcessLooseLoot(List<Template> looseloot)
{ {

View File

@ -3,10 +3,11 @@ using LootDumpProcessor.Model.Input;
using LootDumpProcessor.Model.Output; using LootDumpProcessor.Model.Output;
using LootDumpProcessor.Model.Output.StaticContainer; using LootDumpProcessor.Model.Output.StaticContainer;
using LootDumpProcessor.Model.Processing; using LootDumpProcessor.Model.Processing;
using LootDumpProcessor.Utils;
namespace LootDumpProcessor.Process.Processor; namespace LootDumpProcessor.Process.Processor;
public class StaticLootProcessor public static class StaticLootProcessor
{ {
public static List<PreProcessedStaticLoot> PreProcessStaticLoot(List<Template> staticloot) public static List<PreProcessedStaticLoot> PreProcessStaticLoot(List<Template> staticloot)
{ {
@ -30,7 +31,6 @@ public class StaticLootProcessor
public static Tuple<string, MapStaticLoot> CreateRealStaticContainers(RootData rawMapDump) public static Tuple<string, MapStaticLoot> CreateRealStaticContainers(RootData rawMapDump)
{ {
List<StaticForced> forcedStaticItems;
var mapName = rawMapDump.Data.Name; var mapName = rawMapDump.Data.Name;
var staticLootPositions = (from li in rawMapDump.Data.Loot var staticLootPositions = (from li in rawMapDump.Data.Loot
where li.IsContainer ?? false where li.IsContainer ?? false
@ -46,7 +46,7 @@ public class StaticLootProcessor
} }
} }
forcedStaticItems = LootDumpProcessorContext.GetForcedItems().ContainsKey(mapName) var forcedStaticItems = LootDumpProcessorContext.GetForcedItems().ContainsKey(mapName)
? LootDumpProcessorContext.GetForcedItems()[mapName] ? LootDumpProcessorContext.GetForcedItems()[mapName]
: new List<StaticForced>(); : new List<StaticForced>();
@ -145,15 +145,12 @@ public class StaticLootProcessor
var itemsHitCounts = new Dictionary<string, int>(); var itemsHitCounts = new Dictionary<string, int>();
foreach (var ci in container_counts_selected) foreach (var ci in container_counts_selected)
{ {
foreach (var cii in ci.Items) foreach (var cii in ci.Items.Where(cii => cii.ParentId == ci.ContainerId))
{ {
if (cii.ParentId == ci.ContainerId) if (itemsHitCounts.ContainsKey(cii.Tpl))
{ itemsHitCounts[cii.Tpl] += 1;
if (itemsHitCounts.ContainsKey(cii.Tpl)) else
itemsHitCounts[cii.Tpl] += 1; itemsHitCounts[cii.Tpl] = 1;
else
itemsHitCounts[cii.Tpl] = 1;
}
} }
} }

View File

@ -3,10 +3,13 @@ using LootDumpProcessor.Logger;
using LootDumpProcessor.Process.Collector; using LootDumpProcessor.Process.Collector;
using LootDumpProcessor.Process.Processor; using LootDumpProcessor.Process.Processor;
using LootDumpProcessor.Process.Processor.DumpProcessor; using LootDumpProcessor.Process.Processor.DumpProcessor;
using LootDumpProcessor.Process.Processor.FileProcessor;
using LootDumpProcessor.Process.Reader; using LootDumpProcessor.Process.Reader;
using LootDumpProcessor.Process.Reader.Filters; using LootDumpProcessor.Process.Reader.Filters;
using LootDumpProcessor.Process.Reader.Intake;
using LootDumpProcessor.Process.Reader.PreProcess; using LootDumpProcessor.Process.Reader.PreProcess;
using LootDumpProcessor.Process.Writer; using LootDumpProcessor.Process.Writer;
using LootDumpProcessor.Utils;
namespace LootDumpProcessor.Process; namespace LootDumpProcessor.Process;

View File

@ -6,8 +6,8 @@ namespace LootDumpProcessor.Process.Reader.Filters;
public class JsonDumpFileFilter : IFileFilter public class JsonDumpFileFilter : IFileFilter
{ {
private static Regex FileNameDateRegex = new("([0-9]{4}(-[0-9]{2}){2}_((-){0,1}[0-9]{2}){3})"); private static readonly Regex _fileNameDateRegex = new("([0-9]{4}(-[0-9]{2}){2}_((-){0,1}[0-9]{2}){3})");
private static DateTime parsedThresholdDate; private static readonly DateTime _parsedThresholdDate;
static JsonDumpFileFilter() static JsonDumpFileFilter()
{ {
@ -17,11 +17,11 @@ public class JsonDumpFileFilter : IFileFilter
LoggerFactory.GetInstance() LoggerFactory.GetInstance()
.Log($"ThresholdDate is null or empty in configs, defaulting to current day minus 30 days", .Log($"ThresholdDate is null or empty in configs, defaulting to current day minus 30 days",
LogLevel.Warning); LogLevel.Warning);
parsedThresholdDate = (DateTime.Now - TimeSpan.FromDays(30)); _parsedThresholdDate = (DateTime.Now - TimeSpan.FromDays(30));
} }
else else
{ {
parsedThresholdDate = DateTime.ParseExact( _parsedThresholdDate = DateTime.ParseExact(
LootDumpProcessorContext.GetConfig().ReaderConfig.ThresholdDate, LootDumpProcessorContext.GetConfig().ReaderConfig.ThresholdDate,
"yyyy-MM-dd", "yyyy-MM-dd",
CultureInfo.InvariantCulture CultureInfo.InvariantCulture
@ -33,8 +33,8 @@ public class JsonDumpFileFilter : IFileFilter
public bool Accept(string filename) public bool Accept(string filename)
{ {
var unparsedDate = FileNameDateRegex.Match(filename).Groups[1].Value; var unparsedDate = _fileNameDateRegex.Match(filename).Groups[1].Value;
var date = DateTime.ParseExact(unparsedDate, "yyyy-MM-dd_HH-mm-ss", CultureInfo.InvariantCulture); var date = DateTime.ParseExact(unparsedDate, "yyyy-MM-dd_HH-mm-ss", CultureInfo.InvariantCulture);
return date > parsedThresholdDate; return date > _parsedThresholdDate;
} }
} }

View File

@ -1,6 +1,6 @@
using LootDumpProcessor.Model.Processing; using LootDumpProcessor.Model.Processing;
namespace LootDumpProcessor.Process; namespace LootDumpProcessor.Process.Reader.Intake;
public interface IIntakeReader public interface IIntakeReader
{ {

View File

@ -1,12 +1,10 @@
using LootDumpProcessor.Process.Impl; namespace LootDumpProcessor.Process.Reader.Intake;
namespace LootDumpProcessor.Process.Reader;
public static class IntakeReaderFactory public static class IntakeReaderFactory
{ {
public static IIntakeReader GetInstance() public static IIntakeReader GetInstance()
{ {
return LootDumpProcessorContext.GetConfig().ReaderConfig.IntakeReaderConfig.IntakeReaderType switch return (LootDumpProcessorContext.GetConfig().ReaderConfig.IntakeReaderConfig?.IntakeReaderType ?? IntakeReaderTypes.Json) switch
{ {
IntakeReaderTypes.Json => new JsonFileIntakeReader(), IntakeReaderTypes.Json => new JsonFileIntakeReader(),
_ => throw new ArgumentOutOfRangeException( _ => throw new ArgumentOutOfRangeException(

View File

@ -1,4 +1,4 @@
namespace LootDumpProcessor.Process.Reader; namespace LootDumpProcessor.Process.Reader.Intake;
public enum IntakeReaderTypes public enum IntakeReaderTypes
{ {

View File

@ -2,10 +2,10 @@
using LootDumpProcessor.Logger; using LootDumpProcessor.Logger;
using LootDumpProcessor.Model.Input; using LootDumpProcessor.Model.Input;
using LootDumpProcessor.Model.Processing; using LootDumpProcessor.Model.Processing;
using LootDumpProcessor.Process.Processor;
using LootDumpProcessor.Serializers.Json; using LootDumpProcessor.Serializers.Json;
using LootDumpProcessor.Utils;
namespace LootDumpProcessor.Process.Impl; namespace LootDumpProcessor.Process.Reader.Intake;
public class JsonFileIntakeReader : IIntakeReader public class JsonFileIntakeReader : IIntakeReader
{ {
@ -26,14 +26,13 @@ public class JsonFileIntakeReader : IIntakeReader
var fi = _jsonSerializer.Deserialize<RootData>(fileData); var fi = _jsonSerializer.Deserialize<RootData>(fileData);
if (fi.Data?.Name != null && (!_ignoredLocations?.Contains(fi.Data.Name) ?? true)) if (fi.Data?.Name != null && (!_ignoredLocations?.Contains(fi.Data.Name) ?? true))
{ {
int counter; if (!_totalMapDumpsCounter.TryGetValue(fi.Data.Name, out var counter))
if (!_totalMapDumpsCounter.TryGetValue(fi.Data.Name, out counter))
{ {
counter = 0; counter = 0;
_totalMapDumpsCounter[fi.Data.Name] = counter; _totalMapDumpsCounter[fi.Data.Name] = counter;
} }
if (counter < LootDumpProcessorContext.GetConfig().ReaderConfig.IntakeReaderConfig.MaxDumpsPerMap) if (counter < (LootDumpProcessorContext.GetConfig().ReaderConfig.IntakeReaderConfig?.MaxDumpsPerMap ?? 1500))
{ {
basicInfo = new BasicInfo basicInfo = new BasicInfo
{ {

View File

@ -4,7 +4,7 @@ namespace LootDumpProcessor.Process.Reader.PreProcess;
public abstract class AbstractPreProcessReader : IPreProcessReader public abstract class AbstractPreProcessReader : IPreProcessReader
{ {
protected string _tempFolder; protected readonly string _tempFolder;
public AbstractPreProcessReader() public AbstractPreProcessReader()
{ {
@ -35,7 +35,7 @@ public abstract class AbstractPreProcessReader : IPreProcessReader
protected string GetBaseDirectory() protected string GetBaseDirectory()
{ {
return $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}\\SPT\\tmp\\PreProcessor"; return $@"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}\SPT\tmp\PreProcessor";
} }
public void Dispose() public void Dispose()

View File

@ -3,7 +3,6 @@
public static class PreProcessReaderFactory public static class PreProcessReaderFactory
{ {
private static readonly Dictionary<PreProcessReaderTypes, IPreProcessReader> _proProcessReaders = new(); private static readonly Dictionary<PreProcessReaderTypes, IPreProcessReader> _proProcessReaders = new();
private static object lockObject = new object();
public static IPreProcessReader GetInstance(PreProcessReaderTypes type) public static IPreProcessReader GetInstance(PreProcessReaderTypes type)
{ {

View File

@ -15,8 +15,6 @@ public class SevenZipPreProcessReader : AbstractPreProcessReader
public override bool TryPreProcess(string file, out List<string> files, out List<string> directories) public override bool TryPreProcess(string file, out List<string> files, out List<string> directories)
{ {
Decoder decoder = new Decoder();
var fileRaw = Path.GetFileNameWithoutExtension(file); var fileRaw = Path.GetFileNameWithoutExtension(file);
// SevenZip library doesnt like forward slashes for some reason // SevenZip library doesnt like forward slashes for some reason
var outPath = $"{_tempFolder}\\{fileRaw}".Replace("/", "\\"); var outPath = $"{_tempFolder}\\{fileRaw}".Replace("/", "\\");
@ -24,7 +22,7 @@ public class SevenZipPreProcessReader : AbstractPreProcessReader
$"Unzipping {file} into temp path {outPath}, this may take a while...", $"Unzipping {file} into temp path {outPath}, this may take a while...",
LogLevel.Info); LogLevel.Info);
var extractor = new SevenZipExtractor(file); var extractor = new SevenZipExtractor(file);
extractor.Extracting += (sender, args) => extractor.Extracting += (_, args) =>
{ {
if (args.PercentDone % 10 == 0) if (args.PercentDone % 10 == 0)
LoggerFactory.GetInstance().Log($"Unzip progress: {args.PercentDone}%", LogLevel.Info); LoggerFactory.GetInstance().Log($"Unzip progress: {args.PercentDone}%", LogLevel.Info);

View File

@ -4,19 +4,16 @@ using LootDumpProcessor.Serializers.Json;
namespace LootDumpProcessor.Process; namespace LootDumpProcessor.Process;
public class TarkovItems public class TarkovItems(string items)
{ {
private static readonly IJsonSerializer _jsonSerializer = JsonSerializerFactory.GetInstance(); private static readonly IJsonSerializer _jsonSerializer = JsonSerializerFactory.GetInstance();
private Dictionary<string, TemplateFileItem> _items; private readonly Dictionary<string, TemplateFileItem>? _items = _jsonSerializer.Deserialize<Dictionary<string, TemplateFileItem>>(File.ReadAllText(items));
public TarkovItems(string items)
{
_items = _jsonSerializer.Deserialize<Dictionary<string, TemplateFileItem>>(File.ReadAllText(items));
}
public virtual bool IsBaseClass(string tpl, string baseclass_id) public virtual bool IsBaseClass(string tpl, string baseclass_id)
{ {
if (_items == null)
throw new Exception("The server items couldnt be found or loaded. Check server config is pointing to the correct place");
if (!_items.TryGetValue(tpl, out var item_template)) if (!_items.TryGetValue(tpl, out var item_template))
{ {
LoggerFactory.GetInstance().Log($"[IsBaseClass] Item template '{tpl}' with base class id '{baseclass_id}' was not found on the server items!", LogLevel.Error); LoggerFactory.GetInstance().Log($"[IsBaseClass] Item template '{tpl}' with base class id '{baseclass_id}' was not found on the server items!", LogLevel.Error);
@ -31,6 +28,8 @@ public class TarkovItems
public virtual bool IsQuestItem(string tpl) public virtual bool IsQuestItem(string tpl)
{ {
if (_items == null)
throw new Exception("The server items couldnt be found or loaded. Check server config is pointing to the correct place");
if (!_items.TryGetValue(tpl, out var item_template)) if (!_items.TryGetValue(tpl, out var item_template))
{ {
LoggerFactory.GetInstance().Log($"[IsQuestItem] Item template '{tpl}' was not found on the server items!", LogLevel.Error); LoggerFactory.GetInstance().Log($"[IsQuestItem] Item template '{tpl}' was not found on the server items!", LogLevel.Error);
@ -41,6 +40,8 @@ public class TarkovItems
public virtual string? MaxDurability(string tpl) public virtual string? MaxDurability(string tpl)
{ {
if (_items == null)
throw new Exception("The server items couldnt be found or loaded. Check server config is pointing to the correct place");
if (!_items.TryGetValue(tpl, out var item_template)) if (!_items.TryGetValue(tpl, out var item_template))
{ {
LoggerFactory.GetInstance().Log($"[MaxDurability] Item template '{tpl}' was not found on the server items!", LogLevel.Error); LoggerFactory.GetInstance().Log($"[MaxDurability] Item template '{tpl}' was not found on the server items!", LogLevel.Error);
@ -51,6 +52,8 @@ public class TarkovItems
public virtual string? AmmoCaliber(string tpl) public virtual string? AmmoCaliber(string tpl)
{ {
if (_items == null)
throw new Exception("The server items couldnt be found or loaded. Check server config is pointing to the correct place");
if (!_items.TryGetValue(tpl, out var item_template)) if (!_items.TryGetValue(tpl, out var item_template))
{ {
LoggerFactory.GetInstance().Log($"[AmmoCaliber] Item template '{tpl}' was not found on the server items!", LogLevel.Error); LoggerFactory.GetInstance().Log($"[AmmoCaliber] Item template '{tpl}' was not found on the server items!", LogLevel.Error);

View File

@ -3,12 +3,12 @@ using LootDumpProcessor.Model.Output.LooseLoot;
using LootDumpProcessor.Model.Output.StaticContainer; using LootDumpProcessor.Model.Output.StaticContainer;
using LootDumpProcessor.Serializers.Json; using LootDumpProcessor.Serializers.Json;
namespace LootDumpProcessor.Process.Impl; namespace LootDumpProcessor.Process.Writer;
public class FileWriter : IWriter public class FileWriter : IWriter
{ {
private static readonly IJsonSerializer _jsonSerializer = JsonSerializerFactory.GetInstance(); private static readonly IJsonSerializer _jsonSerializer = JsonSerializerFactory.GetInstance();
private static string _outputPath; private static readonly string _outputPath;
static FileWriter() static FileWriter()
{ {
@ -47,9 +47,9 @@ public class FileWriter : IWriter
{ {
foreach (var s in LootDumpProcessorContext.GetDirectoryMappings()[key].Name) foreach (var s in LootDumpProcessorContext.GetDirectoryMappings()[key].Name)
{ {
if (!Directory.Exists($"{_outputPath}\\locations\\{s}")) if (!Directory.Exists($@"{_outputPath}\locations\{s}"))
Directory.CreateDirectory($"{_outputPath}\\locations\\{s}"); Directory.CreateDirectory($@"{_outputPath}\locations\{s}");
File.WriteAllText($"{_outputPath}\\locations\\{s}\\looseLoot.json", File.WriteAllText($@"{_outputPath}\locations\{s}\looseLoot.json",
_jsonSerializer.Serialize(value)); _jsonSerializer.Serialize(value));
} }
} }
@ -57,17 +57,17 @@ public class FileWriter : IWriter
break; break;
case OutputFileType.StaticContainer: case OutputFileType.StaticContainer:
var staticContainer = (Dictionary<string, MapStaticLoot>)data; var staticContainer = (Dictionary<string, MapStaticLoot>)data;
File.WriteAllText($"{_outputPath}\\loot\\staticContainers.json", File.WriteAllText($@"{_outputPath}\loot\staticContainers.json",
_jsonSerializer.Serialize(staticContainer)); _jsonSerializer.Serialize(staticContainer));
break; break;
case OutputFileType.StaticLoot: case OutputFileType.StaticLoot:
var staticLoot = (Dictionary<string, StaticItemDistribution>)data; var staticLoot = (Dictionary<string, StaticItemDistribution>)data;
File.WriteAllText($"{_outputPath}\\loot\\staticLoot.json", File.WriteAllText($@"{_outputPath}\loot\staticLoot.json",
_jsonSerializer.Serialize(staticLoot)); _jsonSerializer.Serialize(staticLoot));
break; break;
case OutputFileType.StaticAmmo: case OutputFileType.StaticAmmo:
var staticAmmo = (Dictionary<string, List<AmmoDistribution>>)data; var staticAmmo = (Dictionary<string, List<AmmoDistribution>>)data;
File.WriteAllText($"{_outputPath}\\loot\\staticAmmo.json", File.WriteAllText($@"{_outputPath}\loot\staticAmmo.json",
_jsonSerializer.Serialize(staticAmmo)); _jsonSerializer.Serialize(staticAmmo));
break; break;
default: default:

View File

@ -1,4 +1,4 @@
namespace LootDumpProcessor.Process; namespace LootDumpProcessor.Process.Writer;
public interface IWriter public interface IWriter
{ {

View File

@ -1,6 +1,4 @@
using LootDumpProcessor.Process.Impl; namespace LootDumpProcessor.Process.Writer;
namespace LootDumpProcessor.Process.Writer;
public static class WriterFactory public static class WriterFactory
{ {

View File

@ -4,9 +4,9 @@ using LootDumpProcessor.Storage;
namespace LootDumpProcessor; namespace LootDumpProcessor;
public class Program public static class Program
{ {
public static void Main(String[] args) public static void Main()
{ {
// Bootstrap the config before anything else, its required by the whole application to work // Bootstrap the config before anything else, its required by the whole application to work
LootDumpProcessorContext.GetConfig(); LootDumpProcessorContext.GetConfig();

View File

@ -3,5 +3,5 @@
public interface ISerializer public interface ISerializer
{ {
string Serialize<T>(T obj); string Serialize<T>(T obj);
T Deserialize<T>(string obj); T? Deserialize<T>(string obj);
} }

View File

@ -6,17 +6,18 @@ namespace LootDumpProcessor.Serializers.Json.Converters;
public class NetDateTimeConverter : JsonConverter<DateTime> public class NetDateTimeConverter : JsonConverter<DateTime>
{ {
private static string _dateTimeFormat = "yyyy-MM-dd HH:mm:ss"; private const string DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{ {
var stringDate = reader.GetString() ?? ""; var stringDate = reader.GetString() ?? "";
if (!DateTime.TryParseExact(stringDate, _dateTimeFormat, null, DateTimeStyles.None, out var parsedDate)) if (!DateTime.TryParseExact(stringDate, DateTimeFormat, null, DateTimeStyles.None, out var parsedDate))
throw new Exception($"Invalid value for DateTime format: {_dateTimeFormat}"); throw new Exception($"Invalid value for DateTime format: {DateTimeFormat}");
return parsedDate; return parsedDate;
} }
public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options) public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
{ {
writer.WriteStringValue(value.ToString(_dateTimeFormat)); writer.WriteStringValue(value.ToString(DateTimeFormat));
} }
} }

View File

@ -31,18 +31,12 @@ public class NetJsonKeyConverter : JsonConverter<IKey?>
throw new Exception("Key serializedKey was missing from json definition"); throw new Exception("Key serializedKey was missing from json definition");
} }
AbstractKey key; AbstractKey key = Enum.Parse<KeyType>(type) switch
switch (Enum.Parse<KeyType>(type))
{ {
case KeyType.Subdivisioned: KeyType.Subdivisioned => new SubdivisionedUniqueKey(serializedKey.Split("|")),
key = new SubdivisionedUniqueKey(serializedKey.Split("|")); KeyType.Unique => new FlatUniqueKey(serializedKey.Split("|")),
break; _ => throw new Exception("Unknown key type used!")
case KeyType.Unique: };
key = new FlatUniqueKey(serializedKey.Split("|"));
break;
default:
throw new Exception("Unknown key type used!");
}
return key; return key;
} }

View File

@ -5,11 +5,11 @@ namespace LootDumpProcessor.Serializers.Json.Converters;
public class NewtonsoftDateTimeConverter : JsonConverter<DateTime> public class NewtonsoftDateTimeConverter : JsonConverter<DateTime>
{ {
private static string _dateTimeFormat = "yyyy-MM-dd HH:mm:ss"; private const string DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
public override void WriteJson(JsonWriter writer, DateTime value, JsonSerializer serializer) public override void WriteJson(JsonWriter writer, DateTime value, JsonSerializer serializer)
{ {
writer.WriteValue(value.ToString(_dateTimeFormat)); writer.WriteValue(value.ToString(DateTimeFormat));
} }
public override DateTime ReadJson( public override DateTime ReadJson(
@ -21,8 +21,8 @@ public class NewtonsoftDateTimeConverter : JsonConverter<DateTime>
) )
{ {
var stringDate = reader.Value?.ToString() ?? ""; var stringDate = reader.Value?.ToString() ?? "";
if (!DateTime.TryParseExact(stringDate, _dateTimeFormat, null, DateTimeStyles.None, out var parsedDate)) if (!DateTime.TryParseExact(stringDate, DateTimeFormat, null, DateTimeStyles.None, out var parsedDate))
throw new Exception($"Invalid value for DateTime format: {_dateTimeFormat}"); throw new Exception($"Invalid value for DateTime format: {DateTimeFormat}");
return parsedDate; return parsedDate;
} }
} }

View File

@ -53,18 +53,12 @@ public class NewtonsoftJsonKeyConverter : JsonConverter<AbstractKey>
throw new Exception("Key serializedKey was missing from json definition"); throw new Exception("Key serializedKey was missing from json definition");
} }
AbstractKey key; AbstractKey key = Enum.Parse<KeyType>(type) switch
switch (Enum.Parse<KeyType>(type))
{ {
case KeyType.Subdivisioned: KeyType.Subdivisioned => new SubdivisionedUniqueKey(serializedKey.Split("|")),
key = new SubdivisionedUniqueKey(serializedKey.Split("|")); KeyType.Unique => new FlatUniqueKey(serializedKey.Split("|")),
break; _ => throw new Exception("Unknown key type used!")
case KeyType.Unique: };
key = new FlatUniqueKey(serializedKey.Split("|"));
break;
default:
throw new Exception("Unknown key type used!");
}
return key; return key;
} }

View File

@ -2,10 +2,8 @@
public static class JsonSerializerFactory public static class JsonSerializerFactory
{ {
private static readonly Dictionary<JsonSerializerTypes, IJsonSerializer> _jsonSerializers = private static readonly Dictionary<JsonSerializerTypes, IJsonSerializer> _jsonSerializers = new();
new Dictionary<JsonSerializerTypes, IJsonSerializer>(); private static object lockObject = new();
private static object lockObject = new object();
/** /**
* Requires LootDumpProcessorContext to be initialized before using * Requires LootDumpProcessorContext to be initialized before using
@ -22,17 +20,12 @@ public static class JsonSerializerFactory
{ {
if (!_jsonSerializers.TryGetValue(type, out serializer)) if (!_jsonSerializers.TryGetValue(type, out serializer))
{ {
switch (type) serializer = type switch
{ {
case JsonSerializerTypes.Newtonsoft: JsonSerializerTypes.Newtonsoft => new NewtonsoftJsonSerializer(),
serializer = new NewtonsoftJsonSerializer(); JsonSerializerTypes.DotNet => new NetJsonSerializer(),
break; _ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
case JsonSerializerTypes.DotNet: };
serializer = new NetJsonSerializer();
break;
default:
throw new ArgumentOutOfRangeException(nameof(type), type, null);
}
_jsonSerializers.Add(type, serializer); _jsonSerializers.Add(type, serializer);
} }

View File

@ -22,7 +22,7 @@ public class NetJsonSerializer : IJsonSerializer
return JsonSerializer.Serialize(obj, _serializeOptions); return JsonSerializer.Serialize(obj, _serializeOptions);
} }
public T Deserialize<T>(string obj) public T? Deserialize<T>(string obj)
{ {
return JsonSerializer.Deserialize<T>(obj, _serializeOptions); return JsonSerializer.Deserialize<T>(obj, _serializeOptions);
} }

View File

@ -6,7 +6,7 @@ namespace LootDumpProcessor.Serializers.Json;
public class NewtonsoftJsonSerializer : IJsonSerializer public class NewtonsoftJsonSerializer : IJsonSerializer
{ {
private static readonly JsonSerializerSettings _settings = new JsonSerializerSettings private static readonly JsonSerializerSettings _settings = new()
{ {
Converters = Converters =
{ {
@ -21,7 +21,7 @@ public class NewtonsoftJsonSerializer : IJsonSerializer
return JsonConvert.SerializeObject(obj, _settings); return JsonConvert.SerializeObject(obj, _settings);
} }
public T Deserialize<T>(string obj) public T? Deserialize<T>(string obj)
{ {
return JsonConvert.DeserializeObject<T>(obj, _settings); return JsonConvert.DeserializeObject<T>(obj, _settings);
} }

View File

@ -3,27 +3,20 @@ using Newtonsoft.Json;
namespace LootDumpProcessor.Storage; namespace LootDumpProcessor.Storage;
public abstract class AbstractKey : IKey public abstract class AbstractKey(string[] indexes) : IKey
{ {
public abstract KeyType GetKeyType(); public abstract KeyType GetKeyType();
private string[] indexes;
[JsonProperty("serializedKey")] [JsonProperty("serializedKey")]
[JsonPropertyName("serializedKey")] [JsonPropertyName("serializedKey")]
public string SerializedKey public string SerializedKey
{ {
get { return string.Join("|", this.indexes); } get => string.Join("|", indexes);
set { indexes = value.Split("|"); } set => indexes = value.Split("|");
}
public AbstractKey(string[] indexes)
{
this.indexes = indexes;
} }
public string[] GetLookupIndex() public string[] GetLookupIndex()
{ {
return this.indexes; return indexes;
} }
} }

View File

@ -1,14 +1,13 @@
using LootDumpProcessor.Storage.Implementations; using LootDumpProcessor.Storage.Implementations.File;
using LootDumpProcessor.Storage.Implementations.Memory; using LootDumpProcessor.Storage.Implementations.Memory;
namespace LootDumpProcessor.Storage; namespace LootDumpProcessor.Storage;
public static class DataStorageFactory public static class DataStorageFactory
{ {
private static readonly Dictionary<DataStorageTypes, IDataStorage> _dataStorage = private static readonly Dictionary<DataStorageTypes, IDataStorage> _dataStorage = new();
new Dictionary<DataStorageTypes, IDataStorage>();
private static object lockObject = new object(); private static object lockObject = new();
/** /**
* Requires LootDumpProcessorContext to be initialized before using * Requires LootDumpProcessorContext to be initialized before using
@ -25,17 +24,12 @@ public static class DataStorageFactory
{ {
if (!_dataStorage.TryGetValue(type, out dataStorage)) if (!_dataStorage.TryGetValue(type, out dataStorage))
{ {
switch (type) dataStorage = type switch
{ {
case DataStorageTypes.File: DataStorageTypes.File => new FileDataStorage(),
dataStorage = new FileDataStorage(); DataStorageTypes.Memory => new MemoryDataStorage(),
break; _ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
case DataStorageTypes.Memory: };
dataStorage = new MemoryDataStorage();
break;
default:
throw new ArgumentOutOfRangeException(nameof(type), type, null);
}
_dataStorage.Add(type, dataStorage); _dataStorage.Add(type, dataStorage);
} }

View File

@ -1,10 +1,6 @@
namespace LootDumpProcessor.Storage; namespace LootDumpProcessor.Storage;
public class FlatUniqueKey : AbstractKey public class FlatUniqueKey(string[] indexes) : AbstractKey(indexes)
{ {
public override KeyType GetKeyType() => KeyType.Unique; public override KeyType GetKeyType() => KeyType.Unique;
public FlatUniqueKey(string[] indexes) : base(indexes)
{
}
} }

View File

@ -1,4 +1,4 @@
namespace LootDumpProcessor.Storage.Implementations; namespace LootDumpProcessor.Storage.Implementations.File;
public class FileDataStorage : IDataStorage public class FileDataStorage : IDataStorage
{ {

View File

@ -1,42 +1,37 @@
using LootDumpProcessor.Storage.Implementations.Serializers; using LootDumpProcessor.Storage.Implementations.File.Serializers;
namespace LootDumpProcessor.Storage.Implementations.Handlers; namespace LootDumpProcessor.Storage.Implementations.File.Handlers;
public abstract class AbstractStoreHandler : IStoreHandler public abstract class AbstractStoreHandler : IStoreHandler
{ {
protected readonly IDataStorageFileSerializer _serializer; protected readonly IDataStorageFileSerializer _serializer = DataStorageFileSerializerFactory.GetInstance();
public AbstractStoreHandler()
{
_serializer = DataStorageFileSerializerFactory.GetInstance();
}
public void Store<T>(T obj, bool failIfDuplicate = true) where T : IKeyable public void Store<T>(T obj, bool failIfDuplicate = true) where T : IKeyable
{ {
var locationWithFile = GetLocation(obj.GetKey()); var locationWithFile = GetLocation(obj.GetKey());
if (File.Exists(locationWithFile) && failIfDuplicate) if (System.IO.File.Exists(locationWithFile) && failIfDuplicate)
{ {
throw new Exception($"Attempted to save duplicated object into data storage: {locationWithFile}"); throw new Exception($"Attempted to save duplicated object into data storage: {locationWithFile}");
} }
File.WriteAllText(locationWithFile, _serializer.GetSerializer().Serialize(obj)); System.IO.File.WriteAllText(locationWithFile, _serializer.GetSerializer().Serialize(obj));
} }
public T? Retrieve<T>(IKey obj) where T : IKeyable public T? Retrieve<T>(IKey obj) where T : IKeyable
{ {
var locationWithFile = GetLocation(obj); var locationWithFile = GetLocation(obj);
if (!File.Exists(locationWithFile)) if (!System.IO.File.Exists(locationWithFile))
{ {
return default; return default;
} }
return _serializer.GetSerializer().Deserialize<T>(File.ReadAllText(locationWithFile)); return _serializer.GetSerializer().Deserialize<T>(System.IO.File.ReadAllText(locationWithFile));
} }
public bool Exists(IKey obj) public bool Exists(IKey obj)
{ {
var locationWithFile = GetLocation(obj); var locationWithFile = GetLocation(obj);
return File.Exists(locationWithFile); return System.IO.File.Exists(locationWithFile);
} }
public abstract List<T> RetrieveAll<T>() where T : IKeyable; public abstract List<T> RetrieveAll<T>() where T : IKeyable;

View File

@ -1,4 +1,4 @@
namespace LootDumpProcessor.Storage.Implementations.Handlers; namespace LootDumpProcessor.Storage.Implementations.File.Handlers;
public class FlatStoreHandler : AbstractStoreHandler public class FlatStoreHandler : AbstractStoreHandler
{ {

View File

@ -1,4 +1,4 @@
namespace LootDumpProcessor.Storage.Implementations.Handlers; namespace LootDumpProcessor.Storage.Implementations.File.Handlers;
public class SubdivisionedStoreHandler : AbstractStoreHandler public class SubdivisionedStoreHandler : AbstractStoreHandler
{ {

View File

@ -1,4 +1,4 @@
namespace LootDumpProcessor.Storage.Implementations; namespace LootDumpProcessor.Storage.Implementations.File;
public interface IStoreHandler public interface IStoreHandler
{ {

View File

@ -1,4 +1,4 @@
namespace LootDumpProcessor.Storage.Implementations.Serializers; namespace LootDumpProcessor.Storage.Implementations.File.Serializers;
public static class DataStorageFileSerializerFactory public static class DataStorageFileSerializerFactory
{ {

View File

@ -1,6 +1,6 @@
using LootDumpProcessor.Serializers; using LootDumpProcessor.Serializers;
namespace LootDumpProcessor.Storage.Implementations.Serializers; namespace LootDumpProcessor.Storage.Implementations.File.Serializers;
public interface IDataStorageFileSerializer public interface IDataStorageFileSerializer
{ {

View File

@ -1,7 +1,7 @@
using LootDumpProcessor.Serializers; using LootDumpProcessor.Serializers;
using LootDumpProcessor.Serializers.Json; using LootDumpProcessor.Serializers.Json;
namespace LootDumpProcessor.Storage.Implementations.Serializers; namespace LootDumpProcessor.Storage.Implementations.File.Serializers;
public class JsonDataStorageFileSerializer : IDataStorageFileSerializer public class JsonDataStorageFileSerializer : IDataStorageFileSerializer
{ {

View File

@ -1,7 +1,7 @@
using LootDumpProcessor.Serializers; using LootDumpProcessor.Serializers;
using LootDumpProcessor.Serializers.Yaml; using LootDumpProcessor.Serializers.Yaml;
namespace LootDumpProcessor.Storage.Implementations.Serializers; namespace LootDumpProcessor.Storage.Implementations.File.Serializers;
public class YamlDataStorageFileSerializer : IDataStorageFileSerializer public class YamlDataStorageFileSerializer : IDataStorageFileSerializer
{ {

View File

@ -1,11 +1,11 @@
using LootDumpProcessor.Storage.Implementations.Handlers; using LootDumpProcessor.Storage.Implementations.File.Handlers;
namespace LootDumpProcessor.Storage.Implementations; namespace LootDumpProcessor.Storage.Implementations.File;
public class StoreHandlerFactory public class StoreHandlerFactory
{ {
private static Dictionary<KeyType, IStoreHandler> _handlers = new Dictionary<KeyType, IStoreHandler>(); private static Dictionary<KeyType, IStoreHandler> _handlers = new();
private static object lockObject = new object(); private static object lockObject = new();
public static IStoreHandler GetInstance(KeyType type) public static IStoreHandler GetInstance(KeyType type)
{ {

View File

@ -2,8 +2,8 @@
public class MemoryDataStorage : IDataStorage public class MemoryDataStorage : IDataStorage
{ {
private static readonly Dictionary<string, object> CachedObjects = new Dictionary<string, object>(); private static readonly Dictionary<string, object> CachedObjects = new();
private static readonly object _cacheObjectLock = new object(); private static readonly object _cacheObjectLock = new();
public void Setup() public void Setup()
{ {

View File

@ -1,10 +1,6 @@
namespace LootDumpProcessor.Storage; namespace LootDumpProcessor.Storage;
public class SubdivisionedUniqueKey : AbstractKey public class SubdivisionedUniqueKey(string[] indexes) : AbstractKey(indexes)
{ {
public override KeyType GetKeyType() => KeyType.Subdivisioned; public override KeyType GetKeyType() => KeyType.Subdivisioned;
public SubdivisionedUniqueKey(string[] indexes) : base(indexes)
{
}
} }

View File

@ -1,6 +1,6 @@
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace LootDumpProcessor.Process.Processor; namespace LootDumpProcessor.Utils;
public static class FileDateParser public static class FileDateParser
{ {

View File

@ -1,16 +1,11 @@
using System.Collections.ObjectModel; using System.Security.Cryptography;
using System.Security.Cryptography;
using System.Text; using System.Text;
using LootDumpProcessor.Model; using LootDumpProcessor.Model;
using LootDumpProcessor.Serializers;
using LootDumpProcessor.Serializers.Json;
namespace LootDumpProcessor.Process.Processor; namespace LootDumpProcessor.Utils;
public static class ProcessorUtil public static class ProcessorUtil
{ {
private static readonly ISerializer Serializer = JsonSerializerFactory.GetInstance();
public static string GetSaneId(this Template x) public static string GetSaneId(this Template x)
{ {
return $"({x.Position.X}, {x.Position.Y}, {x.Position.Z}, {Math.Round(x.Rotation.X ?? 0, 3)}," + return $"({x.Position.X}, {x.Position.Y}, {x.Position.Z}, {Math.Round(x.Rotation.X ?? 0, 3)}," +
@ -32,9 +27,7 @@ public static class ProcessorUtil
public static List<T>? Copy<T>(List<T>? obj) where T : ICloneable public static List<T>? Copy<T>(List<T>? obj) where T : ICloneable
{ {
if (obj == null) return obj?.Select(o => o.Clone()).Cast<T>().ToList();
return null;
return obj.Select(o => o.Clone()).Cast<T>().ToList();
} }
public static string HashFile(string text) public static string HashFile(string text)