wabbajack/Wabbajack.Lib/CompilationSteps/IgnoreSaveFiles.cs

62 lines
2.0 KiB
C#
Raw Normal View History

2021-03-14 14:51:52 +00:00
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Wabbajack.Common;
namespace Wabbajack.Lib.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;
_sourcePath = compiler.SourcePath;
string rootDirectory = (string)_sourcePath;
try
{
_includeSaves = File.Exists(((String)Directory.EnumerateFiles(rootDirectory, _tag).ToList().First())) ? true : false;
}
catch // Cant get a .First() if the list is empty, which it is when the files doesn't exist.
{
_includeSaves = false;
}
_profilePaths =
2020-10-18 12:59:49 +00:00
MO2Compiler.SelectedProfiles.Select(p => MO2Compiler.SourcePath.Combine("profiles", p, "saves")).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>();
result.SourceDataID = await _compiler.IncludeFile(source.AbsolutePath);
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;
}
}
}