Merge pull request #365 from wabbajack-tools/game-folder-files-override

Add override for Game Folder Files
This commit is contained in:
Timothy Baldridge 2020-01-06 16:32:24 -08:00 committed by GitHub
commit ae43c93c4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 115 additions and 0 deletions

View File

@ -0,0 +1,46 @@
using System.Threading.Tasks;
using Alphaleonis.Win32.Filesystem;
using Wabbajack.Common;
namespace Wabbajack.Lib.CompilationSteps
{
public class IgnoreGameFilesIfGameFolderFilesExist : ACompilationStep
{
private readonly bool _gameFolderFilesExists;
private readonly string _gameFolder;
public IgnoreGameFilesIfGameFolderFilesExist(ACompiler compiler) : base(compiler)
{
_gameFolderFilesExists = Directory.Exists(Path.Combine(((MO2Compiler)compiler).MO2Folder, Consts.GameFolderFilesDir));
_gameFolder = compiler.GamePath;
}
public override async ValueTask<Directive> Run(RawSourceFile source)
{
if (_gameFolderFilesExists)
{
if (source.AbsolutePath.IsInPath(_gameFolder))
{
var result = source.EvolveTo<IgnoredDirectly>();
result.Reason = $"Ignoring game files because {Consts.GameFolderFilesDir} exists";
return result;
}
}
return null;
}
public override IState GetState()
{
return new State();
}
public class State : IState
{
public ICompilationStep CreateStep(ACompiler compiler)
{
return new IgnoreGameFilesIfGameFolderFilesExist(compiler);
}
}
}
}

View File

@ -496,6 +496,7 @@ namespace Wabbajack.Lib
Utils.Log("Generating compilation stack");
return new List<ICompilationStep>
{
new IgnoreGameFilesIfGameFolderFilesExist(this),
new IncludePropertyFiles(this),
new IgnoreStartsWith(this,"logs\\"),
new IgnoreStartsWith(this, "downloads\\"),

View File

@ -101,6 +101,7 @@
<Compile Include="CompilationSteps\IgnoreDisabledVortexMods.cs" />
<Compile Include="CompilationSteps\IgnoreEndsWith.cs" />
<Compile Include="CompilationSteps\IgnoreGameFiles.cs" />
<Compile Include="CompilationSteps\IgnoreGameFilesIfGameFolderFilesExist.cs" />
<Compile Include="CompilationSteps\IgnorePathContains.cs" />
<Compile Include="CompilationSteps\IgnoreRegex.cs" />
<Compile Include="CompilationSteps\IgnoreStartsWith.cs" />

View File

@ -32,6 +32,44 @@ namespace Wabbajack.Test
utils.VerifyInstalledFile(mod, @"Data\scripts\test.pex");
}
[TestMethod]
public async Task TestDirectMatchFromGameFolder()
{
var profile = utils.AddProfile();
var mod = utils.AddMod();
var test_pex = utils.AddGameFile(@"enbstuff\test.pex", 10);
utils.Configure();
utils.AddManualDownload(
new Dictionary<string, byte[]> {{"/baz/biz.pex", File.ReadAllBytes(test_pex)}});
await CompileAndInstall(profile);
utils.VerifyInstalledGameFile(@"enbstuff\test.pex");
}
[TestMethod]
public async Task TestDirectMatchIsIgnoredWhenGameFolderFilesOverrideExists()
{
var profile = utils.AddProfile();
var mod = utils.AddMod();
var test_pex = utils.AddGameFile(@"enbstuff\test.pex", 10);
utils.Configure();
Directory.CreateDirectory(Path.Combine(utils.MO2Folder, Consts.GameFolderFilesDir));
utils.AddManualDownload(
new Dictionary<string, byte[]> {{"/baz/biz.pex", File.ReadAllBytes(test_pex)}});
await CompileAndInstall(profile);
Assert.IsFalse(File.Exists(Path.Combine(utils.InstallFolder, Consts.GameFolderFilesDir, @"enbstuff\test.pex")));
}
[TestMethod]
public async Task TestDuplicateFilesAreCopied()

View File

@ -177,7 +177,26 @@ namespace Wabbajack.Test
Assert.Fail($"Index {x} of {mod}\\{file} are not the same");
}
}
public void VerifyInstalledGameFile(string file)
{
var src = Path.Combine(GameFolder, file);
Assert.IsTrue(File.Exists(src), src);
var dest = Path.Combine(InstallFolder, Consts.GameFolderFilesDir, file);
Assert.IsTrue(File.Exists(dest), dest);
var src_data = File.ReadAllBytes(src);
var dest_data = File.ReadAllBytes(dest);
Assert.AreEqual(src_data.Length, dest_data.Length);
for(int x = 0; x < src_data.Length; x++)
{
if (src_data[x] != dest_data[x])
Assert.Fail($"Index {x} of {Consts.GameFolderFilesDir}\\{file} are not the same");
}
}
public string PathOfInstalledFile(string mod, string file)
{
return Path.Combine(InstallFolder, "mods", mod, file);
@ -218,5 +237,15 @@ namespace Wabbajack.Test
}
}
}
public string AddGameFile(string path, int i)
{
var full_path = Path.Combine(GameFolder, path);
var dir = Path.GetDirectoryName(full_path);
if (!Directory.Exists(dir))
Directory.CreateDirectory(dir);
GenerateRandomFileData(full_path, i);
return full_path;
}
}
}