Files

64 lines
2.1 KiB
C#
Raw Permalink Normal View History

2026-03-10 17:27:58 -04:00
using System;
using System.IO;
2026-03-18 16:37:59 -04:00
namespace SabreTools.Wrappers
2026-03-10 17:27:58 -04:00
{
public partial class FDS : IExtractable
{
/// <inheritdoc/>
2026-04-14 10:33:30 -04:00
/// TODO: Convert to QD as well?
2026-03-10 17:27:58 -04:00
public bool Extract(string outputDirectory, bool includeDebug)
{
// Get the base path
string baseFilename = Filename is null
? Guid.NewGuid().ToString()
: Path.GetFileNameWithoutExtension(Filename);
string basePath = Path.Combine(outputDirectory, baseFilename);
2026-04-14 12:17:42 -04:00
// Create the writer
var writer = new Serialization.Writers.FDS { Debug = includeDebug };
2026-03-10 17:27:58 -04:00
// Check if any data was extracted successfully
bool success = false;
// Header data
if (Header is not null)
{
string headerPath = $"{basePath}.hdr";
if (includeDebug) Console.WriteLine($"Attempting to extract header data to {headerPath}");
// Try to write the data
try
{
using var fs = File.Open(headerPath, FileMode.Create, FileAccess.Write, FileShare.None);
2026-04-14 12:17:42 -04:00
success |= writer.WriteHeader(Header, fs);
2026-03-10 17:27:58 -04:00
}
catch (Exception ex)
{
if (includeDebug) Console.Error.WriteLine(ex);
}
}
2026-04-14 10:33:30 -04:00
// ROM data
2026-03-10 17:27:58 -04:00
if (Model.Data.Length > 0)
{
2026-04-14 10:33:30 -04:00
string romPath = $"{basePath}.bin";
if (includeDebug) Console.WriteLine($"Attempting to extract ROM data to {romPath}");
2026-03-10 17:27:58 -04:00
// Try to write the data
try
{
2026-04-14 10:33:30 -04:00
using var fs = File.Open(romPath, FileMode.Create, FileAccess.Write, FileShare.None);
2026-04-14 12:17:42 -04:00
success |= writer.WriteRom(Model.Data, fs);
2026-03-10 17:27:58 -04:00
}
catch (Exception ex)
{
if (includeDebug) Console.Error.WriteLine(ex);
}
}
return success;
}
}
}