Code cleanup.

This commit is contained in:
2018-06-22 08:08:38 +01:00
parent d2850929d6
commit 4c15d8c8cb
16 changed files with 75 additions and 67 deletions

View File

@@ -239,7 +239,7 @@ namespace DiscImageChef
public static short ToInt16(byte[] value, int startIndex)
{
return !IsLittleEndian
? BitConverter.ToInt16(value, startIndex)
? BitConverter.ToInt16(value, startIndex)
: BitConverter.ToInt16(value.Reverse().ToArray(), value.Length - sizeof(short) - startIndex);
}
@@ -261,7 +261,7 @@ namespace DiscImageChef
public static int ToInt32(byte[] value, int startIndex)
{
return !IsLittleEndian
? BitConverter.ToInt32(value, startIndex)
? BitConverter.ToInt32(value, startIndex)
: BitConverter.ToInt32(value.Reverse().ToArray(), value.Length - sizeof(int) - startIndex);
}
@@ -283,7 +283,7 @@ namespace DiscImageChef
public static long ToInt64(byte[] value, int startIndex)
{
return !IsLittleEndian
? BitConverter.ToInt64(value, startIndex)
? BitConverter.ToInt64(value, startIndex)
: BitConverter.ToInt64(value.Reverse().ToArray(), value.Length - sizeof(long) - startIndex);
}
@@ -306,7 +306,7 @@ namespace DiscImageChef
public static float ToSingle(byte[] value, int startIndex)
{
return !IsLittleEndian
? BitConverter.ToSingle(value, startIndex)
? BitConverter.ToSingle(value, startIndex)
: BitConverter.ToSingle(value.Reverse().ToArray(), value.Length - sizeof(float) - startIndex);
}
@@ -343,7 +343,7 @@ namespace DiscImageChef
public static string ToString(byte[] value, int startIndex)
{
return !IsLittleEndian
? BitConverter.ToString(value, startIndex)
? BitConverter.ToString(value, startIndex)
: BitConverter.ToString(value.Reverse().ToArray(), startIndex);
}
@@ -370,7 +370,7 @@ namespace DiscImageChef
public static string ToString(byte[] value, int startIndex, int length)
{
return !IsLittleEndian
? BitConverter.ToString(value, startIndex, length)
? BitConverter.ToString(value, startIndex, length)
: BitConverter.ToString(value.Reverse().ToArray(), startIndex, length);
}
@@ -389,7 +389,7 @@ namespace DiscImageChef
public static ushort ToUInt16(byte[] value, int startIndex)
{
return !IsLittleEndian
? BitConverter.ToUInt16(value, startIndex)
? BitConverter.ToUInt16(value, startIndex)
: BitConverter.ToUInt16(value.Reverse().ToArray(), value.Length - sizeof(ushort) - startIndex);
}
@@ -411,7 +411,7 @@ namespace DiscImageChef
public static uint ToUInt32(byte[] value, int startIndex)
{
return !IsLittleEndian
? BitConverter.ToUInt32(value, startIndex)
? BitConverter.ToUInt32(value, startIndex)
: BitConverter.ToUInt32(value.Reverse().ToArray(), value.Length - sizeof(uint) - startIndex);
}
@@ -433,16 +433,19 @@ namespace DiscImageChef
public static ulong ToUInt64(byte[] value, int startIndex)
{
return !IsLittleEndian
? BitConverter.ToUInt64(value, startIndex)
? BitConverter.ToUInt64(value, startIndex)
: BitConverter.ToUInt64(value.Reverse().ToArray(), value.Length - sizeof(ulong) - startIndex);
}
public static Guid ToGuid(byte[] value, int startIndex)
{
return new Guid(ToUInt32(value, 0 + startIndex), ToUInt16(value, 4 + startIndex),
ToUInt16(value, 6 + startIndex), value[8 + startIndex + 0], value[8 + startIndex + 1],
value[8 + startIndex + 2], value[8 + startIndex + 3], value[8 + startIndex + 5],
value[8 + startIndex + 5], value[8 + startIndex + 6], value[8 + startIndex + 7]);
ToUInt16(value, 6 + startIndex), value[8 + startIndex + 0],
value[8 + startIndex + 1],
value[8 + startIndex + 2], value[8 + startIndex + 3],
value[8 + startIndex + 5],
value[8 + startIndex + 5], value[8 + startIndex + 6],
value[8 + startIndex + 7]);
}
}
}

