Disabled mods will now be ignored in the VortexCompiler

This commit is contained in:
erri120 2019-11-17 17:26:04 +01:00
parent ac178ed0c5
commit 7dbe31581f
No known key found for this signature in database
GPG Key ID: A8C0A18D8D4D3135
4 changed files with 115 additions and 10 deletions

View File

@ -0,0 +1,41 @@
using Alphaleonis.Win32.Filesystem;
using Wabbajack.Common;
namespace Wabbajack.Lib.CompilationSteps
{
public class IgnoreDisabledVortexMods : ACompilationStep
{
private readonly VortexCompiler _vortexCompiler;
public IgnoreDisabledVortexMods(ACompiler compiler) : base(compiler)
{
_vortexCompiler = (VortexCompiler) compiler;
}
public override Directive Run(RawSourceFile source)
{
var b = false;
_vortexCompiler.ActiveArchives.Do(a =>
{
if (source.Path.Contains(a)) b = true;
});
if (b) return null;
var r = source.EvolveTo<IgnoredDirectly>();
r.Reason = "Disabled Archive";
return r;
}
public override IState GetState()
{
return new State();
}
public class State : IState
{
public ICompilationStep CreateStep(ACompiler compiler)
{
return new IgnoreDisabledVortexMods(compiler);
}
}
}
}

View File

@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Wabbajack.Common;
using System.IO;
namespace Wabbajack.Lib.CompilationSteps
{
@ -16,8 +10,9 @@ namespace Wabbajack.Lib.CompilationSteps
public override Directive Run(RawSourceFile source)
{
if (!source.Path.EndsWith("vortex.deployment.msgpack") &&
!source.Path.EndsWith("\\vortex.deployment.json")) return null;
!source.Path.EndsWith("\\vortex.deployment.json") && Path.GetExtension(source.Path) != ".meta") return null;
var inline = source.EvolveTo<InlineFile>();
inline.SourceDataID = _compiler.IncludeFile(File.ReadAllBytes(source.AbsolutePath));
return inline;

View File

@ -5,6 +5,7 @@ using System.Linq;
using System.Security.Cryptography;
using System.Text;
using Microsoft.WindowsAPICodePack.Shell;
using Newtonsoft.Json;
using Wabbajack.Common;
using Wabbajack.Lib.CompilationSteps;
using Wabbajack.Lib.NexusApi;
@ -15,6 +16,14 @@ namespace Wabbajack.Lib
{
public class VortexCompiler : ACompiler
{
/* vortex creates a vortex.deployment.json file that contains information
about all deployed files, parsing that file, we can get a list of all 'active'
archives so we don't force the user to install all archives found in the downloads folder.
Similar to how IgnoreDisabledMods for MO2 works
*/
public VortexDeployment VortexDeployment;
public List<string> ActiveArchives;
public Game Game { get; }
public string GameName { get; }
@ -44,6 +53,8 @@ namespace Wabbajack.Lib
DownloadsFolder = downloadsFolder;
StagingFolder = stagingFolder;
ModListOutputFolder = "output_folder";
ActiveArchives = new List<string>();
}
public override bool Compile()
@ -54,6 +65,8 @@ namespace Wabbajack.Lib
Info($"Starting Vortex compilation for {GameName} at {GamePath} with staging folder at {StagingFolder} and downloads folder at {DownloadsFolder}.");
ParseDeploymentFile();
Info("Starting pre-compilation steps");
CreateMetaFiles();
@ -186,6 +199,46 @@ namespace Wabbajack.Lib
return true;
}
private void ParseDeploymentFile()
{
Info("Searching for vortex.deployment.json...");
var deploymentFile = "";
Directory.EnumerateFiles(GamePath, "vortex.deployment.json", SearchOption.AllDirectories)
.Where(File.Exists)
.Do(f => deploymentFile = f);
var currentGame = GameRegistry.Games[Game];
if (currentGame.AdditionalFolders != null && currentGame.AdditionalFolders.Count != 0)
currentGame.AdditionalFolders.Do(f => Directory.EnumerateFiles(f, "vortex.deployment.json", SearchOption.AllDirectories)
.Where(File.Exists)
.Do(d => deploymentFile = d));
if (string.IsNullOrEmpty(deploymentFile))
{
Info("vortex.deployment.json not found!");
return;
}
Info("vortex.deployment.json found at "+deploymentFile);
Info("Parsing vortex.deployment.json...");
try
{
VortexDeployment = deploymentFile.FromJSON<VortexDeployment>();
}
catch (JsonSerializationException e)
{
Info("Failed to parse vortex.deployment.json!");
Utils.LogToFile(e.Message);
Utils.LogToFile(e.StackTrace);
}
VortexDeployment.files.Do(f =>
{
var archive = f.source;
if(!ActiveArchives.Contains(archive)) ActiveArchives.Add(archive);
});
}
/// <summary>
/// Some have mods outside their game folder located
/// </summary>
@ -208,7 +261,7 @@ namespace Wabbajack.Lib
var nexusClient = new NexusApiClient();
Directory.EnumerateFiles(DownloadsFolder, "*", SearchOption.TopDirectoryOnly)
.Where(f => File.Exists(f) && Path.GetExtension(f) != ".meta" && !File.Exists(f+".meta"))
.Where(f => File.Exists(f) && Path.GetExtension(f) != ".meta" && !File.Exists(f+".meta") && ActiveArchives.Contains(Path.GetFileNameWithoutExtension(f)))
.Do(f =>
{
Utils.Log($"Trying to create meta file for {Path.GetFileName(f)}");
@ -266,8 +319,8 @@ namespace Wabbajack.Lib
return new List<ICompilationStep>
{
new IncludePropertyFiles(this),
new IgnoreDisabledVortexMods(this),
new IncludeVortexDeployment(this),
new IncludeRegex(this, "^*\\.meta"),
new IgnoreVortex(this),
new IgnoreRegex(this, "^*__vortex_staging_folder$"),
@ -330,4 +383,19 @@ namespace Wabbajack.Lib
return IsValidBaseStagingFolder(Path.GetDirectoryName(path));
}
}
public class VortexDeployment
{
public string instance;
public int version;
public string deploymentMethod;
public List<VortexFile> files;
}
public class VortexFile
{
public string relPath;
public string source;
public string target;
}
}

View File

@ -86,6 +86,7 @@
<Compile Include="CompilationSteps\DirectMatch.cs" />
<Compile Include="CompilationSteps\DropAll.cs" />
<Compile Include="CompilationSteps\IgnoreDisabledMods.cs" />
<Compile Include="CompilationSteps\IgnoreDisabledVortexMods.cs" />
<Compile Include="CompilationSteps\IgnoreEndsWith.cs" />
<Compile Include="CompilationSteps\IgnoreGameFiles.cs" />
<Compile Include="CompilationSteps\IgnorePathContains.cs" />