mirror of
https://github.com/SabreTools/BinaryObjectScanner.git
synced 2026-09-22 14:54:56 +00:00
Use new BSP extarction code
This commit is contained in:
70
BurnOutSharp/FileType/BSP.cs
Normal file
70
BurnOutSharp/FileType/BSP.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.IO;
|
||||
using BurnOutSharp.Interfaces;
|
||||
using static BurnOutSharp.Utilities.Dictionary;
|
||||
|
||||
namespace BurnOutSharp.FileType
|
||||
{
|
||||
/// <summary>
|
||||
/// Valve Package File
|
||||
/// </summary>
|
||||
public class BSP : IScannable
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public ConcurrentDictionary<string, ConcurrentQueue<string>> Scan(Scanner scanner, string file)
|
||||
{
|
||||
if (!File.Exists(file))
|
||||
return null;
|
||||
|
||||
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
|
||||
{
|
||||
return Scan(scanner, fs, file);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ConcurrentDictionary<string, ConcurrentQueue<string>> Scan(Scanner scanner, Stream stream, string file)
|
||||
{
|
||||
// If the BSP file itself fails
|
||||
try
|
||||
{
|
||||
string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
|
||||
Directory.CreateDirectory(tempPath);
|
||||
|
||||
// Create the wrapper
|
||||
Wrappers.BSP bsp = Wrappers.BSP.Create(stream);
|
||||
if (bsp == null)
|
||||
return null;
|
||||
|
||||
// Loop through and extract all files
|
||||
bsp.ExtractAllLumps(tempPath);
|
||||
bsp.ExtractAllTextures(tempPath);
|
||||
|
||||
// Collect and format all found protections
|
||||
var protections = scanner.GetProtections(tempPath);
|
||||
|
||||
// If temp directory cleanup fails
|
||||
try
|
||||
{
|
||||
Directory.Delete(tempPath, true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (scanner.IncludeDebug) Console.WriteLine(ex);
|
||||
}
|
||||
|
||||
// Remove temporary path references
|
||||
StripFromKeys(protections, tempPath);
|
||||
|
||||
return protections;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (scanner.IncludeDebug) Console.WriteLine(ex);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -312,8 +312,7 @@ namespace BurnOutSharp.Tools
|
||||
|
||||
#region BSP
|
||||
|
||||
if (extension.Equals("bsp", StringComparison.OrdinalIgnoreCase))
|
||||
return SupportedFileType.BSP;
|
||||
// Shares an extension with VBSP so it can't be used accurately
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -574,8 +573,7 @@ namespace BurnOutSharp.Tools
|
||||
|
||||
#region VBSP
|
||||
|
||||
if (extension.Equals("bsp", StringComparison.OrdinalIgnoreCase))
|
||||
return SupportedFileType.VBSP;
|
||||
// Shares an extension with BSP so it can't be used accurately
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -619,7 +617,7 @@ namespace BurnOutSharp.Tools
|
||||
switch (fileType)
|
||||
{
|
||||
case SupportedFileType.BFPK: return new FileType.BFPK();
|
||||
case SupportedFileType.BSP: return new FileType.Valve();
|
||||
case SupportedFileType.BSP: return new FileType.BSP();
|
||||
case SupportedFileType.BZip2: return new FileType.BZip2();
|
||||
case SupportedFileType.Executable: return new FileType.Executable();
|
||||
case SupportedFileType.GCF: return new FileType.Valve();
|
||||
|
||||
Reference in New Issue
Block a user