mirror of
https://github.com/sp-tarkov/loot-dump-processor.git
synced 2025-02-12 20:50:45 -05:00
![CWX](/assets/img/avatar_default.png)
* Seperate Tasks into their own methods, Add method to add map name to file name * Formatting and added a few comments * Add Clear method to collectors * Change to local var, so data isnt stored longer than needed * add Clear method to Storages * Add changes for Per Map Processing and file i forgot to commit last time * Update config to have mapNames in it, removed unused yaml file * update comment * changed to not throw so Filemode still can be used
57 lines
1.8 KiB
C#
57 lines
1.8 KiB
C#
using LootDumpProcessor.Model.Processing;
|
|
using LootDumpProcessor.Serializers.Json;
|
|
|
|
namespace LootDumpProcessor.Process.Collector;
|
|
|
|
public class DumpCollector : ICollector
|
|
{
|
|
private static readonly string DumpLocation = $"{LootDumpProcessorContext.GetConfig().CollectorConfig.DumpLocation}/collector/";
|
|
private readonly List<PartialData> processedDumps = new(LootDumpProcessorContext.GetConfig().CollectorConfig.MaxEntitiesBeforeDumping + 50);
|
|
private readonly object lockObject = new();
|
|
|
|
public void Setup()
|
|
{
|
|
if (Directory.Exists(DumpLocation))
|
|
{
|
|
Directory.Delete(DumpLocation, true);
|
|
}
|
|
|
|
Directory.CreateDirectory(DumpLocation);
|
|
}
|
|
|
|
public void Hold(PartialData parsedDump)
|
|
{
|
|
lock (lockObject)
|
|
{
|
|
processedDumps.Add(parsedDump);
|
|
if (processedDumps.Count > LootDumpProcessorContext.GetConfig().CollectorConfig.MaxEntitiesBeforeDumping)
|
|
{
|
|
var fileName = $"collector-{DateTime.Now.ToString("yyyyMMddHHmmssfffff")}.json";
|
|
File.WriteAllText($"{DumpLocation}{fileName}", JsonSerializerFactory.GetInstance().Serialize(processedDumps));
|
|
processedDumps.Clear();
|
|
}
|
|
}
|
|
}
|
|
|
|
public List<PartialData> Retrieve()
|
|
{
|
|
foreach (var file in Directory.GetFiles(DumpLocation))
|
|
{
|
|
processedDumps.AddRange(JsonSerializerFactory.GetInstance().Deserialize<List<PartialData>>(File.ReadAllText(file)));
|
|
}
|
|
|
|
return processedDumps;
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
lock (lockObject)
|
|
{
|
|
foreach (var file in Directory.GetFiles(DumpLocation))
|
|
{
|
|
File.Delete(file);
|
|
}
|
|
processedDumps.Clear();
|
|
}
|
|
}
|
|
} |