First pass cleanup and code conversion to net8.0
This commit is contained in:
parent
f95664961d
commit
59c0de7702
@ -1,6 +1,6 @@
|
||||
namespace LootDumpProcessor;
|
||||
|
||||
public class GCHandler
|
||||
public static class GCHandler
|
||||
{
|
||||
public static void Collect()
|
||||
{
|
||||
|
@ -4,12 +4,12 @@ namespace LootDumpProcessor.Logger;
|
||||
|
||||
public class QueueLogger : ILogger
|
||||
{
|
||||
private BlockingCollection<LoggedMessage> queuedMessages = new BlockingCollection<LoggedMessage>();
|
||||
private readonly BlockingCollection<LoggedMessage> 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; }
|
||||
|
@ -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<string, MapDirectoryMapping>? _mapDirectoryMappings;
|
||||
private static readonly object _mapDirectoryMappingsLock = new object();
|
||||
private static readonly object _mapDirectoryMappingsLock = new();
|
||||
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 readonly object _forcedItemsLock = new object();
|
||||
private static readonly object _forcedItemsLock = new();
|
||||
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 readonly object _tarkovItemsLock = new object();
|
||||
private static readonly object _tarkovItemsLock = new();
|
||||
|
||||
public static Config GetConfig()
|
||||
{
|
||||
|
@ -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();
|
||||
|
@ -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<string> IgnoredDumpLocations { get; set; } = new List<string>();
|
||||
public List<string> IgnoredDumpLocations { get; set; } = new();
|
||||
}
|
@ -24,7 +24,7 @@ public class ReaderConfig
|
||||
|
||||
[JsonProperty("acceptedFileExtensions")]
|
||||
[JsonPropertyName("acceptedFileExtensions")]
|
||||
public List<string> AcceptedFileExtensions { get; set; } = new List<string>();
|
||||
public List<string> AcceptedFileExtensions { get; set; } = new();
|
||||
|
||||
[JsonProperty("processSubFolders")]
|
||||
[JsonPropertyName("processSubFolders")]
|
||||
|
@ -13,7 +13,7 @@ namespace LootDumpProcessor.Model
|
||||
{
|
||||
return new FireMode
|
||||
{
|
||||
FireModeType = this.FireModeType
|
||||
FireModeType = FireModeType
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ namespace LootDumpProcessor.Model
|
||||
{
|
||||
return new Foldable
|
||||
{
|
||||
Folded = this.Folded
|
||||
Folded = Folded
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -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<PreProcessedStaticLoot> 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()
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -17,8 +17,8 @@ namespace LootDumpProcessor.Model
|
||||
{
|
||||
return new Repairable
|
||||
{
|
||||
Durability = this.Durability,
|
||||
MaxDurability = this.MaxDurability
|
||||
Durability = Durability,
|
||||
MaxDurability = MaxDurability
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -4,9 +4,9 @@ namespace LootDumpProcessor.Process.Collector;
|
||||
|
||||
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()
|
||||
|
@ -1,5 +1,4 @@
|
||||
using LootDumpProcessor.Model.Config;
|
||||
using LootDumpProcessor.Model.Processing;
|
||||
using LootDumpProcessor.Model.Processing;
|
||||
|
||||
namespace LootDumpProcessor.Process.Collector;
|
||||
|
||||
|
@ -1,6 +0,0 @@
|
||||
namespace LootDumpProcessor.Process;
|
||||
|
||||
public class FilesGatherer
|
||||
{
|
||||
|
||||
}
|
@ -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;
|
||||
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -1,6 +1,4 @@
|
||||
using LootDumpProcessor.Process.Impl;
|
||||
|
||||
namespace LootDumpProcessor.Process.Processor;
|
||||
namespace LootDumpProcessor.Process.Processor.FileProcessor;
|
||||
|
||||
public static class FileProcessorFactory
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
using LootDumpProcessor.Model.Processing;
|
||||
|
||||
namespace LootDumpProcessor.Process;
|
||||
namespace LootDumpProcessor.Process.Processor.FileProcessor;
|
||||
|
||||
public interface IFileProcessor
|
||||
{
|
||||
|
@ -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<Template> looseloot)
|
||||
{
|
||||
|
@ -3,10 +3,11 @@ using LootDumpProcessor.Model.Input;
|
||||
using LootDumpProcessor.Model.Output;
|
||||
using LootDumpProcessor.Model.Output.StaticContainer;
|
||||
using LootDumpProcessor.Model.Processing;
|
||||
using LootDumpProcessor.Utils;
|
||||
|
||||
namespace LootDumpProcessor.Process.Processor;
|
||||
|
||||
public class StaticLootProcessor
|
||||
public static class StaticLootProcessor
|
||||
{
|
||||
public static List<PreProcessedStaticLoot> PreProcessStaticLoot(List<Template> staticloot)
|
||||
{
|
||||
@ -30,7 +31,6 @@ public class StaticLootProcessor
|
||||
|
||||
public static Tuple<string, MapStaticLoot> CreateRealStaticContainers(RootData rawMapDump)
|
||||
{
|
||||
List<StaticForced> forcedStaticItems;
|
||||
var mapName = rawMapDump.Data.Name;
|
||||
var staticLootPositions = (from li in rawMapDump.Data.Loot
|
||||
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]
|
||||
: new List<StaticForced>();
|
||||
|
||||
@ -145,15 +145,12 @@ public class StaticLootProcessor
|
||||
var itemsHitCounts = new Dictionary<string, int>();
|
||||
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;
|
||||
else
|
||||
itemsHitCounts[cii.Tpl] = 1;
|
||||
}
|
||||
if (itemsHitCounts.ContainsKey(cii.Tpl))
|
||||
itemsHitCounts[cii.Tpl] += 1;
|
||||
else
|
||||
itemsHitCounts[cii.Tpl] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,10 +3,13 @@ using LootDumpProcessor.Logger;
|
||||
using LootDumpProcessor.Process.Collector;
|
||||
using LootDumpProcessor.Process.Processor;
|
||||
using LootDumpProcessor.Process.Processor.DumpProcessor;
|
||||
using LootDumpProcessor.Process.Processor.FileProcessor;
|
||||
using LootDumpProcessor.Process.Reader;
|
||||
using LootDumpProcessor.Process.Reader.Filters;
|
||||
using LootDumpProcessor.Process.Reader.Intake;
|
||||
using LootDumpProcessor.Process.Reader.PreProcess;
|
||||
using LootDumpProcessor.Process.Writer;
|
||||
using LootDumpProcessor.Utils;
|
||||
|
||||
namespace LootDumpProcessor.Process;
|
||||
|
||||
|
@ -6,8 +6,8 @@ namespace LootDumpProcessor.Process.Reader.Filters;
|
||||
|
||||
public class JsonDumpFileFilter : IFileFilter
|
||||
{
|
||||
private static Regex FileNameDateRegex = new("([0-9]{4}(-[0-9]{2}){2}_((-){0,1}[0-9]{2}){3})");
|
||||
private static DateTime parsedThresholdDate;
|
||||
private static readonly Regex _fileNameDateRegex = new("([0-9]{4}(-[0-9]{2}){2}_((-){0,1}[0-9]{2}){3})");
|
||||
private static readonly DateTime _parsedThresholdDate;
|
||||
|
||||
static JsonDumpFileFilter()
|
||||
{
|
||||
@ -17,11 +17,11 @@ public class JsonDumpFileFilter : IFileFilter
|
||||
LoggerFactory.GetInstance()
|
||||
.Log($"ThresholdDate is null or empty in configs, defaulting to current day minus 30 days",
|
||||
LogLevel.Warning);
|
||||
parsedThresholdDate = (DateTime.Now - TimeSpan.FromDays(30));
|
||||
_parsedThresholdDate = (DateTime.Now - TimeSpan.FromDays(30));
|
||||
}
|
||||
else
|
||||
{
|
||||
parsedThresholdDate = DateTime.ParseExact(
|
||||
_parsedThresholdDate = DateTime.ParseExact(
|
||||
LootDumpProcessorContext.GetConfig().ReaderConfig.ThresholdDate,
|
||||
"yyyy-MM-dd",
|
||||
CultureInfo.InvariantCulture
|
||||
@ -33,8 +33,8 @@ public class JsonDumpFileFilter : IFileFilter
|
||||
|
||||
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);
|
||||
return date > parsedThresholdDate;
|
||||
return date > _parsedThresholdDate;
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
using LootDumpProcessor.Model.Processing;
|
||||
|
||||
namespace LootDumpProcessor.Process;
|
||||
namespace LootDumpProcessor.Process.Reader.Intake;
|
||||
|
||||
public interface IIntakeReader
|
||||
{
|
||||
|
@ -1,12 +1,10 @@
|
||||
using LootDumpProcessor.Process.Impl;
|
||||
|
||||
namespace LootDumpProcessor.Process.Reader;
|
||||
namespace LootDumpProcessor.Process.Reader.Intake;
|
||||
|
||||
public static class IntakeReaderFactory
|
||||
{
|
||||
public static IIntakeReader GetInstance()
|
||||
{
|
||||
return LootDumpProcessorContext.GetConfig().ReaderConfig.IntakeReaderConfig.IntakeReaderType switch
|
||||
return (LootDumpProcessorContext.GetConfig().ReaderConfig.IntakeReaderConfig?.IntakeReaderType ?? IntakeReaderTypes.Json) switch
|
||||
{
|
||||
IntakeReaderTypes.Json => new JsonFileIntakeReader(),
|
||||
_ => throw new ArgumentOutOfRangeException(
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace LootDumpProcessor.Process.Reader;
|
||||
namespace LootDumpProcessor.Process.Reader.Intake;
|
||||
|
||||
public enum IntakeReaderTypes
|
||||
{
|
||||
|
@ -2,10 +2,10 @@
|
||||
using LootDumpProcessor.Logger;
|
||||
using LootDumpProcessor.Model.Input;
|
||||
using LootDumpProcessor.Model.Processing;
|
||||
using LootDumpProcessor.Process.Processor;
|
||||
using LootDumpProcessor.Serializers.Json;
|
||||
using LootDumpProcessor.Utils;
|
||||
|
||||
namespace LootDumpProcessor.Process.Impl;
|
||||
namespace LootDumpProcessor.Process.Reader.Intake;
|
||||
|
||||
public class JsonFileIntakeReader : IIntakeReader
|
||||
{
|
||||
@ -26,14 +26,13 @@ public class JsonFileIntakeReader : IIntakeReader
|
||||
var fi = _jsonSerializer.Deserialize<RootData>(fileData);
|
||||
if (fi.Data?.Name != null && (!_ignoredLocations?.Contains(fi.Data.Name) ?? true))
|
||||
{
|
||||
int counter;
|
||||
if (!_totalMapDumpsCounter.TryGetValue(fi.Data.Name, out counter))
|
||||
if (!_totalMapDumpsCounter.TryGetValue(fi.Data.Name, out var counter))
|
||||
{
|
||||
counter = 0;
|
||||
_totalMapDumpsCounter[fi.Data.Name] = counter;
|
||||
}
|
||||
|
||||
if (counter < LootDumpProcessorContext.GetConfig().ReaderConfig.IntakeReaderConfig.MaxDumpsPerMap)
|
||||
if (counter < (LootDumpProcessorContext.GetConfig().ReaderConfig.IntakeReaderConfig?.MaxDumpsPerMap ?? 1500))
|
||||
{
|
||||
basicInfo = new BasicInfo
|
||||
{
|
||||
|
@ -4,7 +4,7 @@ namespace LootDumpProcessor.Process.Reader.PreProcess;
|
||||
|
||||
public abstract class AbstractPreProcessReader : IPreProcessReader
|
||||
{
|
||||
protected string _tempFolder;
|
||||
protected readonly string _tempFolder;
|
||||
|
||||
public AbstractPreProcessReader()
|
||||
{
|
||||
@ -35,7 +35,7 @@ public abstract class AbstractPreProcessReader : IPreProcessReader
|
||||
|
||||
protected string GetBaseDirectory()
|
||||
{
|
||||
return $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}\\SPT\\tmp\\PreProcessor";
|
||||
return $@"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}\SPT\tmp\PreProcessor";
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
@ -3,7 +3,6 @@
|
||||
public static class PreProcessReaderFactory
|
||||
{
|
||||
private static readonly Dictionary<PreProcessReaderTypes, IPreProcessReader> _proProcessReaders = new();
|
||||
private static object lockObject = new object();
|
||||
|
||||
public static IPreProcessReader GetInstance(PreProcessReaderTypes type)
|
||||
{
|
||||
|
@ -15,8 +15,6 @@ public class SevenZipPreProcessReader : AbstractPreProcessReader
|
||||
|
||||
public override bool TryPreProcess(string file, out List<string> files, out List<string> directories)
|
||||
{
|
||||
Decoder decoder = new Decoder();
|
||||
|
||||
var fileRaw = Path.GetFileNameWithoutExtension(file);
|
||||
// SevenZip library doesnt like forward slashes for some reason
|
||||
var outPath = $"{_tempFolder}\\{fileRaw}".Replace("/", "\\");
|
||||
@ -24,7 +22,7 @@ public class SevenZipPreProcessReader : AbstractPreProcessReader
|
||||
$"Unzipping {file} into temp path {outPath}, this may take a while...",
|
||||
LogLevel.Info);
|
||||
var extractor = new SevenZipExtractor(file);
|
||||
extractor.Extracting += (sender, args) =>
|
||||
extractor.Extracting += (_, args) =>
|
||||
{
|
||||
if (args.PercentDone % 10 == 0)
|
||||
LoggerFactory.GetInstance().Log($"Unzip progress: {args.PercentDone}%", LogLevel.Info);
|
||||
|
@ -4,19 +4,16 @@ using LootDumpProcessor.Serializers.Json;
|
||||
|
||||
namespace LootDumpProcessor.Process;
|
||||
|
||||
public class TarkovItems
|
||||
public class TarkovItems(string items)
|
||||
{
|
||||
private static readonly IJsonSerializer _jsonSerializer = JsonSerializerFactory.GetInstance();
|
||||
|
||||
private Dictionary<string, TemplateFileItem> _items;
|
||||
|
||||
public TarkovItems(string items)
|
||||
{
|
||||
_items = _jsonSerializer.Deserialize<Dictionary<string, TemplateFileItem>>(File.ReadAllText(items));
|
||||
}
|
||||
private readonly Dictionary<string, TemplateFileItem>? _items = _jsonSerializer.Deserialize<Dictionary<string, TemplateFileItem>>(File.ReadAllText(items));
|
||||
|
||||
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))
|
||||
{
|
||||
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)
|
||||
{
|
||||
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))
|
||||
{
|
||||
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)
|
||||
{
|
||||
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))
|
||||
{
|
||||
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)
|
||||
{
|
||||
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))
|
||||
{
|
||||
LoggerFactory.GetInstance().Log($"[AmmoCaliber] Item template '{tpl}' was not found on the server items!", LogLevel.Error);
|
||||
|
@ -3,12 +3,12 @@ using LootDumpProcessor.Model.Output.LooseLoot;
|
||||
using LootDumpProcessor.Model.Output.StaticContainer;
|
||||
using LootDumpProcessor.Serializers.Json;
|
||||
|
||||
namespace LootDumpProcessor.Process.Impl;
|
||||
namespace LootDumpProcessor.Process.Writer;
|
||||
|
||||
public class FileWriter : IWriter
|
||||
{
|
||||
private static readonly IJsonSerializer _jsonSerializer = JsonSerializerFactory.GetInstance();
|
||||
private static string _outputPath;
|
||||
private static readonly string _outputPath;
|
||||
|
||||
static FileWriter()
|
||||
{
|
||||
@ -47,9 +47,9 @@ public class FileWriter : IWriter
|
||||
{
|
||||
foreach (var s in LootDumpProcessorContext.GetDirectoryMappings()[key].Name)
|
||||
{
|
||||
if (!Directory.Exists($"{_outputPath}\\locations\\{s}"))
|
||||
Directory.CreateDirectory($"{_outputPath}\\locations\\{s}");
|
||||
File.WriteAllText($"{_outputPath}\\locations\\{s}\\looseLoot.json",
|
||||
if (!Directory.Exists($@"{_outputPath}\locations\{s}"))
|
||||
Directory.CreateDirectory($@"{_outputPath}\locations\{s}");
|
||||
File.WriteAllText($@"{_outputPath}\locations\{s}\looseLoot.json",
|
||||
_jsonSerializer.Serialize(value));
|
||||
}
|
||||
}
|
||||
@ -57,17 +57,17 @@ public class FileWriter : IWriter
|
||||
break;
|
||||
case OutputFileType.StaticContainer:
|
||||
var staticContainer = (Dictionary<string, MapStaticLoot>)data;
|
||||
File.WriteAllText($"{_outputPath}\\loot\\staticContainers.json",
|
||||
File.WriteAllText($@"{_outputPath}\loot\staticContainers.json",
|
||||
_jsonSerializer.Serialize(staticContainer));
|
||||
break;
|
||||
case OutputFileType.StaticLoot:
|
||||
var staticLoot = (Dictionary<string, StaticItemDistribution>)data;
|
||||
File.WriteAllText($"{_outputPath}\\loot\\staticLoot.json",
|
||||
File.WriteAllText($@"{_outputPath}\loot\staticLoot.json",
|
||||
_jsonSerializer.Serialize(staticLoot));
|
||||
break;
|
||||
case OutputFileType.StaticAmmo:
|
||||
var staticAmmo = (Dictionary<string, List<AmmoDistribution>>)data;
|
||||
File.WriteAllText($"{_outputPath}\\loot\\staticAmmo.json",
|
||||
File.WriteAllText($@"{_outputPath}\loot\staticAmmo.json",
|
||||
_jsonSerializer.Serialize(staticAmmo));
|
||||
break;
|
||||
default:
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace LootDumpProcessor.Process;
|
||||
namespace LootDumpProcessor.Process.Writer;
|
||||
|
||||
public interface IWriter
|
||||
{
|
||||
|
@ -1,6 +1,4 @@
|
||||
using LootDumpProcessor.Process.Impl;
|
||||
|
||||
namespace LootDumpProcessor.Process.Writer;
|
||||
namespace LootDumpProcessor.Process.Writer;
|
||||
|
||||
public static class WriterFactory
|
||||
{
|
||||
|
@ -4,9 +4,9 @@ using LootDumpProcessor.Storage;
|
||||
|
||||
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
|
||||
LootDumpProcessorContext.GetConfig();
|
||||
|
@ -3,5 +3,5 @@
|
||||
public interface ISerializer
|
||||
{
|
||||
string Serialize<T>(T obj);
|
||||
T Deserialize<T>(string obj);
|
||||
T? Deserialize<T>(string obj);
|
||||
}
|
@ -6,17 +6,18 @@ namespace LootDumpProcessor.Serializers.Json.Converters;
|
||||
|
||||
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)
|
||||
{
|
||||
var stringDate = reader.GetString() ?? "";
|
||||
if (!DateTime.TryParseExact(stringDate, _dateTimeFormat, null, DateTimeStyles.None, out var parsedDate))
|
||||
throw new Exception($"Invalid value for DateTime format: {_dateTimeFormat}");
|
||||
if (!DateTime.TryParseExact(stringDate, DateTimeFormat, null, DateTimeStyles.None, out var parsedDate))
|
||||
throw new Exception($"Invalid value for DateTime format: {DateTimeFormat}");
|
||||
return parsedDate;
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStringValue(value.ToString(_dateTimeFormat));
|
||||
writer.WriteStringValue(value.ToString(DateTimeFormat));
|
||||
}
|
||||
}
|
@ -31,18 +31,12 @@ public class NetJsonKeyConverter : JsonConverter<IKey?>
|
||||
throw new Exception("Key serializedKey was missing from json definition");
|
||||
}
|
||||
|
||||
AbstractKey key;
|
||||
switch (Enum.Parse<KeyType>(type))
|
||||
AbstractKey key = Enum.Parse<KeyType>(type) switch
|
||||
{
|
||||
case KeyType.Subdivisioned:
|
||||
key = new SubdivisionedUniqueKey(serializedKey.Split("|"));
|
||||
break;
|
||||
case KeyType.Unique:
|
||||
key = new FlatUniqueKey(serializedKey.Split("|"));
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Unknown key type used!");
|
||||
}
|
||||
KeyType.Subdivisioned => new SubdivisionedUniqueKey(serializedKey.Split("|")),
|
||||
KeyType.Unique => new FlatUniqueKey(serializedKey.Split("|")),
|
||||
_ => throw new Exception("Unknown key type used!")
|
||||
};
|
||||
|
||||
return key;
|
||||
}
|
||||
|
@ -5,11 +5,11 @@ namespace LootDumpProcessor.Serializers.Json.Converters;
|
||||
|
||||
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)
|
||||
{
|
||||
writer.WriteValue(value.ToString(_dateTimeFormat));
|
||||
writer.WriteValue(value.ToString(DateTimeFormat));
|
||||
}
|
||||
|
||||
public override DateTime ReadJson(
|
||||
@ -21,8 +21,8 @@ public class NewtonsoftDateTimeConverter : JsonConverter<DateTime>
|
||||
)
|
||||
{
|
||||
var stringDate = reader.Value?.ToString() ?? "";
|
||||
if (!DateTime.TryParseExact(stringDate, _dateTimeFormat, null, DateTimeStyles.None, out var parsedDate))
|
||||
throw new Exception($"Invalid value for DateTime format: {_dateTimeFormat}");
|
||||
if (!DateTime.TryParseExact(stringDate, DateTimeFormat, null, DateTimeStyles.None, out var parsedDate))
|
||||
throw new Exception($"Invalid value for DateTime format: {DateTimeFormat}");
|
||||
return parsedDate;
|
||||
}
|
||||
}
|
@ -53,18 +53,12 @@ public class NewtonsoftJsonKeyConverter : JsonConverter<AbstractKey>
|
||||
throw new Exception("Key serializedKey was missing from json definition");
|
||||
}
|
||||
|
||||
AbstractKey key;
|
||||
switch (Enum.Parse<KeyType>(type))
|
||||
AbstractKey key = Enum.Parse<KeyType>(type) switch
|
||||
{
|
||||
case KeyType.Subdivisioned:
|
||||
key = new SubdivisionedUniqueKey(serializedKey.Split("|"));
|
||||
break;
|
||||
case KeyType.Unique:
|
||||
key = new FlatUniqueKey(serializedKey.Split("|"));
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Unknown key type used!");
|
||||
}
|
||||
KeyType.Subdivisioned => new SubdivisionedUniqueKey(serializedKey.Split("|")),
|
||||
KeyType.Unique => new FlatUniqueKey(serializedKey.Split("|")),
|
||||
_ => throw new Exception("Unknown key type used!")
|
||||
};
|
||||
|
||||
return key;
|
||||
}
|
||||
|
@ -2,10 +2,8 @@
|
||||
|
||||
public static class JsonSerializerFactory
|
||||
{
|
||||
private static readonly Dictionary<JsonSerializerTypes, IJsonSerializer> _jsonSerializers =
|
||||
new Dictionary<JsonSerializerTypes, IJsonSerializer>();
|
||||
|
||||
private static object lockObject = new object();
|
||||
private static readonly Dictionary<JsonSerializerTypes, IJsonSerializer> _jsonSerializers = new();
|
||||
private static object lockObject = new();
|
||||
|
||||
/**
|
||||
* Requires LootDumpProcessorContext to be initialized before using
|
||||
@ -22,17 +20,12 @@ public static class JsonSerializerFactory
|
||||
{
|
||||
if (!_jsonSerializers.TryGetValue(type, out serializer))
|
||||
{
|
||||
switch (type)
|
||||
serializer = type switch
|
||||
{
|
||||
case JsonSerializerTypes.Newtonsoft:
|
||||
serializer = new NewtonsoftJsonSerializer();
|
||||
break;
|
||||
case JsonSerializerTypes.DotNet:
|
||||
serializer = new NetJsonSerializer();
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(type), type, null);
|
||||
}
|
||||
JsonSerializerTypes.Newtonsoft => new NewtonsoftJsonSerializer(),
|
||||
JsonSerializerTypes.DotNet => new NetJsonSerializer(),
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
|
||||
};
|
||||
|
||||
_jsonSerializers.Add(type, serializer);
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ public class NetJsonSerializer : IJsonSerializer
|
||||
return JsonSerializer.Serialize(obj, _serializeOptions);
|
||||
}
|
||||
|
||||
public T Deserialize<T>(string obj)
|
||||
public T? Deserialize<T>(string obj)
|
||||
{
|
||||
return JsonSerializer.Deserialize<T>(obj, _serializeOptions);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ namespace LootDumpProcessor.Serializers.Json;
|
||||
|
||||
public class NewtonsoftJsonSerializer : IJsonSerializer
|
||||
{
|
||||
private static readonly JsonSerializerSettings _settings = new JsonSerializerSettings
|
||||
private static readonly JsonSerializerSettings _settings = new()
|
||||
{
|
||||
Converters =
|
||||
{
|
||||
@ -21,7 +21,7 @@ public class NewtonsoftJsonSerializer : IJsonSerializer
|
||||
return JsonConvert.SerializeObject(obj, _settings);
|
||||
}
|
||||
|
||||
public T Deserialize<T>(string obj)
|
||||
public T? Deserialize<T>(string obj)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<T>(obj, _settings);
|
||||
}
|
||||
|
@ -3,27 +3,20 @@ using Newtonsoft.Json;
|
||||
|
||||
namespace LootDumpProcessor.Storage;
|
||||
|
||||
public abstract class AbstractKey : IKey
|
||||
public abstract class AbstractKey(string[] indexes) : IKey
|
||||
{
|
||||
public abstract KeyType GetKeyType();
|
||||
|
||||
private string[] indexes;
|
||||
|
||||
[JsonProperty("serializedKey")]
|
||||
[JsonPropertyName("serializedKey")]
|
||||
public string SerializedKey
|
||||
{
|
||||
get { return string.Join("|", this.indexes); }
|
||||
set { indexes = value.Split("|"); }
|
||||
}
|
||||
|
||||
public AbstractKey(string[] indexes)
|
||||
{
|
||||
this.indexes = indexes;
|
||||
get => string.Join("|", indexes);
|
||||
set => indexes = value.Split("|");
|
||||
}
|
||||
|
||||
public string[] GetLookupIndex()
|
||||
{
|
||||
return this.indexes;
|
||||
return indexes;
|
||||
}
|
||||
}
|
@ -1,14 +1,13 @@
|
||||
using LootDumpProcessor.Storage.Implementations;
|
||||
using LootDumpProcessor.Storage.Implementations.File;
|
||||
using LootDumpProcessor.Storage.Implementations.Memory;
|
||||
|
||||
namespace LootDumpProcessor.Storage;
|
||||
|
||||
public static class DataStorageFactory
|
||||
{
|
||||
private static readonly Dictionary<DataStorageTypes, IDataStorage> _dataStorage =
|
||||
new Dictionary<DataStorageTypes, IDataStorage>();
|
||||
private static readonly Dictionary<DataStorageTypes, IDataStorage> _dataStorage = new();
|
||||
|
||||
private static object lockObject = new object();
|
||||
private static object lockObject = new();
|
||||
|
||||
/**
|
||||
* Requires LootDumpProcessorContext to be initialized before using
|
||||
@ -25,17 +24,12 @@ public static class DataStorageFactory
|
||||
{
|
||||
if (!_dataStorage.TryGetValue(type, out dataStorage))
|
||||
{
|
||||
switch (type)
|
||||
dataStorage = type switch
|
||||
{
|
||||
case DataStorageTypes.File:
|
||||
dataStorage = new FileDataStorage();
|
||||
break;
|
||||
case DataStorageTypes.Memory:
|
||||
dataStorage = new MemoryDataStorage();
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(type), type, null);
|
||||
}
|
||||
DataStorageTypes.File => new FileDataStorage(),
|
||||
DataStorageTypes.Memory => new MemoryDataStorage(),
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
|
||||
};
|
||||
|
||||
_dataStorage.Add(type, dataStorage);
|
||||
}
|
||||
|
@ -1,10 +1,6 @@
|
||||
namespace LootDumpProcessor.Storage;
|
||||
|
||||
public class FlatUniqueKey : AbstractKey
|
||||
public class FlatUniqueKey(string[] indexes) : AbstractKey(indexes)
|
||||
{
|
||||
public override KeyType GetKeyType() => KeyType.Unique;
|
||||
|
||||
public FlatUniqueKey(string[] indexes) : base(indexes)
|
||||
{
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
namespace LootDumpProcessor.Storage.Implementations;
|
||||
namespace LootDumpProcessor.Storage.Implementations.File;
|
||||
|
||||
public class FileDataStorage : IDataStorage
|
||||
{
|
||||
|
@ -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
|
||||
{
|
||||
protected readonly IDataStorageFileSerializer _serializer;
|
||||
|
||||
public AbstractStoreHandler()
|
||||
{
|
||||
_serializer = DataStorageFileSerializerFactory.GetInstance();
|
||||
}
|
||||
protected readonly IDataStorageFileSerializer _serializer = DataStorageFileSerializerFactory.GetInstance();
|
||||
|
||||
public void Store<T>(T obj, bool failIfDuplicate = true) where T : IKeyable
|
||||
{
|
||||
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}");
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
var locationWithFile = GetLocation(obj);
|
||||
if (!File.Exists(locationWithFile))
|
||||
if (!System.IO.File.Exists(locationWithFile))
|
||||
{
|
||||
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)
|
||||
{
|
||||
var locationWithFile = GetLocation(obj);
|
||||
return File.Exists(locationWithFile);
|
||||
return System.IO.File.Exists(locationWithFile);
|
||||
}
|
||||
|
||||
public abstract List<T> RetrieveAll<T>() where T : IKeyable;
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace LootDumpProcessor.Storage.Implementations.Handlers;
|
||||
namespace LootDumpProcessor.Storage.Implementations.File.Handlers;
|
||||
|
||||
public class FlatStoreHandler : AbstractStoreHandler
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace LootDumpProcessor.Storage.Implementations.Handlers;
|
||||
namespace LootDumpProcessor.Storage.Implementations.File.Handlers;
|
||||
|
||||
public class SubdivisionedStoreHandler : AbstractStoreHandler
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace LootDumpProcessor.Storage.Implementations;
|
||||
namespace LootDumpProcessor.Storage.Implementations.File;
|
||||
|
||||
public interface IStoreHandler
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace LootDumpProcessor.Storage.Implementations.Serializers;
|
||||
namespace LootDumpProcessor.Storage.Implementations.File.Serializers;
|
||||
|
||||
public static class DataStorageFileSerializerFactory
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
using LootDumpProcessor.Serializers;
|
||||
|
||||
namespace LootDumpProcessor.Storage.Implementations.Serializers;
|
||||
namespace LootDumpProcessor.Storage.Implementations.File.Serializers;
|
||||
|
||||
public interface IDataStorageFileSerializer
|
||||
{
|
||||
|
@ -1,7 +1,7 @@
|
||||
using LootDumpProcessor.Serializers;
|
||||
using LootDumpProcessor.Serializers.Json;
|
||||
|
||||
namespace LootDumpProcessor.Storage.Implementations.Serializers;
|
||||
namespace LootDumpProcessor.Storage.Implementations.File.Serializers;
|
||||
|
||||
public class JsonDataStorageFileSerializer : IDataStorageFileSerializer
|
||||
{
|
||||
|
@ -1,7 +1,7 @@
|
||||
using LootDumpProcessor.Serializers;
|
||||
using LootDumpProcessor.Serializers.Yaml;
|
||||
|
||||
namespace LootDumpProcessor.Storage.Implementations.Serializers;
|
||||
namespace LootDumpProcessor.Storage.Implementations.File.Serializers;
|
||||
|
||||
public class YamlDataStorageFileSerializer : IDataStorageFileSerializer
|
||||
{
|
||||
|
@ -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
|
||||
{
|
||||
private static Dictionary<KeyType, IStoreHandler> _handlers = new Dictionary<KeyType, IStoreHandler>();
|
||||
private static object lockObject = new object();
|
||||
private static Dictionary<KeyType, IStoreHandler> _handlers = new();
|
||||
private static object lockObject = new();
|
||||
|
||||
public static IStoreHandler GetInstance(KeyType type)
|
||||
{
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
public class MemoryDataStorage : IDataStorage
|
||||
{
|
||||
private static readonly Dictionary<string, object> CachedObjects = new Dictionary<string, object>();
|
||||
private static readonly object _cacheObjectLock = new object();
|
||||
private static readonly Dictionary<string, object> CachedObjects = new();
|
||||
private static readonly object _cacheObjectLock = new();
|
||||
|
||||
public void Setup()
|
||||
{
|
||||
|
@ -1,10 +1,6 @@
|
||||
namespace LootDumpProcessor.Storage;
|
||||
|
||||
public class SubdivisionedUniqueKey : AbstractKey
|
||||
public class SubdivisionedUniqueKey(string[] indexes) : AbstractKey(indexes)
|
||||
{
|
||||
public override KeyType GetKeyType() => KeyType.Subdivisioned;
|
||||
|
||||
public SubdivisionedUniqueKey(string[] indexes) : base(indexes)
|
||||
{
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace LootDumpProcessor.Process.Processor;
|
||||
namespace LootDumpProcessor.Utils;
|
||||
|
||||
public static class FileDateParser
|
||||
{
|
||||
|
@ -1,16 +1,11 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Security.Cryptography;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using LootDumpProcessor.Model;
|
||||
using LootDumpProcessor.Serializers;
|
||||
using LootDumpProcessor.Serializers.Json;
|
||||
|
||||
namespace LootDumpProcessor.Process.Processor;
|
||||
namespace LootDumpProcessor.Utils;
|
||||
|
||||
public static class ProcessorUtil
|
||||
{
|
||||
private static readonly ISerializer Serializer = JsonSerializerFactory.GetInstance();
|
||||
|
||||
public static string GetSaneId(this Template x)
|
||||
{
|
||||
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
|
||||
{
|
||||
if (obj == null)
|
||||
return null;
|
||||
return obj.Select(o => o.Clone()).Cast<T>().ToList();
|
||||
return obj?.Select(o => o.Clone()).Cast<T>().ToList();
|
||||
}
|
||||
|
||||
public static string HashFile(string text)
|
||||
|
Loading…
x
Reference in New Issue
Block a user