a bunch of integration work, and ba2 fixes

This commit is contained in:
Timothy Baldridge 2019-10-09 23:04:28 -06:00
parent 88fa091d07
commit 473ffbd806
17 changed files with 133 additions and 125 deletions

View File

@ -22,7 +22,8 @@ namespace Compression.BSA.Test
private static void Main(string[] args)
{
foreach (var bsa in Directory.EnumerateFiles(TestDir, "*.ba2", SearchOption.AllDirectories)
.Concat(Directory.EnumerateFiles(TestDir, "*.bsa", SearchOption.AllDirectories)).Skip(200))
//.Concat(Directory.EnumerateFiles(TestDir, "*.bsa", SearchOption.AllDirectories))
)
{
Console.WriteLine($"From {bsa}");
Console.WriteLine("Cleaning Output Dir");
@ -108,13 +109,22 @@ namespace Compression.BSA.Test
Equal(pair.ai.Path, pair.bi.Path);
//Equal(pair.ai.Compressed, pair.bi.Compressed);
Equal(pair.ai.Size, pair.bi.Size);
//Equal(pair.ai.GetData(), pair.bi.GetData());
Equal(GetData(pair.ai), GetData(pair.bi));
}
}
}
}
}
private static byte[] GetData(IFile pairAi)
{
using (var ms = new MemoryStream())
{
pairAi.CopyDataTo(ms);
return ms.ToArray();
}
}
public static T ViaJson<T>(T i)
{
var settings = new JsonSerializerSettings
@ -184,8 +194,12 @@ namespace Compression.BSA.Test
if (a.Length != b.Length) throw new InvalidDataException("Byte array sizes are not equal");
for (var idx = 0; idx < a.Length; idx++)
{
if (a[idx] != b[idx])
throw new InvalidDataException($"Byte array contents not equal at {idx} - {a[idx]} vs {b[idx]}");
{
Console.WriteLine($"Byte array contents not equal at {idx} - {a[idx]} vs {b[idx]}");
}
}
}
}
}

View File

