diff --git a/BurnOutSharp/FileType/BFPK.cs b/BurnOutSharp/FileType/BFPK.cs index 362084f8..282050a3 100644 --- a/BurnOutSharp/FileType/BFPK.cs +++ b/BurnOutSharp/FileType/BFPK.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Text; using SharpCompress.Compressors; using SharpCompress.Compressors.Deflate; @@ -88,7 +89,9 @@ namespace BurnOutSharp.FileType } } - string protection = ProtectionFind.ScanContent(tempFile, includePosition); + // Collect and format all found protections + var fileProtections = ProtectionFind.Scan(tempFile, includePosition); + string protection = string.Join("\r\n", fileProtections.Select(kvp => kvp.Key + ": " + kvp.Value.TrimEnd())); // If tempfile cleanup fails try diff --git a/BurnOutSharp/FileType/BZip2.cs b/BurnOutSharp/FileType/BZip2.cs index 279c528f..e06a1486 100644 --- a/BurnOutSharp/FileType/BZip2.cs +++ b/BurnOutSharp/FileType/BZip2.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using SharpCompress.Compressors; using SharpCompress.Compressors.BZip2; @@ -31,18 +32,20 @@ namespace BurnOutSharp.FileType // If an individual entry fails try { - string tempfile = Path.Combine(tempPath, Guid.NewGuid().ToString()); - using (FileStream fs = File.OpenWrite(tempfile)) + string tempFile = Path.Combine(tempPath, Guid.NewGuid().ToString()); + using (FileStream fs = File.OpenWrite(tempFile)) { bz2File.CopyTo(fs); } - string protection = ProtectionFind.ScanContent(tempfile, includePosition); + // Collect and format all found protections + var fileProtections = ProtectionFind.Scan(tempFile, includePosition); + string protection = string.Join("\r\n", fileProtections.Select(kvp => kvp.Key + ": " + kvp.Value.TrimEnd())); // If tempfile cleanup fails try { - File.Delete(tempfile); + File.Delete(tempFile); } catch { } diff --git a/BurnOutSharp/FileType/GZIP.cs b/BurnOutSharp/FileType/GZIP.cs index 744d498c..5c88ef4e 100644 --- a/BurnOutSharp/FileType/GZIP.cs +++ b/BurnOutSharp/FileType/GZIP.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using SharpCompress.Archives; using SharpCompress.Archives.GZip; @@ -37,14 +38,17 @@ namespace BurnOutSharp.FileType if (entry.IsDirectory) continue; - string tempfile = Path.Combine(tempPath, entry.Key); - entry.WriteToFile(tempfile); - string protection = ProtectionFind.ScanContent(tempfile, includePosition); + string tempFile = Path.Combine(tempPath, entry.Key); + entry.WriteToFile(tempFile); + + // Collect and format all found protections + var fileProtections = ProtectionFind.Scan(tempFile, includePosition); + string protection = string.Join("\r\n", fileProtections.Select(kvp => kvp.Key + ": " + kvp.Value.TrimEnd())); // If tempfile cleanup fails try { - File.Delete(tempfile); + File.Delete(tempFile); } catch { } diff --git a/BurnOutSharp/FileType/InstallShieldCAB.cs b/BurnOutSharp/FileType/InstallShieldCAB.cs index 65e63496..21e4cb7b 100644 --- a/BurnOutSharp/FileType/InstallShieldCAB.cs +++ b/BurnOutSharp/FileType/InstallShieldCAB.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Text.RegularExpressions; using UnshieldSharp; @@ -50,7 +51,9 @@ namespace BurnOutSharp.FileType string tempFile = Path.Combine(tempPath, cabfile.FileName(i)); if (cabfile.FileSave(i, tempFile)) { - string protection = ProtectionFind.ScanContent(tempFile, includePosition); + // Collect and format all found protections + var fileProtections = ProtectionFind.Scan(tempFile, includePosition); + string protection = string.Join("\r\n", fileProtections.Select(kvp => kvp.Key + ": " + kvp.Value.TrimEnd())); // If tempfile cleanup fails try diff --git a/BurnOutSharp/FileType/MPQ.cs b/BurnOutSharp/FileType/MPQ.cs index 8784f866..df1e7730 100644 --- a/BurnOutSharp/FileType/MPQ.cs +++ b/BurnOutSharp/FileType/MPQ.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using StormLibSharp; namespace BurnOutSharp.FileType @@ -44,15 +45,18 @@ namespace BurnOutSharp.FileType // If an individual entry fails try { - string tempfile = Path.Combine(tempPath, sub); - Directory.CreateDirectory(Path.GetDirectoryName(tempfile)); - mpqArchive.ExtractFile(sub, tempfile); - string protection = ProtectionFind.ScanContent(tempfile, includePosition); + string tempFile = Path.Combine(tempPath, sub); + Directory.CreateDirectory(Path.GetDirectoryName(tempFile)); + mpqArchive.ExtractFile(sub, tempFile); + + // Collect and format all found protections + var fileProtections = ProtectionFind.Scan(tempFile, includePosition); + string protection = string.Join("\r\n", fileProtections.Select(kvp => kvp.Key + ": " + kvp.Value.TrimEnd())); // If tempfile cleanup fails try { - File.Delete(tempfile); + File.Delete(tempFile); } catch { } diff --git a/BurnOutSharp/FileType/MicrosoftCAB.cs b/BurnOutSharp/FileType/MicrosoftCAB.cs index 98ffe556..f44d2edb 100644 --- a/BurnOutSharp/FileType/MicrosoftCAB.cs +++ b/BurnOutSharp/FileType/MicrosoftCAB.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using LibMSPackN; namespace BurnOutSharp.FileType @@ -33,14 +34,17 @@ namespace BurnOutSharp.FileType // If an individual entry fails try { - string tempfile = Path.Combine(tempPath, sub.Filename); - sub.ExtractTo(tempfile); - string protection = ProtectionFind.ScanContent(tempfile, includePosition); + string tempFile = Path.Combine(tempPath, sub.Filename); + sub.ExtractTo(tempFile); + + // Collect and format all found protections + var fileProtections = ProtectionFind.Scan(tempFile, includePosition); + string protection = string.Join("\r\n", fileProtections.Select(kvp => kvp.Key + ": " + kvp.Value.TrimEnd())); // If tempfile cleanup fails try { - File.Delete(tempfile); + File.Delete(tempFile); } catch { } diff --git a/BurnOutSharp/FileType/PKZIP.cs b/BurnOutSharp/FileType/PKZIP.cs index cc7e5708..7e9d3f0c 100644 --- a/BurnOutSharp/FileType/PKZIP.cs +++ b/BurnOutSharp/FileType/PKZIP.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using SharpCompress.Archives; using SharpCompress.Archives.Zip; @@ -46,14 +47,17 @@ namespace BurnOutSharp.FileType if (entry.IsDirectory) continue; - string tempfile = Path.Combine(tempPath, entry.Key); - entry.WriteToFile(tempfile); - string protection = ProtectionFind.ScanContent(tempfile, includePosition); + string tempFile = Path.Combine(tempPath, entry.Key); + entry.WriteToFile(tempFile); + + // Collect and format all found protections + var fileProtections = ProtectionFind.Scan(tempFile, includePosition); + string protection = string.Join("\r\n", fileProtections.Select(kvp => kvp.Key + ": " + kvp.Value.TrimEnd())); // If tempfile cleanup fails try { - File.Delete(tempfile); + File.Delete(tempFile); } catch { } diff --git a/BurnOutSharp/FileType/RAR.cs b/BurnOutSharp/FileType/RAR.cs index bee494ff..61de179f 100644 --- a/BurnOutSharp/FileType/RAR.cs +++ b/BurnOutSharp/FileType/RAR.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using SharpCompress.Archives; using SharpCompress.Archives.Rar; @@ -42,14 +43,17 @@ namespace BurnOutSharp.FileType if (entry.IsDirectory) continue; - string tempfile = Path.Combine(tempPath, entry.Key); - entry.WriteToFile(tempfile); - string protection = ProtectionFind.ScanContent(tempfile, includePosition); + string tempFile = Path.Combine(tempPath, entry.Key); + entry.WriteToFile(tempFile); + + // Collect and format all found protections + var fileProtections = ProtectionFind.Scan(tempFile, includePosition); + string protection = string.Join("\r\n", fileProtections.Select(kvp => kvp.Key + ": " + kvp.Value.TrimEnd())); // If tempfile cleanup fails try { - File.Delete(tempfile); + File.Delete(tempFile); } catch { } diff --git a/BurnOutSharp/FileType/SevenZip.cs b/BurnOutSharp/FileType/SevenZip.cs index 4aeefa8e..252c8de9 100644 --- a/BurnOutSharp/FileType/SevenZip.cs +++ b/BurnOutSharp/FileType/SevenZip.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using SharpCompress.Archives; using SharpCompress.Archives.SevenZip; @@ -37,14 +38,17 @@ namespace BurnOutSharp.FileType if (entry.IsDirectory) continue; - string tempfile = Path.Combine(tempPath, entry.Key); - entry.WriteToFile(tempfile); - string protection = ProtectionFind.ScanContent(tempfile, includePosition); + string tempFile = Path.Combine(tempPath, entry.Key); + entry.WriteToFile(tempFile); + + // Collect and format all found protections + var fileProtections = ProtectionFind.Scan(tempFile, includePosition); + string protection = string.Join("\r\n", fileProtections.Select(kvp => kvp.Key + ": " + kvp.Value.TrimEnd())); // If tempfile cleanup fails try { - File.Delete(tempfile); + File.Delete(tempFile); } catch { } diff --git a/BurnOutSharp/FileType/TapeArchive.cs b/BurnOutSharp/FileType/TapeArchive.cs index a70539c1..31b93e82 100644 --- a/BurnOutSharp/FileType/TapeArchive.cs +++ b/BurnOutSharp/FileType/TapeArchive.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using SharpCompress.Archives; using SharpCompress.Archives.Tar; @@ -40,14 +41,17 @@ namespace BurnOutSharp.FileType if (entry.IsDirectory) continue; - string tempfile = Path.Combine(tempPath, entry.Key); - entry.WriteToFile(tempfile); - string protection = ProtectionFind.ScanContent(tempfile, includePosition); + string tempFile = Path.Combine(tempPath, entry.Key); + entry.WriteToFile(tempFile); + + // Collect and format all found protections + var fileProtections = ProtectionFind.Scan(tempFile, includePosition); + string protection = string.Join("\r\n", fileProtections.Select(kvp => kvp.Key + ": " + kvp.Value.TrimEnd())); // If tempfile cleanup fails try { - File.Delete(tempfile); + File.Delete(tempFile); } catch { } diff --git a/BurnOutSharp/FileType/Valve.cs b/BurnOutSharp/FileType/Valve.cs index 7c8bd1bb..79b2209b 100644 --- a/BurnOutSharp/FileType/Valve.cs +++ b/BurnOutSharp/FileType/Valve.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using HLExtract.Net; namespace BurnOutSharp.FileType @@ -55,7 +56,9 @@ namespace BurnOutSharp.FileType { foreach (string tempFile in Directory.EnumerateFiles(tempPath, "*", SearchOption.AllDirectories)) { - string protection = ProtectionFind.ScanContent(tempFile, includePosition); + // Collect and format all found protections + var fileProtections = ProtectionFind.Scan(tempFile, includePosition); + string protection = string.Join("\r\n", fileProtections.Select(kvp => kvp.Key + ": " + kvp.Value.TrimEnd())); // If tempfile cleanup fails try diff --git a/BurnOutSharp/FileType/XZ.cs b/BurnOutSharp/FileType/XZ.cs index 80c83929..092de2ed 100644 --- a/BurnOutSharp/FileType/XZ.cs +++ b/BurnOutSharp/FileType/XZ.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using SharpCompress.Compressors.Xz; namespace BurnOutSharp.FileType @@ -30,18 +31,20 @@ namespace BurnOutSharp.FileType // If an individual entry fails try { - string tempfile = Path.Combine(tempPath, Guid.NewGuid().ToString()); - using (FileStream fs = File.OpenWrite(tempfile)) + string tempFile = Path.Combine(tempPath, Guid.NewGuid().ToString()); + using (FileStream fs = File.OpenWrite(tempFile)) { xzFile.CopyTo(fs); } - string protection = ProtectionFind.ScanContent(tempfile, includePosition); + // Collect and format all found protections + var fileProtections = ProtectionFind.Scan(tempFile, includePosition); + string protection = string.Join("\r\n", fileProtections.Select(kvp => kvp.Key + ": " + kvp.Value.TrimEnd())); // If tempfile cleanup fails try { - File.Delete(tempfile); + File.Delete(tempFile); } catch { } diff --git a/BurnOutSharp/ProtectionFind.cs b/BurnOutSharp/ProtectionFind.cs index 46bdd1c7..5857f8bb 100644 --- a/BurnOutSharp/ProtectionFind.cs +++ b/BurnOutSharp/ProtectionFind.cs @@ -28,6 +28,11 @@ namespace BurnOutSharp { public static class ProtectionFind { + /// + /// Progress indicator + /// + private static IProgress FileProgress = null; + /// /// Scan a path to find any known copy protection(s) /// @@ -35,12 +40,18 @@ namespace BurnOutSharp /// True to include scanned copy protection position, false otherwise (default) /// Optional progress indicator that will return a float in the range from 0 to 1 /// Dictionary of filename to protection mappings, if possible + /// TODO: For all of the archives that use this, ensure that they scan the temp extraction directory, if applicable public static Dictionary Scan(string path, bool includePosition = false, IProgress progress = null) { + // Set the progress indicator, if it's not set already + if (FileProgress == null) + FileProgress = progress; + + // Initialize the protections dictionary var protections = new Dictionary(); // Checkpoint - progress?.Report(new FileProtection(null, 0, null)); + FileProgress?.Report(new FileProtection(null, 0, null)); // If we have a file if (File.Exists(path)) @@ -61,7 +72,7 @@ namespace BurnOutSharp } // Checkpoint - progress?.Report(new FileProtection(path, 1, contentProtection)); + FileProgress?.Report(new FileProtection(path, 1, contentProtection)); } // If we have a directory else if (Directory.Exists(path)) @@ -96,7 +107,7 @@ namespace BurnOutSharp } // Checkpoint - progress?.Report(new FileProtection(file, i / (float)files.Count(), contentProtection)); + FileProgress?.Report(new FileProtection(file, i / (float)files.Count(), contentProtection)); } } diff --git a/BurnOutSharp/ProtectionType/WiseInstaller.cs b/BurnOutSharp/ProtectionType/WiseInstaller.cs index 5e7d550a..39d9fe78 100644 --- a/BurnOutSharp/ProtectionType/WiseInstaller.cs +++ b/BurnOutSharp/ProtectionType/WiseInstaller.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using Wise = WiseUnpacker.WiseUnpacker; namespace BurnOutSharp.ProtectionType @@ -40,7 +41,9 @@ namespace BurnOutSharp.ProtectionType foreach (string tempFile in Directory.EnumerateFiles(tempPath, "*", SearchOption.AllDirectories)) { - string protection = ProtectionFind.ScanContent(tempFile, includePosition); + // Collect and format all found protections + var fileProtections = ProtectionFind.Scan(tempFile, includePosition); + string protection = string.Join("\r\n", fileProtections.Select(kvp => kvp.Key + ": " + kvp.Value.TrimEnd())); // If tempfile cleanup fails try diff --git a/Test/Program.cs b/Test/Program.cs index 3cbc871f..6bc21ca6 100644 --- a/Test/Program.cs +++ b/Test/Program.cs @@ -13,7 +13,7 @@ namespace Test p.ProgressChanged += Changed; foreach (string arg in args) { - string protections = String.Join("\r\n", ProtectionFind.Scan(arg, true, p).Select(kvp => kvp.Key + ": " + kvp.Value.TrimEnd())); + string protections = string.Join("\r\n", ProtectionFind.Scan(arg, true, p).Select(kvp => kvp.Key + ": " + kvp.Value.TrimEnd())); Console.WriteLine(protections); using (StreamWriter sw = new StreamWriter(File.OpenWrite($"{DateTime.Now:yyyy-MM-dd_HHmmss}.txt"))) {