mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Fix CHD parsing, threading, version
This commit is contained in:
@@ -42,21 +42,28 @@ namespace SabreTools.Library.FileTypes
|
||||
/// <param name="chdstream">Stream representing the CHD file</param>
|
||||
public static CHDFile Create(Stream chdstream)
|
||||
{
|
||||
// Read the standard CHD headers
|
||||
(char[] tag, uint length, uint version) = GetHeaderValues(chdstream);
|
||||
chdstream.Seek(-16, SeekOrigin.Current); // Seek back to start
|
||||
try
|
||||
{
|
||||
// Read the standard CHD headers
|
||||
(char[] tag, uint length, uint version) = GetHeaderValues(chdstream);
|
||||
chdstream.Seek(-16, SeekOrigin.Current); // Seek back to start
|
||||
|
||||
// Validate that this is actually a valid CHD
|
||||
uint validatedVersion = ValidateHeader(tag, length, version);
|
||||
if (validatedVersion == 0)
|
||||
// Validate that this is actually a valid CHD
|
||||
uint validatedVersion = ValidateHeader(tag, length, version);
|
||||
if (validatedVersion == 0)
|
||||
return null;
|
||||
|
||||
// Read and retrun the current CHD
|
||||
CHDFile generated = ReadAsVersion(chdstream, version);
|
||||
if (generated != null)
|
||||
generated.Type = FileType.CHD;
|
||||
|
||||
return generated;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
|
||||
// Read and retrun the current CHD
|
||||
CHDFile generated = ReadAsVersion(chdstream, version);
|
||||
if (generated != null)
|
||||
generated.Type = FileType.CHD;
|
||||
|
||||
return generated;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -85,7 +92,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true))
|
||||
{
|
||||
parsedTag = br.ReadCharsBigEndian(8);
|
||||
parsedTag = br.ReadChars(8);
|
||||
parsedLength = br.ReadUInt32BigEndian();
|
||||
parsedVersion = br.ReadUInt32BigEndian();
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true))
|
||||
{
|
||||
chd.tag = br.ReadCharsBigEndian(8);
|
||||
chd.tag = br.ReadChars(8);
|
||||
chd.length = br.ReadUInt32BigEndian();
|
||||
chd.version = br.ReadUInt32BigEndian();
|
||||
chd.flags = (Flags)br.ReadUInt32BigEndian();
|
||||
@@ -72,8 +72,10 @@ namespace SabreTools.Library.FileTypes
|
||||
chd.cylinders = br.ReadUInt32BigEndian();
|
||||
chd.heads = br.ReadUInt32BigEndian();
|
||||
chd.sectors = br.ReadUInt32BigEndian();
|
||||
chd.md5 = br.ReadBytesBigEndian(16);
|
||||
chd.parentmd5 = br.ReadBytesBigEndian(16);
|
||||
chd.md5 = br.ReadBytes(16);
|
||||
chd.parentmd5 = br.ReadBytes(16);
|
||||
|
||||
chd.MD5 = chd.md5;
|
||||
}
|
||||
|
||||
return chd;
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true))
|
||||
{
|
||||
chd.tag = br.ReadCharsBigEndian(8);
|
||||
chd.tag = br.ReadChars(8);
|
||||
chd.length = br.ReadUInt32BigEndian();
|
||||
chd.version = br.ReadUInt32BigEndian();
|
||||
chd.flags = (Flags)br.ReadUInt32BigEndian();
|
||||
@@ -73,9 +73,11 @@ namespace SabreTools.Library.FileTypes
|
||||
chd.cylinders = br.ReadUInt32BigEndian();
|
||||
chd.heads = br.ReadUInt32BigEndian();
|
||||
chd.sectors = br.ReadUInt32BigEndian();
|
||||
chd.md5 = br.ReadBytesBigEndian(16);
|
||||
chd.parentmd5 = br.ReadBytesBigEndian(16);
|
||||
chd.md5 = br.ReadBytes(16);
|
||||
chd.parentmd5 = br.ReadBytes(16);
|
||||
chd.seclen = br.ReadUInt32BigEndian();
|
||||
|
||||
chd.MD5 = chd.md5;
|
||||
}
|
||||
|
||||
return chd;
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true))
|
||||
{
|
||||
chd.tag = br.ReadCharsBigEndian(8);
|
||||
chd.tag = br.ReadChars(8);
|
||||
chd.length = br.ReadUInt32BigEndian();
|
||||
chd.version = br.ReadUInt32BigEndian();
|
||||
chd.flags = (Flags)br.ReadUInt32BigEndian();
|
||||
@@ -75,11 +75,14 @@ namespace SabreTools.Library.FileTypes
|
||||
chd.totalhunks = br.ReadUInt32BigEndian();
|
||||
chd.logicalbytes = br.ReadUInt64BigEndian();
|
||||
chd.metaoffset = br.ReadUInt64BigEndian();
|
||||
chd.md5 = br.ReadBytesBigEndian(16);
|
||||
chd.parentmd5 = br.ReadBytesBigEndian(16);
|
||||
chd.md5 = br.ReadBytes(16);
|
||||
chd.parentmd5 = br.ReadBytes(16);
|
||||
chd.hunkbytes = br.ReadUInt32BigEndian();
|
||||
chd.sha1 = br.ReadBytesBigEndian(20);
|
||||
chd.parentsha1 = br.ReadBytesBigEndian(20);
|
||||
chd.sha1 = br.ReadBytes(20);
|
||||
chd.parentsha1 = br.ReadBytes(20);
|
||||
|
||||
chd.MD5 = chd.md5;
|
||||
chd.SHA1 = chd.sha1;
|
||||
}
|
||||
|
||||
return chd;
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true))
|
||||
{
|
||||
chd.tag = br.ReadCharsBigEndian(8);
|
||||
chd.tag = br.ReadChars(8);
|
||||
chd.length = br.ReadUInt32BigEndian();
|
||||
chd.version = br.ReadUInt32BigEndian();
|
||||
chd.flags = (Flags)br.ReadUInt32BigEndian();
|
||||
@@ -76,9 +76,11 @@ namespace SabreTools.Library.FileTypes
|
||||
chd.logicalbytes = br.ReadUInt64BigEndian();
|
||||
chd.metaoffset = br.ReadUInt64BigEndian();
|
||||
chd.hunkbytes = br.ReadUInt32BigEndian();
|
||||
chd.sha1 = br.ReadBytesBigEndian(20);
|
||||
chd.parentsha1 = br.ReadBytesBigEndian(20);
|
||||
chd.rawsha1 = br.ReadBytesBigEndian(20);
|
||||
chd.sha1 = br.ReadBytes(20);
|
||||
chd.parentsha1 = br.ReadBytes(20);
|
||||
chd.rawsha1 = br.ReadBytes(20);
|
||||
|
||||
chd.SHA1 = chd.sha1;
|
||||
}
|
||||
|
||||
return chd;
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true))
|
||||
{
|
||||
chd.tag = br.ReadCharsBigEndian(8);
|
||||
chd.tag = br.ReadChars(8);
|
||||
chd.length = br.ReadUInt32BigEndian();
|
||||
chd.version = br.ReadUInt32BigEndian();
|
||||
chd.compressors = new uint[4];
|
||||
@@ -79,9 +79,11 @@ namespace SabreTools.Library.FileTypes
|
||||
chd.metaoffset = br.ReadUInt64BigEndian();
|
||||
chd.hunkbytes = br.ReadUInt32BigEndian();
|
||||
chd.unitbytes = br.ReadUInt32BigEndian();
|
||||
chd.rawsha1 = br.ReadBytesBigEndian(20);
|
||||
chd.sha1 = br.ReadBytesBigEndian(20);
|
||||
chd.parentsha1 = br.ReadBytesBigEndian(20);
|
||||
chd.rawsha1 = br.ReadBytes(20);
|
||||
chd.sha1 = br.ReadBytes(20);
|
||||
chd.parentsha1 = br.ReadBytes(20);
|
||||
|
||||
chd.SHA1 = chd.sha1;
|
||||
}
|
||||
|
||||
return chd;
|
||||
|
||||
Reference in New Issue
Block a user