DOCUMENTATION: Added XML documentation to DiscImageChef.Helpers.

This commit is contained in:
2017-12-23 03:51:42 +00:00
parent 6622bef335
commit 481e39c399
17 changed files with 687 additions and 437 deletions

View File

@@ -31,12 +31,24 @@ namespace DiscImageChef
{
public static partial class ArrayHelpers
{
/// <summary>
/// Fills an array with the specified value
/// </summary>
/// <param name="destinationArray">Array</param>
/// <param name="value">Value</param>
/// <typeparam name="T">Array type</typeparam>
public static void ArrayFill<T>(T[] destinationArray, T value)
{
// if called with a single value, wrap the value in an array and call the main function
ArrayFill(destinationArray, new[] {value});
}
/// <summary>
/// Fills an array with the contents of the specified array
/// </summary>
/// <param name="destinationArray">Array</param>
/// <param name="value">Value</param>
/// <typeparam name="T">Array type</typeparam>
public static void ArrayFill<T>(T[] destinationArray, T[] value)
{
if(destinationArray == null) throw new ArgumentNullException(nameof(destinationArray));
@@ -54,6 +66,12 @@ namespace DiscImageChef
Array.Copy(destinationArray, 0, destinationArray, copyLength, destinationArray.Length - copyLength);
}
/// <summary>
/// Converts a byte array to its hexadecimal representation
/// </summary>
/// <param name="array">Byte array</param>
/// <param name="upper"><c>true</c> to use uppercase</param>
/// <returns></returns>
public static string ByteArrayToHex(byte[] array, bool upper = false)
{
StringBuilder sb = new StringBuilder();

View File

@@ -36,11 +36,21 @@ namespace DiscImageChef
{
public static partial class ArrayHelpers
{
/// <summary>
/// Checks if an array is null, filled with the NULL byte (0x00) or ASCII whitespace (0x20)
/// </summary>
/// <param name="array">Array</param>
/// <returns>True if null or whitespace</returns>
public static bool ArrayIsNullOrWhiteSpace(byte[] array)
{
return array == null || array.All(b => b == 0x00 || b == 0x20);
}
/// <summary>
/// Checks if an array is null or filled with the NULL byte (0x00)
/// </summary>
/// <param name="array">Array</param>
/// <returns>True if null</returns>
public static bool ArrayIsNullOrEmpty(byte[] array)
{
return array == null || array.All(b => b == 0x00);

View File

@@ -40,327 +40,186 @@ namespace DiscImageChef
/// data types.
/// All info taken from the meta data of System.BitConverter. This implementation
/// allows for Endianness consideration.
///</summary>
/// </summary>
public static class BigEndianBitConverter
{
/// <summary>
/// Indicates the byte order ("endianess") in which data is stored in this computer
/// architecture.
///</summary>
/// </summary>
public static bool IsLittleEndian { get; set; }
// should default to false, which is what we want for Empire
/// <summary>
/// Converts the specified double-precision floating point number to a 64-bit
/// signed integer.
///
/// Parameters:
/// value:
/// The number to convert.
///
/// Returns:
/// A 64-bit signed integer whose value is equivalent to value.
///</summary>
/// Converts the specified double-precision floating point number to a 64-bit signed integer.
/// </summary>
/// <param name="value">The number to convert.</param>
/// <returns>A 64-bit signed integer whose value is equivalent to value.</returns>
/// <exception cref="NotImplementedException">It is not currently implemented</exception>
public static long DoubleToInt64Bits(double value)
{
throw new NotImplementedException();
}
///
/// <summary>
/// Returns the specified Boolean value as an array of bytes.
///
/// Parameters:
/// value:
/// A Boolean value.
///
/// Returns:
/// An array of bytes with length 1.
///</summary>
/// </summary>
/// <param name="value">A Boolean value.</param>
/// <returns>An array of bytes with length 1.</returns>
public static byte[] GetBytes(bool value)
{
return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray();
}
///
/// <summary>
/// Returns the specified Unicode character value as an array of bytes.
///
/// Parameters:
/// value:
/// A character to convert.
///
/// Returns:
/// An array of bytes with length 2.
///</summary>
/// </summary>
/// <param name="value">A character to convert.</param>
/// <returns>An array of bytes with length 2.</returns>
public static byte[] GetBytes(char value)
{
return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray();
}
///
/// <summary>
/// Returns the specified double-precision floating point value as an array of
/// bytes.
///
/// Parameters:
/// value:
/// The number to convert.
///
/// Returns:
/// An array of bytes with length 8.
///</summary>
/// Returns the specified double-precision floating point value as an array of bytes.
/// </summary>
/// <param name="value">The number to convert.</param>
/// <returns>An array of bytes with length 8.</returns>
public static byte[] GetBytes(double value)
{
return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray();
}
///
/// <summary>
/// Returns the specified single-precision floating point value as an array of
/// bytes.
///
/// Parameters:
/// value:
/// The number to convert.
///
/// Returns:
/// An array of bytes with length 4.
///</summary>
/// Returns the specified single-precision floating point value as an array of bytes.
/// </summary>
/// <param name="value">The number to convert.</param>
/// <returns>An array of bytes with length 4.</returns>
public static byte[] GetBytes(float value)
{
return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray();
}
///
/// <summary>
/// Returns the specified 32-bit signed integer value as an array of bytes.
///
/// Parameters:
/// value:
/// The number to convert.
///
/// Returns:
/// An array of bytes with length 4.
///</summary>
/// </summary>
/// <param name="value">The number to convert.</param>
/// <returns>An array of bytes with length 4.</returns>
public static byte[] GetBytes(int value)
{
return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray();
}
///
/// <summary>
/// Returns the specified 64-bit signed integer value as an array of bytes.
///
/// Parameters:
/// value:
/// The number to convert.
///
/// Returns:
/// An array of bytes with length 8.
///</summary>
/// </summary>
/// <param name="value">The number to convert.</param>
/// <returns>An array of bytes with length 8.</returns>
public static byte[] GetBytes(long value)
{
return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray();
}
///
/// <summary>
/// Returns the specified 16-bit signed integer value as an array of bytes.
///
/// Parameters:
/// value:
/// The number to convert.
///
/// Returns:
/// An array of bytes with length 2.
///</summary>
/// </summary>
/// <param name="value">The number to convert.</param>
/// <returns>An array of bytes with length 2.</returns>
public static byte[] GetBytes(short value)
{
return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray();
}
///
/// <summary>
/// Returns the specified 32-bit unsigned integer value as an array of bytes.
///
/// Parameters:
/// value:
/// The number to convert.
///
/// Returns:
/// An array of bytes with length 4.
///</summary>
//[CLSCompliant(false)]
/// </summary>
/// <param name="value">The number to convert.</param>
/// <returns>An array of bytes with length 4.</returns>
public static byte[] GetBytes(uint value)
{
return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray();
}
///
/// <summary>
/// Returns the specified 64-bit unsigned integer value as an array of bytes.
///
/// Parameters:
/// value:
/// The number to convert.
///
/// Returns:
/// An array of bytes with length 8.
///</summary>
//[CLSCompliant(false)]
/// </summary>
/// <param name="value">The number to convert.</param>
/// <returns>An array of bytes with length 8.</returns>
public static byte[] GetBytes(ulong value)
{
return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray();
}
///
/// <summary>
/// Returns the specified 16-bit unsigned integer value as an array of bytes.
///
/// Parameters:
/// value:
/// The number to convert.
///
/// Returns:
/// An array of bytes with length 2.
///</summary>
/// </summary>
/// <param name="value">The number to convert.</param>
/// <returns>An array of bytes with length 2.</returns>
public static byte[] GetBytes(ushort value)
{
return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray();
}
///
/// <summary>
/// Converts the specified 64-bit signed integer to a double-precision floating
/// point number.
///
/// Parameters:
/// value:
/// The number to convert.
///
/// Returns:
/// A double-precision floating point number whose value is equivalent to value.
///</summary>
/// Converts the specified 64-bit signed integer to a double-precision floating point number.
/// </summary>
/// <param name="value">The number to convert.</param>
/// <returns>A double-precision floating point number whose value is equivalent to value.</returns>
public static double Int64BitsToDouble(long value)
{
throw new NotImplementedException();
}
///
/// <summary>
/// Returns a Boolean value converted from one byte at a specified position in
/// a byte array.
///
/// Parameters:
/// value:
/// An array of bytes.
///
/// startIndex:
/// The starting position within value.
///
/// Returns:
/// true if the byte at startIndex in value is nonzero; otherwise, false.
///
/// Exceptions:
/// System.ArgumentNullException:
/// value is null.
///
/// System.ArgumentOutOfRangeException:
/// startIndex is less than zero or greater than the length of value minus 1.
///</summary>
/// Returns a Boolean value converted from one byte at a specified position in a byte array.
/// </summary>
/// <param name="value">An array of bytes.</param>
/// <param name="startIndex">The starting position within value.</param>
/// <returns>true if the byte at <see cref="startIndex"/> in value is nonzero; otherwise, false.</returns>
/// <exception cref="System.ArgumentNullException">value is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException"><see cref="startIndex"/> is less than zero or greater than the length of value minus 1.</exception>
public static bool ToBoolean(byte[] value, int startIndex)
{
throw new NotImplementedException();
}
///
/// <summary>
/// Returns a Unicode character converted from two bytes at a specified position
/// in a byte array.
///
/// Parameters:
/// value:
/// An array.
///
/// startIndex:
/// The starting position within value.
///
/// Returns:
/// A character formed by two bytes beginning at startIndex.
///
/// Exceptions:
/// System.ArgumentException:
/// startIndex equals the length of value minus 1.
///
/// System.ArgumentNullException:
/// value is null.
///
/// System.ArgumentOutOfRangeException:
/// startIndex is less than zero or greater than the length of value minus 1.
///</summary>
/// Returns a Unicode character converted from two bytes at a specified position in a byte array.
/// </summary>
/// <param name="value">An array.</param>
/// <param name="startIndex">The starting position within value.</param>
/// <returns>A character formed by two bytes beginning at <see cref="startIndex"/>.</returns>
/// <exception cref="System.ArgumentException"><see cref="startIndex"/> equals the length of value minus 1.</exception>
/// <exception cref="System.ArgumentNullException">value is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException"><see cref="startIndex"/> is less than zero or greater than the length of value minus 1.</exception>
public static char ToChar(byte[] value, int startIndex)
{
throw new NotImplementedException();
}
///
/// <summary>
/// Returns a double-precision floating point number converted from eight bytes
/// at a specified position in a byte array.
///
/// Parameters:
/// value:
/// An array of bytes.
///
/// startIndex:
/// The starting position within value.
///
/// Returns:
/// A double precision floating point number formed by eight bytes beginning
/// at startIndex.
///
/// Exceptions:
/// System.ArgumentException:
/// startIndex is greater than or equal to the length of value minus 7, and is
/// less than or equal to the length of value minus 1.
///
/// System.ArgumentNullException:
/// value is null.
///
/// System.ArgumentOutOfRangeException:
/// startIndex is less than zero or greater than the length of value minus 1.
///</summary>
/// Returns a double-precision floating point number converted from eight bytes at a specified position in a byte array.
/// </summary>
/// <param name="value">An array of bytes.</param>
/// <param name="startIndex">The starting position within value.</param>
/// <returns>A double precision floating point number formed by eight bytes beginning at <see cref="startIndex"/>.</returns>
/// <exception cref="System.ArgumentException"><see cref="startIndex"/> is greater than or equal to the length of value minus 7, and is less than or equal to the length of value minus 1.</exception>
/// <exception cref="System.ArgumentNullException">value is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException"><see cref="startIndex"/> is less than zero or greater than the length of value minus 1.</exception>
public static double ToDouble(byte[] value, int startIndex)
{
throw new NotImplementedException();
}
///
/// <summary>
/// Returns a 16-bit signed integer converted from two bytes at a specified position
/// in a byte array.
///
/// Parameters:
/// value:
/// An array of bytes.
///
/// startIndex:
/// The starting position within value.
///
/// Returns:
/// A 16-bit signed integer formed by two bytes beginning at startIndex.
///
/// Exceptions:
/// System.ArgumentException:
/// startIndex equals the length of value minus 1.
///
/// System.ArgumentNullException:
/// value is null.
///
/// System.ArgumentOutOfRangeException:
/// startIndex is less than zero or greater than the length of value minus 1.
///</summary>
/// Returns a 16-bit signed integer converted from two bytes at a specified position in a byte array.
/// </summary>
/// <param name="value">An array of bytes.</param>
/// <param name="startIndex">The starting position within value.</param>
/// <returns>A 16-bit signed integer formed by two bytes beginning at <see cref="startIndex"/>.</returns>
/// <exception cref="System.ArgumentException"><see cref="startIndex"/> equals the length of value minus 1.</exception>
/// <exception cref="System.ArgumentNullException">value is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException">startIndex is less than zero or greater than the length of value minus 1.</exception>
public static short ToInt16(byte[] value, int startIndex)
{
return !IsLittleEndian
@@ -368,32 +227,15 @@ namespace DiscImageChef
: BitConverter.ToInt16(value.Reverse().ToArray(), value.Length - sizeof(short) - startIndex);
}
///
/// <summary>
/// Returns a 32-bit signed integer converted from four bytes at a specified
/// position in a byte array.
///
/// Parameters:
/// value:
/// An array of bytes.
///
/// startIndex:
/// The starting position within value.
///
/// Returns:
/// A 32-bit signed integer formed by four bytes beginning at startIndex.
///
/// Exceptions:
/// System.ArgumentException:
/// startIndex is greater than or equal to the length of value minus 3, and is
/// less than or equal to the length of value minus 1.
///
/// System.ArgumentNullException:
/// value is null.
///
/// System.ArgumentOutOfRangeException:
/// startIndex is less than zero or greater than the length of value minus 1.
///</summary>
/// Returns a 32-bit signed integer converted from four bytes at a specified position in a byte array.
/// </summary>
/// <param name="value">An array of bytes.</param>
/// <param name="startIndex">The starting position within value.</param>
/// <returns>A 32-bit signed integer formed by four bytes beginning at <see cref="startIndex"/>.</returns>
/// <exception cref="System.ArgumentException"><see cref="startIndex"/> is greater than or equal to the length of value minus 3, and is less than or equal to the length of value minus 1.</exception>
/// <exception cref="System.ArgumentNullException">value is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException">startIndex is less than zero or greater than the length of value minus 1.</exception>
public static int ToInt32(byte[] value, int startIndex)
{
return !IsLittleEndian
@@ -401,32 +243,15 @@ namespace DiscImageChef
: BitConverter.ToInt32(value.Reverse().ToArray(), value.Length - sizeof(int) - startIndex);
}
///
/// <summary>
/// Returns a 64-bit signed integer converted from eight bytes at a specified
/// position in a byte array.
///
/// Parameters:
/// value:
/// An array of bytes.
///
/// startIndex:
/// The starting position within value.
///
/// Returns:
/// A 64-bit signed integer formed by eight bytes beginning at startIndex.
///
/// Exceptions:
/// System.ArgumentException:
/// startIndex is greater than or equal to the length of value minus 7, and is
/// less than or equal to the length of value minus 1.
///
/// System.ArgumentNullException:
/// value is null.
///
/// System.ArgumentOutOfRangeException:
/// startIndex is less than zero or greater than the length of value minus 1.
///</summary>
/// Returns a 64-bit signed integer converted from eight bytes at a specified position in a byte array.
/// </summary>
/// <param name="value">An array of bytes.</param>
/// <param name="startIndex">The starting position within value.</param>
/// <returns>A 64-bit signed integer formed by eight bytes beginning at <see cref="startIndex"/>.</returns>
/// <exception cref="System.ArgumentException"><see cref="startIndex"/> is greater than or equal to the length of value minus 7, and is less than or equal to the length of value minus 1.</exception>
/// <exception cref="System.ArgumentNullException">value is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException"><see cref="startIndex"/> is less than zero or greater than the length of value minus 1.</exception>
public static long ToInt64(byte[] value, int startIndex)
{
return !IsLittleEndian
@@ -434,33 +259,15 @@ namespace DiscImageChef
: BitConverter.ToInt64(value.Reverse().ToArray(), value.Length - sizeof(long) - startIndex);
}
///
/// <summary>
/// Returns a single-precision floating point number converted from four bytes
/// at a specified position in a byte array.
///
/// Parameters:
/// value:
/// An array of bytes.
///
/// startIndex:
/// The starting position within value.
///
/// Returns:
/// A single-precision floating point number formed by four bytes beginning at
/// startIndex.
///
/// Exceptions:
/// System.ArgumentException:
/// startIndex is greater than or equal to the length of value minus 3, and is
/// less than or equal to the length of value minus 1.
///
/// System.ArgumentNullException:
/// value is null.
///
/// System.ArgumentOutOfRangeException:
/// startIndex is less than zero or greater than the length of value minus 1.
///</summary>
/// Returns a single-precision floating point number converted from four bytes at a specified position in a byte array.
/// </summary>
/// <param name="value">An array of bytes.</param>
/// <param name="startIndex">The starting position within value.</param>
/// <returns>A single-precision floating point number formed by four bytes beginning at <see cref="startIndex"/>.</returns>
/// <exception cref="System.ArgumentException"><see cref="startIndex"/> is greater than or equal to the length of value minus 3, and is less than or equal to the length of value minus 1.</exception>
/// <exception cref="System.ArgumentNullException">value is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException"><see cref="startIndex"/> is less than zero or greater than the length of value minus 1.</exception>
public static float ToSingle(byte[] value, int startIndex)
{
return !IsLittleEndian
@@ -468,52 +275,25 @@ namespace DiscImageChef
: BitConverter.ToSingle(value.Reverse().ToArray(), value.Length - sizeof(float) - startIndex);
}
///
/// <summary>
/// Converts the numeric value of each element of a specified array of bytes
/// to its equivalent hexadecimal string representation.
///
/// Parameters:
/// value:
/// An array of bytes.
///
/// Returns:
/// A System.String of hexadecimal pairs separated by hyphens, where each pair
/// represents the corresponding element in value; for example, "7F-2C-4A".
///
/// Exceptions:
/// System.ArgumentNullException:
/// value is null.
///</summary>
/// Converts the numeric value of each element of a specified array of bytes to its equivalent hexadecimal string representation.
/// </summary>
/// <param name="value">An array of bytes.</param>
/// <returns>A System.String of hexadecimal pairs separated by hyphens, where each pair represents the corresponding element in value; for example, "7F-2C-4A".</returns>
/// <exception cref="System.ArgumentNullException">value is null.</exception>
public static string ToString(byte[] value)
{
return !IsLittleEndian ? BitConverter.ToString(value) : BitConverter.ToString(value.Reverse().ToArray());
}
///
/// <summary>
/// Converts the numeric value of each element of a specified subarray of bytes
/// to its equivalent hexadecimal string representation.
///
/// Parameters:
/// value:
/// An array of bytes.
///
/// startIndex:
/// The starting position within value.
///
/// Returns:
/// A System.String of hexadecimal pairs separated by hyphens, where each pair
/// represents the corresponding element in a subarray of value; for example,
/// "7F-2C-4A".
///
/// Exceptions:
/// System.ArgumentNullException:
/// value is null.
///
/// System.ArgumentOutOfRangeException:
/// startIndex is less than zero or greater than the length of value minus 1.
///</summary>
/// Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal string representation.
/// </summary>
/// <param name="value">An array of bytes.</param>
/// <param name="startIndex">The starting position within value.</param>
/// <returns>A System.String of hexadecimal pairs separated by hyphens, where each pair represents the corresponding element in a subarray of value; for example, "7F-2C-4A".</returns>
/// <exception cref="System.ArgumentNullException">value is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException">startIndex is less than zero or greater than the length of value minus 1.</exception>
public static string ToString(byte[] value, int startIndex)
{
return !IsLittleEndian
@@ -521,39 +301,16 @@ namespace DiscImageChef
: BitConverter.ToString(value.Reverse().ToArray(), startIndex);
}
///
/// <summary>
/// Converts the numeric value of each element of a specified subarray of bytes
/// to its equivalent hexadecimal string representation.
///
/// Parameters:
/// value:
/// An array of bytes.
///
/// startIndex:
/// The starting position within value.
///
/// length:
/// The number of array elements in value to convert.
///
/// Returns:
/// A System.String of hexadecimal pairs separated by hyphens, where each pair
/// represents the corresponding element in a subarray of value; for example,
/// "7F-2C-4A".
///
/// Exceptions:
/// System.ArgumentNullException:
/// value is null.
///
/// System.ArgumentOutOfRangeException:
/// startIndex or length is less than zero. -or- startIndex is greater than
/// zero and is greater than or equal to the length of value.
///
/// System.ArgumentException:
/// The combination of startIndex and length does not specify a position within
/// value; that is, the startIndex parameter is greater than the length of value
/// minus the length parameter.
///</summary>
/// Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal string representation.
/// </summary>
/// <param name="value">An array of bytes.</param>
/// <param name="startIndex">The starting position within value.</param>
/// <param name="length">The number of array elements in value to convert.</param>
/// <returns>A System.String of hexadecimal pairs separated by hyphens, where each pair represents the corresponding element in a subarray of value; for example, "7F-2C-4A".</returns>
/// <exception cref="System.ArgumentNullException">value is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException">startIndex or length is less than zero. -or- startIndex is greater than zero and is greater than or equal to the length of value.</exception>
/// <exception cref="System.ArgumentException">The combination of startIndex and length does not specify a position within value; that is, the startIndex parameter is greater than the length of value minus the length parameter.</exception>
public static string ToString(byte[] value, int startIndex, int length)
{
return !IsLittleEndian
@@ -561,31 +318,15 @@ namespace DiscImageChef
: BitConverter.ToString(value.Reverse().ToArray(), startIndex, length);
}
///
/// <summary>
/// Returns a 16-bit unsigned integer converted from two bytes at a specified
/// position in a byte array.
///
/// Parameters:
/// value:
/// The array of bytes.
///
/// startIndex:
/// The starting position within value.
///
/// Returns:
/// A 16-bit unsigned integer formed by two bytes beginning at startIndex.
///
/// Exceptions:
/// System.ArgumentException:
/// startIndex equals the length of value minus 1.
///
/// System.ArgumentNullException:
/// value is null.
///
/// System.ArgumentOutOfRangeException:
/// startIndex is less than zero or greater than the length of value minus 1.
///</summary>
/// Returns a 16-bit unsigned integer converted from two bytes at a specified position in a byte array.
/// </summary>
/// <param name="value">The array of bytes.</param>
/// <param name="startIndex">The starting position within value.</param>
/// <returns>A 16-bit unsigned integer formed by two bytes beginning at startIndex.</returns>
/// <exception cref="System.ArgumentException">startIndex equals the length of value minus 1.</exception>
/// <exception cref="System.ArgumentNullException">value is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException">startIndex is less than zero or greater than the length of value minus 1.</exception>
public static ushort ToUInt16(byte[] value, int startIndex)
{
return !IsLittleEndian
@@ -593,32 +334,15 @@ namespace DiscImageChef
: BitConverter.ToUInt16(value.Reverse().ToArray(), value.Length - sizeof(ushort) - startIndex);
}
///
/// <summary>
/// Returns a 32-bit unsigned integer converted from four bytes at a specified
/// position in a byte array.
///
/// Parameters:
/// value:
/// An array of bytes.
///
/// startIndex:
/// The starting position within value.
///
/// Returns:
/// A 32-bit unsigned integer formed by four bytes beginning at startIndex.
///
/// Exceptions:
/// System.ArgumentException:
/// startIndex is greater than or equal to the length of value minus 3, and is
/// less than or equal to the length of value minus 1.
///
/// System.ArgumentNullException:
/// value is null.
///
/// System.ArgumentOutOfRangeException:
/// startIndex is less than zero or greater than the length of value minus 1.
///</summary>
/// Returns a 32-bit unsigned integer converted from four bytes at a specified position in a byte array.
/// </summary>
/// <param name="value">An array of bytes.</param>
/// <param name="startIndex">The starting position within value.</param>
/// <returns>A 32-bit unsigned integer formed by four bytes beginning at startIndex.</returns>
/// <exception cref="System.ArgumentException">startIndex is greater than or equal to the length of value minus 3, and is less than or equal to the length of value minus 1.</exception>
/// <exception cref="System.ArgumentNullException">value is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException">startIndex is less than zero or greater than the length of value minus 1.</exception>
public static uint ToUInt32(byte[] value, int startIndex)
{
return !IsLittleEndian
@@ -626,32 +350,15 @@ namespace DiscImageChef
: BitConverter.ToUInt32(value.Reverse().ToArray(), value.Length - sizeof(uint) - startIndex);
}
///
/// <summary>
/// Returns a 64-bit unsigned integer converted from eight bytes at a specified
/// position in a byte array.
///
/// Parameters:
/// value:
/// An array of bytes.
///
/// startIndex:
/// The starting position within value.
///
/// Returns:
/// A 64-bit unsigned integer formed by the eight bytes beginning at startIndex.
///
/// Exceptions:
/// System.ArgumentException:
/// startIndex is greater than or equal to the length of value minus 7, and is
/// less than or equal to the length of value minus 1.
///
/// System.ArgumentNullException:
/// value is null.
///
/// System.ArgumentOutOfRangeException:
/// startIndex is less than zero or greater than the length of value minus 1.
///</summary>
/// Returns a 64-bit unsigned integer converted from eight bytes at a specified position in a byte array.
/// </summary>
/// <param name="value">An array of bytes.</param>
/// <param name="startIndex">The starting position within value.</param>
/// <returns>A 64-bit unsigned integer formed by the eight bytes beginning at startIndex.</returns>
/// <exception cref="System.ArgumentException">startIndex is greater than or equal to the length of value minus 7, and is less than or equal to the length of value minus 1.</exception>
/// <exception cref="System.ArgumentNullException">value is null.</exception>
/// <exception cref="System.ArgumentOutOfRangeException">startIndex is less than zero or greater than the length of value minus 1.</exception>
public static ulong ToUInt64(byte[] value, int startIndex)
{
return !IsLittleEndian

9
CHS.cs
View File

@@ -34,6 +34,15 @@ namespace DiscImageChef.Helpers
{
public static class CHS
{
/// <summary>
/// Converts a CHS position to a LBA one
/// </summary>
/// <param name="cyl">Cylinder</param>
/// <param name="head">Head</param>
/// <param name="sector">Sector</param>
/// <param name="maxHead">Number of heads</param>
/// <param name="maxSector">Number of sectors per track</param>
/// <returns></returns>
public static uint ToLBA(uint cyl, uint head, uint sector, uint maxHead, uint maxSector)
{
return maxHead == 0 || maxSector == 0

View File

@@ -34,6 +34,13 @@ namespace DiscImageChef
{
public static partial class ArrayHelpers
{
/// <summary>
/// Compares two byte arrays
/// </summary>
/// <param name="different"><c>true</c> if they are different in any way</param>
/// <param name="sameSize"><c>true</c> if they have the same size</param>
/// <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)
{

View File

@@ -34,6 +34,11 @@ namespace DiscImageChef.Helpers
{
public static class CountBits
{
/// <summary>
/// Counts the number of bits set to <c>true</c> in a number
/// </summary>
/// <param name="number">Number</param>
/// <returns>Bits set to <c>true</c></returns>
public static int Count(uint number)
{
number = number - ((number >> 1) & 0x55555555);

View File

@@ -46,41 +46,82 @@ namespace DiscImageChef
static readonly DateTime AmigaEpoch = new DateTime(1978, 1, 1, 0, 0, 0);
static readonly DateTime AppleDoubleEpoch = new DateTime(1970, 1, 1, 0, 0, 0);
/// <summary>
/// Converts a Macintosh timestamp to a .NET DateTime
/// </summary>
/// <param name="MacTimeStamp">Macintosh timestamp (seconds since 1st Jan. 1904)</param>
/// <returns>.NET DateTime</returns>
public static DateTime MacToDateTime(ulong MacTimeStamp)
{
return MacEpoch.AddTicks((long)(MacTimeStamp * 10000000));
}
/// <summary>
/// Converts a Lisa timestamp to a .NET DateTime
/// </summary>
/// <param name="LisaTimeStamp">Lisa timestamp (seconds since 1st Jan. 1901)</param>
/// <returns>.NET DateTime</returns>
public static DateTime LisaToDateTime(uint LisaTimeStamp)
{
return LisaEpoch.AddSeconds(LisaTimeStamp);
}
/// <summary>
/// Converts a UNIX timestamp to a .NET DateTime
/// </summary>
/// <param name="UNIXTimeStamp">UNIX timestamp (seconds since 1st Jan. 1970)</param>
/// <returns>.NET DateTime</returns>
public static DateTime UNIXToDateTime(int UNIXTimeStamp)
{
return UNIXEpoch.AddSeconds(UNIXTimeStamp);
}
/// <summary>
/// Converts a UNIX timestamp to a .NET DateTime
/// </summary>
/// <param name="UNIXTimeStamp">UNIX timestamp (seconds since 1st Jan. 1970)</param>
/// <returns>.NET DateTime</returns>
public static DateTime UNIXToDateTime(long UNIXTimeStamp)
{
return UNIXEpoch.AddSeconds(UNIXTimeStamp);
}
/// <summary>
/// Converts a UNIX timestamp to a .NET DateTime
/// </summary>
/// <param name="UNIXTimeStamp">UNIX timestamp (seconds since 1st Jan. 1970)</param>
/// <returns>.NET DateTime</returns>
public static DateTime UNIXUnsignedToDateTime(uint UNIXTimeStamp)
{
return UNIXEpoch.AddSeconds(UNIXTimeStamp);
}
/// <summary>
/// Converts a UNIX timestamp to a .NET DateTime
/// </summary>
/// <param name="seconds">Seconds since 1st Jan. 1970)</param>
/// <param name="nanoseconds">Nanoseconds</param>
/// <returns>.NET DateTime</returns>
public static DateTime UNIXUnsignedToDateTime(uint seconds, uint nanoseconds)
{
return UNIXEpoch.AddSeconds(seconds).AddTicks((long)nanoseconds / 100);
}
/// <summary>
/// Converts a UNIX timestamp to a .NET DateTime
/// </summary>
/// <param name="UNIXTimeStamp">UNIX timestamp (seconds since 1st Jan. 1970)</param>
/// <returns>.NET DateTime</returns>
public static DateTime UNIXUnsignedToDateTime(ulong UNIXTimeStamp)
{
return UNIXEpoch.AddSeconds(UNIXTimeStamp);
}
/// <summary>
/// Converts a High Sierra Format timestamp to a .NET DateTime
/// </summary>
/// <param name="VDDateTime">High Sierra Format timestamp</param>
/// <returns>.NET DateTime</returns>
public static DateTime HighSierraToDateTime(byte[] VDDateTime)
{
byte[] isotime = new byte[17];
@@ -89,6 +130,11 @@ namespace DiscImageChef
}
// TODO: Timezone
/// <summary>
/// Converts an ISO9660 timestamp to a .NET DateTime
/// </summary>
/// <param name="VDDateTime">ISO9660 timestamp</param>
/// <returns>.NET DateTime</returns>
public static DateTime ISO9660ToDateTime(byte[] VDDateTime)
{
int year, month, day, hour, minute, second, hundredths;
@@ -155,13 +201,25 @@ namespace DiscImageChef
return decodedDT;
}
// C# works in UTC, VMS on Julian Date, some displacement may occur on disks created outside UTC
/// <summary>
/// Converts a VMS timestamp to a .NET DateTime
/// </summary>
/// <param name="vmsDate">VMS timestamp (tenths of microseconds since day 0 of the Julian Date)</param>
/// <returns>.NET DateTime</returns>
/// <remarks>C# works in UTC, VMS on Julian Date, some displacement may occur on disks created outside UTC</remarks>
public static DateTime VMSToDateTime(ulong vmsDate)
{
double delta = vmsDate * 0.0001; // Tenths of microseconds to milliseconds, will lose some detail
return JulianEpoch.AddMilliseconds(delta);
}
/// <summary>
/// Converts an Amiga timestamp to a .NET DateTime
/// </summary>
/// <param name="days">Days since the 1st Jan. 1978</param>
/// <param name="minutes">Minutes since o'clock</param>
/// <param name="ticks">Ticks</param>
/// <returns>.NET DateTime</returns>
public static DateTime AmigaToDateTime(uint days, uint minutes, uint ticks)
{
DateTime temp = AmigaEpoch.AddDays(days);
@@ -169,6 +227,11 @@ namespace DiscImageChef
return temp.AddMilliseconds(ticks * 20);
}
/// <summary>
/// Converts an UCSD Pascal timestamp to a .NET DateTime
/// </summary>
/// <param name="dateRecord">UCSD Pascal timestamp</param>
/// <returns>.NET DateTime</returns>
public static DateTime UCSDPascalToDateTime(short dateRecord)
{
int year = ((dateRecord & 0xFE00) >> 9) + 1900;
@@ -181,6 +244,12 @@ namespace DiscImageChef
return new DateTime(year, month, day);
}
/// <summary>
/// Converts a DOS timestamp to a .NET DateTime
/// </summary>
/// <param name="date">Date</param>
/// <param name="time">Time</param>
/// <returns>.NET DateTime</returns>
public static DateTime DOSToDateTime(ushort date, ushort time)
{
int year = ((date & 0xFE00) >> 9) + 1980;
@@ -203,6 +272,11 @@ namespace DiscImageChef
return dosdate;
}
/// <summary>
/// Converts a CP/M timestamp to .NET DateTime
/// </summary>
/// <param name="timestamp">CP/M timestamp</param>
/// <returns>.NET DateTime</returns>
public static DateTime CPMToDateTime(byte[] timestamp)
{
ushort days = BitConverter.ToUInt16(timestamp, 0);
@@ -216,11 +290,26 @@ namespace DiscImageChef
return temp;
}
// TODO: This is unix
public static DateTime AppleDoubleToDateTime(ulong AppleDoubleTimeStamp)
{
return AppleDoubleEpoch.AddSeconds(AppleDoubleTimeStamp);
}
/// <summary>
/// Converts an ECMA timestamp to a .NET DateTime
/// </summary>
/// <param name="typeAndTimeZone">Timezone</param>
/// <param name="year">Year</param>
/// <param name="month">Month</param>
/// <param name="day">Day</param>
/// <param name="hour">Hour</param>
/// <param name="minute">Minute</param>
/// <param name="second">Second</param>
/// <param name="centiseconds">Centiseconds</param>
/// <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)
@@ -245,11 +334,21 @@ namespace DiscImageChef
.AddTicks(ticks).DateTime;
}
/// <summary>
/// Convers a Solaris high resolution timestamp to .NET DateTime
/// </summary>
/// <param name="HRTimeStamp">Solaris high resolution timestamp</param>
/// <returns>.NET DateTime</returns>
public static DateTime UNIXHrTimeToDateTime(ulong HRTimeStamp)
{
return UNIXEpoch.AddTicks((long)(HRTimeStamp / 100));
}
/// <summary>
/// Converts an OS-9 timestamp to .NET DateTime
/// </summary>
/// <param name="date">OS-9 timestamp</param>
/// <returns>.NET DateTime</returns>
public static DateTime OS9ToDateTime(byte[] date)
{
if(date == null || date.Length != 3 && date.Length != 5) return DateTime.MinValue;
@@ -267,6 +366,11 @@ namespace DiscImageChef
return os9date;
}
/// <summary>
/// Converts a LIF timestamp to .NET DateTime
/// </summary>
/// <param name="date">LIF timestamp</param>
/// <returns>.NET DateTime</returns>
public static DateTime LifToDateTime(byte[] date)
{
if(date == null || date.Length != 6) return new DateTime(1970, 1, 1, 0, 0, 0);
@@ -274,6 +378,16 @@ namespace DiscImageChef
return LifToDateTime(date[0], date[1], date[2], date[3], date[4], date[5]);
}
/// <summary>
/// Converts a LIF timestamp to .NET DateTime
/// </summary>
/// <param name="year">Yer</param>
/// <param name="month">Month</param>
/// <param name="day">Day</param>
/// <param name="hour">Hour</param>
/// <param name="minute">Minute</param>
/// <param name="second">Second</param>
/// <returns>.NET DateTime</returns>
public static DateTime LifToDateTime(byte year, byte month, byte day, byte hour, byte minute, byte second)
{
try

View File

@@ -30,6 +30,7 @@
// Copyright © 2011-2018 Natalia Portillo
// ****************************************************************************/
// TODO: Just remove
using System;
using System.IO;
using System.Linq;

View File

@@ -36,22 +36,39 @@ using System.Linq;
namespace Extents
{
/// <summary>
/// Implements extents for <see cref="byte"/>
/// </summary>
public class ExtentsByte
{
List<Tuple<byte, byte>> backend;
/// <summary>
/// Initialize an empty list of extents
/// </summary>
public ExtentsByte()
{
backend = new List<Tuple<byte, byte>>();
}
/// <summary>
/// Initializes extents with an specific list
/// </summary>
/// <param name="list">List of extents as tuples "start, end"</param>
public ExtentsByte(IEnumerable<Tuple<byte, byte>> list)
{
backend = list.OrderBy(t => t.Item1).ToList();
}
/// <summary>
/// Gets a count of how many extents are stored
/// </summary>
public int Count => backend.Count;
/// <summary>
/// Adds the specified number to the corresponding extent, or creates a new one
/// </summary>
/// <param name="item"></param>
public void Add(byte item)
{
Tuple<byte, byte> removeOne = null;
@@ -105,6 +122,12 @@ namespace Extents
backend = backend.OrderBy(t => t.Item1).ToList();
}
/// <summary>
/// Adds a new extent
/// </summary>
/// <param name="start">First element of the extent</param>
/// <param name="end">Last element of the extent or if <see cref="run"/> is <c>true</c> how many elements the extent runs for</param>
/// <param name="run">If set to <c>true</c>, <see cref="end"/> indicates how many elements the extent runs for</param>
public void Add(byte start, byte end, bool run = false)
{
byte realEnd;
@@ -115,16 +138,29 @@ namespace Extents
for(byte t = start; t <= realEnd; t++) Add(t);
}
/// <summary>
/// Checks if the specified item is contained by an extent on this instance
/// </summary>
/// <param name="item">Item to seach for</param>
/// <returns><c>true</c> if any of the extents on this instance contains the item</returns>
public bool Contains(byte item)
{
return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2);
}
/// <summary>
/// Removes all extents from this instance
/// </summary>
public void Clear()
{
backend.Clear();
}
/// <summary>
/// Removes an item from the extents in this instance
/// </summary>
/// <param name="item">Item to remove</param>
/// <returns><c>true</c> if the item was contained in a known extent and removed, false otherwise</returns>
public bool Remove(byte item)
{
Tuple<byte, byte> toRemove = null;
@@ -178,11 +214,21 @@ namespace Extents
return true;
}
/// <summary>
/// Converts the list of extents to an array of <see cref="Tuple"/> where T1 is first element of the extent and T2 is last element
/// </summary>
/// <returns>Array of <see cref="Tuple"/></returns>
public Tuple<byte, byte>[] ToArray()
{
return backend.ToArray();
}
/// <summary>
/// Gets the first element of the extent that contains the specified item
/// </summary>
/// <param name="item">Item</param>
/// <param name="start">First element of extent</param>
/// <returns><c>true</c> if item was found in an extent, false otherwise</returns>
public bool GetStart(byte item, out byte start)
{
start = 0;

View File

@@ -36,22 +36,39 @@ using System.Linq;
namespace Extents
{
/// <summary>
/// Implements extents for <see cref="int"/>
/// </summary>
public class ExtentsInt
{
List<Tuple<int, int>> backend;
/// <summary>
/// Initialize an empty list of extents
/// </summary>
public ExtentsInt()
{
backend = new List<Tuple<int, int>>();
}
/// <summary>
/// Initializes extents with an specific list
/// </summary>
/// <param name="list">List of extents as tuples "start, end"</param>
public ExtentsInt(IEnumerable<Tuple<int, int>> list)
{
backend = list.OrderBy(t => t.Item1).ToList();
}
/// <summary>
/// Gets a count of how many extents are stored
/// </summary>
public int Count => backend.Count;
/// <summary>
/// Adds the specified number to the corresponding extent, or creates a new one
/// </summary>
/// <param name="item"></param>
public void Add(int item)
{
Tuple<int, int> removeOne = null;
@@ -105,6 +122,12 @@ namespace Extents
backend = backend.OrderBy(t => t.Item1).ToList();
}
/// <summary>
/// Adds a new extent
/// </summary>
/// <param name="start">First element of the extent</param>
/// <param name="end">Last element of the extent or if <see cref="run"/> is <c>true</c> how many elements the extent runs for</param>
/// <param name="run">If set to <c>true</c>, <see cref="end"/> indicates how many elements the extent runs for</param>
public void Add(int start, int end, bool run = false)
{
int realEnd;
@@ -115,16 +138,29 @@ namespace Extents
for(int t = start; t <= realEnd; t++) Add(t);
}
/// <summary>
/// Checks if the specified item is contained by an extent on this instance
/// </summary>
/// <param name="item">Item to seach for</param>
/// <returns><c>true</c> if any of the extents on this instance contains the item</returns>
public bool Contains(int item)
{
return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2);
}
/// <summary>
/// Removes all extents from this instance
/// </summary>
public void Clear()
{
backend.Clear();
}
/// <summary>
/// Removes an item from the extents in this instance
/// </summary>
/// <param name="item">Item to remove</param>
/// <returns><c>true</c> if the item was contained in a known extent and removed, false otherwise</returns>
public bool Remove(int item)
{
Tuple<int, int> toRemove = null;
@@ -178,11 +214,21 @@ namespace Extents
return true;
}
/// <summary>
/// Converts the list of extents to an array of <see cref="Tuple"/> where T1 is first element of the extent and T2 is last element
/// </summary>
/// <returns>Array of <see cref="Tuple"/></returns>
public Tuple<int, int>[] ToArray()
{
return backend.ToArray();
}
/// <summary>
/// Gets the first element of the extent that contains the specified item
/// </summary>
/// <param name="item">Item</param>
/// <param name="start">First element of extent</param>
/// <returns><c>true</c> if item was found in an extent, false otherwise</returns>
public bool GetStart(int item, out int start)
{
start = 0;

View File

@@ -36,22 +36,39 @@ using System.Linq;
namespace Extents
{
/// <summary>
/// Implements extents for <see cref="long"/>
/// </summary>
public class ExtentsLong
{
List<Tuple<long, long>> backend;
/// <summary>
/// Initialize an empty list of extents
/// </summary>
public ExtentsLong()
{
backend = new List<Tuple<long, long>>();
}
/// <summary>
/// Initializes extents with an specific list
/// </summary>
/// <param name="list">List of extents as tuples "start, end"</param>
public ExtentsLong(IEnumerable<Tuple<long, long>> list)
{
backend = list.OrderBy(t => t.Item1).ToList();
}
/// <summary>
/// Gets a count of how many extents are stored
/// </summary>
public int Count => backend.Count;
/// <summary>
/// Adds the specified number to the corresponding extent, or creates a new one
/// </summary>
/// <param name="item"></param>
public void Add(long item)
{
Tuple<long, long> removeOne = null;
@@ -105,6 +122,12 @@ namespace Extents
backend = backend.OrderBy(t => t.Item1).ToList();
}
/// <summary>
/// Adds a new extent
/// </summary>
/// <param name="start">First element of the extent</param>
/// <param name="end">Last element of the extent or if <see cref="run"/> is <c>true</c> how many elements the extent runs for</param>
/// <param name="run">If set to <c>true</c>, <see cref="end"/> indicates how many elements the extent runs for</param>
public void Add(long start, long end, bool run = false)
{
long realEnd;
@@ -115,16 +138,29 @@ namespace Extents
for(long t = start; t <= realEnd; t++) Add(t);
}
/// <summary>
/// Checks if the specified item is contained by an extent on this instance
/// </summary>
/// <param name="item">Item to seach for</param>
/// <returns><c>true</c> if any of the extents on this instance contains the item</returns>
public bool Contains(long item)
{
return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2);
}
/// <summary>
/// Removes all extents from this instance
/// </summary>
public void Clear()
{
backend.Clear();
}
/// <summary>
/// Removes an item from the extents in this instance
/// </summary>
/// <param name="item">Item to remove</param>
/// <returns><c>true</c> if the item was contained in a known extent and removed, false otherwise</returns>
public bool Remove(long item)
{
Tuple<long, long> toRemove = null;
@@ -178,11 +214,21 @@ namespace Extents
return true;
}
/// <summary>
/// Converts the list of extents to an array of <see cref="Tuple"/> where T1 is first element of the extent and T2 is last element
/// </summary>
/// <returns>Array of <see cref="Tuple"/></returns>
public Tuple<long, long>[] ToArray()
{
return backend.ToArray();
}
/// <summary>
/// Gets the first element of the extent that contains the specified item
/// </summary>
/// <param name="item">Item</param>
/// <param name="start">First element of extent</param>
/// <returns><c>true</c> if item was found in an extent, false otherwise</returns>
public bool GetStart(long item, out long start)
{
start = 0;

View File

@@ -36,22 +36,39 @@ using System.Linq;
namespace Extents
{
/// <summary>
/// Implements extents for <see cref="sbyte"/>
/// </summary>
public class ExtentsSByte
{
List<Tuple<sbyte, sbyte>> backend;
/// <summary>
/// Initialize an empty list of extents
/// </summary>
public ExtentsSByte()
{
backend = new List<Tuple<sbyte, sbyte>>();
}
/// <summary>
/// Initializes extents with an specific list
/// </summary>
/// <param name="list">List of extents as tuples "start, end"</param>
public ExtentsSByte(IEnumerable<Tuple<sbyte, sbyte>> list)
{
backend = list.OrderBy(t => t.Item1).ToList();
}
/// <summary>
/// Gets a count of how many extents are stored
/// </summary>
public int Count => backend.Count;
/// <summary>
/// Adds the specified number to the corresponding extent, or creates a new one
/// </summary>
/// <param name="item"></param>
public void Add(sbyte item)
{
Tuple<sbyte, sbyte> removeOne = null;
@@ -105,6 +122,12 @@ namespace Extents
backend = backend.OrderBy(t => t.Item1).ToList();
}
/// <summary>
/// Adds a new extent
/// </summary>
/// <param name="start">First element of the extent</param>
/// <param name="end">Last element of the extent or if <see cref="run"/> is <c>true</c> how many elements the extent runs for</param>
/// <param name="run">If set to <c>true</c>, <see cref="end"/> indicates how many elements the extent runs for</param>
public void Add(sbyte start, sbyte end, bool run = false)
{
sbyte realEnd;
@@ -115,16 +138,29 @@ namespace Extents
for(sbyte t = start; t <= realEnd; t++) Add(t);
}
/// <summary>
/// Checks if the specified item is contained by an extent on this instance
/// </summary>
/// <param name="item">Item to seach for</param>
/// <returns><c>true</c> if any of the extents on this instance contains the item</returns>
public bool Contains(sbyte item)
{
return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2);
}
/// <summary>
/// Removes all extents from this instance
/// </summary>
public void Clear()
{
backend.Clear();
}
/// <summary>
/// Removes an item from the extents in this instance
/// </summary>
/// <param name="item">Item to remove</param>
/// <returns><c>true</c> if the item was contained in a known extent and removed, false otherwise</returns>
public bool Remove(sbyte item)
{
Tuple<sbyte, sbyte> toRemove = null;
@@ -178,11 +214,21 @@ namespace Extents
return true;
}
/// <summary>
/// Converts the list of extents to an array of <see cref="Tuple"/> where T1 is first element of the extent and T2 is last element
/// </summary>
/// <returns>Array of <see cref="Tuple"/></returns>
public Tuple<sbyte, sbyte>[] ToArray()
{
return backend.ToArray();
}
/// <summary>
/// Gets the first element of the extent that contains the specified item
/// </summary>
/// <param name="item">Item</param>
/// <param name="start">First element of extent</param>
/// <returns><c>true</c> if item was found in an extent, false otherwise</returns>
public bool GetStart(sbyte item, out sbyte start)
{
start = 0;

View File

@@ -36,22 +36,39 @@ using System.Linq;
namespace Extents
{
/// <summary>
/// Implements extents for <see cref="short"/>
/// </summary>
public class ExtentsShort
{
List<Tuple<short, short>> backend;
/// <summary>
/// Initialize an empty list of extents
/// </summary>
public ExtentsShort()
{
backend = new List<Tuple<short, short>>();
}
/// <summary>
/// Initializes extents with an specific list
/// </summary>
/// <param name="list">List of extents as tuples "start, end"</param>
public ExtentsShort(IEnumerable<Tuple<short, short>> list)
{
backend = list.OrderBy(t => t.Item1).ToList();
}
/// <summary>
/// Gets a count of how many extents are stored
/// </summary>
public int Count => backend.Count;
/// <summary>
/// Adds the specified number to the corresponding extent, or creates a new one
/// </summary>
/// <param name="item"></param>
public void Add(short item)
{
Tuple<short, short> removeOne = null;
@@ -105,6 +122,12 @@ namespace Extents
backend = backend.OrderBy(t => t.Item1).ToList();
}
/// <summary>
/// Adds a new extent
/// </summary>
/// <param name="start">First element of the extent</param>
/// <param name="end">Last element of the extent or if <see cref="run"/> is <c>true</c> how many elements the extent runs for</param>
/// <param name="run">If set to <c>true</c>, <see cref="end"/> indicates how many elements the extent runs for</param>
public void Add(short start, short end, bool run = false)
{
short realEnd;
@@ -115,16 +138,29 @@ namespace Extents
for(short t = start; t <= realEnd; t++) Add(t);
}
/// <summary>
/// Checks if the specified item is contained by an extent on this instance
/// </summary>
/// <param name="item">Item to seach for</param>
/// <returns><c>true</c> if any of the extents on this instance contains the item</returns>
public bool Contains(short item)
{
return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2);
}
/// <summary>
/// Removes all extents from this instance
/// </summary>
public void Clear()
{
backend.Clear();
}
/// <summary>
/// Removes an item from the extents in this instance
/// </summary>
/// <param name="item">Item to remove</param>
/// <returns><c>true</c> if the item was contained in a known extent and removed, false otherwise</returns>
public bool Remove(short item)
{
Tuple<short, short> toRemove = null;
@@ -178,11 +214,21 @@ namespace Extents
return true;
}
/// <summary>
/// Converts the list of extents to an array of <see cref="Tuple"/> where T1 is first element of the extent and T2 is last element
/// </summary>
/// <returns>Array of <see cref="Tuple"/></returns>
public Tuple<short, short>[] ToArray()
{
return backend.ToArray();
}
/// <summary>
/// Gets the first element of the extent that contains the specified item
/// </summary>
/// <param name="item">Item</param>
/// <param name="start">First element of extent</param>
/// <returns><c>true</c> if item was found in an extent, false otherwise</returns>
public bool GetStart(short item, out short start)
{
start = 0;

View File

@@ -36,22 +36,39 @@ using System.Linq;
namespace Extents
{
/// <summary>
/// Implements extents for <see cref="uint"/>
/// </summary>
public class ExtentsUInt
{
List<Tuple<uint, uint>> backend;
/// <summary>
/// Initialize an empty list of extents
/// </summary>
public ExtentsUInt()
{
backend = new List<Tuple<uint, uint>>();
}
/// <summary>
/// Initializes extents with an specific list
/// </summary>
/// <param name="list">List of extents as tuples "start, end"</param>
public ExtentsUInt(IEnumerable<Tuple<uint, uint>> list)
{
backend = list.OrderBy(t => t.Item1).ToList();
}
/// <summary>
/// Gets a count of how many extents are stored
/// </summary>
public int Count => backend.Count;
/// <summary>
/// Adds the specified number to the corresponding extent, or creates a new one
/// </summary>
/// <param name="item"></param>
public void Add(uint item)
{
Tuple<uint, uint> removeOne = null;
@@ -105,6 +122,12 @@ namespace Extents
backend = backend.OrderBy(t => t.Item1).ToList();
}
/// <summary>
/// Adds a new extent
/// </summary>
/// <param name="start">First element of the extent</param>
/// <param name="end">Last element of the extent or if <see cref="run"/> is <c>true</c> how many elements the extent runs for</param>
/// <param name="run">If set to <c>true</c>, <see cref="end"/> indicates how many elements the extent runs for</param>
public void Add(uint start, uint end, bool run = false)
{
uint realEnd;
@@ -115,16 +138,29 @@ namespace Extents
for(uint t = start; t <= realEnd; t++) Add(t);
}
/// <summary>
/// Checks if the specified item is contained by an extent on this instance
/// </summary>
/// <param name="item">Item to seach for</param>
/// <returns><c>true</c> if any of the extents on this instance contains the item</returns>
public bool Contains(uint item)
{
return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2);
}
/// <summary>
/// Removes all extents from this instance
/// </summary>
public void Clear()
{
backend.Clear();
}
/// <summary>
/// Removes an item from the extents in this instance
/// </summary>
/// <param name="item">Item to remove</param>
/// <returns><c>true</c> if the item was contained in a known extent and removed, false otherwise</returns>
public bool Remove(uint item)
{
Tuple<uint, uint> toRemove = null;
@@ -178,11 +214,21 @@ namespace Extents
return true;
}
/// <summary>
/// Converts the list of extents to an array of <see cref="Tuple"/> where T1 is first element of the extent and T2 is last element
/// </summary>
/// <returns>Array of <see cref="Tuple"/></returns>
public Tuple<uint, uint>[] ToArray()
{
return backend.ToArray();
}
/// <summary>
/// Gets the first element of the extent that contains the specified item
/// </summary>
/// <param name="item">Item</param>
/// <param name="start">First element of extent</param>
/// <returns><c>true</c> if item was found in an extent, false otherwise</returns>
public bool GetStart(uint item, out uint start)
{
start = 0;

View File

@@ -36,22 +36,39 @@ using System.Linq;
namespace Extents
{
/// <summary>
/// Implements extents for <see cref="ulong"/>
/// </summary>
public class ExtentsULong
{
List<Tuple<ulong, ulong>> backend;
/// <summary>
/// Initialize an empty list of extents
/// </summary>
public ExtentsULong()
{
backend = new List<Tuple<ulong, ulong>>();
}
/// <summary>
/// Initializes extents with an specific list
/// </summary>
/// <param name="list">List of extents as tuples "start, end"</param>
public ExtentsULong(IEnumerable<Tuple<ulong, ulong>> list)
{
backend = list.OrderBy(t => t.Item1).ToList();
}
/// <summary>
/// Gets a count of how many extents are stored
/// </summary>
public int Count => backend.Count;
/// <summary>
/// Adds the specified number to the corresponding extent, or creates a new one
/// </summary>
/// <param name="item"></param>
public void Add(ulong item)
{
Tuple<ulong, ulong> removeOne = null;
@@ -105,6 +122,12 @@ namespace Extents
backend = backend.OrderBy(t => t.Item1).ToList();
}
/// <summary>
/// Adds a new extent
/// </summary>
/// <param name="start">First element of the extent</param>
/// <param name="end">Last element of the extent or if <see cref="run"/> is <c>true</c> how many elements the extent runs for</param>
/// <param name="run">If set to <c>true</c>, <see cref="end"/> indicates how many elements the extent runs for</param>
public void Add(ulong start, ulong end, bool run = false)
{
ulong realEnd;
@@ -115,16 +138,29 @@ namespace Extents
for(ulong t = start; t <= realEnd; t++) Add(t);
}
/// <summary>
/// Checks if the specified item is contained by an extent on this instance
/// </summary>
/// <param name="item">Item to seach for</param>
/// <returns><c>true</c> if any of the extents on this instance contains the item</returns>
public bool Contains(ulong item)
{
return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2);
}
/// <summary>
/// Removes all extents from this instance
/// </summary>
public void Clear()
{
backend.Clear();
}
/// <summary>
/// Removes an item from the extents in this instance
/// </summary>
/// <param name="item">Item to remove</param>
/// <returns><c>true</c> if the item was contained in a known extent and removed, false otherwise</returns>
public bool Remove(ulong item)
{
Tuple<ulong, ulong> toRemove = null;
@@ -178,11 +214,21 @@ namespace Extents
return true;
}
/// <summary>
/// Converts the list of extents to an array of <see cref="Tuple"/> where T1 is first element of the extent and T2 is last element
/// </summary>
/// <returns>Array of <see cref="Tuple"/></returns>
public Tuple<ulong, ulong>[] ToArray()
{
return backend.ToArray();
}
/// <summary>
/// Gets the first element of the extent that contains the specified item
/// </summary>
/// <param name="item">Item</param>
/// <param name="start">First element of extent</param>
/// <returns><c>true</c> if item was found in an extent, false otherwise</returns>
public bool GetStart(ulong item, out ulong start)
{
start = 0;

View File

@@ -36,22 +36,39 @@ using System.Linq;
namespace Extents
{
/// <summary>
/// Implements extents for <see cref="ushort"/>
/// </summary>
public class ExtentsUShort
{
List<Tuple<ushort, ushort>> backend;
/// <summary>
/// Initialize an empty list of extents
/// </summary>
public ExtentsUShort()
{
backend = new List<Tuple<ushort, ushort>>();
}
/// <summary>
/// Initializes extents with an specific list
/// </summary>
/// <param name="list">List of extents as tuples "start, end"</param>
public ExtentsUShort(IEnumerable<Tuple<ushort, ushort>> list)
{
backend = list.OrderBy(t => t.Item1).ToList();
}
/// <summary>
/// Gets a count of how many extents are stored
/// </summary>
public int Count => backend.Count;
/// <summary>
/// Adds the specified number to the corresponding extent, or creates a new one
/// </summary>
/// <param name="item"></param>
public void Add(ushort item)
{
Tuple<ushort, ushort> removeOne = null;
@@ -105,6 +122,12 @@ namespace Extents
backend = backend.OrderBy(t => t.Item1).ToList();
}
/// <summary>
/// Adds a new extent
/// </summary>
/// <param name="start">First element of the extent</param>
/// <param name="end">Last element of the extent or if <see cref="run"/> is <c>true</c> how many elements the extent runs for</param>
/// <param name="run">If set to <c>true</c>, <see cref="end"/> indicates how many elements the extent runs for</param>
public void Add(ushort start, ushort end, bool run = false)
{
ushort realEnd;
@@ -115,16 +138,29 @@ namespace Extents
for(ushort t = start; t <= realEnd; t++) Add(t);
}
/// <summary>
/// Checks if the specified item is contained by an extent on this instance
/// </summary>
/// <param name="item">Item to seach for</param>
/// <returns><c>true</c> if any of the extents on this instance contains the item</returns>
public bool Contains(ushort item)
{
return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2);
}
/// <summary>
/// Removes all extents from this instance
/// </summary>
public void Clear()
{
backend.Clear();
}
/// <summary>
/// Removes an item from the extents in this instance
/// </summary>
/// <param name="item">Item to remove</param>
/// <returns><c>true</c> if the item was contained in a known extent and removed, false otherwise</returns>
public bool Remove(ushort item)
{
Tuple<ushort, ushort> toRemove = null;
@@ -178,11 +214,21 @@ namespace Extents
return true;
}
/// <summary>
/// Converts the list of extents to an array of <see cref="Tuple"/> where T1 is first element of the extent and T2 is last element
/// </summary>
/// <returns>Array of <see cref="Tuple"/></returns>
public Tuple<ushort, ushort>[] ToArray()
{
return backend.ToArray();
}
/// <summary>
/// Gets the first element of the extent that contains the specified item
/// </summary>
/// <param name="item">Item</param>
/// <param name="start">First element of extent</param>
/// <returns><c>true</c> if item was found in an extent, false otherwise</returns>
public bool GetStart(ushort item, out ushort start)
{
start = 0;

View File

@@ -37,11 +37,22 @@ namespace DiscImageChef
{
public static class PrintHex
{
/// <summary>
/// Prints a byte array as hexadecimal values to the console
/// </summary>
/// <param name="array">Array</param>
/// <param name="width">Width of line</param>
public static void PrintHexArray(byte[] array, int width)
{
DicConsole.WriteLine(ByteArrayToHexArrayString(array, width));
}
/// <summary>
/// Prints a byte array as hexadecimal values to a string
/// </summary>
/// <param name="array">Array</param>
/// <param name="width">Width of line</param>
/// <returns>String containing hexadecimal values</returns>
public static string ByteArrayToHexArrayString(byte[] array, int width)
{
StringBuilder sb = new StringBuilder();