mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
REFACTOR: All refactor in DiscImageChef.Helpers.
This commit is contained in:
@@ -54,12 +54,7 @@ namespace DiscImageChef
|
|||||||
Array.Copy(destinationArray, 0, destinationArray, copyLength, destinationArray.Length - copyLength);
|
Array.Copy(destinationArray, 0, destinationArray, copyLength, destinationArray.Length - copyLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string ByteArrayToHex(byte[] array)
|
public static string ByteArrayToHex(byte[] array, bool upper = false)
|
||||||
{
|
|
||||||
return ByteArrayToHex(array, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string ByteArrayToHex(byte[] array, bool upper)
|
|
||||||
{
|
{
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for(long i = 0; i < array.LongLength; i++) sb.AppendFormat("{0:x2}", array[i]);
|
for(long i = 0; i < array.LongLength; i++) sb.AppendFormat("{0:x2}", array[i]);
|
||||||
|
|||||||
@@ -38,16 +38,12 @@ namespace DiscImageChef
|
|||||||
{
|
{
|
||||||
public static bool ArrayIsNullOrWhiteSpace(byte[] array)
|
public static bool ArrayIsNullOrWhiteSpace(byte[] array)
|
||||||
{
|
{
|
||||||
if(array == null) return true;
|
return array == null || array.All(b => b == 0x00 || b == 0x20);
|
||||||
|
|
||||||
return array.All(b => b == 0x00 || b == 0x20);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool ArrayIsNullOrEmpty(byte[] array)
|
public static bool ArrayIsNullOrEmpty(byte[] array)
|
||||||
{
|
{
|
||||||
if(array == null) return true;
|
return array == null || array.All(b => b == 0x00);
|
||||||
|
|
||||||
return array.All(b => b == 0x00);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -45,15 +45,12 @@ namespace Extents
|
|||||||
backend = new List<Tuple<byte, byte>>();
|
backend = new List<Tuple<byte, byte>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExtentsByte(List<Tuple<byte, byte>> list)
|
public ExtentsByte(IEnumerable<Tuple<byte, byte>> list)
|
||||||
{
|
{
|
||||||
backend = list.OrderBy(t => t.Item1).ToList();
|
backend = list.OrderBy(t => t.Item1).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Count
|
public int Count => backend.Count;
|
||||||
{
|
|
||||||
get { return backend.Count; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Add(byte item)
|
public void Add(byte item)
|
||||||
{
|
{
|
||||||
@@ -108,12 +105,7 @@ namespace Extents
|
|||||||
backend = backend.OrderBy(t => t.Item1).ToList();
|
backend = backend.OrderBy(t => t.Item1).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Add(byte start, byte end)
|
public void Add(byte start, byte end, bool run = false)
|
||||||
{
|
|
||||||
Add(start, end, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Add(byte start, byte end, bool run)
|
|
||||||
{
|
{
|
||||||
byte realEnd;
|
byte realEnd;
|
||||||
if(run) realEnd = (byte)(start + end - 1);
|
if(run) realEnd = (byte)(start + end - 1);
|
||||||
|
|||||||
@@ -45,15 +45,12 @@ namespace Extents
|
|||||||
backend = new List<Tuple<int, int>>();
|
backend = new List<Tuple<int, int>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExtentsInt(List<Tuple<int, int>> list)
|
public ExtentsInt(IEnumerable<Tuple<int, int>> list)
|
||||||
{
|
{
|
||||||
backend = list.OrderBy(t => t.Item1).ToList();
|
backend = list.OrderBy(t => t.Item1).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Count
|
public int Count => backend.Count;
|
||||||
{
|
|
||||||
get { return backend.Count; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Add(int item)
|
public void Add(int item)
|
||||||
{
|
{
|
||||||
@@ -108,12 +105,7 @@ namespace Extents
|
|||||||
backend = backend.OrderBy(t => t.Item1).ToList();
|
backend = backend.OrderBy(t => t.Item1).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Add(int start, int end)
|
public void Add(int start, int end, bool run = false)
|
||||||
{
|
|
||||||
Add(start, end, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Add(int start, int end, bool run)
|
|
||||||
{
|
{
|
||||||
int realEnd;
|
int realEnd;
|
||||||
if(run) realEnd = start + end - 1;
|
if(run) realEnd = start + end - 1;
|
||||||
|
|||||||
@@ -45,15 +45,12 @@ namespace Extents
|
|||||||
backend = new List<Tuple<long, long>>();
|
backend = new List<Tuple<long, long>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExtentsLong(List<Tuple<long, long>> list)
|
public ExtentsLong(IEnumerable<Tuple<long, long>> list)
|
||||||
{
|
{
|
||||||
backend = list.OrderBy(t => t.Item1).ToList();
|
backend = list.OrderBy(t => t.Item1).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Count
|
public int Count => backend.Count;
|
||||||
{
|
|
||||||
get { return backend.Count; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Add(long item)
|
public void Add(long item)
|
||||||
{
|
{
|
||||||
@@ -108,12 +105,7 @@ namespace Extents
|
|||||||
backend = backend.OrderBy(t => t.Item1).ToList();
|
backend = backend.OrderBy(t => t.Item1).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Add(long start, long end)
|
public void Add(long start, long end, bool run = false)
|
||||||
{
|
|
||||||
Add(start, end, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Add(long start, long end, bool run)
|
|
||||||
{
|
{
|
||||||
long realEnd;
|
long realEnd;
|
||||||
if(run) realEnd = start + end - 1;
|
if(run) realEnd = start + end - 1;
|
||||||
|
|||||||
@@ -45,15 +45,12 @@ namespace Extents
|
|||||||
backend = new List<Tuple<sbyte, sbyte>>();
|
backend = new List<Tuple<sbyte, sbyte>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExtentsSByte(List<Tuple<sbyte, sbyte>> list)
|
public ExtentsSByte(IEnumerable<Tuple<sbyte, sbyte>> list)
|
||||||
{
|
{
|
||||||
backend = list.OrderBy(t => t.Item1).ToList();
|
backend = list.OrderBy(t => t.Item1).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Count
|
public int Count => backend.Count;
|
||||||
{
|
|
||||||
get { return backend.Count; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Add(sbyte item)
|
public void Add(sbyte item)
|
||||||
{
|
{
|
||||||
@@ -108,12 +105,7 @@ namespace Extents
|
|||||||
backend = backend.OrderBy(t => t.Item1).ToList();
|
backend = backend.OrderBy(t => t.Item1).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Add(sbyte start, sbyte end)
|
public void Add(sbyte start, sbyte end, bool run = false)
|
||||||
{
|
|
||||||
Add(start, end, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Add(sbyte start, sbyte end, bool run)
|
|
||||||
{
|
{
|
||||||
sbyte realEnd;
|
sbyte realEnd;
|
||||||
if(run) realEnd = (sbyte)(start + end - 1);
|
if(run) realEnd = (sbyte)(start + end - 1);
|
||||||
|
|||||||
@@ -45,15 +45,12 @@ namespace Extents
|
|||||||
backend = new List<Tuple<short, short>>();
|
backend = new List<Tuple<short, short>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExtentsShort(List<Tuple<short, short>> list)
|
public ExtentsShort(IEnumerable<Tuple<short, short>> list)
|
||||||
{
|
{
|
||||||
backend = list.OrderBy(t => t.Item1).ToList();
|
backend = list.OrderBy(t => t.Item1).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Count
|
public int Count => backend.Count;
|
||||||
{
|
|
||||||
get { return backend.Count; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Add(short item)
|
public void Add(short item)
|
||||||
{
|
{
|
||||||
@@ -108,12 +105,7 @@ namespace Extents
|
|||||||
backend = backend.OrderBy(t => t.Item1).ToList();
|
backend = backend.OrderBy(t => t.Item1).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Add(short start, short end)
|
public void Add(short start, short end, bool run = false)
|
||||||
{
|
|
||||||
Add(start, end, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Add(short start, short end, bool run)
|
|
||||||
{
|
{
|
||||||
short realEnd;
|
short realEnd;
|
||||||
if(run) realEnd = (short)(start + end - 1);
|
if(run) realEnd = (short)(start + end - 1);
|
||||||
|
|||||||
@@ -45,15 +45,12 @@ namespace Extents
|
|||||||
backend = new List<Tuple<uint, uint>>();
|
backend = new List<Tuple<uint, uint>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExtentsUInt(List<Tuple<uint, uint>> list)
|
public ExtentsUInt(IEnumerable<Tuple<uint, uint>> list)
|
||||||
{
|
{
|
||||||
backend = list.OrderBy(t => t.Item1).ToList();
|
backend = list.OrderBy(t => t.Item1).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Count
|
public int Count => backend.Count;
|
||||||
{
|
|
||||||
get { return backend.Count; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Add(uint item)
|
public void Add(uint item)
|
||||||
{
|
{
|
||||||
@@ -108,12 +105,7 @@ namespace Extents
|
|||||||
backend = backend.OrderBy(t => t.Item1).ToList();
|
backend = backend.OrderBy(t => t.Item1).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Add(uint start, uint end)
|
public void Add(uint start, uint end, bool run = false)
|
||||||
{
|
|
||||||
Add(start, end, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Add(uint start, uint end, bool run)
|
|
||||||
{
|
{
|
||||||
uint realEnd;
|
uint realEnd;
|
||||||
if(run) realEnd = start + end - 1;
|
if(run) realEnd = start + end - 1;
|
||||||
|
|||||||
@@ -45,15 +45,12 @@ namespace Extents
|
|||||||
backend = new List<Tuple<ulong, ulong>>();
|
backend = new List<Tuple<ulong, ulong>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExtentsULong(List<Tuple<ulong, ulong>> list)
|
public ExtentsULong(IEnumerable<Tuple<ulong, ulong>> list)
|
||||||
{
|
{
|
||||||
backend = list.OrderBy(t => t.Item1).ToList();
|
backend = list.OrderBy(t => t.Item1).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Count
|
public int Count => backend.Count;
|
||||||
{
|
|
||||||
get { return backend.Count; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Add(ulong item)
|
public void Add(ulong item)
|
||||||
{
|
{
|
||||||
@@ -108,12 +105,7 @@ namespace Extents
|
|||||||
backend = backend.OrderBy(t => t.Item1).ToList();
|
backend = backend.OrderBy(t => t.Item1).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Add(ulong start, ulong end)
|
public void Add(ulong start, ulong end, bool run = false)
|
||||||
{
|
|
||||||
Add(start, end, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Add(ulong start, ulong end, bool run)
|
|
||||||
{
|
{
|
||||||
ulong realEnd;
|
ulong realEnd;
|
||||||
if(run) realEnd = start + end - 1;
|
if(run) realEnd = start + end - 1;
|
||||||
|
|||||||
@@ -45,15 +45,12 @@ namespace Extents
|
|||||||
backend = new List<Tuple<ushort, ushort>>();
|
backend = new List<Tuple<ushort, ushort>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExtentsUShort(List<Tuple<ushort, ushort>> list)
|
public ExtentsUShort(IEnumerable<Tuple<ushort, ushort>> list)
|
||||||
{
|
{
|
||||||
backend = list.OrderBy(t => t.Item1).ToList();
|
backend = list.OrderBy(t => t.Item1).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Count
|
public int Count => backend.Count;
|
||||||
{
|
|
||||||
get { return backend.Count; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Add(ushort item)
|
public void Add(ushort item)
|
||||||
{
|
{
|
||||||
@@ -108,12 +105,7 @@ namespace Extents
|
|||||||
backend = backend.OrderBy(t => t.Item1).ToList();
|
backend = backend.OrderBy(t => t.Item1).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Add(ushort start, ushort end)
|
public void Add(ushort start, ushort end, bool run = false)
|
||||||
{
|
|
||||||
Add(start, end, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Add(ushort start, ushort end, bool run)
|
|
||||||
{
|
{
|
||||||
ushort realEnd;
|
ushort realEnd;
|
||||||
if(run) realEnd = (ushort)(start + end - 1);
|
if(run) realEnd = (ushort)(start + end - 1);
|
||||||
|
|||||||
@@ -118,12 +118,12 @@ namespace DiscImageChef
|
|||||||
|
|
||||||
public static ushort Swap(ushort x)
|
public static ushort Swap(ushort x)
|
||||||
{
|
{
|
||||||
return (ushort)((x << 8) | (x >> 8));
|
return (ushort) ((x << 8) | (x >> 8));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static short Swap(short x)
|
public static short Swap(short x)
|
||||||
{
|
{
|
||||||
return (short)((x << 8) | ((x >> 8) & 0xFF));
|
return (short) ((x << 8) | ((x >> 8) & 0xFF));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static uint Swap(uint x)
|
public static uint Swap(uint x)
|
||||||
@@ -134,8 +134,8 @@ namespace DiscImageChef
|
|||||||
|
|
||||||
public static int Swap(int x)
|
public static int Swap(int x)
|
||||||
{
|
{
|
||||||
x = (int)(((x << 8) & 0xFF00FF00) | (((uint)x >> 8) & 0xFF00FF));
|
x = (int) (((x << 8) & 0xFF00FF00) | (((uint) x >> 8) & 0xFF00FF));
|
||||||
return (int)(((uint)x << 16) | (((uint)x >> 16) & 0xFFFF));
|
return (int) (((uint) x << 16) | (((uint) x >> 16) & 0xFFFF));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user