Update Hashing to 1.4.2

This commit is contained in:
Matt Nadareski
2025-01-06 10:12:46 -05:00
parent 6b977fa075
commit 7159b21afd
13 changed files with 22 additions and 48 deletions

View File

@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks> <TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks>
@@ -24,12 +24,12 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.2"> <PackageReference Include="coverlet.collector" Version="6.0.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="SabreTools.Hashing" Version="1.4.1" /> <PackageReference Include="SabreTools.Hashing" Version="1.4.2" />
<PackageReference Include="SabreTools.Models" Version="1.5.8" /> <PackageReference Include="SabreTools.Models" Version="1.5.8" />
<PackageReference Include="xunit" Version="2.9.2" /> <PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0"> <PackageReference Include="xunit.runner.visualstudio" Version="3.0.0">

View File

@@ -42,7 +42,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="SabreTools.Hashing" Version="1.4.1" /> <PackageReference Include="SabreTools.Hashing" Version="1.4.2" />
<PackageReference Include="SabreTools.IO" Version="1.6.2" /> <PackageReference Include="SabreTools.IO" Version="1.6.2" />
<PackageReference Include="SabreTools.Matching" Version="1.5.1" /> <PackageReference Include="SabreTools.Matching" Version="1.5.1" />
<PackageReference Include="SabreTools.Models" Version="1.5.8" /> <PackageReference Include="SabreTools.Models" Version="1.5.8" />

View File

@@ -37,11 +37,11 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="SabreTools.Hashing" Version="1.4.1" /> <PackageReference Include="SabreTools.Hashing" Version="1.4.2" />
<PackageReference Include="SabreTools.IO" Version="1.6.2" /> <PackageReference Include="SabreTools.IO" Version="1.6.2" />
<PackageReference Include="SabreTools.Matching" Version="1.5.1" /> <PackageReference Include="SabreTools.Matching" Version="1.5.1" />
<PackageReference Include="SabreTools.Models" Version="1.5.8" /> <PackageReference Include="SabreTools.Models" Version="1.5.8" />
<PackageReference Include="SabreTools.Serialization" Version="1.8.4" /> <PackageReference Include="SabreTools.Serialization" Version="1.8.6" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks> <TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks>
@@ -12,7 +12,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.2"> <PackageReference Include="coverlet.collector" Version="6.0.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
</PackageReference> </PackageReference>

View File

@@ -240,7 +240,7 @@ namespace SabreTools.FileTypes.Archives
var gz = new gZip(); var gz = new gZip();
ZipReturn ret = gz.ZipFileOpen(Filename); ZipReturn ret = gz.ZipFileOpen(Filename);
ret = gz.ZipFileOpenReadStream(0, out Stream? gzstream, out ulong streamSize); ret = gz.ZipFileOpenReadStream(0, out Stream? gzstream, out ulong streamSize);
gzipEntryRom = FileTypeTool.GetInfo(gzstream, (long)streamSize, _hashTypes); gzipEntryRom = FileTypeTool.GetInfo(gzstream, _hashTypes);
gzipEntryRom.Filename = gz.GetLocalFile(0).Filename; gzipEntryRom.Filename = gz.GetLocalFile(0).Filename;
gzipEntryRom.Parent = gamename; gzipEntryRom.Parent = gamename;
gzipEntryRom.Date = (gz.TimeStamp > 0 ? gz.TimeStamp.ToString() : null); gzipEntryRom.Date = (gz.TimeStamp > 0 ? gz.TimeStamp.ToString() : null);
@@ -438,7 +438,7 @@ namespace SabreTools.FileTypes.Archives
outDir = Path.GetFullPath(outDir); outDir = Path.GetFullPath(outDir);
// If the base file is null, get the hash information // If the base file is null, get the hash information
baseFile ??= FileTypeTool.GetInfo(stream, -1, _hashTypes, keepReadOpen: true); baseFile ??= FileTypeTool.GetInfo(stream, _hashTypes, keepReadOpen: true);
// Get the output file name // Get the output file name
string outfile = Path.Combine(outDir, Utilities.GetDepotPath(baseFile.SHA1, Depth) ?? string.Empty); string outfile = Path.Combine(outDir, Utilities.GetDepotPath(baseFile.SHA1, Depth) ?? string.Empty);

