wabbajack/Wabbajack.Lib/CompilationSteps/IncludePropertyFiles.cs

57 lines
1.7 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Alphaleonis.Win32.Filesystem;
using Newtonsoft.Json;
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)
{
var files = new HashSet<string>
{
2019-11-17 14:30:06 +00:00
_compiler.ModListImage, _compiler.ModListReadme
};
if (!files.Any(f => source.AbsolutePath.Equals(f))) return null;
if (!File.Exists(source.AbsolutePath)) 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>();
result.SourceDataID = _compiler.IncludeFile(File.ReadAllBytes(source.AbsolutePath));
if (isBanner)
{
result.Type = PropertyType.Banner;
2019-11-17 14:30:06 +00:00
_compiler.ModListImage = result.SourceDataID;
}
else
{
result.Type = PropertyType.Readme;
2019-11-17 14:30:06 +00:00
_compiler.ModListReadme = result.SourceDataID;
}
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);
}
}
}
}