Verify command
This commit is contained in:
+77
-1
@@ -1733,7 +1733,83 @@ namespace LibIRD
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region IRD Validation
|
||||
|
||||
/// <summary>
|
||||
/// Returns dictionary of file paths and their offset
|
||||
/// </summary>
|
||||
/// <param name="cd">CDReader object</param>
|
||||
public Dictionary<string, byte[]> GetFileHashes()
|
||||
{
|
||||
using MemoryStream headerStream = new MemoryStream(Header);
|
||||
using GZipStream gzStream = new GZipStream(headerStream, CompressionMode.Decompress);
|
||||
using MemoryStream isoStream = new MemoryStream();
|
||||
#if NETCOREAPP || NETSTANDARD || NET40_OR_GREATER
|
||||
gzStream.CopyTo(isoStream);
|
||||
#else
|
||||
byte[] buffer = new byte[SectorSize];
|
||||
int bytesRead;
|
||||
while ((bytesRead = gzStream.Read(buffer, 0, buffer.Length)) > 0)
|
||||
{
|
||||
isoStream.Write(buffer, 0, bytesRead);
|
||||
}
|
||||
#endif
|
||||
isoStream.Position = 0;
|
||||
using CDReader reader = new CDReader(isoStream);
|
||||
|
||||
// Get all file paths and their offsets
|
||||
var files = new Dictionary<string, long>();
|
||||
DiscDirectoryInfo rootDir = reader.GetDirectoryInfo("\\");
|
||||
GetFileOffsets(reader, rootDir, files);
|
||||
|
||||
// Get all paths at each offset
|
||||
var offsetToHash = new Dictionary<long, byte[]>();
|
||||
for (int i = 0; i < FileCount; i++)
|
||||
offsetToHash[FileKeys[i]] = FileHashes[i];
|
||||
|
||||
// Return dictionary of paths and hashes
|
||||
var result = new Dictionary<string, byte[]>();
|
||||
foreach (KeyValuePair<string, long> kvp in files)
|
||||
{
|
||||
if (offsetToHash.ContainsKey(kvp.Value))
|
||||
result[kvp.Key] = offsetToHash[kvp.Value];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all file paths from the ISO header
|
||||
/// </summary>
|
||||
/// <param name="reader">CDReader object</param>
|
||||
/// <param name="path">Path to look within</param>
|
||||
/// <param name="files">Dictionary of files and their offset</param>
|
||||
public void GetFileOffsets(CDReader reader, DiscDirectoryInfo path, Dictionary<string, long> files)
|
||||
{
|
||||
foreach (DiscFileInfo fileInfo in path.GetFiles())
|
||||
{
|
||||
string filePath = fileInfo.FullName;
|
||||
Range<long, long>[] fileExtent = reader.PathToClusters(filePath);
|
||||
if (fileExtent == null && fileExtent.Length == 0)
|
||||
throw new IOException($"Unexpected file extents for {filePath}");
|
||||
long offset = fileExtent[0].Offset;
|
||||
for (int i = 1; i < fileExtent.Length; i++)
|
||||
{
|
||||
if (fileExtent[i] == null)
|
||||
throw new IOException($"Unexpected file extents for {filePath}");
|
||||
if (fileExtent[i].Offset < offset)
|
||||
offset = fileExtent[i].Offset;
|
||||
}
|
||||
files[filePath] = offset;
|
||||
}
|
||||
foreach (DiscDirectoryInfo dirInfo in path.GetDirectories())
|
||||
{
|
||||
GetFileOffsets(reader, dirInfo, files);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Helper Functions
|
||||
|
||||
|
||||
+3
-11
@@ -2,12 +2,12 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<!-- Assembly Properties -->
|
||||
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64</RuntimeIdentifiers>
|
||||
<TargetFrameworks>net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
|
||||
<CheckEolTargetFramework>false</CheckEolTargetFramework>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<Version>0.9.4</Version>
|
||||
<Version>0.9.5</Version>
|
||||
<PackageOutputPath>../nupkg</PackageOutputPath>
|
||||
|
||||
<!-- Avoid inexact read with 'System.IO.Stream.Read' -->
|
||||
@@ -24,14 +24,6 @@
|
||||
<PackageLicenseExpression>GPL-3.0-only</PackageLicenseExpression>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="$(RuntimeIdentifier.StartsWith(`osx-arm`))">
|
||||
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="!$(RuntimeIdentifier.StartsWith(`osx-arm`))">
|
||||
<TargetFrameworks>net20;net35;net40;net452;net462;net472;net48;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="./README.md" Pack="true" PackagePath="" />
|
||||
@@ -44,7 +36,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="SabreTools.Hashing" Version="1.4.0" />
|
||||
<PackageReference Include="SabreTools.Hashing" Version="1.5.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user