Use new SGA extraction

This commit is contained in:
Matt Nadareski
2022-12-27 01:07:46 -08:00
parent c389ea1e49
commit 18cdf9d7ed
6 changed files with 83 additions and 2 deletions

View File

@@ -1,5 +1,8 @@
namespace BurnOutSharp.Models.SGA
{
/// <summary>
/// SGA game archive
/// </summary>
/// <see href="https://github.com/RavuAlHemio/hllib/blob/master/HLLib/SGAFile.h"/>
public class File
{

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>
/// SGA game archive
/// </summary>
public class SGA : 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 SGA file itself fails
try
{
string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(tempPath);
// Create the wrapper
Wrappers.SGA sga = Wrappers.SGA.Create(stream);
if (sga == null)
return null;
// Loop through and extract all files
sga.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

@@ -473,6 +473,14 @@ namespace BurnOutSharp
AppendToDictionary(protections, subProtections);
}
// SGA
if (scannable is SGA)
{
var subProtections = scannable.Scan(this, stream, fileName);
PrependToKeys(subProtections, fileName);
AppendToDictionary(protections, subProtections);
}
// Tape Archive
if (scannable is TapeArchive)
{

View File

@@ -640,6 +640,7 @@ namespace BurnOutSharp.Tools
case SupportedFileType.RAR: return new FileType.RAR();
case SupportedFileType.SevenZip: return new FileType.SevenZip();
case SupportedFileType.SFFS: return new FileType.SFFS();
case SupportedFileType.SGA: return new FileType.SGA();
case SupportedFileType.TapeArchive: return new FileType.TapeArchive();
case SupportedFileType.Textfile: return new FileType.Textfile();
case SupportedFileType.VBSP: return new FileType.VBSP();

View File

@@ -166,7 +166,7 @@ Below is a list of container formats that are supported in some way:
| PlayJ audio file (PLJ) | No | Yes | No | |
| Portable Executable | Yes | Yes | No* | Some packed executables are supported |
| RAR archive (RAR) | No | Yes | Yes | Via `SharpCompress` |
| SGA? | No | No | No | Skeleton only |
| SGA game archive | Yes | Yes | Yes | |
| StarForce Filesystem file (SFFS) | No | Yes | No | Skeleton only |
| Tape archive (TAR) | No | Yes | Yes | Via `SharpCompress` |
| Valve Package File (VPK) | Yes | Yes | Yes | |

View File

@@ -424,7 +424,7 @@ namespace Test
pak.Print();
}
// PAK
// SGA
else if (ft == SupportedFileType.SGA)
{
// Build the archive information