mirror of
https://github.com/SabreTools/BinaryObjectScanner.git
synced 2026-02-08 05:37:43 +00:00
51 lines
1.4 KiB
C#
51 lines
1.4 KiB
C#
using System;
|
|
using System.IO;
|
|
using BinaryObjectScanner.Interfaces;
|
|
|
|
namespace BinaryObjectScanner.FileType
|
|
{
|
|
/// <summary>
|
|
/// Half-Life Game Cache File
|
|
/// </summary>
|
|
public class GCF : IExtractable
|
|
{
|
|
/// <inheritdoc/>
|
|
public string Extract(string file, bool includeDebug)
|
|
{
|
|
if (!File.Exists(file))
|
|
return null;
|
|
|
|
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
|
|
{
|
|
return Extract(fs, file, includeDebug);
|
|
}
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public string Extract(Stream stream, string file, bool includeDebug)
|
|
{
|
|
try
|
|
{
|
|
// Create the wrapper
|
|
Wrappers.GCF gcf = Wrappers.GCF.Create(stream);
|
|
if (gcf == null)
|
|
return null;
|
|
|
|
// Create a temp output directory
|
|
string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
|
|
Directory.CreateDirectory(tempPath);
|
|
|
|
// Loop through and extract all files
|
|
gcf.ExtractAll(tempPath);
|
|
|
|
return tempPath;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (includeDebug) Console.WriteLine(ex);
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
}
|