wabbajack/Wabbajack.Compiler/CompilationSteps/IgnoreSaveFiles.cs

55 lines
1.8 KiB
C#
Raw Normal View History

2021-03-14 14:51:52 +00:00
using System;
using System.IO;
using System.Linq;
2021-09-27 12:42:46 +00:00
using System.Threading;
using System.Threading.Tasks;
2021-09-27 12:42:46 +00:00
using Wabbajack.DTOs;
using Wabbajack.DTOs.Directives;
using Wabbajack.Paths;
using Wabbajack.Paths.IO;
2021-09-27 12:42:46 +00:00
namespace Wabbajack.Compiler.CompilationSteps
{
public class IgnoreSaveFiles : MO2CompilationStep
{
private AbsolutePath[] _profilePaths;
2021-03-14 14:51:52 +00:00
private readonly bool _includeSaves;
private readonly string _tag;
private readonly AbsolutePath _sourcePath;
public IgnoreSaveFiles(ACompiler compiler) : base(compiler)
{
2021-03-14 14:51:52 +00:00
_tag = Consts.WABBAJACK_INCLUDE_SAVES;
2021-09-27 12:42:46 +00:00
_includeSaves = _compiler._settings.Source.EnumerateFiles(_tag, true).FirstOrDefault() != default;
2021-03-14 14:51:52 +00:00
_profilePaths =
2021-09-27 12:42:46 +00:00
MO2Compiler._settings.SelectedProfiles.Select(p => _compiler._settings.Source.Combine(Consts.MO2Profiles, p, Consts.MO2Saves)).ToArray();
}
public override async ValueTask<Directive?> Run(RawSourceFile source)
{
2021-03-14 14:51:52 +00:00
if (_includeSaves)
{
foreach (var folderpath in _profilePaths)
{
if (!source.AbsolutePath.InFolder(folderpath)) continue;
var result = source.EvolveTo<InlineFile>();
2021-09-27 12:42:46 +00:00
result.SourceDataID = await _compiler.IncludeFile(source.AbsolutePath, CancellationToken.None);
2021-03-14 14:51:52 +00:00
return result;
}
}
else
{
if (!_profilePaths.Any(p => source.File.AbsoluteName.InFolder(p)))
return null;
var result = source.EvolveTo<IgnoredDirectly>();
result.Reason = "Ignore Save files";
return result;
}
return null;
}
}
}