mirror of
https://github.com/sp-tarkov/loot-dump-processor.git
synced 2025-02-13 07:10:45 -05:00
![BlueXTX](/assets/img/avatar_default.png)
* Improved thread safety and async processing in dump processor components * Removed unused _processedDumps field and simplified variable scope in QueuePipeline * Refactored service registration into dedicated extension methods * Added configuration binding and environment variables support * Refactored collector initialization to use dependency injection * Refactored data storage to use dependency injection * Refactored configuration models to use records and added validation * Refactored static loot configuration to use dependency injection The changes include: - Moved static weapon IDs and forced items from LootDumpProcessorContext to ForcedStatic record - Added ForcedStatic configuration injection in StaticLootProcessor and StaticContainerProcessor - Improved immutability by using read-only collections in ForcedStatic model - Simplified LootDumpProcessorContext by removing unused methods * Refactored configuration access to use dependency injection consistently * Fixed ForcedStatic configuration * Refactored forced items configuration to use async provider pattern The changes introduce a new `IForcedItemsProvider` abstraction to handle loading and caching of forced static and loose loot configurations. This improves the code by: 1. Making configuration loading asynchronous 2. Implementing caching of loaded configurations 3. Centralizing forced items configuration access 4. Removing direct file system dependencies from processors 5. Improving testability through dependency injection The change also updates related processors and interfaces to use async/await pattern consistently. * Refactored loose loot processor to use async forced items provider * Reorganized processor and service components into dedicated namespaces
90 lines
3.7 KiB
C#
90 lines
3.7 KiB
C#
using System.Text.Json;
|
|
using LootDumpProcessor.Model.Config;
|
|
using LootDumpProcessor.Model.Output;
|
|
using LootDumpProcessor.Model.Output.LooseLoot;
|
|
using LootDumpProcessor.Model.Output.StaticContainer;
|
|
using LootDumpProcessor.Serializers.Json;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace LootDumpProcessor.Process.Writer;
|
|
|
|
public class FileWriter : IWriter
|
|
{
|
|
private readonly string _outputPath;
|
|
|
|
public FileWriter(IOptions<Config> config)
|
|
{
|
|
var config1 = (config ?? throw new ArgumentNullException(nameof(config))).Value;
|
|
var path = config1.WriterConfig.OutputLocation;
|
|
if (string.IsNullOrEmpty(path))
|
|
throw new Exception("Output directory must be set in WriterConfigs");
|
|
|
|
if (!Directory.Exists(path)) Directory.CreateDirectory(path);
|
|
|
|
_outputPath = path;
|
|
}
|
|
|
|
public void WriteAll(Dictionary<OutputFileType, object> dumpData)
|
|
{
|
|
foreach (var (key, value) in dumpData) Write(key, value);
|
|
}
|
|
|
|
public void Write(
|
|
OutputFileType type,
|
|
object data
|
|
)
|
|
{
|
|
if (!Directory.Exists($"{_outputPath}\\loot"))
|
|
Directory.CreateDirectory($"{_outputPath}\\loot");
|
|
switch (type)
|
|
{
|
|
case OutputFileType.LooseLoot:
|
|
var looseLootData = (IReadOnlyDictionary<string, LooseLootRoot>)data;
|
|
foreach (var (key, value) in looseLootData)
|
|
{
|
|
if (!Directory.Exists($@"{_outputPath}\locations\{key}"))
|
|
Directory.CreateDirectory($@"{_outputPath}\locations\{key}");
|
|
File.WriteAllText($@"{_outputPath}\locations\{key}\looseLoot.json",
|
|
JsonSerializer.Serialize(value, JsonSerializerSettings.Default));
|
|
}
|
|
|
|
break;
|
|
case OutputFileType.StaticContainer:
|
|
var staticContainer = (IReadOnlyDictionary<string, MapStaticLoot>)data;
|
|
foreach (var (key, value) in staticContainer)
|
|
{
|
|
if (!Directory.Exists($@"{_outputPath}\locations\{key}"))
|
|
Directory.CreateDirectory($@"{_outputPath}\locations\{key}");
|
|
File.WriteAllText($@"{_outputPath}\locations\{key}\staticContainers.json",
|
|
JsonSerializer.Serialize(value, JsonSerializerSettings.Default));
|
|
}
|
|
|
|
break;
|
|
case OutputFileType.StaticLoot:
|
|
var staticLootData =
|
|
(IReadOnlyDictionary<string, IReadOnlyDictionary<string, StaticItemDistribution>>)data;
|
|
foreach (var (key, value) in staticLootData)
|
|
{
|
|
if (!Directory.Exists($@"{_outputPath}\locations\{key}"))
|
|
Directory.CreateDirectory($@"{_outputPath}\locations\{key}");
|
|
File.WriteAllText($@"{_outputPath}\locations\{key}\staticLoot.json",
|
|
JsonSerializer.Serialize(value, JsonSerializerSettings.Default));
|
|
}
|
|
|
|
break;
|
|
case OutputFileType.StaticAmmo:
|
|
var staticAmmo = (IReadOnlyDictionary<string, IReadOnlyDictionary<string, List<AmmoDistribution>>>)data;
|
|
foreach (var (key, value) in staticAmmo)
|
|
{
|
|
if (!Directory.Exists($@"{_outputPath}\locations\{key}"))
|
|
Directory.CreateDirectory($@"{_outputPath}\locations\{key}");
|
|
File.WriteAllText($@"{_outputPath}\locations\{key}\staticAmmo.json",
|
|
JsonSerializer.Serialize(value, JsonSerializerSettings.Default));
|
|
}
|
|
|
|
break;
|
|
default:
|
|
throw new ArgumentOutOfRangeException(nameof(type), type, null);
|
|
}
|
|
}
|
|
} |