wabbajack/Wabbajack.Lib/CompilationSteps/IncludePropertyFiles.cs

53 lines
1.6 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Alphaleonis.Win32.Filesystem;
using Newtonsoft.Json;
2020-03-25 12:47:25 +00:00
using Wabbajack.Common;
namespace Wabbajack.Lib.CompilationSteps
{
public class IncludePropertyFiles : ACompilationStep
{
2019-11-11 20:05:23 +00:00
public IncludePropertyFiles(ACompiler compiler) : base(compiler)
{
}
public override async ValueTask<Directive?> Run(RawSourceFile source)
{
2020-03-25 12:47:25 +00:00
var files = new HashSet<AbsolutePath>
{
2020-04-15 17:40:41 +00:00
_compiler.ModListImage
};
if (!files.Any(f => source.AbsolutePath.Equals(f))) return null;
2020-03-25 12:47:25 +00:00
if (!source.AbsolutePath.Exists) return null;
2019-11-17 14:30:06 +00:00
var isBanner = source.AbsolutePath == _compiler.ModListImage;
//var isReadme = source.AbsolutePath == ModListReadme;
var result = source.EvolveTo<PropertyFile>();
2020-03-25 22:30:43 +00:00
result.SourceDataID = await _compiler.IncludeFile(await source.AbsolutePath.ReadAllBytesAsync());
if (isBanner)
{
result.Type = PropertyType.Banner;
2020-03-25 22:30:43 +00:00
_compiler.ModListImage = result.SourceDataID.RelativeTo(_compiler.ModListOutputFolder);
}
return result;
2019-11-17 14:30:06 +00:00
}
public override IState GetState()
{
return new State();
}
[JsonObject("IncludePropertyFiles")]
public class State : IState
{
public ICompilationStep CreateStep(ACompiler compiler)
{
return new IncludePropertyFiles(compiler);
}
}
}
}