support auto extraction exes as archive sources

This commit is contained in:
Timothy Baldridge 2019-09-24 05:27:43 -06:00
parent 05a0fec7fd
commit 24c948f138
6 changed files with 67 additions and 3 deletions

View File

@ -8,10 +8,10 @@ namespace VirtualFileSystem.Test
private static void Main(string[] args)
{
Utils.SetLoggerFn(s => Console.WriteLine(s));
Utils.SetStatusFn((s, i) => Console.WriteLine(s));
Utils.SetStatusFn((s, i) => Console.Write(s + "\r"));
WorkQueue.Init((a, b, c) => { },
(a, b) => { });
VFS.VirtualFileSystem.VFS.AddRoot(@"D:\tmp\Interesting NPCs SSE 3.42\Data");
VFS.VirtualFileSystem.VFS.AddRoot(@"D:\tmp\archivetests");
}
}
}

View File

@ -13,7 +13,7 @@ namespace Wabbajack.Common
public static string BSACreationDir = "TEMP_BSA_FILES";
public static string MegaPrefix = "https://mega.nz/#!";
public static HashSet<string> SupportedArchives = new HashSet<string> {".zip", ".rar", ".7z", ".7zip", ".fomod"};
public static HashSet<string> SupportedArchives = new HashSet<string> {".zip", ".rar", ".7z", ".7zip", ".fomod", ".exe"};
public static HashSet<string> SupportedBSAs = new HashSet<string> {".bsa"};
public static HashSet<string> ConfigFileExtensions = new HashSet<string> {".json", ".ini", ".yml"};

View File

@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using Alphaleonis.Win32.Filesystem;
using Compression.BSA;
@ -13,6 +14,7 @@ namespace Wabbajack.Common
{
ExtractResource("Wabbajack.Common.7z.dll.gz", "7z.dll");
ExtractResource("Wabbajack.Common.7z.exe.gz", "7z.exe");
ExtractResource("Wabbajack.Common.innounp.exe.gz", "innounp.exe");
}
private static void ExtractResource(string from, string to)
@ -34,6 +36,8 @@ namespace Wabbajack.Common
{
if (source.EndsWith(".bsa"))
ExtractAllWithBSA(source, dest);
if (source.EndsWith(".exe"))
ExtractAllWithInno(source, dest);
else
ExtractAllWith7Zip(source, dest);
}
@ -134,6 +138,64 @@ namespace Wabbajack.Common
}
}
private static void ExtractAllWithInno(string source, string dest)
{
Utils.Log($"Extracting {Path.GetFileName(source)}");
var info = new ProcessStartInfo
{
FileName = "innounp.exe",
Arguments = $"-x -y -b -d\"{dest}\" \"{source}\"",
RedirectStandardError = true,
RedirectStandardInput = true,
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
};
var p = new Process
{
StartInfo = info
};
p.Start();
ChildProcessTracker.AddProcess(p);
try
{
p.PriorityClass = ProcessPriorityClass.BelowNormal;
}
catch (Exception)
{
}
var name = Path.GetFileName(source);
try
{
while (!p.HasExited)
{
var line = p.StandardOutput.ReadLine();
if (line == null)
break;
var percent = 0;
if (line.Length > 4 && line[3] == '%')
{
int.TryParse(line.Substring(0, 3), out percent);
Utils.Status($"Extracting {name} - {line.Trim()}", percent);
}
}
}
catch (Exception ex)
{
}
p.WaitForExit();
if (p.ExitCode != 0)
{
Utils.Log(p.StandardOutput.ReadToEnd());
Utils.Log($"Extraction error extracting {source}");
}
}
/// <summary>
/// Returns true if the given extension type can be extracted
/// </summary>

View File

@ -99,6 +99,7 @@
<ItemGroup>
<EmbeddedResource Include="7z.dll.gz" />
<EmbeddedResource Include="7z.exe.gz" />
<EmbeddedResource Include="innounp.exe.gz" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
@ -110,6 +111,7 @@
<ItemGroup>
<Content Include="7z.dll" />
<Content Include="7z.exe" />
<Content Include="innounp.exe" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

Binary file not shown.

Binary file not shown.