mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-09-22 06:45:11 +00:00
Data source shennanigans
This commit is contained in:
@@ -64,6 +64,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
/// Parse a Stream into a FileEntry
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <param name="initialOffset">Initial offset to use in address comparisons</param>
|
||||
/// <returns>Filled FileEntry on success, null on error</returns>
|
||||
public static FileEntry ParseFileEntry(Stream data, long initialOffset)
|
||||
{
|
||||
|
||||
@@ -100,6 +100,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
/// <summary>
|
||||
/// Get the matching CHD version, if possible
|
||||
/// </summary>
|
||||
/// <param name="initialOffset">Initial offset to use in address comparisons</param>
|
||||
/// <returns>Matching version, 0 if none</returns>
|
||||
private static uint GetVersion(Stream data, long initialOffset)
|
||||
{
|
||||
|
||||
@@ -89,6 +89,25 @@ namespace SabreTools.Serialization.Wrappers
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the filename from the source, if possible
|
||||
/// </summary>
|
||||
/// <returns>String representing the filename on success, null otherwise</returns>
|
||||
/// <remarks>This only works if the source was a <see cref="FileStream"/></remarks>
|
||||
public string? GetFilename()
|
||||
{
|
||||
// Only streams can have a filename
|
||||
if (_dataSourceType != DataSourceType.Stream)
|
||||
return null;
|
||||
|
||||
// Only file streams can have a filename
|
||||
if (_streamData == null || _streamData is not FileStream fs)
|
||||
return null;
|
||||
|
||||
// Return the name
|
||||
return fs.Name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the usable length of the underlying data
|
||||
/// </summary>
|
||||
|
||||
@@ -53,23 +53,12 @@ namespace SabreTools.Serialization.Wrappers
|
||||
foreach (var entry in SegmentTable)
|
||||
{
|
||||
// Get end of segment data
|
||||
long offset = _initialPosition + (entry.Offset * (1 << Header.SegmentAlignmentShiftCount)) + entry.Length;
|
||||
long offset = (entry.Offset * (1 << Header.SegmentAlignmentShiftCount)) + entry.Length;
|
||||
|
||||
// Read and find the end of the relocation data
|
||||
if ((entry.FlagWord & SegmentTableEntryFlag.RELOCINFO) != 0)
|
||||
{
|
||||
Stream? dataStream = null;
|
||||
if (_byteArrayData != null)
|
||||
dataStream = new MemoryStream(_byteArrayData);
|
||||
else if (_streamData != null)
|
||||
dataStream = _streamData;
|
||||
else
|
||||
break;
|
||||
|
||||
dataStream.Seek(offset, SeekOrigin.Begin);
|
||||
var relocationData = Deserializers.NewExecutable.ParsePerSegmentData(dataStream);
|
||||
|
||||
offset = dataStream.Position;
|
||||
// TODO: When the model and deserializer get updated, fix this
|
||||
}
|
||||
|
||||
if (offset > endOfSectionData)
|
||||
|
||||
@@ -29,15 +29,16 @@ namespace SabreTools.Serialization.Wrappers
|
||||
return _archiveFilenames;
|
||||
|
||||
// If we don't have a source filename
|
||||
if (!(_streamData is FileStream fs) || string.IsNullOrEmpty(fs.Name))
|
||||
string? sourceFilename = _dataSource.GetFilename();
|
||||
if (string.IsNullOrEmpty(sourceFilename))
|
||||
return null;
|
||||
|
||||
// If the filename is not the right format
|
||||
string extension = Path.GetExtension(fs.Name).TrimStart('.');
|
||||
string? directoryName = Path.GetDirectoryName(fs.Name);
|
||||
string extension = Path.GetExtension(sourceFilename).TrimStart('.');
|
||||
string? directoryName = Path.GetDirectoryName(sourceFilename);
|
||||
string fileName = directoryName == null
|
||||
? Path.GetFileNameWithoutExtension(fs.Name)
|
||||
: Path.Combine(directoryName, Path.GetFileNameWithoutExtension(fs.Name));
|
||||
? Path.GetFileNameWithoutExtension(sourceFilename)
|
||||
: Path.Combine(directoryName, Path.GetFileNameWithoutExtension(sourceFilename));
|
||||
|
||||
if (fileName.Length < 3)
|
||||
return null;
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace SabreTools.Serialization.Wrappers
|
||||
/// <summary>
|
||||
/// Source of the original data
|
||||
/// </summary>
|
||||
private readonly DataSource _dataSource;
|
||||
protected readonly DataSource _dataSource;
|
||||
|
||||
#if NETCOREAPP
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user