0
0
mirror of https://github.com/sp-tarkov/loot-dump-processor.git synced 2025-02-13 09:50:44 -05:00

51 lines
1.7 KiB
C#
Raw Normal View History

using LootDumpProcessor.Process.Reader.PreProcess;
2023-08-12 19:08:38 +01:00
using SevenZip;
using Microsoft.Extensions.Logging;
2023-08-12 19:08:38 +01:00
public class SevenZipPreProcessReader : AbstractPreProcessReader
{
private readonly ILogger<SevenZipPreProcessReader> _logger;
public SevenZipPreProcessReader(ILogger<SevenZipPreProcessReader> logger) : base(logger)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
2023-08-12 19:08:38 +01:00
public override string GetHandleExtension() => "7z";
static SevenZipPreProcessReader()
{
SevenZipBase.SetLibraryPath("./x64/7z.dll");
}
public override bool TryPreProcess(string file, out List<string> files, out List<string> directories)
{
files = new List<string>();
directories = new List<string>();
2023-08-12 19:08:38 +01:00
var fileRaw = Path.GetFileNameWithoutExtension(file);
// SevenZip library doesn't handle forward slashes properly
2023-08-12 19:08:38 +01:00
var outPath = $"{_tempFolder}\\{fileRaw}".Replace("/", "\\");
_logger.LogInformation("Unzipping {File} into temp path {OutPath}, this may take a while...", file, outPath);
2023-08-12 19:08:38 +01:00
var extractor = new SevenZipExtractor(file);
// Log progress in debug mode
extractor.Extracting += (_, args) =>
2023-08-12 19:08:38 +01:00
{
if (args.PercentDone % 10 == 0)
{
_logger.LogDebug("Unzip progress: {PercentDone}%", args.PercentDone);
}
};
2023-08-12 19:08:38 +01:00
extractor.ExtractArchive(outPath);
_logger.LogInformation("Finished unzipping {File} into temp path {OutPath}", file, outPath);
2023-08-12 19:08:38 +01:00
files = Directory.GetFiles(outPath).ToList();
directories = Directory.GetDirectories(outPath).ToList();
2023-08-12 19:08:38 +01:00
return true;
}
}