mirror of
https://github.com/aaru-dps/Aaru.Checksums.git
synced 2025-12-16 19:24:29 +00:00
REFACTOR: Invert 'if' statement to reduce nesting.
This commit is contained in:
@@ -124,11 +124,11 @@ namespace DiscImageChef.Checksums
|
|||||||
{
|
{
|
||||||
EccInit();
|
EccInit();
|
||||||
|
|
||||||
if(channel[0x000] == 0x00 && // sync (12 bytes)
|
if(channel[0x000] != 0x00 || channel[0x001] != 0xFF || channel[0x002] != 0xFF || channel[0x003] != 0xFF ||
|
||||||
channel[0x001] == 0xFF && channel[0x002] == 0xFF && channel[0x003] == 0xFF && channel[0x004] == 0xFF &&
|
channel[0x004] != 0xFF || channel[0x005] != 0xFF || channel[0x006] != 0xFF || channel[0x007] != 0xFF ||
|
||||||
channel[0x005] == 0xFF && channel[0x006] == 0xFF && channel[0x007] == 0xFF && channel[0x008] == 0xFF &&
|
channel[0x008] != 0xFF || channel[0x009] != 0xFF || channel[0x00A] != 0xFF ||
|
||||||
channel[0x009] == 0xFF && channel[0x00A] == 0xFF && channel[0x00B] == 0x00)
|
channel[0x00B] != 0x00) return null;
|
||||||
{
|
|
||||||
DicConsole.DebugWriteLine("CD checksums", "Data sector, address {0:X2}:{1:X2}:{2:X2}", channel[0x00C],
|
DicConsole.DebugWriteLine("CD checksums", "Data sector, address {0:X2}:{1:X2}:{2:X2}", channel[0x00C],
|
||||||
channel[0x00D], channel[0x00E]);
|
channel[0x00D], channel[0x00E]);
|
||||||
|
|
||||||
@@ -295,9 +295,6 @@ namespace DiscImageChef.Checksums
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool? CheckCdSectorSubChannel(byte[] subchannel)
|
static bool? CheckCdSectorSubChannel(byte[] subchannel)
|
||||||
{
|
{
|
||||||
bool? status = true;
|
bool? status = true;
|
||||||
@@ -478,8 +475,8 @@ namespace DiscImageChef.Checksums
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if((cdTextPack4[0] & 0x80) == 0x80)
|
if((cdTextPack4[0] & 0x80) != 0x80) return status;
|
||||||
{
|
|
||||||
ushort cdTextPack4Crc = BigEndianBitConverter.ToUInt16(cdTextPack4, 16);
|
ushort cdTextPack4Crc = BigEndianBitConverter.ToUInt16(cdTextPack4, 16);
|
||||||
byte[] cdTextPack4ForCrc = new byte[16];
|
byte[] cdTextPack4ForCrc = new byte[16];
|
||||||
Array.Copy(cdTextPack4, 0, cdTextPack4ForCrc, 0, 16);
|
Array.Copy(cdTextPack4, 0, cdTextPack4ForCrc, 0, 16);
|
||||||
@@ -487,13 +484,11 @@ namespace DiscImageChef.Checksums
|
|||||||
DicConsole.DebugWriteLine("CD checksums", "Cyclic CDTP4 0x{0:X4}, Calc CDTP4 0x{1:X4}", cdTextPack4Crc,
|
DicConsole.DebugWriteLine("CD checksums", "Cyclic CDTP4 0x{0:X4}, Calc CDTP4 0x{1:X4}", cdTextPack4Crc,
|
||||||
calculatedCdtp4Crc);
|
calculatedCdtp4Crc);
|
||||||
|
|
||||||
if(cdTextPack4Crc != calculatedCdtp4Crc && cdTextPack4Crc != 0)
|
if(cdTextPack4Crc == calculatedCdtp4Crc || cdTextPack4Crc == 0) return status;
|
||||||
{
|
|
||||||
DicConsole.DebugWriteLine("CD checksums", "CD-Text Pack 4 CRC 0x{0:X4}, expected 0x{1:X4}",
|
DicConsole.DebugWriteLine("CD checksums", "CD-Text Pack 4 CRC 0x{0:X4}, expected 0x{1:X4}",
|
||||||
cdTextPack4Crc, calculatedCdtp4Crc);
|
cdTextPack4Crc, calculatedCdtp4Crc);
|
||||||
status = false;
|
status = false;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -305,8 +305,8 @@ namespace DiscImageChef.Checksums
|
|||||||
/// <param name="bb">Outs parity symbols.</param>
|
/// <param name="bb">Outs parity symbols.</param>
|
||||||
public int encode_rs(int[] data, out int[] bb)
|
public int encode_rs(int[] data, out int[] bb)
|
||||||
{
|
{
|
||||||
if(initialized)
|
if(!initialized) throw new UnauthorizedAccessException("Trying to calculate RS without initializing!");
|
||||||
{
|
|
||||||
int i, j;
|
int i, j;
|
||||||
int feedback;
|
int feedback;
|
||||||
bb = new int[nn - kk];
|
bb = new int[nn - kk];
|
||||||
@@ -339,9 +339,6 @@ namespace DiscImageChef.Checksums
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new UnauthorizedAccessException("Trying to calculate RS without initializing!");
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Performs ERRORS+ERASURES decoding of RS codes. If decoding is successful,
|
* Performs ERRORS+ERASURES decoding of RS codes. If decoding is successful,
|
||||||
* writes the codeword into data[] itself. Otherwise data[] is unaltered.
|
* writes the codeword into data[] itself. Otherwise data[] is unaltered.
|
||||||
@@ -364,8 +361,8 @@ namespace DiscImageChef.Checksums
|
|||||||
/// <param name="noEras">Number of erasures.</param>
|
/// <param name="noEras">Number of erasures.</param>
|
||||||
public int eras_dec_rs(ref int[] data, out int[] erasPos, int noEras)
|
public int eras_dec_rs(ref int[] data, out int[] erasPos, int noEras)
|
||||||
{
|
{
|
||||||
if(initialized)
|
if(!initialized) throw new UnauthorizedAccessException("Trying to calculate RS without initializing!");
|
||||||
{
|
|
||||||
erasPos = new int[nn - kk];
|
erasPos = new int[nn - kk];
|
||||||
int degLambda, el, degOmega;
|
int degLambda, el, degOmega;
|
||||||
int i, j, r;
|
int i, j, r;
|
||||||
@@ -438,8 +435,7 @@ namespace DiscImageChef.Checksums
|
|||||||
q ^= alpha_to[reg[j]];
|
q ^= alpha_to[reg[j]];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(q == 0)
|
if(q != 0) continue;
|
||||||
{
|
|
||||||
/* store root and error location
|
/* store root and error location
|
||||||
* number indices
|
* number indices
|
||||||
*/
|
*/
|
||||||
@@ -447,7 +443,6 @@ namespace DiscImageChef.Checksums
|
|||||||
loc[count] = nn - i;
|
loc[count] = nn - i;
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(count != noEras)
|
if(count != noEras)
|
||||||
{
|
{
|
||||||
@@ -539,14 +534,12 @@ namespace DiscImageChef.Checksums
|
|||||||
q ^= alpha_to[reg[j]];
|
q ^= alpha_to[reg[j]];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(q == 0)
|
if(q != 0) continue;
|
||||||
{
|
|
||||||
/* store root (index-form) and error location number */
|
/* store root (index-form) and error location number */
|
||||||
root[count] = i;
|
root[count] = i;
|
||||||
loc[count] = nn - i;
|
loc[count] = nn - i;
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
DicConsole.DebugWriteLine("Reed Solomon", "\n Final error positions:\t");
|
DicConsole.DebugWriteLine("Reed Solomon", "\n Final error positions:\t");
|
||||||
@@ -599,8 +592,5 @@ namespace DiscImageChef.Checksums
|
|||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new UnauthorizedAccessException("Trying to calculate RS without initializing!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -246,12 +246,11 @@ namespace DiscImageChef.Checksums
|
|||||||
* */
|
* */
|
||||||
self.Bh[i].Digest[++self.Bh[i].Dlen] = 0;
|
self.Bh[i].Digest[++self.Bh[i].Dlen] = 0;
|
||||||
self.Bh[i].H = HASH_INIT;
|
self.Bh[i].H = HASH_INIT;
|
||||||
if(self.Bh[i].Dlen < SPAMSUM_LENGTH / 2)
|
if(self.Bh[i].Dlen >= SPAMSUM_LENGTH / 2) continue;
|
||||||
{
|
|
||||||
self.Bh[i].Halfh = HASH_INIT;
|
self.Bh[i].Halfh = HASH_INIT;
|
||||||
self.Bh[i].Halfdigest = 0;
|
self.Bh[i].Halfdigest = 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else fuzzy_try_reduce_blockhash();
|
else fuzzy_try_reduce_blockhash();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user