2019-10-30 12:29:06 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
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-03 16:45:49 +00:00
|
|
|
|
public IncludeThisProfile(ACompiler compiler) : base(compiler)
|
2019-10-30 12:29:06 +00:00
|
|
|
|
{
|
2019-11-05 12:48:03 +00:00
|
|
|
|
_correctProfiles = _compiler._mo2Compiler.SelectedProfiles.Select(p => Path.Combine("profiles", p) + "\\").ToList();
|
2019-10-30 12:29:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Directive Run(RawSourceFile source)
|
|
|
|
|
{
|
|
|
|
|
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-10-31 02:24:42 +00:00
|
|
|
|
}
|