@ -104,12 +104,16 @@ namespace Compression.BSA
public BA2DX10FileEntryBuilder(BA2DX10EntryState state, Stream src)
{
_state = state;
var header_size = DDS.HeaderSizeForFormat((DXGI_FORMAT) state.PixelFormat) + 4;
new BinaryReader(src).ReadBytes((int)header_size);
_chunks = _state.Chunks.Select(ch => new ChunkBuilder(state, ch, src)).ToList();
}
public uint FileHash => _state.NameHash;
public uint DirHash => _state.DirHash;
public string FullName => _state.FullName;
public string FullName => _state.Path;
public int Index => _state.Index;
public void WriteHeader(BinaryWriter bw)
@ -148,13 +152,22 @@ namespace Compression.BSA
public ChunkBuilder(BA2DX10EntryState state, ChunkState ch, Stream src)
{
_chunk = ch;
_data = new byte[_chunk.FullSz];
using (var ms = new MemoryStream())
{
src.CopyToLimit(ms, (int)_chunk.FullSz);
_data = ms.ToArray();
}
if (_chunk.Compressed)
{
using (var ms = new MemoryStream())
using (var ds = new DeflaterOutputStream(ms))
{
ds.Write(_data, 0, _data.Length);
using (var ds = new DeflaterOutputStream(ms))
{
ds.Write(_data, 0, _data.Length);
}
_data = ms.ToArray();
}
_packSize = (uint)_data.Length;
}
@ -203,10 +216,14 @@ namespace Compression.BSA
if (state.Compressed)
{
using (var ms = new MemoryStream())
using (var ds = new DeflaterOutputStream(ms))
{
ds.Write(_data, 0, _data.Length);
using (var ds = new DeflaterOutputStream(ms))
{
ds.Write(_data, 0, _data.Length);
}
_data = ms.ToArray();
}
_size = _data.Length;
}
@ -214,7 +231,7 @@ namespace Compression.BSA
public uint FileHash => _state.NameHash;
public uint DirHash => _state.DirHash;
public string FullName => _state.FullPath;
public string FullName => _state.Path;
public int Index => _state.Index;
public void WriteHeader(BinaryWriter wtr)

View File

@ -186,25 +186,7 @@ namespace Compression.BSA
public uint Size => (uint)_chunks.Sum(f => f._fullSz) + HeaderSize + sizeof(uint);
public FileStateObject State => new BA2DX10EntryState(this);
public uint HeaderSize
{
get
{
switch ((DXGI_FORMAT) _format)
{
case DXGI_FORMAT.DXGI_FORMAT_BC1_UNORM_SRGB:
case DXGI_FORMAT.DXGI_FORMAT_BC3_UNORM_SRGB:
case DXGI_FORMAT.DXGI_FORMAT_BC4_UNORM:
case DXGI_FORMAT.DXGI_FORMAT_BC5_SNORM:
case DXGI_FORMAT.DXGI_FORMAT_BC6H_UF16:
case DXGI_FORMAT.DXGI_FORMAT_BC7_UNORM:
case DXGI_FORMAT.DXGI_FORMAT_BC7_UNORM_SRGB:
return DDS_HEADER_DXT10.Size + DDS_HEADER.Size;
default:
return DDS_HEADER.Size;
}
}
}
public uint HeaderSize => DDS.HeaderSizeForFormat((DXGI_FORMAT)_format);
public void CopyDataTo(Stream output)
{
@ -354,7 +336,7 @@ namespace Compression.BSA
public BA2DX10EntryState() { }
public BA2DX10EntryState(BA2DX10Entry ba2Dx10Entry)
{
FullName = ba2Dx10Entry.FullPath;
Path = ba2Dx10Entry.FullPath;
NameHash = ba2Dx10Entry._nameHash;
Extension = ba2Dx10Entry._extension;
DirHash = ba2Dx10Entry._dirHash;
@ -369,7 +351,7 @@ namespace Compression.BSA
Chunks = ba2Dx10Entry._chunks.Select(ch => new ChunkState(ch)).ToList();
}
public string FullName { get; set; }
public string Path { get; set; }
public List<ChunkState> Chunks { get; set; }
@ -403,7 +385,7 @@ namespace Compression.BSA
StartMip = ch._startMip;
EndMip = ch._endMip;
Align = ch._align;
Compressed = ch._packSz != null;
Compressed = ch._packSz != 0;
}
public bool Compressed { get; set; }
@ -509,13 +491,13 @@ namespace Compression.BSA
Flags = ba2FileEntry._flags;
Align = ba2FileEntry._align;
Compressed = ba2FileEntry.Compressed;
FullPath = ba2FileEntry.FullPath;
Path = ba2FileEntry.FullPath;
Extension = ba2FileEntry._extension;
Index = ba2FileEntry._index;
}
public string Extension { get; set; }
public string FullPath { get; set; }
public string Path { get; set; }
public bool Compressed { get; set; }
public uint Align { get; set; }
public uint Flags { get; set; }

View File

@ -23,6 +23,23 @@ namespace Compression.BSA
public class DDS
{
public static uint HeaderSizeForFormat(DXGI_FORMAT fmt)
{
switch (fmt)
{
case DXGI_FORMAT.DXGI_FORMAT_BC1_UNORM_SRGB:
case DXGI_FORMAT.DXGI_FORMAT_BC3_UNORM_SRGB:
case DXGI_FORMAT.DXGI_FORMAT_BC4_UNORM:
case DXGI_FORMAT.DXGI_FORMAT_BC5_SNORM:
case DXGI_FORMAT.DXGI_FORMAT_BC6H_UF16:
case DXGI_FORMAT.DXGI_FORMAT_BC7_UNORM:
case DXGI_FORMAT.DXGI_FORMAT_BC7_UNORM_SRGB:
return DDS_HEADER_DXT10.Size + DDS_HEADER.Size;
default:
return DDS_HEADER.Size;
}
}
public const int DDS_MAGIC = 0x20534444; // "DDS "
public static uint MAKEFOURCC(char ch0, char ch1, char ch2, char ch3)

View File

@ -34,6 +34,7 @@ namespace Compression.BSA
public class FileStateObject
{
public int Index { get; set; }
public string Path { get; set; }
}
public interface IFile

View File

@ -51,7 +51,6 @@ namespace Compression.BSA
return GetEncoding(version).GetString(acc.ToArray());
}
/// <summary>
/// Returns bytes for a \0 terminated string
/// </summary>

