Use new GCF extraction code

This commit is contained in:
Matt Nadareski
2022-12-25 22:55:48 -08:00
parent ef2f037909
commit dc3914e976
2 changed files with 70 additions and 1 deletions

View File

@@ -0,0 +1,69 @@
using System;
using System.Collections.Concurrent;
using System.IO;
using BurnOutSharp.Interfaces;
using static BurnOutSharp.Utilities.Dictionary;
namespace BurnOutSharp.FileType
{
/// <summary>
/// Half-Life Game Cache File
/// </summary>
public class GCF : 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.GCF gcf = Wrappers.GCF.Create(stream);
if (gcf == null)
return null;
// Loop through and extract all files
gcf.ExtractAll(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;
}
}
}

View File

@@ -620,7 +620,7 @@ namespace BurnOutSharp.Tools
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();
case SupportedFileType.GCF: return new FileType.GCF();
case SupportedFileType.GZIP: return new FileType.GZIP();
//case FileTypes.IniFile: return new FileType.IniFile();
case SupportedFileType.InstallShieldArchiveV3: return new FileType.InstallShieldArchiveV3();