Files
BinaryObjectScanner/BinaryObjectScanner.FileType/GCF.cs

51 lines
1.4 KiB
C#
Raw Normal View History

2022-12-25 22:55:48 -08:00
using System;
using System.IO;
using BinaryObjectScanner.Interfaces;
2022-12-25 22:55:48 -08:00
namespace BinaryObjectScanner.FileType
2022-12-25 22:55:48 -08:00
{
/// <summary>
/// Half-Life Game Cache File
/// </summary>
2023-03-09 15:07:35 -05:00
public class GCF : IExtractable
2022-12-25 22:55:48 -08:00
{
/// <inheritdoc/>
2023-03-09 17:16:39 -05:00
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))
{
2023-03-09 17:16:39 -05:00
return Extract(fs, file, includeDebug);
}
}
/// <inheritdoc/>
2023-03-09 17:16:39 -05:00
public string Extract(Stream stream, string file, bool includeDebug)
{
2023-03-09 17:16:39 -05:00
try
{
// Create the wrapper
Wrappers.GCF gcf = Wrappers.GCF.Create(stream);
2023-03-09 17:16:39 -05:00
if (gcf == null)
return null;
2023-03-09 14:39:26 -05:00
2023-03-09 17:16:39 -05:00
// Create a temp output directory
string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(tempPath);
2023-03-09 14:39:26 -05:00
2023-03-09 17:16:39 -05:00
// Loop through and extract all files
gcf.ExtractAll(tempPath);
2023-03-09 14:39:26 -05:00
2023-03-09 17:16:39 -05:00
return tempPath;
}
catch (Exception ex)
{
if (includeDebug) Console.WriteLine(ex);
return null;
}
}
2022-12-25 22:55:48 -08:00
}
}