diff --git a/BurnOutSharp/FileType/BFPK.cs b/BurnOutSharp/FileType/BFPK.cs
index 030848ca..22cbde80 100644
--- a/BurnOutSharp/FileType/BFPK.cs
+++ b/BurnOutSharp/FileType/BFPK.cs
@@ -102,6 +102,9 @@ namespace BurnOutSharp.FileType
}
catch { }
+ // Remove temporary path references
+ Utilities.StripFromKeys(protections, tempPath);
+
return protections;
}
catch { }
diff --git a/BurnOutSharp/FileType/BZip2.cs b/BurnOutSharp/FileType/BZip2.cs
index 5aee4645..fba6077c 100644
--- a/BurnOutSharp/FileType/BZip2.cs
+++ b/BurnOutSharp/FileType/BZip2.cs
@@ -49,6 +49,9 @@ namespace BurnOutSharp.FileType
}
catch { }
+ // Remove temporary path references
+ Utilities.StripFromKeys(protections, tempPath);
+
return protections;
}
catch { }
diff --git a/BurnOutSharp/FileType/GZIP.cs b/BurnOutSharp/FileType/GZIP.cs
index e1e3aac7..7bbb804a 100644
--- a/BurnOutSharp/FileType/GZIP.cs
+++ b/BurnOutSharp/FileType/GZIP.cs
@@ -52,6 +52,9 @@ namespace BurnOutSharp.FileType
}
catch { }
+ // Remove temporary path references
+ Utilities.StripFromKeys(protections, tempPath);
+
return protections;
}
catch { }
diff --git a/BurnOutSharp/FileType/InstallShieldCAB.cs b/BurnOutSharp/FileType/InstallShieldCAB.cs
index d90ffb55..dd8ce43b 100644
--- a/BurnOutSharp/FileType/InstallShieldCAB.cs
+++ b/BurnOutSharp/FileType/InstallShieldCAB.cs
@@ -61,6 +61,9 @@ namespace BurnOutSharp.FileType
}
catch { }
+ // Remove temporary path references
+ Utilities.StripFromKeys(protections, tempPath);
+
return protections;
}
catch { }
diff --git a/BurnOutSharp/FileType/MPQ.cs b/BurnOutSharp/FileType/MPQ.cs
index e791db4e..d9035197 100644
--- a/BurnOutSharp/FileType/MPQ.cs
+++ b/BurnOutSharp/FileType/MPQ.cs
@@ -60,6 +60,9 @@ namespace BurnOutSharp.FileType
}
catch { }
+ // Remove temporary path references
+ Utilities.StripFromKeys(protections, tempPath);
+
return protections;
}
catch { }
diff --git a/BurnOutSharp/FileType/MSI.cs b/BurnOutSharp/FileType/MSI.cs
index f04af890..9c5f6738 100644
--- a/BurnOutSharp/FileType/MSI.cs
+++ b/BurnOutSharp/FileType/MSI.cs
@@ -39,6 +39,9 @@ namespace BurnOutSharp.FileType
}
catch { }
+ // Remove temporary path references
+ Utilities.StripFromKeys(protections, tempPath);
+
return protections;
}
catch { }
diff --git a/BurnOutSharp/FileType/MicrosoftCAB.cs b/BurnOutSharp/FileType/MicrosoftCAB.cs
index 78a54099..932ff599 100644
--- a/BurnOutSharp/FileType/MicrosoftCAB.cs
+++ b/BurnOutSharp/FileType/MicrosoftCAB.cs
@@ -48,6 +48,9 @@ namespace BurnOutSharp.FileType
}
catch { }
+ // Remove temporary path references
+ Utilities.StripFromKeys(protections, tempPath);
+
return protections;
}
catch { }
diff --git a/BurnOutSharp/FileType/PKZIP.cs b/BurnOutSharp/FileType/PKZIP.cs
index ece85434..18db5350 100644
--- a/BurnOutSharp/FileType/PKZIP.cs
+++ b/BurnOutSharp/FileType/PKZIP.cs
@@ -61,6 +61,9 @@ namespace BurnOutSharp.FileType
}
catch { }
+ // Remove temporary path references
+ Utilities.StripFromKeys(protections, tempPath);
+
return protections;
}
catch { }
diff --git a/BurnOutSharp/FileType/RAR.cs b/BurnOutSharp/FileType/RAR.cs
index 6f71727d..319af925 100644
--- a/BurnOutSharp/FileType/RAR.cs
+++ b/BurnOutSharp/FileType/RAR.cs
@@ -57,6 +57,9 @@ namespace BurnOutSharp.FileType
}
catch { }
+ // Remove temporary path references
+ Utilities.StripFromKeys(protections, tempPath);
+
return protections;
}
catch { }
diff --git a/BurnOutSharp/FileType/SevenZip.cs b/BurnOutSharp/FileType/SevenZip.cs
index 77813321..3a172c68 100644
--- a/BurnOutSharp/FileType/SevenZip.cs
+++ b/BurnOutSharp/FileType/SevenZip.cs
@@ -51,6 +51,9 @@ namespace BurnOutSharp.FileType
}
catch { }
+ // Remove temporary path references
+ Utilities.StripFromKeys(protections, tempPath);
+
return protections;
}
}
diff --git a/BurnOutSharp/FileType/TapeArchive.cs b/BurnOutSharp/FileType/TapeArchive.cs
index 5e8c2b98..d7756566 100644
--- a/BurnOutSharp/FileType/TapeArchive.cs
+++ b/BurnOutSharp/FileType/TapeArchive.cs
@@ -55,6 +55,9 @@ namespace BurnOutSharp.FileType
}
catch { }
+ // Remove temporary path references
+ Utilities.StripFromKeys(protections, tempPath);
+
return protections;
}
catch { }
diff --git a/BurnOutSharp/FileType/Valve.cs b/BurnOutSharp/FileType/Valve.cs
index 9aa534fc..02583479 100644
--- a/BurnOutSharp/FileType/Valve.cs
+++ b/BurnOutSharp/FileType/Valve.cs
@@ -59,6 +59,9 @@ namespace BurnOutSharp.FileType
}
catch { }
+ // Remove temporary path references
+ Utilities.StripFromKeys(protections, tempPath);
+
return protections;
}
}
diff --git a/BurnOutSharp/FileType/XZ.cs b/BurnOutSharp/FileType/XZ.cs
index fc73ad66..7d762f7d 100644
--- a/BurnOutSharp/FileType/XZ.cs
+++ b/BurnOutSharp/FileType/XZ.cs
@@ -47,6 +47,9 @@ namespace BurnOutSharp.FileType
}
catch { }
+ // Remove temporary path references
+ Utilities.StripFromKeys(protections, tempPath);
+
return protections;
}
catch { }
diff --git a/BurnOutSharp/Scanner.cs b/BurnOutSharp/Scanner.cs
index b88f4f26..fb8060f1 100644
--- a/BurnOutSharp/Scanner.cs
+++ b/BurnOutSharp/Scanner.cs
@@ -156,7 +156,8 @@ namespace BurnOutSharp
// Throw on an invalid path
else
{
- // throw new FileNotFoundException($"{path} is not a directory or file, skipping...");
+ Console.WriteLine($"{path} is not a directory or file, skipping...");
+ //throw new FileNotFoundException($"{path} is not a directory or file, skipping...");
}
}
@@ -459,6 +460,7 @@ namespace BurnOutSharp
if (SevenZip.ShouldScan(magic))
{
var subProtections = SevenZip.Scan(this, fs);
+ Utilities.PrependToKeys(protections, file);
Utilities.AppendToDictionary(protections, subProtections);
}
@@ -466,6 +468,7 @@ namespace BurnOutSharp
if (BFPK.ShouldScan(magic))
{
var subProtections = BFPK.Scan(this, fs);
+ Utilities.PrependToKeys(protections, file);
Utilities.AppendToDictionary(protections, subProtections);
}
@@ -473,6 +476,7 @@ namespace BurnOutSharp
if (BZip2.ShouldScan(magic))
{
var subProtections = BZip2.Scan(this, fs);
+ Utilities.PrependToKeys(protections, file);
Utilities.AppendToDictionary(protections, subProtections);
}
@@ -480,6 +484,7 @@ namespace BurnOutSharp
if (GZIP.ShouldScan(magic))
{
var subProtections = GZIP.Scan(this, fs);
+ Utilities.PrependToKeys(protections, file);
Utilities.AppendToDictionary(protections, subProtections);
}
@@ -487,6 +492,7 @@ namespace BurnOutSharp
if (file != null && InstallShieldCAB.ShouldScan(magic))
{
var subProtections = InstallShieldCAB.Scan(this, file);
+ Utilities.PrependToKeys(protections, file);
Utilities.AppendToDictionary(protections, subProtections);
}
@@ -494,6 +500,7 @@ namespace BurnOutSharp
if (file != null && MicrosoftCAB.ShouldScan(magic))
{
var subProtections = MicrosoftCAB.Scan(this, file);
+ Utilities.PrependToKeys(protections, file);
Utilities.AppendToDictionary(protections, subProtections);
}
@@ -501,6 +508,7 @@ namespace BurnOutSharp
if (file != null && MSI.ShouldScan(magic))
{
var subProtections = MSI.Scan(this, file);
+ Utilities.PrependToKeys(protections, file);
Utilities.AppendToDictionary(protections, subProtections);
}
@@ -508,6 +516,7 @@ namespace BurnOutSharp
if (file != null && MPQ.ShouldScan(magic))
{
var subProtections = MPQ.Scan(this, file);
+ Utilities.PrependToKeys(protections, file);
Utilities.AppendToDictionary(protections, subProtections);
}
@@ -515,6 +524,7 @@ namespace BurnOutSharp
if (PKZIP.ShouldScan(magic))
{
var subProtections = PKZIP.Scan(this, fs);
+ Utilities.PrependToKeys(protections, file);
Utilities.AppendToDictionary(protections, subProtections);
}
@@ -522,6 +532,7 @@ namespace BurnOutSharp
if (RAR.ShouldScan(magic))
{
var subProtections = RAR.Scan(this, fs);
+ Utilities.PrependToKeys(protections, file);
Utilities.AppendToDictionary(protections, subProtections);
}
@@ -529,6 +540,7 @@ namespace BurnOutSharp
if (TapeArchive.ShouldScan(magic))
{
var subProtections = TapeArchive.Scan(this, fs);
+ Utilities.PrependToKeys(protections, file);
Utilities.AppendToDictionary(protections, subProtections);
}
@@ -536,6 +548,7 @@ namespace BurnOutSharp
if (file != null && Valve.ShouldScan(magic))
{
var subProtections = Valve.Scan(this, file);
+ Utilities.PrependToKeys(protections, file);
Utilities.AppendToDictionary(protections, subProtections);
}
@@ -543,6 +556,7 @@ namespace BurnOutSharp
if (XZ.ShouldScan(magic))
{
var subProtections = XZ.Scan(this, fs);
+ Utilities.PrependToKeys(protections, file);
Utilities.AppendToDictionary(protections, subProtections);
}
}
diff --git a/BurnOutSharp/Utilities.cs b/BurnOutSharp/Utilities.cs
index 0e80c59b..6c809b93 100644
--- a/BurnOutSharp/Utilities.cs
+++ b/BurnOutSharp/Utilities.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
+using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
@@ -10,6 +11,127 @@ namespace BurnOutSharp
{
internal static class Utilities
{
+ #region Dictionary Manipulation
+
+ ///
+ /// Append one result to a results dictionary
+ ///
+ /// Dictionary to append to
+ /// Key to add information to
+ /// String value to add
+ public static void AppendToDictionary(Dictionary> original, string key, string value)
+ {
+ AppendToDictionary(original, key, new List { value });
+ }
+
+ ///
+ /// Append one result to a results dictionary
+ ///
+ /// Dictionary to append to
+ /// Key to add information to
+ /// String value to add
+ public static void AppendToDictionary(Dictionary> original, string key, List values)
+ {
+ // If the dictionary is null, just return
+ if (original == null)
+ return;
+
+ // Use a placeholder value if the key is null
+ key = key ?? "NO FILENAME";
+
+ // Add the key if needed and then append the lists
+ if (!original.ContainsKey(key))
+ original[key] = new List();
+
+ original[key].AddRange(values);
+ }
+
+ ///
+ /// Append one results dictionary to another
+ ///
+ /// Dictionary to append to
+ /// Dictionary to pull from
+ public static void AppendToDictionary(Dictionary> original, Dictionary> addition)
+ {
+ // If either dictionary is missing, just return
+ if (original == null || addition == null)
+ return;
+
+ // Loop through each of the addition keys and add accordingly
+ foreach (string key in addition.Keys)
+ {
+ if (!original.ContainsKey(key))
+ original[key] = new List();
+
+ original[key].AddRange(addition[key]);
+ }
+ }
+
+ ///
+ /// Prepend a parent path from dictionary keys, if possible
+ ///
+ /// Dictionary to strip values from
+ /// Path to strip from the keys
+ public static void PrependToKeys(Dictionary> original, string pathToPrepend)
+ {
+ // If the dictionary is missing, we can't do anything
+ if (original == null)
+ return;
+
+ // Use a placeholder value if the path is null
+ pathToPrepend = pathToPrepend ?? "ARCHIVE";
+
+ // Get a list of all of the keys
+ var keys = original.Keys.ToList();
+
+ // Iterate and reset keys
+ for (int i = 0; i < keys.Count; i++)
+ {
+ // Get the current key
+ string currentKey = keys[i];
+
+ // Otherwise, get the new key name and transfer over
+ string newKey = Path.Combine(pathToPrepend, currentKey);
+ original[newKey] = original[currentKey];
+ original.Remove(currentKey);
+ }
+ }
+
+ ///
+ /// Strip a parent path from dictionary keys, if possible
+ ///
+ /// Dictionary to strip values from
+ /// Path to strip from the keys
+ public static void StripFromKeys(Dictionary> original, string pathToStrip)
+ {
+ // If either is missing, we can't do anything
+ if (original == null || string.IsNullOrEmpty(pathToStrip))
+ return;
+
+ // Get a list of all of the keys
+ var keys = original.Keys.ToList();
+
+ // Iterate and reset keys
+ for (int i = 0; i < keys.Count; i++)
+ {
+ // Get the current key
+ string currentKey = keys[i];
+
+ // If the key doesn't start with the path, don't touch it
+ if (!currentKey.StartsWith(pathToStrip, StringComparison.OrdinalIgnoreCase))
+ continue;
+
+ // Otherwise, get the new key name and transfer over
+ string newKey = currentKey.Substring(pathToStrip.Length);
+ original[newKey] = original[currentKey];
+ original.Remove(currentKey);
+ }
+ }
+
+ #endregion
+
+ #region Byte Arrays
+
///
/// Search for a byte array in another array
///
@@ -70,6 +192,8 @@ namespace BurnOutSharp
return true;
}
+ #endregion
+
///
/// Get the file version as reported by the filesystem
///
@@ -110,60 +234,6 @@ namespace BurnOutSharp
return fsName;
}
- ///
- /// Append one result to a results dictionary
- ///
- /// Dictionary to append to
- /// Key to add information to
- /// String value to add
- public static void AppendToDictionary(Dictionary> original, string key, string value)
- {
- AppendToDictionary(original, key, new List { value });
- }
-
- ///
- /// Append one result to a results dictionary
- ///
- /// Dictionary to append to
- /// Key to add information to
- /// String value to add
- public static void AppendToDictionary(Dictionary> original, string key, List values)
- {
- // If the dictionary is null, just return
- if (original == null)
- return;
-
- // Use a placeholder value if the key is null
- key = key ?? "NO FILENAME";
-
- // Add the key if needed and then append the lists
- if (!original.ContainsKey(key))
- original[key] = new List();
-
- original[key].AddRange(values);
- }
-
- ///
- /// Append one results dictionary to another
- ///
- /// Dictionary to append to
- /// Dictionary to pull from
- public static void AppendToDictionary(Dictionary> original, Dictionary> addition)
- {
- // If either dictionary is missing, just return
- if (original == null || addition == null)
- return;
-
- // Loop through each of the addition keys and add accordingly
- foreach (string key in addition.Keys)
- {
- if (!original.ContainsKey(key))
- original[key] = new List();
-
- original[key].AddRange(addition[key]);
- }
- }
-
#region P/Invoke
// https://stackoverflow.com/questions/8819188/c-sharp-classes-to-undelete-files/8820157#8820157