2019-10-30 12:29:06 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
2019-12-04 01:26:26 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2019-10-30 12:29:06 +00:00
|
|
|
|
using Alphaleonis.Win32.Filesystem;
|
2019-10-31 02:24:42 +00:00
|
|
|
|
using Newtonsoft.Json;
|
2019-10-30 12:29:06 +00:00
|
|
|
|
|
|
|
|
|
namespace Wabbajack.Lib.CompilationSteps
|
|
|
|
|
{
|
|
|
|
|
public class IncludeThisProfile : ACompilationStep
|
|
|
|
|
{
|
|
|
|
|
private readonly IEnumerable<string> _correctProfiles;
|
2019-11-18 00:17:06 +00:00
|
|
|
|
private readonly MO2Compiler _mo2Compiler;
|
2019-10-30 12:29:06 +00:00
|
|
|
|
|
2019-11-03 16:45:49 +00:00
|
|
|
|
public IncludeThisProfile(ACompiler compiler) : base(compiler)
|
2019-10-30 12:29:06 +00:00
|
|
|
|
{
|
2019-11-18 00:17:06 +00:00
|
|
|
|
_mo2Compiler = (MO2Compiler) compiler;
|
2019-11-11 20:03:27 +00:00
|
|
|
|
_correctProfiles = _mo2Compiler.SelectedProfiles.Select(p => Path.Combine("profiles", p) + "\\").ToList();
|
2019-10-30 12:29:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-04 01:26:26 +00:00
|
|
|
|
public override async ValueTask<Directive> Run(RawSourceFile source)
|
2019-10-30 12:29:06 +00:00
|
|
|
|
{
|
|
|
|
|
if (_correctProfiles.Any(p => source.Path.StartsWith(p)))
|
|
|
|
|
{
|
2019-10-31 02:24:42 +00:00
|
|
|
|
var data = source.Path.EndsWith("\\modlist.txt")
|
|
|
|
|
? ReadAndCleanModlist(source.AbsolutePath)
|
|
|
|
|
: File.ReadAllBytes(source.AbsolutePath);
|
2019-10-30 12:29:06 +00:00
|
|
|
|
|
|
|
|
|
var e = source.EvolveTo<InlineFile>();
|
|
|
|
|
e.SourceDataID = _compiler.IncludeFile(data);
|
|
|
|
|
return e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2019-10-31 02:24:42 +00:00
|
|
|
|
|
|
|
|
|
public override IState GetState()
|
|
|
|
|
{
|
|
|
|
|
return new State();
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-30 12:29:06 +00:00
|
|
|
|
private static byte[] ReadAndCleanModlist(string absolutePath)
|
|
|
|
|
{
|
|
|
|
|
var lines = File.ReadAllLines(absolutePath);
|
|
|
|
|
lines = (from line in lines
|
|
|
|
|
where !(line.StartsWith("-") && !line.EndsWith("_separator"))
|
|
|
|
|
select line).ToArray();
|
|
|
|
|
return Encoding.UTF8.GetBytes(string.Join("\r\n", lines));
|
|
|
|
|
}
|
2019-10-31 02:24:42 +00:00
|
|
|
|
|
|
|
|
|
[JsonObject("IncludeThisProfile")]
|
|
|
|
|
public class State : IState
|
|
|
|
|
{
|
2019-11-03 16:45:49 +00:00
|
|
|
|
public ICompilationStep CreateStep(ACompiler compiler)
|
2019-10-31 02:24:42 +00:00
|
|
|
|
{
|
|
|
|
|
return new IncludeThisProfile(compiler);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-30 12:29:06 +00:00
|
|
|
|
}
|
2019-12-04 01:26:26 +00:00
|
|
|
|
}
|