Added 7zip archive test before extraction for .dat files

This commit is contained in:
erri120 2019-12-15 12:27:16 +01:00
parent 77539b6142
commit d2a80b25c6
No known key found for this signature in database
GPG Key ID: A8C0A18D8D4D3135
2 changed files with 45 additions and 1 deletions

View File

@ -20,7 +20,10 @@ namespace Wabbajack.Common
public static string MegaPrefix = "https://mega.nz/#!";
public static HashSet<string> SupportedArchives = new HashSet<string> {".zip", ".rar", ".7z", ".7zip", ".fomod", ".omod", ".exe"};
public static HashSet<string> SupportedArchives = new HashSet<string> {".zip", ".rar", ".7z", ".7zip", ".fomod", ".omod", ".exe", ".dat"};
// HashSet with archive extensions that need to be tested before extraction
public static HashSet<string> TestArchivesBeforeExtraction = new HashSet<string> {".dat"};
public static HashSet<string> SupportedBSAs = new HashSet<string> {".bsa", ".ba2", ".BA2"};

View File

@ -160,6 +160,47 @@ namespace Wabbajack.Common
private static void ExtractAllWith7Zip(string source, string dest)
{
if (Consts.TestArchivesBeforeExtraction.Contains(Path.GetExtension(source)))
{
Utils.Log(new GenericInfo($"Testing archive {Path.GetFileName(source)}", $"The archive {source} is being tested using 7zip.exe"));
var testInfo = new ProcessStartInfo
{
FileName = "7z.exe",
Arguments = $"t \"{source}\"",
RedirectStandardError = true,
RedirectStandardInput = true,
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
};
var testP = new Process {StartInfo = testInfo};
testP.Start();
ChildProcessTracker.AddProcess(testP);
try
{
testP.PriorityClass = ProcessPriorityClass.BelowNormal;
}
catch (Exception)
{
}
try
{
while (!testP.HasExited)
{
var line = testP.StandardOutput.ReadLine();
if (line == null)
break;
}
} catch (Exception){}
testP.WaitForExit();
if (testP.ExitCode != 0)
return;
}
Utils.Log(new GenericInfo($"Extracting {Path.GetFileName(source)}", $"The contents of {source} are being extracted to {dest} using 7zip.exe"));
var info = new ProcessStartInfo