wabbajack/Wabbajack.Compiler/CompilationSteps/IgnoreSaveFiles.cs

51 lines
1.6 KiB
C#
Raw Normal View History

2021-10-23 16:51:17 +00:00
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-10-23 16:51:17 +00:00
namespace Wabbajack.Compiler.CompilationSteps;
public class IgnoreSaveFiles : MO2CompilationStep
{
2021-10-23 16:51:17 +00:00
private readonly bool _includeSaves;
private readonly string _tag;
private readonly AbsolutePath[] _profilePaths;
2021-10-23 16:51:17 +00:00
public IgnoreSaveFiles(ACompiler compiler) : base(compiler)
{
_tag = Consts.WABBAJACK_INCLUDE_SAVES;
_includeSaves = _compiler._settings.Source.EnumerateFiles(_tag).FirstOrDefault() != default;
2021-03-14 14:51:52 +00:00
2021-10-23 16:51:17 +00:00
_profilePaths =
MO2Compiler._settings.AllProfiles
2021-10-23 16:51:17 +00:00
.Select(p => _compiler._settings.Source.Combine(Consts.MO2Profiles, p, Consts.MO2Saves)).ToArray();
}
2021-10-23 16:51:17 +00:00
public override async ValueTask<Directive?> Run(RawSourceFile source)
{
if (_includeSaves)
{
2021-10-23 16:51:17 +00:00
foreach (var folderpath in _profilePaths)
2021-03-14 14:51:52 +00:00
{
2021-10-23 16:51:17 +00:00
if (!source.AbsolutePath.InFolder(folderpath)) continue;
var result = source.EvolveTo<InlineFile>();
result.SourceDataID = await _compiler.IncludeFile(source.AbsolutePath, CancellationToken.None);
2021-03-14 14:51:52 +00:00
return result;
}
2021-10-23 16:51:17 +00:00
}
else
{
if (!_profilePaths.Any(p => source.File.AbsoluteName.InFolder(p)))
return null;
2021-10-23 16:51:17 +00:00
var result = source.EvolveTo<IgnoredDirectly>();
result.Reason = "Ignore Save files";
return result;
}
2021-10-23 16:51:17 +00:00
return null;
}
2021-10-23 16:51:17 +00:00
}