diff --git a/Wabbajack.Common/Consts.cs b/Wabbajack.Common/Consts.cs index c7a16b0b..0b6fca64 100644 --- a/Wabbajack.Common/Consts.cs +++ b/Wabbajack.Common/Consts.cs @@ -17,7 +17,7 @@ namespace Wabbajack.Common public static string MegaPrefix = "https://mega.nz/#!"; - public static HashSet SupportedArchives = new HashSet {".zip", ".rar", ".7z", ".7zip", ".fomod", ".omod"}; + public static HashSet SupportedArchives = new HashSet {".zip", ".rar", ".7z", ".7zip", ".fomod", ".omod", ".exe"}; public static HashSet SupportedBSAs = new HashSet {".bsa", ".ba2", ".BA2"}; diff --git a/Wabbajack.Common/FileExtractor.cs b/Wabbajack.Common/FileExtractor.cs index b87d21da..2ef4b2aa 100644 --- a/Wabbajack.Common/FileExtractor.cs +++ b/Wabbajack.Common/FileExtractor.cs @@ -1,10 +1,14 @@ using System; +using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using System.Net.Http; using System.Reflection; +using System.Security.Cryptography; using Alphaleonis.Win32.Filesystem; using Compression.BSA; using ICSharpCode.SharpZipLib.GZip; +using Newtonsoft.Json; using OMODFramework; namespace Wabbajack.Common @@ -15,7 +19,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"); + ExtractResource("Wabbajack.Common.innounp.exe.gz", "innounp.exe"); } private static void ExtractResource(string from, string to) @@ -39,6 +43,8 @@ namespace Wabbajack.Common ExtractAllWithBSA(queue, source, dest); else if (source.EndsWith(".omod")) ExtractAllWithOMOD(source, dest); + else if (source.EndsWith(".exe")) + ExtractAllWithInno(source, dest); else ExtractAllWith7Zip(source, dest); } @@ -49,6 +55,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 e) + { + Utils.LogToFile($"Error while setting process priority level for innounp.exe\n{e}"); + } + + var name = Path.GetFileName(source); + try + { + while (!p.HasExited) + { + var line = p.StandardOutput.ReadLine(); + if (line == null) + break; + + if (line.Length <= 4 || line[3] != '%') + continue; + + int.TryParse(line.Substring(0, 3), out var percent); + Utils.Status($"Extracting {name} - {line.Trim()}", percent); + } + } + catch (Exception e) + { + Utils.LogToFile($"Error while reading StandardOutput for innounp.exe\n{e}"); + } + + p.WaitForExit(); + if (p.ExitCode == 0) + return; + + Utils.Log(p.StandardOutput.ReadToEnd()); + Utils.Log($"Extraction error extracting {source}"); + } + private static string ExtractAllWithOMOD(string source, string dest) { Utils.Log($"Extracting {Path.GetFileName(source)}"); @@ -108,10 +172,7 @@ namespace Wabbajack.Common CreateNoWindow = true }; - var p = new Process - { - StartInfo = info - }; + var p = new Process {StartInfo = info}; p.Start(); ChildProcessTracker.AddProcess(p); @@ -131,9 +192,9 @@ namespace Wabbajack.Common var line = p.StandardOutput.ReadLine(); if (line == null) break; - + if (line.Length <= 4 || line[3] != '%') continue; - + int.TryParse(line.Substring(0, 3), out var percent); Utils.Status($"Extracting {name} - {line.Trim()}", percent); } @@ -157,8 +218,41 @@ namespace Wabbajack.Common /// public static bool CanExtract(string v) { - v = v.ToLower(); - return Consts.SupportedArchives.Contains(v) || Consts.SupportedBSAs.Contains(v); + var ext = Path.GetExtension(v.ToLower()); + if(ext != ".exe") + return Consts.SupportedArchives.Contains(ext) || Consts.SupportedBSAs.Contains(ext); + + var info = new ProcessStartInfo + { + FileName = "innounp.exe", + Arguments = $"-t \"{v}\" ", + RedirectStandardError = true, + RedirectStandardInput = true, + RedirectStandardOutput = true, + UseShellExecute = false, + CreateNoWindow = true + }; + + var p = new Process {StartInfo = info}; + + p.Start(); + ChildProcessTracker.AddProcess(p); + + var name = Path.GetFileName(v); + while (!p.HasExited) + { + var line = p.StandardOutput.ReadLine(); + if (line == null) + break; + + if (line[0] != '#') + continue; + + Utils.Status($"Testing {name} - {line.Trim()}"); + } + + p.WaitForExit(); + return p.ExitCode == 0; } } -} \ No newline at end of file +} diff --git a/Wabbajack.Common/Wabbajack.Common.csproj b/Wabbajack.Common/Wabbajack.Common.csproj index 265ff2d8..16e66d2e 100644 --- a/Wabbajack.Common/Wabbajack.Common.csproj +++ b/Wabbajack.Common/Wabbajack.Common.csproj @@ -114,6 +114,7 @@ + @@ -128,6 +129,7 @@ + diff --git a/Wabbajack.VirtualFileSystem/VirtualFile.cs b/Wabbajack.VirtualFileSystem/VirtualFile.cs index efc9553a..9ea8b4e4 100644 --- a/Wabbajack.VirtualFileSystem/VirtualFile.cs +++ b/Wabbajack.VirtualFileSystem/VirtualFile.cs @@ -143,7 +143,7 @@ namespace Wabbajack.VirtualFileSystem Hash = abs_path.FileHash() }; - if (FileExtractor.CanExtract(Path.GetExtension(abs_path))) + if (FileExtractor.CanExtract(abs_path)) { using (var tempFolder = context.GetTemporaryFolder())