2025-01-11 09:12:21 +03:00
|
|
|
using Microsoft.Extensions.Logging;
|
2023-08-12 19:08:38 +01:00
|
|
|
|
|
|
|
namespace LootDumpProcessor.Process.Reader.PreProcess;
|
|
|
|
|
|
|
|
public abstract class AbstractPreProcessReader : IPreProcessReader
|
|
|
|
{
|
2024-04-16 18:29:40 +00:00
|
|
|
protected readonly string _tempFolder;
|
2023-08-12 19:08:38 +01:00
|
|
|
|
2025-01-11 09:12:21 +03:00
|
|
|
public AbstractPreProcessReader(ILogger logger)
|
2023-08-12 19:08:38 +01:00
|
|
|
{
|
|
|
|
var tempFolder = LootDumpProcessorContext.GetConfig().ReaderConfig.PreProcessorConfig?.PreProcessorTempFolder;
|
|
|
|
if (string.IsNullOrEmpty(tempFolder))
|
|
|
|
{
|
|
|
|
tempFolder = GetBaseDirectory();
|
2025-01-11 09:12:21 +03:00
|
|
|
logger.LogWarning(
|
|
|
|
"No temp folder was assigned preProcessorTempFolder in PreProcessorConfig, defaulting to {tempFolder}",
|
|
|
|
tempFolder
|
|
|
|
);
|
2023-08-12 19:08:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Cleanup the temp directory before starting the process
|
2025-01-11 10:52:23 +03:00
|
|
|
if (Directory.Exists(tempFolder)) Directory.Delete(tempFolder, true);
|
2023-08-12 19:08:38 +01:00
|
|
|
|
|
|
|
Directory.CreateDirectory(tempFolder);
|
|
|
|
|
|
|
|
_tempFolder = tempFolder;
|
|
|
|
}
|
|
|
|
|
|
|
|
public abstract string GetHandleExtension();
|
|
|
|
public abstract bool TryPreProcess(string file, out List<string> files, out List<string> directories);
|
|
|
|
|
2025-01-11 09:12:21 +03:00
|
|
|
protected string GetBaseDirectory() =>
|
|
|
|
$@"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}\SPT\tmp\PreProcessor";
|
2023-08-12 19:08:38 +01:00
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
if (LootDumpProcessorContext.GetConfig().ReaderConfig.PreProcessorConfig?.CleanupTempFolderAfterProcess ?? true)
|
|
|
|
Directory.Delete(_tempFolder, true);
|
|
|
|
}
|
|
|
|
}
|