Improve diff

This commit is contained in:
Deterous
2024-01-31 23:41:46 +09:00
parent 563b05b44f
commit 1ef9f06e35
4 changed files with 36 additions and 29 deletions
+3 -3
View File
@@ -10,7 +10,7 @@
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64</RuntimeIdentifiers>
<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Version>0.3.0</Version>
<Version>0.3.1</Version>
<!-- Package Properties -->
<Authors>Deterous</Authors>
@@ -29,8 +29,8 @@
<ItemGroup>
<ProjectReference Include="..\LibIRD\LibIRD.csproj" />
<ProjectReference Include="..\DiscUtils\Library\DiscUtils.Core\DiscUtils.Core.csproj" />
<ProjectReference Include="..\DiscUtils\Library\DiscUtils.Iso9660\DiscUtils.Iso9660.csproj" />
<ProjectReference Include="..\DiscUtils\Library\DiscUtils.Core\DiscUtils.Core.csproj" />
<ProjectReference Include="..\DiscUtils\Library\DiscUtils.Iso9660\DiscUtils.Iso9660.csproj" />
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="SabreTools.RedumpLib" Version="1.3.2" />
</ItemGroup>
+27 -19
View File
@@ -487,7 +487,7 @@ namespace IRDKit
printText.AppendLine($"TitleID: {IRD1.TitleID} vs {IRD2.TitleID}");
if (IRD1.Title != IRD2.Title)
printText.AppendLine($"Title: {IRD1.Title} vs {IRD2.Title}");
printText.AppendLine($"Title: \"{IRD1.Title}\" vs \"{IRD2.Title}\"");
if (IRD1.SystemVersion != IRD2.SystemVersion)
printText.AppendLine($"PUP Version: {IRD1.SystemVersion} vs {IRD2.SystemVersion}");
@@ -504,8 +504,13 @@ namespace IRDKit
if (header1.Length != header2.Length)
printText.AppendLine($"Header Length: {header1.Length} vs {header2.Length}");
if (!header1.SequenceEqual(header2))
printText.AppendLine($"Header: Differs");
int headerDiff;
if (header1.Length < header2.Length)
headerDiff = header2.Length - header1.Length + header1.Where((x, i) => x != header2[i]).Count();
else
headerDiff = header1.Length - header2.Length + header2.Where((x, i) => x != header1[i]).Count();
if (headerDiff != 0)
printText.AppendLine($"Header: Differs by {headerDiff} bytes");
byte[] footer1 = Decompress(IRD1.Footer);
byte[] footer2 = Decompress(IRD2.Footer);
@@ -513,8 +518,13 @@ namespace IRDKit
if (footer1.Length != footer2.Length)
printText.AppendLine($"Footer Length: {footer1.Length} vs {footer2.Length}");
if (!footer1.SequenceEqual(footer2))
printText.AppendLine($"Footer: Differs");
int footerDiff;
if (footer1.Length < footer2.Length)
footerDiff = footer2.Length - footer1.Length + footer1.Where((x, i) => x != footer2[i]).Count();
else
footerDiff = footer1.Length - footer2.Length + footer2.Where((x, i) => x != footer1[i]).Count();
if (footerDiff != 0)
printText.AppendLine($"Footer: Differs by {footerDiff} bytes");
if (IRD1.RegionCount != IRD2.RegionCount)
printText.AppendLine($"Region Count: {IRD1.RegionCount} vs {IRD2.RegionCount}");
@@ -533,21 +543,19 @@ namespace IRDKit
if (IRD1.FileCount != IRD2.FileCount)
printText.AppendLine($"File Count: {IRD1.FileCount} vs {IRD2.FileCount}");
int fileCount = IRD2.FileCount < IRD1.FileCount ? (int)IRD2.FileCount : (int)IRD1.FileCount;
if (fileCount > IRD1.FileKeys.Length)
fileCount = IRD1.FileKeys.Length;
if (fileCount > IRD2.FileKeys.Length)
fileCount = IRD2.FileKeys.Length;
if (fileCount > IRD1.FileHashes.Length)
fileCount = IRD1.FileHashes.Length;
if (fileCount > IRD2.FileHashes.Length)
fileCount = IRD2.FileHashes.Length;
for (int i = 0; i < fileCount; i++)
for (int i = 0; i < IRD1.FileKeys.Length; i++)
{
if (IRD1.FileKeys[i] != IRD2.FileKeys[i])
printText.AppendLine($"File {i} Offset: {IRD1.FileKeys[i]} vs {IRD2.FileKeys[i]}");
if (!IRD1.FileHashes[i].SequenceEqual(IRD2.FileHashes[i]))
printText.AppendLine($"File {i} Hash: {Convert.ToHexString(IRD1.FileHashes[i])} vs {Convert.ToHexString(IRD2.FileHashes[i])}");
int j = Array.FindIndex(IRD2.FileKeys, element => element == IRD1.FileKeys[i]);
if (j == -1)
printText.AppendLine($"File Offset: {IRD1.FileKeys[i]} vs [Not Present]");
if (j != -1 && !IRD1.FileHashes[i].SequenceEqual(IRD2.FileHashes[j]))
printText.AppendLine($"File Hash at Offset {IRD1.FileKeys[i]}: {Convert.ToHexString(IRD1.FileHashes[i])} vs {Convert.ToHexString(IRD2.FileHashes[j])}");
}
for (int i = 0; i < IRD2.FileKeys.Length; i++)
{
int j = Array.FindIndex(IRD1.FileKeys, element => element == IRD2.FileKeys[i]);
if (j == -1)
printText.AppendLine($"File Offset: [Not Present] vs {IRD2.FileKeys[i]}");
}
if (IRD1.ExtraConfig != IRD2.ExtraConfig)
+5 -6
View File
@@ -117,7 +117,6 @@ namespace LibIRD
}
}
private byte[] _discKey;
// TODO: Link Data1Key and Disc Key
/// <summary>
/// D1 key
@@ -640,7 +639,7 @@ namespace LibIRD
ExtraConfig |= 0x01;
// Redump-style IRDs use fields from PS3_DISC.SFB
using DiscUtils.Streams.SparseStream s = reader.OpenFile("PS3_DISC.SFB", FileMode.Open, FileAccess.Read);
using SparseStream s = reader.OpenFile("PS3_DISC.SFB", FileMode.Open, FileAccess.Read);
// Parse PS3_DISC.SFB file
PS3_DiscSFB ps3_DiscSFB = new(s);
@@ -658,7 +657,7 @@ namespace LibIRD
}
// Read PS3 Metadata from PARAM.SFO
using (DiscUtils.Streams.SparseStream s = reader.OpenFile("\\PS3_GAME\\PARAM.SFO", FileMode.Open, FileAccess.Read))
using (SparseStream s = reader.OpenFile("\\PS3_GAME\\PARAM.SFO", FileMode.Open, FileAccess.Read))
{
// Parse PARAM.SFO file
ParamSFO paramSFO = new(s);
@@ -744,7 +743,7 @@ namespace LibIRD
private void GetSystemVersion(FileStream fs, CDReader reader)
{
// Determine PUP file offset via cluster
DiscUtils.Streams.Range<long, long>[] updateClusters = reader.PathToClusters("\\PS3_UPDATE\\PS3UPDAT.PUP");
Range<long, long>[] updateClusters = reader.PathToClusters("\\PS3_UPDATE\\PS3UPDAT.PUP");
if (updateClusters == null && updateClusters.Length == 0 && updateClusters[0] == null)
throw new InvalidFileSystemException("Invalid file extents for PS3UPDAT.PUP");
@@ -787,7 +786,7 @@ namespace LibIRD
private void GetHeader(FileStream fs, CDReader reader)
{
// Determine the extent of the header via cluster (Sector 0 to first data sector)
DiscUtils.Streams.Range<long, long>[] sfbClusters = reader.PathToClusters("\\PS3_DISC.SFB");
Range<long, long>[] sfbClusters = reader.PathToClusters("\\PS3_DISC.SFB");
if (sfbClusters == null && sfbClusters.Length == 0 && sfbClusters[0] == null)
throw new InvalidFileSystemException("Invalid file extents for PS3_DISC.SFB");
// End of header is at beginning of first byte of dedicated cluster
@@ -929,7 +928,7 @@ namespace LibIRD
string filePath = fileInfo.FullName;
// Determine the extents of the file via clusters
DiscUtils.Streams.Range<long, long>[] fileClusters = reader.PathToClusters(filePath);
Range<long, long>[] fileClusters = reader.PathToClusters(filePath);
// If invalid clusters were returned, we can't hash this file
if (fileClusters == null && fileClusters.Length == 0)
+1 -1
View File
@@ -6,7 +6,7 @@
<RuntimeIdentifiers>win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64</RuntimeIdentifiers>
<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Version>0.3.0</Version>
<Version>0.3.1</Version>
<!-- Package Properties -->
<Authors>Deterous</Authors>