@ -1 +0,0 @@
Subproject commit 91009782d5bfe909558bde9a946bbf3c9844faec

View File

@ -17,7 +17,7 @@ namespace Wabbajack.Common
public static HashSet<string> SupportedArchives = new HashSet<string> {".zip", ".rar", ".7z", ".7zip", ".fomod", ".omod"};
public static HashSet<string> SupportedBSAs = new HashSet<string> {".bsa"};
public static HashSet<string> SupportedBSAs = new HashSet<string> {".bsa", ".ba2"};
public static HashSet<string> ConfigFileExtensions = new HashSet<string> {".json", ".ini", ".yml"};
public static HashSet<string> ESPFileExtensions = new HashSet<string>() { ".esp", ".esm", ".esl"};

View File

@ -5,7 +5,7 @@ using System.Reflection;
using Alphaleonis.Win32.Filesystem;
using Compression.BSA;
using ICSharpCode.SharpZipLib.GZip;
using OMODFramework;
//using OMODFramework;
namespace Wabbajack.Common
{
@ -35,7 +35,7 @@ namespace Wabbajack.Common
{
try
{
if (source.EndsWith(".bsa"))
if (Consts.SupportedBSAs.Any(b => source.EndsWith(b)))
ExtractAllWithBSA(source, dest);
else if (source.EndsWith(".exe"))
ExtractAllWithInno(source, dest);
@ -53,19 +53,19 @@ namespace Wabbajack.Common
private static void ExtractAllWithOMOD(string source, string dest)
{
Utils.Log($"Extracting {Path.GetFileName(source)}");
/*Utils.Log($"Extracting {Path.GetFileName(source)}");
Framework f = new Framework();
f.SetTempDirectory(dest);
OMOD omod = new OMOD(source, ref f);
omod.ExtractDataFiles();
omod.ExtractPlugins();
omod.ExtractPlugins();*/
}
private static void ExtractAllWithBSA(string source, string dest)
{
try
{
using (var arch = new BSAReader(source))
using (var arch = BSADispatch.OpenRead(source))
{
arch.Files.PMap(f =>
{
@ -216,7 +216,7 @@ namespace Wabbajack.Common
/// <returns></returns>
public static bool CanExtract(string v)
{
return Consts.SupportedArchives.Contains(v) || v == ".bsa";
return Consts.SupportedArchives.Contains(v) || Consts.SupportedBSAs.Contains(v);
}
public class Entry

View File

@ -107,10 +107,6 @@
<Project>{ff5d892f-8ff4-44fc-8f7f-cd58f307ad1b}</Project>
<Name>Compression.BSA</Name>
</ProjectReference>
<ProjectReference Include="..\OMOD-Framework\OMOD-Framework\OMOD-Framework.csproj">
<Project>{1b2576a1-0208-485f-8e79-38551e4593b4}</Project>
<Name>OMOD-Framework</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="7z.dll" />

View File

@ -30,8 +30,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wabbajack.WebAutomation.Tes
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wabbajack.Test", "Wabbajack.Test\Wabbajack.Test.csproj", "{A47FFF32-782B-4D9F-8704-C98FB32FA8CC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OMOD-Framework", "OMOD-Framework\OMOD-Framework\OMOD-Framework.csproj", "{1B2576A1-0208-485F-8E79-38551E4593B4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug (no commandargs)|Any CPU = Debug (no commandargs)|Any CPU
@ -150,18 +148,6 @@ Global
{A47FFF32-782B-4D9F-8704-C98FB32FA8CC}.Release|Any CPU.Build.0 = Release|Any CPU
{A47FFF32-782B-4D9F-8704-C98FB32FA8CC}.Release|x64.ActiveCfg = Release|Any CPU
{A47FFF32-782B-4D9F-8704-C98FB32FA8CC}.Release|x64.Build.0 = Release|Any CPU
{1B2576A1-0208-485F-8E79-38551E4593B4}.Debug (no commandargs)|Any CPU.ActiveCfg = Release|Any CPU
{1B2576A1-0208-485F-8E79-38551E4593B4}.Debug (no commandargs)|Any CPU.Build.0 = Release|Any CPU
{1B2576A1-0208-485F-8E79-38551E4593B4}.Debug (no commandargs)|x64.ActiveCfg = Release|Any CPU
{1B2576A1-0208-485F-8E79-38551E4593B4}.Debug (no commandargs)|x64.Build.0 = Release|Any CPU
{1B2576A1-0208-485F-8E79-38551E4593B4}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{1B2576A1-0208-485F-8E79-38551E4593B4}.Debug|Any CPU.Build.0 = Release|Any CPU
{1B2576A1-0208-485F-8E79-38551E4593B4}.Debug|x64.ActiveCfg = Release|Any CPU
{1B2576A1-0208-485F-8E79-38551E4593B4}.Debug|x64.Build.0 = Release|Any CPU
{1B2576A1-0208-485F-8E79-38551E4593B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1B2576A1-0208-485F-8E79-38551E4593B4}.Release|Any CPU.Build.0 = Release|Any CPU
{1B2576A1-0208-485F-8E79-38551E4593B4}.Release|x64.ActiveCfg = Release|Any CPU
{1B2576A1-0208-485F-8E79-38551E4593B4}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -13,7 +13,7 @@ namespace Wabbajack
{
public App()
{
/*
Utils.Log($"Wabbajack Build - {ThisAssembly.Git.Sha}");
SetupHandlers();
@ -28,7 +28,7 @@ namespace Wabbajack
Environment.Exit(0);
}
Environment.Exit(1);
}
}*/
}

View File

@ -432,7 +432,11 @@ namespace Wabbajack
using (var a = new BSAReader(Path.Combine(MO2Folder, bsa.To)))
{
var file = a.Files.First(e => e.Path == Path.Combine(to.Split('\\').Skip(2).ToArray()));
return file.GetData();
using (var ms = new MemoryStream())
{
file.CopyDataTo(ms);
return ms.ToArray();
}
}
}
@ -924,23 +928,16 @@ namespace Wabbajack
ExtraFiles.Add(match);
}
;
CreateBSA directive;
using (var bsa = new BSAReader(source.AbsolutePath))
{
directive = new CreateBSA
{
To = source.Path,
TempID = id,
Type = (uint) bsa.HeaderType,
FileFlags = (uint) bsa.FileFlags,
ArchiveFlags = (uint) bsa.ArchiveFlags
State = bsa.State,
FileStates = bsa.Files.Select(f => f.State).ToList()
};
}
;
return directive;
};
}

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Compression.BSA;
using Newtonsoft.Json;
using VFS;
using Wabbajack.Common;
@ -131,15 +132,9 @@ namespace Wabbajack
[Serializable]
public class CreateBSA : Directive
{
public string IsCompressed;
public bool ShareData;
public string TempID;
public uint Type;
public uint Version;
public uint FileFlags { get; set; }
public bool Compress { get; set; }
public uint ArchiveFlags { get; set; }
public ArchiveStateObject State { get; set; }
public List<FileStateObject> FileStates { get; set; }
}
[Serializable]

View File

@ -251,19 +251,15 @@ namespace Wabbajack
.ToList();
if (source_files.Count > 0)
using (var a = new BSABuilder())
using (var a = bsa.State.MakeBuilder())
{
//a.Create(Path.Combine(Outputfolder, bsa.To), (bsa_archive_type_t)bsa.Type, entries);
a.HeaderType = (VersionType) bsa.Type;
a.FileFlags = (FileFlags) bsa.FileFlags;
a.ArchiveFlags = (ArchiveFlags) bsa.ArchiveFlags;
var indexed = bsa.FileStates.ToDictionary(d => d.Path);
source_files.PMap(f =>
{
Status($"Adding {f} to BSA");
using (var fs = File.OpenRead(Path.Combine(source_dir, f)))
{
a.AddFile(f, fs);
a.AddFile(indexed[f.ToLower()], fs);
}
});

View File

@ -25,62 +25,71 @@ namespace Wabbajack
public MainWindow(RunMode mode, string source)
{
_mode = mode;
_source = source;
var args = Environment.GetCommandLineArgs();
var DebugMode = false;
string MO2Folder = null, InstallFolder = null, MO2Profile = null;
InitializeComponent();
}
var context = new AppState(Dispatcher, "Building");
DataContext = context;
WorkQueue.Init((id, msg, progress) => context.SetProgress(id, msg, progress),
(max, current) => context.SetQueueSize(max, current));
public MainWindow Start()
{
_context = new AppState(Dispatcher, "Building");
DataContext = _context;
WorkQueue.Init((id, msg, progress) => _context.SetProgress(id, msg, progress),
(max, current) => _context.SetQueueSize(max, current));
Utils.SetLoggerFn(s => context.LogMsg(s));
Utils.SetLoggerFn(s => _context.LogMsg(s));
Utils.SetStatusFn((msg, progress) => WorkQueue.Report(msg, progress));
UIUtils.Dispatcher = Dispatcher;
_state._nexusSiteURL = "https://github.com/halgari/wabbajack";
_context._nexusSiteURL = "https://github.com/halgari/wabbajack";
var thread = new Thread(() => { SetupWindow(_mode, _source, _context); });
thread.Start();
return this;
}
new Thread(() =>
private void SetupWindow(RunMode mode, string source, AppState context)
{
if (mode == RunMode.Compile)
{
if (mode == RunMode.Compile)
Utils.Log("Compiler ready to execute");
context.Location = Path.GetDirectoryName(source);
}
else if (mode == RunMode.Install)
{
context.UIReady = false;
var modlist = Installer.LoadFromFile(source);
if (modlist == null)
{
Utils.Log("Compiler ready to execute");
context.Location = Path.GetDirectoryName(source);
MessageBox.Show("Invalid Modlist, or file not found.", "Invalid Modlist", MessageBoxButton.OK,
MessageBoxImage.Error);
Dispatcher.Invoke(() =>
{
context.Running = false;
ExitWhenClosing = false;
var window = new ModeSelectionWindow();
window.ShowActivated = true;
window.Show();
Close();
});
}
else if (mode == RunMode.Install)
else
{
context.UIReady = false;
var modlist = Installer.LoadFromFile(source);
if (modlist == null)
{
MessageBox.Show("Invalid Modlist, or file not found.", "Invalid Modlist", MessageBoxButton.OK,
MessageBoxImage.Error);
Dispatcher.Invoke(() =>
{
context.Running = false;
ExitWhenClosing = false;
var window = new ModeSelectionWindow();
window.ShowActivated = true;
window.Show();
Close();
});
}
else
{
context.ConfigureForInstall(source, modlist);
}
context.ConfigureForInstall(source, modlist);
}
}
context.UIReady = true;
}).Start();
context.UIReady = true;
}
internal bool ExitWhenClosing = true;
private RunMode _mode;
private string _source;
private AppState _context;
private void Window_Closing(object sender, CancelEventArgs e)
{

View File

@ -43,7 +43,7 @@ namespace Wabbajack
if (file != null)
{
ShutdownOnClose = false;
new MainWindow(RunMode.Compile, file).Show();
new MainWindow(RunMode.Compile, file).Start().Show();
Close();
}
}
@ -54,7 +54,7 @@ namespace Wabbajack
if (file != null)
{
ShutdownOnClose = false;
new MainWindow(RunMode.Install, file).Show();
new MainWindow(RunMode.Install, file).Start().Show();
Close();
}
}