Skip to content

Commit

Permalink
Use System.IO.Hashing.Crc32
Browse files Browse the repository at this point in the history
  • Loading branch information
xPaw committed Jan 7, 2024
1 parent 0becf3c commit fd4f57b
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 90 deletions.
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
</PropertyGroup>
<PropertyGroup>
<Authors>ValvePak Contributors</Authors>
Expand Down
1 change: 0 additions & 1 deletion ValvePak/ValvePak.Test/ValvePak.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<IsTestProject>true</IsTestProject>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>../ValvePak/ValvePak.snk</AssemblyOriginatorKeyFile>
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
</PropertyGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion ValvePak/ValvePak/Package.Read.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Hashing;
using System.IO.MemoryMappedFiles;
using System.Runtime.CompilerServices;
using System.Text;
Expand Down Expand Up @@ -158,7 +159,7 @@ public void ReadEntry(PackageEntry entry, byte[] output, bool validateCrc = true
return;
}

var actualChecksum = Crc32.Compute(output, totalLength);
var actualChecksum = Crc32.HashToUInt32(output.AsSpan(0, totalLength));

if (entry.CRC32 != actualChecksum)
{
Expand Down
3 changes: 2 additions & 1 deletion ValvePak/ValvePak/Package.Save.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Buffers;
using System.Collections.Generic;
using System.IO;
using System.IO.Hashing;
using System.Security.Cryptography;
using System.Text;

Expand Down Expand Up @@ -71,7 +72,7 @@ public PackageEntry AddFile(string filePath, byte[] fileData)
DirectoryName = directory,
TypeName = extension,
SmallData = fileData,
CRC32 = Crc32.Compute(fileData, fileData.Length),
CRC32 = Crc32.HashToUInt32(fileData),
ArchiveIndex = 0x7FFF,
};

Expand Down
84 changes: 0 additions & 84 deletions ValvePak/ValvePak/Utilities/Crc32.cs

This file was deleted.

6 changes: 3 additions & 3 deletions ValvePak/ValvePak/ValvePak.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
<PackageIcon>logo.png</PackageIcon>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>ValvePak.snk</AssemblyOriginatorKeyFile>
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.IO.Hashing" Version="8.0.0" />
<PackageReference Include="System.Security.Cryptography.Algorithms" Version="4.3.1" />
</ItemGroup>

<ItemGroup>
<None Include="..\..\README.md" Pack="true" PackagePath="\"/>
<None Include="..\..\Misc\logo.png" Pack="true" PackagePath="\"/>
<None Include="..\..\README.md" Pack="true" PackagePath="\" />
<None Include="..\..\Misc\logo.png" Pack="true" PackagePath="\" />
</ItemGroup>

</Project>

0 comments on commit fd4f57b

Please sign in to comment.