View File

@@ -210,7 +210,7 @@ namespace SabreTools.FileTypes.Archives
else else
{ {
using Stream entryStream = entry.OpenEntryStream(); using Stream entryStream = entry.OpenEntryStream();
rarEntryRom = FileTypeTool.GetInfo(entryStream, entry.Size, _hashTypes); rarEntryRom = FileTypeTool.GetInfo(entryStream, _hashTypes);
} }
// Fill in common details and add to the list // Fill in common details and add to the list

View File

@@ -283,7 +283,6 @@ namespace SabreTools.FileTypes.Archives
else else
{ {
zipEntryRom = FileTypeTool.GetInfo(readStream, zipEntryRom = FileTypeTool.GetInfo(readStream,
(long)zf.GetLocalFile(i).UncompressedSize,
_hashTypes, _hashTypes,
keepReadOpen: true); keepReadOpen: true);
} }

View File

@@ -203,7 +203,7 @@ namespace SabreTools.FileTypes.Archives
else else
{ {
using Stream entryStream = entry.OpenEntryStream(); using Stream entryStream = entry.OpenEntryStream();
tarEntryRom = FileTypeTool.GetInfo(entryStream, entry.Size, _hashTypes); tarEntryRom = FileTypeTool.GetInfo(entryStream, _hashTypes);
} }
// Fill in common details and add to the list // Fill in common details and add to the list

View File

