mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-04-05 22:01:33 +00:00
Editorconfig cleanup of ZAR
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using SabreTools.Data.Models.ZArchive;
|
||||
using SabreTools.Numerics;
|
||||
using Xunit;
|
||||
|
||||
namespace SabreTools.Data.Extensions.Test
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using SabreTools.Data.Models.ZArchive;
|
||||
using SabreTools.Numerics;
|
||||
|
||||
namespace SabreTools.Data.Extensions
|
||||
{
|
||||
|
||||
@@ -4,19 +4,19 @@ namespace SabreTools.Data.Models.ZArchive
|
||||
public static class Constants
|
||||
{
|
||||
/// <summary>
|
||||
/// Number of compressed blocks referred to by a record
|
||||
/// Number of compressed blocks referred to by a record
|
||||
/// </summary>
|
||||
public const int BlockSize = 64 * 1024;
|
||||
|
||||
/// <summary>
|
||||
/// Number of compressed blocks referred to by a record
|
||||
/// Number of compressed blocks referred to by a record
|
||||
/// </summary>
|
||||
public const int BlocksPerOffsetRecord = 16;
|
||||
|
||||
/// <summary>
|
||||
/// Number of bytes stored in an offset record
|
||||
/// </summary>
|
||||
public const int OffsetRecordSize = sizeof(ulong) + sizeof(ushort) * BlocksPerOffsetRecord;
|
||||
public const int OffsetRecordSize = sizeof(ulong) + (sizeof(ushort) * BlocksPerOffsetRecord);
|
||||
|
||||
/// <summary>
|
||||
/// Number of bytes stored in a file/directory entry
|
||||
@@ -25,7 +25,7 @@ namespace SabreTools.Data.Models.ZArchive
|
||||
|
||||
/// <summary>
|
||||
/// Number of bytes stored in the footer
|
||||
/// 6 OffsetInfo fields,
|
||||
/// 6 OffsetInfo fields,
|
||||
/// </summary>
|
||||
public const int FooterSize = 144;
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace SabreTools.Data.Models.ZArchive
|
||||
public uint NodeStartIndex { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Number of
|
||||
/// Number of
|
||||
/// </summary>
|
||||
/// <remarks>Big-endian</remarks>
|
||||
public uint Count { get; set; }
|
||||
|
||||
@@ -8,13 +8,13 @@ namespace SabreTools.Data.Models.ZArchive
|
||||
{
|
||||
/// <summary>
|
||||
/// Filename length, with MSB set to 0 for filenames less than 127 long
|
||||
/// NodeLengthShort and NodeLengthLong fields are exclusive, and one must be present
|
||||
/// NodeLengthShort and NodeLengthLong fields are exclusive, and one must be present
|
||||
/// </summary>
|
||||
public byte? NodeLengthShort { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Filename length, with prefix byte's MSB set to 1 for filenames greater than 127 long
|
||||
/// NodeLengthShort and NodeLengthLong fields are exclusive, and one must be present
|
||||
/// NodeLengthShort and NodeLengthLong fields are exclusive, and one must be present
|
||||
/// </summary>
|
||||
public ushort? NodeLengthLong { get; set; }
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using SabreTools.Data.Extensions;
|
||||
using SabreTools.Data.Models.ZArchive;
|
||||
using SabreTools.Hashing;
|
||||
using SabreTools.IO.Extensions;
|
||||
using SabreTools.Matching;
|
||||
using SabreTools.Numerics.Extensions;
|
||||
@@ -20,7 +18,7 @@ namespace SabreTools.Serialization.Readers
|
||||
return null;
|
||||
|
||||
// Simple check for a valid stream length
|
||||
if (data.Length - data.Position < Constants.FooterSize)
|
||||
if (data.Length - data.Position < Constants.FooterSize)
|
||||
return null;
|
||||
|
||||
try
|
||||
@@ -57,7 +55,7 @@ namespace SabreTools.Serialization.Readers
|
||||
return null;
|
||||
|
||||
// Seek to and then read the name table entries
|
||||
data.SeekIfPossible((long)nameTableOffset, SeekOrigin.Begin);
|
||||
data.SeekIfPossible(nameTableOffset, SeekOrigin.Begin);
|
||||
var nameTable = ParseNameTable(data, archive.Footer.SectionNameTable.Size);
|
||||
if (nameTable is null)
|
||||
return null;
|
||||
@@ -70,7 +68,7 @@ namespace SabreTools.Serialization.Readers
|
||||
return null;
|
||||
|
||||
// Seek to and then read the file tree entries
|
||||
data.SeekIfPossible((long)fileTreeOffset, SeekOrigin.Begin);
|
||||
data.SeekIfPossible(fileTreeOffset, SeekOrigin.Begin);
|
||||
var fileTree = ParseFileTree(data, archive.Footer.SectionFileTree.Size, archive.Footer.SectionNameTable.Size);
|
||||
if (fileTree is null)
|
||||
return null;
|
||||
@@ -212,10 +210,10 @@ namespace SabreTools.Serialization.Readers
|
||||
var nameEntry = new NameEntry();
|
||||
|
||||
// Cache the offset into the NameEntry table
|
||||
nameOffsets.Add(bytesRead);
|
||||
nameOffsets.Add(bytesRead);
|
||||
|
||||
// Read length of name
|
||||
uint nameLength = (uint)data.ReadByteValue();
|
||||
uint nameLength = data.ReadByteValue();
|
||||
bytesRead += 1;
|
||||
if ((nameLength & 0x80) == 0x80)
|
||||
{
|
||||
@@ -238,8 +236,8 @@ namespace SabreTools.Serialization.Readers
|
||||
nameEntries.Add(nameEntry);
|
||||
}
|
||||
|
||||
obj.NameEntries = [..nameEntries];
|
||||
obj.NameTableOffsets = [..nameOffsets];
|
||||
obj.NameEntries = [.. nameEntries];
|
||||
obj.NameTableOffsets = [.. nameOffsets];
|
||||
|
||||
return obj;
|
||||
}
|
||||
@@ -260,7 +258,7 @@ namespace SabreTools.Serialization.Readers
|
||||
{
|
||||
var nameOffsetAndFlag = data.ReadUInt32BigEndian();
|
||||
|
||||
// Validate name table offset value
|
||||
// Validate name table offset value
|
||||
if ((nameOffsetAndFlag & Constants.RootNode) > nameTableSize && nameOffsetAndFlag != Constants.RootNode)
|
||||
return null;
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
@@ -961,7 +961,7 @@ namespace SabreTools.Wrappers
|
||||
|
||||
#region ZSTD
|
||||
|
||||
// ZArchive magic is the final 4 bytes of the file: [0x16, 0x9F, 0x52, 0xD6]
|
||||
// ZArchive magic is the final 4 bytes of the file: [0x16, 0x9F, 0x52, 0xD6]
|
||||
|
||||
if (extension.Equals("zar", StringComparison.OrdinalIgnoreCase))
|
||||
return WrapperType.ZArchive;
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
using System;
|
||||
#if NET462_OR_GREATER || NETCOREAPP || NETSTANDARD2_0_OR_GREATER
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SabreTools.Data.Extensions;
|
||||
using SabreTools.Data.Models.ZArchive;
|
||||
using SabreTools.IO.Extensions;
|
||||
@@ -19,7 +17,7 @@ namespace SabreTools.Wrappers
|
||||
{
|
||||
if (_dataSource is null || !_dataSource.CanRead)
|
||||
return false;
|
||||
|
||||
|
||||
#if NET462_OR_GREATER || NETCOREAPP || NETSTANDARD2_0_OR_GREATER
|
||||
try
|
||||
{
|
||||
@@ -88,8 +86,8 @@ namespace SabreTools.Wrappers
|
||||
var dataLength = Footer.SectionCompressedData.Size;
|
||||
if (node is FileEntry file)
|
||||
{
|
||||
ulong fileOffset = ((ulong)file.FileOffsetHigh << 32) | (ulong)file.FileOffsetLow;
|
||||
ulong fileSize = ((ulong)file.FileSizeHigh << 32) | (ulong)file.FileSizeLow;
|
||||
ulong fileOffset = ((ulong)file.FileOffsetHigh << 32) | file.FileOffsetLow;
|
||||
ulong fileSize = ((ulong)file.FileSizeHigh << 32) | file.FileSizeLow;
|
||||
|
||||
// Write the output file
|
||||
if (includeDebug) Console.WriteLine($"Extracting: {outputPath}");
|
||||
@@ -102,8 +100,8 @@ namespace SabreTools.Wrappers
|
||||
{
|
||||
// Determine offset and size of next read
|
||||
ulong absoluteOffset = fileOffset + fileProgress;
|
||||
ulong blockIndex = absoluteOffset / (ulong)Constants.BlockSize;
|
||||
int recordIndex = (int)(blockIndex / (ulong)Constants.BlocksPerOffsetRecord);
|
||||
ulong blockIndex = absoluteOffset / Constants.BlockSize;
|
||||
int recordIndex = (int)(blockIndex / Constants.BlocksPerOffsetRecord);
|
||||
if (recordIndex >= OffsetRecords.Length)
|
||||
{
|
||||
if (includeDebug) Console.WriteLine($"File offset out of range: {outputPath}");
|
||||
@@ -111,16 +109,16 @@ namespace SabreTools.Wrappers
|
||||
}
|
||||
|
||||
var offsetRecord = OffsetRecords[recordIndex];
|
||||
int withinRecordIndex = (int)(blockIndex % (ulong)Constants.BlocksPerOffsetRecord);
|
||||
int withinRecordIndex = (int)(blockIndex % Constants.BlocksPerOffsetRecord);
|
||||
if (withinRecordIndex >= offsetRecord.Size.Length)
|
||||
{
|
||||
if (includeDebug) Console.WriteLine($"Blocks per record mismatch: {outputPath}");
|
||||
return false;
|
||||
}
|
||||
|
||||
int intraBlockOffset = (int)(absoluteOffset % (ulong)Constants.BlockSize);
|
||||
int bytesToRead = (int)(offsetRecord.Size[withinRecordIndex]) + 1;
|
||||
int bytesToWrite = (int)Math.Min(fileSize - fileProgress, (ulong)Constants.BlockSize - (ulong)intraBlockOffset);
|
||||
int intraBlockOffset = (int)(absoluteOffset % Constants.BlockSize);
|
||||
int bytesToRead = offsetRecord.Size[withinRecordIndex] + 1;
|
||||
int bytesToWrite = (int)Math.Min(fileSize - fileProgress, Constants.BlockSize - (ulong)intraBlockOffset);
|
||||
|
||||
ulong readOffset = dataOffset + offsetRecord.Offset;
|
||||
for (int i = 0; i < withinRecordIndex; i++)
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace SabreTools.Wrappers
|
||||
Print(builder, Footer);
|
||||
}
|
||||
|
||||
public void Print(StringBuilder builder, OffsetRecord[] records)
|
||||
private static void Print(StringBuilder builder, OffsetRecord[] records)
|
||||
{
|
||||
builder.AppendLine(" Compression Offset Records:");
|
||||
builder.AppendLine(" -------------------------");
|
||||
@@ -46,7 +46,7 @@ namespace SabreTools.Wrappers
|
||||
}
|
||||
}
|
||||
|
||||
public void Print(StringBuilder builder, NameTable nameTable)
|
||||
private static void Print(StringBuilder builder, NameTable nameTable)
|
||||
{
|
||||
builder.AppendLine(" Name Table:");
|
||||
builder.AppendLine(" -------------------------");
|
||||
@@ -72,7 +72,7 @@ namespace SabreTools.Wrappers
|
||||
}
|
||||
}
|
||||
|
||||
public void Print(StringBuilder builder, FileDirectoryEntry[] fileTree)
|
||||
private static void Print(StringBuilder builder, FileDirectoryEntry[] fileTree)
|
||||
{
|
||||
builder.AppendLine(" File Tree:");
|
||||
builder.AppendLine(" -------------------------");
|
||||
@@ -95,9 +95,9 @@ namespace SabreTools.Wrappers
|
||||
|
||||
if (node is FileEntry fe)
|
||||
{
|
||||
var fileOffset = ((ulong)fe.FileOffsetHigh << 32) | (ulong)fe.FileOffsetLow;
|
||||
var fileOffset = ((ulong)fe.FileOffsetHigh << 32) | fe.FileOffsetLow;
|
||||
builder.AppendLine(fileOffset, " File Offset");
|
||||
var fileSize = ((ulong)fe.FileSizeHigh << 32) | (ulong)fe.FileSizeLow;
|
||||
var fileSize = ((ulong)fe.FileSizeHigh << 32) | fe.FileSizeLow;
|
||||
builder.AppendLine(fileSize, " File Size");
|
||||
}
|
||||
else if (node is DirectoryEntry de)
|
||||
@@ -115,7 +115,7 @@ namespace SabreTools.Wrappers
|
||||
}
|
||||
}
|
||||
|
||||
public void Print(StringBuilder builder, Footer footer)
|
||||
private static void Print(StringBuilder builder, Footer footer)
|
||||
{
|
||||
builder.AppendLine(" Footer:");
|
||||
builder.AppendLine(" -------------------------");
|
||||
|
||||
Reference in New Issue
Block a user