2019-10-30 12:29:06 +00:00
|
|
|
|
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
|
|
|
|
using Wabbajack.Common;
|
|
|
|
|
|
|
|
|
|
namespace Wabbajack.Lib.CompilationSteps
|
|
|
|
|
{
|
|
|
|
|
public class IncludeStubbedConfigFiles : ACompilationStep
|
|
|
|
|
{
|
2019-11-18 00:17:06 +00:00
|
|
|
|
private readonly MO2Compiler _mo2Compiler;
|
2019-11-11 20:03:27 +00:00
|
|
|
|
|
2019-11-03 16:45:49 +00:00
|
|
|
|
public IncludeStubbedConfigFiles(ACompiler compiler) : base(compiler)
|
2019-10-30 12:29:06 +00:00
|
|
|
|
{
|
2019-11-18 00:17:06 +00:00
|
|
|
|
_mo2Compiler = (MO2Compiler) compiler;
|
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
|
|
|
|
{
|
2020-03-25 12:47:25 +00:00
|
|
|
|
return Consts.ConfigFileExtensions.Contains(source.Path.Extension) ? await RemapFile(source) : null;
|
2019-10-30 12:29:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-31 02:24:42 +00:00
|
|
|
|
public override IState GetState()
|
|
|
|
|
{
|
|
|
|
|
return new State();
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-25 12:47:25 +00:00
|
|
|
|
private async Task<Directive> RemapFile(RawSourceFile source)
|
2019-10-30 12:29:06 +00:00
|
|
|
|
{
|
2020-03-25 12:47:25 +00:00
|
|
|
|
var data = await source.AbsolutePath.ReadAllTextAsync();
|
2019-10-30 12:29:06 +00:00
|
|
|
|
var originalData = data;
|
|
|
|
|
|
2020-03-25 12:47:25 +00:00
|
|
|
|
data = data.Replace((string)_mo2Compiler.GamePath, Consts.GAME_PATH_MAGIC_BACK);
|
|
|
|
|
data = data.Replace(((string)_mo2Compiler.GamePath).Replace("\\", "\\\\"), Consts.GAME_PATH_MAGIC_DOUBLE_BACK);
|
|
|
|
|
data = data.Replace(((string)_mo2Compiler.GamePath).Replace("\\", "/"), Consts.GAME_PATH_MAGIC_FORWARD);
|
2019-10-30 12:29:06 +00:00
|
|
|
|
|
2020-03-25 12:47:25 +00:00
|
|
|
|
data = data.Replace((string)_mo2Compiler.MO2Folder, Consts.MO2_PATH_MAGIC_BACK);
|
|
|
|
|
data = data.Replace(((string)_mo2Compiler.MO2Folder).Replace("\\", "\\\\"), Consts.MO2_PATH_MAGIC_DOUBLE_BACK);
|
|
|
|
|
data = data.Replace(((string)_mo2Compiler.MO2Folder).Replace("\\", "/"), Consts.MO2_PATH_MAGIC_FORWARD);
|
2019-10-30 12:29:06 +00:00
|
|
|
|
|
2020-03-25 12:47:25 +00:00
|
|
|
|
data = data.Replace((string)_mo2Compiler.MO2DownloadsFolder, Consts.DOWNLOAD_PATH_MAGIC_BACK);
|
|
|
|
|
data = data.Replace(((string)_mo2Compiler.MO2DownloadsFolder).Replace("\\", "\\\\"),
|
2019-10-31 02:24:42 +00:00
|
|
|
|
Consts.DOWNLOAD_PATH_MAGIC_DOUBLE_BACK);
|
2020-03-25 12:47:25 +00:00
|
|
|
|
data = data.Replace(((string)_mo2Compiler.MO2DownloadsFolder).Replace("\\", "/"), Consts.DOWNLOAD_PATH_MAGIC_FORWARD);
|
2019-10-30 12:29:06 +00:00
|
|
|
|
|
|
|
|
|
if (data == originalData)
|
|
|
|
|
return null;
|
|
|
|
|
var result = source.EvolveTo<RemappedInlineFile>();
|
2020-03-25 22:30:43 +00:00
|
|
|
|
result.SourceDataID = await _compiler.IncludeFile(Encoding.UTF8.GetBytes(data));
|
2019-10-30 12:29:06 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
2019-10-31 02:24:42 +00:00
|
|
|
|
|
|
|
|
|
[JsonObject("IncludeStubbedConfigFiles")]
|
|
|
|
|
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 IncludeStubbedConfigFiles(compiler);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-30 12:29:06 +00:00
|
|
|
|
}
|
2019-12-04 01:26:26 +00:00
|
|
|
|
}
|