mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
Merge branch 'master' into downloader-fixes
This commit is contained in:
commit
4dba097c40
28
Wabbajack.Common.Test/PathTests.cs
Normal file
28
Wabbajack.Common.Test/PathTests.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using Xunit;
|
||||
|
||||
namespace Wabbajack.Common.Test
|
||||
{
|
||||
public class PathTests
|
||||
{
|
||||
[Fact]
|
||||
public void CanDeleteReadOnlyFile()
|
||||
{
|
||||
var tempFile = new TempFile();
|
||||
tempFile.Path.WriteAllText("Test");
|
||||
tempFile.Path.SetReadOnly(true);
|
||||
|
||||
tempFile.Path.Delete();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanMoveReadOnlyFiles()
|
||||
{
|
||||
var tempFile = new TempFile();
|
||||
var tempFile2 = new TempFile();
|
||||
tempFile.Path.WriteAllText("Test");
|
||||
tempFile.Path.SetReadOnly(true);
|
||||
|
||||
tempFile.Path.MoveTo(tempFile2.Path);
|
||||
}
|
||||
}
|
||||
}
|
@ -146,6 +146,11 @@ namespace Wabbajack.Common
|
||||
}
|
||||
}
|
||||
|
||||
public void SetReadOnly(bool val)
|
||||
{
|
||||
IsReadOnly = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the full path the folder that contains Wabbajack.Common. This will almost always be
|
||||
/// where all the binaries for the project reside.
|
||||
@ -263,10 +268,11 @@ namespace Wabbajack.Common
|
||||
|
||||
public void Delete()
|
||||
{
|
||||
if (IsFile)
|
||||
{
|
||||
File.Delete(_path);
|
||||
}
|
||||
if (!IsFile) return;
|
||||
|
||||
if (IsReadOnly) IsReadOnly = false;
|
||||
|
||||
File.Delete(_path);
|
||||
}
|
||||
|
||||
public bool InFolder(AbsolutePath folder)
|
||||
|
@ -13,7 +13,7 @@ namespace Wabbajack.Lib.CompilationSteps
|
||||
{
|
||||
public class DeconstructBSAs : ACompilationStep
|
||||
{
|
||||
private readonly IEnumerable<string> _includeDirectly;
|
||||
private readonly IEnumerable<RelativePath> _includeDirectly;
|
||||
private readonly Func<VirtualFile, List<ICompilationStep>> _microstack;
|
||||
private readonly Func<VirtualFile, List<ICompilationStep>> _microstackWithInclude;
|
||||
private readonly MO2Compiler _mo2Compiler;
|
||||
@ -24,11 +24,11 @@ namespace Wabbajack.Lib.CompilationSteps
|
||||
_includeDirectly = _mo2Compiler.ModInis.Where(kv =>
|
||||
{
|
||||
var general = kv.Value.General;
|
||||
if (general.notes != null && general.notes.Contains(Consts.WABBAJACK_INCLUDE)) return true;
|
||||
if (general.comments != null && general.comments.Contains(Consts.WABBAJACK_INCLUDE)) return true;
|
||||
if (general.notes != null && (general.notes.Contains(Consts.WABBAJACK_INCLUDE) || general.notes.Contains(Consts.WABBAJACK_NOMATCH_INCLUDE))) return true;
|
||||
if (general.comments != null && (general.notes.Contains(Consts.WABBAJACK_INCLUDE) || general.notes.Contains(Consts.WABBAJACK_NOMATCH_INCLUDE))) return true;
|
||||
return false;
|
||||
})
|
||||
.Select(kv => $"mods\\{kv.Key}\\")
|
||||
.Select(kv => kv.Key.RelativeTo(_mo2Compiler.MO2Folder))
|
||||
.ToList();
|
||||
|
||||
_microstack = bsa => new List<ICompilationStep>
|
||||
@ -77,6 +77,13 @@ namespace Wabbajack.Lib.CompilationSteps
|
||||
|
||||
var id = Guid.NewGuid().ToString();
|
||||
|
||||
|
||||
Func<Task>? _cleanup = null;
|
||||
if (defaultInclude)
|
||||
{
|
||||
_cleanup = await source.File.Context.Stage(source.File.Children);
|
||||
}
|
||||
|
||||
var matches = await sourceFiles.PMap(_mo2Compiler.Queue, e => _mo2Compiler.RunStack(stack, new RawSourceFile(e, Consts.BSACreationDir.Combine((RelativePath)id, (RelativePath)e.Name))));
|
||||
|
||||
|
||||
@ -99,6 +106,8 @@ namespace Wabbajack.Lib.CompilationSteps
|
||||
};
|
||||
}
|
||||
|
||||
if (_cleanup != null)
|
||||
await _cleanup();
|
||||
return directive;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System.Threading.Tasks;
|
||||
using Alphaleonis.Win32.Filesystem;
|
||||
using Newtonsoft.Json;
|
||||
using Wabbajack.Common;
|
||||
|
||||
namespace Wabbajack.Lib.CompilationSteps
|
||||
{
|
||||
@ -13,7 +14,8 @@ namespace Wabbajack.Lib.CompilationSteps
|
||||
public override async ValueTask<Directive?> Run(RawSourceFile source)
|
||||
{
|
||||
var inline = source.EvolveTo<InlineFile>();
|
||||
inline.SourceDataID = await _compiler.IncludeFile(await source.AbsolutePath.ReadAllBytesAsync());
|
||||
await using var file = source.File.StagedFile.OpenRead();
|
||||
inline.SourceDataID = await _compiler.IncludeFile(await file.ReadAllAsync());
|
||||
return inline;
|
||||
}
|
||||
|
||||
|
@ -295,6 +295,53 @@ namespace Wabbajack.Test
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CanNoMatchIncludeFilesFromBSAs()
|
||||
{
|
||||
var profile = utils.AddProfile();
|
||||
var mod = utils.AddMod();
|
||||
var file = utils.AddModFile(mod, @"baz.bsa", 10);
|
||||
|
||||
await file.Parent.Combine("meta.ini").WriteAllLinesAsync(new[]
|
||||
{
|
||||
"[General]",
|
||||
"notes= asdf WABBAJACK_NOMATCH_INCLUDE asdfa"
|
||||
});
|
||||
|
||||
await utils.Configure();
|
||||
|
||||
|
||||
using var tempFile = new TempFile();
|
||||
var bsaState = new BSAStateObject
|
||||
{
|
||||
Magic = "BSA\0", Version = 0x69, ArchiveFlags = 0x107, FileFlags = 0x0,
|
||||
};
|
||||
|
||||
|
||||
var tempFileData = utils.RandomData(1024);
|
||||
|
||||
await using (var bsa = bsaState.MakeBuilder(1024 * 1024))
|
||||
{
|
||||
await bsa.AddFile(new BSAFileStateObject
|
||||
{
|
||||
Path = (RelativePath)@"matching_file.bin", Index = 0, FlipCompression = false
|
||||
}, new MemoryStream(tempFileData));
|
||||
await bsa.AddFile(
|
||||
new BSAFileStateObject()
|
||||
{
|
||||
Path = (RelativePath)@"unmatching_file.bin", Index = 1, FlipCompression = false
|
||||
}, new MemoryStream(utils.RandomData(1024)));
|
||||
await bsa.Build(file);
|
||||
}
|
||||
|
||||
var archive = utils.AddManualDownload(
|
||||
new Dictionary<string, byte[]> { { "/stuff/matching_file_data.bin", tempFileData } });
|
||||
|
||||
await CompileAndInstall(profile);
|
||||
utils.VerifyInstalledFile(mod, @"baz.bsa");
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CanInstallFilesFromBSAAndBSA()
|
||||
{
|
||||
|
@ -21,7 +21,6 @@ namespace Wabbajack
|
||||
public App()
|
||||
{
|
||||
TempFolder.EnsureInited();
|
||||
RenderOptions.ProcessRenderMode = RenderMode.Default;
|
||||
CLIOld.ParseOptions(Environment.GetCommandLineArgs());
|
||||
if (CLIArguments.Help)
|
||||
CLIOld.DisplayHelpText();
|
||||
|
Loading…
Reference in New Issue
Block a user