@@ -216,7 +216,7 @@ namespace SabreTools.FileTypes.Archives
else else
{ {
var xzStream = new XZStream(File.Open(Filename!, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)); var xzStream = new XZStream(File.Open(Filename!, FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
xzEntryRom = FileTypeTool.GetInfo(xzStream, size: -1, _hashTypes); xzEntryRom = FileTypeTool.GetInfo(xzStream, _hashTypes);
xzEntryRom.Filename = gamename; xzEntryRom.Filename = gamename;
xzStream.Dispose(); xzStream.Dispose();
} }
@@ -332,7 +332,7 @@ namespace SabreTools.FileTypes.Archives
outDir = Path.GetFullPath(outDir); outDir = Path.GetFullPath(outDir);
// If the base file is null, get the hash information // If the base file is null, get the hash information
baseFile ??= FileTypeTool.GetInfo(stream, -1, _hashTypes, keepReadOpen: true); baseFile ??= FileTypeTool.GetInfo(stream, _hashTypes, keepReadOpen: true);
// Get the output file name // Get the output file name
string outfile = Path.Combine(outDir, Core.Tools.Utilities.GetDepotPath(baseFile.SHA1, Depth)!); string outfile = Path.Combine(outDir, Core.Tools.Utilities.GetDepotPath(baseFile.SHA1, Depth)!);

View File

@@ -362,7 +362,6 @@ namespace SabreTools.FileTypes.Archives
else else
{ {
zipEntryRom = FileTypeTool.GetInfo(readStream, zipEntryRom = FileTypeTool.GetInfo(readStream,
(long)localFile.UncompressedSize,
_hashTypes, _hashTypes,
keepReadOpen: true); keepReadOpen: true);
} }
@@ -419,7 +418,6 @@ namespace SabreTools.FileTypes.Archives
else else
{ {
zipEntryRom = FileTypeTool.GetInfo(readStream, zipEntryRom = FileTypeTool.GetInfo(readStream,
localFile.Length,
_hashTypes, _hashTypes,
keepReadOpen: false); keepReadOpen: false);
} }

View File

@@ -64,21 +64,10 @@ namespace SabreTools.FileTypes
/// Retrieve file information for a single stream /// Retrieve file information for a single stream
/// </summary> /// </summary>
/// <param name="input">Stream to get information from</param> /// <param name="input">Stream to get information from</param>
/// <param name="size">Size of the input stream</param>
/// <param name="hashes">Hashes to include in the information</param> /// <param name="hashes">Hashes to include in the information</param>
/// <returns>Populated BaseFile object if success, null on error</returns> /// <returns>Populated BaseFile object if success, null on error</returns>
public static BaseFile GetInfo(Stream? input, long size, HashType[] hashes) public static BaseFile GetInfo(Stream? input, HashType[] hashes)
=> GetInfo(input, size, hashes, keepReadOpen: false); => GetInfo(input, hashes, keepReadOpen: false);
/// <summary>
/// Retrieve file information for a single stream
/// </summary>
/// <param name="input">Stream to get information from</param>
/// <param name="hashes">Hashes to include in the information</param>
/// <param name="keepReadOpen">Indicates if the underlying read stream should be kept open</param>
/// <returns>Populated BaseFile object if success, null on error</returns>
public static BaseFile GetInfo(Stream? input, HashType[] hashes, bool keepReadOpen)
=> GetInfo(input, size: -1, hashes, keepReadOpen);
/// <summary> /// <summary>
/// Retrieve file information for a single file /// Retrieve file information for a single file
@@ -88,7 +77,7 @@ namespace SabreTools.FileTypes
/// <param name="hashes">Hashes to include in the information</param> /// <param name="hashes">Hashes to include in the information</param>
/// <param name="keepReadOpen">Indicates if the underlying read stream should be kept open</param> /// <param name="keepReadOpen">Indicates if the underlying read stream should be kept open</param>
/// <returns>Populated BaseFile object if success, empty one on error</returns> /// <returns>Populated BaseFile object if success, empty one on error</returns>
public static BaseFile GetInfo(Stream? input, long size, HashType[] hashes, bool keepReadOpen) public static BaseFile GetInfo(Stream? input, HashType[] hashes, bool keepReadOpen)
{ {
// If we have no stream // If we have no stream
if (input == null) if (input == null)
@@ -96,20 +85,8 @@ namespace SabreTools.FileTypes
try try
{ {
try
{
// If we want to automatically set the size
if (size == -1)
size = input.Length;
}
catch
{
// Don't set the length if the stream doesn't support it
}
// TODO: Replace this with size variant when added
// Run the hashing on the input stream // Run the hashing on the input stream
var hashDict = HashTool.GetStreamHashes(input, hashes); var hashDict = HashTool.GetStreamHashesAndSize(input, hashes, out long size);
if (hashDict == null) if (hashDict == null)
return new BaseFile(); return new BaseFile();

View File

@@ -38,10 +38,10 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="SabreTools.Hashing" Version="1.4.1" /> <PackageReference Include="SabreTools.Hashing" Version="1.4.2" />
<PackageReference Include="SabreTools.IO" Version="1.6.2" /> <PackageReference Include="SabreTools.IO" Version="1.6.2" />
<PackageReference Include="SabreTools.Matching" Version="1.5.1" /> <PackageReference Include="SabreTools.Matching" Version="1.5.1" />
<PackageReference Include="SabreTools.Serialization" Version="1.8.4" /> <PackageReference Include="SabreTools.Serialization" Version="1.8.6" />
<PackageReference Include="SabreTools.Skippers" Version="1.3.1" /> <PackageReference Include="SabreTools.Skippers" Version="1.3.1" />
</ItemGroup> </ItemGroup>

View File

@@ -26,13 +26,13 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.2"> <PackageReference Include="coverlet.collector" Version="6.0.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="SabreTools.Models" Version="1.5.8" /> <PackageReference Include="SabreTools.Models" Version="1.5.8" />
<PackageReference Include="SabreTools.Serialization" Version="1.8.4" /> <PackageReference Include="SabreTools.Serialization" Version="1.8.6" />
<PackageReference Include="xunit" Version="2.9.2" /> <PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0"> <PackageReference Include="xunit.runner.visualstudio" Version="3.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>