Can include patches, still randomly fails for some reason, a race condition perhaps?

This commit is contained in:
Timothy Baldridge 2020-10-18 18:15:22 -06:00
parent 18ac41729d
commit c1c6f10b5b
3 changed files with 24 additions and 16 deletions

View File

@ -16,13 +16,13 @@ namespace Wabbajack.Lib.CompilationSteps
private readonly Dictionary<RelativePath, IGrouping<RelativePath, VirtualFile>> _indexed;
private VirtualFile? _bsa;
private Dictionary<RelativePath, IEnumerable<VirtualFile>> _indexedByName;
private MO2Compiler _mo2Compiler;
private ACompiler _compiler;
private bool _isGenericGame;
public IncludePatches(ACompiler compiler, VirtualFile? constructingFromBSA = null) : base(compiler)
{
_bsa = constructingFromBSA;
_mo2Compiler = (MO2Compiler)compiler;
_compiler = compiler;
_indexed = _compiler.IndexedFiles.Values
.SelectMany(f => f)
.GroupBy(f => f.Name.FileName)
@ -33,7 +33,7 @@ namespace Wabbajack.Lib.CompilationSteps
.GroupBy(f => f.Name.FileName)
.ToDictionary(f => f.Key, f => (IEnumerable<VirtualFile>)f);
_isGenericGame = _mo2Compiler.CompilingGame.IsGenericMO2Plugin;
_isGenericGame = _compiler.CompilingGame.IsGenericMO2Plugin;
}
public override async ValueTask<Directive?> Run(RawSourceFile source)
@ -53,13 +53,16 @@ namespace Wabbajack.Lib.CompilationSteps
_indexed.TryGetValue(nameWithoutExt, out choices);
dynamic? modIni = null;
if (_bsa == null && source.File.IsNative && source.AbsolutePath.InFolder(_mo2Compiler.MO2ModsFolder))
((MO2Compiler)_compiler).ModInis.TryGetValue(ModForFile(source.AbsolutePath), out modIni);
else if (_bsa != null)
if (_compiler is MO2Compiler)
{
var bsaPath = _bsa.FullPath.Base;
((MO2Compiler)_compiler).ModInis.TryGetValue(ModForFile(bsaPath), out modIni);
if (_bsa == null && source.File.IsNative && source.AbsolutePath.InFolder(((MO2Compiler)_compiler).MO2ModsFolder))
((MO2Compiler)_compiler).ModInis.TryGetValue(ModForFile(source.AbsolutePath), out modIni);
else if (_bsa != null)
{
var bsaPath = _bsa.FullPath.Base;
((MO2Compiler)_compiler).ModInis.TryGetValue(ModForFile(bsaPath), out modIni);
}
}
var installationFile = (string?)modIni?.General?.installationFile;
@ -105,7 +108,7 @@ namespace Wabbajack.Lib.CompilationSteps
if (patches.All(p => p.Item1))
{
var (_, bytes, file) = PickPatch(_mo2Compiler, patches);
var (_, bytes, file) = PickPatch(_compiler, patches);
e.FromHash = file.Hash;
e.ArchiveHashPath = file.MakeRelativePaths();
e.PatchID = await _compiler.IncludeFile(bytes!);

View File

@ -620,11 +620,14 @@ namespace Wabbajack.Test
var some_dds = utils.SourcePath.Combine("some_file.dds");
await some_dds.WriteAllBytesAsync(utils.RandomData());
var blerg = utils.SourcePath.Combine("file1.blerg");
await blerg.WriteAllBytesAsync(utils.RandomData());
await utils.AddManualDownload(
new Dictionary<string, byte[]>
{
{"/file1.blerg", await some_dds.ReadAllBytesAsync()},
{"file1.blerg", await some_dds.ReadAllBytesAsync()},
});
var settings = new NativeCompilerSettings
@ -635,6 +638,7 @@ namespace Wabbajack.Test
new []{"IgnoreStartsWith", "downloads"},
new []{"IncludeConfigs"},
new []{"IncludeDirectMatches"},
new []{"IncludePatches"}
}
};

View File

@ -163,12 +163,13 @@ namespace Wabbajack.Test
await using FileStream fs = await DownloadsPath.Combine(name).Create();
using ZipArchive archive = new ZipArchive(fs, ZipArchiveMode.Create);
contents.Do(kv =>
foreach (var (key, value) in contents)
{
var entry = archive.CreateEntry(kv.Key);
using var os = entry.Open();
os.Write(kv.Value, 0, kv.Value.Length);
});
Utils.Log($"Adding {value.Length.ToFileSizeString()} entry {key}");
var entry = archive.CreateEntry(key);
await using var os = entry.Open();
await os.WriteAsync(value, 0, value.Length);
}
await DownloadsPath.Combine(name + Consts.MetaFileExtension).WriteAllLinesAsync(
"[General]",