mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-07-08 18:06:41 +00:00
Minor cleanup
This commit is contained in:
@@ -25,6 +25,7 @@ Options:
|
||||
-c, --hash Output file hashes
|
||||
-f, --file Print to file only
|
||||
-j, --json Print info as JSON
|
||||
-r, --recursive Recursively print info from embedded files
|
||||
```
|
||||
|
||||
## ExtractionTool
|
||||
|
||||
@@ -4,7 +4,6 @@ using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.Data.Extensions;
|
||||
using SabreTools.Data.Models.ISO9660;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Matching;
|
||||
using SabreTools.Numerics.Extensions;
|
||||
using SabreTools.Text.Extensions;
|
||||
@@ -18,7 +17,7 @@ namespace SabreTools.Wrappers
|
||||
/// <summary>
|
||||
/// List of printed embedded files by their sector offset
|
||||
/// </summary>
|
||||
private readonly HashSet<int> printedFiles = [];
|
||||
private readonly HashSet<int> _printedFiles = [];
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -33,7 +32,7 @@ namespace SabreTools.Wrappers
|
||||
/// <inheritdoc/>
|
||||
public void PrintInformation(StringBuilder builder, bool recursive)
|
||||
{
|
||||
printedFiles.Clear();
|
||||
_printedFiles.Clear();
|
||||
|
||||
builder.AppendLine("ISO 9660 Information:");
|
||||
builder.AppendLine("-------------------------");
|
||||
@@ -113,15 +112,15 @@ namespace SabreTools.Wrappers
|
||||
continue;
|
||||
|
||||
// Add extent before recursion
|
||||
if (!printedFiles.Contains(dr.ExtentLocation.LittleEndian))
|
||||
if (!_printedFiles.Contains(dr.ExtentLocation.LittleEndian))
|
||||
{
|
||||
printedFiles.Add(dr.ExtentLocation.LittleEndian);
|
||||
_printedFiles.Add(dr.ExtentLocation.LittleEndian);
|
||||
RecursivePrint(builder, dr.ExtentLocation.LittleEndian, path, encoding, blockLength, initialOffset);
|
||||
}
|
||||
|
||||
if (!dr.ExtentLocation.IsValid && !printedFiles.Contains(dr.ExtentLocation.BigEndian))
|
||||
if (!dr.ExtentLocation.IsValid && !_printedFiles.Contains(dr.ExtentLocation.BigEndian))
|
||||
{
|
||||
printedFiles.Add(dr.ExtentLocation.BigEndian);
|
||||
_printedFiles.Add(dr.ExtentLocation.BigEndian);
|
||||
RecursivePrint(builder, dr.ExtentLocation.BigEndian, path, encoding, blockLength, initialOffset);
|
||||
}
|
||||
}
|
||||
@@ -132,11 +131,11 @@ namespace SabreTools.Wrappers
|
||||
continue;
|
||||
|
||||
// Print embedded file from LittleEndian location
|
||||
if (!printedFiles.Contains(dr.ExtentLocation.LittleEndian))
|
||||
if (!_printedFiles.Contains(dr.ExtentLocation.LittleEndian))
|
||||
{
|
||||
try
|
||||
{
|
||||
long offset = initialOffset + ((long)dr.ExtentLocation.LittleEndian + (long)dr.ExtendedAttributeRecordLength) * (long)blockLength;
|
||||
long offset = initialOffset + ((dr.ExtentLocation.LittleEndian + (long)dr.ExtendedAttributeRecordLength) * blockLength);
|
||||
var wrapper = GetFileWrapper(offset, filename);
|
||||
if (wrapper is not null && wrapper is IPrintable printable)
|
||||
{
|
||||
@@ -145,7 +144,7 @@ namespace SabreTools.Wrappers
|
||||
builder.AppendLine("-------------------------");
|
||||
printable.PrintInformation(builder, true);
|
||||
|
||||
printedFiles.Add(dr.ExtentLocation.LittleEndian);
|
||||
_printedFiles.Add(dr.ExtentLocation.LittleEndian);
|
||||
}
|
||||
}
|
||||
catch
|
||||
@@ -156,11 +155,11 @@ namespace SabreTools.Wrappers
|
||||
}
|
||||
|
||||
// Print embedded file from BigEndian location
|
||||
if (!dr.ExtentLocation.IsValid && !printedFiles.Contains(dr.ExtentLocation.BigEndian))
|
||||
if (!dr.ExtentLocation.IsValid && !_printedFiles.Contains(dr.ExtentLocation.BigEndian))
|
||||
{
|
||||
try
|
||||
{
|
||||
long offset = initialOffset + (dr.ExtentLocation.BigEndian + dr.ExtendedAttributeRecordLength) * blockLength;
|
||||
long offset = initialOffset + ((dr.ExtentLocation.BigEndian + dr.ExtendedAttributeRecordLength) * blockLength);
|
||||
var wrapper = GetFileWrapper(offset, filename);
|
||||
if (wrapper is not null && wrapper is IPrintable printable)
|
||||
{
|
||||
@@ -169,7 +168,7 @@ namespace SabreTools.Wrappers
|
||||
builder.AppendLine("-------------------------");
|
||||
printable.PrintInformation(builder, true);
|
||||
|
||||
printedFiles.Add(dr.ExtentLocation.BigEndian);
|
||||
_printedFiles.Add(dr.ExtentLocation.BigEndian);
|
||||
}
|
||||
}
|
||||
catch
|
||||
@@ -185,8 +184,10 @@ namespace SabreTools.Wrappers
|
||||
private IWrapper? GetFileWrapper(long offset, string filename)
|
||||
{
|
||||
_dataSource.Seek(offset, SeekOrigin.Begin);
|
||||
|
||||
byte[] magic = _dataSource.PeekBytes(16);
|
||||
string extension = Path.GetExtension(filename).TrimStart('.');
|
||||
|
||||
WrapperType ft = WrapperFactory.GetFileType(magic, extension);
|
||||
return WrapperFactory.CreateWrapper(ft, _dataSource);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.Data.Models.XDVDFS;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Numerics.Extensions;
|
||||
using SabreTools.Text.Extensions;
|
||||
|
||||
@@ -16,7 +15,7 @@ namespace SabreTools.Wrappers
|
||||
/// <summary>
|
||||
/// List of printed embedded files by their sector offset
|
||||
/// </summary>
|
||||
private readonly HashSet<uint> printedFiles = [];
|
||||
private readonly HashSet<uint> _printedFiles = [];
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -31,7 +30,7 @@ namespace SabreTools.Wrappers
|
||||
/// <inheritdoc/>
|
||||
public void PrintInformation(StringBuilder builder, bool recursive)
|
||||
{
|
||||
printedFiles.Clear();
|
||||
_printedFiles.Clear();
|
||||
|
||||
builder.AppendLine("Xbox DVD Filesystem Information:");
|
||||
builder.AppendLine("-------------------------");
|
||||
@@ -57,23 +56,23 @@ namespace SabreTools.Wrappers
|
||||
|
||||
private void RecursivePrint(StringBuilder builder, uint sectorNumber, string filePath, long initialOffset)
|
||||
{
|
||||
if (!Model.DirectoryDescriptors.ContainsKey(sectorNumber))
|
||||
if (!Model.DirectoryDescriptors.TryGetValue(sectorNumber, out DirectoryDescriptor? dd))
|
||||
return;
|
||||
|
||||
foreach (DirectoryRecord dr in Model.DirectoryDescriptors[sectorNumber].DirectoryRecords)
|
||||
foreach (DirectoryRecord dr in dd.DirectoryRecords)
|
||||
{
|
||||
string filename = Encoding.UTF8.GetString(dr.Filename);
|
||||
string path = Path.Combine(filePath, filename);
|
||||
|
||||
// Skip already printed files
|
||||
if (printedFiles.Contains(dr.ExtentOffset))
|
||||
if (_printedFiles.Contains(dr.ExtentOffset))
|
||||
continue;
|
||||
|
||||
// Recurse into directory
|
||||
if ((dr.FileFlags & FileFlags.DIRECTORY) == FileFlags.DIRECTORY)
|
||||
{
|
||||
// Add directory extent before recursing
|
||||
printedFiles.Add(dr.ExtentOffset);
|
||||
_printedFiles.Add(dr.ExtentOffset);
|
||||
|
||||
RecursivePrint(builder, dr.ExtentOffset, path, initialOffset);
|
||||
continue;
|
||||
@@ -82,9 +81,11 @@ namespace SabreTools.Wrappers
|
||||
// Parse embedded file
|
||||
try
|
||||
{
|
||||
_dataSource.Seek(initialOffset + Constants.SectorSize * dr.ExtentOffset, SeekOrigin.Begin);
|
||||
_dataSource.Seek(initialOffset + (Constants.SectorSize * dr.ExtentOffset), SeekOrigin.Begin);
|
||||
|
||||
byte[] magic = _dataSource.PeekBytes(16);
|
||||
string extension = Path.GetExtension(filename).TrimStart('.');
|
||||
|
||||
WrapperType ft = WrapperFactory.GetFileType(magic, extension);
|
||||
var wrapper = WrapperFactory.CreateWrapper(ft, _dataSource);
|
||||
if (wrapper is null || wrapper is not IPrintable printable)
|
||||
@@ -95,7 +96,7 @@ namespace SabreTools.Wrappers
|
||||
builder.AppendLine("-------------------------");
|
||||
printable.PrintInformation(builder, true);
|
||||
|
||||
printedFiles.Add(dr.ExtentOffset);
|
||||
_printedFiles.Add(dr.ExtentOffset);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user