2
CHS.cs
View File

@@ -46,7 +46,7 @@ namespace DiscImageChef.Helpers
public static uint ToLBA(uint cyl, uint head, uint sector, uint maxHead, uint maxSector)
{
return maxHead == 0 || maxSector == 0
? (cyl * 16 + head) * 63 + sector - 1
? (cyl * 16 + head) * 63 + sector - 1
: (cyl * maxHead + head) * maxSector + sector - 1;
}
}

View File

@@ -42,20 +42,20 @@ namespace DiscImageChef
/// <param name="compareArray1">Left array</param>
/// <param name="compareArray2">Right array</param>
public static void CompareBytes(out bool different, out bool sameSize, byte[] compareArray1,
byte[] compareArray2)
byte[] compareArray2)
{
different = false;
sameSize = true;
sameSize = true;
long leastBytes;
if(compareArray1.LongLength < compareArray2.LongLength)
{
sameSize = false;
sameSize = false;
leastBytes = compareArray1.LongLength;
}
else if(compareArray1.LongLength > compareArray2.LongLength)
{
sameSize = false;
sameSize = false;
leastBytes = compareArray2.LongLength;
}
else leastBytes = compareArray1.LongLength;

View File

@@ -42,7 +42,7 @@ namespace DiscImageChef.Helpers
public static int Count(uint number)
{
number = number - ((number >> 1) & 0x55555555);
number = (number & 0x33333333) + ((number >> 2) & 0x33333333);
number = (number & 0x33333333) + ((number >> 2) & 0x33333333);
return (int)((((number + (number >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24);
}
}

View File

@@ -39,7 +39,7 @@ namespace DiscImageChef
public static class DateHandlers
{
static readonly DateTime LisaEpoch = new DateTime(1901, 1, 1, 0, 0, 0);
static readonly DateTime MacEpoch = new DateTime(1904, 1, 1, 0, 0, 0);
static readonly DateTime MacEpoch = new DateTime(1904, 1, 1, 0, 0, 0);
static readonly DateTime UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0);
/// <summary>
/// Day 0 of Julian Date system
@@ -138,7 +138,7 @@ namespace DiscImageChef
/// <returns>.NET DateTime</returns>
public static DateTime Iso9660ToDateTime(byte[] vdDateTime)
{
byte[] twocharvalue = new byte[2];
byte[] twocharvalue = new byte[2];
byte[] fourcharvalue = new byte[4];
fourcharvalue[0] = vdDateTime[0];
@@ -228,8 +228,8 @@ namespace DiscImageChef
/// <returns>.NET DateTime</returns>
public static DateTime UcsdPascalToDateTime(short dateRecord)
{
int year = ((dateRecord & 0xFE00) >> 9) + 1900;
int day = (dateRecord & 0x01F0) >> 4;
int year = ((dateRecord & 0xFE00) >> 9) + 1900;
int day = (dateRecord & 0x01F0) >> 4;
int month = dateRecord & 0x000F;
DicConsole.DebugWriteLine("UCSDPascalToDateTime handler",
@@ -246,11 +246,11 @@ namespace DiscImageChef
/// <returns>.NET DateTime</returns>
public static DateTime DosToDateTime(ushort date, ushort time)
{
int year = ((date & 0xFE00) >> 9) + 1980;
int month = (date & 0x1E0) >> 5;
int day = date & 0x1F;
int hour = (time & 0xF800) >> 11;
int minute = (time & 0x7E0) >> 5;
int year = ((date & 0xFE00) >> 9) + 1980;
int month = (date & 0x1E0) >> 5;
int day = date & 0x1F;
int hour = (time & 0xF800) >> 11;
int minute = (time & 0x7E0) >> 5;
int second = (time & 0x1F) * 2;
DicConsole.DebugWriteLine("DOSToDateTime handler", "date = 0x{0:X4}, year = {1}, month = {2}, day = {3}",
@@ -273,9 +273,9 @@ namespace DiscImageChef
/// <returns>.NET DateTime</returns>
public static DateTime CpmToDateTime(byte[] timestamp)
{
ushort days = BitConverter.ToUInt16(timestamp, 0);
int hours = timestamp[2];
int minutes = timestamp[3];
ushort days = BitConverter.ToUInt16(timestamp, 0);
int hours = timestamp[2];
int minutes = timestamp[3];
DateTime temp = AmigaEpoch.AddDays(days);
temp = temp.AddHours(hours);
@@ -298,20 +298,23 @@ namespace DiscImageChef
/// <param name="hundredsOfMicroseconds">Hundreds of microseconds</param>
/// <param name="microseconds">Microseconds</param>
/// <returns></returns>
public static DateTime EcmaToDateTime(ushort typeAndTimeZone, short year, byte month, byte day, byte hour,
byte minute, byte second, byte centiseconds, byte hundredsOfMicroseconds,
byte microseconds)
public static DateTime EcmaToDateTime(ushort typeAndTimeZone, short year, byte month, byte day,
byte hour,
byte minute, byte second, byte centiseconds,
byte hundredsOfMicroseconds,
byte microseconds)
{
byte specification = (byte)((typeAndTimeZone & 0xF000) >> 12);
long ticks = (long)centiseconds * 100000 + (long)hundredsOfMicroseconds * 1000 + (long)microseconds * 10;
long ticks = (long)centiseconds * 100000 + (long)hundredsOfMicroseconds * 1000 +
(long)microseconds * 10;
if(specification == 0)
return new DateTime(year, month, day, hour, minute, second, DateTimeKind.Utc).AddTicks(ticks);
ushort preOffset = (ushort)(typeAndTimeZone & 0xFFF);
short offset;
short offset;
if((preOffset & 0x800) == 0x800) offset = (short)(preOffset | 0xF000);
else offset = (short)(preOffset & 0x7FF);
else offset = (short)(preOffset & 0x7FF);
if(offset == -2047)
return new DateTime(year, month, day, hour, minute, second, DateTimeKind.Unspecified).AddTicks(ticks);
@@ -319,7 +322,7 @@ namespace DiscImageChef
if(offset < -1440 || offset > 1440) offset = 0;
return new DateTimeOffset(year, month, day, hour, minute, second, new TimeSpan(0, offset, 0))
.AddTicks(ticks).DateTime;
.AddTicks(ticks).DateTime;
}
/// <summary>
@@ -347,7 +350,7 @@ namespace DiscImageChef
{
os9Date = date.Length == 5
? new DateTime(1900 + date[0], date[1], date[2], date[3], date[4], 0)
: new DateTime(1900 + date[0], date[1], date[2], 0, 0, 0);
: new DateTime(1900 + date[0], date[1], date[2], 0, 0, 0);
}
catch(ArgumentOutOfRangeException) { os9Date = new DateTime(1900, 0, 0, 0, 0, 0); }
@@ -380,15 +383,15 @@ namespace DiscImageChef
{
try
{
int iyear = (year >> 4) * 10 + (year & 0xF);
int imonth = (month >> 4) * 10 + (month & 0xF);
int iday = (day >> 4) * 10 + (day & 0xF);
int iyear = (year >> 4) * 10 + (year & 0xF);
int imonth = (month >> 4) * 10 + (month & 0xF);
int iday = (day >> 4) * 10 + (day & 0xF);
int iminute = (minute >> 4) * 10 + (minute & 0xF);
int ihour = (hour >> 4) * 10 + (hour & 0xF);
int ihour = (hour >> 4) * 10 + (hour & 0xF);
int isecond = (second >> 4) * 10 + (second & 0xF);
if(iyear >= 70) iyear += 1900;
else iyear += 2000;
else iyear += 2000;
return new DateTime(iyear, imonth, iday, ihour, iminute, isecond);
}

View File

@@ -135,7 +135,7 @@ namespace Extents
{
byte realEnd;
if(run) realEnd = (byte)(start + end - 1);
else realEnd = end;
else realEnd = end;
// TODO: Optimize this
for(byte t = start; t <= realEnd; t++) Add(t);
@@ -177,7 +177,7 @@ namespace Extents
{
toRemove = extent;
toAddOne = new Tuple<byte, byte>(extent.Item1, (byte)(item - 1));
toAddTwo = new Tuple<byte, byte>((byte)(item + 1), extent.Item2);
toAddTwo = new Tuple<byte, byte>((byte)(item + 1), extent.Item2);
break;
}

View File

@@ -135,7 +135,7 @@ namespace Extents
{
int realEnd;
if(run) realEnd = start + end - 1;
else realEnd = end;
else realEnd = end;
// TODO: Optimize this
for(int t = start; t <= realEnd; t++) Add(t);
@@ -177,7 +177,7 @@ namespace Extents
{
toRemove = extent;
toAddOne = new Tuple<int, int>(extent.Item1, item - 1);
toAddTwo = new Tuple<int, int>(item + 1, extent.Item2);
toAddTwo = new Tuple<int, int>(item + 1, extent.Item2);
break;
}

View File

@@ -135,7 +135,7 @@ namespace Extents
{
long realEnd;
if(run) realEnd = start + end - 1;
else realEnd = end;
else realEnd = end;
// TODO: Optimize this
for(long t = start; t <= realEnd; t++) Add(t);
@@ -177,7 +177,7 @@ namespace Extents
{
toRemove = extent;
toAddOne = new Tuple<long, long>(extent.Item1, item - 1);
toAddTwo = new Tuple<long, long>(item + 1, extent.Item2);
toAddTwo = new Tuple<long, long>(item + 1, extent.Item2);
break;
}

View File

@@ -135,7 +135,7 @@ namespace Extents
{
sbyte realEnd;
if(run) realEnd = (sbyte)(start + end - 1);
else realEnd = end;
else realEnd = end;
// TODO: Optimize this
for(sbyte t = start; t <= realEnd; t++) Add(t);
@@ -177,7 +177,7 @@ namespace Extents
{
toRemove = extent;
toAddOne = new Tuple<sbyte, sbyte>(extent.Item1, (sbyte)(item - 1));
toAddTwo = new Tuple<sbyte, sbyte>((sbyte)(item + 1), extent.Item2);
toAddTwo = new Tuple<sbyte, sbyte>((sbyte)(item + 1), extent.Item2);
break;
}

View File

@@ -135,7 +135,7 @@ namespace Extents
{
short realEnd;
if(run) realEnd = (short)(start + end - 1);
else realEnd = end;
else realEnd = end;
// TODO: Optimize this
for(short t = start; t <= realEnd; t++) Add(t);
@@ -177,7 +177,7 @@ namespace Extents
{
toRemove = extent;
toAddOne = new Tuple<short, short>(extent.Item1, (short)(item - 1));
toAddTwo = new Tuple<short, short>((short)(item + 1), extent.Item2);
toAddTwo = new Tuple<short, short>((short)(item + 1), extent.Item2);
break;
}

View File

@@ -135,7 +135,7 @@ namespace Extents
{
uint realEnd;
if(run) realEnd = start + end - 1;
else realEnd = end;
else realEnd = end;
// TODO: Optimize this
for(uint t = start; t <= realEnd; t++) Add(t);
@@ -177,7 +177,7 @@ namespace Extents
{
toRemove = extent;
toAddOne = new Tuple<uint, uint>(extent.Item1, item - 1);
toAddTwo = new Tuple<uint, uint>(item + 1, extent.Item2);
toAddTwo = new Tuple<uint, uint>(item + 1, extent.Item2);
break;
}

View File

@@ -135,7 +135,7 @@ namespace Extents
{
ulong realEnd;
if(run) realEnd = start + end - 1;
else realEnd = end;
else realEnd = end;
// TODO: Optimize this
for(ulong t = start; t <= realEnd; t++) Add(t);
@@ -177,7 +177,7 @@ namespace Extents
{
toRemove = extent;
toAddOne = new Tuple<ulong, ulong>(extent.Item1, item - 1);
toAddTwo = new Tuple<ulong, ulong>(item + 1, extent.Item2);
toAddTwo = new Tuple<ulong, ulong>(item + 1, extent.Item2);
break;
}

View File

@@ -135,7 +135,7 @@ namespace Extents
{
ushort realEnd;
if(run) realEnd = (ushort)(start + end - 1);
else realEnd = end;
else realEnd = end;
// TODO: Optimize this
for(ushort t = start; t <= realEnd; t++) Add(t);
@@ -177,7 +177,7 @@ namespace Extents
{
toRemove = extent;
toAddOne = new Tuple<ushort, ushort>(extent.Item1, (ushort)(item - 1));
toAddTwo = new Tuple<ushort, ushort>((ushort)(item + 1), extent.Item2);
toAddTwo = new Tuple<ushort, ushort>((ushort)(item + 1), extent.Item2);
break;
}

View File

@@ -57,7 +57,7 @@ namespace DiscImageChef
{
StringBuilder sb = new StringBuilder();
int counter = 0;
int counter = 0;
int subcounter = 0;
for(long i = 0; i < array.LongLength; i++)
{
@@ -84,7 +84,7 @@ namespace DiscImageChef
if(counter == width - 1)
{
counter = 0;
counter = 0;
subcounter = 0;
}
else counter++;

View File

@@ -71,10 +71,12 @@ namespace DiscImageChef
len++;
break;
}
// if((i + 1) == CString.Length)
// break;
}
else break;
else
break;
len++;
}
@@ -107,7 +109,7 @@ namespace DiscImageChef
if(PascalString == null) return null;
byte length = PascalString[start];
int len = 0;
int len = 0;
for(int i = start + 1; i < length + 1 && i < PascalString.Length; i++)
{
@@ -166,15 +168,15 @@ namespace DiscImageChef
public static string DecompressUnicode(byte[] dstring)
{
ushort unicode;
byte compId = dstring[0];
string temp = "";
byte compId = dstring[0];
string temp = "";
if(compId != 8 && compId != 16) return null;
for(int byteIndex = 1; byteIndex < dstring.Length;)
{
if(compId == 16) unicode = (ushort)(dstring[byteIndex++] << 8);
else unicode = 0;
else unicode = 0;
if(byteIndex < dstring.Length) unicode |= dstring[byteIndex++];

View File

@@ -107,7 +107,7 @@ namespace DiscImageChef
{
x = ((x & 0x00000000FFFFFFFF) << 32) | ((x & 0xFFFFFFFF00000000) >> 32);
x = ((x & 0x0000FFFF0000FFFF) << 16) | ((x & 0xFFFF0000FFFF0000) >> 16);
x = ((x & 0x00FF00FF00FF00FF) << 8) | ((x & 0xFF00FF00FF00FF00) >> 8);
x = ((x & 0x00FF00FF00FF00FF) << 8) | ((x & 0xFF00FF00FF00FF00) >> 8);
return x;
}