2021-03-14 14:51:52 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2020-07-01 03:46:26 +00:00
|
|
|
|
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;
|
2020-07-01 03:46:26 +00:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-07-01 03:46:26 +00:00
|
|
|
|
_profilePaths =
|
2020-10-18 12:59:49 +00:00
|
|
|
|
MO2Compiler.SelectedProfiles.Select(p => MO2Compiler.SourcePath.Combine("profiles", p, "saves")).ToArray();
|
2020-07-01 03:46:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
2020-07-01 03:46:26 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|