From 9c5a9a3671f7151009133f00be1892508745802a Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 5 Oct 2015 18:58:13 +0100 Subject: [PATCH 001/217] * DiscImageChef/Checksums/MD5Context.cs: * DiscImageChef.Checksums/MD5Context.cs: * DiscImageChef/Checksums/CDChecksums.cs: * DiscImageChef.Checksums/ReedSolomon.cs: * DiscImageChef.Checksums/SHA1Context.cs: * DiscImageChef/Checksums/ReedSolomon.cs: * DiscImageChef/Checksums/SHA1Context.cs: * DiscImageChef.Checksums/CDChecksums.cs: * DiscImageChef/Checksums/CRC64Context.cs: * DiscImageChef/Checksums/CRC32Context.cs: * DiscImageChef/Checksums/CRC16Context.cs: * DiscImageChef.Checksums/CRC64Context.cs: * DiscImageChef.Checksums/CRC32Context.cs: * DiscImageChef.Checksums/CRC16Context.cs: * DiscImageChef/Checksums/SHA256Context.cs: * DiscImageChef.Checksums/SHA512Context.cs: * DiscImageChef.Checksums/SHA384Context.cs: * DiscImageChef/Checksums/SHA384Context.cs: * DiscImageChef/Checksums/SHA512Context.cs: * DiscImageChef.Checksums/SHA256Context.cs: * DiscImageChef.Checksums/Adler32Context.cs: * DiscImageChef/Checksums/SpamSumContext.cs: * DiscImageChef/Checksums/Adler32Context.cs: * DiscImageChef.Checksums/SpamSumContext.cs: * DiscImageChef.Checksums/FletcherContext.cs: * DiscImageChef/Checksums/FletcherContext.cs: * DiscImageChef.Checksums/RIPEMD160Context.cs: * DiscImageChef/Checksums/RIPEMD160Context.cs: * DiscImageChef.Checksums/Properties/AssemblyInfo.cs: * DiscImageChef.Checksums/DiscImageChef.Checksums.csproj: Move checksums to a separate library. * DiscImageChef/Swapping.cs: * DiscImageChef/PrintHex.cs: * DiscImageChef/ArrayFill.cs: * DiscImageChef/DateHandlers.cs: * DiscImageChef/StringHandlers.cs: * DiscImageChef.Helpers/Swapping.cs: * DiscImageChef.Helpers/PrintHex.cs: * DiscImageChef/DiscImageChef.csproj: * DiscImageChef.Helpers/ArrayFill.cs: * DiscImageChef.Helpers/DateHandlers.cs: * DiscImageChef/BigEndianBitConverter.cs: * DiscImageChef.Helpers/StringHandlers.cs: * DiscImageChef/EndianAwareBinaryReader.cs: * DiscImageChef.Helpers/BigEndianBitConverter.cs: * DiscImageChef.Helpers/EndianAwareBinaryReader.cs: * DiscImageChef.Helpers/Properties/AssemblyInfo.cs: * DiscImageChef.Helpers/DiscImageChef.Helpers.csproj: Move helpers to a separate library. * DiscImageChef.sln: Move helpers to a separate library. Move checksums to a separate library. --- ArrayFill.cs | 70 ++++ BigEndianBitConverter.cs | 660 +++++++++++++++++++++++++++++++++++ ChangeLog | 13 + DateHandlers.cs | 158 +++++++++ DiscImageChef.Helpers.csproj | 47 +++ EndianAwareBinaryReader.cs | 162 +++++++++ PrintHex.cs | 93 +++++ Properties/AssemblyInfo.cs | 27 ++ StringHandlers.cs | 113 ++++++ Swapping.cs | 111 ++++++ 10 files changed, 1454 insertions(+) create mode 100644 ArrayFill.cs create mode 100644 BigEndianBitConverter.cs create mode 100644 ChangeLog create mode 100644 DateHandlers.cs create mode 100644 DiscImageChef.Helpers.csproj create mode 100644 EndianAwareBinaryReader.cs create mode 100644 PrintHex.cs create mode 100644 Properties/AssemblyInfo.cs create mode 100644 StringHandlers.cs create mode 100644 Swapping.cs diff --git a/ArrayFill.cs b/ArrayFill.cs new file mode 100644 index 000000000..c3ba54cc6 --- /dev/null +++ b/ArrayFill.cs @@ -0,0 +1,70 @@ +/*************************************************************************** +The Disc Image Chef +---------------------------------------------------------------------------- + +Filename : ArrayFill.cs +Version : 1.0 +Author(s) : https://github.com/mykohsu + +Component : Helpers + +Revision : $Revision$ +Last change by : $Author$ +Date : $Date$ + +--[ Description ] ---------------------------------------------------------- + +Fills an array with a + +--[ License ] -------------------------------------------------------------- + + No license specified by creator. + + Published on https://github.com/mykohsu/Extensions/blob/master/ArrayExtensions.cs + + Assuming open source. + +---------------------------------------------------------------------------- +Copyright (C) 2014 mykohsu +****************************************************************************/ +//$Id$ +using System; + +namespace DiscImageChef +{ + public static class ArrayHelpers + { + public static void ArrayFill(T[] destinationArray, T value) + { + // if called with a single value, wrap the value in an array and call the main function + ArrayFill(destinationArray, new T[] { value }); + } + + public static void ArrayFill(T[] destinationArray, T[] value) + { + if (destinationArray == null) + { + throw new ArgumentNullException("destinationArray"); + } + + if (value.Length > destinationArray.Length) + { + throw new ArgumentException("Length of value array must not be more than length of destination"); + } + + // set the initial array value + Array.Copy(value, destinationArray, value.Length); + + int arrayToFillHalfLength = destinationArray.Length / 2; + int copyLength; + + for(copyLength = value.Length; copyLength < arrayToFillHalfLength; copyLength <<= 1) + { + Array.Copy(destinationArray, 0, destinationArray, copyLength, copyLength); + } + + Array.Copy(destinationArray, 0, destinationArray, copyLength, destinationArray.Length - copyLength); + } + } +} + diff --git a/BigEndianBitConverter.cs b/BigEndianBitConverter.cs new file mode 100644 index 000000000..171848d98 --- /dev/null +++ b/BigEndianBitConverter.cs @@ -0,0 +1,660 @@ +/*************************************************************************** +The Disc Image Chef +---------------------------------------------------------------------------- + +Filename : BigEndianBitConverter.cs +Version : 1.0 +Author(s) : Natalia Portillo + +Component : Program tools + +Revision : $Revision$ +Last change by : $Author$ +Date : $Date$ + +--[ Description ] ---------------------------------------------------------- + +Override of System.BitConverter that knows how to handle big-endian. + +--[ License ] -------------------------------------------------------------- + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +---------------------------------------------------------------------------- +Copyright (C) 2011-2014 Claunia.com +****************************************************************************/ +//$Id$ + +using System; +using System.Linq; + +namespace DiscImageChef +{ + /// + /// Converts base data types to an array of bytes, and an array of bytes to base + /// data types. + /// All info taken from the meta data of System.BitConverter. This implementation + /// allows for Endianness consideration. + /// + public static class BigEndianBitConverter + { + /// + /// Indicates the byte order ("endianess") in which data is stored in this computer + /// architecture. + /// + public static bool IsLittleEndian { get; set; } + // should default to false, which is what we want for Empire + /// + /// 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. + /// + public static long DoubleToInt64Bits(double value) + { + throw new NotImplementedException(); + } + + /// + /// + /// Returns the specified Boolean value as an array of bytes. + /// + /// Parameters: + /// value: + /// A Boolean value. + /// + /// Returns: + /// An array of bytes with length 1. + /// + public static byte[] GetBytes(bool value) + { + return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); + } + + /// + /// + /// 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. + /// + public static byte[] GetBytes(char value) + { + return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); + } + + /// + /// + /// 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. + /// + public static byte[] GetBytes(double value) + { + return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); + } + + /// + /// + /// 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. + /// + public static byte[] GetBytes(float value) + { + return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); + } + + /// + /// + /// 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. + /// + public static byte[] GetBytes(int value) + { + return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); + } + + /// + /// + /// 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. + /// + public static byte[] GetBytes(long value) + { + return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); + } + + /// + /// + /// 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. + /// + public static byte[] GetBytes(short value) + { + return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); + } + + /// + /// + /// 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. + /// + //[CLSCompliant(false)] + public static byte[] GetBytes(uint value) + { + return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); + } + + /// + /// + /// 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. + /// + //[CLSCompliant(false)] + public static byte[] GetBytes(ulong value) + { + return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); + } + + /// + /// + /// 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. + /// + public static byte[] GetBytes(ushort value) + { + return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); + } + + /// + /// + /// 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. + /// + public static double Int64BitsToDouble(long value) + { + throw new NotImplementedException(); + } + + /// + /// + /// 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. + /// + public static bool ToBoolean(byte[] value, int startIndex) + { + throw new NotImplementedException(); + } + + /// + /// + /// 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. + /// + public static char ToChar(byte[] value, int startIndex) + { + throw new NotImplementedException(); + } + + /// + /// + /// 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. + /// + public static double ToDouble(byte[] value, int startIndex) + { + throw new NotImplementedException(); + } + + /// + /// + /// 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. + /// + public static short ToInt16(byte[] value, int startIndex) + { + return !IsLittleEndian ? BitConverter.ToInt16(value, startIndex) : BitConverter.ToInt16(value.Reverse().ToArray(), value.Length - sizeof(Int16) - startIndex); + } + + /// + /// + /// 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. + /// + public static int ToInt32(byte[] value, int startIndex) + { + return !IsLittleEndian ? BitConverter.ToInt32(value, startIndex) : BitConverter.ToInt32(value.Reverse().ToArray(), value.Length - sizeof(Int32) - startIndex); + } + + /// + /// + /// 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. + /// + public static long ToInt64(byte[] value, int startIndex) + { + return !IsLittleEndian ? BitConverter.ToInt64(value, startIndex) : BitConverter.ToInt64(value.Reverse().ToArray(), value.Length - sizeof(Int64) - startIndex); + } + + /// + /// + /// 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. + /// + public static float ToSingle(byte[] value, int startIndex) + { + return !IsLittleEndian ? BitConverter.ToSingle(value, startIndex) : BitConverter.ToSingle(value.Reverse().ToArray(), value.Length - sizeof(Single) - startIndex); + } + + /// + /// + /// 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. + /// + public static string ToString(byte[] value) + { + return !IsLittleEndian ? BitConverter.ToString(value) : BitConverter.ToString(value.Reverse().ToArray()); + } + + /// + /// + /// 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. + /// + public static string ToString(byte[] value, int startIndex) + { + return !IsLittleEndian ? BitConverter.ToString(value, startIndex) : BitConverter.ToString(value.Reverse().ToArray(), startIndex); + } + + /// + /// + /// 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. + /// + public static string ToString(byte[] value, int startIndex, int length) + { + return !IsLittleEndian ? BitConverter.ToString(value, startIndex, length) : BitConverter.ToString(value.Reverse().ToArray(), startIndex, length); + } + + /// + /// + /// 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. + /// + public static ushort ToUInt16(byte[] value, int startIndex) + { + return !IsLittleEndian ? BitConverter.ToUInt16(value, startIndex) : BitConverter.ToUInt16(value.Reverse().ToArray(), value.Length - sizeof(UInt16) - startIndex); + } + + /// + /// + /// 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. + /// + public static uint ToUInt32(byte[] value, int startIndex) + { + return !IsLittleEndian ? BitConverter.ToUInt32(value, startIndex) : BitConverter.ToUInt32(value.Reverse().ToArray(), value.Length - sizeof(UInt32) - startIndex); + } + + /// + /// + /// 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. + /// + public static ulong ToUInt64(byte[] value, int startIndex) + { + return !IsLittleEndian ? BitConverter.ToUInt64(value, startIndex) : BitConverter.ToUInt64(value.Reverse().ToArray(), value.Length - sizeof(UInt64) - startIndex); + } + + public static Guid ToGuid(byte[] value, int startIndex) + { + return new Guid(BigEndianBitConverter.ToUInt32(value, 0 + startIndex), + BigEndianBitConverter.ToUInt16(value, 4 + startIndex), + BigEndianBitConverter.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]); + } + } +} \ No newline at end of file diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 000000000..cbde71e5b --- /dev/null +++ b/ChangeLog @@ -0,0 +1,13 @@ +2015-10-05 Natalia Portillo + + * PrintHex.cs: + * Swapping.cs: + * ArrayFill.cs: + * DateHandlers.cs: + * StringHandlers.cs: + * BigEndianBitConverter.cs: + * EndianAwareBinaryReader.cs: + * Properties/AssemblyInfo.cs: + * DiscImageChef.Helpers.csproj: + Move helpers to a separate library. + diff --git a/DateHandlers.cs b/DateHandlers.cs new file mode 100644 index 000000000..2382044c6 --- /dev/null +++ b/DateHandlers.cs @@ -0,0 +1,158 @@ +/*************************************************************************** +The Disc Image Chef +---------------------------------------------------------------------------- + +Filename : DateHandlers.cs +Version : 1.0 +Author(s) : Natalia Portillo + +Component : Program tools + +Revision : $Revision$ +Last change by : $Author$ +Date : $Date$ + +--[ Description ] ---------------------------------------------------------- + +Convert several timestamp formats to C# DateTime. + +--[ License ] -------------------------------------------------------------- + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +---------------------------------------------------------------------------- +Copyright (C) 2011-2014 Claunia.com +****************************************************************************/ +//$Id$ + +using System; + +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 UNIXEpoch = new DateTime(1970, 1, 1, 0, 0, 0); + // Day 0 of Julian Date system + static readonly DateTime JulianEpoch = new DateTime(1858, 11, 17, 0, 0, 0); + static readonly DateTime AmigaEpoch = new DateTime(1978, 1, 1, 0, 0, 0); + + public static DateTime MacToDateTime(ulong MacTimeStamp) + { + return MacEpoch.AddTicks((long)(MacTimeStamp * 10000000)); + } + + public static DateTime LisaToDateTime(UInt32 LisaTimeStamp) + { + return LisaEpoch.AddSeconds(LisaTimeStamp); + } + + public static DateTime UNIXToDateTime(Int32 UNIXTimeStamp) + { + return UNIXEpoch.AddSeconds(UNIXTimeStamp); + } + + public static DateTime UNIXUnsignedToDateTime(UInt32 UNIXTimeStamp) + { + return UNIXEpoch.AddSeconds(UNIXTimeStamp); + } + + public static DateTime ISO9660ToDateTime(byte[] VDDateTime) + { + int year, month, day, hour, minute, second, hundredths; + byte[] twocharvalue = new byte[2]; + byte[] fourcharvalue = new byte[4]; + + fourcharvalue[0] = VDDateTime[0]; + fourcharvalue[1] = VDDateTime[1]; + fourcharvalue[2] = VDDateTime[2]; + fourcharvalue[3] = VDDateTime[3]; + //if (MainClass.isDebug) + Console.WriteLine("DEBUG (ISO9600ToDateTime handler): year = \"{0}\"", StringHandlers.CToString(fourcharvalue)); + if (!Int32.TryParse(StringHandlers.CToString(fourcharvalue), out year)) + year = 0; +// year = Convert.ToInt32(StringHandlers.CToString(fourcharvalue)); + + twocharvalue[0] = VDDateTime[4]; + twocharvalue[1] = VDDateTime[5]; + //if (MainClass.isDebug) + Console.WriteLine("DEBUG (ISO9600ToDateTime handler): month = \"{0}\"", StringHandlers.CToString(twocharvalue)); + if (!Int32.TryParse(StringHandlers.CToString(twocharvalue), out month)) + month = 0; +// month = Convert.ToInt32(StringHandlers.CToString(twocharvalue)); + + twocharvalue[0] = VDDateTime[6]; + twocharvalue[1] = VDDateTime[7]; + //if (MainClass.isDebug) + Console.WriteLine("DEBUG (ISO9600ToDateTime handler): day = \"{0}\"", StringHandlers.CToString(twocharvalue)); + if (!Int32.TryParse(StringHandlers.CToString(twocharvalue), out day)) + day = 0; +// day = Convert.ToInt32(StringHandlers.CToString(twocharvalue)); + + twocharvalue[0] = VDDateTime[8]; + twocharvalue[1] = VDDateTime[9]; + //if (MainClass.isDebug) + Console.WriteLine("DEBUG (ISO9600ToDateTime handler): hour = \"{0}\"", StringHandlers.CToString(twocharvalue)); + if (!Int32.TryParse(StringHandlers.CToString(twocharvalue), out hour)) + hour = 0; +// hour = Convert.ToInt32(StringHandlers.CToString(twocharvalue)); + + twocharvalue[0] = VDDateTime[10]; + twocharvalue[1] = VDDateTime[11]; + //if (MainClass.isDebug) + Console.WriteLine("DEBUG (ISO9600ToDateTime handler): minute = \"{0}\"", StringHandlers.CToString(twocharvalue)); + if (!Int32.TryParse(StringHandlers.CToString(twocharvalue), out minute)) + minute = 0; +// minute = Convert.ToInt32(StringHandlers.CToString(twocharvalue)); + + twocharvalue[0] = VDDateTime[12]; + twocharvalue[1] = VDDateTime[13]; + //if (MainClass.isDebug) + Console.WriteLine("DEBUG (ISO9600ToDateTime handler): second = \"{0}\"", StringHandlers.CToString(twocharvalue)); + if (!Int32.TryParse(StringHandlers.CToString(twocharvalue), out second)) + second = 0; +// second = Convert.ToInt32(StringHandlers.CToString(twocharvalue)); + + twocharvalue[0] = VDDateTime[14]; + twocharvalue[1] = VDDateTime[15]; + //if (MainClass.isDebug) + Console.WriteLine("DEBUG (ISO9600ToDateTime handler): hundredths = \"{0}\"", StringHandlers.CToString(twocharvalue)); + if (!Int32.TryParse(StringHandlers.CToString(twocharvalue), out hundredths)) + hundredths = 0; +// hundredths = Convert.ToInt32(StringHandlers.CToString(twocharvalue)); + + //if (MainClass.isDebug) + Console.WriteLine("DEBUG (ISO9600ToDateTime handler): decodedDT = new DateTime({0}, {1}, {2}, {3}, {4}, {5}, {6}, DateTimeKind.Unspecified);", year, month, day, hour, minute, second, hundredths * 10); + DateTime decodedDT = new DateTime(year, month, day, hour, minute, second, hundredths * 10, DateTimeKind.Unspecified); + + return decodedDT; + } + + // C# works in UTC, VMS on Julian Date, some displacement may occur on disks created outside UTC + public static DateTime VMSToDateTime(UInt64 vmsDate) + { + double delta = vmsDate * 0.0001; // Tenths of microseconds to milliseconds, will lose some detail + return JulianEpoch.AddMilliseconds(delta); + } + + public static DateTime AmigaToDateTime(UInt32 days, UInt32 minutes, UInt32 ticks) + { + DateTime temp = AmigaEpoch.AddDays(days); + temp = temp.AddMinutes(minutes); + return temp.AddMilliseconds(ticks * 20); + } + } +} + diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj new file mode 100644 index 000000000..e424bb92a --- /dev/null +++ b/DiscImageChef.Helpers.csproj @@ -0,0 +1,47 @@ + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {F8BDF57B-1571-4CD0-84B3-B422088D359A} + Library + DiscImageChef.Helpers + DiscImageChef.Helpers + 2.2 + v3.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + false + + + full + true + bin\Release + prompt + 4 + false + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/EndianAwareBinaryReader.cs b/EndianAwareBinaryReader.cs new file mode 100644 index 000000000..dce8b6be8 --- /dev/null +++ b/EndianAwareBinaryReader.cs @@ -0,0 +1,162 @@ +/*************************************************************************** +The Disc Image Chef +---------------------------------------------------------------------------- + +Filename : EndianAwareBinaryReader.cs +Version : 1.0 +Author(s) : Natalia Portillo + +Component : Program tools + +Revision : $Revision$ +Last change by : $Author$ +Date : $Date$ + +--[ Description ] ---------------------------------------------------------- + +Override for System.IO.Binary.Reader that knows how to handle big-endian. + +--[ License ] -------------------------------------------------------------- + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +---------------------------------------------------------------------------- +Copyright (C) 2011-2014 Claunia.com +****************************************************************************/ +//$Id$ + +using System; +using System.IO; +using System.Linq; +using System.Text; + +namespace DiscImageChef +{ + public class EndianAwareBinaryReader : BinaryReader + { + byte[] buffer = new byte[8]; + + public EndianAwareBinaryReader(Stream input, Encoding encoding, bool isLittleEndian) + : base(input, encoding) + { + IsLittleEndian = isLittleEndian; + } + + public EndianAwareBinaryReader(Stream input, bool isLittleEndian) + : this(input, Encoding.UTF8, isLittleEndian) + { + } + + public bool IsLittleEndian + { + get; + set; + } + + public override double ReadDouble() + { + if (IsLittleEndian) + return base.ReadDouble(); + FillMyBuffer(8); + return BitConverter.ToDouble(buffer.Take(8).Reverse().ToArray(), 0); + } + + public override short ReadInt16() + { + if (IsLittleEndian) + return base.ReadInt16(); + FillMyBuffer(2); + return BitConverter.ToInt16(buffer.Take(2).Reverse().ToArray(), 0); + + } + + public override int ReadInt32() + { + if (IsLittleEndian) + return base.ReadInt32(); + FillMyBuffer(4); + return BitConverter.ToInt32(buffer.Take(4).Reverse().ToArray(), 0); + + } + + public override long ReadInt64() + { + if (IsLittleEndian) + return base.ReadInt64(); + FillMyBuffer(8); + return BitConverter.ToInt64(buffer.Take(8).Reverse().ToArray(), 0); + + } + + public override float ReadSingle() + { + if (IsLittleEndian) + return base.ReadSingle(); + FillMyBuffer(4); + return BitConverter.ToSingle(buffer.Take(4).Reverse().ToArray(), 0); + } + + public override ushort ReadUInt16() + { + if (IsLittleEndian) + return base.ReadUInt16(); + FillMyBuffer(2); + return BitConverter.ToUInt16(buffer.Take(2).Reverse().ToArray(), 0); + } + + public override uint ReadUInt32() + { + if (IsLittleEndian) + return base.ReadUInt32(); + FillMyBuffer(4); + return BitConverter.ToUInt32(buffer.Take(4).Reverse().ToArray(), 0); + } + + public override ulong ReadUInt64() + { + if (IsLittleEndian) + return base.ReadUInt64(); + FillMyBuffer(8); + return BitConverter.ToUInt64(buffer.Take(8).Reverse().ToArray(), 0); + } + + void FillMyBuffer(int numBytes) + { + int offset = 0; + int num2; + if (numBytes == 1) + { + num2 = BaseStream.ReadByte(); + if (num2 == -1) + { + throw new EndOfStreamException("Attempted to read past the end of the stream."); + } + buffer[0] = (byte)num2; + } + else + { + do + { + num2 = BaseStream.Read(buffer, offset, numBytes - offset); + if (num2 == 0) + { + throw new EndOfStreamException("Attempted to read past the end of the stream."); + } + offset += num2; + } + while (offset < numBytes); + } + } + } +} \ No newline at end of file diff --git a/PrintHex.cs b/PrintHex.cs new file mode 100644 index 000000000..a9564e2f4 --- /dev/null +++ b/PrintHex.cs @@ -0,0 +1,93 @@ +/*************************************************************************** +The Disc Image Chef +---------------------------------------------------------------------------- + +Filename : PrintHex.cs +Version : 1.0 +Author(s) : Natalia Portillo + +Component : Helpers + +Revision : $Revision$ +Last change by : $Author$ +Date : $Date$ + +--[ Description ] ---------------------------------------------------------- + +Prints a byte array as hexadecimal in console. + +--[ License ] -------------------------------------------------------------- + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +---------------------------------------------------------------------------- +Copyright (C) 2011-2014 Claunia.com +****************************************************************************/ +//$Id$ +using System; + +namespace DiscImageChef +{ + public static class PrintHex + { + public static void PrintHexArray(byte[] array, int width) + { + Console.WriteLine(ByteArrayToHexArrayString(array, width)); + } + + public static string ByteArrayToHexArrayString(byte[] array, int width) + { + System.Text.StringBuilder sb = new System.Text.StringBuilder(); + + int counter = 0; + int subcounter = 0; + for (long i = 0; i < array.LongLength; i++) + { + if (counter == 0) + { + sb.AppendLine(); + sb.AppendFormat("{0:X16} ", i); + } + else + { + if (subcounter == 3 ) + { + Console.Write(" "); + subcounter = 0; + } + else + { + Console.Write(" "); + subcounter++; + } + } + + sb.AppendFormat("{0:X2}", array[i]); + + if (counter == width - 1) + { + counter = 0; + subcounter = 0; + } + else + counter++; + } + sb.AppendLine(); + sb.AppendLine(); + + return sb.ToString(); + } + } +} + diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..0b0685491 --- /dev/null +++ b/Properties/AssemblyInfo.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("DiscImageChef.Helpers")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Claunia.com")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("© Claunia.com")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/StringHandlers.cs b/StringHandlers.cs new file mode 100644 index 000000000..faba521ae --- /dev/null +++ b/StringHandlers.cs @@ -0,0 +1,113 @@ +/*************************************************************************** +The Disc Image Chef +---------------------------------------------------------------------------- + +Filename : StringHandlers.cs +Version : 1.0 +Author(s) : Natalia Portillo + +Component : Program tools + +Revision : $Revision$ +Last change by : $Author$ +Date : $Date$ + +--[ Description ] ---------------------------------------------------------- + +Convert byte arrays to C# strings. + +--[ License ] -------------------------------------------------------------- + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +---------------------------------------------------------------------------- +Copyright (C) 2011-2014 Claunia.com +****************************************************************************/ +//$Id$ + +using System; +using System.Text; + +namespace DiscImageChef +{ + public static class StringHandlers + { + /// + /// Converts a null-terminated (aka C string) ASCII byte array to a C# string + /// + /// The corresponding C# string + /// A null-terminated (aka C string) ASCII byte array + public static string CToString(byte[] CString) + { + StringBuilder sb = new StringBuilder(); + + for (int i = 0; i < CString.Length; i++) + { + if (CString[i] == 0) + break; + + sb.Append(Encoding.ASCII.GetString(CString, i, 1)); + } + + return sb.ToString(); + } + + /// + /// Converts a length-prefixed (aka Pascal string) ASCII byte array to a C# string + /// + /// The corresponding C# string + /// A length-prefixed (aka Pascal string) ASCII byte array + public static string PascalToString(byte[] PascalString) + { + StringBuilder sb = new StringBuilder(); + + byte length = PascalString[0]; + + for (int i = 1; i < length + 1; i++) + { + sb.Append(Encoding.ASCII.GetString(PascalString, i, 1)); + } + + return sb.ToString(); + } + + /// + /// Converts a space (' ', 0x20, ASCII SPACE) padded ASCII byte array to a C# string + /// + /// The corresponding C# string + /// A space (' ', 0x20, ASCII SPACE) padded ASCII byte array + public static string SpacePaddedToString(byte[] SpacePaddedString) + { + int length = 0; + + for (int i = SpacePaddedString.Length; i >= 0; i--) + { + if (i == 0) + return ""; + + if (SpacePaddedString[i - 1] != 0x20) + { + length = i; + break; + } + } + + if (length == 0) + return ""; + + return Encoding.ASCII.GetString(SpacePaddedString, 0, length); + } + } +} + diff --git a/Swapping.cs b/Swapping.cs new file mode 100644 index 000000000..177673103 --- /dev/null +++ b/Swapping.cs @@ -0,0 +1,111 @@ +/*************************************************************************** +The Disc Image Chef +---------------------------------------------------------------------------- + +Filename : Swapping.cs +Version : 1.0 +Author(s) : Natalia Portillo + +Component : Program tools + +Revision : $Revision$ +Last change by : $Author$ +Date : $Date$ + +--[ Description ] ---------------------------------------------------------- + +Byte-swapping methods + +--[ License ] -------------------------------------------------------------- + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +---------------------------------------------------------------------------- +Copyright (C) 2011-2014 Claunia.com +****************************************************************************/ +//$Id$ + +using System; + +namespace DiscImageChef +{ + public static class Swapping + { + public static byte[] SwapTenBytes(byte[] source) + { + byte[] destination = new byte[8]; + + destination[0] = source[9]; + destination[1] = source[8]; + destination[2] = source[7]; + destination[3] = source[6]; + destination[4] = source[5]; + destination[5] = source[4]; + destination[6] = source[3]; + destination[7] = source[2]; + destination[8] = source[1]; + destination[9] = source[0]; + + return destination; + } + + public static byte[] SwapEightBytes(byte[] source) + { + byte[] destination = new byte[8]; + + destination[0] = source[7]; + destination[1] = source[6]; + destination[2] = source[5]; + destination[3] = source[4]; + destination[4] = source[3]; + destination[5] = source[2]; + destination[6] = source[1]; + destination[7] = source[0]; + + return destination; + } + + public static byte[] SwapFourBytes(byte[] source) + { + byte[] destination = new byte[4]; + + destination[0] = source[3]; + destination[1] = source[2]; + destination[2] = source[1]; + destination[3] = source[0]; + + return destination; + } + + public static byte[] SwapTwoBytes(byte[] source) + { + byte[] destination = new byte[2]; + + destination[0] = source[1]; + destination[1] = source[0]; + + return destination; + } + + public static UInt32 PDPFromLittleEndian(UInt32 x) + { + return ((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16); + } + + public static UInt32 PDPFromBigEndian(UInt32 x) + { + return ((x & 0xff00ff) << 8) | ((x & 0xff00ff00) >> 8); + } + } +} From b28f690aabf9a7fa1634ba385b8aab6a2a32a085 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 18 Oct 2015 22:04:03 +0100 Subject: [PATCH 002/217] Added specific console handling for standard, verbose, debug and error outputs. --- ChangeLog | 8 ++++++++ DateHandlers.cs | 25 +++++++++---------------- DiscImageChef.Helpers.csproj | 6 ++++++ PrintHex.cs | 7 ++++--- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index cbde71e5b..04c2fc99c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2015-10-18 Natalia Portillo + + * PrintHex.cs: + * DateHandlers.cs: + * DiscImageChef.Helpers.csproj: + Added specific console handling for standard, verbose, debug + and error outputs. + 2015-10-05 Natalia Portillo * PrintHex.cs: diff --git a/DateHandlers.cs b/DateHandlers.cs index 2382044c6..72802a5de 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -37,6 +37,7 @@ You should have received a copy of the GNU General Public License //$Id$ using System; +using DiscImageChef.Console; namespace DiscImageChef { @@ -79,62 +80,54 @@ public static DateTime ISO9660ToDateTime(byte[] VDDateTime) fourcharvalue[1] = VDDateTime[1]; fourcharvalue[2] = VDDateTime[2]; fourcharvalue[3] = VDDateTime[3]; - //if (MainClass.isDebug) - Console.WriteLine("DEBUG (ISO9600ToDateTime handler): year = \"{0}\"", StringHandlers.CToString(fourcharvalue)); + DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "year = \"{0}\"", StringHandlers.CToString(fourcharvalue)); if (!Int32.TryParse(StringHandlers.CToString(fourcharvalue), out year)) year = 0; // year = Convert.ToInt32(StringHandlers.CToString(fourcharvalue)); twocharvalue[0] = VDDateTime[4]; twocharvalue[1] = VDDateTime[5]; - //if (MainClass.isDebug) - Console.WriteLine("DEBUG (ISO9600ToDateTime handler): month = \"{0}\"", StringHandlers.CToString(twocharvalue)); + DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "month = \"{0}\"", StringHandlers.CToString(twocharvalue)); if (!Int32.TryParse(StringHandlers.CToString(twocharvalue), out month)) month = 0; // month = Convert.ToInt32(StringHandlers.CToString(twocharvalue)); twocharvalue[0] = VDDateTime[6]; twocharvalue[1] = VDDateTime[7]; - //if (MainClass.isDebug) - Console.WriteLine("DEBUG (ISO9600ToDateTime handler): day = \"{0}\"", StringHandlers.CToString(twocharvalue)); + DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "day = \"{0}\"", StringHandlers.CToString(twocharvalue)); if (!Int32.TryParse(StringHandlers.CToString(twocharvalue), out day)) day = 0; // day = Convert.ToInt32(StringHandlers.CToString(twocharvalue)); twocharvalue[0] = VDDateTime[8]; twocharvalue[1] = VDDateTime[9]; - //if (MainClass.isDebug) - Console.WriteLine("DEBUG (ISO9600ToDateTime handler): hour = \"{0}\"", StringHandlers.CToString(twocharvalue)); + DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "hour = \"{0}\"", StringHandlers.CToString(twocharvalue)); if (!Int32.TryParse(StringHandlers.CToString(twocharvalue), out hour)) hour = 0; // hour = Convert.ToInt32(StringHandlers.CToString(twocharvalue)); twocharvalue[0] = VDDateTime[10]; twocharvalue[1] = VDDateTime[11]; - //if (MainClass.isDebug) - Console.WriteLine("DEBUG (ISO9600ToDateTime handler): minute = \"{0}\"", StringHandlers.CToString(twocharvalue)); + DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "minute = \"{0}\"", StringHandlers.CToString(twocharvalue)); if (!Int32.TryParse(StringHandlers.CToString(twocharvalue), out minute)) minute = 0; // minute = Convert.ToInt32(StringHandlers.CToString(twocharvalue)); twocharvalue[0] = VDDateTime[12]; twocharvalue[1] = VDDateTime[13]; - //if (MainClass.isDebug) - Console.WriteLine("DEBUG (ISO9600ToDateTime handler): second = \"{0}\"", StringHandlers.CToString(twocharvalue)); + DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "second = \"{0}\"", StringHandlers.CToString(twocharvalue)); if (!Int32.TryParse(StringHandlers.CToString(twocharvalue), out second)) second = 0; // second = Convert.ToInt32(StringHandlers.CToString(twocharvalue)); twocharvalue[0] = VDDateTime[14]; twocharvalue[1] = VDDateTime[15]; - //if (MainClass.isDebug) - Console.WriteLine("DEBUG (ISO9600ToDateTime handler): hundredths = \"{0}\"", StringHandlers.CToString(twocharvalue)); + DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "hundredths = \"{0}\"", StringHandlers.CToString(twocharvalue)); if (!Int32.TryParse(StringHandlers.CToString(twocharvalue), out hundredths)) hundredths = 0; // hundredths = Convert.ToInt32(StringHandlers.CToString(twocharvalue)); - //if (MainClass.isDebug) - Console.WriteLine("DEBUG (ISO9600ToDateTime handler): decodedDT = new DateTime({0}, {1}, {2}, {3}, {4}, {5}, {6}, DateTimeKind.Unspecified);", year, month, day, hour, minute, second, hundredths * 10); + DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "decodedDT = new DateTime({0}, {1}, {2}, {3}, {4}, {5}, {6}, DateTimeKind.Unspecified);", year, month, day, hour, minute, second, hundredths * 10); DateTime decodedDT = new DateTime(year, month, day, hour, minute, second, hundredths * 10, DateTimeKind.Unspecified); return decodedDT; diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index e424bb92a..0e68a7c4e 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -44,4 +44,10 @@ + + + {CCAA7AFE-C094-4D82-A66D-630DE8A3F545} + DiscImageChef.Console + + \ No newline at end of file diff --git a/PrintHex.cs b/PrintHex.cs index a9564e2f4..15c242397 100644 --- a/PrintHex.cs +++ b/PrintHex.cs @@ -36,6 +36,7 @@ You should have received a copy of the GNU General Public License ****************************************************************************/ //$Id$ using System; +using DiscImageChef.Console; namespace DiscImageChef { @@ -43,7 +44,7 @@ public static class PrintHex { public static void PrintHexArray(byte[] array, int width) { - Console.WriteLine(ByteArrayToHexArrayString(array, width)); + DicConsole.WriteLine(ByteArrayToHexArrayString(array, width)); } public static string ByteArrayToHexArrayString(byte[] array, int width) @@ -63,12 +64,12 @@ public static string ByteArrayToHexArrayString(byte[] array, int width) { if (subcounter == 3 ) { - Console.Write(" "); + sb.Append(" "); subcounter = 0; } else { - Console.Write(" "); + sb.Append(" "); subcounter++; } } From ed0c1e6860a4ad7dfa64a0ca6d4072ed22302c1a Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 19 Oct 2015 04:48:17 +0100 Subject: [PATCH 003/217] Upgrade .NET version to 4.0. --- ChangeLog | 5 +++++ DiscImageChef.Helpers.csproj | 1 - 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 04c2fc99c..842b7f196 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-10-19 Natalia Portillo + + * DiscImageChef.Helpers.csproj: + Upgrade .NET version to 4.0. + 2015-10-18 Natalia Portillo * PrintHex.cs: diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index 0e68a7c4e..fece7f719 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -10,7 +10,6 @@ DiscImageChef.Helpers DiscImageChef.Helpers 2.2 - v3.5 true From efc93f37eac6d746cb5d2027bc465be7985ddbeb Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Fri, 4 Dec 2015 03:34:44 +0000 Subject: [PATCH 004/217] Finally CD-Text on lead-in is getting decoded correctly... --- ChangeLog | 5 +++++ StringHandlers.cs | 13 ++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 842b7f196..025495ff5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-12-04 Natalia Portillo + + * StringHandlers.cs: + Finally CD-Text on lead-in is getting decoded correctly... + 2015-10-19 Natalia Portillo * DiscImageChef.Helpers.csproj: diff --git a/StringHandlers.cs b/StringHandlers.cs index faba521ae..a97d8d546 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -49,6 +49,17 @@ public static class StringHandlers /// The corresponding C# string /// A null-terminated (aka C string) ASCII byte array public static string CToString(byte[] CString) + { + return CToString(CString, Encoding.ASCII); + } + + /// + /// Converts a null-terminated (aka C string) byte array with the specified encoding to a C# string + /// + /// The corresponding C# string + /// A null-terminated (aka C string) byte array in the specified encoding + /// Encoding. + public static string CToString(byte[] CString, Encoding encoding) { StringBuilder sb = new StringBuilder(); @@ -57,7 +68,7 @@ public static string CToString(byte[] CString) if (CString[i] == 0) break; - sb.Append(Encoding.ASCII.GetString(CString, i, 1)); + sb.Append(encoding.GetString(CString, i, 1)); } return sb.ToString(); From 819ff3eb756b9d89b5bbe81a1e684a1129abee86 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 30 Dec 2015 11:45:27 +0000 Subject: [PATCH 005/217] * DiscImageChef/Main.cs: * DiscImageChef/Options.cs: * DiscImageChef/DiscImageChef.csproj: * DiscImageChef/Commands/MediaScan.cs: Added media-scan command. * DiscImageChef.Decoders/SCSI/Inquiry.cs: Fixes decoding for devices that follow old 5-byte SCSI INQUIRY format. * DiscImageChef.Decoders/SCSI/Sense.cs: Fixes printing of sense block missing a newline. * DiscImageChef.Devices/Device/Variables.cs: * DiscImageChef.Devices/Device/Constructor.cs: Added an IsRemovable field. * DiscImageChef.Devices/Device/ScsiCommands.cs: Fixed SCSI READ CAPACITY CDB size. Fixed READ CD-DA MSF method name. Implemented SCSI SEEK (6) and SEEK (10) commands. * DiscImageChef.Devices/Linux/Command.cs: * DiscImageChef.Devices/Windows/Command.cs: Fixed memory leaking on unmanaged heap. * DiscImageChef.Helpers/StringHandlers.cs: Fixed string conversion when input byte array is null. * DiscImageChef/Commands/MediaInfo.cs: Check for inserted medium only on removable media devices. --- ChangeLog | 5 +++++ StringHandlers.cs | 14 ++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 025495ff5..9a709ca09 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-12-30 Natalia Portillo + + * StringHandlers.cs: + Fixed string conversion when input byte array is null. + 2015-12-04 Natalia Portillo * StringHandlers.cs: diff --git a/StringHandlers.cs b/StringHandlers.cs index a97d8d546..19816cf81 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -61,6 +61,9 @@ public static string CToString(byte[] CString) /// Encoding. public static string CToString(byte[] CString, Encoding encoding) { + if (CString == null) + return null; + StringBuilder sb = new StringBuilder(); for (int i = 0; i < CString.Length; i++) @@ -81,6 +84,9 @@ public static string CToString(byte[] CString, Encoding encoding) /// A length-prefixed (aka Pascal string) ASCII byte array public static string PascalToString(byte[] PascalString) { + if (PascalString == null) + return null; + StringBuilder sb = new StringBuilder(); byte length = PascalString[0]; @@ -100,6 +106,9 @@ public static string PascalToString(byte[] PascalString) /// A space (' ', 0x20, ASCII SPACE) padded ASCII byte array public static string SpacePaddedToString(byte[] SpacePaddedString) { + if (SpacePaddedString == null) + return null; + int length = 0; for (int i = SpacePaddedString.Length; i >= 0; i--) @@ -114,10 +123,7 @@ public static string SpacePaddedToString(byte[] SpacePaddedString) } } - if (length == 0) - return ""; - - return Encoding.ASCII.GetString(SpacePaddedString, 0, length); + return length == 0 ? "" : Encoding.ASCII.GetString(SpacePaddedString, 0, length); } } } From 0ce352425c2be891c4eca567b99ebd00749e4787 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 13 Jan 2016 19:59:44 +0000 Subject: [PATCH 006/217] * DiscImageChef.Devices/Enums.cs: * DiscImageChef.Helpers/ArrayFill.cs: * DiscImageChef.Helpers/ArrayIsEmpty.cs: * DiscImageChef.Devices/DiscImageChef.Devices.csproj: * DiscImageChef.Helpers/DiscImageChef.Helpers.csproj: Implemented Certance, Fujitsu and Hewlett-Packard vendor commands. * DiscImageChef.Devices/Device/ScsiCommands/Certance.cs: Implemented Certance vendor commands. * DiscImageChef.Devices/Device/ScsiCommands/Fujitsu.cs: Implemented Fujitsu vendor commands. * DiscImageChef.Devices/Device/ScsiCommands/HP.cs: Implemented Hewlett-Packard vendor commands. --- ArrayFill.cs | 2 +- ArrayIsEmpty.cs | 69 ++++++++++++++++++++++++++++++++++++ ChangeLog | 8 +++++ DiscImageChef.Helpers.csproj | 1 + 4 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 ArrayIsEmpty.cs diff --git a/ArrayFill.cs b/ArrayFill.cs index c3ba54cc6..9798aee1f 100644 --- a/ArrayFill.cs +++ b/ArrayFill.cs @@ -32,7 +32,7 @@ Assuming open source. namespace DiscImageChef { - public static class ArrayHelpers + public static partial class ArrayHelpers { public static void ArrayFill(T[] destinationArray, T value) { diff --git a/ArrayIsEmpty.cs b/ArrayIsEmpty.cs new file mode 100644 index 000000000..35ee8f868 --- /dev/null +++ b/ArrayIsEmpty.cs @@ -0,0 +1,69 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : ArrayIsEmpty.cs +// Version : 1.0 +// Author(s) : Natalia Portillo +// +// Component : Component +// +// Revision : $Revision$ +// Last change by : $Author$ +// Date : $Date$ +// +// --[ Description ] ---------------------------------------------------------- +// +// Description +// +// --[ License ] -------------------------------------------------------------- +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// ---------------------------------------------------------------------------- +// Copyright (C) 2011-2015 Claunia.com +// ****************************************************************************/ +// //$Id$ +using System; + +namespace DiscImageChef +{ + public static partial class ArrayHelpers + { + public static bool ArrayIsNullOrWhiteSpace(byte[] array) + { + if (array == null) + return true; + + foreach (byte b in array) + if (b != 0x00 && b != 0x20) + return false; + + return true; + } + + public static bool ArrayIsNullOrEmpty(byte[] array) + { + if (array == null) + return true; + + foreach (byte b in array) + if (b != 0x00) + return false; + + return true; + } + } +} + diff --git a/ChangeLog b/ChangeLog index 9a709ca09..e4872eee0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2016-01-13 Natalia Portillo + + * ArrayFill.cs: + * ArrayIsEmpty.cs: + * DiscImageChef.Helpers.csproj: + Implemented Certance, Fujitsu and Hewlett-Packard vendor + commands. + 2015-12-30 Natalia Portillo * StringHandlers.cs: diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index fece7f719..7d7520eaa 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -41,6 +41,7 @@ + From 025f080728eee623f845253cfcbfb4492e9c7c3b Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 19 Apr 2016 02:11:47 +0100 Subject: [PATCH 007/217] Reformatted. --- ArrayFill.cs | 4 ++-- ArrayIsEmpty.cs | 12 +++++------ BigEndianBitConverter.cs | 2 +- DateHandlers.cs | 44 +++++++++++++++++++------------------- EndianAwareBinaryReader.cs | 34 ++++++++++++++--------------- PrintHex.cs | 8 +++---- StringHandlers.cs | 24 ++++++++++----------- 7 files changed, 64 insertions(+), 64 deletions(-) diff --git a/ArrayFill.cs b/ArrayFill.cs index 9798aee1f..4e3193008 100644 --- a/ArrayFill.cs +++ b/ArrayFill.cs @@ -42,12 +42,12 @@ public static void ArrayFill(T[] destinationArray, T value) public static void ArrayFill(T[] destinationArray, T[] value) { - if (destinationArray == null) + if(destinationArray == null) { throw new ArgumentNullException("destinationArray"); } - if (value.Length > destinationArray.Length) + if(value.Length > destinationArray.Length) { throw new ArgumentException("Length of value array must not be more than length of destination"); } diff --git a/ArrayIsEmpty.cs b/ArrayIsEmpty.cs index 35ee8f868..d81457a3b 100644 --- a/ArrayIsEmpty.cs +++ b/ArrayIsEmpty.cs @@ -43,11 +43,11 @@ public static partial class ArrayHelpers { public static bool ArrayIsNullOrWhiteSpace(byte[] array) { - if (array == null) + if(array == null) return true; - foreach (byte b in array) - if (b != 0x00 && b != 0x20) + foreach(byte b in array) + if(b != 0x00 && b != 0x20) return false; return true; @@ -55,11 +55,11 @@ public static bool ArrayIsNullOrWhiteSpace(byte[] array) public static bool ArrayIsNullOrEmpty(byte[] array) { - if (array == null) + if(array == null) return true; - foreach (byte b in array) - if (b != 0x00) + foreach(byte b in array) + if(b != 0x00) return false; return true; diff --git a/BigEndianBitConverter.cs b/BigEndianBitConverter.cs index 171848d98..5bc6f799f 100644 --- a/BigEndianBitConverter.cs +++ b/BigEndianBitConverter.cs @@ -649,7 +649,7 @@ public static ulong ToUInt64(byte[] value, int startIndex) public static Guid ToGuid(byte[] value, int startIndex) { return new Guid(BigEndianBitConverter.ToUInt32(value, 0 + startIndex), - BigEndianBitConverter.ToUInt16(value, 4 + startIndex), + BigEndianBitConverter.ToUInt16(value, 4 + startIndex), BigEndianBitConverter.ToUInt16(value, 6 + startIndex), value[8 + startIndex + 0], value[8 + startIndex + 1], value[8 + startIndex + 2], value[8 + startIndex + 3], diff --git a/DateHandlers.cs b/DateHandlers.cs index 72802a5de..c39be0a32 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -75,61 +75,61 @@ public static DateTime ISO9660ToDateTime(byte[] VDDateTime) int year, month, day, hour, minute, second, hundredths; byte[] twocharvalue = new byte[2]; byte[] fourcharvalue = new byte[4]; - + fourcharvalue[0] = VDDateTime[0]; fourcharvalue[1] = VDDateTime[1]; fourcharvalue[2] = VDDateTime[2]; fourcharvalue[3] = VDDateTime[3]; DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "year = \"{0}\"", StringHandlers.CToString(fourcharvalue)); - if (!Int32.TryParse(StringHandlers.CToString(fourcharvalue), out year)) + if(!Int32.TryParse(StringHandlers.CToString(fourcharvalue), out year)) year = 0; -// year = Convert.ToInt32(StringHandlers.CToString(fourcharvalue)); - + // year = Convert.ToInt32(StringHandlers.CToString(fourcharvalue)); + twocharvalue[0] = VDDateTime[4]; twocharvalue[1] = VDDateTime[5]; DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "month = \"{0}\"", StringHandlers.CToString(twocharvalue)); - if (!Int32.TryParse(StringHandlers.CToString(twocharvalue), out month)) + if(!Int32.TryParse(StringHandlers.CToString(twocharvalue), out month)) month = 0; -// month = Convert.ToInt32(StringHandlers.CToString(twocharvalue)); - + // month = Convert.ToInt32(StringHandlers.CToString(twocharvalue)); + twocharvalue[0] = VDDateTime[6]; twocharvalue[1] = VDDateTime[7]; DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "day = \"{0}\"", StringHandlers.CToString(twocharvalue)); - if (!Int32.TryParse(StringHandlers.CToString(twocharvalue), out day)) + if(!Int32.TryParse(StringHandlers.CToString(twocharvalue), out day)) day = 0; -// day = Convert.ToInt32(StringHandlers.CToString(twocharvalue)); - + // day = Convert.ToInt32(StringHandlers.CToString(twocharvalue)); + twocharvalue[0] = VDDateTime[8]; twocharvalue[1] = VDDateTime[9]; DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "hour = \"{0}\"", StringHandlers.CToString(twocharvalue)); - if (!Int32.TryParse(StringHandlers.CToString(twocharvalue), out hour)) + if(!Int32.TryParse(StringHandlers.CToString(twocharvalue), out hour)) hour = 0; -// hour = Convert.ToInt32(StringHandlers.CToString(twocharvalue)); - + // hour = Convert.ToInt32(StringHandlers.CToString(twocharvalue)); + twocharvalue[0] = VDDateTime[10]; twocharvalue[1] = VDDateTime[11]; DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "minute = \"{0}\"", StringHandlers.CToString(twocharvalue)); - if (!Int32.TryParse(StringHandlers.CToString(twocharvalue), out minute)) + if(!Int32.TryParse(StringHandlers.CToString(twocharvalue), out minute)) minute = 0; -// minute = Convert.ToInt32(StringHandlers.CToString(twocharvalue)); - + // minute = Convert.ToInt32(StringHandlers.CToString(twocharvalue)); + twocharvalue[0] = VDDateTime[12]; twocharvalue[1] = VDDateTime[13]; DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "second = \"{0}\"", StringHandlers.CToString(twocharvalue)); - if (!Int32.TryParse(StringHandlers.CToString(twocharvalue), out second)) + if(!Int32.TryParse(StringHandlers.CToString(twocharvalue), out second)) second = 0; -// second = Convert.ToInt32(StringHandlers.CToString(twocharvalue)); - + // second = Convert.ToInt32(StringHandlers.CToString(twocharvalue)); + twocharvalue[0] = VDDateTime[14]; twocharvalue[1] = VDDateTime[15]; DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "hundredths = \"{0}\"", StringHandlers.CToString(twocharvalue)); - if (!Int32.TryParse(StringHandlers.CToString(twocharvalue), out hundredths)) + if(!Int32.TryParse(StringHandlers.CToString(twocharvalue), out hundredths)) hundredths = 0; -// hundredths = Convert.ToInt32(StringHandlers.CToString(twocharvalue)); + // hundredths = Convert.ToInt32(StringHandlers.CToString(twocharvalue)); DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "decodedDT = new DateTime({0}, {1}, {2}, {3}, {4}, {5}, {6}, DateTimeKind.Unspecified);", year, month, day, hour, minute, second, hundredths * 10); DateTime decodedDT = new DateTime(year, month, day, hour, minute, second, hundredths * 10, DateTimeKind.Unspecified); - + return decodedDT; } diff --git a/EndianAwareBinaryReader.cs b/EndianAwareBinaryReader.cs index dce8b6be8..4b5288572 100644 --- a/EndianAwareBinaryReader.cs +++ b/EndianAwareBinaryReader.cs @@ -48,13 +48,13 @@ public class EndianAwareBinaryReader : BinaryReader byte[] buffer = new byte[8]; public EndianAwareBinaryReader(Stream input, Encoding encoding, bool isLittleEndian) - : base(input, encoding) + : base(input, encoding) { IsLittleEndian = isLittleEndian; } public EndianAwareBinaryReader(Stream input, bool isLittleEndian) - : this(input, Encoding.UTF8, isLittleEndian) + : this(input, Encoding.UTF8, isLittleEndian) { } @@ -66,7 +66,7 @@ public bool IsLittleEndian public override double ReadDouble() { - if (IsLittleEndian) + if(IsLittleEndian) return base.ReadDouble(); FillMyBuffer(8); return BitConverter.ToDouble(buffer.Take(8).Reverse().ToArray(), 0); @@ -74,34 +74,34 @@ public override double ReadDouble() public override short ReadInt16() { - if (IsLittleEndian) + if(IsLittleEndian) return base.ReadInt16(); FillMyBuffer(2); return BitConverter.ToInt16(buffer.Take(2).Reverse().ToArray(), 0); - + } public override int ReadInt32() { - if (IsLittleEndian) + if(IsLittleEndian) return base.ReadInt32(); FillMyBuffer(4); return BitConverter.ToInt32(buffer.Take(4).Reverse().ToArray(), 0); - + } public override long ReadInt64() { - if (IsLittleEndian) + if(IsLittleEndian) return base.ReadInt64(); FillMyBuffer(8); return BitConverter.ToInt64(buffer.Take(8).Reverse().ToArray(), 0); - + } public override float ReadSingle() { - if (IsLittleEndian) + if(IsLittleEndian) return base.ReadSingle(); FillMyBuffer(4); return BitConverter.ToSingle(buffer.Take(4).Reverse().ToArray(), 0); @@ -109,7 +109,7 @@ public override float ReadSingle() public override ushort ReadUInt16() { - if (IsLittleEndian) + if(IsLittleEndian) return base.ReadUInt16(); FillMyBuffer(2); return BitConverter.ToUInt16(buffer.Take(2).Reverse().ToArray(), 0); @@ -117,7 +117,7 @@ public override ushort ReadUInt16() public override uint ReadUInt32() { - if (IsLittleEndian) + if(IsLittleEndian) return base.ReadUInt32(); FillMyBuffer(4); return BitConverter.ToUInt32(buffer.Take(4).Reverse().ToArray(), 0); @@ -125,7 +125,7 @@ public override uint ReadUInt32() public override ulong ReadUInt64() { - if (IsLittleEndian) + if(IsLittleEndian) return base.ReadUInt64(); FillMyBuffer(8); return BitConverter.ToUInt64(buffer.Take(8).Reverse().ToArray(), 0); @@ -135,10 +135,10 @@ void FillMyBuffer(int numBytes) { int offset = 0; int num2; - if (numBytes == 1) + if(numBytes == 1) { num2 = BaseStream.ReadByte(); - if (num2 == -1) + if(num2 == -1) { throw new EndOfStreamException("Attempted to read past the end of the stream."); } @@ -149,13 +149,13 @@ void FillMyBuffer(int numBytes) do { num2 = BaseStream.Read(buffer, offset, numBytes - offset); - if (num2 == 0) + if(num2 == 0) { throw new EndOfStreamException("Attempted to read past the end of the stream."); } offset += num2; } - while (offset < numBytes); + while(offset < numBytes); } } } diff --git a/PrintHex.cs b/PrintHex.cs index 15c242397..ea4bd5c5e 100644 --- a/PrintHex.cs +++ b/PrintHex.cs @@ -53,16 +53,16 @@ public static string ByteArrayToHexArrayString(byte[] array, int width) int counter = 0; int subcounter = 0; - for (long i = 0; i < array.LongLength; i++) + for(long i = 0; i < array.LongLength; i++) { - if (counter == 0) + if(counter == 0) { sb.AppendLine(); sb.AppendFormat("{0:X16} ", i); } else { - if (subcounter == 3 ) + if(subcounter == 3) { sb.Append(" "); subcounter = 0; @@ -76,7 +76,7 @@ public static string ByteArrayToHexArrayString(byte[] array, int width) sb.AppendFormat("{0:X2}", array[i]); - if (counter == width - 1) + if(counter == width - 1) { counter = 0; subcounter = 0; diff --git a/StringHandlers.cs b/StringHandlers.cs index 19816cf81..19707d470 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -61,19 +61,19 @@ public static string CToString(byte[] CString) /// Encoding. public static string CToString(byte[] CString, Encoding encoding) { - if (CString == null) + if(CString == null) return null; StringBuilder sb = new StringBuilder(); - - for (int i = 0; i < CString.Length; i++) + + for(int i = 0; i < CString.Length; i++) { - if (CString[i] == 0) + if(CString[i] == 0) break; sb.Append(encoding.GetString(CString, i, 1)); } - + return sb.ToString(); } @@ -84,14 +84,14 @@ public static string CToString(byte[] CString, Encoding encoding) /// A length-prefixed (aka Pascal string) ASCII byte array public static string PascalToString(byte[] PascalString) { - if (PascalString == null) + if(PascalString == null) return null; StringBuilder sb = new StringBuilder(); byte length = PascalString[0]; - for (int i = 1; i < length + 1; i++) + for(int i = 1; i < length + 1; i++) { sb.Append(Encoding.ASCII.GetString(PascalString, i, 1)); } @@ -106,17 +106,17 @@ public static string PascalToString(byte[] PascalString) /// A space (' ', 0x20, ASCII SPACE) padded ASCII byte array public static string SpacePaddedToString(byte[] SpacePaddedString) { - if (SpacePaddedString == null) + if(SpacePaddedString == null) return null; - + int length = 0; - for (int i = SpacePaddedString.Length; i >= 0; i--) + for(int i = SpacePaddedString.Length; i >= 0; i--) { - if (i == 0) + if(i == 0) return ""; - if (SpacePaddedString[i - 1] != 0x20) + if(SpacePaddedString[i - 1] != 0x20) { length = i; break; From 994a760d4080d8f397f66f52a29c181ca4c11f00 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 19 Jul 2016 22:29:08 +0100 Subject: [PATCH 008/217] * README.md: * DiscImageChef.sln: * DiscImageChef/AssemblyInfo.cs: * DiscImageChef/DiscImageChef.csproj: * DiscImageChef.Interop/DiscImageChef.Interop.csproj: * DiscImageChef.Helpers/DiscImageChef.Helpers.csproj: * DiscImageChef.Checksums/Properties/AssemblyInfo.cs: * DiscImageChef.Devices/DiscImageChef.Devices.csproj: * DiscImageChef.Console/DiscImageChef.Console.csproj: * DiscImageChef.Decoders/DiscImageChef.Decoders.csproj: * DiscImageChef.Metadata/DiscImageChef.Metadata.csproj: * DiscImageChef.Settings/DiscImageChef.Settings.csproj: * DiscImageChef.Checksums/DiscImageChef.Checksums.csproj: * DiscImageChef.DiscImages/DiscImageChef.DiscImages.csproj: * DiscImageChef.Partitions/DiscImageChef.Partitions.csproj: * DiscImageChef.CommonTypes/DiscImageChef.CommonTypes.csproj: * DiscImageChef.Filesystems/DiscImageChef.Filesystems.csproj: * Packages.mdproj: Bumped version to 3.0.0.0. --- DiscImageChef.Helpers.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index 7d7520eaa..ff1f147d2 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -9,7 +9,7 @@ Library DiscImageChef.Helpers DiscImageChef.Helpers - 2.2 + 3.0.0 true From de385b12262988e2c105bbd8a63829560219accd Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 28 Jul 2016 18:13:49 +0100 Subject: [PATCH 009/217] * LICENSE.MIT: * LICENSE.LGPL: Added LICENSE files for LGPL and MIT licenses. * DiscImageChef.Devices/Enums.cs: * DiscImageChef.Partitions/MBR.cs: * DiscImageChef.Partitions/RDB.cs: * DiscImageChef.DiscImages/GDI.cs: * DiscImageChef.Partitions/Sun.cs: * DiscImageChef.DiscImages/VHD.cs: * DiscImageChef.Partitions/GPT.cs: * DiscImageChef.Filesystems/FFS.cs: * DiscImageChef.Filesystems/FAT.cs: * DiscImageChef.Partitions/NeXT.cs: * DiscImageChef.Devices/Command.cs: * DiscImageChef.DiscImages/Nero.cs: * DiscImageChef.Decoders/CD/PMA.cs: * DiscImageChef.Decoders/CD/TOC.cs: * DiscImageChef.Filesystems/BFS.cs: * DiscImageChef.Filesystems/ODS.cs: * DiscImageChef.Helpers/PrintHex.cs: * DiscImageChef.Helpers/Swapping.cs: * DiscImageChef.Decoders/DVD/PRI.cs: * DiscImageChef.Decoders/DVD/DMI.cs: * DiscImageChef.Decoders/DVD/DDS.cs: * DiscImageChef.Decoders/DVD/RMD.cs: * DiscImageChef.Decoders/DVD/UDI.cs: * DiscImageChef.Partitions/Atari.cs: * DiscImageChef.Decoders/DVD/BCA.cs: * DiscImageChef.Filesystems/SysV.cs: * DiscImageChef.Filesystems/HPFS.cs: * DiscImageChef.Filesystems/NTFS.cs: * DiscImageChef.Filesystems/APFS.cs: * DiscImageChef.Decoders/DVD/PFI.cs: * DiscImageChef.Decoders/CD/ATIP.cs: * DiscImageChef.Filesystems/Acorn.cs: * DiscImageChef.DiscImages/CDRWin.cs: * DiscImageChef.DiscImages/CDRDAO.cs: * DiscImageChef.Filesystems/BTRFS.cs: * DiscImageChef.Decoders/Xbox/DMI.cs: * DiscImageChef.Helpers/ArrayFill.cs: * DiscImageChef.Settings/Settings.cs: * DiscImageChef.Filesystems/Opera.cs: * DiscImageChef.Filesystems/extFS.cs: * DiscImageChef.Decoders/DVD/CPRM.cs: * DiscImageChef.Decoders/DVD/ADIP.cs: * DiscImageChef.Decoders/CD/Enums.cs: * DiscImageChef.Decoders/DVD/AACS.cs: * DiscImageChef.Decoders/SCSI/EVPD.cs: * DiscImageChef.Filesystems/ProDOS.cs: * DiscImageChef.Metadata/MediaType.cs: * DiscImageChef.Console/DicConsole.cs: * DiscImageChef.Decoders/DVD/Spare.cs: * DiscImageChef.Filesystems/ext2FS.cs: * DiscImageChef.Decoders/DVD/Enums.cs: * DiscImageChef.Filesystems/Symbian.cs: * DiscImageChef.Decoders/SCSI/Types.cs: * DiscImageChef.Filesystems/UNIXBFS.cs: * DiscImageChef.DiscImages/TeleDisk.cs: * DiscImageChef.Decoders/SCSI/Sense.cs: * DiscImageChef.Decoders/CD/FullTOC.cs: * DiscImageChef.Decoders/Blu-ray/DI.cs: * DiscImageChef.Decoders/ATA/Errors.cs: * DiscImageChef.Filesystems/ISO9660.cs: * DiscImageChef.Filesystems/MinixFS.cs: * DiscImageChef.Devices/Linux/Enums.cs: * DiscImageChef.Filesystems/SolarFS.cs: * DiscImageChef.Filesystems/Structs.cs: * DiscImageChef.DiscImages/Apple2MG.cs: * DiscImageChef.Decoders/SCSI/Modes.cs: * DiscImageChef.Metadata/Dimensions.cs: * DiscImageChef.Partitions/AppleMap.cs: * DiscImageChef.Decoders/Floppy/ISO.cs: * DiscImageChef.Decoders/DVD/Layers.cs: * DiscImageChef.Decoders/CD/Session.cs: * DiscImageChef.Decoders/SCSI/Enums.cs: * DiscImageChef.Filesystems/Nintendo.cs: * DiscImageChef.Helpers/DateHandlers.cs: * DiscImageChef.Filesystems/AmigaDOS.cs: * DiscImageChef.DiscImages/ImageInfo.cs: * DiscImageChef.Checksums/MD5Context.cs: * DiscImageChef.Devices/Linux/Extern.cs: * DiscImageChef.Filesystems/AppleHFS.cs: * DiscImageChef.Filesystems/AppleMFS.cs: * DiscImageChef.Helpers/ArrayIsEmpty.cs: * DiscImageChef.Decoders/Blu-ray/BCA.cs: * DiscImageChef.Decoders/Blu-ray/DDS.cs: * DiscImageChef.Filesystems/PCEngine.cs: * DiscImageChef.Decoders/ATA/Identify.cs: * DiscImageChef.Devices/Linux/Command.cs: * DiscImageChef.Devices/FreeBSD/Enums.cs: * DiscImageChef.Decoders/SCSI/Inquiry.cs: * DiscImageChef.Metadata/DeviceReport.cs: * DiscImageChef.Decoders/Floppy/Amiga.cs: * DiscImageChef.Devices/Linux/Structs.cs: * DiscImageChef.Devices/Windows/Enums.cs: * DiscImageChef.Decoders/DVD/CSS&CPRM.cs: * DiscImageChef.Checksums/SHA1Context.cs: * DiscImageChef.DiscImages/DiskCopy42.cs: * DiscImageChef.Partitions/PartPlugin.cs: * DiscImageChef.CommonTypes/Partition.cs: * DiscImageChef.Decoders/Floppy/Enums.cs: * DiscImageChef.CommonTypes/MediaType.cs: * DiscImageChef.Decoders/Floppy/Apple2.cs: * DiscImageChef.Devices/Windows/Extern.cs: * DiscImageChef.Decoders/SCSI/MMC/CPRM.cs: * DiscImageChef.Helpers/StringHandlers.cs: * DiscImageChef.DiscImages/ImagePlugin.cs: * DiscImageChef.Checksums/CRC64Context.cs: * DiscImageChef.Checksums/CRC32Context.cs: * DiscImageChef.DiscImages/ZZZRawImage.cs: * DiscImageChef.Checksums/CRC16Context.cs: * DiscImageChef.Filesystems/LisaFS/Dir.cs: * DiscImageChef.Decoders/DVD/Cartridge.cs: * DiscImageChef.Decoders/Blu-ray/Spare.cs: * DiscImageChef.Filesystems/Filesystem.cs: * DiscImageChef.Decoders/SCSI/MMC/AACS.cs: * DiscImageChef.Devices/FreeBSD/Extern.cs: * DiscImageChef.Devices/Device/Commands.cs: * DiscImageChef.Checksums/SHA384Context.cs: * DiscImageChef.Devices/FreeBSD/Command.cs: * DiscImageChef.Checksums/SHA512Context.cs: * DiscImageChef.Decoders/SCSI/MMC/Enums.cs: * DiscImageChef.Devices/Windows/Command.cs: * DiscImageChef.Devices/FreeBSD/Structs.cs: * DiscImageChef.Devices/Windows/Structs.cs: * DiscImageChef.Filesystems/LisaFS/Info.cs: * DiscImageChef.Checksums/SHA256Context.cs: * DiscImageChef.Filesystems/LisaFS/File.cs: * DiscImageChef.Filesystems/AppleHFSPlus.cs: * DiscImageChef.Filesystems/LisaFS/Super.cs: * DiscImageChef.Filesystems/LisaFS/Xattr.cs: * DiscImageChef.Checksums/Adler32Context.cs: * DiscImageChef.Decoders/Floppy/System34.cs: * DiscImageChef.Checksums/SpamSumContext.cs: * DiscImageChef.Decoders/SCSI/MMC/Hybrid.cs: * DiscImageChef.Devices/Device/Variables.cs: * DiscImageChef.Filesystems/LisaFS/Consts.cs: * DiscImageChef.Filesystems/LisaFS/LisaFS.cs: * DiscImageChef.Decoders/Floppy/Commodore.cs: * DiscImageChef.Checksums/FletcherContext.cs: * DiscImageChef.Filesystems/LisaFS/Extent.cs: * DiscImageChef.Devices/Device/Destructor.cs: * DiscImageChef.Decoders/Floppy/AppleSony.cs: * DiscImageChef.Filesystems/LisaFS/Structs.cs: * DiscImageChef.Decoders/SCSI/VendorString.cs: * DiscImageChef.Decoders/SCSI/MMC/Features.cs: * DiscImageChef.Devices/Device/Constructor.cs: * DiscImageChef.Checksums/RIPEMD160Context.cs: * DiscImageChef.Decoders/CD/CDTextOnLeadIn.cs: * DiscImageChef.Decoders/Blu-ray/Cartridge.cs: * DiscImageChef.Decoders/Floppy/System3740.cs: * DiscImageChef.Filesystems/LisaFS/Encoding.cs: * DiscImageChef.Decoders/SCSI/ModesEncoders.cs: * DiscImageChef.CommonTypes/MediaTypeFromSCSI.cs: * DiscImageChef.Helpers/BigEndianBitConverter.cs: * DiscImageChef.Decoders/Floppy/Perpendicular.cs: * DiscImageChef.Decoders/SCSI/SSC/BlockLimits.cs: * DiscImageChef.Decoders/SCSI/MMC/WriteProtect.cs: * DiscImageChef.Devices/Device/ScsiCommands/HP.cs: * DiscImageChef.Devices/Device/AtaCommands/Cfa.cs: * DiscImageChef.Devices/Device/ScsiCommands/NEC.cs: * DiscImageChef.Helpers/EndianAwareBinaryReader.cs: * DiscImageChef.Devices/Device/ScsiCommands/MMC.cs: * DiscImageChef.Devices/Device/AtaCommands/MCPT.cs: * DiscImageChef.Devices/Device/ScsiCommands/SSC.cs: * DiscImageChef.Devices/Device/ScsiCommands/SPC.cs: * DiscImageChef.Devices/Device/ScsiCommands/SMC.cs: * DiscImageChef.Devices/Device/ScsiCommands/SBC.cs: * DiscImageChef.Metadata/Properties/AssemblyInfo.cs: * DiscImageChef.Devices/Device/AtaCommands/Atapi.cs: * DiscImageChef.Devices/Device/AtaCommands/Ata28.cs: * DiscImageChef.Devices/Device/AtaCommands/Smart.cs: * DiscImageChef.Decoders/SCSI/SSC/DensitySupport.cs: * DiscImageChef.Devices/Device/AtaCommands/Ata48.cs: * DiscImageChef.Decoders/SCSI/MMC/DiscInformation.cs: * DiscImageChef.Devices/Device/AtaCommands/AtaCHS.cs: * DiscImageChef.Devices/Device/ScsiCommands/SyQuest.cs: * DiscImageChef.Devices/Device/ScsiCommands/Plextor.cs: * DiscImageChef.Devices/Device/ScsiCommands/Plasmon.cs: * DiscImageChef.Devices/Device/ScsiCommands/Pioneer.cs: * DiscImageChef.Devices/Device/ScsiCommands/Adaptec.cs: * DiscImageChef.Devices/Device/ScsiCommands/Fujitsu.cs: * DiscImageChef.Devices/Device/ScsiCommands/HL-DT-ST.cs: * DiscImageChef.Devices/Device/ScsiCommands/Certance.cs: * DiscImageChef.Decoders/SCSI/DiscStructureCapabilities.cs: * DiscImageChef.Devices/Device/ScsiCommands/ArchiveCorp.cs: Relicensed as LGPL. Updated standard header. * DiscImageChef/Main.cs: * DiscImageChef/Plugins.cs: * DiscImageChef/Options.cs: * DiscImageChef/Commands/Ls.cs: * DiscImageChef/Core/IBGLog.cs: * DiscImageChef/Core/MHDDLog.cs: * DiscImageChef/AssemblyInfo.cs: * DiscImageChef/Core/Checksum.cs: * DiscImageChef/Commands/Decode.cs: * DiscImageChef/Core/Statistics.cs: * DiscImageChef/Commands/Verify.cs: * DiscImageChef/Commands/Formats.cs: * DiscImageChef/Commands/Entropy.cs: * DiscImageChef/Commands/Compare.cs: * DiscImageChef.Interop/DetectOS.cs: * DiscImageChef/Commands/Analyze.cs: * DiscImageChef/Commands/Commands.cs: * DiscImageChef/Commands/PrintHex.cs: * DiscImageChef/Commands/Checksum.cs: * DiscImageChef/DetectImageFormat.cs: * DiscImageChef/Commands/DumpMedia.cs: * DiscImageChef/Commands/Benchmark.cs: * DiscImageChef/Commands/Configure.cs: * DiscImageChef/Commands/MediaInfo.cs: * DiscImageChef.Interop/PlatformID.cs: * DiscImageChef/Commands/MediaScan.cs: * DiscImageChef/Commands/Statistics.cs: * DiscImageChef/Commands/DeviceInfo.cs: * DiscImageChef.Checksums/ReedSolomon.cs: * DiscImageChef/Commands/DeviceReport.cs: * DiscImageChef/Commands/ExtractFiles.cs: * DiscImageChef.Checksums/CDChecksums.cs: * DiscImageChef/Commands/CreateSidecar.cs: Updated standard header. * DiscImageChef.Checksums/DiscImageChef.Checksums.csproj: Relicensed project as LGPL. Updated standard header. Embed license as resource. * DiscImageChef.Console/DiscImageChef.Console.csproj: * DiscImageChef.Devices/DiscImageChef.Devices.csproj: * DiscImageChef.Helpers/DiscImageChef.Helpers.csproj: * DiscImageChef.Settings/DiscImageChef.Settings.csproj: * DiscImageChef.Decoders/DiscImageChef.Decoders.csproj: * DiscImageChef.Metadata/DiscImageChef.Metadata.csproj: * DiscImageChef.Partitions/DiscImageChef.Partitions.csproj: * DiscImageChef.DiscImages/DiscImageChef.DiscImages.csproj: * DiscImageChef.Filesystems/DiscImageChef.Filesystems.csproj: * DiscImageChef.CommonTypes/DiscImageChef.CommonTypes.csproj: Relicensed as LGPL. Updated standard header. Embed license as resource. * DiscImageChef/DiscImageChef.csproj: * DiscImageChef.Interop/DiscImageChef.Interop.csproj: Updated standard header. Embed license as resource. --- ArrayFill.cs | 54 +++++++++++++--------------- ArrayIsEmpty.cs | 33 ++++++++--------- BigEndianBitConverter.cs | 68 ++++++++++++++++-------------------- DateHandlers.cs | 68 ++++++++++++++++-------------------- DiscImageChef.Helpers.csproj | 14 ++++++++ EndianAwareBinaryReader.cs | 68 ++++++++++++++++-------------------- PrintHex.cs | 67 ++++++++++++++++------------------- StringHandlers.cs | 24 ++++++------- Swapping.cs | 68 ++++++++++++++++-------------------- 9 files changed, 220 insertions(+), 244 deletions(-) diff --git a/ArrayFill.cs b/ArrayFill.cs index 4e3193008..436825b88 100644 --- a/ArrayFill.cs +++ b/ArrayFill.cs @@ -1,33 +1,29 @@ -/*************************************************************************** -The Disc Image Chef ----------------------------------------------------------------------------- - -Filename : ArrayFill.cs -Version : 1.0 -Author(s) : https://github.com/mykohsu - -Component : Helpers +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : ArrayFill.cs +// Author(s) : Natalia Portillo +// +// Component : Helpers. +// +// --[ Description ] ---------------------------------------------------------- +// +// Fills an array with a specified value. +// +// --[ License ] -------------------------------------------------------------- +// +// No license specified by creator. +// +// Published on https://github.com/mykohsu/Extensions/blob/master/ArrayExtensions.cs +// +// Assuming open source. +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2016 Natalia Portillo +// Copyright(C) 2014 mykohsu +// ****************************************************************************/ -Revision : $Revision$ -Last change by : $Author$ -Date : $Date$ - ---[ Description ] ---------------------------------------------------------- - -Fills an array with a - ---[ License ] -------------------------------------------------------------- - - No license specified by creator. - - Published on https://github.com/mykohsu/Extensions/blob/master/ArrayExtensions.cs - - Assuming open source. - ----------------------------------------------------------------------------- -Copyright (C) 2014 mykohsu -****************************************************************************/ -//$Id$ using System; namespace DiscImageChef diff --git a/ArrayIsEmpty.cs b/ArrayIsEmpty.cs index d81457a3b..a443c5e83 100644 --- a/ArrayIsEmpty.cs +++ b/ArrayIsEmpty.cs @@ -3,38 +3,33 @@ // ---------------------------------------------------------------------------- // // Filename : ArrayIsEmpty.cs -// Version : 1.0 -// Author(s) : Natalia Portillo +// Author(s) : Natalia Portillo // -// Component : Component -// -// Revision : $Revision$ -// Last change by : $Author$ -// Date : $Date$ +// Component : Helpers. // // --[ Description ] ---------------------------------------------------------- // -// Description +// Methods for detecting an empty array. // // --[ License ] -------------------------------------------------------------- // -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as -// published by the Free Software Foundation, either version 3 of the +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the // License, or (at your option) any later version. // -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. // -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright (C) 2011-2015 Claunia.com +// Copyright © 2011-2016 Natalia Portillo // ****************************************************************************/ -// //$Id$ + using System; namespace DiscImageChef diff --git a/BigEndianBitConverter.cs b/BigEndianBitConverter.cs index 5bc6f799f..d12099407 100644 --- a/BigEndianBitConverter.cs +++ b/BigEndianBitConverter.cs @@ -1,40 +1,34 @@ -/*************************************************************************** -The Disc Image Chef ----------------------------------------------------------------------------- - -Filename : BigEndianBitConverter.cs -Version : 1.0 -Author(s) : Natalia Portillo - -Component : Program tools - -Revision : $Revision$ -Last change by : $Author$ -Date : $Date$ - ---[ Description ] ---------------------------------------------------------- - -Override of System.BitConverter that knows how to handle big-endian. - ---[ License ] -------------------------------------------------------------- - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as - published by the Free Software Foundation, either version 3 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - ----------------------------------------------------------------------------- -Copyright (C) 2011-2014 Claunia.com -****************************************************************************/ -//$Id$ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : BigEndianBitConverter.cs +// Author(s) : Natalia Portillo +// +// Component : Helpers. +// +// --[ Description ] ---------------------------------------------------------- +// +// Override of System.BitConverter that knows how to handle big-endian. +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2016 Natalia Portillo +// ****************************************************************************/ using System; using System.Linq; diff --git a/DateHandlers.cs b/DateHandlers.cs index c39be0a32..e4dcf1718 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -1,40 +1,34 @@ -/*************************************************************************** -The Disc Image Chef ----------------------------------------------------------------------------- - -Filename : DateHandlers.cs -Version : 1.0 -Author(s) : Natalia Portillo - -Component : Program tools - -Revision : $Revision$ -Last change by : $Author$ -Date : $Date$ - ---[ Description ] ---------------------------------------------------------- - -Convert several timestamp formats to C# DateTime. - ---[ License ] -------------------------------------------------------------- - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as - published by the Free Software Foundation, either version 3 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - ----------------------------------------------------------------------------- -Copyright (C) 2011-2014 Claunia.com -****************************************************************************/ -//$Id$ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : DateHandlers.cs +// Author(s) : Natalia Portillo +// +// Component : Helpers. +// +// --[ Description ] ---------------------------------------------------------- +// +// Convert several timestamp formats to C# DateTime. +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2016 Natalia Portillo +// ****************************************************************************/ using System; using DiscImageChef.Console; diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index ff1f147d2..70461eef6 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -50,4 +50,18 @@ DiscImageChef.Console + + + LICENSE.LGPL + + + + + + + + + + + \ No newline at end of file diff --git a/EndianAwareBinaryReader.cs b/EndianAwareBinaryReader.cs index 4b5288572..301b7e825 100644 --- a/EndianAwareBinaryReader.cs +++ b/EndianAwareBinaryReader.cs @@ -1,40 +1,34 @@ -/*************************************************************************** -The Disc Image Chef ----------------------------------------------------------------------------- - -Filename : EndianAwareBinaryReader.cs -Version : 1.0 -Author(s) : Natalia Portillo - -Component : Program tools - -Revision : $Revision$ -Last change by : $Author$ -Date : $Date$ - ---[ Description ] ---------------------------------------------------------- - -Override for System.IO.Binary.Reader that knows how to handle big-endian. - ---[ License ] -------------------------------------------------------------- - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as - published by the Free Software Foundation, either version 3 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - ----------------------------------------------------------------------------- -Copyright (C) 2011-2014 Claunia.com -****************************************************************************/ -//$Id$ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : EndianAwareBinaryReader.cs +// Author(s) : Natalia Portillo +// +// Component : Helpers. +// +// --[ Description ] ---------------------------------------------------------- +// +// Override for System.IO.Binary.Reader that knows how to handle big-endian. +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2016 Natalia Portillo +// ****************************************************************************/ using System; using System.IO; diff --git a/PrintHex.cs b/PrintHex.cs index ea4bd5c5e..3d5a502e8 100644 --- a/PrintHex.cs +++ b/PrintHex.cs @@ -1,40 +1,35 @@ -/*************************************************************************** -The Disc Image Chef ----------------------------------------------------------------------------- - -Filename : PrintHex.cs -Version : 1.0 -Author(s) : Natalia Portillo - -Component : Helpers +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : PrintHex.cs +// Author(s) : Natalia Portillo +// +// Component : Helpers. +// +// --[ Description ] ---------------------------------------------------------- +// +// Prints a byte array as hexadecimal. +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2016 Natalia Portillo +// ****************************************************************************/ -Revision : $Revision$ -Last change by : $Author$ -Date : $Date$ - ---[ Description ] ---------------------------------------------------------- - -Prints a byte array as hexadecimal in console. - ---[ License ] -------------------------------------------------------------- - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as - published by the Free Software Foundation, either version 3 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - ----------------------------------------------------------------------------- -Copyright (C) 2011-2014 Claunia.com -****************************************************************************/ -//$Id$ using System; using DiscImageChef.Console; diff --git a/StringHandlers.cs b/StringHandlers.cs index 19707d470..162376003 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -18,18 +18,18 @@ Convert byte arrays to C# strings. --[ License ] -------------------------------------------------------------- - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as - published by the Free Software Foundation, either version 3 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . + This library is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of the + License, or(at your option) any later version. + + This library is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, see . ---------------------------------------------------------------------------- Copyright (C) 2011-2014 Claunia.com diff --git a/Swapping.cs b/Swapping.cs index 177673103..8a182c7de 100644 --- a/Swapping.cs +++ b/Swapping.cs @@ -1,40 +1,34 @@ -/*************************************************************************** -The Disc Image Chef ----------------------------------------------------------------------------- - -Filename : Swapping.cs -Version : 1.0 -Author(s) : Natalia Portillo - -Component : Program tools - -Revision : $Revision$ -Last change by : $Author$ -Date : $Date$ - ---[ Description ] ---------------------------------------------------------- - -Byte-swapping methods - ---[ License ] -------------------------------------------------------------- - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as - published by the Free Software Foundation, either version 3 of the - License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - ----------------------------------------------------------------------------- -Copyright (C) 2011-2014 Claunia.com -****************************************************************************/ -//$Id$ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : Swapping.cs +// Author(s) : Natalia Portillo +// +// Component : Helpers. +// +// --[ Description ] ---------------------------------------------------------- +// +// Byte-swapping methods. +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2016 Natalia Portillo +// ****************************************************************************/ using System; From 3873e4d9ed07746fe5c866f91e1dbab8d0a61eb2 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 28 Jul 2016 22:25:26 +0100 Subject: [PATCH 010/217] Refactor and code cleanup. --- ArrayFill.cs | 4 +-- ArrayIsEmpty.cs | 2 -- BigEndianBitConverter.cs | 20 +++++------ ChangeLog | 11 ++++++ DateHandlers.cs | 24 ++++++------- EndianAwareBinaryReader.cs | 2 +- PrintHex.cs | 1 - StringHandlers.cs | 71 +++++++++++++++++--------------------- Swapping.cs | 6 ++-- 9 files changed, 70 insertions(+), 71 deletions(-) diff --git a/ArrayFill.cs b/ArrayFill.cs index 436825b88..7c6be86cb 100644 --- a/ArrayFill.cs +++ b/ArrayFill.cs @@ -33,14 +33,14 @@ public static partial class ArrayHelpers public static void ArrayFill(T[] destinationArray, T value) { // if called with a single value, wrap the value in an array and call the main function - ArrayFill(destinationArray, new T[] { value }); + ArrayFill(destinationArray, new T[] { value }); } public static void ArrayFill(T[] destinationArray, T[] value) { if(destinationArray == null) { - throw new ArgumentNullException("destinationArray"); + throw new ArgumentNullException(nameof(destinationArray)); } if(value.Length > destinationArray.Length) diff --git a/ArrayIsEmpty.cs b/ArrayIsEmpty.cs index a443c5e83..8e5375ad6 100644 --- a/ArrayIsEmpty.cs +++ b/ArrayIsEmpty.cs @@ -30,8 +30,6 @@ // Copyright © 2011-2016 Natalia Portillo // ****************************************************************************/ -using System; - namespace DiscImageChef { public static partial class ArrayHelpers diff --git a/BigEndianBitConverter.cs b/BigEndianBitConverter.cs index d12099407..17ecfbf6d 100644 --- a/BigEndianBitConverter.cs +++ b/BigEndianBitConverter.cs @@ -362,7 +362,7 @@ public static double ToDouble(byte[] value, int startIndex) /// public static short ToInt16(byte[] value, int startIndex) { - return !IsLittleEndian ? BitConverter.ToInt16(value, startIndex) : BitConverter.ToInt16(value.Reverse().ToArray(), value.Length - sizeof(Int16) - startIndex); + return !IsLittleEndian ? BitConverter.ToInt16(value, startIndex) : BitConverter.ToInt16(value.Reverse().ToArray(), value.Length - sizeof(short) - startIndex); } /// @@ -393,7 +393,7 @@ public static short ToInt16(byte[] value, int startIndex) /// public static int ToInt32(byte[] value, int startIndex) { - return !IsLittleEndian ? BitConverter.ToInt32(value, startIndex) : BitConverter.ToInt32(value.Reverse().ToArray(), value.Length - sizeof(Int32) - startIndex); + return !IsLittleEndian ? BitConverter.ToInt32(value, startIndex) : BitConverter.ToInt32(value.Reverse().ToArray(), value.Length - sizeof(int) - startIndex); } /// @@ -424,7 +424,7 @@ public static int ToInt32(byte[] value, int startIndex) /// public static long ToInt64(byte[] value, int startIndex) { - return !IsLittleEndian ? BitConverter.ToInt64(value, startIndex) : BitConverter.ToInt64(value.Reverse().ToArray(), value.Length - sizeof(Int64) - startIndex); + return !IsLittleEndian ? BitConverter.ToInt64(value, startIndex) : BitConverter.ToInt64(value.Reverse().ToArray(), value.Length - sizeof(long) - startIndex); } /// @@ -456,7 +456,7 @@ public static long ToInt64(byte[] value, int startIndex) /// public static float ToSingle(byte[] value, int startIndex) { - return !IsLittleEndian ? BitConverter.ToSingle(value, startIndex) : BitConverter.ToSingle(value.Reverse().ToArray(), value.Length - sizeof(Single) - startIndex); + return !IsLittleEndian ? BitConverter.ToSingle(value, startIndex) : BitConverter.ToSingle(value.Reverse().ToArray(), value.Length - sizeof(float) - startIndex); } /// @@ -575,7 +575,7 @@ public static string ToString(byte[] value, int startIndex, int length) /// public static ushort ToUInt16(byte[] value, int startIndex) { - return !IsLittleEndian ? BitConverter.ToUInt16(value, startIndex) : BitConverter.ToUInt16(value.Reverse().ToArray(), value.Length - sizeof(UInt16) - startIndex); + return !IsLittleEndian ? BitConverter.ToUInt16(value, startIndex) : BitConverter.ToUInt16(value.Reverse().ToArray(), value.Length - sizeof(ushort) - startIndex); } /// @@ -606,7 +606,7 @@ public static ushort ToUInt16(byte[] value, int startIndex) /// public static uint ToUInt32(byte[] value, int startIndex) { - return !IsLittleEndian ? BitConverter.ToUInt32(value, startIndex) : BitConverter.ToUInt32(value.Reverse().ToArray(), value.Length - sizeof(UInt32) - startIndex); + return !IsLittleEndian ? BitConverter.ToUInt32(value, startIndex) : BitConverter.ToUInt32(value.Reverse().ToArray(), value.Length - sizeof(uint) - startIndex); } /// @@ -637,14 +637,14 @@ public static uint ToUInt32(byte[] value, int startIndex) /// public static ulong ToUInt64(byte[] value, int startIndex) { - return !IsLittleEndian ? BitConverter.ToUInt64(value, startIndex) : BitConverter.ToUInt64(value.Reverse().ToArray(), value.Length - sizeof(UInt64) - startIndex); + return !IsLittleEndian ? 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(BigEndianBitConverter.ToUInt32(value, 0 + startIndex), - BigEndianBitConverter.ToUInt16(value, 4 + startIndex), - BigEndianBitConverter.ToUInt16(value, 6 + 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], diff --git a/ChangeLog b/ChangeLog index e4872eee0..4bce39523 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2016-07-28 Natalia Portillo + + * Swapping.cs: + * PrintHex.cs: + * ArrayFill.cs: + * ArrayIsEmpty.cs: + * DateHandlers.cs: + * StringHandlers.cs: + * BigEndianBitConverter.cs: + * EndianAwareBinaryReader.cs: Refactor and code cleanup. + 2016-01-13 Natalia Portillo * ArrayFill.cs: diff --git a/DateHandlers.cs b/DateHandlers.cs index e4dcf1718..b80804f80 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -49,17 +49,17 @@ public static DateTime MacToDateTime(ulong MacTimeStamp) return MacEpoch.AddTicks((long)(MacTimeStamp * 10000000)); } - public static DateTime LisaToDateTime(UInt32 LisaTimeStamp) + public static DateTime LisaToDateTime(uint LisaTimeStamp) { return LisaEpoch.AddSeconds(LisaTimeStamp); } - public static DateTime UNIXToDateTime(Int32 UNIXTimeStamp) + public static DateTime UNIXToDateTime(int UNIXTimeStamp) { return UNIXEpoch.AddSeconds(UNIXTimeStamp); } - public static DateTime UNIXUnsignedToDateTime(UInt32 UNIXTimeStamp) + public static DateTime UNIXUnsignedToDateTime(uint UNIXTimeStamp) { return UNIXEpoch.AddSeconds(UNIXTimeStamp); } @@ -75,49 +75,49 @@ public static DateTime ISO9660ToDateTime(byte[] VDDateTime) fourcharvalue[2] = VDDateTime[2]; fourcharvalue[3] = VDDateTime[3]; DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "year = \"{0}\"", StringHandlers.CToString(fourcharvalue)); - if(!Int32.TryParse(StringHandlers.CToString(fourcharvalue), out year)) + if(!int.TryParse(StringHandlers.CToString(fourcharvalue), out year)) year = 0; // year = Convert.ToInt32(StringHandlers.CToString(fourcharvalue)); twocharvalue[0] = VDDateTime[4]; twocharvalue[1] = VDDateTime[5]; DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "month = \"{0}\"", StringHandlers.CToString(twocharvalue)); - if(!Int32.TryParse(StringHandlers.CToString(twocharvalue), out month)) + if(!int.TryParse(StringHandlers.CToString(twocharvalue), out month)) month = 0; // month = Convert.ToInt32(StringHandlers.CToString(twocharvalue)); twocharvalue[0] = VDDateTime[6]; twocharvalue[1] = VDDateTime[7]; DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "day = \"{0}\"", StringHandlers.CToString(twocharvalue)); - if(!Int32.TryParse(StringHandlers.CToString(twocharvalue), out day)) + if(!int.TryParse(StringHandlers.CToString(twocharvalue), out day)) day = 0; // day = Convert.ToInt32(StringHandlers.CToString(twocharvalue)); twocharvalue[0] = VDDateTime[8]; twocharvalue[1] = VDDateTime[9]; DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "hour = \"{0}\"", StringHandlers.CToString(twocharvalue)); - if(!Int32.TryParse(StringHandlers.CToString(twocharvalue), out hour)) + if(!int.TryParse(StringHandlers.CToString(twocharvalue), out hour)) hour = 0; // hour = Convert.ToInt32(StringHandlers.CToString(twocharvalue)); twocharvalue[0] = VDDateTime[10]; twocharvalue[1] = VDDateTime[11]; DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "minute = \"{0}\"", StringHandlers.CToString(twocharvalue)); - if(!Int32.TryParse(StringHandlers.CToString(twocharvalue), out minute)) + if(!int.TryParse(StringHandlers.CToString(twocharvalue), out minute)) minute = 0; // minute = Convert.ToInt32(StringHandlers.CToString(twocharvalue)); twocharvalue[0] = VDDateTime[12]; twocharvalue[1] = VDDateTime[13]; DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "second = \"{0}\"", StringHandlers.CToString(twocharvalue)); - if(!Int32.TryParse(StringHandlers.CToString(twocharvalue), out second)) + if(!int.TryParse(StringHandlers.CToString(twocharvalue), out second)) second = 0; // second = Convert.ToInt32(StringHandlers.CToString(twocharvalue)); twocharvalue[0] = VDDateTime[14]; twocharvalue[1] = VDDateTime[15]; DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "hundredths = \"{0}\"", StringHandlers.CToString(twocharvalue)); - if(!Int32.TryParse(StringHandlers.CToString(twocharvalue), out hundredths)) + if(!int.TryParse(StringHandlers.CToString(twocharvalue), out hundredths)) hundredths = 0; // hundredths = Convert.ToInt32(StringHandlers.CToString(twocharvalue)); @@ -128,13 +128,13 @@ public static DateTime ISO9660ToDateTime(byte[] VDDateTime) } // C# works in UTC, VMS on Julian Date, some displacement may occur on disks created outside UTC - public static DateTime VMSToDateTime(UInt64 vmsDate) + public static DateTime VMSToDateTime(ulong vmsDate) { double delta = vmsDate * 0.0001; // Tenths of microseconds to milliseconds, will lose some detail return JulianEpoch.AddMilliseconds(delta); } - public static DateTime AmigaToDateTime(UInt32 days, UInt32 minutes, UInt32 ticks) + public static DateTime AmigaToDateTime(uint days, uint minutes, uint ticks) { DateTime temp = AmigaEpoch.AddDays(days); temp = temp.AddMinutes(minutes); diff --git a/EndianAwareBinaryReader.cs b/EndianAwareBinaryReader.cs index 301b7e825..194802973 100644 --- a/EndianAwareBinaryReader.cs +++ b/EndianAwareBinaryReader.cs @@ -39,7 +39,7 @@ namespace DiscImageChef { public class EndianAwareBinaryReader : BinaryReader { - byte[] buffer = new byte[8]; + readonly byte[] buffer = new byte[8]; public EndianAwareBinaryReader(Stream input, Encoding encoding, bool isLittleEndian) : base(input, encoding) diff --git a/PrintHex.cs b/PrintHex.cs index 3d5a502e8..61898fd12 100644 --- a/PrintHex.cs +++ b/PrintHex.cs @@ -30,7 +30,6 @@ // Copyright © 2011-2016 Natalia Portillo // ****************************************************************************/ -using System; using DiscImageChef.Console; namespace DiscImageChef diff --git a/StringHandlers.cs b/StringHandlers.cs index 162376003..2e43fb5bb 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -1,42 +1,35 @@ -/*************************************************************************** -The Disc Image Chef ----------------------------------------------------------------------------- - -Filename : StringHandlers.cs -Version : 1.0 -Author(s) : Natalia Portillo - -Component : Program tools - -Revision : $Revision$ -Last change by : $Author$ -Date : $Date$ - ---[ Description ] ---------------------------------------------------------- - -Convert byte arrays to C# strings. - ---[ License ] -------------------------------------------------------------- - - This library is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 2.1 of the - License, or(at your option) any later version. - - This library is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, see . - ----------------------------------------------------------------------------- -Copyright (C) 2011-2014 Claunia.com -****************************************************************************/ -//$Id$ - -using System; +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : StringHandlers.cs +// Author(s) : Natalia Portillo +// +// Component : Helpers. +// +// --[ Description ] ---------------------------------------------------------- +// +// Convert byte arrays to C# strings. +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2016 Natalia Portillo +// ****************************************************************************/ + using System.Text; namespace DiscImageChef diff --git a/Swapping.cs b/Swapping.cs index 8a182c7de..b255c0274 100644 --- a/Swapping.cs +++ b/Swapping.cs @@ -30,8 +30,6 @@ // Copyright © 2011-2016 Natalia Portillo // ****************************************************************************/ -using System; - namespace DiscImageChef { public static class Swapping @@ -92,12 +90,12 @@ public static byte[] SwapTwoBytes(byte[] source) return destination; } - public static UInt32 PDPFromLittleEndian(UInt32 x) + public static uint PDPFromLittleEndian(uint x) { return ((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16); } - public static UInt32 PDPFromBigEndian(UInt32 x) + public static uint PDPFromBigEndian(uint x) { return ((x & 0xff00ff) << 8) | ((x & 0xff00ff00) >> 8); } From 4f91af4cd90136bd603c7ca9ad06edff8633e042 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 28 Jul 2016 23:08:22 +0100 Subject: [PATCH 011/217] Code re-styling. --- ChangeLog | 4 ++++ DiscImageChef.Helpers.csproj | 2 ++ 2 files changed, 6 insertions(+) diff --git a/ChangeLog b/ChangeLog index 4bce39523..b6f498cfe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2016-07-28 Natalia Portillo + + * DiscImageChef.Helpers.csproj: Code re-styling. + 2016-07-28 Natalia Portillo * Swapping.cs: diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index 70461eef6..0c87f71b7 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -60,6 +60,8 @@ + + From 8cb8e43dfa5b48d38e6f55c3fa2b605864ea6662 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Fri, 29 Jul 2016 02:25:29 +0100 Subject: [PATCH 012/217] Bump to version 3.1.0. --- ChangeLog | 4 ++++ DiscImageChef.Helpers.csproj | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index b6f498cfe..2dcf524ba 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2016-07-29 Natalia Portillo + + * DiscImageChef.Helpers.csproj: Bump to version 3.1.0. + 2016-07-28 Natalia Portillo * DiscImageChef.Helpers.csproj: Code re-styling. diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index 0c87f71b7..4f1a329ae 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -9,7 +9,7 @@ Library DiscImageChef.Helpers DiscImageChef.Helpers - 3.0.0 + 3.1.0 true From 333b1dce44d0754f42b3837555b3274f0c6de3ed Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 31 Jul 2016 20:56:53 +0100 Subject: [PATCH 013/217] Added support for U.C.S.D. Pascal filesystem, closes #31 --- ChangeLog | 5 +++++ DateHandlers.cs | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/ChangeLog b/ChangeLog index 2dcf524ba..a4aa678cf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-07-31 Natalia Portillo + + * DateHandlers.cs: Added support for U.C.S.D. Pascal + filesystem, closes #31 + 2016-07-29 Natalia Portillo * DiscImageChef.Helpers.csproj: Bump to version 3.1.0. diff --git a/DateHandlers.cs b/DateHandlers.cs index b80804f80..fef562475 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -140,6 +140,16 @@ public static DateTime AmigaToDateTime(uint days, uint minutes, uint ticks) temp = temp.AddMinutes(minutes); return temp.AddMilliseconds(ticks * 20); } + + public static DateTime UCSDPascalToDateTime(short dateRecord) + { + int year = ((dateRecord & 0xFE00) >> 9) + 1900; + int day = (dateRecord & 0x01F0) >> 4; + int month = (dateRecord & 0x000F); + + DicConsole.DebugWriteLine("UCSDPascalToDateTime handler", "dateRecord = 0x{0:X4}, year = {1}, month = {2}, day = {3}", dateRecord, year, month, day); + return new DateTime(year, month, day); + } } } From b74ddef4362d0cfcf7b66433c1a54365476a54e4 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 1 Aug 2016 19:01:21 +0100 Subject: [PATCH 014/217] Bump to version 3.2.0 --- ChangeLog | 5 +++++ DiscImageChef.Helpers.csproj | 2 +- Properties/AssemblyInfo.cs | 6 +++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index a4aa678cf..9db409b9a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-08-01 Natalia Portillo + + * AssemblyInfo.cs: + * DiscImageChef.Helpers.csproj: Bump to version 3.2.0 + 2016-07-31 Natalia Portillo * DateHandlers.cs: Added support for U.C.S.D. Pascal diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index 4f1a329ae..00f9e322a 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -9,7 +9,7 @@ Library DiscImageChef.Helpers DiscImageChef.Helpers - 3.1.0 + 3.2.0 true diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 0b0685491..1ce9b1c7c 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -5,11 +5,11 @@ // Change them to the values specific to your project. [assembly: AssemblyTitle("DiscImageChef.Helpers")] -[assembly: AssemblyDescription("")] +[assembly: AssemblyDescription("The Disc Image Chef")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Claunia.com")] [assembly: AssemblyProduct("")] -[assembly: AssemblyCopyright("© Claunia.com")] +[assembly: AssemblyCopyright("Copyright © 2011-2016 Natalia Portillo")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -17,7 +17,7 @@ // The form "{Major}.{Minor}.*" will automatically update the build and revision, // and "{Major}.{Minor}.{Build}.*" will update just the revision. -[assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("3.2.0.0")] // The following attributes are used to specify the signing key for the assembly, // if desired. See the Mono documentation for more information about signing. From 53477406f0d5bc820b5e4cd96eaa6bf9a91dc114 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 1 Aug 2016 19:07:04 +0100 Subject: [PATCH 015/217] Bumped to version 3.2.1. --- ChangeLog | 5 +++++ DiscImageChef.Helpers.csproj | 2 +- Properties/AssemblyInfo.cs | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9db409b9a..477776b34 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-08-01 Natalia Portillo + + * AssemblyInfo.cs: + * DiscImageChef.Helpers.csproj: Bumped to version 3.2.1. + 2016-08-01 Natalia Portillo * AssemblyInfo.cs: diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index 00f9e322a..784466b3d 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -9,7 +9,7 @@ Library DiscImageChef.Helpers DiscImageChef.Helpers - 3.2.0 + 3.2.1 true diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 1ce9b1c7c..c5812a9f3 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -17,7 +17,7 @@ // The form "{Major}.{Minor}.*" will automatically update the build and revision, // and "{Major}.{Minor}.{Build}.*" will update just the revision. -[assembly: AssemblyVersion("3.2.0.0")] +[assembly: AssemblyVersion("3.2.1.0")] // The following attributes are used to specify the signing key for the assembly, // if desired. See the Mono documentation for more information about signing. From a063ac04dc0d3cc3d9a1ecf77e7bad0b143f899c Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 7 Aug 2016 04:35:32 +0100 Subject: [PATCH 016/217] * README.md: * DiscImageChef.DiscImages/CopyQM.cs: * DiscImageChef.DiscImages/DiscImageChef.DiscImages.csproj: Added support for Sydex CopyQM disk image format. * DiscImageChef.CommonTypes/MediaType.cs: Corrected typo. * DiscImageChef.DiscImages/DiskCopy42.cs: Misplacement of XML media type setting. * DiscImageChef.Helpers/DateHandlers.cs: Added DOS to C# date converter. --- ChangeLog | 4 ++++ DateHandlers.cs | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/ChangeLog b/ChangeLog index 477776b34..8fb99fd03 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2016-08-07 Natalia Portillo + + * DateHandlers.cs: Added DOS to C# date converter. + 2016-08-01 Natalia Portillo * AssemblyInfo.cs: diff --git a/DateHandlers.cs b/DateHandlers.cs index fef562475..9ada51109 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -150,6 +150,20 @@ public static DateTime UCSDPascalToDateTime(short dateRecord) DicConsole.DebugWriteLine("UCSDPascalToDateTime handler", "dateRecord = 0x{0:X4}, year = {1}, month = {2}, day = {3}", dateRecord, year, month, day); return new DateTime(year, month, day); } + + 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 second = (time & 0x1F) * 2; + + DicConsole.DebugWriteLine("DOSToDateTime handler", "date = 0x{0:X4}, year = {1}, month = {2}, day = {3}", date, year, month, day); + DicConsole.DebugWriteLine("DOSToDateTime handler", "time = 0x{0:X4}, hour = {1}, minute = {2}, second = {3}", time, hour, minute, second); + return new DateTime(year, month, day, hour, minute, second); + } } } From 828e28a04e78d21f5aa076a133735eb5861c49c1 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 7 Aug 2016 04:38:07 +0100 Subject: [PATCH 017/217] Public beta release 3.2.99.1. --- ChangeLog | 4 ++++ DiscImageChef.Helpers.csproj | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 8fb99fd03..306a912f8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2016-08-07 Natalia Portillo + + * DiscImageChef.Helpers.csproj: Public beta release 3.2.99.1. + 2016-08-07 Natalia Portillo * DateHandlers.cs: Added DOS to C# date converter. diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index 784466b3d..eae4508ab 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -9,7 +9,7 @@ Library DiscImageChef.Helpers DiscImageChef.Helpers - 3.2.1 + 3.2.99.1 true From dbea12cc2c81b13aa3c0353db60bcd83c35fa53e Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 9 Aug 2016 15:34:26 +0100 Subject: [PATCH 018/217] Bumped version to 3.2.99.2. --- ChangeLog | 4 ++++ DiscImageChef.Helpers.csproj | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 306a912f8..3b9f5c686 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2016-08-09 Natalia Portillo + + * DiscImageChef.Helpers.csproj: Bumped version to 3.2.99.2. + 2016-08-07 Natalia Portillo * DiscImageChef.Helpers.csproj: Public beta release 3.2.99.1. diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index eae4508ab..bad2344d3 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -9,7 +9,7 @@ Library DiscImageChef.Helpers DiscImageChef.Helpers - 3.2.99.1 + 3.2.99.2 true From 2dc2107adee7e7e58709a9e3282c68b978075d7d Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 21 Aug 2016 08:27:43 +0100 Subject: [PATCH 019/217] * DiscImageChef.Helpers/BigEndianStructure.cs: * DiscImageChef.Helpers/DiscImageChef.Helpers.csproj: Added code that directly marshals from a big-endian byte array. But untested with nested structures. * DiscImageChef.Partitions/Acorn.cs: Added support for Acorn FileCore partition, closes #4. * DiscImageChef.Partitions/BSD.cs: Moved BSD partitions from inside MBR code to separate code, as they can (and do) appear on other architectures as the only scheme. * DiscImageChef.Partitions/DEC.cs: Added support for DEC disklabels, closes #11. * DiscImageChef.Partitions/DragonFlyBSD.cs: Added support for DragonFly BSD 64-bit disklabels. * DiscImageChef.Partitions/PC98.cs: Added support for NEC PC-9800 partitions. * DiscImageChef.Partitions/RioKarma.cs: Added support for Rio Karma partitions. * DiscImageChef.Partitions/SGI.cs: Added support for SGI DVHs, closes #9. * DiscImageChef.Partitions/UNIX.cs: Moved UNIX partitions from inside MBR code to separate code, as they can (and do) appear on other architectures as the only scheme. * TODO: * README.md: * DiscImageChef.Partitions/DiscImageChef.Partitions.csproj: Added support for Acorn FileCore partition, closes #4. Added support for DEC disklabels, closes #11. Added support for SGI DVHs, closes #9. Moved BSD partitions from inside MBR code to separate code, as they can (and do) appear on other architectures as the only scheme. Added support for DragonFly BSD 64-bit disklabels. Added support for NEC PC-9800 partitions. Added support for Rio Karma partitions. Moved UNIX partitions from inside MBR code to separate code, as they can (and do) appear on other architectures as the only scheme. * DiscImageChef.Partitions/GPT.cs: Added new partition type UUIDs. * DiscImageChef.Partitions/MBR.cs: Moved BSD partitions from inside MBR code to separate code, as they can (and do) appear on other architectures as the only scheme. Moved UNIX partitions from inside MBR code to separate code, as they can (and do) appear on other architectures as the only scheme. * DiscImageChef.Partitions/Sun.cs: Added new partition types. Prepare structures for marshaling. --- BigEndianStructure.cs | 118 +++++++++++++++++++++++++++++++++++ ChangeLog | 7 +++ DiscImageChef.Helpers.csproj | 1 + 3 files changed, 126 insertions(+) create mode 100644 BigEndianStructure.cs diff --git a/BigEndianStructure.cs b/BigEndianStructure.cs new file mode 100644 index 000000000..c15ca8daf --- /dev/null +++ b/BigEndianStructure.cs @@ -0,0 +1,118 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : EndianSwapStructure.cs +// Author(s) : Natalia Portillo +// +// Component : Component +// +// --[ Description ] ---------------------------------------------------------- +// +// Description +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2016 Natalia Portillo +// ****************************************************************************/ +using System; +using System.Linq; +using System.Reflection; +using System.Runtime.InteropServices; + +namespace DiscImageChef.Helpers +{ + public static class BigEndianStructure + { + // TODO: Check this works + /// + /// Marshals a big-endian byte array to a C# structure. Dunno if it works with nested structures. + /// + /// The big endian byte array. + /// Byte array. + /// C# structure type. + public static T ByteArrayToStructureBigEndian(byte[] bytes) where T : struct + { + GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned); + T stuff = (T)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(T)); + handle.Free(); + Type t = stuff.GetType(); + FieldInfo[] fieldInfo = t.GetFields(); + foreach(FieldInfo fi in fieldInfo) + { + if(fi.FieldType == typeof(short)) + { + short i16 = (short)fi.GetValue(stuff); + byte[] b16 = BitConverter.GetBytes(i16); + byte[] b16r = b16.Reverse().ToArray(); + fi.SetValueDirect(__makeref(stuff), BitConverter.ToInt16(b16r, 0)); + } + else if(fi.FieldType == typeof(int)) + { + int i32 = (int)fi.GetValue(stuff); + byte[] b32 = BitConverter.GetBytes(i32); + byte[] b32r = b32.Reverse().ToArray(); + fi.SetValueDirect(__makeref(stuff), BitConverter.ToInt32(b32r, 0)); + } + else if(fi.FieldType == typeof(long)) + { + long i64 = (long)fi.GetValue(stuff); + byte[] b64 = BitConverter.GetBytes(i64); + byte[] b64r = b64.Reverse().ToArray(); + fi.SetValueDirect(__makeref(stuff), BitConverter.ToInt64(b64r, 0)); + } + else if(fi.FieldType == typeof(ushort)) + { + ushort i16 = (ushort)fi.GetValue(stuff); + byte[] b16 = BitConverter.GetBytes(i16); + byte[] b16r = b16.Reverse().ToArray(); + fi.SetValueDirect(__makeref(stuff), BitConverter.ToUInt16(b16r, 0)); + } + else if(fi.FieldType == typeof(uint)) + { + uint i32 = (uint)fi.GetValue(stuff); + byte[] b32 = BitConverter.GetBytes(i32); + byte[] b32r = b32.Reverse().ToArray(); + fi.SetValueDirect(__makeref(stuff), BitConverter.ToUInt32(b32r, 0)); + } + else if(fi.FieldType == typeof(ulong)) + { + ulong i64 = (ulong)fi.GetValue(stuff); + byte[] b64 = BitConverter.GetBytes(i64); + byte[] b64r = b64.Reverse().ToArray(); + fi.SetValueDirect(__makeref(stuff), BitConverter.ToUInt64(b64r, 0)); + } + else if(fi.FieldType == typeof(float)) + { + float iflt = (float)fi.GetValue(stuff); + byte[] bflt = BitConverter.GetBytes(iflt); + byte[] bfltr = bflt.Reverse().ToArray(); + fi.SetValueDirect(__makeref(stuff), BitConverter.ToSingle(bfltr, 0)); + } + else if(fi.FieldType == typeof(double)) + { + double idbl = (double)fi.GetValue(stuff); + byte[] bdbl = BitConverter.GetBytes(idbl); + byte[] bdblr = bdbl.Reverse().ToArray(); + fi.SetValueDirect(__makeref(stuff), BitConverter.ToDouble(bdblr, 0)); + } + } + return stuff; + } + } +} + diff --git a/ChangeLog b/ChangeLog index 3b9f5c686..486a931fc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2016-08-21 Natalia Portillo + + * BigEndianStructure.cs: + * DiscImageChef.Helpers.csproj: Added code that directly + marshals from a big-endian byte array. But untested with + nested structures. + 2016-08-09 Natalia Portillo * DiscImageChef.Helpers.csproj: Bumped version to 3.2.99.2. diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index bad2344d3..f1d6aea1c 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -42,6 +42,7 @@ + From e2d84659feee9b1fb4165aa737cfdf4c09e595e0 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 22 Aug 2016 00:49:48 +0100 Subject: [PATCH 020/217] * DiscImageChef.Partitions/Human68k.cs: * DiscImageChef.Partitions/DiscImageChef.Partitions.csproj: Added Human68k partition table. * DiscImageChef.Partitions/RioKarma.cs: Corrected typo. * DiscImageChef.DiscImages/ZZZRawImage.cs: Detect X68000 SASI hard disks that use 256 bytes/sector. Correct size of ECMA-154 magnetoptical. * DiscImageChef.Partitions/PC98.cs: Correct handling of partition name, do not directly marshal as it may crash. Prevent false positives checking for sanity and partition type, so this limits it to FreeBSD right now. * DiscImageChef.Partitions/Acorn.cs: Do not try to read past device. * DiscImageChef.Helpers/BigEndianMarshal.cs: * DiscImageChef.Helpers/BigEndianStructure.cs: * DiscImageChef.Helpers/DiscImageChef.Helpers.csproj: Reworked big endian marshal. Does not traverse nested structures. * DiscImageChef.Partitions/SGI.cs: Corrected big endian marshaling, manually traversing nested structures. * DiscImageChef.Decoders/LisaTag.cs: Removed temporal variable. * DiscImageChef.Partitions/Sun.cs: Sun insists all devices must be 512 bytes/sector. Really. Even CDs. But this allows bigger ones. --- BigEndianMarshal.cs | 131 +++++++++++++++++++++++++++++++++++ BigEndianStructure.cs | 118 ------------------------------- ChangeLog | 7 ++ DiscImageChef.Helpers.csproj | 2 +- 4 files changed, 139 insertions(+), 119 deletions(-) create mode 100644 BigEndianMarshal.cs delete mode 100644 BigEndianStructure.cs diff --git a/BigEndianMarshal.cs b/BigEndianMarshal.cs new file mode 100644 index 000000000..3b6f72847 --- /dev/null +++ b/BigEndianMarshal.cs @@ -0,0 +1,131 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : BigEndianMarshal.cs +// Author(s) : Natalia Portillo +// +// Component : Component +// +// --[ Description ] ---------------------------------------------------------- +// +// Description +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2016 Natalia Portillo +// ****************************************************************************/ + +using System; +using System.Reflection; +using System.Runtime.InteropServices; +using System.Linq; + +namespace DiscImageChef +{ + public static class BigEndianMarshal + { + /// + /// Marshals a big endian structure from a byte array. + /// Nested structures are still marshalled as little endian. + /// + /// The structure. + /// Byte array. + /// Structure type. + public static T ByteArrayToStructureBigEndian(byte[] bytes) where T : struct + { + GCHandle ptr = GCHandle.Alloc(bytes, GCHandleType.Pinned); + T str = (T)Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(T)); + ptr.Free(); + return SwapStructureMembersEndian(str); + } + + /// + /// Swaps endian of structure members that correspond to numerical types. + /// Does not traverse nested structures. + /// + /// The structure with its members endian swapped. + /// The structure. + /// Structure type. + public static T SwapStructureMembersEndian(T str) where T : struct + { + Type t = str.GetType(); + FieldInfo[] fieldInfo = t.GetFields(); + foreach(FieldInfo fi in fieldInfo) + { + if(fi.FieldType == typeof(short)) + { + short int16 = (short)fi.GetValue(str); + byte[] int16_b = BitConverter.GetBytes(int16); + byte[] int16_r = int16_b.Reverse().ToArray(); + fi.SetValueDirect(__makeref(str), BitConverter.ToInt16(int16_r, 0)); + } + else if(fi.FieldType == typeof(int)) + { + int int32 = (int)fi.GetValue(str); + byte[] int32_b = BitConverter.GetBytes(int32); + byte[] int32_r = int32_b.Reverse().ToArray(); + fi.SetValueDirect(__makeref(str), BitConverter.ToInt32(int32_r, 0)); + } + else if(fi.FieldType == typeof(long)) + { + long int64 = (long)fi.GetValue(str); + byte[] int64_b = BitConverter.GetBytes(int64); + byte[] int64_r = int64_b.Reverse().ToArray(); + fi.SetValueDirect(__makeref(str), BitConverter.ToInt64(int64_r, 0)); + } + else if(fi.FieldType == typeof(ushort)) + { + ushort uint16 = (ushort)fi.GetValue(str); + byte[] uint16_b = BitConverter.GetBytes(uint16); + byte[] uint16_r = uint16_b.Reverse().ToArray(); + fi.SetValueDirect(__makeref(str), BitConverter.ToInt16(uint16_r, 0)); + } + else if(fi.FieldType == typeof(uint)) + { + uint uint32 = (uint)fi.GetValue(str); + byte[] uint32_b = BitConverter.GetBytes(uint32); + byte[] uint32_r = uint32_b.Reverse().ToArray(); + fi.SetValueDirect(__makeref(str), BitConverter.ToInt32(uint32_r, 0)); + } + else if(fi.FieldType == typeof(ulong)) + { + ulong uint64 = (ulong)fi.GetValue(str); + byte[] uint64_b = BitConverter.GetBytes(uint64); + byte[] uint64_r = uint64_b.Reverse().ToArray(); + fi.SetValueDirect(__makeref(str), BitConverter.ToInt64(uint64_r, 0)); + } + else if(fi.FieldType == typeof(float)) + { + float flt = (float)fi.GetValue(str); + byte[] flt_b = BitConverter.GetBytes(flt); + byte[] flt_r = flt_b.Reverse().ToArray(); + fi.SetValueDirect(__makeref(str), BitConverter.ToSingle(flt_r, 0)); + } + else if(fi.FieldType == typeof(double)) + { + double dbl = (double)fi.GetValue(str); + byte[] dbl_b = BitConverter.GetBytes(dbl); + byte[] dbl_r = dbl_b.Reverse().ToArray(); + fi.SetValueDirect(__makeref(str), BitConverter.ToDouble(dbl_r, 0)); + } + } + return str; + } + } +} + diff --git a/BigEndianStructure.cs b/BigEndianStructure.cs deleted file mode 100644 index c15ca8daf..000000000 --- a/BigEndianStructure.cs +++ /dev/null @@ -1,118 +0,0 @@ -// /*************************************************************************** -// The Disc Image Chef -// ---------------------------------------------------------------------------- -// -// Filename : EndianSwapStructure.cs -// Author(s) : Natalia Portillo -// -// Component : Component -// -// --[ Description ] ---------------------------------------------------------- -// -// Description -// -// --[ License ] -------------------------------------------------------------- -// -// This library is free software; you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 2.1 of the -// License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, see . -// -// ---------------------------------------------------------------------------- -// Copyright © 2011-2016 Natalia Portillo -// ****************************************************************************/ -using System; -using System.Linq; -using System.Reflection; -using System.Runtime.InteropServices; - -namespace DiscImageChef.Helpers -{ - public static class BigEndianStructure - { - // TODO: Check this works - /// - /// Marshals a big-endian byte array to a C# structure. Dunno if it works with nested structures. - /// - /// The big endian byte array. - /// Byte array. - /// C# structure type. - public static T ByteArrayToStructureBigEndian(byte[] bytes) where T : struct - { - GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned); - T stuff = (T)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(T)); - handle.Free(); - Type t = stuff.GetType(); - FieldInfo[] fieldInfo = t.GetFields(); - foreach(FieldInfo fi in fieldInfo) - { - if(fi.FieldType == typeof(short)) - { - short i16 = (short)fi.GetValue(stuff); - byte[] b16 = BitConverter.GetBytes(i16); - byte[] b16r = b16.Reverse().ToArray(); - fi.SetValueDirect(__makeref(stuff), BitConverter.ToInt16(b16r, 0)); - } - else if(fi.FieldType == typeof(int)) - { - int i32 = (int)fi.GetValue(stuff); - byte[] b32 = BitConverter.GetBytes(i32); - byte[] b32r = b32.Reverse().ToArray(); - fi.SetValueDirect(__makeref(stuff), BitConverter.ToInt32(b32r, 0)); - } - else if(fi.FieldType == typeof(long)) - { - long i64 = (long)fi.GetValue(stuff); - byte[] b64 = BitConverter.GetBytes(i64); - byte[] b64r = b64.Reverse().ToArray(); - fi.SetValueDirect(__makeref(stuff), BitConverter.ToInt64(b64r, 0)); - } - else if(fi.FieldType == typeof(ushort)) - { - ushort i16 = (ushort)fi.GetValue(stuff); - byte[] b16 = BitConverter.GetBytes(i16); - byte[] b16r = b16.Reverse().ToArray(); - fi.SetValueDirect(__makeref(stuff), BitConverter.ToUInt16(b16r, 0)); - } - else if(fi.FieldType == typeof(uint)) - { - uint i32 = (uint)fi.GetValue(stuff); - byte[] b32 = BitConverter.GetBytes(i32); - byte[] b32r = b32.Reverse().ToArray(); - fi.SetValueDirect(__makeref(stuff), BitConverter.ToUInt32(b32r, 0)); - } - else if(fi.FieldType == typeof(ulong)) - { - ulong i64 = (ulong)fi.GetValue(stuff); - byte[] b64 = BitConverter.GetBytes(i64); - byte[] b64r = b64.Reverse().ToArray(); - fi.SetValueDirect(__makeref(stuff), BitConverter.ToUInt64(b64r, 0)); - } - else if(fi.FieldType == typeof(float)) - { - float iflt = (float)fi.GetValue(stuff); - byte[] bflt = BitConverter.GetBytes(iflt); - byte[] bfltr = bflt.Reverse().ToArray(); - fi.SetValueDirect(__makeref(stuff), BitConverter.ToSingle(bfltr, 0)); - } - else if(fi.FieldType == typeof(double)) - { - double idbl = (double)fi.GetValue(stuff); - byte[] bdbl = BitConverter.GetBytes(idbl); - byte[] bdblr = bdbl.Reverse().ToArray(); - fi.SetValueDirect(__makeref(stuff), BitConverter.ToDouble(bdblr, 0)); - } - } - return stuff; - } - } -} - diff --git a/ChangeLog b/ChangeLog index 486a931fc..b50dcf8dc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2016-08-22 Natalia Portillo + + * BigEndianMarshal.cs: + * BigEndianStructure.cs: + * DiscImageChef.Helpers.csproj: Reworked big endian marshal. + Does not traverse nested structures. + 2016-08-21 Natalia Portillo * BigEndianStructure.cs: diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index f1d6aea1c..bdccdb876 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -42,7 +42,7 @@ - + From 251d59dc54e53ff0b3032cec3ff523c3423b67eb Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Fri, 26 Aug 2016 01:43:15 +0100 Subject: [PATCH 021/217] * DiscImageChef.Filesystems/UCSDPascal/Dir.cs: Typo. * DiscImageChef.Helpers/DateHandlers.cs: Added CP/M timestamp converter. * DiscImageChef.Partitions/Acorn.cs: Corrected handling of negative values. * DiscImageChef/Commands/ExtractFiles.cs: Corrected behaviour when volume name is missing, null or empty. * DiscImageChef.DiscImages/ImagePlugin.cs: Added floppy address mark sector tag. --- ChangeLog | 4 ++++ DateHandlers.cs | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/ChangeLog b/ChangeLog index b50dcf8dc..1112561b6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2016-08-26 Natalia Portillo + + * DateHandlers.cs: Added CP/M timestamp converter. + 2016-08-22 Natalia Portillo * BigEndianMarshal.cs: diff --git a/DateHandlers.cs b/DateHandlers.cs index 9ada51109..4cc02b68f 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -164,6 +164,19 @@ public static DateTime DOSToDateTime(ushort date, ushort time) DicConsole.DebugWriteLine("DOSToDateTime handler", "time = 0x{0:X4}, hour = {1}, minute = {2}, second = {3}", time, hour, minute, second); return new DateTime(year, month, day, hour, minute, second); } + + public static DateTime CPMToDateTime(byte[] timestamp) + { + ushort days = BitConverter.ToUInt16(timestamp, 0); + int hours = timestamp[2]; + int minutes = timestamp[3]; + + DateTime temp = AmigaEpoch.AddDays(days); + temp = temp.AddHours(hours); + temp = temp.AddMinutes(minutes); + + return temp; + } } } From 863a88acaa88d8ce816f57ceb6167a591f8304f9 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Fri, 2 Sep 2016 06:49:59 +0100 Subject: [PATCH 022/217] * TODO: * README.md: * DiscImageChef.Filesystems/JFS.cs: * DiscImageChef.Filesystems/DiscImageChef.Filesystems.csproj: Adds support for IBM JFS, closes #20. * DiscImageChef.Helpers/DateHandlers.cs: Add supports for UNIX timestamps divided in seconds+nanoseconds. --- ChangeLog | 5 +++++ DateHandlers.cs | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/ChangeLog b/ChangeLog index 1112561b6..4180fa755 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-09-02 Natalia Portillo + + * DateHandlers.cs: Add supports for UNIX timestamps divided in + seconds+nanoseconds. + 2016-08-26 Natalia Portillo * DateHandlers.cs: Added CP/M timestamp converter. diff --git a/DateHandlers.cs b/DateHandlers.cs index 4cc02b68f..6c1c563b3 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -64,6 +64,11 @@ public static DateTime UNIXUnsignedToDateTime(uint UNIXTimeStamp) return UNIXEpoch.AddSeconds(UNIXTimeStamp); } + public static DateTime UNIXUnsignedToDateTime(uint seconds, uint nanoseconds) + { + return UNIXEpoch.AddSeconds(seconds).AddTicks((long)nanoseconds / 100); + } + public static DateTime ISO9660ToDateTime(byte[] VDDateTime) { int year, month, day, hour, minute, second, hundredths; From 6318e37915e26848f74d955ba19e3aab8a23d535 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Fri, 2 Sep 2016 18:46:55 +0100 Subject: [PATCH 023/217] Adds support for NILFS2 filesystem. --- ChangeLog | 4 ++++ DateHandlers.cs | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/ChangeLog b/ChangeLog index 4180fa755..0374ccada 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2016-09-02 Natalia Portillo + + * DateHandlers.cs: Adds support for NILFS2 filesystem. + 2016-09-02 Natalia Portillo * DateHandlers.cs: Add supports for UNIX timestamps divided in diff --git a/DateHandlers.cs b/DateHandlers.cs index 6c1c563b3..da2f873af 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -59,6 +59,11 @@ public static DateTime UNIXToDateTime(int UNIXTimeStamp) return UNIXEpoch.AddSeconds(UNIXTimeStamp); } + public static DateTime UNIXToDateTime(long UNIXTimeStamp) + { + return UNIXEpoch.AddSeconds(UNIXTimeStamp); + } + public static DateTime UNIXUnsignedToDateTime(uint UNIXTimeStamp) { return UNIXEpoch.AddSeconds(UNIXTimeStamp); @@ -69,6 +74,11 @@ public static DateTime UNIXUnsignedToDateTime(uint seconds, uint nanoseconds) return UNIXEpoch.AddSeconds(seconds).AddTicks((long)nanoseconds / 100); } + public static DateTime UNIXUnsignedToDateTime(ulong UNIXTimeStamp) + { + return UNIXEpoch.AddSeconds(UNIXTimeStamp); + } + public static DateTime ISO9660ToDateTime(byte[] VDDateTime) { int year, month, day, hour, minute, second, hundredths; From 16fc38695febe634052eeb4b1d00b297501bc1a9 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 5 Sep 2016 21:22:04 +0100 Subject: [PATCH 024/217] * TODO: * README.md: * docs/AppleSingle_AppleDouble_v2.pdf: * docs/AppleSingle_AppleDouble_v1.pdf: * DiscImageChef.Filters/AppleSingle.cs: * DiscImageChef.Filters/AppleDouble.cs: * DiscImageChef.Helpers/DateHandlers.cs: * DiscImageChef.Filters/DiscImageChef.Filters.csproj: Added AppleSingle and AppleDouble filters. * DiscImageChef.DiscImages/CDRWin.cs: Show correct filename from filter. --- ChangeLog | 4 ++++ DateHandlers.cs | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/ChangeLog b/ChangeLog index 0374ccada..d688afe15 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2016-09-05 Natalia Portillo + + * DateHandlers.cs: Added AppleSingle and AppleDouble filters. + 2016-09-02 Natalia Portillo * DateHandlers.cs: Adds support for NILFS2 filesystem. diff --git a/DateHandlers.cs b/DateHandlers.cs index da2f873af..e634e713d 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -43,6 +43,7 @@ public static class DateHandlers // Day 0 of Julian Date system static readonly DateTime JulianEpoch = new DateTime(1858, 11, 17, 0, 0, 0); static readonly DateTime AmigaEpoch = new DateTime(1978, 1, 1, 0, 0, 0); + static readonly DateTime AppleDoubleEpoch = new DateTime(1970, 1, 1, 0, 0, 0); public static DateTime MacToDateTime(ulong MacTimeStamp) { @@ -192,6 +193,11 @@ public static DateTime CPMToDateTime(byte[] timestamp) return temp; } + + public static DateTime AppleDoubleToDateTime(ulong AppleDoubleTimeStamp) + { + return AppleDoubleEpoch.AddSeconds(AppleDoubleTimeStamp); + } } } From 140711b5b642d454fe3e0134ff5cb4c9fc5c93e0 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 15 Sep 2016 01:54:13 +0100 Subject: [PATCH 025/217] * DiscImageChef.Helpers/StringHandlers.cs: Adds support for OSTA Compressed Unicode. * DiscImageChef.Helpers/DateHandlers.cs: Adds support for timestamps in ECMA-167 format. --- DateHandlers.cs | 26 ++++++++++++++++++++++++++ StringHandlers.cs | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/DateHandlers.cs b/DateHandlers.cs index e634e713d..2a0e5fd5b 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -198,6 +198,32 @@ public static DateTime AppleDoubleToDateTime(ulong AppleDoubleTimeStamp) { return AppleDoubleEpoch.AddSeconds(AppleDoubleTimeStamp); } + + 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; + if(specification == 0) + return new DateTime(year, month, day, hour, minute, second, DateTimeKind.Utc).AddTicks(ticks); + + ushort preOffset = (ushort)(typeAndTimeZone & 0xFFF); + short offset; + + if((preOffset & 0x800) == 0x800) + { + offset = (short)(preOffset | 0xF000); + } + else + offset = (short)(preOffset & 0x7FF); + + if(offset == -2047) + return new DateTime(year, month, day, hour, minute, second, DateTimeKind.Unspecified).AddTicks(ticks); + + if(offset < -1440 || offset > 1440) + offset = 0; + + return new DateTimeOffset(year, month, day, hour, minute, second, new TimeSpan(0, offset, 0)).AddTicks(ticks).DateTime; + } } } diff --git a/StringHandlers.cs b/StringHandlers.cs index 2e43fb5bb..a17a2acbe 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -118,6 +118,40 @@ public static string SpacePaddedToString(byte[] SpacePaddedString) return length == 0 ? "" : Encoding.ASCII.GetString(SpacePaddedString, 0, length); } + + /// + /// Converts an OSTA compressed unicode byte array to a C# string + /// + /// The C# string. + /// OSTA compressed unicode byte array. + public static string DecompressUnicode(byte[] dstring) + { + ushort unicode; + 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; + + if(byteIndex < dstring.Length) + unicode |= dstring[byteIndex++]; + + if(unicode == 0) + break; + + temp += Encoding.Unicode.GetString(System.BitConverter.GetBytes(unicode)); + } + + return temp; + } + } } From f15c7958a4e4982eb328dc871005dd51664e86fe Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 18 Sep 2016 05:09:02 +0100 Subject: [PATCH 026/217] Added support for Sun's hrtime_t. --- DateHandlers.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/DateHandlers.cs b/DateHandlers.cs index 2a0e5fd5b..592c10f5a 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -224,6 +224,11 @@ public static DateTime ECMAToDateTime(ushort typeAndTimeZone, short year, byte m return new DateTimeOffset(year, month, day, hour, minute, second, new TimeSpan(0, offset, 0)).AddTicks(ticks).DateTime; } + + public static DateTime UNIXHrTimeToDateTime(ulong HRTimeStamp) + { + return UNIXEpoch.AddTicks((long)(HRTimeStamp / 100)); + } } } From adac1ea9dbd843e5e6d1391c04b004513828f688 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 21 Sep 2016 01:54:09 +0100 Subject: [PATCH 027/217] Add method to get hexadecimal printout of a byte array. --- ArrayFill.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ArrayFill.cs b/ArrayFill.cs index 7c6be86cb..772e36684 100644 --- a/ArrayFill.cs +++ b/ArrayFill.cs @@ -25,6 +25,7 @@ // ****************************************************************************/ using System; +using System.Text; namespace DiscImageChef { @@ -61,6 +62,20 @@ public static void ArrayFill(T[] destinationArray, T[] value) Array.Copy(destinationArray, 0, destinationArray, copyLength, destinationArray.Length - copyLength); } + + public static string ByteArrayToHex(byte[] array) + { + return ByteArrayToHex(array, false); + } + + public static string ByteArrayToHex(byte[] array, bool upper) + { + StringBuilder sb = new StringBuilder(); + for(long i = 0; i < array.LongLength; i++) + sb.AppendFormat("{0:x2}", array[i]); + + return upper ? sb.ToString().ToUpper() : sb.ToString(); + } } } From 35750083bc89d935f0aab1bfb7d2f4c2ee79b821 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 16 May 2017 08:26:38 +0100 Subject: [PATCH 028/217] Some changes made by VS/Mac, harmless. --- DiscImageChef.Helpers.csproj | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index bdccdb876..0d5e9223c 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -60,9 +60,18 @@ - - - + + + + + + + + + + + + From 7aef610cfde13e05ff6674dca5ff7477b93acb8d Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Fri, 19 May 2017 18:39:15 +0100 Subject: [PATCH 029/217] Upped version to 3.3.99.0. Do not use version from solution on library projects. --- ChangeLog | 5 +++++ DiscImageChef.Helpers.csproj | 18 +++++------------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index d688afe15..46d37eda2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2017-05-19 Natalia Portillo + + * DiscImageChef.Helpers.csproj: Upped version to 3.3.99.0. Do + not use version from solution on library projects. + 2016-09-05 Natalia Portillo * DateHandlers.cs: Added AppleSingle and AppleDouble filters. diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index 0d5e9223c..832c00a9f 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -9,7 +9,8 @@ Library DiscImageChef.Helpers DiscImageChef.Helpers - 3.2.99.2 + 3.3.99.0 + false true @@ -60,18 +61,9 @@ - - - - - - - - - - - - + + + From f8453cd06f3a2406cb2d28a543cc7bbf278cc308 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Fri, 19 May 2017 20:27:27 +0100 Subject: [PATCH 030/217] Bumped version to 3.3.99.0. --- ChangeLog | 4 ++++ Properties/AssemblyInfo.cs | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 46d37eda2..53e2fbea6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2017-05-19 Natalia Portillo + + * AssemblyInfo.cs: Bumped version to 3.3.99.0. + 2017-05-19 Natalia Portillo * DiscImageChef.Helpers.csproj: Upped version to 3.3.99.0. Do diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index c5812a9f3..c1be8a3a3 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -1,4 +1,4 @@ -using System.Reflection; +using System.Reflection; using System.Runtime.CompilerServices; // Information about this assembly is defined by the following attributes. @@ -17,7 +17,7 @@ // The form "{Major}.{Minor}.*" will automatically update the build and revision, // and "{Major}.{Minor}.{Build}.*" will update just the revision. -[assembly: AssemblyVersion("3.2.1.0")] +[assembly: AssemblyVersion("3.3.99.0")] // The following attributes are used to specify the signing key for the assembly, // if desired. See the Mono documentation for more information about signing. From f50ff31f0771f3aaa1b2621c82c0b6d353e44a9f Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Fri, 19 May 2017 20:28:49 +0100 Subject: [PATCH 031/217] Updated copyright string. --- ArrayFill.cs | 4 ++-- ArrayIsEmpty.cs | 4 ++-- BigEndianBitConverter.cs | 4 ++-- BigEndianMarshal.cs | 4 ++-- ChangeLog | 13 +++++++++++++ DateHandlers.cs | 2 +- EndianAwareBinaryReader.cs | 2 +- PrintHex.cs | 4 ++-- Properties/AssemblyInfo.cs | 2 +- StringHandlers.cs | 2 +- Swapping.cs | 2 +- 11 files changed, 28 insertions(+), 15 deletions(-) diff --git a/ArrayFill.cs b/ArrayFill.cs index 772e36684..e886d7c31 100644 --- a/ArrayFill.cs +++ b/ArrayFill.cs @@ -1,4 +1,4 @@ -// /*************************************************************************** +// /*************************************************************************** // The Disc Image Chef // ---------------------------------------------------------------------------- // @@ -20,7 +20,7 @@ // Assuming open source. // // ---------------------------------------------------------------------------- -// Copyright © 2011-2016 Natalia Portillo +// Copyright © 2011-2017 Natalia Portillo // Copyright(C) 2014 mykohsu // ****************************************************************************/ diff --git a/ArrayIsEmpty.cs b/ArrayIsEmpty.cs index 8e5375ad6..a6faa4a13 100644 --- a/ArrayIsEmpty.cs +++ b/ArrayIsEmpty.cs @@ -1,4 +1,4 @@ -// /*************************************************************************** +// /*************************************************************************** // The Disc Image Chef // ---------------------------------------------------------------------------- // @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2016 Natalia Portillo +// Copyright © 2011-2017 Natalia Portillo // ****************************************************************************/ namespace DiscImageChef diff --git a/BigEndianBitConverter.cs b/BigEndianBitConverter.cs index 17ecfbf6d..80e27d048 100644 --- a/BigEndianBitConverter.cs +++ b/BigEndianBitConverter.cs @@ -1,4 +1,4 @@ -// /*************************************************************************** +// /*************************************************************************** // The Disc Image Chef // ---------------------------------------------------------------------------- // @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2016 Natalia Portillo +// Copyright © 2011-2017 Natalia Portillo // ****************************************************************************/ using System; diff --git a/BigEndianMarshal.cs b/BigEndianMarshal.cs index 3b6f72847..d51c17984 100644 --- a/BigEndianMarshal.cs +++ b/BigEndianMarshal.cs @@ -1,4 +1,4 @@ -// /*************************************************************************** +// /*************************************************************************** // The Disc Image Chef // ---------------------------------------------------------------------------- // @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2016 Natalia Portillo +// Copyright © 2011-2017 Natalia Portillo // ****************************************************************************/ using System; diff --git a/ChangeLog b/ChangeLog index 53e2fbea6..5762b8d53 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2017-05-19 Natalia Portillo + + * Swapping.cs: + * PrintHex.cs: + * ArrayFill.cs: + * ArrayIsEmpty.cs: + * DateHandlers.cs: + * StringHandlers.cs: + * BigEndianMarshal.cs: + * BigEndianBitConverter.cs: + * AssemblyInfo.cs: + * EndianAwareBinaryReader.cs: Updated copyright string. + 2017-05-19 Natalia Portillo * AssemblyInfo.cs: Bumped version to 3.3.99.0. diff --git a/DateHandlers.cs b/DateHandlers.cs index 592c10f5a..ce27ce59c 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2016 Natalia Portillo +// Copyright © 2011-2017 Natalia Portillo // ****************************************************************************/ using System; diff --git a/EndianAwareBinaryReader.cs b/EndianAwareBinaryReader.cs index 194802973..cebd581ef 100644 --- a/EndianAwareBinaryReader.cs +++ b/EndianAwareBinaryReader.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2016 Natalia Portillo +// Copyright © 2011-2017 Natalia Portillo // ****************************************************************************/ using System; diff --git a/PrintHex.cs b/PrintHex.cs index 61898fd12..af01d99bb 100644 --- a/PrintHex.cs +++ b/PrintHex.cs @@ -1,4 +1,4 @@ -// /*************************************************************************** +// /*************************************************************************** // The Disc Image Chef // ---------------------------------------------------------------------------- // @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2016 Natalia Portillo +// Copyright © 2011-2017 Natalia Portillo // ****************************************************************************/ using DiscImageChef.Console; diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index c1be8a3a3..07739d456 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -9,7 +9,7 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Claunia.com")] [assembly: AssemblyProduct("")] -[assembly: AssemblyCopyright("Copyright © 2011-2016 Natalia Portillo")] +[assembly: AssemblyCopyright("Copyright © 2011-2017 Natalia Portillo")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] diff --git a/StringHandlers.cs b/StringHandlers.cs index a17a2acbe..70033b457 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2016 Natalia Portillo +// Copyright © 2011-2017 Natalia Portillo // ****************************************************************************/ using System.Text; diff --git a/Swapping.cs b/Swapping.cs index b255c0274..50588c5fa 100644 --- a/Swapping.cs +++ b/Swapping.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2016 Natalia Portillo +// Copyright © 2011-2017 Natalia Portillo // ****************************************************************************/ namespace DiscImageChef From e0fbb3ea42a02ce897a39afbead138d02345d0ac Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sat, 27 May 2017 18:20:27 +0100 Subject: [PATCH 032/217] Refactor: Moved CompareBytes to Helpers. --- ChangeLog | 6 ++++ CompareBytes.cs | 66 ++++++++++++++++++++++++++++++++++++ DiscImageChef.Helpers.csproj | 1 + 3 files changed, 73 insertions(+) create mode 100644 CompareBytes.cs diff --git a/ChangeLog b/ChangeLog index 5762b8d53..5234cf643 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2017-05-27 Natalia Portillo + + * CompareBytes.cs: + * DiscImageChef.Helpers.csproj: Refactor: Moved CompareBytes + to Helpers. + 2017-05-19 Natalia Portillo * Swapping.cs: diff --git a/CompareBytes.cs b/CompareBytes.cs new file mode 100644 index 000000000..74413d86a --- /dev/null +++ b/CompareBytes.cs @@ -0,0 +1,66 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : CompareBytes.cs +// Author(s) : Natalia Portillo +// +// Component : Component +// +// --[ Description ] ---------------------------------------------------------- +// +// Description +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2017 Natalia Portillo +// ****************************************************************************/ + +namespace DiscImageChef +{ + public static partial class ArrayHelpers + { + public static void CompareBytes(out bool different, out bool sameSize, byte[] compareArray1, byte[] compareArray2) + { + different = false; + sameSize = true; + + long leastBytes; + if(compareArray1.LongLength < compareArray2.LongLength) + { + sameSize = false; + leastBytes = compareArray1.LongLength; + } + else if(compareArray1.LongLength > compareArray2.LongLength) + { + sameSize = false; + leastBytes = compareArray2.LongLength; + } + else + leastBytes = compareArray1.LongLength; + + for(long i = 0; i < leastBytes; i++) + { + if(compareArray1[i] != compareArray2[i]) + { + different = true; + return; + } + } + } + } +} diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index 832c00a9f..13ee39b32 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -44,6 +44,7 @@ + From ff392f2109fdb76b6f373e1b9004103bd4b9c88a Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sat, 3 Jun 2017 01:13:47 +0100 Subject: [PATCH 033/217] Project file formatting. --- DiscImageChef.Helpers.csproj | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index 13ee39b32..038f95d8c 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -62,9 +62,18 @@ - - - + + + + + + + + + + + + From a7184159a2f8fa6f493d04ff533c8ac71e86da83 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 4 Jun 2017 23:09:27 +0100 Subject: [PATCH 034/217] Version bumped to 3.4.99.0. --- DiscImageChef.Helpers.csproj | 2 +- Properties/AssemblyInfo.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index 038f95d8c..b20970cb1 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -9,7 +9,7 @@ Library DiscImageChef.Helpers DiscImageChef.Helpers - 3.3.99.0 + 3.4.99.0 false diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 07739d456..a10709ab0 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -1,4 +1,4 @@ -using System.Reflection; +using System.Reflection; using System.Runtime.CompilerServices; // Information about this assembly is defined by the following attributes. @@ -17,7 +17,7 @@ // The form "{Major}.{Minor}.*" will automatically update the build and revision, // and "{Major}.{Minor}.{Build}.*" will update just the revision. -[assembly: AssemblyVersion("3.3.99.0")] +[assembly: AssemblyVersion("3.4.99.0")] // The following attributes are used to specify the signing key for the assembly, // if desired. See the Mono documentation for more information about signing. From ff9408d18193b9cf811c98a4478a398d6a06966f Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 6 Jun 2017 21:23:20 +0100 Subject: [PATCH 035/217] Added support for different character encodings. --- DateHandlers.cs | 43 ++++++++++++++++++++++--------------------- StringHandlers.cs | 26 ++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 23 deletions(-) diff --git a/DateHandlers.cs b/DateHandlers.cs index ce27ce59c..8d90eda67 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -32,6 +32,7 @@ using System; using DiscImageChef.Console; +using System.Text; namespace DiscImageChef { @@ -90,52 +91,52 @@ public static DateTime ISO9660ToDateTime(byte[] VDDateTime) fourcharvalue[1] = VDDateTime[1]; fourcharvalue[2] = VDDateTime[2]; fourcharvalue[3] = VDDateTime[3]; - DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "year = \"{0}\"", StringHandlers.CToString(fourcharvalue)); - if(!int.TryParse(StringHandlers.CToString(fourcharvalue), out year)) + DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "year = \"{0}\"", StringHandlers.CToString(fourcharvalue, Encoding.ASCII)); + if(!int.TryParse(StringHandlers.CToString(fourcharvalue, Encoding.ASCII), out year)) year = 0; - // year = Convert.ToInt32(StringHandlers.CToString(fourcharvalue)); + // year = Convert.ToInt32(StringHandlers.CToString(fourcharvalue, Encoding.ASCII)); twocharvalue[0] = VDDateTime[4]; twocharvalue[1] = VDDateTime[5]; - DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "month = \"{0}\"", StringHandlers.CToString(twocharvalue)); - if(!int.TryParse(StringHandlers.CToString(twocharvalue), out month)) + DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "month = \"{0}\"", StringHandlers.CToString(twocharvalue, Encoding.ASCII)); + if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out month)) month = 0; - // month = Convert.ToInt32(StringHandlers.CToString(twocharvalue)); + // month = Convert.ToInt32(StringHandlers.CToString(twocharvalue, Encoding.ASCII)); twocharvalue[0] = VDDateTime[6]; twocharvalue[1] = VDDateTime[7]; - DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "day = \"{0}\"", StringHandlers.CToString(twocharvalue)); - if(!int.TryParse(StringHandlers.CToString(twocharvalue), out day)) + DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "day = \"{0}\"", StringHandlers.CToString(twocharvalue, Encoding.ASCII)); + if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out day)) day = 0; - // day = Convert.ToInt32(StringHandlers.CToString(twocharvalue)); + // day = Convert.ToInt32(StringHandlers.CToString(twocharvalue, Encoding.ASCII)); twocharvalue[0] = VDDateTime[8]; twocharvalue[1] = VDDateTime[9]; - DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "hour = \"{0}\"", StringHandlers.CToString(twocharvalue)); - if(!int.TryParse(StringHandlers.CToString(twocharvalue), out hour)) + DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "hour = \"{0}\"", StringHandlers.CToString(twocharvalue, Encoding.ASCII)); + if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out hour)) hour = 0; - // hour = Convert.ToInt32(StringHandlers.CToString(twocharvalue)); + // hour = Convert.ToInt32(StringHandlers.CToString(twocharvalue, Encoding.ASCII)); twocharvalue[0] = VDDateTime[10]; twocharvalue[1] = VDDateTime[11]; - DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "minute = \"{0}\"", StringHandlers.CToString(twocharvalue)); - if(!int.TryParse(StringHandlers.CToString(twocharvalue), out minute)) + DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "minute = \"{0}\"", StringHandlers.CToString(twocharvalue, Encoding.ASCII)); + if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out minute)) minute = 0; - // minute = Convert.ToInt32(StringHandlers.CToString(twocharvalue)); + // minute = Convert.ToInt32(StringHandlers.CToString(twocharvalue, Encoding.ASCII)); twocharvalue[0] = VDDateTime[12]; twocharvalue[1] = VDDateTime[13]; - DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "second = \"{0}\"", StringHandlers.CToString(twocharvalue)); - if(!int.TryParse(StringHandlers.CToString(twocharvalue), out second)) + DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "second = \"{0}\"", StringHandlers.CToString(twocharvalue, Encoding.ASCII)); + if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out second)) second = 0; - // second = Convert.ToInt32(StringHandlers.CToString(twocharvalue)); + // second = Convert.ToInt32(StringHandlers.CToString(twocharvalue, Encoding.ASCII)); twocharvalue[0] = VDDateTime[14]; twocharvalue[1] = VDDateTime[15]; - DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "hundredths = \"{0}\"", StringHandlers.CToString(twocharvalue)); - if(!int.TryParse(StringHandlers.CToString(twocharvalue), out hundredths)) + DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "hundredths = \"{0}\"", StringHandlers.CToString(twocharvalue, Encoding.ASCII)); + if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out hundredths)) hundredths = 0; - // hundredths = Convert.ToInt32(StringHandlers.CToString(twocharvalue)); + // hundredths = Convert.ToInt32(StringHandlers.CToString(twocharvalue, Encoding.ASCII)); DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "decodedDT = new DateTime({0}, {1}, {2}, {3}, {4}, {5}, {6}, DateTimeKind.Unspecified);", year, month, day, hour, minute, second, hundredths * 10); DateTime decodedDT = new DateTime(year, month, day, hour, minute, second, hundredths * 10, DateTimeKind.Unspecified); diff --git a/StringHandlers.cs b/StringHandlers.cs index 70033b457..e0a8c18e5 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -76,6 +76,17 @@ public static string CToString(byte[] CString, Encoding encoding) /// The corresponding C# string /// A length-prefixed (aka Pascal string) ASCII byte array public static string PascalToString(byte[] PascalString) + { + return PascalToString(PascalString, Encoding.ASCII); + } + + /// + /// Converts a length-prefixed (aka Pascal string) ASCII byte array to a C# string + /// + /// The corresponding C# string + /// A length-prefixed (aka Pascal string) ASCII byte array + /// Encoding. + public static string PascalToString(byte[] PascalString, Encoding encoding) { if(PascalString == null) return null; @@ -86,7 +97,7 @@ public static string PascalToString(byte[] PascalString) for(int i = 1; i < length + 1; i++) { - sb.Append(Encoding.ASCII.GetString(PascalString, i, 1)); + sb.Append(encoding.GetString(PascalString, i, 1)); } return sb.ToString(); @@ -98,6 +109,17 @@ public static string PascalToString(byte[] PascalString) /// The corresponding C# string /// A space (' ', 0x20, ASCII SPACE) padded ASCII byte array public static string SpacePaddedToString(byte[] SpacePaddedString) + { + return SpacePaddedToString(SpacePaddedString, Encoding.ASCII); + } + + /// + /// Converts a space (' ', 0x20, ASCII SPACE) padded ASCII byte array to a C# string + /// + /// The corresponding C# string + /// A space (' ', 0x20, ASCII SPACE) padded ASCII byte array + /// Encoding. + public static string SpacePaddedToString(byte[] SpacePaddedString, Encoding encoding) { if(SpacePaddedString == null) return null; @@ -116,7 +138,7 @@ public static string SpacePaddedToString(byte[] SpacePaddedString) } } - return length == 0 ? "" : Encoding.ASCII.GetString(SpacePaddedString, 0, length); + return length == 0 ? "" : encoding.GetString(SpacePaddedString, 0, length); } /// From b8b99343e4e1062085c602b4f75582b56c29d323 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 6 Jun 2017 21:38:30 +0100 Subject: [PATCH 036/217] Change conversion algorithm to behave correctly with multibyte encodings. --- StringHandlers.cs | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/StringHandlers.cs b/StringHandlers.cs index e0a8c18e5..d7673784d 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -31,6 +31,7 @@ // ****************************************************************************/ using System.Text; +using System; namespace DiscImageChef { @@ -57,17 +58,20 @@ public static string CToString(byte[] CString, Encoding encoding) if(CString == null) return null; - StringBuilder sb = new StringBuilder(); + int len = 0; for(int i = 0; i < CString.Length; i++) { if(CString[i] == 0) break; - sb.Append(encoding.GetString(CString, i, 1)); + len++; } - return sb.ToString(); + byte[] dest = new byte[len]; + Array.Copy(CString, 0, dest, 0, len); + + return len == 0 ? "" : encoding.GetString(dest); } /// @@ -91,16 +95,21 @@ public static string PascalToString(byte[] PascalString, Encoding encoding) if(PascalString == null) return null; - StringBuilder sb = new StringBuilder(); - byte length = PascalString[0]; + int len = 0; - for(int i = 1; i < length + 1; i++) + for(int i = 1; i < length + 1 && i < PascalString.Length; i++) { - sb.Append(encoding.GetString(PascalString, i, 1)); + if(PascalString[i] == 0) + break; + + len++; } - return sb.ToString(); + byte[] dest = new byte[len]; + Array.Copy(PascalString, 1, dest, 0, len); + + return len == 0 ? "" : encoding.GetString(dest); } /// @@ -124,7 +133,7 @@ public static string SpacePaddedToString(byte[] SpacePaddedString, Encoding enco if(SpacePaddedString == null) return null; - int length = 0; + int len = 0; for(int i = SpacePaddedString.Length; i >= 0; i--) { @@ -133,12 +142,12 @@ public static string SpacePaddedToString(byte[] SpacePaddedString, Encoding enco if(SpacePaddedString[i - 1] != 0x20) { - length = i; + len = i; break; } } - return length == 0 ? "" : encoding.GetString(SpacePaddedString, 0, length); + return len == 0 ? "" : encoding.GetString(SpacePaddedString, 0, len); } /// @@ -173,7 +182,6 @@ public static string DecompressUnicode(byte[] dstring) return temp; } - } } From 8e639f379a1c0371439da490a9bba5979d122a02 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 8 Jun 2017 18:41:41 +0100 Subject: [PATCH 037/217] Added helpers for extents. --- DiscImageChef.Helpers.csproj | 13 ++- Extents/ExtentsByte.cs | 200 +++++++++++++++++++++++++++++++++++ Extents/ExtentsInt.cs | 200 +++++++++++++++++++++++++++++++++++ Extents/ExtentsLong.cs | 200 +++++++++++++++++++++++++++++++++++ Extents/ExtentsSByte.cs | 200 +++++++++++++++++++++++++++++++++++ Extents/ExtentsShort.cs | 200 +++++++++++++++++++++++++++++++++++ Extents/ExtentsUInt.cs | 200 +++++++++++++++++++++++++++++++++++ Extents/ExtentsULong.cs | 200 +++++++++++++++++++++++++++++++++++ Extents/ExtentsUShort.cs | 200 +++++++++++++++++++++++++++++++++++ 9 files changed, 1612 insertions(+), 1 deletion(-) create mode 100644 Extents/ExtentsByte.cs create mode 100644 Extents/ExtentsInt.cs create mode 100644 Extents/ExtentsLong.cs create mode 100644 Extents/ExtentsSByte.cs create mode 100644 Extents/ExtentsShort.cs create mode 100644 Extents/ExtentsUInt.cs create mode 100644 Extents/ExtentsULong.cs create mode 100644 Extents/ExtentsUShort.cs diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index b20970cb1..7f2ebf4a0 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -45,6 +45,14 @@ + + + + + + + + @@ -58,6 +66,9 @@ LICENSE.LGPL + + + @@ -70,7 +81,7 @@ - + diff --git a/Extents/ExtentsByte.cs b/Extents/ExtentsByte.cs new file mode 100644 index 000000000..f5e0dd5ff --- /dev/null +++ b/Extents/ExtentsByte.cs @@ -0,0 +1,200 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : ExtentsByte.cs +// Author(s) : Natalia Portillo +// +// Component : Component +// +// --[ Description ] ---------------------------------------------------------- +// +// Description +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2017 Natalia Portillo +// ****************************************************************************/ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Extents +{ + public class ExtentsByte + { + List> backend; + + public ExtentsByte() + { + backend = new List>(); + } + + public int Count { get { return backend.Count; } } + + public void Add(byte item) + { + Tuple removeOne = null; + Tuple removeTwo = null; + Tuple itemToAdd = null; + + for(int i = 0; i < backend.Count; i++) + { + // Already contained in an extent + if(item >= backend[i].Item1 && item <= backend[i].Item2) + return; + + // Expands existing extent start + if(item == backend[i].Item1 - 1) + { + removeOne = backend[i]; + + if(i > 0 && item == backend[i - 1].Item2 + 1) + { + removeTwo = backend[i - 1]; + itemToAdd = new Tuple(backend[i - 1].Item1, backend[i].Item2); + } + else + itemToAdd = new Tuple(item, backend[i].Item2); + + break; + } + + // Expands existing extent end + if(item == backend[i].Item2 + 1) + { + removeOne = backend[i]; + + if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) + { + removeTwo = backend[i + 1]; + itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); + } + else + itemToAdd = new Tuple(backend[i].Item1, item); + + break; + } + } + + if(itemToAdd != null) + { + backend.Remove(removeOne); + backend.Remove(removeTwo); + backend.Add(itemToAdd); + } + else + backend.Add(new Tuple(item, item)); + + // Sort + backend = backend.OrderBy(t => t.Item1).ToList(); + } + + public void Add(byte start, byte end) + { + Add(start, end, false); + } + + public void Add(byte start, byte end, bool run) + { + byte realEnd; + if(run) + realEnd = (byte)(start + end - 1); + else + realEnd = end; + + // TODO: Optimize this + for(byte t = start; t <= realEnd; t++) + Add(t); + } + + public bool Contains(byte item) + { + foreach(Tuple extent in backend) + if(item >= extent.Item1 && item <= extent.Item2) + return true; + return false; + } + + public void Clear() + { + backend.Clear(); + } + + public bool Remove(byte item) + { + Tuple toRemove = null; + Tuple toAddOne = null; + Tuple toAddTwo = null; + + foreach(Tuple extent in backend) + { + // Extent is contained and not a border + if(item > extent.Item1 && item < extent.Item2) + { + toRemove = extent; + toAddOne = new Tuple(extent.Item1, (byte)(item - 1)); + toAddTwo = new Tuple((byte)(item + 1), extent.Item2); + break; + } + + // Extent is left border, but not only element + if(item == extent.Item1 && item != extent.Item2) + { + toRemove = extent; + toAddOne = new Tuple((byte)(item + 1), extent.Item2); + break; + } + + // Extent is right border, but not only element + if(item != extent.Item1 && item == extent.Item2) + { + toRemove = extent; + toAddOne = new Tuple(extent.Item1, (byte)(item - 1)); + break; + } + + // Extent is only element + if(item == extent.Item1 && item == extent.Item2) + { + toRemove = extent; + break; + } + } + + // Item not found + if(toRemove == null) + return false; + + backend.Remove(toRemove); + if(toAddOne != null) + backend.Add(toAddOne); + if(toAddTwo != null) + backend.Add(toAddTwo); + + // Sort + backend = backend.OrderBy(t => t.Item1).ToList(); + + return true; + } + + public Tuple[] ToArray() + { + return backend.ToArray(); + } + } +} diff --git a/Extents/ExtentsInt.cs b/Extents/ExtentsInt.cs new file mode 100644 index 000000000..096aa5f1d --- /dev/null +++ b/Extents/ExtentsInt.cs @@ -0,0 +1,200 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : ExtentsInt.cs +// Author(s) : Natalia Portillo +// +// Component : Component +// +// --[ Description ] ---------------------------------------------------------- +// +// Description +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License aint with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2017 Natalia Portillo +// ****************************************************************************/ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Extents +{ + public class ExtentsInt + { + List> backend; + + public ExtentsInt() + { + backend = new List>(); + } + + public int Count { get { return backend.Count; } } + + public void Add(int item) + { + Tuple removeOne = null; + Tuple removeTwo = null; + Tuple itemToAdd = null; + + for(int i = 0; i < backend.Count; i++) + { + // Already contained in an extent + if(item >= backend[i].Item1 && item <= backend[i].Item2) + return; + + // Expands existing extent start + if(item == backend[i].Item1 - 1) + { + removeOne = backend[i]; + + if(i > 0 && item == backend[i - 1].Item2 + 1) + { + removeTwo = backend[i - 1]; + itemToAdd = new Tuple(backend[i - 1].Item1, backend[i].Item2); + } + else + itemToAdd = new Tuple(item, backend[i].Item2); + + break; + } + + // Expands existing extent end + if(item == backend[i].Item2 + 1) + { + removeOne = backend[i]; + + if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) + { + removeTwo = backend[i + 1]; + itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); + } + else + itemToAdd = new Tuple(backend[i].Item1, item); + + break; + } + } + + if(itemToAdd != null) + { + backend.Remove(removeOne); + backend.Remove(removeTwo); + backend.Add(itemToAdd); + } + else + backend.Add(new Tuple(item, item)); + + // Sort + backend = backend.OrderBy(t => t.Item1).ToList(); + } + + public void Add(int start, int end) + { + Add(start, end, false); + } + + public void Add(int start, int end, bool run) + { + int realEnd; + if(run) + realEnd = start + end - 1; + else + realEnd = end; + + // TODO: Optimize this + for(int t = start; t <= realEnd; t++) + Add(t); + } + + public bool Contains(int item) + { + foreach(Tuple extent in backend) + if(item >= extent.Item1 && item <= extent.Item2) + return true; + return false; + } + + public void Clear() + { + backend.Clear(); + } + + public bool Remove(int item) + { + Tuple toRemove = null; + Tuple toAddOne = null; + Tuple toAddTwo = null; + + foreach(Tuple extent in backend) + { + // Extent is contained and not a border + if(item > extent.Item1 && item < extent.Item2) + { + toRemove = extent; + toAddOne = new Tuple(extent.Item1, item - 1); + toAddTwo = new Tuple(item + 1, extent.Item2); + break; + } + + // Extent is left border, but not only element + if(item == extent.Item1 && item != extent.Item2) + { + toRemove = extent; + toAddOne = new Tuple(item + 1, extent.Item2); + break; + } + + // Extent is right border, but not only element + if(item != extent.Item1 && item == extent.Item2) + { + toRemove = extent; + toAddOne = new Tuple(extent.Item1, item - 1); + break; + } + + // Extent is only element + if(item == extent.Item1 && item == extent.Item2) + { + toRemove = extent; + break; + } + } + + // Item not found + if(toRemove == null) + return false; + + backend.Remove(toRemove); + if(toAddOne != null) + backend.Add(toAddOne); + if(toAddTwo != null) + backend.Add(toAddTwo); + + // Sort + backend = backend.OrderBy(t => t.Item1).ToList(); + + return true; + } + + public Tuple[] ToArray() + { + return backend.ToArray(); + } + } +} diff --git a/Extents/ExtentsLong.cs b/Extents/ExtentsLong.cs new file mode 100644 index 000000000..dde1c4dc2 --- /dev/null +++ b/Extents/ExtentsLong.cs @@ -0,0 +1,200 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : ExtentsLong.cs +// Author(s) : Natalia Portillo +// +// Component : Component +// +// --[ Description ] ---------------------------------------------------------- +// +// Description +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2017 Natalia Portillo +// ****************************************************************************/ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Extents +{ + public class ExtentsLong + { + List> backend; + + public ExtentsLong() + { + backend = new List>(); + } + + public int Count { get { return backend.Count; } } + + public void Add(long item) + { + Tuple removeOne = null; + Tuple removeTwo = null; + Tuple itemToAdd = null; + + for(int i = 0; i < backend.Count; i++) + { + // Already contained in an extent + if(item >= backend[i].Item1 && item <= backend[i].Item2) + return; + + // Expands existing extent start + if(item == backend[i].Item1 - 1) + { + removeOne = backend[i]; + + if(i > 0 && item == backend[i - 1].Item2 + 1) + { + removeTwo = backend[i - 1]; + itemToAdd = new Tuple(backend[i - 1].Item1, backend[i].Item2); + } + else + itemToAdd = new Tuple(item, backend[i].Item2); + + break; + } + + // Expands existing extent end + if(item == backend[i].Item2 + 1) + { + removeOne = backend[i]; + + if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) + { + removeTwo = backend[i + 1]; + itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); + } + else + itemToAdd = new Tuple(backend[i].Item1, item); + + break; + } + } + + if(itemToAdd != null) + { + backend.Remove(removeOne); + backend.Remove(removeTwo); + backend.Add(itemToAdd); + } + else + backend.Add(new Tuple(item, item)); + + // Sort + backend = backend.OrderBy(t => t.Item1).ToList(); + } + + public void Add(long start, long end) + { + Add(start, end, false); + } + + public void Add(long start, long end, bool run) + { + long realEnd; + if(run) + realEnd = start + end - 1; + else + realEnd = end; + + // TODO: Optimize this + for(long t = start; t <= realEnd; t++) + Add(t); + } + + public bool Contains(long item) + { + foreach(Tuple extent in backend) + if(item >= extent.Item1 && item <= extent.Item2) + return true; + return false; + } + + public void Clear() + { + backend.Clear(); + } + + public bool Remove(long item) + { + Tuple toRemove = null; + Tuple toAddOne = null; + Tuple toAddTwo = null; + + foreach(Tuple extent in backend) + { + // Extent is contained and not a border + if(item > extent.Item1 && item < extent.Item2) + { + toRemove = extent; + toAddOne = new Tuple(extent.Item1, item - 1); + toAddTwo = new Tuple(item + 1, extent.Item2); + break; + } + + // Extent is left border, but not only element + if(item == extent.Item1 && item != extent.Item2) + { + toRemove = extent; + toAddOne = new Tuple(item + 1, extent.Item2); + break; + } + + // Extent is right border, but not only element + if(item != extent.Item1 && item == extent.Item2) + { + toRemove = extent; + toAddOne = new Tuple(extent.Item1, item - 1); + break; + } + + // Extent is only element + if(item == extent.Item1 && item == extent.Item2) + { + toRemove = extent; + break; + } + } + + // Item not found + if(toRemove == null) + return false; + + backend.Remove(toRemove); + if(toAddOne != null) + backend.Add(toAddOne); + if(toAddTwo != null) + backend.Add(toAddTwo); + + // Sort + backend = backend.OrderBy(t => t.Item1).ToList(); + + return true; + } + + public Tuple[] ToArray() + { + return backend.ToArray(); + } + } +} diff --git a/Extents/ExtentsSByte.cs b/Extents/ExtentsSByte.cs new file mode 100644 index 000000000..ec1c06083 --- /dev/null +++ b/Extents/ExtentsSByte.cs @@ -0,0 +1,200 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : ExtentsSByte.cs +// Author(s) : Natalia Portillo +// +// Component : Component +// +// --[ Description ] ---------------------------------------------------------- +// +// Description +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2017 Natalia Portillo +// ****************************************************************************/ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Extents +{ + public class ExtentsSByte + { + List> backend; + + public ExtentsSByte() + { + backend = new List>(); + } + + public int Count { get { return backend.Count; } } + + public void Add(sbyte item) + { + Tuple removeOne = null; + Tuple removeTwo = null; + Tuple itemToAdd = null; + + for(int i = 0; i < backend.Count; i++) + { + // Already contained in an extent + if(item >= backend[i].Item1 && item <= backend[i].Item2) + return; + + // Expands existing extent start + if(item == backend[i].Item1 - 1) + { + removeOne = backend[i]; + + if(i > 0 && item == backend[i - 1].Item2 + 1) + { + removeTwo = backend[i - 1]; + itemToAdd = new Tuple(backend[i - 1].Item1, backend[i].Item2); + } + else + itemToAdd = new Tuple(item, backend[i].Item2); + + break; + } + + // Expands existing extent end + if(item == backend[i].Item2 + 1) + { + removeOne = backend[i]; + + if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) + { + removeTwo = backend[i + 1]; + itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); + } + else + itemToAdd = new Tuple(backend[i].Item1, item); + + break; + } + } + + if(itemToAdd != null) + { + backend.Remove(removeOne); + backend.Remove(removeTwo); + backend.Add(itemToAdd); + } + else + backend.Add(new Tuple(item, item)); + + // Sort + backend = backend.OrderBy(t => t.Item1).ToList(); + } + + public void Add(sbyte start, sbyte end) + { + Add(start, end, false); + } + + public void Add(sbyte start, sbyte end, bool run) + { + sbyte realEnd; + if(run) + realEnd = (sbyte)(start + end - 1); + else + realEnd = end; + + // TODO: Optimize this + for(sbyte t = start; t <= realEnd; t++) + Add(t); + } + + public bool Contains(sbyte item) + { + foreach(Tuple extent in backend) + if(item >= extent.Item1 && item <= extent.Item2) + return true; + return false; + } + + public void Clear() + { + backend.Clear(); + } + + public bool Remove(sbyte item) + { + Tuple toRemove = null; + Tuple toAddOne = null; + Tuple toAddTwo = null; + + foreach(Tuple extent in backend) + { + // Extent is contained and not a border + if(item > extent.Item1 && item < extent.Item2) + { + toRemove = extent; + toAddOne = new Tuple(extent.Item1, (sbyte)(item - 1)); + toAddTwo = new Tuple((sbyte)(item + 1), extent.Item2); + break; + } + + // Extent is left border, but not only element + if(item == extent.Item1 && item != extent.Item2) + { + toRemove = extent; + toAddOne = new Tuple((sbyte)(item + 1), extent.Item2); + break; + } + + // Extent is right border, but not only element + if(item != extent.Item1 && item == extent.Item2) + { + toRemove = extent; + toAddOne = new Tuple(extent.Item1, (sbyte)(item - 1)); + break; + } + + // Extent is only element + if(item == extent.Item1 && item == extent.Item2) + { + toRemove = extent; + break; + } + } + + // Item not found + if(toRemove == null) + return false; + + backend.Remove(toRemove); + if(toAddOne != null) + backend.Add(toAddOne); + if(toAddTwo != null) + backend.Add(toAddTwo); + + // Sort + backend = backend.OrderBy(t => t.Item1).ToList(); + + return true; + } + + public Tuple[] ToArray() + { + return backend.ToArray(); + } + } +} diff --git a/Extents/ExtentsShort.cs b/Extents/ExtentsShort.cs new file mode 100644 index 000000000..70f9c7e78 --- /dev/null +++ b/Extents/ExtentsShort.cs @@ -0,0 +1,200 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : ExtentsShort.cs +// Author(s) : Natalia Portillo +// +// Component : Component +// +// --[ Description ] ---------------------------------------------------------- +// +// Description +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License ashort with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2017 Natalia Portillo +// ****************************************************************************/ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Extents +{ + public class ExtentsShort + { + List> backend; + + public ExtentsShort() + { + backend = new List>(); + } + + public int Count { get { return backend.Count; } } + + public void Add(short item) + { + Tuple removeOne = null; + Tuple removeTwo = null; + Tuple itemToAdd = null; + + for(int i = 0; i < backend.Count; i++) + { + // Already contained in an extent + if(item >= backend[i].Item1 && item <= backend[i].Item2) + return; + + // Expands existing extent start + if(item == backend[i].Item1 - 1) + { + removeOne = backend[i]; + + if(i > 0 && item == backend[i - 1].Item2 + 1) + { + removeTwo = backend[i - 1]; + itemToAdd = new Tuple(backend[i - 1].Item1, backend[i].Item2); + } + else + itemToAdd = new Tuple(item, backend[i].Item2); + + break; + } + + // Expands existing extent end + if(item == backend[i].Item2 + 1) + { + removeOne = backend[i]; + + if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) + { + removeTwo = backend[i + 1]; + itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); + } + else + itemToAdd = new Tuple(backend[i].Item1, item); + + break; + } + } + + if(itemToAdd != null) + { + backend.Remove(removeOne); + backend.Remove(removeTwo); + backend.Add(itemToAdd); + } + else + backend.Add(new Tuple(item, item)); + + // Sort + backend = backend.OrderBy(t => t.Item1).ToList(); + } + + public void Add(short start, short end) + { + Add(start, end, false); + } + + public void Add(short start, short end, bool run) + { + short realEnd; + if(run) + realEnd = (short)(start + end - 1); + else + realEnd = end; + + // TODO: Optimize this + for(short t = start; t <= realEnd; t++) + Add(t); + } + + public bool Contains(short item) + { + foreach(Tuple extent in backend) + if(item >= extent.Item1 && item <= extent.Item2) + return true; + return false; + } + + public void Clear() + { + backend.Clear(); + } + + public bool Remove(short item) + { + Tuple toRemove = null; + Tuple toAddOne = null; + Tuple toAddTwo = null; + + foreach(Tuple extent in backend) + { + // Extent is contained and not a border + if(item > extent.Item1 && item < extent.Item2) + { + toRemove = extent; + toAddOne = new Tuple(extent.Item1, (short)(item - 1)); + toAddTwo = new Tuple((short)(item + 1), extent.Item2); + break; + } + + // Extent is left border, but not only element + if(item == extent.Item1 && item != extent.Item2) + { + toRemove = extent; + toAddOne = new Tuple((short)(item + 1), extent.Item2); + break; + } + + // Extent is right border, but not only element + if(item != extent.Item1 && item == extent.Item2) + { + toRemove = extent; + toAddOne = new Tuple(extent.Item1, (short)(item - 1)); + break; + } + + // Extent is only element + if(item == extent.Item1 && item == extent.Item2) + { + toRemove = extent; + break; + } + } + + // Item not found + if(toRemove == null) + return false; + + backend.Remove(toRemove); + if(toAddOne != null) + backend.Add(toAddOne); + if(toAddTwo != null) + backend.Add(toAddTwo); + + // Sort + backend = backend.OrderBy(t => t.Item1).ToList(); + + return true; + } + + public Tuple[] ToArray() + { + return backend.ToArray(); + } + } +} diff --git a/Extents/ExtentsUInt.cs b/Extents/ExtentsUInt.cs new file mode 100644 index 000000000..a91ef9ad1 --- /dev/null +++ b/Extents/ExtentsUInt.cs @@ -0,0 +1,200 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : ExtentsUInt.cs +// Author(s) : Natalia Portillo +// +// Component : Component +// +// --[ Description ] ---------------------------------------------------------- +// +// Description +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License auint with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2017 Natalia Portillo +// ****************************************************************************/ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Extents +{ + public class ExtentsUInt + { + List> backend; + + public ExtentsUInt() + { + backend = new List>(); + } + + public int Count { get { return backend.Count; } } + + public void Add(uint item) + { + Tuple removeOne = null; + Tuple removeTwo = null; + Tuple itemToAdd = null; + + for(int i = 0; i < backend.Count; i++) + { + // Already contained in an extent + if(item >= backend[i].Item1 && item <= backend[i].Item2) + return; + + // Expands existing extent start + if(item == backend[i].Item1 - 1) + { + removeOne = backend[i]; + + if(i > 0 && item == backend[i - 1].Item2 + 1) + { + removeTwo = backend[i - 1]; + itemToAdd = new Tuple(backend[i - 1].Item1, backend[i].Item2); + } + else + itemToAdd = new Tuple(item, backend[i].Item2); + + break; + } + + // Expands existing extent end + if(item == backend[i].Item2 + 1) + { + removeOne = backend[i]; + + if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) + { + removeTwo = backend[i + 1]; + itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); + } + else + itemToAdd = new Tuple(backend[i].Item1, item); + + break; + } + } + + if(itemToAdd != null) + { + backend.Remove(removeOne); + backend.Remove(removeTwo); + backend.Add(itemToAdd); + } + else + backend.Add(new Tuple(item, item)); + + // Sort + backend = backend.OrderBy(t => t.Item1).ToList(); + } + + public void Add(uint start, uint end) + { + Add(start, end, false); + } + + public void Add(uint start, uint end, bool run) + { + uint realEnd; + if(run) + realEnd = start + end - 1; + else + realEnd = end; + + // TODO: Optimize this + for(uint t = start; t <= realEnd; t++) + Add(t); + } + + public bool Contains(uint item) + { + foreach(Tuple extent in backend) + if(item >= extent.Item1 && item <= extent.Item2) + return true; + return false; + } + + public void Clear() + { + backend.Clear(); + } + + public bool Remove(uint item) + { + Tuple toRemove = null; + Tuple toAddOne = null; + Tuple toAddTwo = null; + + foreach(Tuple extent in backend) + { + // Extent is contained and not a border + if(item > extent.Item1 && item < extent.Item2) + { + toRemove = extent; + toAddOne = new Tuple(extent.Item1, item - 1); + toAddTwo = new Tuple(item + 1, extent.Item2); + break; + } + + // Extent is left border, but not only element + if(item == extent.Item1 && item != extent.Item2) + { + toRemove = extent; + toAddOne = new Tuple(item + 1, extent.Item2); + break; + } + + // Extent is right border, but not only element + if(item != extent.Item1 && item == extent.Item2) + { + toRemove = extent; + toAddOne = new Tuple(extent.Item1, item - 1); + break; + } + + // Extent is only element + if(item == extent.Item1 && item == extent.Item2) + { + toRemove = extent; + break; + } + } + + // Item not found + if(toRemove == null) + return false; + + backend.Remove(toRemove); + if(toAddOne != null) + backend.Add(toAddOne); + if(toAddTwo != null) + backend.Add(toAddTwo); + + // Sort + backend = backend.OrderBy(t => t.Item1).ToList(); + + return true; + } + + public Tuple[] ToArray() + { + return backend.ToArray(); + } + } +} diff --git a/Extents/ExtentsULong.cs b/Extents/ExtentsULong.cs new file mode 100644 index 000000000..95d0051da --- /dev/null +++ b/Extents/ExtentsULong.cs @@ -0,0 +1,200 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : ExtentsULong.cs +// Author(s) : Natalia Portillo +// +// Component : Component +// +// --[ Description ] ---------------------------------------------------------- +// +// Description +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License aulong with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2017 Natalia Portillo +// ****************************************************************************/ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Extents +{ + public class ExtentsULong + { + List> backend; + + public ExtentsULong() + { + backend = new List>(); + } + + public int Count { get { return backend.Count; } } + + public void Add(ulong item) + { + Tuple removeOne = null; + Tuple removeTwo = null; + Tuple itemToAdd = null; + + for(int i = 0; i < backend.Count; i++) + { + // Already contained in an extent + if(item >= backend[i].Item1 && item <= backend[i].Item2) + return; + + // Expands existing extent start + if(item == backend[i].Item1 - 1) + { + removeOne = backend[i]; + + if(i > 0 && item == backend[i - 1].Item2 + 1) + { + removeTwo = backend[i - 1]; + itemToAdd = new Tuple(backend[i - 1].Item1, backend[i].Item2); + } + else + itemToAdd = new Tuple(item, backend[i].Item2); + + break; + } + + // Expands existing extent end + if(item == backend[i].Item2 + 1) + { + removeOne = backend[i]; + + if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) + { + removeTwo = backend[i + 1]; + itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); + } + else + itemToAdd = new Tuple(backend[i].Item1, item); + + break; + } + } + + if(itemToAdd != null) + { + backend.Remove(removeOne); + backend.Remove(removeTwo); + backend.Add(itemToAdd); + } + else + backend.Add(new Tuple(item, item)); + + // Sort + backend = backend.OrderBy(t => t.Item1).ToList(); + } + + public void Add(ulong start, ulong end) + { + Add(start, end, false); + } + + public void Add(ulong start, ulong end, bool run) + { + ulong realEnd; + if(run) + realEnd = start + end - 1; + else + realEnd = end; + + // TODO: Optimize this + for(ulong t = start; t <= realEnd; t++) + Add(t); + } + + public bool Contains(ulong item) + { + foreach(Tuple extent in backend) + if(item >= extent.Item1 && item <= extent.Item2) + return true; + return false; + } + + public void Clear() + { + backend.Clear(); + } + + public bool Remove(ulong item) + { + Tuple toRemove = null; + Tuple toAddOne = null; + Tuple toAddTwo = null; + + foreach(Tuple extent in backend) + { + // Extent is contained and not a border + if(item > extent.Item1 && item < extent.Item2) + { + toRemove = extent; + toAddOne = new Tuple(extent.Item1, item - 1); + toAddTwo = new Tuple(item + 1, extent.Item2); + break; + } + + // Extent is left border, but not only element + if(item == extent.Item1 && item != extent.Item2) + { + toRemove = extent; + toAddOne = new Tuple(item + 1, extent.Item2); + break; + } + + // Extent is right border, but not only element + if(item != extent.Item1 && item == extent.Item2) + { + toRemove = extent; + toAddOne = new Tuple(extent.Item1, item - 1); + break; + } + + // Extent is only element + if(item == extent.Item1 && item == extent.Item2) + { + toRemove = extent; + break; + } + } + + // Item not found + if(toRemove == null) + return false; + + backend.Remove(toRemove); + if(toAddOne != null) + backend.Add(toAddOne); + if(toAddTwo != null) + backend.Add(toAddTwo); + + // Sort + backend = backend.OrderBy(t => t.Item1).ToList(); + + return true; + } + + public Tuple[] ToArray() + { + return backend.ToArray(); + } + } +} diff --git a/Extents/ExtentsUShort.cs b/Extents/ExtentsUShort.cs new file mode 100644 index 000000000..3950aaa3c --- /dev/null +++ b/Extents/ExtentsUShort.cs @@ -0,0 +1,200 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : ExtentsUShort.cs +// Author(s) : Natalia Portillo +// +// Component : Component +// +// --[ Description ] ---------------------------------------------------------- +// +// Description +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License aushort with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2017 Natalia Portillo +// ****************************************************************************/ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Extents +{ + public class ExtentsUShort + { + List> backend; + + public ExtentsUShort() + { + backend = new List>(); + } + + public int Count { get { return backend.Count; } } + + public void Add(ushort item) + { + Tuple removeOne = null; + Tuple removeTwo = null; + Tuple itemToAdd = null; + + for(int i = 0; i < backend.Count; i++) + { + // Already contained in an extent + if(item >= backend[i].Item1 && item <= backend[i].Item2) + return; + + // Expands existing extent start + if(item == backend[i].Item1 - 1) + { + removeOne = backend[i]; + + if(i > 0 && item == backend[i - 1].Item2 + 1) + { + removeTwo = backend[i - 1]; + itemToAdd = new Tuple(backend[i - 1].Item1, backend[i].Item2); + } + else + itemToAdd = new Tuple(item, backend[i].Item2); + + break; + } + + // Expands existing extent end + if(item == backend[i].Item2 + 1) + { + removeOne = backend[i]; + + if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) + { + removeTwo = backend[i + 1]; + itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); + } + else + itemToAdd = new Tuple(backend[i].Item1, item); + + break; + } + } + + if(itemToAdd != null) + { + backend.Remove(removeOne); + backend.Remove(removeTwo); + backend.Add(itemToAdd); + } + else + backend.Add(new Tuple(item, item)); + + // Sort + backend = backend.OrderBy(t => t.Item1).ToList(); + } + + public void Add(ushort start, ushort end) + { + Add(start, end, false); + } + + public void Add(ushort start, ushort end, bool run) + { + ushort realEnd; + if(run) + realEnd = (ushort)(start + end - 1); + else + realEnd = end; + + // TODO: Optimize this + for(ushort t = start; t <= realEnd; t++) + Add(t); + } + + public bool Contains(ushort item) + { + foreach(Tuple extent in backend) + if(item >= extent.Item1 && item <= extent.Item2) + return true; + return false; + } + + public void Clear() + { + backend.Clear(); + } + + public bool Remove(ushort item) + { + Tuple toRemove = null; + Tuple toAddOne = null; + Tuple toAddTwo = null; + + foreach(Tuple extent in backend) + { + // Extent is contained and not a border + if(item > extent.Item1 && item < extent.Item2) + { + toRemove = extent; + toAddOne = new Tuple(extent.Item1, (ushort)(item - 1)); + toAddTwo = new Tuple((ushort)(item + 1), extent.Item2); + break; + } + + // Extent is left border, but not only element + if(item == extent.Item1 && item != extent.Item2) + { + toRemove = extent; + toAddOne = new Tuple((ushort)(item + 1), extent.Item2); + break; + } + + // Extent is right border, but not only element + if(item != extent.Item1 && item == extent.Item2) + { + toRemove = extent; + toAddOne = new Tuple(extent.Item1, (ushort)(item - 1)); + break; + } + + // Extent is only element + if(item == extent.Item1 && item == extent.Item2) + { + toRemove = extent; + break; + } + } + + // Item not found + if(toRemove == null) + return false; + + backend.Remove(toRemove); + if(toAddOne != null) + backend.Add(toAddOne); + if(toAddTwo != null) + backend.Add(toAddTwo); + + // Sort + backend = backend.OrderBy(t => t.Item1).ToList(); + + return true; + } + + public Tuple[] ToArray() + { + return backend.ToArray(); + } + } +} From 4a285dd623fb04cd72a5c12d901fa6e11a55a055 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 8 Jun 2017 19:05:35 +0100 Subject: [PATCH 038/217] Added constructors from List. --- Extents/ExtentsByte.cs | 5 +++++ Extents/ExtentsInt.cs | 5 +++++ Extents/ExtentsLong.cs | 5 +++++ Extents/ExtentsSByte.cs | 5 +++++ Extents/ExtentsShort.cs | 5 +++++ Extents/ExtentsUInt.cs | 5 +++++ Extents/ExtentsULong.cs | 5 +++++ Extents/ExtentsUShort.cs | 5 +++++ 8 files changed, 40 insertions(+) diff --git a/Extents/ExtentsByte.cs b/Extents/ExtentsByte.cs index f5e0dd5ff..2e6717a9e 100644 --- a/Extents/ExtentsByte.cs +++ b/Extents/ExtentsByte.cs @@ -44,6 +44,11 @@ public ExtentsByte() backend = new List>(); } + public ExtentsByte(List> list) + { + backend = list.OrderBy(t => t.Item1).ToList(); + } + public int Count { get { return backend.Count; } } public void Add(byte item) diff --git a/Extents/ExtentsInt.cs b/Extents/ExtentsInt.cs index 096aa5f1d..91604f116 100644 --- a/Extents/ExtentsInt.cs +++ b/Extents/ExtentsInt.cs @@ -44,6 +44,11 @@ public ExtentsInt() backend = new List>(); } + public ExtentsInt(List> list) + { + backend = list.OrderBy(t => t.Item1).ToList(); + } + public int Count { get { return backend.Count; } } public void Add(int item) diff --git a/Extents/ExtentsLong.cs b/Extents/ExtentsLong.cs index dde1c4dc2..11e1c7f03 100644 --- a/Extents/ExtentsLong.cs +++ b/Extents/ExtentsLong.cs @@ -44,6 +44,11 @@ public ExtentsLong() backend = new List>(); } + public ExtentsLong(List> list) + { + backend = list.OrderBy(t => t.Item1).ToList(); + } + public int Count { get { return backend.Count; } } public void Add(long item) diff --git a/Extents/ExtentsSByte.cs b/Extents/ExtentsSByte.cs index ec1c06083..bfc07ac9e 100644 --- a/Extents/ExtentsSByte.cs +++ b/Extents/ExtentsSByte.cs @@ -44,6 +44,11 @@ public ExtentsSByte() backend = new List>(); } + public ExtentsSByte(List> list) + { + backend = list.OrderBy(t => t.Item1).ToList(); + } + public int Count { get { return backend.Count; } } public void Add(sbyte item) diff --git a/Extents/ExtentsShort.cs b/Extents/ExtentsShort.cs index 70f9c7e78..f508ace86 100644 --- a/Extents/ExtentsShort.cs +++ b/Extents/ExtentsShort.cs @@ -44,6 +44,11 @@ public ExtentsShort() backend = new List>(); } + public ExtentsShort(List> list) + { + backend = list.OrderBy(t => t.Item1).ToList(); + } + public int Count { get { return backend.Count; } } public void Add(short item) diff --git a/Extents/ExtentsUInt.cs b/Extents/ExtentsUInt.cs index a91ef9ad1..3d0988da9 100644 --- a/Extents/ExtentsUInt.cs +++ b/Extents/ExtentsUInt.cs @@ -44,6 +44,11 @@ public ExtentsUInt() backend = new List>(); } + public ExtentsUInt(List> list) + { + backend = list.OrderBy(t => t.Item1).ToList(); + } + public int Count { get { return backend.Count; } } public void Add(uint item) diff --git a/Extents/ExtentsULong.cs b/Extents/ExtentsULong.cs index 95d0051da..c9f457060 100644 --- a/Extents/ExtentsULong.cs +++ b/Extents/ExtentsULong.cs @@ -44,6 +44,11 @@ public ExtentsULong() backend = new List>(); } + public ExtentsULong(List> list) + { + backend = list.OrderBy(t => t.Item1).ToList(); + } + public int Count { get { return backend.Count; } } public void Add(ulong item) diff --git a/Extents/ExtentsUShort.cs b/Extents/ExtentsUShort.cs index 3950aaa3c..9f7da19bc 100644 --- a/Extents/ExtentsUShort.cs +++ b/Extents/ExtentsUShort.cs @@ -44,6 +44,11 @@ public ExtentsUShort() backend = new List>(); } + public ExtentsUShort(List> list) + { + backend = list.OrderBy(t => t.Item1).ToList(); + } + public int Count { get { return backend.Count; } } public void Add(ushort item) From ea11109716ed2f73acbea5b1b59ae5189232b178 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 29 Jun 2017 21:23:39 +0100 Subject: [PATCH 039/217] Formatting options. --- DiscImageChef.Helpers.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index 7f2ebf4a0..e62b1117e 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -81,7 +81,7 @@ - + From f19f3ffda35cb6efabafac965e528e4f0e04ed37 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 10 Jul 2017 21:36:43 +0100 Subject: [PATCH 040/217] Changed tests to reflect correct values. --- CountBits.cs | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 CountBits.cs diff --git a/CountBits.cs b/CountBits.cs new file mode 100644 index 000000000..cf228966b --- /dev/null +++ b/CountBits.cs @@ -0,0 +1,41 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : CountBits.cs +// Author(s) : Natalia Portillo +// +// Component : Component +// +// --[ Description ] ---------------------------------------------------------- +// +// Description +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2017 Natalia Portillo +// ****************************************************************************/ +using System; +namespace DiscImageChef.Helpers +{ + public class CountBits + { + public CountBits() + { + } + } +} From 7f776a194020d2856a2be3eb219a7424777a9612 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 10 Jul 2017 21:37:19 +0100 Subject: [PATCH 041/217] Added helper to count bits from uint. --- CountBits.cs | 7 +++++-- DiscImageChef.Helpers.csproj | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CountBits.cs b/CountBits.cs index cf228966b..d8313ff19 100644 --- a/CountBits.cs +++ b/CountBits.cs @@ -32,10 +32,13 @@ using System; namespace DiscImageChef.Helpers { - public class CountBits + public static class CountBits { - public CountBits() + public static int Count(uint number) { + number = number - ((number >> 1) & 0x55555555); + number = (number & 0x33333333) + ((number >> 2) & 0x33333333); + return (int)((((number + (number >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24); } } } diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index e62b1117e..78c4a7bb4 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -53,6 +53,7 @@ + From 8c9939e0b76e97a13e566cc41739ba322f773475 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 11 Jul 2017 02:32:40 +0100 Subject: [PATCH 042/217] Added support for UTF-16 and other two-byte encodings. --- StringHandlers.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/StringHandlers.cs b/StringHandlers.cs index d7673784d..51102d9ab 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -53,7 +53,7 @@ public static string CToString(byte[] CString) /// The corresponding C# string /// A null-terminated (aka C string) byte array in the specified encoding /// Encoding. - public static string CToString(byte[] CString, Encoding encoding) + public static string CToString(byte[] CString, Encoding encoding, bool twoBytes = false) { if(CString == null) return null; @@ -63,7 +63,20 @@ public static string CToString(byte[] CString, Encoding encoding) for(int i = 0; i < CString.Length; i++) { if(CString[i] == 0) - break; + { + if(twoBytes) + { + if((i + 1) < CString.Length && CString[i + 1] == 0) + { + len++; + break; + } + // if((i + 1) == CString.Length) +// break; + } + else + break; + } len++; } From ae7416466957e54ad08163761265e849aaa33c22 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sat, 15 Jul 2017 01:29:26 +0100 Subject: [PATCH 043/217] Added swappers for reference values. --- Swapping.cs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/Swapping.cs b/Swapping.cs index 50588c5fa..88de46905 100644 --- a/Swapping.cs +++ b/Swapping.cs @@ -29,6 +29,8 @@ // ---------------------------------------------------------------------------- // Copyright © 2011-2017 Natalia Portillo // ****************************************************************************/ +using System; +using System.Linq; namespace DiscImageChef { @@ -99,5 +101,40 @@ public static uint PDPFromBigEndian(uint x) { return ((x & 0xff00ff) << 8) | ((x & 0xff00ff00) >> 8); } + + public static ulong Swap(ulong x) + { + x = (x & 0x00000000FFFFFFFF) << 32 | (x & 0xFFFFFFFF00000000) >> 32; + x = (x & 0x0000FFFF0000FFFF) << 16 | (x & 0xFFFF0000FFFF0000) >> 16; + x = (x & 0x00FF00FF00FF00FF) << 8 | (x & 0xFF00FF00FF00FF00) >> 8; + return x; + } + + public static long Swap(long x) + { + return BitConverter.ToInt64(BitConverter.GetBytes(x).Reverse().ToArray(), 0); + } + + public static ushort Swap(ushort x) + { + return (ushort)((x << 8) | (x >> 8)); + } + + public static short Swap(short x) + { + return (short)((x << 8) | ((x >> 8) & 0xFF)); + } + + public static uint Swap(uint x) + { + x = ((x << 8) & 0xFF00FF00) | ((x >> 8) & 0xFF00FF); + return (x << 16) | (x >> 16); + } + + public static int Swap(int x) + { + x = (int)(((x << 8) & 0xFF00FF00) | ((x >> 8) & 0xFF00FF)); + return (x << 16) | ((x >> 16) & 0xFFFF); + } } } From 4c2673828ab9a332845992fa52c13a3436612fa4 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 19 Jul 2017 05:19:28 +0100 Subject: [PATCH 044/217] On DOS date time if value is outside representation just return DOS epoch. --- DateHandlers.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/DateHandlers.cs b/DateHandlers.cs index 8d90eda67..360d17fde 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -179,7 +179,18 @@ public static DateTime DOSToDateTime(ushort date, ushort time) DicConsole.DebugWriteLine("DOSToDateTime handler", "date = 0x{0:X4}, year = {1}, month = {2}, day = {3}", date, year, month, day); DicConsole.DebugWriteLine("DOSToDateTime handler", "time = 0x{0:X4}, hour = {1}, minute = {2}, second = {3}", time, hour, minute, second); - return new DateTime(year, month, day, hour, minute, second); + + DateTime dosdate; + try + { + dosdate = new DateTime(year, month, day, hour, minute, second); + } + catch(ArgumentOutOfRangeException) + { + dosdate = new DateTime(1980, 1, 1, 0, 0, 0); + } + + return dosdate; } public static DateTime CPMToDateTime(byte[] timestamp) From 1e6583613f6c24553f1c8ed22c5aaefa5a343cc6 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 2 Aug 2017 23:01:11 +0100 Subject: [PATCH 045/217] Added disk geometry. --- CHS.cs | 42 ++++++++++++++++++++++++++++++++++++ DiscImageChef.Helpers.csproj | 3 ++- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 CHS.cs diff --git a/CHS.cs b/CHS.cs new file mode 100644 index 000000000..d2e8e7500 --- /dev/null +++ b/CHS.cs @@ -0,0 +1,42 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : CHS.cs +// Author(s) : Natalia Portillo +// +// Component : Component +// +// --[ Description ] ---------------------------------------------------------- +// +// Description +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2017 Natalia Portillo +// ****************************************************************************/ +using System; +namespace DiscImageChef.Helpers +{ + public static class CHS + { + 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 * maxHead + head) * maxSector + sector - 1; + } + } +} diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index 78c4a7bb4..d509b8756 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -54,6 +54,7 @@ + @@ -82,7 +83,7 @@ - + From 7a5d78637b6d6b5a122f2f4ca5ae3605b1d5bc82 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 16 Aug 2017 15:45:15 +0100 Subject: [PATCH 046/217] Added decoders for OS-9 date fields. --- DateHandlers.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/DateHandlers.cs b/DateHandlers.cs index 360d17fde..edb8e6e14 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -241,6 +241,25 @@ public static DateTime UNIXHrTimeToDateTime(ulong HRTimeStamp) { return UNIXEpoch.AddTicks((long)(HRTimeStamp / 100)); } + + public static DateTime OS9ToDateTime(byte[] date) + { + if(date == null || (date.Length != 3 && date.Length != 5)) + return DateTime.MinValue; + + DateTime os9date; + + try + { + 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); + } + catch(ArgumentOutOfRangeException) + { + os9date = new DateTime(1900, 0, 0, 0, 0, 0); + } + + return os9date; + } } } From 2d0e5a81c4770142c6b9700f16ec63d7dfdeab14 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 22 Aug 2017 03:40:12 +0100 Subject: [PATCH 047/217] Added support for a start offset on byte arrays. --- StringHandlers.cs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/StringHandlers.cs b/StringHandlers.cs index 51102d9ab..3a227d469 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -53,14 +53,14 @@ public static string CToString(byte[] CString) /// The corresponding C# string /// A null-terminated (aka C string) byte array in the specified encoding /// Encoding. - public static string CToString(byte[] CString, Encoding encoding, bool twoBytes = false) + public static string CToString(byte[] CString, Encoding encoding, bool twoBytes = false, int start = 0) { if(CString == null) return null; int len = 0; - for(int i = 0; i < CString.Length; i++) + for(int i = start; i < CString.Length; i++) { if(CString[i] == 0) { @@ -82,7 +82,7 @@ public static string CToString(byte[] CString, Encoding encoding, bool twoBytes } byte[] dest = new byte[len]; - Array.Copy(CString, 0, dest, 0, len); + Array.Copy(CString, start, dest, 0, len); return len == 0 ? "" : encoding.GetString(dest); } @@ -103,15 +103,15 @@ public static string PascalToString(byte[] PascalString) /// The corresponding C# string /// A length-prefixed (aka Pascal string) ASCII byte array /// Encoding. - public static string PascalToString(byte[] PascalString, Encoding encoding) + public static string PascalToString(byte[] PascalString, Encoding encoding, int start = 0) { if(PascalString == null) return null; - byte length = PascalString[0]; + byte length = PascalString[start]; int len = 0; - for(int i = 1; i < length + 1 && i < PascalString.Length; i++) + for(int i = start + 1; i < length + 1 && i < PascalString.Length; i++) { if(PascalString[i] == 0) break; @@ -120,7 +120,7 @@ public static string PascalToString(byte[] PascalString, Encoding encoding) } byte[] dest = new byte[len]; - Array.Copy(PascalString, 1, dest, 0, len); + Array.Copy(PascalString, start + 1, dest, 0, len); return len == 0 ? "" : encoding.GetString(dest); } @@ -141,16 +141,16 @@ public static string SpacePaddedToString(byte[] SpacePaddedString) /// The corresponding C# string /// A space (' ', 0x20, ASCII SPACE) padded ASCII byte array /// Encoding. - public static string SpacePaddedToString(byte[] SpacePaddedString, Encoding encoding) + public static string SpacePaddedToString(byte[] SpacePaddedString, Encoding encoding, int start = 0) { if(SpacePaddedString == null) return null; - int len = 0; + int len = start; - for(int i = SpacePaddedString.Length; i >= 0; i--) + for(int i = SpacePaddedString.Length; i >= start; i--) { - if(i == 0) + if(i == start) return ""; if(SpacePaddedString[i - 1] != 0x20) @@ -160,7 +160,7 @@ public static string SpacePaddedToString(byte[] SpacePaddedString, Encoding enco } } - return len == 0 ? "" : encoding.GetString(SpacePaddedString, 0, len); + return len == 0 ? "" : encoding.GetString(SpacePaddedString, start, len); } /// From 5ba86d3186c7aea4fd240aa1fc1494801a9530b2 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 5 Sep 2017 17:21:24 +0100 Subject: [PATCH 048/217] Version bumped to 3.5.99.0. --- DiscImageChef.Helpers.csproj | 17 ++++------------- Properties/AssemblyInfo.cs | 2 +- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index d509b8756..44b65a15c 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -9,7 +9,7 @@ Library DiscImageChef.Helpers DiscImageChef.Helpers - 3.4.99.0 + 3.5.99.0 false @@ -75,18 +75,9 @@ - - - - - - - - - - - - + + + diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index a10709ab0..5803d7cce 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -17,7 +17,7 @@ // The form "{Major}.{Minor}.*" will automatically update the build and revision, // and "{Major}.{Minor}.{Build}.*" will update just the revision. -[assembly: AssemblyVersion("3.4.99.0")] +[assembly: AssemblyVersion("3.5.99.0")] // The following attributes are used to specify the signing key for the assembly, // if desired. See the Mono documentation for more information about signing. From 3798f1f8941453a83b3664610b209f6dd39c4bff Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 14 Sep 2017 02:01:43 +0100 Subject: [PATCH 049/217] Added support for HP Logical Interchange Format. --- DateHandlers.cs | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/DateHandlers.cs b/DateHandlers.cs index edb8e6e14..0c63e4499 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -230,7 +230,7 @@ public static DateTime ECMAToDateTime(ushort typeAndTimeZone, short year, byte m if(offset == -2047) return new DateTime(year, month, day, hour, minute, second, DateTimeKind.Unspecified).AddTicks(ticks); - + if(offset < -1440 || offset > 1440) offset = 0; @@ -260,6 +260,38 @@ public static DateTime OS9ToDateTime(byte[] date) return os9date; } + + public static DateTime LifToDateTime(byte[] date) + { + if(date == null || date.Length != 6) + return new DateTime(1970, 1, 1, 0, 0, 0); + + return LifToDateTime(date[0], date[1], date[2], date[3], date[4], date[5]); + } + + public static DateTime LifToDateTime(byte year, byte month, byte day, byte hour, byte minute, byte second) + { + try + { + 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 isecond = (second >> 4) * 10 + (second & 0xF); + + if(iyear >= 70) + iyear += 1900; + else + iyear += 2000; + + return new DateTime(iyear, imonth, iday, ihour, iminute, isecond); + } + catch(ArgumentOutOfRangeException) + { + return new DateTime(1970, 1, 1, 0, 0, 0); + } + } } } From bcaea74953c033afc5aa6a1d826439d6db9ee20d Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 21 Sep 2017 18:31:17 +0100 Subject: [PATCH 050/217] Added support to get the start of an extent from any item in them. --- Extents/ExtentsByte.cs | 14 ++++++++++++++ Extents/ExtentsInt.cs | 14 ++++++++++++++ Extents/ExtentsLong.cs | 14 ++++++++++++++ Extents/ExtentsSByte.cs | 14 ++++++++++++++ Extents/ExtentsShort.cs | 14 ++++++++++++++ Extents/ExtentsUInt.cs | 14 ++++++++++++++ Extents/ExtentsULong.cs | 14 ++++++++++++++ Extents/ExtentsUShort.cs | 14 ++++++++++++++ 8 files changed, 112 insertions(+) diff --git a/Extents/ExtentsByte.cs b/Extents/ExtentsByte.cs index 2e6717a9e..a4ac19149 100644 --- a/Extents/ExtentsByte.cs +++ b/Extents/ExtentsByte.cs @@ -201,5 +201,19 @@ public Tuple[] ToArray() { return backend.ToArray(); } + + public bool GetStart(byte item, out byte start) + { + start = 0; + foreach(Tuple extent in backend) + { + if(item >= extent.Item1 && item <= extent.Item2) + { + start = extent.Item1; + return true; + } + } + return false; + } } } diff --git a/Extents/ExtentsInt.cs b/Extents/ExtentsInt.cs index 91604f116..2b9d46fb9 100644 --- a/Extents/ExtentsInt.cs +++ b/Extents/ExtentsInt.cs @@ -201,5 +201,19 @@ public Tuple[] ToArray() { return backend.ToArray(); } + + public bool GetStart(int item, out int start) + { + start = 0; + foreach(Tuple extent in backend) + { + if(item >= extent.Item1 && item <= extent.Item2) + { + start = extent.Item1; + return true; + } + } + return false; + } } } diff --git a/Extents/ExtentsLong.cs b/Extents/ExtentsLong.cs index 11e1c7f03..eae4ca61e 100644 --- a/Extents/ExtentsLong.cs +++ b/Extents/ExtentsLong.cs @@ -201,5 +201,19 @@ public Tuple[] ToArray() { return backend.ToArray(); } + + public bool GetStart(long item, out long start) + { + start = 0; + foreach(Tuple extent in backend) + { + if(item >= extent.Item1 && item <= extent.Item2) + { + start = extent.Item1; + return true; + } + } + return false; + } } } diff --git a/Extents/ExtentsSByte.cs b/Extents/ExtentsSByte.cs index bfc07ac9e..25af736e7 100644 --- a/Extents/ExtentsSByte.cs +++ b/Extents/ExtentsSByte.cs @@ -201,5 +201,19 @@ public Tuple[] ToArray() { return backend.ToArray(); } + + public bool GetStart(sbyte item, out sbyte start) + { + start = 0; + foreach(Tuple extent in backend) + { + if(item >= extent.Item1 && item <= extent.Item2) + { + start = extent.Item1; + return true; + } + } + return false; + } } } diff --git a/Extents/ExtentsShort.cs b/Extents/ExtentsShort.cs index f508ace86..079c34642 100644 --- a/Extents/ExtentsShort.cs +++ b/Extents/ExtentsShort.cs @@ -201,5 +201,19 @@ public Tuple[] ToArray() { return backend.ToArray(); } + + public bool GetStart(short item, out short start) + { + start = 0; + foreach(Tuple extent in backend) + { + if(item >= extent.Item1 && item <= extent.Item2) + { + start = extent.Item1; + return true; + } + } + return false; + } } } diff --git a/Extents/ExtentsUInt.cs b/Extents/ExtentsUInt.cs index 3d0988da9..bd24b6db2 100644 --- a/Extents/ExtentsUInt.cs +++ b/Extents/ExtentsUInt.cs @@ -201,5 +201,19 @@ public Tuple[] ToArray() { return backend.ToArray(); } + + public bool GetStart(uint item, out uint start) + { + start = 0; + foreach(Tuple extent in backend) + { + if(item >= extent.Item1 && item <= extent.Item2) + { + start = extent.Item1; + return true; + } + } + return false; + } } } diff --git a/Extents/ExtentsULong.cs b/Extents/ExtentsULong.cs index c9f457060..fcb7a40bc 100644 --- a/Extents/ExtentsULong.cs +++ b/Extents/ExtentsULong.cs @@ -201,5 +201,19 @@ public Tuple[] ToArray() { return backend.ToArray(); } + + public bool GetStart(ulong item, out ulong start) + { + start = 0; + foreach(Tuple extent in backend) + { + if(item >= extent.Item1 && item <= extent.Item2) + { + start = extent.Item1; + return true; + } + } + return false; + } } } diff --git a/Extents/ExtentsUShort.cs b/Extents/ExtentsUShort.cs index 9f7da19bc..3e019e2ab 100644 --- a/Extents/ExtentsUShort.cs +++ b/Extents/ExtentsUShort.cs @@ -201,5 +201,19 @@ public Tuple[] ToArray() { return backend.ToArray(); } + + public bool GetStart(ushort item, out ushort start) + { + start = 0; + foreach(Tuple extent in backend) + { + if(item >= extent.Item1 && item <= extent.Item2) + { + start = extent.Item1; + return true; + } + } + return false; + } } } From 6af967169447c4b643434e3672a7a8a771143f2a Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 8 Oct 2017 22:47:09 +0100 Subject: [PATCH 051/217] Added support for High Sierra Format. --- DateHandlers.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/DateHandlers.cs b/DateHandlers.cs index 0c63e4499..915f31b27 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -81,6 +81,13 @@ public static DateTime UNIXUnsignedToDateTime(ulong UNIXTimeStamp) return UNIXEpoch.AddSeconds(UNIXTimeStamp); } + public static DateTime HighSierraToDateTime(byte[] VDDateTime) + { + byte[] isotime = new byte[17]; + Array.Copy(VDDateTime, 0, isotime, 0, 16); + return ISO9660ToDateTime(isotime); + } + public static DateTime ISO9660ToDateTime(byte[] VDDateTime) { int year, month, day, hour, minute, second, hundredths; From 26c6f5607f9bad688e75ee38b66c0ccd60396a2f Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Fri, 13 Oct 2017 21:50:10 +0100 Subject: [PATCH 052/217] Added support for the CD-i filesystem described in Green Book. --- DateHandlers.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/DateHandlers.cs b/DateHandlers.cs index 915f31b27..ee612530b 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -88,6 +88,7 @@ public static DateTime HighSierraToDateTime(byte[] VDDateTime) return ISO9660ToDateTime(isotime); } + // TODO: Timezone public static DateTime ISO9660ToDateTime(byte[] VDDateTime) { int year, month, day, hour, minute, second, hundredths; From aa21751a58168dcb6b3af655cc4bdb6eba8bf8c0 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 13 Nov 2017 17:06:21 +0000 Subject: [PATCH 053/217] Corrected casting of unsigned and signed in bigendian marshal code. --- BigEndianMarshal.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/BigEndianMarshal.cs b/BigEndianMarshal.cs index d51c17984..a3ad6bdaa 100644 --- a/BigEndianMarshal.cs +++ b/BigEndianMarshal.cs @@ -93,21 +93,21 @@ public static T SwapStructureMembersEndian(T str) where T : struct ushort uint16 = (ushort)fi.GetValue(str); byte[] uint16_b = BitConverter.GetBytes(uint16); byte[] uint16_r = uint16_b.Reverse().ToArray(); - fi.SetValueDirect(__makeref(str), BitConverter.ToInt16(uint16_r, 0)); + fi.SetValueDirect(__makeref(str), BitConverter.ToUInt16(uint16_r, 0)); } else if(fi.FieldType == typeof(uint)) { uint uint32 = (uint)fi.GetValue(str); byte[] uint32_b = BitConverter.GetBytes(uint32); byte[] uint32_r = uint32_b.Reverse().ToArray(); - fi.SetValueDirect(__makeref(str), BitConverter.ToInt32(uint32_r, 0)); + fi.SetValueDirect(__makeref(str), BitConverter.ToUInt32(uint32_r, 0)); } else if(fi.FieldType == typeof(ulong)) { ulong uint64 = (ulong)fi.GetValue(str); byte[] uint64_b = BitConverter.GetBytes(uint64); byte[] uint64_r = uint64_b.Reverse().ToArray(); - fi.SetValueDirect(__makeref(str), BitConverter.ToInt64(uint64_r, 0)); + fi.SetValueDirect(__makeref(str), BitConverter.ToUInt64(uint64_r, 0)); } else if(fi.FieldType == typeof(float)) { From 8668d27fc81006817a1ae16ae835aec144c31f54 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 29 Nov 2017 16:02:19 +0000 Subject: [PATCH 054/217] Bumped version to 3.99.6.0. --- DiscImageChef.Helpers.csproj | 4 ++-- Properties/AssemblyInfo.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index 44b65a15c..d41be17c2 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -9,7 +9,7 @@ Library DiscImageChef.Helpers DiscImageChef.Helpers - 3.5.99.0 + 3.99.6.0 false @@ -77,7 +77,7 @@ - + diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 5803d7cce..99f2030aa 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -17,7 +17,7 @@ // The form "{Major}.{Minor}.*" will automatically update the build and revision, // and "{Major}.{Minor}.{Build}.*" will update just the revision. -[assembly: AssemblyVersion("3.5.99.0")] +[assembly: AssemblyVersion("3.99.6.0")] // The following attributes are used to specify the signing key for the assembly, // if desired. See the Mono documentation for more information about signing. From d441b376462d1abda183d0f5e24909be99a6ab78 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 19 Dec 2017 03:50:57 +0000 Subject: [PATCH 055/217] REFACTOR: Updated comments and copyright date. --- ArrayFill.cs | 2 +- ArrayIsEmpty.cs | 2 +- BigEndianBitConverter.cs | 2 +- BigEndianMarshal.cs | 6 +++--- CHS.cs | 6 +++--- CompareBytes.cs | 6 +++--- CountBits.cs | 6 +++--- DateHandlers.cs | 2 +- EndianAwareBinaryReader.cs | 2 +- Extents/ExtentsByte.cs | 6 +++--- Extents/ExtentsInt.cs | 6 +++--- Extents/ExtentsLong.cs | 6 +++--- Extents/ExtentsSByte.cs | 6 +++--- Extents/ExtentsShort.cs | 6 +++--- Extents/ExtentsUInt.cs | 6 +++--- Extents/ExtentsULong.cs | 6 +++--- Extents/ExtentsUShort.cs | 6 +++--- PrintHex.cs | 2 +- Properties/AssemblyInfo.cs | 34 +++++++++++++++++++++++++++++++++- StringHandlers.cs | 2 +- Swapping.cs | 2 +- 21 files changed, 77 insertions(+), 45 deletions(-) diff --git a/ArrayFill.cs b/ArrayFill.cs index e886d7c31..6cc52325f 100644 --- a/ArrayFill.cs +++ b/ArrayFill.cs @@ -20,7 +20,7 @@ // Assuming open source. // // ---------------------------------------------------------------------------- -// Copyright © 2011-2017 Natalia Portillo +// Copyright © 2011-2018 Natalia Portillo // Copyright(C) 2014 mykohsu // ****************************************************************************/ diff --git a/ArrayIsEmpty.cs b/ArrayIsEmpty.cs index a6faa4a13..41df20741 100644 --- a/ArrayIsEmpty.cs +++ b/ArrayIsEmpty.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2017 Natalia Portillo +// Copyright © 2011-2018 Natalia Portillo // ****************************************************************************/ namespace DiscImageChef diff --git a/BigEndianBitConverter.cs b/BigEndianBitConverter.cs index 80e27d048..91a995dad 100644 --- a/BigEndianBitConverter.cs +++ b/BigEndianBitConverter.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2017 Natalia Portillo +// Copyright © 2011-2018 Natalia Portillo // ****************************************************************************/ using System; diff --git a/BigEndianMarshal.cs b/BigEndianMarshal.cs index a3ad6bdaa..f8109b012 100644 --- a/BigEndianMarshal.cs +++ b/BigEndianMarshal.cs @@ -5,11 +5,11 @@ // Filename : BigEndianMarshal.cs // Author(s) : Natalia Portillo // -// Component : Component +// Component : Helpers. // // --[ Description ] ---------------------------------------------------------- // -// Description +// Provides marshalling for big-endian data. // // --[ License ] -------------------------------------------------------------- // @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2017 Natalia Portillo +// Copyright © 2011-2018 Natalia Portillo // ****************************************************************************/ using System; diff --git a/CHS.cs b/CHS.cs index d2e8e7500..46dda4475 100644 --- a/CHS.cs +++ b/CHS.cs @@ -5,11 +5,11 @@ // Filename : CHS.cs // Author(s) : Natalia Portillo // -// Component : Component +// Component : Helpers. // // --[ Description ] ---------------------------------------------------------- // -// Description +// Helpers for CHS<->LBA conversions // // --[ License ] -------------------------------------------------------------- // @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2017 Natalia Portillo +// Copyright © 2011-2018 Natalia Portillo // ****************************************************************************/ using System; namespace DiscImageChef.Helpers diff --git a/CompareBytes.cs b/CompareBytes.cs index 74413d86a..9712b01e3 100644 --- a/CompareBytes.cs +++ b/CompareBytes.cs @@ -5,11 +5,11 @@ // Filename : CompareBytes.cs // Author(s) : Natalia Portillo // -// Component : Component +// Component : Helpers. // // --[ Description ] ---------------------------------------------------------- // -// Description +// Compares two byte arrays. // // --[ License ] -------------------------------------------------------------- // @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2017 Natalia Portillo +// Copyright © 2011-2018 Natalia Portillo // ****************************************************************************/ namespace DiscImageChef diff --git a/CountBits.cs b/CountBits.cs index d8313ff19..929fe9a1a 100644 --- a/CountBits.cs +++ b/CountBits.cs @@ -5,11 +5,11 @@ // Filename : CountBits.cs // Author(s) : Natalia Portillo // -// Component : Component +// Component : Helpers. // // --[ Description ] ---------------------------------------------------------- // -// Description +// Counts bits in a number. // // --[ License ] -------------------------------------------------------------- // @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2017 Natalia Portillo +// Copyright © 2011-2018 Natalia Portillo // ****************************************************************************/ using System; namespace DiscImageChef.Helpers diff --git a/DateHandlers.cs b/DateHandlers.cs index ee612530b..a79422ba5 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2017 Natalia Portillo +// Copyright © 2011-2018 Natalia Portillo // ****************************************************************************/ using System; diff --git a/EndianAwareBinaryReader.cs b/EndianAwareBinaryReader.cs index cebd581ef..194ad7f25 100644 --- a/EndianAwareBinaryReader.cs +++ b/EndianAwareBinaryReader.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2017 Natalia Portillo +// Copyright © 2011-2018 Natalia Portillo // ****************************************************************************/ using System; diff --git a/Extents/ExtentsByte.cs b/Extents/ExtentsByte.cs index a4ac19149..10b9a36c9 100644 --- a/Extents/ExtentsByte.cs +++ b/Extents/ExtentsByte.cs @@ -5,11 +5,11 @@ // Filename : ExtentsByte.cs // Author(s) : Natalia Portillo // -// Component : Component +// Component : Extent helpers. // // --[ Description ] ---------------------------------------------------------- // -// Description +// Provides extents for byte types. // // --[ License ] -------------------------------------------------------------- // @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2017 Natalia Portillo +// Copyright © 2011-2018 Natalia Portillo // ****************************************************************************/ using System; using System.Collections.Generic; diff --git a/Extents/ExtentsInt.cs b/Extents/ExtentsInt.cs index 2b9d46fb9..80aaac99d 100644 --- a/Extents/ExtentsInt.cs +++ b/Extents/ExtentsInt.cs @@ -5,11 +5,11 @@ // Filename : ExtentsInt.cs // Author(s) : Natalia Portillo // -// Component : Component +// Component : Extent helpers. // // --[ Description ] ---------------------------------------------------------- // -// Description +// Provides extents for int types. // // --[ License ] -------------------------------------------------------------- // @@ -27,7 +27,7 @@ // License aint with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2017 Natalia Portillo +// Copyright © 2011-2018 Natalia Portillo // ****************************************************************************/ using System; using System.Collections.Generic; diff --git a/Extents/ExtentsLong.cs b/Extents/ExtentsLong.cs index eae4ca61e..d9309a734 100644 --- a/Extents/ExtentsLong.cs +++ b/Extents/ExtentsLong.cs @@ -5,11 +5,11 @@ // Filename : ExtentsLong.cs // Author(s) : Natalia Portillo // -// Component : Component +// Component : Extent helpers. // // --[ Description ] ---------------------------------------------------------- // -// Description +// Provides extents for long types. // // --[ License ] -------------------------------------------------------------- // @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2017 Natalia Portillo +// Copyright © 2011-2018 Natalia Portillo // ****************************************************************************/ using System; using System.Collections.Generic; diff --git a/Extents/ExtentsSByte.cs b/Extents/ExtentsSByte.cs index 25af736e7..4997b3a25 100644 --- a/Extents/ExtentsSByte.cs +++ b/Extents/ExtentsSByte.cs @@ -5,11 +5,11 @@ // Filename : ExtentsSByte.cs // Author(s) : Natalia Portillo // -// Component : Component +// Component : Extent helpers. // // --[ Description ] ---------------------------------------------------------- // -// Description +// Provides extents for sbyte types. // // --[ License ] -------------------------------------------------------------- // @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2017 Natalia Portillo +// Copyright © 2011-2018 Natalia Portillo // ****************************************************************************/ using System; using System.Collections.Generic; diff --git a/Extents/ExtentsShort.cs b/Extents/ExtentsShort.cs index 079c34642..0b6714146 100644 --- a/Extents/ExtentsShort.cs +++ b/Extents/ExtentsShort.cs @@ -5,11 +5,11 @@ // Filename : ExtentsShort.cs // Author(s) : Natalia Portillo // -// Component : Component +// Component : Extent helpers. // // --[ Description ] ---------------------------------------------------------- // -// Description +// Provides extents for short types. // // --[ License ] -------------------------------------------------------------- // @@ -27,7 +27,7 @@ // License ashort with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2017 Natalia Portillo +// Copyright © 2011-2018 Natalia Portillo // ****************************************************************************/ using System; using System.Collections.Generic; diff --git a/Extents/ExtentsUInt.cs b/Extents/ExtentsUInt.cs index bd24b6db2..0d03bb8e2 100644 --- a/Extents/ExtentsUInt.cs +++ b/Extents/ExtentsUInt.cs @@ -5,11 +5,11 @@ // Filename : ExtentsUInt.cs // Author(s) : Natalia Portillo // -// Component : Component +// Component : Extent helpers. // // --[ Description ] ---------------------------------------------------------- // -// Description +// Provides extents for uint types. // // --[ License ] -------------------------------------------------------------- // @@ -27,7 +27,7 @@ // License auint with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2017 Natalia Portillo +// Copyright © 2011-2018 Natalia Portillo // ****************************************************************************/ using System; using System.Collections.Generic; diff --git a/Extents/ExtentsULong.cs b/Extents/ExtentsULong.cs index fcb7a40bc..8d849449c 100644 --- a/Extents/ExtentsULong.cs +++ b/Extents/ExtentsULong.cs @@ -5,11 +5,11 @@ // Filename : ExtentsULong.cs // Author(s) : Natalia Portillo // -// Component : Component +// Component : Extent helpers. // // --[ Description ] ---------------------------------------------------------- // -// Description +// Provides extents for ulong types. // // --[ License ] -------------------------------------------------------------- // @@ -27,7 +27,7 @@ // License aulong with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2017 Natalia Portillo +// Copyright © 2011-2018 Natalia Portillo // ****************************************************************************/ using System; using System.Collections.Generic; diff --git a/Extents/ExtentsUShort.cs b/Extents/ExtentsUShort.cs index 3e019e2ab..fdaec78cc 100644 --- a/Extents/ExtentsUShort.cs +++ b/Extents/ExtentsUShort.cs @@ -5,11 +5,11 @@ // Filename : ExtentsUShort.cs // Author(s) : Natalia Portillo // -// Component : Component +// Component : Extent helpers. // // --[ Description ] ---------------------------------------------------------- // -// Description +// Provides extents for ushort types. // // --[ License ] -------------------------------------------------------------- // @@ -27,7 +27,7 @@ // License aushort with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2017 Natalia Portillo +// Copyright © 2011-2018 Natalia Portillo // ****************************************************************************/ using System; using System.Collections.Generic; diff --git a/PrintHex.cs b/PrintHex.cs index af01d99bb..01ffed386 100644 --- a/PrintHex.cs +++ b/PrintHex.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2017 Natalia Portillo +// Copyright © 2011-2018 Natalia Portillo // ****************************************************************************/ using DiscImageChef.Console; diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 99f2030aa..e2ea5cce5 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -1,4 +1,36 @@ -using System.Reflection; +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : AssemblyInfo.cs +// Author(s) : Natalia Portillo +// +// Component : Helpers. +// +// --[ Description ] ---------------------------------------------------------- +// +// C# assembly definitions. +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2018 Natalia Portillo +// ****************************************************************************/ + +using System.Reflection; using System.Runtime.CompilerServices; // Information about this assembly is defined by the following attributes. diff --git a/StringHandlers.cs b/StringHandlers.cs index 3a227d469..a3bad4777 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2017 Natalia Portillo +// Copyright © 2011-2018 Natalia Portillo // ****************************************************************************/ using System.Text; diff --git a/Swapping.cs b/Swapping.cs index 88de46905..d8323e9c2 100644 --- a/Swapping.cs +++ b/Swapping.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2017 Natalia Portillo +// Copyright © 2011-2018 Natalia Portillo // ****************************************************************************/ using System; using System.Linq; From 8c19d1d93a122e6df11ff522e9d76fb70792c5be Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 19 Dec 2017 19:33:46 +0000 Subject: [PATCH 056/217] REFACTOR: Sort and removed usings. --- BigEndianMarshal.cs | 2 +- CHS.cs | 2 +- CountBits.cs | 2 +- DateHandlers.cs | 2 +- Extents/ExtentsByte.cs | 1 + Extents/ExtentsInt.cs | 1 + Extents/ExtentsLong.cs | 1 + Extents/ExtentsSByte.cs | 1 + Extents/ExtentsShort.cs | 1 + Extents/ExtentsUInt.cs | 1 + Extents/ExtentsULong.cs | 1 + Extents/ExtentsUShort.cs | 1 + Properties/AssemblyInfo.cs | 1 - StringHandlers.cs | 2 +- Swapping.cs | 1 + 15 files changed, 14 insertions(+), 6 deletions(-) diff --git a/BigEndianMarshal.cs b/BigEndianMarshal.cs index f8109b012..548a35bde 100644 --- a/BigEndianMarshal.cs +++ b/BigEndianMarshal.cs @@ -31,9 +31,9 @@ // ****************************************************************************/ using System; +using System.Linq; using System.Reflection; using System.Runtime.InteropServices; -using System.Linq; namespace DiscImageChef { diff --git a/CHS.cs b/CHS.cs index 46dda4475..34e4cebca 100644 --- a/CHS.cs +++ b/CHS.cs @@ -29,7 +29,7 @@ // ---------------------------------------------------------------------------- // Copyright © 2011-2018 Natalia Portillo // ****************************************************************************/ -using System; + namespace DiscImageChef.Helpers { public static class CHS diff --git a/CountBits.cs b/CountBits.cs index 929fe9a1a..0a377d6fe 100644 --- a/CountBits.cs +++ b/CountBits.cs @@ -29,7 +29,7 @@ // ---------------------------------------------------------------------------- // Copyright © 2011-2018 Natalia Portillo // ****************************************************************************/ -using System; + namespace DiscImageChef.Helpers { public static class CountBits diff --git a/DateHandlers.cs b/DateHandlers.cs index a79422ba5..5399d6cae 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -31,8 +31,8 @@ // ****************************************************************************/ using System; -using DiscImageChef.Console; using System.Text; +using DiscImageChef.Console; namespace DiscImageChef { diff --git a/Extents/ExtentsByte.cs b/Extents/ExtentsByte.cs index 10b9a36c9..0d948ac52 100644 --- a/Extents/ExtentsByte.cs +++ b/Extents/ExtentsByte.cs @@ -29,6 +29,7 @@ // ---------------------------------------------------------------------------- // Copyright © 2011-2018 Natalia Portillo // ****************************************************************************/ + using System; using System.Collections.Generic; using System.Linq; diff --git a/Extents/ExtentsInt.cs b/Extents/ExtentsInt.cs index 80aaac99d..6e6842f30 100644 --- a/Extents/ExtentsInt.cs +++ b/Extents/ExtentsInt.cs @@ -29,6 +29,7 @@ // ---------------------------------------------------------------------------- // Copyright © 2011-2018 Natalia Portillo // ****************************************************************************/ + using System; using System.Collections.Generic; using System.Linq; diff --git a/Extents/ExtentsLong.cs b/Extents/ExtentsLong.cs index d9309a734..c139ee24e 100644 --- a/Extents/ExtentsLong.cs +++ b/Extents/ExtentsLong.cs @@ -29,6 +29,7 @@ // ---------------------------------------------------------------------------- // Copyright © 2011-2018 Natalia Portillo // ****************************************************************************/ + using System; using System.Collections.Generic; using System.Linq; diff --git a/Extents/ExtentsSByte.cs b/Extents/ExtentsSByte.cs index 4997b3a25..b67a2c3c6 100644 --- a/Extents/ExtentsSByte.cs +++ b/Extents/ExtentsSByte.cs @@ -29,6 +29,7 @@ // ---------------------------------------------------------------------------- // Copyright © 2011-2018 Natalia Portillo // ****************************************************************************/ + using System; using System.Collections.Generic; using System.Linq; diff --git a/Extents/ExtentsShort.cs b/Extents/ExtentsShort.cs index 0b6714146..62065c87a 100644 --- a/Extents/ExtentsShort.cs +++ b/Extents/ExtentsShort.cs @@ -29,6 +29,7 @@ // ---------------------------------------------------------------------------- // Copyright © 2011-2018 Natalia Portillo // ****************************************************************************/ + using System; using System.Collections.Generic; using System.Linq; diff --git a/Extents/ExtentsUInt.cs b/Extents/ExtentsUInt.cs index 0d03bb8e2..197eadfc7 100644 --- a/Extents/ExtentsUInt.cs +++ b/Extents/ExtentsUInt.cs @@ -29,6 +29,7 @@ // ---------------------------------------------------------------------------- // Copyright © 2011-2018 Natalia Portillo // ****************************************************************************/ + using System; using System.Collections.Generic; using System.Linq; diff --git a/Extents/ExtentsULong.cs b/Extents/ExtentsULong.cs index 8d849449c..f8aa06851 100644 --- a/Extents/ExtentsULong.cs +++ b/Extents/ExtentsULong.cs @@ -29,6 +29,7 @@ // ---------------------------------------------------------------------------- // Copyright © 2011-2018 Natalia Portillo // ****************************************************************************/ + using System; using System.Collections.Generic; using System.Linq; diff --git a/Extents/ExtentsUShort.cs b/Extents/ExtentsUShort.cs index fdaec78cc..27b936f66 100644 --- a/Extents/ExtentsUShort.cs +++ b/Extents/ExtentsUShort.cs @@ -29,6 +29,7 @@ // ---------------------------------------------------------------------------- // Copyright © 2011-2018 Natalia Portillo // ****************************************************************************/ + using System; using System.Collections.Generic; using System.Linq; diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index e2ea5cce5..c93539f7d 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -31,7 +31,6 @@ // ****************************************************************************/ using System.Reflection; -using System.Runtime.CompilerServices; // Information about this assembly is defined by the following attributes. // Change them to the values specific to your project. diff --git a/StringHandlers.cs b/StringHandlers.cs index a3bad4777..d2bebcda7 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -30,8 +30,8 @@ // Copyright © 2011-2018 Natalia Portillo // ****************************************************************************/ -using System.Text; using System; +using System.Text; namespace DiscImageChef { diff --git a/Swapping.cs b/Swapping.cs index d8323e9c2..da3a9f44d 100644 --- a/Swapping.cs +++ b/Swapping.cs @@ -29,6 +29,7 @@ // ---------------------------------------------------------------------------- // Copyright © 2011-2018 Natalia Portillo // ****************************************************************************/ + using System; using System.Linq; From 7f2a201ab75e45ff01675ac1823f1bcabf489547 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 19 Dec 2017 20:33:03 +0000 Subject: [PATCH 057/217] REFACTOR: Reformat code. --- ArrayFill.cs | 13 ++--- ArrayIsEmpty.cs | 17 ++---- BigEndianBitConverter.cs | 48 ++++++++++----- BigEndianMarshal.cs | 4 +- CHS.cs | 6 +- CompareBytes.cs | 8 +-- CountBits.cs | 2 +- DateHandlers.cs | 117 +++++++++++++++++-------------------- EndianAwareBinaryReader.cs | 62 ++++++++------------ Extents/ExtentsByte.cs | 43 ++++++-------- Extents/ExtentsInt.cs | 43 ++++++-------- Extents/ExtentsLong.cs | 43 ++++++-------- Extents/ExtentsSByte.cs | 43 ++++++-------- Extents/ExtentsShort.cs | 43 ++++++-------- Extents/ExtentsUInt.cs | 43 ++++++-------- Extents/ExtentsULong.cs | 43 ++++++-------- Extents/ExtentsUShort.cs | 42 ++++++------- PrintHex.cs | 7 +-- Properties/AssemblyInfo.cs | 3 +- StringHandlers.cs | 42 +++++-------- Swapping.cs | 2 +- 21 files changed, 294 insertions(+), 380 deletions(-) diff --git a/ArrayFill.cs b/ArrayFill.cs index 6cc52325f..733a35136 100644 --- a/ArrayFill.cs +++ b/ArrayFill.cs @@ -34,15 +34,12 @@ public static partial class ArrayHelpers public static void ArrayFill(T[] destinationArray, T value) { // if called with a single value, wrap the value in an array and call the main function - ArrayFill(destinationArray, new T[] { value }); + ArrayFill(destinationArray, new T[] {value}); } public static void ArrayFill(T[] destinationArray, T[] value) { - if(destinationArray == null) - { - throw new ArgumentNullException(nameof(destinationArray)); - } + if(destinationArray == null) { throw new ArgumentNullException(nameof(destinationArray)); } if(value.Length > destinationArray.Length) { @@ -71,11 +68,9 @@ public static string ByteArrayToHex(byte[] array) public static string ByteArrayToHex(byte[] array, bool upper) { 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]); return upper ? sb.ToString().ToUpper() : sb.ToString(); } } -} - +} \ No newline at end of file diff --git a/ArrayIsEmpty.cs b/ArrayIsEmpty.cs index 41df20741..b83f8b10c 100644 --- a/ArrayIsEmpty.cs +++ b/ArrayIsEmpty.cs @@ -36,27 +36,20 @@ public static partial class ArrayHelpers { public static bool ArrayIsNullOrWhiteSpace(byte[] array) { - if(array == null) - return true; + if(array == null) return true; - foreach(byte b in array) - if(b != 0x00 && b != 0x20) - return false; + foreach(byte b in array) if(b != 0x00 && b != 0x20) return false; return true; } public static bool ArrayIsNullOrEmpty(byte[] array) { - if(array == null) - return true; + if(array == null) return true; - foreach(byte b in array) - if(b != 0x00) - return false; + foreach(byte b in array) if(b != 0x00) return false; return true; } } -} - +} \ No newline at end of file diff --git a/BigEndianBitConverter.cs b/BigEndianBitConverter.cs index 91a995dad..46d0706f1 100644 --- a/BigEndianBitConverter.cs +++ b/BigEndianBitConverter.cs @@ -48,6 +48,7 @@ public static class BigEndianBitConverter /// architecture. /// public static bool IsLittleEndian { get; set; } + // should default to false, which is what we want for Empire /// /// Converts the specified double-precision floating point number to a 64-bit @@ -362,7 +363,9 @@ public static double ToDouble(byte[] value, int startIndex) /// public static short ToInt16(byte[] value, int startIndex) { - return !IsLittleEndian ? BitConverter.ToInt16(value, startIndex) : BitConverter.ToInt16(value.Reverse().ToArray(), value.Length - sizeof(short) - startIndex); + return !IsLittleEndian + ? BitConverter.ToInt16(value, startIndex) + : BitConverter.ToInt16(value.Reverse().ToArray(), value.Length - sizeof(short) - startIndex); } /// @@ -393,7 +396,9 @@ public static short ToInt16(byte[] value, int startIndex) /// public static int ToInt32(byte[] value, int startIndex) { - return !IsLittleEndian ? BitConverter.ToInt32(value, startIndex) : BitConverter.ToInt32(value.Reverse().ToArray(), value.Length - sizeof(int) - startIndex); + return !IsLittleEndian + ? BitConverter.ToInt32(value, startIndex) + : BitConverter.ToInt32(value.Reverse().ToArray(), value.Length - sizeof(int) - startIndex); } /// @@ -424,7 +429,9 @@ public static int ToInt32(byte[] value, int startIndex) /// public static long ToInt64(byte[] value, int startIndex) { - return !IsLittleEndian ? BitConverter.ToInt64(value, startIndex) : BitConverter.ToInt64(value.Reverse().ToArray(), value.Length - sizeof(long) - startIndex); + return !IsLittleEndian + ? BitConverter.ToInt64(value, startIndex) + : BitConverter.ToInt64(value.Reverse().ToArray(), value.Length - sizeof(long) - startIndex); } /// @@ -456,7 +463,9 @@ public static long ToInt64(byte[] value, int startIndex) /// public static float ToSingle(byte[] value, int startIndex) { - return !IsLittleEndian ? BitConverter.ToSingle(value, startIndex) : BitConverter.ToSingle(value.Reverse().ToArray(), value.Length - sizeof(float) - startIndex); + return !IsLittleEndian + ? BitConverter.ToSingle(value, startIndex) + : BitConverter.ToSingle(value.Reverse().ToArray(), value.Length - sizeof(float) - startIndex); } /// @@ -507,7 +516,9 @@ public static string ToString(byte[] value) /// public static string ToString(byte[] value, int startIndex) { - return !IsLittleEndian ? BitConverter.ToString(value, startIndex) : BitConverter.ToString(value.Reverse().ToArray(), startIndex); + return !IsLittleEndian + ? BitConverter.ToString(value, startIndex) + : BitConverter.ToString(value.Reverse().ToArray(), startIndex); } /// @@ -545,7 +556,9 @@ public static string ToString(byte[] value, int startIndex) /// public static string ToString(byte[] value, int startIndex, int length) { - return !IsLittleEndian ? BitConverter.ToString(value, startIndex, length) : BitConverter.ToString(value.Reverse().ToArray(), startIndex, length); + return !IsLittleEndian + ? BitConverter.ToString(value, startIndex, length) + : BitConverter.ToString(value.Reverse().ToArray(), startIndex, length); } /// @@ -575,7 +588,9 @@ public static string ToString(byte[] value, int startIndex, int length) /// public static ushort ToUInt16(byte[] value, int startIndex) { - return !IsLittleEndian ? BitConverter.ToUInt16(value, startIndex) : BitConverter.ToUInt16(value.Reverse().ToArray(), value.Length - sizeof(ushort) - startIndex); + return !IsLittleEndian + ? BitConverter.ToUInt16(value, startIndex) + : BitConverter.ToUInt16(value.Reverse().ToArray(), value.Length - sizeof(ushort) - startIndex); } /// @@ -606,7 +621,9 @@ public static ushort ToUInt16(byte[] value, int startIndex) /// public static uint ToUInt32(byte[] value, int startIndex) { - return !IsLittleEndian ? BitConverter.ToUInt32(value, startIndex) : BitConverter.ToUInt32(value.Reverse().ToArray(), value.Length - sizeof(uint) - startIndex); + return !IsLittleEndian + ? BitConverter.ToUInt32(value, startIndex) + : BitConverter.ToUInt32(value.Reverse().ToArray(), value.Length - sizeof(uint) - startIndex); } /// @@ -637,18 +654,17 @@ public static uint ToUInt32(byte[] value, int startIndex) /// public static ulong ToUInt64(byte[] value, int startIndex) { - return !IsLittleEndian ? BitConverter.ToUInt64(value, startIndex) : BitConverter.ToUInt64(value.Reverse().ToArray(), value.Length - sizeof(ulong) - startIndex); + return !IsLittleEndian + ? 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]); + 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]); } } } \ No newline at end of file diff --git a/BigEndianMarshal.cs b/BigEndianMarshal.cs index 548a35bde..84fadb932 100644 --- a/BigEndianMarshal.cs +++ b/BigEndianMarshal.cs @@ -124,8 +124,8 @@ public static T SwapStructureMembersEndian(T str) where T : struct fi.SetValueDirect(__makeref(str), BitConverter.ToDouble(dbl_r, 0)); } } + return str; } } -} - +} \ No newline at end of file diff --git a/CHS.cs b/CHS.cs index 34e4cebca..869669143 100644 --- a/CHS.cs +++ b/CHS.cs @@ -36,7 +36,9 @@ public static class CHS { 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 * maxHead + head) * maxSector + sector - 1; + return maxHead == 0 || maxSector == 0 + ? (cyl * 16 + head) * 63 + sector - 1 + : (cyl * maxHead + head) * maxSector + sector - 1; } } -} +} \ No newline at end of file diff --git a/CompareBytes.cs b/CompareBytes.cs index 9712b01e3..776fffa33 100644 --- a/CompareBytes.cs +++ b/CompareBytes.cs @@ -34,7 +34,8 @@ namespace DiscImageChef { public static partial class ArrayHelpers { - public static void CompareBytes(out bool different, out bool sameSize, byte[] compareArray1, byte[] compareArray2) + public static void CompareBytes(out bool different, out bool sameSize, byte[] compareArray1, + byte[] compareArray2) { different = false; sameSize = true; @@ -50,8 +51,7 @@ public static void CompareBytes(out bool different, out bool sameSize, byte[] co sameSize = false; leastBytes = compareArray2.LongLength; } - else - leastBytes = compareArray1.LongLength; + else leastBytes = compareArray1.LongLength; for(long i = 0; i < leastBytes; i++) { @@ -63,4 +63,4 @@ public static void CompareBytes(out bool different, out bool sameSize, byte[] co } } } -} +} \ No newline at end of file diff --git a/CountBits.cs b/CountBits.cs index 0a377d6fe..29a153fb4 100644 --- a/CountBits.cs +++ b/CountBits.cs @@ -41,4 +41,4 @@ public static int Count(uint number) return (int)((((number + (number >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24); } } -} +} \ No newline at end of file diff --git a/DateHandlers.cs b/DateHandlers.cs index 5399d6cae..87160d81e 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -99,55 +99,58 @@ public static DateTime ISO9660ToDateTime(byte[] VDDateTime) fourcharvalue[1] = VDDateTime[1]; fourcharvalue[2] = VDDateTime[2]; fourcharvalue[3] = VDDateTime[3]; - DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "year = \"{0}\"", StringHandlers.CToString(fourcharvalue, Encoding.ASCII)); - if(!int.TryParse(StringHandlers.CToString(fourcharvalue, Encoding.ASCII), out year)) - year = 0; + DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "year = \"{0}\"", + StringHandlers.CToString(fourcharvalue, Encoding.ASCII)); + if(!int.TryParse(StringHandlers.CToString(fourcharvalue, Encoding.ASCII), out year)) year = 0; // year = Convert.ToInt32(StringHandlers.CToString(fourcharvalue, Encoding.ASCII)); twocharvalue[0] = VDDateTime[4]; twocharvalue[1] = VDDateTime[5]; - DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "month = \"{0}\"", StringHandlers.CToString(twocharvalue, Encoding.ASCII)); - if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out month)) - month = 0; + DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "month = \"{0}\"", + StringHandlers.CToString(twocharvalue, Encoding.ASCII)); + if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out month)) month = 0; // month = Convert.ToInt32(StringHandlers.CToString(twocharvalue, Encoding.ASCII)); twocharvalue[0] = VDDateTime[6]; twocharvalue[1] = VDDateTime[7]; - DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "day = \"{0}\"", StringHandlers.CToString(twocharvalue, Encoding.ASCII)); - if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out day)) - day = 0; + DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "day = \"{0}\"", + StringHandlers.CToString(twocharvalue, Encoding.ASCII)); + if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out day)) day = 0; // day = Convert.ToInt32(StringHandlers.CToString(twocharvalue, Encoding.ASCII)); twocharvalue[0] = VDDateTime[8]; twocharvalue[1] = VDDateTime[9]; - DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "hour = \"{0}\"", StringHandlers.CToString(twocharvalue, Encoding.ASCII)); - if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out hour)) - hour = 0; + DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "hour = \"{0}\"", + StringHandlers.CToString(twocharvalue, Encoding.ASCII)); + if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out hour)) hour = 0; // hour = Convert.ToInt32(StringHandlers.CToString(twocharvalue, Encoding.ASCII)); twocharvalue[0] = VDDateTime[10]; twocharvalue[1] = VDDateTime[11]; - DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "minute = \"{0}\"", StringHandlers.CToString(twocharvalue, Encoding.ASCII)); - if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out minute)) - minute = 0; + DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "minute = \"{0}\"", + StringHandlers.CToString(twocharvalue, Encoding.ASCII)); + if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out minute)) minute = 0; // minute = Convert.ToInt32(StringHandlers.CToString(twocharvalue, Encoding.ASCII)); twocharvalue[0] = VDDateTime[12]; twocharvalue[1] = VDDateTime[13]; - DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "second = \"{0}\"", StringHandlers.CToString(twocharvalue, Encoding.ASCII)); - if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out second)) - second = 0; + DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "second = \"{0}\"", + StringHandlers.CToString(twocharvalue, Encoding.ASCII)); + if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out second)) second = 0; // second = Convert.ToInt32(StringHandlers.CToString(twocharvalue, Encoding.ASCII)); twocharvalue[0] = VDDateTime[14]; twocharvalue[1] = VDDateTime[15]; - DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "hundredths = \"{0}\"", StringHandlers.CToString(twocharvalue, Encoding.ASCII)); - if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out hundredths)) - hundredths = 0; + DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "hundredths = \"{0}\"", + StringHandlers.CToString(twocharvalue, Encoding.ASCII)); + if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out hundredths)) hundredths = 0; // hundredths = Convert.ToInt32(StringHandlers.CToString(twocharvalue, Encoding.ASCII)); - DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "decodedDT = new DateTime({0}, {1}, {2}, {3}, {4}, {5}, {6}, DateTimeKind.Unspecified);", year, month, day, hour, minute, second, hundredths * 10); - DateTime decodedDT = new DateTime(year, month, day, hour, minute, second, hundredths * 10, DateTimeKind.Unspecified); + DicConsole.DebugWriteLine("ISO9600ToDateTime handler", + "decodedDT = new DateTime({0}, {1}, {2}, {3}, {4}, {5}, {6}, DateTimeKind.Unspecified);", + year, month, day, hour, minute, second, hundredths * 10); + DateTime decodedDT = new DateTime(year, month, day, hour, minute, second, hundredths * 10, + DateTimeKind.Unspecified); return decodedDT; } @@ -172,7 +175,9 @@ public static DateTime UCSDPascalToDateTime(short dateRecord) int day = (dateRecord & 0x01F0) >> 4; int month = (dateRecord & 0x000F); - DicConsole.DebugWriteLine("UCSDPascalToDateTime handler", "dateRecord = 0x{0:X4}, year = {1}, month = {2}, day = {3}", dateRecord, year, month, day); + DicConsole.DebugWriteLine("UCSDPascalToDateTime handler", + "dateRecord = 0x{0:X4}, year = {1}, month = {2}, day = {3}", dateRecord, year, + month, day); return new DateTime(year, month, day); } @@ -185,18 +190,15 @@ public static DateTime DOSToDateTime(ushort date, ushort time) int minute = (time & 0x7E0) >> 5; int second = (time & 0x1F) * 2; - DicConsole.DebugWriteLine("DOSToDateTime handler", "date = 0x{0:X4}, year = {1}, month = {2}, day = {3}", date, year, month, day); - DicConsole.DebugWriteLine("DOSToDateTime handler", "time = 0x{0:X4}, hour = {1}, minute = {2}, second = {3}", time, hour, minute, second); + DicConsole.DebugWriteLine("DOSToDateTime handler", "date = 0x{0:X4}, year = {1}, month = {2}, day = {3}", + date, year, month, day); + DicConsole.DebugWriteLine("DOSToDateTime handler", + "time = 0x{0:X4}, hour = {1}, minute = {2}, second = {3}", time, hour, minute, + second); DateTime dosdate; - try - { - dosdate = new DateTime(year, month, day, hour, minute, second); - } - catch(ArgumentOutOfRangeException) - { - dosdate = new DateTime(1980, 1, 1, 0, 0, 0); - } + try { dosdate = new DateTime(year, month, day, hour, minute, second); } + catch(ArgumentOutOfRangeException) { dosdate = new DateTime(1980, 1, 1, 0, 0, 0); } return dosdate; } @@ -219,7 +221,9 @@ public static DateTime AppleDoubleToDateTime(ulong AppleDoubleTimeStamp) return AppleDoubleEpoch.AddSeconds(AppleDoubleTimeStamp); } - 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; @@ -229,20 +233,16 @@ public static DateTime ECMAToDateTime(ushort typeAndTimeZone, short year, byte m ushort preOffset = (ushort)(typeAndTimeZone & 0xFFF); short offset; - if((preOffset & 0x800) == 0x800) - { - offset = (short)(preOffset | 0xF000); - } - else - offset = (short)(preOffset & 0x7FF); + if((preOffset & 0x800) == 0x800) { offset = (short)(preOffset | 0xF000); } + else offset = (short)(preOffset & 0x7FF); if(offset == -2047) return new DateTime(year, month, day, hour, minute, second, DateTimeKind.Unspecified).AddTicks(ticks); - if(offset < -1440 || offset > 1440) - offset = 0; + if(offset < -1440 || offset > 1440) offset = 0; - return new DateTimeOffset(year, month, day, hour, minute, second, new TimeSpan(0, offset, 0)).AddTicks(ticks).DateTime; + return new DateTimeOffset(year, month, day, hour, minute, second, new TimeSpan(0, offset, 0)) + .AddTicks(ticks).DateTime; } public static DateTime UNIXHrTimeToDateTime(ulong HRTimeStamp) @@ -252,27 +252,24 @@ public static DateTime UNIXHrTimeToDateTime(ulong HRTimeStamp) public static DateTime OS9ToDateTime(byte[] date) { - if(date == null || (date.Length != 3 && date.Length != 5)) - return DateTime.MinValue; + if(date == null || (date.Length != 3 && date.Length != 5)) return DateTime.MinValue; DateTime os9date; try { - 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); - } - catch(ArgumentOutOfRangeException) - { - os9date = new DateTime(1900, 0, 0, 0, 0, 0); + 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); } + catch(ArgumentOutOfRangeException) { os9date = new DateTime(1900, 0, 0, 0, 0, 0); } return os9date; } public static DateTime LifToDateTime(byte[] date) { - if(date == null || date.Length != 6) - return new DateTime(1970, 1, 1, 0, 0, 0); + if(date == null || date.Length != 6) return new DateTime(1970, 1, 1, 0, 0, 0); return LifToDateTime(date[0], date[1], date[2], date[3], date[4], date[5]); } @@ -288,18 +285,12 @@ public static DateTime LifToDateTime(byte year, byte month, byte day, byte hour, int ihour = (hour >> 4) * 10 + (hour & 0xF); int isecond = (second >> 4) * 10 + (second & 0xF); - if(iyear >= 70) - iyear += 1900; - else - iyear += 2000; + if(iyear >= 70) iyear += 1900; + else iyear += 2000; return new DateTime(iyear, imonth, iday, ihour, iminute, isecond); } - catch(ArgumentOutOfRangeException) - { - return new DateTime(1970, 1, 1, 0, 0, 0); - } + catch(ArgumentOutOfRangeException) { return new DateTime(1970, 1, 1, 0, 0, 0); } } } -} - +} \ No newline at end of file diff --git a/EndianAwareBinaryReader.cs b/EndianAwareBinaryReader.cs index 194ad7f25..b0d6366ff 100644 --- a/EndianAwareBinaryReader.cs +++ b/EndianAwareBinaryReader.cs @@ -41,86 +41,76 @@ public class EndianAwareBinaryReader : BinaryReader { readonly byte[] buffer = new byte[8]; - public EndianAwareBinaryReader(Stream input, Encoding encoding, bool isLittleEndian) - : base(input, encoding) + public EndianAwareBinaryReader(Stream input, Encoding encoding, bool isLittleEndian) : base(input, encoding) { IsLittleEndian = isLittleEndian; } - public EndianAwareBinaryReader(Stream input, bool isLittleEndian) - : this(input, Encoding.UTF8, isLittleEndian) - { - } + public EndianAwareBinaryReader(Stream input, bool isLittleEndian) : + this(input, Encoding.UTF8, isLittleEndian) { } - public bool IsLittleEndian - { - get; - set; - } + public bool IsLittleEndian { get; set; } public override double ReadDouble() { - if(IsLittleEndian) - return base.ReadDouble(); + if(IsLittleEndian) return base.ReadDouble(); + FillMyBuffer(8); return BitConverter.ToDouble(buffer.Take(8).Reverse().ToArray(), 0); } public override short ReadInt16() { - if(IsLittleEndian) - return base.ReadInt16(); + if(IsLittleEndian) return base.ReadInt16(); + FillMyBuffer(2); return BitConverter.ToInt16(buffer.Take(2).Reverse().ToArray(), 0); - } public override int ReadInt32() { - if(IsLittleEndian) - return base.ReadInt32(); + if(IsLittleEndian) return base.ReadInt32(); + FillMyBuffer(4); return BitConverter.ToInt32(buffer.Take(4).Reverse().ToArray(), 0); - } public override long ReadInt64() { - if(IsLittleEndian) - return base.ReadInt64(); + if(IsLittleEndian) return base.ReadInt64(); + FillMyBuffer(8); return BitConverter.ToInt64(buffer.Take(8).Reverse().ToArray(), 0); - } public override float ReadSingle() { - if(IsLittleEndian) - return base.ReadSingle(); + if(IsLittleEndian) return base.ReadSingle(); + FillMyBuffer(4); return BitConverter.ToSingle(buffer.Take(4).Reverse().ToArray(), 0); } public override ushort ReadUInt16() { - if(IsLittleEndian) - return base.ReadUInt16(); + if(IsLittleEndian) return base.ReadUInt16(); + FillMyBuffer(2); return BitConverter.ToUInt16(buffer.Take(2).Reverse().ToArray(), 0); } public override uint ReadUInt32() { - if(IsLittleEndian) - return base.ReadUInt32(); + if(IsLittleEndian) return base.ReadUInt32(); + FillMyBuffer(4); return BitConverter.ToUInt32(buffer.Take(4).Reverse().ToArray(), 0); } public override ulong ReadUInt64() { - if(IsLittleEndian) - return base.ReadUInt64(); + if(IsLittleEndian) return base.ReadUInt64(); + FillMyBuffer(8); return BitConverter.ToUInt64(buffer.Take(8).Reverse().ToArray(), 0); } @@ -132,10 +122,8 @@ void FillMyBuffer(int numBytes) if(numBytes == 1) { num2 = BaseStream.ReadByte(); - if(num2 == -1) - { - throw new EndOfStreamException("Attempted to read past the end of the stream."); - } + if(num2 == -1) { throw new EndOfStreamException("Attempted to read past the end of the stream."); } + buffer[0] = (byte)num2; } else @@ -143,10 +131,8 @@ void FillMyBuffer(int numBytes) do { num2 = BaseStream.Read(buffer, offset, numBytes - offset); - if(num2 == 0) - { - throw new EndOfStreamException("Attempted to read past the end of the stream."); - } + if(num2 == 0) { throw new EndOfStreamException("Attempted to read past the end of the stream."); } + offset += num2; } while(offset < numBytes); diff --git a/Extents/ExtentsByte.cs b/Extents/ExtentsByte.cs index 0d948ac52..59a38066c 100644 --- a/Extents/ExtentsByte.cs +++ b/Extents/ExtentsByte.cs @@ -50,7 +50,10 @@ public ExtentsByte(List> list) backend = list.OrderBy(t => t.Item1).ToList(); } - public int Count { get { return backend.Count; } } + public int Count + { + get { return backend.Count; } + } public void Add(byte item) { @@ -61,8 +64,7 @@ public void Add(byte item) for(int i = 0; i < backend.Count; i++) { // Already contained in an extent - if(item >= backend[i].Item1 && item <= backend[i].Item2) - return; + if(item >= backend[i].Item1 && item <= backend[i].Item2) return; // Expands existing extent start if(item == backend[i].Item1 - 1) @@ -74,8 +76,7 @@ public void Add(byte item) removeTwo = backend[i - 1]; itemToAdd = new Tuple(backend[i - 1].Item1, backend[i].Item2); } - else - itemToAdd = new Tuple(item, backend[i].Item2); + else itemToAdd = new Tuple(item, backend[i].Item2); break; } @@ -90,8 +91,7 @@ public void Add(byte item) removeTwo = backend[i + 1]; itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); } - else - itemToAdd = new Tuple(backend[i].Item1, item); + else itemToAdd = new Tuple(backend[i].Item1, item); break; } @@ -103,8 +103,7 @@ public void Add(byte item) backend.Remove(removeTwo); backend.Add(itemToAdd); } - else - backend.Add(new Tuple(item, item)); + else backend.Add(new Tuple(item, item)); // Sort backend = backend.OrderBy(t => t.Item1).ToList(); @@ -118,21 +117,17 @@ public void Add(byte start, byte end) public void Add(byte start, byte end, bool run) { byte realEnd; - if(run) - realEnd = (byte)(start + end - 1); - else - realEnd = end; + if(run) realEnd = (byte)(start + end - 1); + else realEnd = end; // TODO: Optimize this - for(byte t = start; t <= realEnd; t++) - Add(t); + for(byte t = start; t <= realEnd; t++) Add(t); } public bool Contains(byte item) { - foreach(Tuple extent in backend) - if(item >= extent.Item1 && item <= extent.Item2) - return true; + foreach(Tuple extent in backend) if(item >= extent.Item1 && item <= extent.Item2) return true; + return false; } @@ -183,14 +178,11 @@ public bool Remove(byte item) } // Item not found - if(toRemove == null) - return false; + if(toRemove == null) return false; backend.Remove(toRemove); - if(toAddOne != null) - backend.Add(toAddOne); - if(toAddTwo != null) - backend.Add(toAddTwo); + if(toAddOne != null) backend.Add(toAddOne); + if(toAddTwo != null) backend.Add(toAddTwo); // Sort backend = backend.OrderBy(t => t.Item1).ToList(); @@ -214,7 +206,8 @@ public bool GetStart(byte item, out byte start) return true; } } + return false; } } -} +} \ No newline at end of file diff --git a/Extents/ExtentsInt.cs b/Extents/ExtentsInt.cs index 6e6842f30..bbdab8ab9 100644 --- a/Extents/ExtentsInt.cs +++ b/Extents/ExtentsInt.cs @@ -50,7 +50,10 @@ public ExtentsInt(List> list) backend = list.OrderBy(t => t.Item1).ToList(); } - public int Count { get { return backend.Count; } } + public int Count + { + get { return backend.Count; } + } public void Add(int item) { @@ -61,8 +64,7 @@ public void Add(int item) for(int i = 0; i < backend.Count; i++) { // Already contained in an extent - if(item >= backend[i].Item1 && item <= backend[i].Item2) - return; + if(item >= backend[i].Item1 && item <= backend[i].Item2) return; // Expands existing extent start if(item == backend[i].Item1 - 1) @@ -74,8 +76,7 @@ public void Add(int item) removeTwo = backend[i - 1]; itemToAdd = new Tuple(backend[i - 1].Item1, backend[i].Item2); } - else - itemToAdd = new Tuple(item, backend[i].Item2); + else itemToAdd = new Tuple(item, backend[i].Item2); break; } @@ -90,8 +91,7 @@ public void Add(int item) removeTwo = backend[i + 1]; itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); } - else - itemToAdd = new Tuple(backend[i].Item1, item); + else itemToAdd = new Tuple(backend[i].Item1, item); break; } @@ -103,8 +103,7 @@ public void Add(int item) backend.Remove(removeTwo); backend.Add(itemToAdd); } - else - backend.Add(new Tuple(item, item)); + else backend.Add(new Tuple(item, item)); // Sort backend = backend.OrderBy(t => t.Item1).ToList(); @@ -118,21 +117,17 @@ public void Add(int start, int end) public void Add(int start, int end, bool run) { int realEnd; - if(run) - realEnd = start + end - 1; - else - realEnd = end; + if(run) realEnd = start + end - 1; + else realEnd = end; // TODO: Optimize this - for(int t = start; t <= realEnd; t++) - Add(t); + for(int t = start; t <= realEnd; t++) Add(t); } public bool Contains(int item) { - foreach(Tuple extent in backend) - if(item >= extent.Item1 && item <= extent.Item2) - return true; + foreach(Tuple extent in backend) if(item >= extent.Item1 && item <= extent.Item2) return true; + return false; } @@ -183,14 +178,11 @@ public bool Remove(int item) } // Item not found - if(toRemove == null) - return false; + if(toRemove == null) return false; backend.Remove(toRemove); - if(toAddOne != null) - backend.Add(toAddOne); - if(toAddTwo != null) - backend.Add(toAddTwo); + if(toAddOne != null) backend.Add(toAddOne); + if(toAddTwo != null) backend.Add(toAddTwo); // Sort backend = backend.OrderBy(t => t.Item1).ToList(); @@ -214,7 +206,8 @@ public bool GetStart(int item, out int start) return true; } } + return false; } } -} +} \ No newline at end of file diff --git a/Extents/ExtentsLong.cs b/Extents/ExtentsLong.cs index c139ee24e..b29e53639 100644 --- a/Extents/ExtentsLong.cs +++ b/Extents/ExtentsLong.cs @@ -50,7 +50,10 @@ public ExtentsLong(List> list) backend = list.OrderBy(t => t.Item1).ToList(); } - public int Count { get { return backend.Count; } } + public int Count + { + get { return backend.Count; } + } public void Add(long item) { @@ -61,8 +64,7 @@ public void Add(long item) for(int i = 0; i < backend.Count; i++) { // Already contained in an extent - if(item >= backend[i].Item1 && item <= backend[i].Item2) - return; + if(item >= backend[i].Item1 && item <= backend[i].Item2) return; // Expands existing extent start if(item == backend[i].Item1 - 1) @@ -74,8 +76,7 @@ public void Add(long item) removeTwo = backend[i - 1]; itemToAdd = new Tuple(backend[i - 1].Item1, backend[i].Item2); } - else - itemToAdd = new Tuple(item, backend[i].Item2); + else itemToAdd = new Tuple(item, backend[i].Item2); break; } @@ -90,8 +91,7 @@ public void Add(long item) removeTwo = backend[i + 1]; itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); } - else - itemToAdd = new Tuple(backend[i].Item1, item); + else itemToAdd = new Tuple(backend[i].Item1, item); break; } @@ -103,8 +103,7 @@ public void Add(long item) backend.Remove(removeTwo); backend.Add(itemToAdd); } - else - backend.Add(new Tuple(item, item)); + else backend.Add(new Tuple(item, item)); // Sort backend = backend.OrderBy(t => t.Item1).ToList(); @@ -118,21 +117,17 @@ public void Add(long start, long end) public void Add(long start, long end, bool run) { long realEnd; - if(run) - realEnd = start + end - 1; - else - realEnd = end; + if(run) realEnd = start + end - 1; + else realEnd = end; // TODO: Optimize this - for(long t = start; t <= realEnd; t++) - Add(t); + for(long t = start; t <= realEnd; t++) Add(t); } public bool Contains(long item) { - foreach(Tuple extent in backend) - if(item >= extent.Item1 && item <= extent.Item2) - return true; + foreach(Tuple extent in backend) if(item >= extent.Item1 && item <= extent.Item2) return true; + return false; } @@ -183,14 +178,11 @@ public bool Remove(long item) } // Item not found - if(toRemove == null) - return false; + if(toRemove == null) return false; backend.Remove(toRemove); - if(toAddOne != null) - backend.Add(toAddOne); - if(toAddTwo != null) - backend.Add(toAddTwo); + if(toAddOne != null) backend.Add(toAddOne); + if(toAddTwo != null) backend.Add(toAddTwo); // Sort backend = backend.OrderBy(t => t.Item1).ToList(); @@ -214,7 +206,8 @@ public bool GetStart(long item, out long start) return true; } } + return false; } } -} +} \ No newline at end of file diff --git a/Extents/ExtentsSByte.cs b/Extents/ExtentsSByte.cs index b67a2c3c6..df33ce34f 100644 --- a/Extents/ExtentsSByte.cs +++ b/Extents/ExtentsSByte.cs @@ -50,7 +50,10 @@ public ExtentsSByte(List> list) backend = list.OrderBy(t => t.Item1).ToList(); } - public int Count { get { return backend.Count; } } + public int Count + { + get { return backend.Count; } + } public void Add(sbyte item) { @@ -61,8 +64,7 @@ public void Add(sbyte item) for(int i = 0; i < backend.Count; i++) { // Already contained in an extent - if(item >= backend[i].Item1 && item <= backend[i].Item2) - return; + if(item >= backend[i].Item1 && item <= backend[i].Item2) return; // Expands existing extent start if(item == backend[i].Item1 - 1) @@ -74,8 +76,7 @@ public void Add(sbyte item) removeTwo = backend[i - 1]; itemToAdd = new Tuple(backend[i - 1].Item1, backend[i].Item2); } - else - itemToAdd = new Tuple(item, backend[i].Item2); + else itemToAdd = new Tuple(item, backend[i].Item2); break; } @@ -90,8 +91,7 @@ public void Add(sbyte item) removeTwo = backend[i + 1]; itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); } - else - itemToAdd = new Tuple(backend[i].Item1, item); + else itemToAdd = new Tuple(backend[i].Item1, item); break; } @@ -103,8 +103,7 @@ public void Add(sbyte item) backend.Remove(removeTwo); backend.Add(itemToAdd); } - else - backend.Add(new Tuple(item, item)); + else backend.Add(new Tuple(item, item)); // Sort backend = backend.OrderBy(t => t.Item1).ToList(); @@ -118,21 +117,17 @@ public void Add(sbyte start, sbyte end) public void Add(sbyte start, sbyte end, bool run) { sbyte realEnd; - if(run) - realEnd = (sbyte)(start + end - 1); - else - realEnd = end; + if(run) realEnd = (sbyte)(start + end - 1); + else realEnd = end; // TODO: Optimize this - for(sbyte t = start; t <= realEnd; t++) - Add(t); + for(sbyte t = start; t <= realEnd; t++) Add(t); } public bool Contains(sbyte item) { - foreach(Tuple extent in backend) - if(item >= extent.Item1 && item <= extent.Item2) - return true; + foreach(Tuple extent in backend) if(item >= extent.Item1 && item <= extent.Item2) return true; + return false; } @@ -183,14 +178,11 @@ public bool Remove(sbyte item) } // Item not found - if(toRemove == null) - return false; + if(toRemove == null) return false; backend.Remove(toRemove); - if(toAddOne != null) - backend.Add(toAddOne); - if(toAddTwo != null) - backend.Add(toAddTwo); + if(toAddOne != null) backend.Add(toAddOne); + if(toAddTwo != null) backend.Add(toAddTwo); // Sort backend = backend.OrderBy(t => t.Item1).ToList(); @@ -214,7 +206,8 @@ public bool GetStart(sbyte item, out sbyte start) return true; } } + return false; } } -} +} \ No newline at end of file diff --git a/Extents/ExtentsShort.cs b/Extents/ExtentsShort.cs index 62065c87a..943e4a55b 100644 --- a/Extents/ExtentsShort.cs +++ b/Extents/ExtentsShort.cs @@ -50,7 +50,10 @@ public ExtentsShort(List> list) backend = list.OrderBy(t => t.Item1).ToList(); } - public int Count { get { return backend.Count; } } + public int Count + { + get { return backend.Count; } + } public void Add(short item) { @@ -61,8 +64,7 @@ public void Add(short item) for(int i = 0; i < backend.Count; i++) { // Already contained in an extent - if(item >= backend[i].Item1 && item <= backend[i].Item2) - return; + if(item >= backend[i].Item1 && item <= backend[i].Item2) return; // Expands existing extent start if(item == backend[i].Item1 - 1) @@ -74,8 +76,7 @@ public void Add(short item) removeTwo = backend[i - 1]; itemToAdd = new Tuple(backend[i - 1].Item1, backend[i].Item2); } - else - itemToAdd = new Tuple(item, backend[i].Item2); + else itemToAdd = new Tuple(item, backend[i].Item2); break; } @@ -90,8 +91,7 @@ public void Add(short item) removeTwo = backend[i + 1]; itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); } - else - itemToAdd = new Tuple(backend[i].Item1, item); + else itemToAdd = new Tuple(backend[i].Item1, item); break; } @@ -103,8 +103,7 @@ public void Add(short item) backend.Remove(removeTwo); backend.Add(itemToAdd); } - else - backend.Add(new Tuple(item, item)); + else backend.Add(new Tuple(item, item)); // Sort backend = backend.OrderBy(t => t.Item1).ToList(); @@ -118,21 +117,17 @@ public void Add(short start, short end) public void Add(short start, short end, bool run) { short realEnd; - if(run) - realEnd = (short)(start + end - 1); - else - realEnd = end; + if(run) realEnd = (short)(start + end - 1); + else realEnd = end; // TODO: Optimize this - for(short t = start; t <= realEnd; t++) - Add(t); + for(short t = start; t <= realEnd; t++) Add(t); } public bool Contains(short item) { - foreach(Tuple extent in backend) - if(item >= extent.Item1 && item <= extent.Item2) - return true; + foreach(Tuple extent in backend) if(item >= extent.Item1 && item <= extent.Item2) return true; + return false; } @@ -183,14 +178,11 @@ public bool Remove(short item) } // Item not found - if(toRemove == null) - return false; + if(toRemove == null) return false; backend.Remove(toRemove); - if(toAddOne != null) - backend.Add(toAddOne); - if(toAddTwo != null) - backend.Add(toAddTwo); + if(toAddOne != null) backend.Add(toAddOne); + if(toAddTwo != null) backend.Add(toAddTwo); // Sort backend = backend.OrderBy(t => t.Item1).ToList(); @@ -214,7 +206,8 @@ public bool GetStart(short item, out short start) return true; } } + return false; } } -} +} \ No newline at end of file diff --git a/Extents/ExtentsUInt.cs b/Extents/ExtentsUInt.cs index 197eadfc7..ccda61f8e 100644 --- a/Extents/ExtentsUInt.cs +++ b/Extents/ExtentsUInt.cs @@ -50,7 +50,10 @@ public ExtentsUInt(List> list) backend = list.OrderBy(t => t.Item1).ToList(); } - public int Count { get { return backend.Count; } } + public int Count + { + get { return backend.Count; } + } public void Add(uint item) { @@ -61,8 +64,7 @@ public void Add(uint item) for(int i = 0; i < backend.Count; i++) { // Already contained in an extent - if(item >= backend[i].Item1 && item <= backend[i].Item2) - return; + if(item >= backend[i].Item1 && item <= backend[i].Item2) return; // Expands existing extent start if(item == backend[i].Item1 - 1) @@ -74,8 +76,7 @@ public void Add(uint item) removeTwo = backend[i - 1]; itemToAdd = new Tuple(backend[i - 1].Item1, backend[i].Item2); } - else - itemToAdd = new Tuple(item, backend[i].Item2); + else itemToAdd = new Tuple(item, backend[i].Item2); break; } @@ -90,8 +91,7 @@ public void Add(uint item) removeTwo = backend[i + 1]; itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); } - else - itemToAdd = new Tuple(backend[i].Item1, item); + else itemToAdd = new Tuple(backend[i].Item1, item); break; } @@ -103,8 +103,7 @@ public void Add(uint item) backend.Remove(removeTwo); backend.Add(itemToAdd); } - else - backend.Add(new Tuple(item, item)); + else backend.Add(new Tuple(item, item)); // Sort backend = backend.OrderBy(t => t.Item1).ToList(); @@ -118,21 +117,17 @@ public void Add(uint start, uint end) public void Add(uint start, uint end, bool run) { uint realEnd; - if(run) - realEnd = start + end - 1; - else - realEnd = end; + if(run) realEnd = start + end - 1; + else realEnd = end; // TODO: Optimize this - for(uint t = start; t <= realEnd; t++) - Add(t); + for(uint t = start; t <= realEnd; t++) Add(t); } public bool Contains(uint item) { - foreach(Tuple extent in backend) - if(item >= extent.Item1 && item <= extent.Item2) - return true; + foreach(Tuple extent in backend) if(item >= extent.Item1 && item <= extent.Item2) return true; + return false; } @@ -183,14 +178,11 @@ public bool Remove(uint item) } // Item not found - if(toRemove == null) - return false; + if(toRemove == null) return false; backend.Remove(toRemove); - if(toAddOne != null) - backend.Add(toAddOne); - if(toAddTwo != null) - backend.Add(toAddTwo); + if(toAddOne != null) backend.Add(toAddOne); + if(toAddTwo != null) backend.Add(toAddTwo); // Sort backend = backend.OrderBy(t => t.Item1).ToList(); @@ -214,7 +206,8 @@ public bool GetStart(uint item, out uint start) return true; } } + return false; } } -} +} \ No newline at end of file diff --git a/Extents/ExtentsULong.cs b/Extents/ExtentsULong.cs index f8aa06851..76a242ace 100644 --- a/Extents/ExtentsULong.cs +++ b/Extents/ExtentsULong.cs @@ -50,7 +50,10 @@ public ExtentsULong(List> list) backend = list.OrderBy(t => t.Item1).ToList(); } - public int Count { get { return backend.Count; } } + public int Count + { + get { return backend.Count; } + } public void Add(ulong item) { @@ -61,8 +64,7 @@ public void Add(ulong item) for(int i = 0; i < backend.Count; i++) { // Already contained in an extent - if(item >= backend[i].Item1 && item <= backend[i].Item2) - return; + if(item >= backend[i].Item1 && item <= backend[i].Item2) return; // Expands existing extent start if(item == backend[i].Item1 - 1) @@ -74,8 +76,7 @@ public void Add(ulong item) removeTwo = backend[i - 1]; itemToAdd = new Tuple(backend[i - 1].Item1, backend[i].Item2); } - else - itemToAdd = new Tuple(item, backend[i].Item2); + else itemToAdd = new Tuple(item, backend[i].Item2); break; } @@ -90,8 +91,7 @@ public void Add(ulong item) removeTwo = backend[i + 1]; itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); } - else - itemToAdd = new Tuple(backend[i].Item1, item); + else itemToAdd = new Tuple(backend[i].Item1, item); break; } @@ -103,8 +103,7 @@ public void Add(ulong item) backend.Remove(removeTwo); backend.Add(itemToAdd); } - else - backend.Add(new Tuple(item, item)); + else backend.Add(new Tuple(item, item)); // Sort backend = backend.OrderBy(t => t.Item1).ToList(); @@ -118,21 +117,17 @@ public void Add(ulong start, ulong end) public void Add(ulong start, ulong end, bool run) { ulong realEnd; - if(run) - realEnd = start + end - 1; - else - realEnd = end; + if(run) realEnd = start + end - 1; + else realEnd = end; // TODO: Optimize this - for(ulong t = start; t <= realEnd; t++) - Add(t); + for(ulong t = start; t <= realEnd; t++) Add(t); } public bool Contains(ulong item) { - foreach(Tuple extent in backend) - if(item >= extent.Item1 && item <= extent.Item2) - return true; + foreach(Tuple extent in backend) if(item >= extent.Item1 && item <= extent.Item2) return true; + return false; } @@ -183,14 +178,11 @@ public bool Remove(ulong item) } // Item not found - if(toRemove == null) - return false; + if(toRemove == null) return false; backend.Remove(toRemove); - if(toAddOne != null) - backend.Add(toAddOne); - if(toAddTwo != null) - backend.Add(toAddTwo); + if(toAddOne != null) backend.Add(toAddOne); + if(toAddTwo != null) backend.Add(toAddTwo); // Sort backend = backend.OrderBy(t => t.Item1).ToList(); @@ -214,7 +206,8 @@ public bool GetStart(ulong item, out ulong start) return true; } } + return false; } } -} +} \ No newline at end of file diff --git a/Extents/ExtentsUShort.cs b/Extents/ExtentsUShort.cs index 27b936f66..d8720d392 100644 --- a/Extents/ExtentsUShort.cs +++ b/Extents/ExtentsUShort.cs @@ -50,7 +50,10 @@ public ExtentsUShort(List> list) backend = list.OrderBy(t => t.Item1).ToList(); } - public int Count { get { return backend.Count; } } + public int Count + { + get { return backend.Count; } + } public void Add(ushort item) { @@ -61,8 +64,7 @@ public void Add(ushort item) for(int i = 0; i < backend.Count; i++) { // Already contained in an extent - if(item >= backend[i].Item1 && item <= backend[i].Item2) - return; + if(item >= backend[i].Item1 && item <= backend[i].Item2) return; // Expands existing extent start if(item == backend[i].Item1 - 1) @@ -74,8 +76,7 @@ public void Add(ushort item) removeTwo = backend[i - 1]; itemToAdd = new Tuple(backend[i - 1].Item1, backend[i].Item2); } - else - itemToAdd = new Tuple(item, backend[i].Item2); + else itemToAdd = new Tuple(item, backend[i].Item2); break; } @@ -90,8 +91,7 @@ public void Add(ushort item) removeTwo = backend[i + 1]; itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); } - else - itemToAdd = new Tuple(backend[i].Item1, item); + else itemToAdd = new Tuple(backend[i].Item1, item); break; } @@ -103,8 +103,7 @@ public void Add(ushort item) backend.Remove(removeTwo); backend.Add(itemToAdd); } - else - backend.Add(new Tuple(item, item)); + else backend.Add(new Tuple(item, item)); // Sort backend = backend.OrderBy(t => t.Item1).ToList(); @@ -118,21 +117,18 @@ public void Add(ushort start, ushort end) public void Add(ushort start, ushort end, bool run) { ushort realEnd; - if(run) - realEnd = (ushort)(start + end - 1); - else - realEnd = end; + if(run) realEnd = (ushort)(start + end - 1); + else realEnd = end; // TODO: Optimize this - for(ushort t = start; t <= realEnd; t++) - Add(t); + for(ushort t = start; t <= realEnd; t++) Add(t); } public bool Contains(ushort item) { foreach(Tuple extent in backend) - if(item >= extent.Item1 && item <= extent.Item2) - return true; + if(item >= extent.Item1 && item <= extent.Item2) return true; + return false; } @@ -183,14 +179,11 @@ public bool Remove(ushort item) } // Item not found - if(toRemove == null) - return false; + if(toRemove == null) return false; backend.Remove(toRemove); - if(toAddOne != null) - backend.Add(toAddOne); - if(toAddTwo != null) - backend.Add(toAddTwo); + if(toAddOne != null) backend.Add(toAddOne); + if(toAddTwo != null) backend.Add(toAddTwo); // Sort backend = backend.OrderBy(t => t.Item1).ToList(); @@ -214,7 +207,8 @@ public bool GetStart(ushort item, out ushort start) return true; } } + return false; } } -} +} \ No newline at end of file diff --git a/PrintHex.cs b/PrintHex.cs index 01ffed386..e5e8046a7 100644 --- a/PrintHex.cs +++ b/PrintHex.cs @@ -75,14 +75,13 @@ public static string ByteArrayToHexArrayString(byte[] array, int width) counter = 0; subcounter = 0; } - else - counter++; + else counter++; } + sb.AppendLine(); sb.AppendLine(); return sb.ToString(); } } -} - +} \ No newline at end of file diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index c93539f7d..c6eb046fa 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -54,5 +54,4 @@ // if desired. See the Mono documentation for more information about signing. //[assembly: AssemblyDelaySign(false)] -//[assembly: AssemblyKeyFile("")] - +//[assembly: AssemblyKeyFile("")] \ No newline at end of file diff --git a/StringHandlers.cs b/StringHandlers.cs index d2bebcda7..09e42989d 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -55,8 +55,7 @@ public static string CToString(byte[] CString) /// Encoding. public static string CToString(byte[] CString, Encoding encoding, bool twoBytes = false, int start = 0) { - if(CString == null) - return null; + if(CString == null) return null; int len = 0; @@ -71,11 +70,10 @@ public static string CToString(byte[] CString, Encoding encoding, bool twoBytes len++; break; } - // if((i + 1) == CString.Length) -// break; + // if((i + 1) == CString.Length) + // break; } - else - break; + else break; } len++; @@ -105,17 +103,15 @@ public static string PascalToString(byte[] PascalString) /// Encoding. public static string PascalToString(byte[] PascalString, Encoding encoding, int start = 0) { - if(PascalString == null) - return null; + if(PascalString == null) return null; byte length = PascalString[start]; int len = 0; for(int i = start + 1; i < length + 1 && i < PascalString.Length; i++) { - if(PascalString[i] == 0) - break; - + if(PascalString[i] == 0) break; + len++; } @@ -143,15 +139,13 @@ public static string SpacePaddedToString(byte[] SpacePaddedString) /// Encoding. public static string SpacePaddedToString(byte[] SpacePaddedString, Encoding encoding, int start = 0) { - if(SpacePaddedString == null) - return null; + if(SpacePaddedString == null) return null; int len = start; for(int i = SpacePaddedString.Length; i >= start; i--) { - if(i == start) - return ""; + if(i == start) return ""; if(SpacePaddedString[i - 1] != 0x20) { @@ -174,21 +168,16 @@ public static string DecompressUnicode(byte[] dstring) byte compId = dstring[0]; string temp = ""; - if(compId != 8 && compId != 16) - return null; + 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; + if(compId == 16) unicode = (ushort)(dstring[byteIndex++] << 8); + else unicode = 0; - if(byteIndex < dstring.Length) - unicode |= dstring[byteIndex++]; + if(byteIndex < dstring.Length) unicode |= dstring[byteIndex++]; - if(unicode == 0) - break; + if(unicode == 0) break; temp += Encoding.Unicode.GetString(System.BitConverter.GetBytes(unicode)); } @@ -196,5 +185,4 @@ public static string DecompressUnicode(byte[] dstring) return temp; } } -} - +} \ No newline at end of file diff --git a/Swapping.cs b/Swapping.cs index da3a9f44d..cfca315bc 100644 --- a/Swapping.cs +++ b/Swapping.cs @@ -138,4 +138,4 @@ public static int Swap(int x) return (x << 16) | ((x >> 16) & 0xFFFF); } } -} +} \ No newline at end of file From 90c6aa30c58fd5886bbf3e776138d3dbb940195b Mon Sep 17 00:00:00 2001 From: Michael D Date: Tue, 19 Dec 2017 22:16:31 +0100 Subject: [PATCH 058/217] Change signed shift to unsigned shift --- Swapping.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Swapping.cs b/Swapping.cs index cfca315bc..4cbccea69 100644 --- a/Swapping.cs +++ b/Swapping.cs @@ -134,8 +134,8 @@ public static uint Swap(uint x) public static int Swap(int x) { - x = (int)(((x << 8) & 0xFF00FF00) | ((x >> 8) & 0xFF00FF)); - return (x << 16) | ((x >> 16) & 0xFFFF); + x = (int)(((x << 8) & 0xFF00FF00) | (((uint)x >> 8) & 0xFF00FF)); + return (int)(((uint)x << 16) | (((uint)x >> 16) & 0xFFFF)); } } } \ No newline at end of file From be41a8d6043b41d61f582d15686fb4fd60b82423 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 20 Dec 2017 17:26:28 +0000 Subject: [PATCH 059/217] REFACTOR: Remove redundant parentheses. --- DateHandlers.cs | 6 +++--- StringHandlers.cs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/DateHandlers.cs b/DateHandlers.cs index 87160d81e..a13c5ffd1 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -173,7 +173,7 @@ public static DateTime UCSDPascalToDateTime(short dateRecord) { int year = ((dateRecord & 0xFE00) >> 9) + 1900; int day = (dateRecord & 0x01F0) >> 4; - int month = (dateRecord & 0x000F); + int month = dateRecord & 0x000F; DicConsole.DebugWriteLine("UCSDPascalToDateTime handler", "dateRecord = 0x{0:X4}, year = {1}, month = {2}, day = {3}", dateRecord, year, @@ -252,7 +252,7 @@ public static DateTime UNIXHrTimeToDateTime(ulong HRTimeStamp) public static DateTime OS9ToDateTime(byte[] date) { - if(date == null || (date.Length != 3 && date.Length != 5)) return DateTime.MinValue; + if(date == null || date.Length != 3 && date.Length != 5) return DateTime.MinValue; DateTime os9date; @@ -278,7 +278,7 @@ public static DateTime LifToDateTime(byte year, byte month, byte day, byte hour, { try { - int iyear = ((year >> 4) * 10 + (year & 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); diff --git a/StringHandlers.cs b/StringHandlers.cs index 09e42989d..c6ccc8875 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -65,7 +65,7 @@ public static string CToString(byte[] CString, Encoding encoding, bool twoBytes { if(twoBytes) { - if((i + 1) < CString.Length && CString[i + 1] == 0) + if(i + 1 < CString.Length && CString[i + 1] == 0) { len++; break; From d9cee2818fa32d1d0f420519368b3ca058fd00a5 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 20 Dec 2017 17:38:12 +0000 Subject: [PATCH 060/217] REFACTOR: Add parentheses to avoid non-obvious precedence. --- Swapping.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Swapping.cs b/Swapping.cs index 4cbccea69..75bec257e 100644 --- a/Swapping.cs +++ b/Swapping.cs @@ -105,9 +105,9 @@ public static uint PDPFromBigEndian(uint x) public static ulong Swap(ulong x) { - x = (x & 0x00000000FFFFFFFF) << 32 | (x & 0xFFFFFFFF00000000) >> 32; - x = (x & 0x0000FFFF0000FFFF) << 16 | (x & 0xFFFF0000FFFF0000) >> 16; - x = (x & 0x00FF00FF00FF00FF) << 8 | (x & 0xFF00FF00FF00FF00) >> 8; + x = ((x & 0x00000000FFFFFFFF) << 32) | ((x & 0xFFFFFFFF00000000) >> 32); + x = ((x & 0x0000FFFF0000FFFF) << 16) | ((x & 0xFFFF0000FFFF0000) >> 16); + x = ((x & 0x00FF00FF00FF00FF) << 8) | ((x & 0xFF00FF00FF00FF00) >> 8); return x; } From 3606b66aed8053526b81b0255e51bfaf9c49ba5a Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 20 Dec 2017 23:07:46 +0000 Subject: [PATCH 061/217] REFACTOR: Use preferred braces style. --- ArrayFill.cs | 12 +++--------- DateHandlers.cs | 2 +- EndianAwareBinaryReader.cs | 6 ++---- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/ArrayFill.cs b/ArrayFill.cs index 733a35136..e443f7bf9 100644 --- a/ArrayFill.cs +++ b/ArrayFill.cs @@ -39,12 +39,9 @@ public static void ArrayFill(T[] destinationArray, T value) public static void ArrayFill(T[] destinationArray, T[] value) { - if(destinationArray == null) { throw new ArgumentNullException(nameof(destinationArray)); } + if(destinationArray == null) throw new ArgumentNullException(nameof(destinationArray)); - if(value.Length > destinationArray.Length) - { - throw new ArgumentException("Length of value array must not be more than length of destination"); - } + if(value.Length > destinationArray.Length) throw new ArgumentException("Length of value array must not be more than length of destination"); // set the initial array value Array.Copy(value, destinationArray, value.Length); @@ -52,10 +49,7 @@ public static void ArrayFill(T[] destinationArray, T[] value) int arrayToFillHalfLength = destinationArray.Length / 2; int copyLength; - for(copyLength = value.Length; copyLength < arrayToFillHalfLength; copyLength <<= 1) - { - Array.Copy(destinationArray, 0, destinationArray, copyLength, copyLength); - } + for(copyLength = value.Length; copyLength < arrayToFillHalfLength; copyLength <<= 1) Array.Copy(destinationArray, 0, destinationArray, copyLength, copyLength); Array.Copy(destinationArray, 0, destinationArray, copyLength, destinationArray.Length - copyLength); } diff --git a/DateHandlers.cs b/DateHandlers.cs index a13c5ffd1..9d394fb0c 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -233,7 +233,7 @@ public static DateTime ECMAToDateTime(ushort typeAndTimeZone, short year, byte m ushort preOffset = (ushort)(typeAndTimeZone & 0xFFF); short offset; - if((preOffset & 0x800) == 0x800) { offset = (short)(preOffset | 0xF000); } + if((preOffset & 0x800) == 0x800) offset = (short)(preOffset | 0xF000); else offset = (short)(preOffset & 0x7FF); if(offset == -2047) diff --git a/EndianAwareBinaryReader.cs b/EndianAwareBinaryReader.cs index b0d6366ff..496f667a6 100644 --- a/EndianAwareBinaryReader.cs +++ b/EndianAwareBinaryReader.cs @@ -122,21 +122,19 @@ void FillMyBuffer(int numBytes) if(numBytes == 1) { num2 = BaseStream.ReadByte(); - if(num2 == -1) { throw new EndOfStreamException("Attempted to read past the end of the stream."); } + if(num2 == -1) throw new EndOfStreamException("Attempted to read past the end of the stream."); buffer[0] = (byte)num2; } else - { do { num2 = BaseStream.Read(buffer, offset, numBytes - offset); - if(num2 == 0) { throw new EndOfStreamException("Attempted to read past the end of the stream."); } + if(num2 == 0) throw new EndOfStreamException("Attempted to read past the end of the stream."); offset += num2; } while(offset < numBytes); - } } } } \ No newline at end of file From 0077694c7514dfb02281e63366de9fd6a6ae0108 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 21 Dec 2017 00:44:33 +0000 Subject: [PATCH 062/217] REFACTOR: Use preferred braces style. --- BigEndianMarshal.cs | 2 -- CompareBytes.cs | 2 -- Extents/ExtentsByte.cs | 2 -- Extents/ExtentsInt.cs | 2 -- Extents/ExtentsLong.cs | 2 -- Extents/ExtentsSByte.cs | 2 -- Extents/ExtentsShort.cs | 2 -- Extents/ExtentsUInt.cs | 2 -- Extents/ExtentsULong.cs | 2 -- Extents/ExtentsUShort.cs | 2 -- StringHandlers.cs | 2 -- 11 files changed, 22 deletions(-) diff --git a/BigEndianMarshal.cs b/BigEndianMarshal.cs index 84fadb932..0fd5c34a3 100644 --- a/BigEndianMarshal.cs +++ b/BigEndianMarshal.cs @@ -66,7 +66,6 @@ public static T SwapStructureMembersEndian(T str) where T : struct Type t = str.GetType(); FieldInfo[] fieldInfo = t.GetFields(); foreach(FieldInfo fi in fieldInfo) - { if(fi.FieldType == typeof(short)) { short int16 = (short)fi.GetValue(str); @@ -123,7 +122,6 @@ public static T SwapStructureMembersEndian(T str) where T : struct byte[] dbl_r = dbl_b.Reverse().ToArray(); fi.SetValueDirect(__makeref(str), BitConverter.ToDouble(dbl_r, 0)); } - } return str; } diff --git a/CompareBytes.cs b/CompareBytes.cs index 776fffa33..5eb96857e 100644 --- a/CompareBytes.cs +++ b/CompareBytes.cs @@ -54,13 +54,11 @@ public static void CompareBytes(out bool different, out bool sameSize, byte[] co else leastBytes = compareArray1.LongLength; for(long i = 0; i < leastBytes; i++) - { if(compareArray1[i] != compareArray2[i]) { different = true; return; } - } } } } \ No newline at end of file diff --git a/Extents/ExtentsByte.cs b/Extents/ExtentsByte.cs index 59a38066c..b7efb0f71 100644 --- a/Extents/ExtentsByte.cs +++ b/Extents/ExtentsByte.cs @@ -199,13 +199,11 @@ public bool GetStart(byte item, out byte start) { start = 0; foreach(Tuple extent in backend) - { if(item >= extent.Item1 && item <= extent.Item2) { start = extent.Item1; return true; } - } return false; } diff --git a/Extents/ExtentsInt.cs b/Extents/ExtentsInt.cs index bbdab8ab9..ee6b2d3cd 100644 --- a/Extents/ExtentsInt.cs +++ b/Extents/ExtentsInt.cs @@ -199,13 +199,11 @@ public bool GetStart(int item, out int start) { start = 0; foreach(Tuple extent in backend) - { if(item >= extent.Item1 && item <= extent.Item2) { start = extent.Item1; return true; } - } return false; } diff --git a/Extents/ExtentsLong.cs b/Extents/ExtentsLong.cs index b29e53639..1e2979ce4 100644 --- a/Extents/ExtentsLong.cs +++ b/Extents/ExtentsLong.cs @@ -199,13 +199,11 @@ public bool GetStart(long item, out long start) { start = 0; foreach(Tuple extent in backend) - { if(item >= extent.Item1 && item <= extent.Item2) { start = extent.Item1; return true; } - } return false; } diff --git a/Extents/ExtentsSByte.cs b/Extents/ExtentsSByte.cs index df33ce34f..8ecd6093d 100644 --- a/Extents/ExtentsSByte.cs +++ b/Extents/ExtentsSByte.cs @@ -199,13 +199,11 @@ public bool GetStart(sbyte item, out sbyte start) { start = 0; foreach(Tuple extent in backend) - { if(item >= extent.Item1 && item <= extent.Item2) { start = extent.Item1; return true; } - } return false; } diff --git a/Extents/ExtentsShort.cs b/Extents/ExtentsShort.cs index 943e4a55b..2e5f40158 100644 --- a/Extents/ExtentsShort.cs +++ b/Extents/ExtentsShort.cs @@ -199,13 +199,11 @@ public bool GetStart(short item, out short start) { start = 0; foreach(Tuple extent in backend) - { if(item >= extent.Item1 && item <= extent.Item2) { start = extent.Item1; return true; } - } return false; } diff --git a/Extents/ExtentsUInt.cs b/Extents/ExtentsUInt.cs index ccda61f8e..8fb27ffc6 100644 --- a/Extents/ExtentsUInt.cs +++ b/Extents/ExtentsUInt.cs @@ -199,13 +199,11 @@ public bool GetStart(uint item, out uint start) { start = 0; foreach(Tuple extent in backend) - { if(item >= extent.Item1 && item <= extent.Item2) { start = extent.Item1; return true; } - } return false; } diff --git a/Extents/ExtentsULong.cs b/Extents/ExtentsULong.cs index 76a242ace..68d5a3b64 100644 --- a/Extents/ExtentsULong.cs +++ b/Extents/ExtentsULong.cs @@ -199,13 +199,11 @@ public bool GetStart(ulong item, out ulong start) { start = 0; foreach(Tuple extent in backend) - { if(item >= extent.Item1 && item <= extent.Item2) { start = extent.Item1; return true; } - } return false; } diff --git a/Extents/ExtentsUShort.cs b/Extents/ExtentsUShort.cs index d8720d392..e74f0287c 100644 --- a/Extents/ExtentsUShort.cs +++ b/Extents/ExtentsUShort.cs @@ -200,13 +200,11 @@ public bool GetStart(ushort item, out ushort start) { start = 0; foreach(Tuple extent in backend) - { if(item >= extent.Item1 && item <= extent.Item2) { start = extent.Item1; return true; } - } return false; } diff --git a/StringHandlers.cs b/StringHandlers.cs index c6ccc8875..839cfea8f 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -62,7 +62,6 @@ public static string CToString(byte[] CString, Encoding encoding, bool twoBytes for(int i = start; i < CString.Length; i++) { if(CString[i] == 0) - { if(twoBytes) { if(i + 1 < CString.Length && CString[i + 1] == 0) @@ -74,7 +73,6 @@ public static string CToString(byte[] CString, Encoding encoding, bool twoBytes // break; } else break; - } len++; } From 4ce965e6cfa46d073b59438e428657baf9aefe85 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 21 Dec 2017 06:06:19 +0000 Subject: [PATCH 063/217] REFACTOR: Invert 'if' statement to reduce nesting. --- Extents/ExtentsByte.cs | 28 +++++++++++++--------------- Extents/ExtentsInt.cs | 28 +++++++++++++--------------- Extents/ExtentsLong.cs | 28 +++++++++++++--------------- Extents/ExtentsSByte.cs | 28 +++++++++++++--------------- Extents/ExtentsShort.cs | 28 +++++++++++++--------------- Extents/ExtentsUInt.cs | 28 +++++++++++++--------------- Extents/ExtentsULong.cs | 28 +++++++++++++--------------- Extents/ExtentsUShort.cs | 28 +++++++++++++--------------- StringHandlers.cs | 9 ++++----- 9 files changed, 108 insertions(+), 125 deletions(-) diff --git a/Extents/ExtentsByte.cs b/Extents/ExtentsByte.cs index b7efb0f71..ad6e549bf 100644 --- a/Extents/ExtentsByte.cs +++ b/Extents/ExtentsByte.cs @@ -82,19 +82,18 @@ public void Add(byte item) } // Expands existing extent end - if(item == backend[i].Item2 + 1) - { - removeOne = backend[i]; + if(item != backend[i].Item2 + 1) continue; - if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) - { - removeTwo = backend[i + 1]; - itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); - } - else itemToAdd = new Tuple(backend[i].Item1, item); + removeOne = backend[i]; - break; + if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) + { + removeTwo = backend[i + 1]; + itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); } + else itemToAdd = new Tuple(backend[i].Item1, item); + + break; } if(itemToAdd != null) @@ -170,11 +169,10 @@ public bool Remove(byte item) } // Extent is only element - if(item == extent.Item1 && item == extent.Item2) - { - toRemove = extent; - break; - } + if(item != extent.Item1 || item != extent.Item2) continue; + + toRemove = extent; + break; } // Item not found diff --git a/Extents/ExtentsInt.cs b/Extents/ExtentsInt.cs index ee6b2d3cd..ad651ff6e 100644 --- a/Extents/ExtentsInt.cs +++ b/Extents/ExtentsInt.cs @@ -82,19 +82,18 @@ public void Add(int item) } // Expands existing extent end - if(item == backend[i].Item2 + 1) - { - removeOne = backend[i]; + if(item != backend[i].Item2 + 1) continue; - if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) - { - removeTwo = backend[i + 1]; - itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); - } - else itemToAdd = new Tuple(backend[i].Item1, item); + removeOne = backend[i]; - break; + if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) + { + removeTwo = backend[i + 1]; + itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); } + else itemToAdd = new Tuple(backend[i].Item1, item); + + break; } if(itemToAdd != null) @@ -170,11 +169,10 @@ public bool Remove(int item) } // Extent is only element - if(item == extent.Item1 && item == extent.Item2) - { - toRemove = extent; - break; - } + if(item != extent.Item1 || item != extent.Item2) continue; + + toRemove = extent; + break; } // Item not found diff --git a/Extents/ExtentsLong.cs b/Extents/ExtentsLong.cs index 1e2979ce4..85fdf56d6 100644 --- a/Extents/ExtentsLong.cs +++ b/Extents/ExtentsLong.cs @@ -82,19 +82,18 @@ public void Add(long item) } // Expands existing extent end - if(item == backend[i].Item2 + 1) - { - removeOne = backend[i]; + if(item != backend[i].Item2 + 1) continue; - if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) - { - removeTwo = backend[i + 1]; - itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); - } - else itemToAdd = new Tuple(backend[i].Item1, item); + removeOne = backend[i]; - break; + if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) + { + removeTwo = backend[i + 1]; + itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); } + else itemToAdd = new Tuple(backend[i].Item1, item); + + break; } if(itemToAdd != null) @@ -170,11 +169,10 @@ public bool Remove(long item) } // Extent is only element - if(item == extent.Item1 && item == extent.Item2) - { - toRemove = extent; - break; - } + if(item != extent.Item1 || item != extent.Item2) continue; + + toRemove = extent; + break; } // Item not found diff --git a/Extents/ExtentsSByte.cs b/Extents/ExtentsSByte.cs index 8ecd6093d..2444eb27e 100644 --- a/Extents/ExtentsSByte.cs +++ b/Extents/ExtentsSByte.cs @@ -82,19 +82,18 @@ public void Add(sbyte item) } // Expands existing extent end - if(item == backend[i].Item2 + 1) - { - removeOne = backend[i]; + if(item != backend[i].Item2 + 1) continue; - if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) - { - removeTwo = backend[i + 1]; - itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); - } - else itemToAdd = new Tuple(backend[i].Item1, item); + removeOne = backend[i]; - break; + if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) + { + removeTwo = backend[i + 1]; + itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); } + else itemToAdd = new Tuple(backend[i].Item1, item); + + break; } if(itemToAdd != null) @@ -170,11 +169,10 @@ public bool Remove(sbyte item) } // Extent is only element - if(item == extent.Item1 && item == extent.Item2) - { - toRemove = extent; - break; - } + if(item != extent.Item1 || item != extent.Item2) continue; + + toRemove = extent; + break; } // Item not found diff --git a/Extents/ExtentsShort.cs b/Extents/ExtentsShort.cs index 2e5f40158..ac32f34b5 100644 --- a/Extents/ExtentsShort.cs +++ b/Extents/ExtentsShort.cs @@ -82,19 +82,18 @@ public void Add(short item) } // Expands existing extent end - if(item == backend[i].Item2 + 1) - { - removeOne = backend[i]; + if(item != backend[i].Item2 + 1) continue; - if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) - { - removeTwo = backend[i + 1]; - itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); - } - else itemToAdd = new Tuple(backend[i].Item1, item); + removeOne = backend[i]; - break; + if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) + { + removeTwo = backend[i + 1]; + itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); } + else itemToAdd = new Tuple(backend[i].Item1, item); + + break; } if(itemToAdd != null) @@ -170,11 +169,10 @@ public bool Remove(short item) } // Extent is only element - if(item == extent.Item1 && item == extent.Item2) - { - toRemove = extent; - break; - } + if(item != extent.Item1 || item != extent.Item2) continue; + + toRemove = extent; + break; } // Item not found diff --git a/Extents/ExtentsUInt.cs b/Extents/ExtentsUInt.cs index 8fb27ffc6..27a0e8b00 100644 --- a/Extents/ExtentsUInt.cs +++ b/Extents/ExtentsUInt.cs @@ -82,19 +82,18 @@ public void Add(uint item) } // Expands existing extent end - if(item == backend[i].Item2 + 1) - { - removeOne = backend[i]; + if(item != backend[i].Item2 + 1) continue; - if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) - { - removeTwo = backend[i + 1]; - itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); - } - else itemToAdd = new Tuple(backend[i].Item1, item); + removeOne = backend[i]; - break; + if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) + { + removeTwo = backend[i + 1]; + itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); } + else itemToAdd = new Tuple(backend[i].Item1, item); + + break; } if(itemToAdd != null) @@ -170,11 +169,10 @@ public bool Remove(uint item) } // Extent is only element - if(item == extent.Item1 && item == extent.Item2) - { - toRemove = extent; - break; - } + if(item != extent.Item1 || item != extent.Item2) continue; + + toRemove = extent; + break; } // Item not found diff --git a/Extents/ExtentsULong.cs b/Extents/ExtentsULong.cs index 68d5a3b64..7fcea95c2 100644 --- a/Extents/ExtentsULong.cs +++ b/Extents/ExtentsULong.cs @@ -82,19 +82,18 @@ public void Add(ulong item) } // Expands existing extent end - if(item == backend[i].Item2 + 1) - { - removeOne = backend[i]; + if(item != backend[i].Item2 + 1) continue; - if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) - { - removeTwo = backend[i + 1]; - itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); - } - else itemToAdd = new Tuple(backend[i].Item1, item); + removeOne = backend[i]; - break; + if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) + { + removeTwo = backend[i + 1]; + itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); } + else itemToAdd = new Tuple(backend[i].Item1, item); + + break; } if(itemToAdd != null) @@ -170,11 +169,10 @@ public bool Remove(ulong item) } // Extent is only element - if(item == extent.Item1 && item == extent.Item2) - { - toRemove = extent; - break; - } + if(item != extent.Item1 || item != extent.Item2) continue; + + toRemove = extent; + break; } // Item not found diff --git a/Extents/ExtentsUShort.cs b/Extents/ExtentsUShort.cs index e74f0287c..e9e11d4ce 100644 --- a/Extents/ExtentsUShort.cs +++ b/Extents/ExtentsUShort.cs @@ -82,19 +82,18 @@ public void Add(ushort item) } // Expands existing extent end - if(item == backend[i].Item2 + 1) - { - removeOne = backend[i]; + if(item != backend[i].Item2 + 1) continue; - if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) - { - removeTwo = backend[i + 1]; - itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); - } - else itemToAdd = new Tuple(backend[i].Item1, item); + removeOne = backend[i]; - break; + if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) + { + removeTwo = backend[i + 1]; + itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); } + else itemToAdd = new Tuple(backend[i].Item1, item); + + break; } if(itemToAdd != null) @@ -171,11 +170,10 @@ public bool Remove(ushort item) } // Extent is only element - if(item == extent.Item1 && item == extent.Item2) - { - toRemove = extent; - break; - } + if(item != extent.Item1 || item != extent.Item2) continue; + + toRemove = extent; + break; } // Item not found diff --git a/StringHandlers.cs b/StringHandlers.cs index 839cfea8f..728715e05 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -145,11 +145,10 @@ public static string SpacePaddedToString(byte[] SpacePaddedString, Encoding enco { if(i == start) return ""; - if(SpacePaddedString[i - 1] != 0x20) - { - len = i; - break; - } + if(SpacePaddedString[i - 1] == 0x20) continue; + + len = i; + break; } return len == 0 ? "" : encoding.GetString(SpacePaddedString, start, len); From 1b81cd63e84c95013bae53be2e0e894776a9b065 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 21 Dec 2017 07:08:26 +0000 Subject: [PATCH 064/217] REFACTOR: Loop can be converted into LINQ-expression. --- ArrayIsEmpty.cs | 10 ++++------ Extents/ExtentsByte.cs | 14 +++++--------- Extents/ExtentsInt.cs | 14 +++++--------- Extents/ExtentsLong.cs | 14 +++++--------- Extents/ExtentsSByte.cs | 14 +++++--------- Extents/ExtentsShort.cs | 14 +++++--------- Extents/ExtentsUInt.cs | 14 +++++--------- Extents/ExtentsULong.cs | 14 +++++--------- Extents/ExtentsUShort.cs | 15 +++++---------- 9 files changed, 44 insertions(+), 79 deletions(-) diff --git a/ArrayIsEmpty.cs b/ArrayIsEmpty.cs index b83f8b10c..bb3769e29 100644 --- a/ArrayIsEmpty.cs +++ b/ArrayIsEmpty.cs @@ -30,6 +30,8 @@ // Copyright © 2011-2018 Natalia Portillo // ****************************************************************************/ +using System.Linq; + namespace DiscImageChef { public static partial class ArrayHelpers @@ -38,18 +40,14 @@ public static bool ArrayIsNullOrWhiteSpace(byte[] array) { if(array == null) return true; - foreach(byte b in array) if(b != 0x00 && b != 0x20) return false; - - return true; + return array.All(b => b == 0x00 || b == 0x20); } public static bool ArrayIsNullOrEmpty(byte[] array) { if(array == null) return true; - foreach(byte b in array) if(b != 0x00) return false; - - return true; + return array.All(b => b == 0x00); } } } \ No newline at end of file diff --git a/Extents/ExtentsByte.cs b/Extents/ExtentsByte.cs index ad6e549bf..b96b174d8 100644 --- a/Extents/ExtentsByte.cs +++ b/Extents/ExtentsByte.cs @@ -125,9 +125,7 @@ public void Add(byte start, byte end, bool run) public bool Contains(byte item) { - foreach(Tuple extent in backend) if(item >= extent.Item1 && item <= extent.Item2) return true; - - return false; + return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2); } public void Clear() @@ -196,12 +194,10 @@ public Tuple[] ToArray() public bool GetStart(byte item, out byte start) { start = 0; - foreach(Tuple extent in backend) - if(item >= extent.Item1 && item <= extent.Item2) - { - start = extent.Item1; - return true; - } + foreach(Tuple extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) { + start = extent.Item1; + return true; + } return false; } diff --git a/Extents/ExtentsInt.cs b/Extents/ExtentsInt.cs index ad651ff6e..92d989250 100644 --- a/Extents/ExtentsInt.cs +++ b/Extents/ExtentsInt.cs @@ -125,9 +125,7 @@ public void Add(int start, int end, bool run) public bool Contains(int item) { - foreach(Tuple extent in backend) if(item >= extent.Item1 && item <= extent.Item2) return true; - - return false; + return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2); } public void Clear() @@ -196,12 +194,10 @@ public Tuple[] ToArray() public bool GetStart(int item, out int start) { start = 0; - foreach(Tuple extent in backend) - if(item >= extent.Item1 && item <= extent.Item2) - { - start = extent.Item1; - return true; - } + foreach(Tuple extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) { + start = extent.Item1; + return true; + } return false; } diff --git a/Extents/ExtentsLong.cs b/Extents/ExtentsLong.cs index 85fdf56d6..e958628fa 100644 --- a/Extents/ExtentsLong.cs +++ b/Extents/ExtentsLong.cs @@ -125,9 +125,7 @@ public void Add(long start, long end, bool run) public bool Contains(long item) { - foreach(Tuple extent in backend) if(item >= extent.Item1 && item <= extent.Item2) return true; - - return false; + return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2); } public void Clear() @@ -196,12 +194,10 @@ public Tuple[] ToArray() public bool GetStart(long item, out long start) { start = 0; - foreach(Tuple extent in backend) - if(item >= extent.Item1 && item <= extent.Item2) - { - start = extent.Item1; - return true; - } + foreach(Tuple extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) { + start = extent.Item1; + return true; + } return false; } diff --git a/Extents/ExtentsSByte.cs b/Extents/ExtentsSByte.cs index 2444eb27e..c5d665611 100644 --- a/Extents/ExtentsSByte.cs +++ b/Extents/ExtentsSByte.cs @@ -125,9 +125,7 @@ public void Add(sbyte start, sbyte end, bool run) public bool Contains(sbyte item) { - foreach(Tuple extent in backend) if(item >= extent.Item1 && item <= extent.Item2) return true; - - return false; + return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2); } public void Clear() @@ -196,12 +194,10 @@ public Tuple[] ToArray() public bool GetStart(sbyte item, out sbyte start) { start = 0; - foreach(Tuple extent in backend) - if(item >= extent.Item1 && item <= extent.Item2) - { - start = extent.Item1; - return true; - } + foreach(Tuple extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) { + start = extent.Item1; + return true; + } return false; } diff --git a/Extents/ExtentsShort.cs b/Extents/ExtentsShort.cs index ac32f34b5..604eee365 100644 --- a/Extents/ExtentsShort.cs +++ b/Extents/ExtentsShort.cs @@ -125,9 +125,7 @@ public void Add(short start, short end, bool run) public bool Contains(short item) { - foreach(Tuple extent in backend) if(item >= extent.Item1 && item <= extent.Item2) return true; - - return false; + return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2); } public void Clear() @@ -196,12 +194,10 @@ public Tuple[] ToArray() public bool GetStart(short item, out short start) { start = 0; - foreach(Tuple extent in backend) - if(item >= extent.Item1 && item <= extent.Item2) - { - start = extent.Item1; - return true; - } + foreach(Tuple extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) { + start = extent.Item1; + return true; + } return false; } diff --git a/Extents/ExtentsUInt.cs b/Extents/ExtentsUInt.cs index 27a0e8b00..1eb22492c 100644 --- a/Extents/ExtentsUInt.cs +++ b/Extents/ExtentsUInt.cs @@ -125,9 +125,7 @@ public void Add(uint start, uint end, bool run) public bool Contains(uint item) { - foreach(Tuple extent in backend) if(item >= extent.Item1 && item <= extent.Item2) return true; - - return false; + return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2); } public void Clear() @@ -196,12 +194,10 @@ public Tuple[] ToArray() public bool GetStart(uint item, out uint start) { start = 0; - foreach(Tuple extent in backend) - if(item >= extent.Item1 && item <= extent.Item2) - { - start = extent.Item1; - return true; - } + foreach(Tuple extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) { + start = extent.Item1; + return true; + } return false; } diff --git a/Extents/ExtentsULong.cs b/Extents/ExtentsULong.cs index 7fcea95c2..47e5a3ef6 100644 --- a/Extents/ExtentsULong.cs +++ b/Extents/ExtentsULong.cs @@ -125,9 +125,7 @@ public void Add(ulong start, ulong end, bool run) public bool Contains(ulong item) { - foreach(Tuple extent in backend) if(item >= extent.Item1 && item <= extent.Item2) return true; - - return false; + return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2); } public void Clear() @@ -196,12 +194,10 @@ public Tuple[] ToArray() public bool GetStart(ulong item, out ulong start) { start = 0; - foreach(Tuple extent in backend) - if(item >= extent.Item1 && item <= extent.Item2) - { - start = extent.Item1; - return true; - } + foreach(Tuple extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) { + start = extent.Item1; + return true; + } return false; } diff --git a/Extents/ExtentsUShort.cs b/Extents/ExtentsUShort.cs index e9e11d4ce..6ee29957c 100644 --- a/Extents/ExtentsUShort.cs +++ b/Extents/ExtentsUShort.cs @@ -125,10 +125,7 @@ public void Add(ushort start, ushort end, bool run) public bool Contains(ushort item) { - foreach(Tuple extent in backend) - if(item >= extent.Item1 && item <= extent.Item2) return true; - - return false; + return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2); } public void Clear() @@ -197,12 +194,10 @@ public Tuple[] ToArray() public bool GetStart(ushort item, out ushort start) { start = 0; - foreach(Tuple extent in backend) - if(item >= extent.Item1 && item <= extent.Item2) - { - start = extent.Item1; - return true; - } + foreach(Tuple extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) { + start = extent.Item1; + return true; + } return false; } From 99abd6638df2f1ca8dd76c312cfa4843518c7b08 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 21 Dec 2017 07:19:46 +0000 Subject: [PATCH 065/217] REFACTOR: Convert variables to auto setters. --- EndianAwareBinaryReader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EndianAwareBinaryReader.cs b/EndianAwareBinaryReader.cs index 496f667a6..b47316903 100644 --- a/EndianAwareBinaryReader.cs +++ b/EndianAwareBinaryReader.cs @@ -49,7 +49,7 @@ public EndianAwareBinaryReader(Stream input, Encoding encoding, bool isLittleEnd public EndianAwareBinaryReader(Stream input, bool isLittleEndian) : this(input, Encoding.UTF8, isLittleEndian) { } - public bool IsLittleEndian { get; set; } + public bool IsLittleEndian { get; set; } public override double ReadDouble() { From 76b26bd3a776c52adfa4035504ee39677f1d44dc Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 21 Dec 2017 14:30:38 +0000 Subject: [PATCH 066/217] REFACTOR: Remove unneeded code. --- ArrayFill.cs | 2 +- PrintHex.cs | 3 ++- StringHandlers.cs | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ArrayFill.cs b/ArrayFill.cs index e443f7bf9..e4a1a4d97 100644 --- a/ArrayFill.cs +++ b/ArrayFill.cs @@ -34,7 +34,7 @@ public static partial class ArrayHelpers public static void ArrayFill(T[] destinationArray, T value) { // if called with a single value, wrap the value in an array and call the main function - ArrayFill(destinationArray, new T[] {value}); + ArrayFill(destinationArray, new[] {value}); } public static void ArrayFill(T[] destinationArray, T[] value) diff --git a/PrintHex.cs b/PrintHex.cs index e5e8046a7..291b30154 100644 --- a/PrintHex.cs +++ b/PrintHex.cs @@ -30,6 +30,7 @@ // Copyright © 2011-2018 Natalia Portillo // ****************************************************************************/ +using System.Text; using DiscImageChef.Console; namespace DiscImageChef @@ -43,7 +44,7 @@ public static void PrintHexArray(byte[] array, int width) public static string ByteArrayToHexArrayString(byte[] array, int width) { - System.Text.StringBuilder sb = new System.Text.StringBuilder(); + StringBuilder sb = new StringBuilder(); int counter = 0; int subcounter = 0; diff --git a/StringHandlers.cs b/StringHandlers.cs index 728715e05..7f93ad326 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -176,7 +176,7 @@ public static string DecompressUnicode(byte[] dstring) if(unicode == 0) break; - temp += Encoding.Unicode.GetString(System.BitConverter.GetBytes(unicode)); + temp += Encoding.Unicode.GetString(BitConverter.GetBytes(unicode)); } return temp; From 3f541e74538fca48f3e9ebe041799a345af1fb7c Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 21 Dec 2017 16:42:20 +0000 Subject: [PATCH 067/217] REFACTOR: Parameter has no matching param tag in the XML comment. --- StringHandlers.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/StringHandlers.cs b/StringHandlers.cs index 7f93ad326..356568b5d 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -53,6 +53,8 @@ public static string CToString(byte[] CString) /// The corresponding C# string /// A null-terminated (aka C string) byte array in the specified encoding /// Encoding. + /// Set if encoding uses 16-bit characters. + /// Start decodint at this position public static string CToString(byte[] CString, Encoding encoding, bool twoBytes = false, int start = 0) { if(CString == null) return null; @@ -99,6 +101,7 @@ public static string PascalToString(byte[] PascalString) /// The corresponding C# string /// A length-prefixed (aka Pascal string) ASCII byte array /// Encoding. + /// Start decodint at this position public static string PascalToString(byte[] PascalString, Encoding encoding, int start = 0) { if(PascalString == null) return null; @@ -135,6 +138,7 @@ public static string SpacePaddedToString(byte[] SpacePaddedString) /// The corresponding C# string /// A space (' ', 0x20, ASCII SPACE) padded ASCII byte array /// Encoding. + /// Start decodint at this position public static string SpacePaddedToString(byte[] SpacePaddedString, Encoding encoding, int start = 0) { if(SpacePaddedString == null) return null; From 6622bef3350f13c1547a40d3847e1e6c2af860af Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Fri, 22 Dec 2017 16:35:31 +0000 Subject: [PATCH 068/217] REFACTOR: All refactor in DiscImageChef.Helpers. --- ArrayFill.cs | 7 +------ ArrayIsEmpty.cs | 8 ++------ Extents/ExtentsByte.cs | 14 +++----------- Extents/ExtentsInt.cs | 14 +++----------- Extents/ExtentsLong.cs | 14 +++----------- Extents/ExtentsSByte.cs | 14 +++----------- Extents/ExtentsShort.cs | 14 +++----------- Extents/ExtentsUInt.cs | 14 +++----------- Extents/ExtentsULong.cs | 14 +++----------- Extents/ExtentsUShort.cs | 14 +++----------- Swapping.cs | 8 ++++---- 11 files changed, 31 insertions(+), 104 deletions(-) diff --git a/ArrayFill.cs b/ArrayFill.cs index e4a1a4d97..d08b4b0b5 100644 --- a/ArrayFill.cs +++ b/ArrayFill.cs @@ -54,12 +54,7 @@ public static void ArrayFill(T[] destinationArray, T[] value) Array.Copy(destinationArray, 0, destinationArray, copyLength, destinationArray.Length - copyLength); } - public static string ByteArrayToHex(byte[] array) - { - return ByteArrayToHex(array, false); - } - - public static string ByteArrayToHex(byte[] array, bool upper) + public static string ByteArrayToHex(byte[] array, bool upper = false) { StringBuilder sb = new StringBuilder(); for(long i = 0; i < array.LongLength; i++) sb.AppendFormat("{0:x2}", array[i]); diff --git a/ArrayIsEmpty.cs b/ArrayIsEmpty.cs index bb3769e29..94c466c00 100644 --- a/ArrayIsEmpty.cs +++ b/ArrayIsEmpty.cs @@ -38,16 +38,12 @@ public static partial class ArrayHelpers { public static bool ArrayIsNullOrWhiteSpace(byte[] array) { - if(array == null) return true; - - return array.All(b => b == 0x00 || b == 0x20); + return array == null || array.All(b => b == 0x00 || b == 0x20); } public static bool ArrayIsNullOrEmpty(byte[] array) { - if(array == null) return true; - - return array.All(b => b == 0x00); + return array == null || array.All(b => b == 0x00); } } } \ No newline at end of file diff --git a/Extents/ExtentsByte.cs b/Extents/ExtentsByte.cs index b96b174d8..13c9ffa15 100644 --- a/Extents/ExtentsByte.cs +++ b/Extents/ExtentsByte.cs @@ -45,15 +45,12 @@ public ExtentsByte() backend = new List>(); } - public ExtentsByte(List> list) + public ExtentsByte(IEnumerable> list) { backend = list.OrderBy(t => t.Item1).ToList(); } - public int Count - { - get { return backend.Count; } - } + public int Count => backend.Count; public void Add(byte item) { @@ -108,12 +105,7 @@ public void Add(byte item) backend = backend.OrderBy(t => t.Item1).ToList(); } - public void Add(byte start, byte end) - { - Add(start, end, false); - } - - public void Add(byte start, byte end, bool run) + public void Add(byte start, byte end, bool run = false) { byte realEnd; if(run) realEnd = (byte)(start + end - 1); diff --git a/Extents/ExtentsInt.cs b/Extents/ExtentsInt.cs index 92d989250..ce631c8b2 100644 --- a/Extents/ExtentsInt.cs +++ b/Extents/ExtentsInt.cs @@ -45,15 +45,12 @@ public ExtentsInt() backend = new List>(); } - public ExtentsInt(List> list) + public ExtentsInt(IEnumerable> list) { backend = list.OrderBy(t => t.Item1).ToList(); } - public int Count - { - get { return backend.Count; } - } + public int Count => backend.Count; public void Add(int item) { @@ -108,12 +105,7 @@ public void Add(int item) backend = backend.OrderBy(t => t.Item1).ToList(); } - public void Add(int start, int end) - { - Add(start, end, false); - } - - public void Add(int start, int end, bool run) + public void Add(int start, int end, bool run = false) { int realEnd; if(run) realEnd = start + end - 1; diff --git a/Extents/ExtentsLong.cs b/Extents/ExtentsLong.cs index e958628fa..68a9faf15 100644 --- a/Extents/ExtentsLong.cs +++ b/Extents/ExtentsLong.cs @@ -45,15 +45,12 @@ public ExtentsLong() backend = new List>(); } - public ExtentsLong(List> list) + public ExtentsLong(IEnumerable> list) { backend = list.OrderBy(t => t.Item1).ToList(); } - public int Count - { - get { return backend.Count; } - } + public int Count => backend.Count; public void Add(long item) { @@ -108,12 +105,7 @@ public void Add(long item) backend = backend.OrderBy(t => t.Item1).ToList(); } - public void Add(long start, long end) - { - Add(start, end, false); - } - - public void Add(long start, long end, bool run) + public void Add(long start, long end, bool run = false) { long realEnd; if(run) realEnd = start + end - 1; diff --git a/Extents/ExtentsSByte.cs b/Extents/ExtentsSByte.cs index c5d665611..df5b0d151 100644 --- a/Extents/ExtentsSByte.cs +++ b/Extents/ExtentsSByte.cs @@ -45,15 +45,12 @@ public ExtentsSByte() backend = new List>(); } - public ExtentsSByte(List> list) + public ExtentsSByte(IEnumerable> list) { backend = list.OrderBy(t => t.Item1).ToList(); } - public int Count - { - get { return backend.Count; } - } + public int Count => backend.Count; public void Add(sbyte item) { @@ -108,12 +105,7 @@ public void Add(sbyte item) backend = backend.OrderBy(t => t.Item1).ToList(); } - public void Add(sbyte start, sbyte end) - { - Add(start, end, false); - } - - public void Add(sbyte start, sbyte end, bool run) + public void Add(sbyte start, sbyte end, bool run = false) { sbyte realEnd; if(run) realEnd = (sbyte)(start + end - 1); diff --git a/Extents/ExtentsShort.cs b/Extents/ExtentsShort.cs index 604eee365..505a4fcba 100644 --- a/Extents/ExtentsShort.cs +++ b/Extents/ExtentsShort.cs @@ -45,15 +45,12 @@ public ExtentsShort() backend = new List>(); } - public ExtentsShort(List> list) + public ExtentsShort(IEnumerable> list) { backend = list.OrderBy(t => t.Item1).ToList(); } - public int Count - { - get { return backend.Count; } - } + public int Count => backend.Count; public void Add(short item) { @@ -108,12 +105,7 @@ public void Add(short item) backend = backend.OrderBy(t => t.Item1).ToList(); } - public void Add(short start, short end) - { - Add(start, end, false); - } - - public void Add(short start, short end, bool run) + public void Add(short start, short end, bool run = false) { short realEnd; if(run) realEnd = (short)(start + end - 1); diff --git a/Extents/ExtentsUInt.cs b/Extents/ExtentsUInt.cs index 1eb22492c..5768ba1ec 100644 --- a/Extents/ExtentsUInt.cs +++ b/Extents/ExtentsUInt.cs @@ -45,15 +45,12 @@ public ExtentsUInt() backend = new List>(); } - public ExtentsUInt(List> list) + public ExtentsUInt(IEnumerable> list) { backend = list.OrderBy(t => t.Item1).ToList(); } - public int Count - { - get { return backend.Count; } - } + public int Count => backend.Count; public void Add(uint item) { @@ -108,12 +105,7 @@ public void Add(uint item) backend = backend.OrderBy(t => t.Item1).ToList(); } - public void Add(uint start, uint end) - { - Add(start, end, false); - } - - public void Add(uint start, uint end, bool run) + public void Add(uint start, uint end, bool run = false) { uint realEnd; if(run) realEnd = start + end - 1; diff --git a/Extents/ExtentsULong.cs b/Extents/ExtentsULong.cs index 47e5a3ef6..f5cc9eb9c 100644 --- a/Extents/ExtentsULong.cs +++ b/Extents/ExtentsULong.cs @@ -45,15 +45,12 @@ public ExtentsULong() backend = new List>(); } - public ExtentsULong(List> list) + public ExtentsULong(IEnumerable> list) { backend = list.OrderBy(t => t.Item1).ToList(); } - public int Count - { - get { return backend.Count; } - } + public int Count => backend.Count; public void Add(ulong item) { @@ -108,12 +105,7 @@ public void Add(ulong item) backend = backend.OrderBy(t => t.Item1).ToList(); } - public void Add(ulong start, ulong end) - { - Add(start, end, false); - } - - public void Add(ulong start, ulong end, bool run) + public void Add(ulong start, ulong end, bool run = false) { ulong realEnd; if(run) realEnd = start + end - 1; diff --git a/Extents/ExtentsUShort.cs b/Extents/ExtentsUShort.cs index 6ee29957c..530f7951f 100644 --- a/Extents/ExtentsUShort.cs +++ b/Extents/ExtentsUShort.cs @@ -45,15 +45,12 @@ public ExtentsUShort() backend = new List>(); } - public ExtentsUShort(List> list) + public ExtentsUShort(IEnumerable> list) { backend = list.OrderBy(t => t.Item1).ToList(); } - public int Count - { - get { return backend.Count; } - } + public int Count => backend.Count; public void Add(ushort item) { @@ -108,12 +105,7 @@ public void Add(ushort item) backend = backend.OrderBy(t => t.Item1).ToList(); } - public void Add(ushort start, ushort end) - { - Add(start, end, false); - } - - public void Add(ushort start, ushort end, bool run) + public void Add(ushort start, ushort end, bool run = false) { ushort realEnd; if(run) realEnd = (ushort)(start + end - 1); diff --git a/Swapping.cs b/Swapping.cs index 75bec257e..75fb4d36f 100644 --- a/Swapping.cs +++ b/Swapping.cs @@ -118,12 +118,12 @@ public static long Swap(long 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) { - return (short)((x << 8) | ((x >> 8) & 0xFF)); + return (short) ((x << 8) | ((x >> 8) & 0xFF)); } public static uint Swap(uint x) @@ -134,8 +134,8 @@ public static uint Swap(uint x) public static int Swap(int x) { - x = (int)(((x << 8) & 0xFF00FF00) | (((uint)x >> 8) & 0xFF00FF)); - return (int)(((uint)x << 16) | (((uint)x >> 16) & 0xFFFF)); + x = (int) (((x << 8) & 0xFF00FF00) | (((uint) x >> 8) & 0xFF00FF)); + return (int) (((uint) x << 16) | (((uint) x >> 16) & 0xFFFF)); } } } \ No newline at end of file From 481e39c39992fe9bdb455cd72d4e359f6ea27bc5 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sat, 23 Dec 2017 03:51:42 +0000 Subject: [PATCH 069/217] DOCUMENTATION: Added XML documentation to DiscImageChef.Helpers. --- ArrayFill.cs | 18 ++ ArrayIsEmpty.cs | 10 + BigEndianBitConverter.cs | 579 +++++++++---------------------------- CHS.cs | 9 + CompareBytes.cs | 7 + CountBits.cs | 5 + DateHandlers.cs | 116 +++++++- EndianAwareBinaryReader.cs | 1 + Extents/ExtentsByte.cs | 46 +++ Extents/ExtentsInt.cs | 46 +++ Extents/ExtentsLong.cs | 46 +++ Extents/ExtentsSByte.cs | 46 +++ Extents/ExtentsShort.cs | 46 +++ Extents/ExtentsUInt.cs | 46 +++ Extents/ExtentsULong.cs | 46 +++ Extents/ExtentsUShort.cs | 46 +++ PrintHex.cs | 11 + 17 files changed, 687 insertions(+), 437 deletions(-) diff --git a/ArrayFill.cs b/ArrayFill.cs index d08b4b0b5..811b33761 100644 --- a/ArrayFill.cs +++ b/ArrayFill.cs @@ -31,12 +31,24 @@ namespace DiscImageChef { public static partial class ArrayHelpers { + /// + /// Fills an array with the specified value + /// + /// Array + /// Value + /// Array type public static void ArrayFill(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}); } + /// + /// Fills an array with the contents of the specified array + /// + /// Array + /// Value + /// Array type public static void ArrayFill(T[] destinationArray, T[] value) { if(destinationArray == null) throw new ArgumentNullException(nameof(destinationArray)); @@ -54,6 +66,12 @@ public static void ArrayFill(T[] destinationArray, T[] value) Array.Copy(destinationArray, 0, destinationArray, copyLength, destinationArray.Length - copyLength); } + /// + /// Converts a byte array to its hexadecimal representation + /// + /// Byte array + /// true to use uppercase + /// public static string ByteArrayToHex(byte[] array, bool upper = false) { StringBuilder sb = new StringBuilder(); diff --git a/ArrayIsEmpty.cs b/ArrayIsEmpty.cs index 94c466c00..cec1d9cb8 100644 --- a/ArrayIsEmpty.cs +++ b/ArrayIsEmpty.cs @@ -36,11 +36,21 @@ namespace DiscImageChef { public static partial class ArrayHelpers { + /// + /// Checks if an array is null, filled with the NULL byte (0x00) or ASCII whitespace (0x20) + /// + /// Array + /// True if null or whitespace public static bool ArrayIsNullOrWhiteSpace(byte[] array) { return array == null || array.All(b => b == 0x00 || b == 0x20); } + /// + /// Checks if an array is null or filled with the NULL byte (0x00) + /// + /// Array + /// True if null public static bool ArrayIsNullOrEmpty(byte[] array) { return array == null || array.All(b => b == 0x00); diff --git a/BigEndianBitConverter.cs b/BigEndianBitConverter.cs index 46d0706f1..53064d00d 100644 --- a/BigEndianBitConverter.cs +++ b/BigEndianBitConverter.cs @@ -40,327 +40,186 @@ namespace DiscImageChef /// data types. /// All info taken from the meta data of System.BitConverter. This implementation /// allows for Endianness consideration. - /// + /// public static class BigEndianBitConverter { /// /// Indicates the byte order ("endianess") in which data is stored in this computer /// architecture. - /// + /// public static bool IsLittleEndian { get; set; } - // should default to false, which is what we want for Empire /// - /// 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. - /// + /// Converts the specified double-precision floating point number to a 64-bit signed integer. + /// + /// The number to convert. + /// A 64-bit signed integer whose value is equivalent to value. + /// It is not currently implemented public static long DoubleToInt64Bits(double value) { throw new NotImplementedException(); } - /// /// /// Returns the specified Boolean value as an array of bytes. - /// - /// Parameters: - /// value: - /// A Boolean value. - /// - /// Returns: - /// An array of bytes with length 1. - /// + /// + /// A Boolean value. + /// An array of bytes with length 1. public static byte[] GetBytes(bool value) { return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); } - /// /// /// 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. - /// + /// + /// A character to convert. + /// An array of bytes with length 2. public static byte[] GetBytes(char value) { return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); } - /// /// - /// 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. - /// + /// Returns the specified double-precision floating point value as an array of bytes. + /// + /// The number to convert. + /// An array of bytes with length 8. public static byte[] GetBytes(double value) { return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); } - /// /// - /// 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. - /// + /// Returns the specified single-precision floating point value as an array of bytes. + /// + /// The number to convert. + /// An array of bytes with length 4. public static byte[] GetBytes(float value) { return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); } - /// /// /// 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. - /// + /// + /// The number to convert. + /// An array of bytes with length 4. public static byte[] GetBytes(int value) { return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); } - /// /// /// 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. - /// + /// + /// The number to convert. + /// An array of bytes with length 8. public static byte[] GetBytes(long value) { return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); } - /// /// /// 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. - /// + /// + /// The number to convert. + /// An array of bytes with length 2. public static byte[] GetBytes(short value) { return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); } - /// /// /// 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. - /// - //[CLSCompliant(false)] + /// + /// The number to convert. + /// An array of bytes with length 4. public static byte[] GetBytes(uint value) { return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); } - /// /// /// 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. - /// - //[CLSCompliant(false)] + /// + /// The number to convert. + /// An array of bytes with length 8. public static byte[] GetBytes(ulong value) { return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); } - /// /// /// 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. - /// + /// + /// The number to convert. + /// An array of bytes with length 2. public static byte[] GetBytes(ushort value) { return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); } - /// /// - /// 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. - /// + /// Converts the specified 64-bit signed integer to a double-precision floating point number. + /// + /// The number to convert. + /// A double-precision floating point number whose value is equivalent to value. public static double Int64BitsToDouble(long value) { throw new NotImplementedException(); } - /// /// - /// 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. - /// + /// Returns a Boolean value converted from one byte at a specified position in a byte array. + /// + /// An array of bytes. + /// The starting position within value. + /// true if the byte at in value is nonzero; otherwise, false. + /// value is null. + /// is less than zero or greater than the length of value minus 1. public static bool ToBoolean(byte[] value, int startIndex) { throw new NotImplementedException(); } - /// /// - /// 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. - /// + /// Returns a Unicode character converted from two bytes at a specified position in a byte array. + /// + /// An array. + /// The starting position within value. + /// A character formed by two bytes beginning at . + /// equals the length of value minus 1. + /// value is null. + /// is less than zero or greater than the length of value minus 1. public static char ToChar(byte[] value, int startIndex) { throw new NotImplementedException(); } - /// /// - /// 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. - /// + /// Returns a double-precision floating point number converted from eight bytes at a specified position in a byte array. + /// + /// An array of bytes. + /// The starting position within value. + /// A double precision floating point number formed by eight bytes beginning at . + /// 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. + /// value is null. + /// is less than zero or greater than the length of value minus 1. public static double ToDouble(byte[] value, int startIndex) { throw new NotImplementedException(); } - /// /// - /// 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. - /// + /// Returns a 16-bit signed integer converted from two bytes at a specified position in a byte array. + /// + /// An array of bytes. + /// The starting position within value. + /// A 16-bit signed integer formed by two bytes beginning at . + /// equals the length of value minus 1. + /// value is null. + /// startIndex is less than zero or greater than the length of value minus 1. public static short ToInt16(byte[] value, int startIndex) { return !IsLittleEndian @@ -368,32 +227,15 @@ public static short ToInt16(byte[] value, int startIndex) : BitConverter.ToInt16(value.Reverse().ToArray(), value.Length - sizeof(short) - startIndex); } - /// /// - /// 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. - /// + /// Returns a 32-bit signed integer converted from four bytes at a specified position in a byte array. + /// + /// An array of bytes. + /// The starting position within value. + /// A 32-bit signed integer formed by four bytes beginning at . + /// 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. + /// value is null. + /// startIndex is less than zero or greater than the length of value minus 1. public static int ToInt32(byte[] value, int startIndex) { return !IsLittleEndian @@ -401,32 +243,15 @@ public static int ToInt32(byte[] value, int startIndex) : BitConverter.ToInt32(value.Reverse().ToArray(), value.Length - sizeof(int) - startIndex); } - /// /// - /// 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. - /// + /// Returns a 64-bit signed integer converted from eight bytes at a specified position in a byte array. + /// + /// An array of bytes. + /// The starting position within value. + /// A 64-bit signed integer formed by eight bytes beginning at . + /// 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. + /// value is null. + /// is less than zero or greater than the length of value minus 1. public static long ToInt64(byte[] value, int startIndex) { return !IsLittleEndian @@ -434,33 +259,15 @@ public static long ToInt64(byte[] value, int startIndex) : BitConverter.ToInt64(value.Reverse().ToArray(), value.Length - sizeof(long) - startIndex); } - /// /// - /// 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. - /// + /// Returns a single-precision floating point number converted from four bytes at a specified position in a byte array. + /// + /// An array of bytes. + /// The starting position within value. + /// A single-precision floating point number formed by four bytes beginning at . + /// 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. + /// value is null. + /// is less than zero or greater than the length of value minus 1. public static float ToSingle(byte[] value, int startIndex) { return !IsLittleEndian @@ -468,52 +275,25 @@ public static float ToSingle(byte[] value, int startIndex) : BitConverter.ToSingle(value.Reverse().ToArray(), value.Length - sizeof(float) - startIndex); } - /// /// - /// 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. - /// + /// Converts the numeric value of each element of a specified array of bytes to its equivalent hexadecimal string representation. + /// + /// An array of bytes. + /// A System.String of hexadecimal pairs separated by hyphens, where each pair represents the corresponding element in value; for example, "7F-2C-4A". + /// value is null. public static string ToString(byte[] value) { return !IsLittleEndian ? BitConverter.ToString(value) : BitConverter.ToString(value.Reverse().ToArray()); } - /// /// - /// 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. - /// + /// Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal string representation. + /// + /// An array of bytes. + /// The starting position within value. + /// 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". + /// value is null. + /// startIndex is less than zero or greater than the length of value minus 1. public static string ToString(byte[] value, int startIndex) { return !IsLittleEndian @@ -521,39 +301,16 @@ public static string ToString(byte[] value, int startIndex) : BitConverter.ToString(value.Reverse().ToArray(), startIndex); } - /// /// - /// 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. - /// + /// Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal string representation. + /// + /// An array of bytes. + /// The starting position within value. + /// The number of array elements in value to convert. + /// 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". + /// value is null. + /// startIndex or length is less than zero. -or- startIndex is greater than zero and is greater than or equal to the length of value. + /// 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. public static string ToString(byte[] value, int startIndex, int length) { return !IsLittleEndian @@ -561,31 +318,15 @@ public static string ToString(byte[] value, int startIndex, int length) : BitConverter.ToString(value.Reverse().ToArray(), startIndex, length); } - /// /// - /// 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. - /// + /// Returns a 16-bit unsigned integer converted from two bytes at a specified position in a byte array. + /// + /// The array of bytes. + /// The starting position within value. + /// A 16-bit unsigned integer formed by two bytes beginning at startIndex. + /// startIndex equals the length of value minus 1. + /// value is null. + /// startIndex is less than zero or greater than the length of value minus 1. public static ushort ToUInt16(byte[] value, int startIndex) { return !IsLittleEndian @@ -593,32 +334,15 @@ public static ushort ToUInt16(byte[] value, int startIndex) : BitConverter.ToUInt16(value.Reverse().ToArray(), value.Length - sizeof(ushort) - startIndex); } - /// /// - /// 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. - /// + /// Returns a 32-bit unsigned integer converted from four bytes at a specified position in a byte array. + /// + /// An array of bytes. + /// The starting position within value. + /// A 32-bit unsigned integer formed by four bytes beginning at startIndex. + /// 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. + /// value is null. + /// startIndex is less than zero or greater than the length of value minus 1. public static uint ToUInt32(byte[] value, int startIndex) { return !IsLittleEndian @@ -626,32 +350,15 @@ public static uint ToUInt32(byte[] value, int startIndex) : BitConverter.ToUInt32(value.Reverse().ToArray(), value.Length - sizeof(uint) - startIndex); } - /// /// - /// 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. - /// + /// Returns a 64-bit unsigned integer converted from eight bytes at a specified position in a byte array. + /// + /// An array of bytes. + /// The starting position within value. + /// A 64-bit unsigned integer formed by the eight bytes beginning at startIndex. + /// 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. + /// value is null. + /// startIndex is less than zero or greater than the length of value minus 1. public static ulong ToUInt64(byte[] value, int startIndex) { return !IsLittleEndian diff --git a/CHS.cs b/CHS.cs index 869669143..5d696ad67 100644 --- a/CHS.cs +++ b/CHS.cs @@ -34,6 +34,15 @@ namespace DiscImageChef.Helpers { public static class CHS { + /// + /// Converts a CHS position to a LBA one + /// + /// Cylinder + /// Head + /// Sector + /// Number of heads + /// Number of sectors per track + /// public static uint ToLBA(uint cyl, uint head, uint sector, uint maxHead, uint maxSector) { return maxHead == 0 || maxSector == 0 diff --git a/CompareBytes.cs b/CompareBytes.cs index 5eb96857e..f10cf41d6 100644 --- a/CompareBytes.cs +++ b/CompareBytes.cs @@ -34,6 +34,13 @@ namespace DiscImageChef { public static partial class ArrayHelpers { + /// + /// Compares two byte arrays + /// + /// true if they are different in any way + /// true if they have the same size + /// Left array + /// Right array public static void CompareBytes(out bool different, out bool sameSize, byte[] compareArray1, byte[] compareArray2) { diff --git a/CountBits.cs b/CountBits.cs index 29a153fb4..7c899f9ff 100644 --- a/CountBits.cs +++ b/CountBits.cs @@ -34,6 +34,11 @@ namespace DiscImageChef.Helpers { public static class CountBits { + /// + /// Counts the number of bits set to true in a number + /// + /// Number + /// Bits set to true public static int Count(uint number) { number = number - ((number >> 1) & 0x55555555); diff --git a/DateHandlers.cs b/DateHandlers.cs index 9d394fb0c..56dda5f56 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -46,41 +46,82 @@ public static class DateHandlers static readonly DateTime AmigaEpoch = new DateTime(1978, 1, 1, 0, 0, 0); static readonly DateTime AppleDoubleEpoch = new DateTime(1970, 1, 1, 0, 0, 0); + /// + /// Converts a Macintosh timestamp to a .NET DateTime + /// + /// Macintosh timestamp (seconds since 1st Jan. 1904) + /// .NET DateTime public static DateTime MacToDateTime(ulong MacTimeStamp) { return MacEpoch.AddTicks((long)(MacTimeStamp * 10000000)); } + /// + /// Converts a Lisa timestamp to a .NET DateTime + /// + /// Lisa timestamp (seconds since 1st Jan. 1901) + /// .NET DateTime public static DateTime LisaToDateTime(uint LisaTimeStamp) { return LisaEpoch.AddSeconds(LisaTimeStamp); } + /// + /// Converts a UNIX timestamp to a .NET DateTime + /// + /// UNIX timestamp (seconds since 1st Jan. 1970) + /// .NET DateTime public static DateTime UNIXToDateTime(int UNIXTimeStamp) { return UNIXEpoch.AddSeconds(UNIXTimeStamp); } + /// + /// Converts a UNIX timestamp to a .NET DateTime + /// + /// UNIX timestamp (seconds since 1st Jan. 1970) + /// .NET DateTime public static DateTime UNIXToDateTime(long UNIXTimeStamp) { return UNIXEpoch.AddSeconds(UNIXTimeStamp); } + /// + /// Converts a UNIX timestamp to a .NET DateTime + /// + /// UNIX timestamp (seconds since 1st Jan. 1970) + /// .NET DateTime public static DateTime UNIXUnsignedToDateTime(uint UNIXTimeStamp) { return UNIXEpoch.AddSeconds(UNIXTimeStamp); } + /// + /// Converts a UNIX timestamp to a .NET DateTime + /// + /// Seconds since 1st Jan. 1970) + /// Nanoseconds + /// .NET DateTime public static DateTime UNIXUnsignedToDateTime(uint seconds, uint nanoseconds) { return UNIXEpoch.AddSeconds(seconds).AddTicks((long)nanoseconds / 100); } + /// + /// Converts a UNIX timestamp to a .NET DateTime + /// + /// UNIX timestamp (seconds since 1st Jan. 1970) + /// .NET DateTime public static DateTime UNIXUnsignedToDateTime(ulong UNIXTimeStamp) { return UNIXEpoch.AddSeconds(UNIXTimeStamp); } + /// + /// Converts a High Sierra Format timestamp to a .NET DateTime + /// + /// High Sierra Format timestamp + /// .NET DateTime public static DateTime HighSierraToDateTime(byte[] VDDateTime) { byte[] isotime = new byte[17]; @@ -89,6 +130,11 @@ public static DateTime HighSierraToDateTime(byte[] VDDateTime) } // TODO: Timezone + /// + /// Converts an ISO9660 timestamp to a .NET DateTime + /// + /// ISO9660 timestamp + /// .NET DateTime public static DateTime ISO9660ToDateTime(byte[] VDDateTime) { int year, month, day, hour, minute, second, hundredths; @@ -155,13 +201,25 @@ public static DateTime ISO9660ToDateTime(byte[] VDDateTime) return decodedDT; } - // C# works in UTC, VMS on Julian Date, some displacement may occur on disks created outside UTC + /// + /// Converts a VMS timestamp to a .NET DateTime + /// + /// VMS timestamp (tenths of microseconds since day 0 of the Julian Date) + /// .NET DateTime + /// C# works in UTC, VMS on Julian Date, some displacement may occur on disks created outside UTC public static DateTime VMSToDateTime(ulong vmsDate) { double delta = vmsDate * 0.0001; // Tenths of microseconds to milliseconds, will lose some detail return JulianEpoch.AddMilliseconds(delta); } + /// + /// Converts an Amiga timestamp to a .NET DateTime + /// + /// Days since the 1st Jan. 1978 + /// Minutes since o'clock + /// Ticks + /// .NET DateTime public static DateTime AmigaToDateTime(uint days, uint minutes, uint ticks) { DateTime temp = AmigaEpoch.AddDays(days); @@ -169,6 +227,11 @@ public static DateTime AmigaToDateTime(uint days, uint minutes, uint ticks) return temp.AddMilliseconds(ticks * 20); } + /// + /// Converts an UCSD Pascal timestamp to a .NET DateTime + /// + /// UCSD Pascal timestamp + /// .NET DateTime public static DateTime UCSDPascalToDateTime(short dateRecord) { int year = ((dateRecord & 0xFE00) >> 9) + 1900; @@ -181,6 +244,12 @@ public static DateTime UCSDPascalToDateTime(short dateRecord) return new DateTime(year, month, day); } + /// + /// Converts a DOS timestamp to a .NET DateTime + /// + /// Date + /// Time + /// .NET DateTime public static DateTime DOSToDateTime(ushort date, ushort time) { int year = ((date & 0xFE00) >> 9) + 1980; @@ -203,6 +272,11 @@ public static DateTime DOSToDateTime(ushort date, ushort time) return dosdate; } + /// + /// Converts a CP/M timestamp to .NET DateTime + /// + /// CP/M timestamp + /// .NET DateTime public static DateTime CPMToDateTime(byte[] timestamp) { ushort days = BitConverter.ToUInt16(timestamp, 0); @@ -216,11 +290,26 @@ public static DateTime CPMToDateTime(byte[] timestamp) return temp; } + // TODO: This is unix public static DateTime AppleDoubleToDateTime(ulong AppleDoubleTimeStamp) { return AppleDoubleEpoch.AddSeconds(AppleDoubleTimeStamp); } + /// + /// Converts an ECMA timestamp to a .NET DateTime + /// + /// Timezone + /// Year + /// Month + /// Day + /// Hour + /// Minute + /// Second + /// Centiseconds + /// Hundreds of microseconds + /// 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) @@ -245,11 +334,21 @@ public static DateTime ECMAToDateTime(ushort typeAndTimeZone, short year, byte m .AddTicks(ticks).DateTime; } + /// + /// Convers a Solaris high resolution timestamp to .NET DateTime + /// + /// Solaris high resolution timestamp + /// .NET DateTime public static DateTime UNIXHrTimeToDateTime(ulong HRTimeStamp) { return UNIXEpoch.AddTicks((long)(HRTimeStamp / 100)); } + /// + /// Converts an OS-9 timestamp to .NET DateTime + /// + /// OS-9 timestamp + /// .NET DateTime public static DateTime OS9ToDateTime(byte[] date) { if(date == null || date.Length != 3 && date.Length != 5) return DateTime.MinValue; @@ -267,6 +366,11 @@ public static DateTime OS9ToDateTime(byte[] date) return os9date; } + /// + /// Converts a LIF timestamp to .NET DateTime + /// + /// LIF timestamp + /// .NET DateTime 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 @@ public static DateTime LifToDateTime(byte[] date) return LifToDateTime(date[0], date[1], date[2], date[3], date[4], date[5]); } + /// + /// Converts a LIF timestamp to .NET DateTime + /// + /// Yer + /// Month + /// Day + /// Hour + /// Minute + /// Second + /// .NET DateTime public static DateTime LifToDateTime(byte year, byte month, byte day, byte hour, byte minute, byte second) { try diff --git a/EndianAwareBinaryReader.cs b/EndianAwareBinaryReader.cs index b47316903..a108895f7 100644 --- a/EndianAwareBinaryReader.cs +++ b/EndianAwareBinaryReader.cs @@ -30,6 +30,7 @@ // Copyright © 2011-2018 Natalia Portillo // ****************************************************************************/ +// TODO: Just remove using System; using System.IO; using System.Linq; diff --git a/Extents/ExtentsByte.cs b/Extents/ExtentsByte.cs index 13c9ffa15..bd0e7b188 100644 --- a/Extents/ExtentsByte.cs +++ b/Extents/ExtentsByte.cs @@ -36,22 +36,39 @@ namespace Extents { + /// + /// Implements extents for + /// public class ExtentsByte { List> backend; + /// + /// Initialize an empty list of extents + /// public ExtentsByte() { backend = new List>(); } + /// + /// Initializes extents with an specific list + /// + /// List of extents as tuples "start, end" public ExtentsByte(IEnumerable> list) { backend = list.OrderBy(t => t.Item1).ToList(); } + /// + /// Gets a count of how many extents are stored + /// public int Count => backend.Count; + /// + /// Adds the specified number to the corresponding extent, or creates a new one + /// + /// public void Add(byte item) { Tuple removeOne = null; @@ -105,6 +122,12 @@ public void Add(byte item) backend = backend.OrderBy(t => t.Item1).ToList(); } + /// + /// Adds a new extent + /// + /// First element of the extent + /// Last element of the extent or if is true how many elements the extent runs for + /// If set to true, indicates how many elements the extent runs for public void Add(byte start, byte end, bool run = false) { byte realEnd; @@ -115,16 +138,29 @@ public void Add(byte start, byte end, bool run = false) for(byte t = start; t <= realEnd; t++) Add(t); } + /// + /// Checks if the specified item is contained by an extent on this instance + /// + /// Item to seach for + /// true if any of the extents on this instance contains the item public bool Contains(byte item) { return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2); } + /// + /// Removes all extents from this instance + /// public void Clear() { backend.Clear(); } + /// + /// Removes an item from the extents in this instance + /// + /// Item to remove + /// true if the item was contained in a known extent and removed, false otherwise public bool Remove(byte item) { Tuple toRemove = null; @@ -178,11 +214,21 @@ public bool Remove(byte item) return true; } + /// + /// Converts the list of extents to an array of where T1 is first element of the extent and T2 is last element + /// + /// Array of public Tuple[] ToArray() { return backend.ToArray(); } + /// + /// Gets the first element of the extent that contains the specified item + /// + /// Item + /// First element of extent + /// true if item was found in an extent, false otherwise public bool GetStart(byte item, out byte start) { start = 0; diff --git a/Extents/ExtentsInt.cs b/Extents/ExtentsInt.cs index ce631c8b2..d41300106 100644 --- a/Extents/ExtentsInt.cs +++ b/Extents/ExtentsInt.cs @@ -36,22 +36,39 @@ namespace Extents { + /// + /// Implements extents for + /// public class ExtentsInt { List> backend; + /// + /// Initialize an empty list of extents + /// public ExtentsInt() { backend = new List>(); } + /// + /// Initializes extents with an specific list + /// + /// List of extents as tuples "start, end" public ExtentsInt(IEnumerable> list) { backend = list.OrderBy(t => t.Item1).ToList(); } + /// + /// Gets a count of how many extents are stored + /// public int Count => backend.Count; + /// + /// Adds the specified number to the corresponding extent, or creates a new one + /// + /// public void Add(int item) { Tuple removeOne = null; @@ -105,6 +122,12 @@ public void Add(int item) backend = backend.OrderBy(t => t.Item1).ToList(); } + /// + /// Adds a new extent + /// + /// First element of the extent + /// Last element of the extent or if is true how many elements the extent runs for + /// If set to true, indicates how many elements the extent runs for public void Add(int start, int end, bool run = false) { int realEnd; @@ -115,16 +138,29 @@ public void Add(int start, int end, bool run = false) for(int t = start; t <= realEnd; t++) Add(t); } + /// + /// Checks if the specified item is contained by an extent on this instance + /// + /// Item to seach for + /// true if any of the extents on this instance contains the item public bool Contains(int item) { return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2); } + /// + /// Removes all extents from this instance + /// public void Clear() { backend.Clear(); } + /// + /// Removes an item from the extents in this instance + /// + /// Item to remove + /// true if the item was contained in a known extent and removed, false otherwise public bool Remove(int item) { Tuple toRemove = null; @@ -178,11 +214,21 @@ public bool Remove(int item) return true; } + /// + /// Converts the list of extents to an array of where T1 is first element of the extent and T2 is last element + /// + /// Array of public Tuple[] ToArray() { return backend.ToArray(); } + /// + /// Gets the first element of the extent that contains the specified item + /// + /// Item + /// First element of extent + /// true if item was found in an extent, false otherwise public bool GetStart(int item, out int start) { start = 0; diff --git a/Extents/ExtentsLong.cs b/Extents/ExtentsLong.cs index 68a9faf15..b293e822f 100644 --- a/Extents/ExtentsLong.cs +++ b/Extents/ExtentsLong.cs @@ -36,22 +36,39 @@ namespace Extents { + /// + /// Implements extents for + /// public class ExtentsLong { List> backend; + /// + /// Initialize an empty list of extents + /// public ExtentsLong() { backend = new List>(); } + /// + /// Initializes extents with an specific list + /// + /// List of extents as tuples "start, end" public ExtentsLong(IEnumerable> list) { backend = list.OrderBy(t => t.Item1).ToList(); } + /// + /// Gets a count of how many extents are stored + /// public int Count => backend.Count; + /// + /// Adds the specified number to the corresponding extent, or creates a new one + /// + /// public void Add(long item) { Tuple removeOne = null; @@ -105,6 +122,12 @@ public void Add(long item) backend = backend.OrderBy(t => t.Item1).ToList(); } + /// + /// Adds a new extent + /// + /// First element of the extent + /// Last element of the extent or if is true how many elements the extent runs for + /// If set to true, indicates how many elements the extent runs for public void Add(long start, long end, bool run = false) { long realEnd; @@ -115,16 +138,29 @@ public void Add(long start, long end, bool run = false) for(long t = start; t <= realEnd; t++) Add(t); } + /// + /// Checks if the specified item is contained by an extent on this instance + /// + /// Item to seach for + /// true if any of the extents on this instance contains the item public bool Contains(long item) { return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2); } + /// + /// Removes all extents from this instance + /// public void Clear() { backend.Clear(); } + /// + /// Removes an item from the extents in this instance + /// + /// Item to remove + /// true if the item was contained in a known extent and removed, false otherwise public bool Remove(long item) { Tuple toRemove = null; @@ -178,11 +214,21 @@ public bool Remove(long item) return true; } + /// + /// Converts the list of extents to an array of where T1 is first element of the extent and T2 is last element + /// + /// Array of public Tuple[] ToArray() { return backend.ToArray(); } + /// + /// Gets the first element of the extent that contains the specified item + /// + /// Item + /// First element of extent + /// true if item was found in an extent, false otherwise public bool GetStart(long item, out long start) { start = 0; diff --git a/Extents/ExtentsSByte.cs b/Extents/ExtentsSByte.cs index df5b0d151..ef52740df 100644 --- a/Extents/ExtentsSByte.cs +++ b/Extents/ExtentsSByte.cs @@ -36,22 +36,39 @@ namespace Extents { + /// + /// Implements extents for + /// public class ExtentsSByte { List> backend; + /// + /// Initialize an empty list of extents + /// public ExtentsSByte() { backend = new List>(); } + /// + /// Initializes extents with an specific list + /// + /// List of extents as tuples "start, end" public ExtentsSByte(IEnumerable> list) { backend = list.OrderBy(t => t.Item1).ToList(); } + /// + /// Gets a count of how many extents are stored + /// public int Count => backend.Count; + /// + /// Adds the specified number to the corresponding extent, or creates a new one + /// + /// public void Add(sbyte item) { Tuple removeOne = null; @@ -105,6 +122,12 @@ public void Add(sbyte item) backend = backend.OrderBy(t => t.Item1).ToList(); } + /// + /// Adds a new extent + /// + /// First element of the extent + /// Last element of the extent or if is true how many elements the extent runs for + /// If set to true, indicates how many elements the extent runs for public void Add(sbyte start, sbyte end, bool run = false) { sbyte realEnd; @@ -115,16 +138,29 @@ public void Add(sbyte start, sbyte end, bool run = false) for(sbyte t = start; t <= realEnd; t++) Add(t); } + /// + /// Checks if the specified item is contained by an extent on this instance + /// + /// Item to seach for + /// true if any of the extents on this instance contains the item public bool Contains(sbyte item) { return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2); } + /// + /// Removes all extents from this instance + /// public void Clear() { backend.Clear(); } + /// + /// Removes an item from the extents in this instance + /// + /// Item to remove + /// true if the item was contained in a known extent and removed, false otherwise public bool Remove(sbyte item) { Tuple toRemove = null; @@ -178,11 +214,21 @@ public bool Remove(sbyte item) return true; } + /// + /// Converts the list of extents to an array of where T1 is first element of the extent and T2 is last element + /// + /// Array of public Tuple[] ToArray() { return backend.ToArray(); } + /// + /// Gets the first element of the extent that contains the specified item + /// + /// Item + /// First element of extent + /// true if item was found in an extent, false otherwise public bool GetStart(sbyte item, out sbyte start) { start = 0; diff --git a/Extents/ExtentsShort.cs b/Extents/ExtentsShort.cs index 505a4fcba..7c47deeb8 100644 --- a/Extents/ExtentsShort.cs +++ b/Extents/ExtentsShort.cs @@ -36,22 +36,39 @@ namespace Extents { + /// + /// Implements extents for + /// public class ExtentsShort { List> backend; + /// + /// Initialize an empty list of extents + /// public ExtentsShort() { backend = new List>(); } + /// + /// Initializes extents with an specific list + /// + /// List of extents as tuples "start, end" public ExtentsShort(IEnumerable> list) { backend = list.OrderBy(t => t.Item1).ToList(); } + /// + /// Gets a count of how many extents are stored + /// public int Count => backend.Count; + /// + /// Adds the specified number to the corresponding extent, or creates a new one + /// + /// public void Add(short item) { Tuple removeOne = null; @@ -105,6 +122,12 @@ public void Add(short item) backend = backend.OrderBy(t => t.Item1).ToList(); } + /// + /// Adds a new extent + /// + /// First element of the extent + /// Last element of the extent or if is true how many elements the extent runs for + /// If set to true, indicates how many elements the extent runs for public void Add(short start, short end, bool run = false) { short realEnd; @@ -115,16 +138,29 @@ public void Add(short start, short end, bool run = false) for(short t = start; t <= realEnd; t++) Add(t); } + /// + /// Checks if the specified item is contained by an extent on this instance + /// + /// Item to seach for + /// true if any of the extents on this instance contains the item public bool Contains(short item) { return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2); } + /// + /// Removes all extents from this instance + /// public void Clear() { backend.Clear(); } + /// + /// Removes an item from the extents in this instance + /// + /// Item to remove + /// true if the item was contained in a known extent and removed, false otherwise public bool Remove(short item) { Tuple toRemove = null; @@ -178,11 +214,21 @@ public bool Remove(short item) return true; } + /// + /// Converts the list of extents to an array of where T1 is first element of the extent and T2 is last element + /// + /// Array of public Tuple[] ToArray() { return backend.ToArray(); } + /// + /// Gets the first element of the extent that contains the specified item + /// + /// Item + /// First element of extent + /// true if item was found in an extent, false otherwise public bool GetStart(short item, out short start) { start = 0; diff --git a/Extents/ExtentsUInt.cs b/Extents/ExtentsUInt.cs index 5768ba1ec..6ba26e927 100644 --- a/Extents/ExtentsUInt.cs +++ b/Extents/ExtentsUInt.cs @@ -36,22 +36,39 @@ namespace Extents { + /// + /// Implements extents for + /// public class ExtentsUInt { List> backend; + /// + /// Initialize an empty list of extents + /// public ExtentsUInt() { backend = new List>(); } + /// + /// Initializes extents with an specific list + /// + /// List of extents as tuples "start, end" public ExtentsUInt(IEnumerable> list) { backend = list.OrderBy(t => t.Item1).ToList(); } + /// + /// Gets a count of how many extents are stored + /// public int Count => backend.Count; + /// + /// Adds the specified number to the corresponding extent, or creates a new one + /// + /// public void Add(uint item) { Tuple removeOne = null; @@ -105,6 +122,12 @@ public void Add(uint item) backend = backend.OrderBy(t => t.Item1).ToList(); } + /// + /// Adds a new extent + /// + /// First element of the extent + /// Last element of the extent or if is true how many elements the extent runs for + /// If set to true, indicates how many elements the extent runs for public void Add(uint start, uint end, bool run = false) { uint realEnd; @@ -115,16 +138,29 @@ public void Add(uint start, uint end, bool run = false) for(uint t = start; t <= realEnd; t++) Add(t); } + /// + /// Checks if the specified item is contained by an extent on this instance + /// + /// Item to seach for + /// true if any of the extents on this instance contains the item public bool Contains(uint item) { return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2); } + /// + /// Removes all extents from this instance + /// public void Clear() { backend.Clear(); } + /// + /// Removes an item from the extents in this instance + /// + /// Item to remove + /// true if the item was contained in a known extent and removed, false otherwise public bool Remove(uint item) { Tuple toRemove = null; @@ -178,11 +214,21 @@ public bool Remove(uint item) return true; } + /// + /// Converts the list of extents to an array of where T1 is first element of the extent and T2 is last element + /// + /// Array of public Tuple[] ToArray() { return backend.ToArray(); } + /// + /// Gets the first element of the extent that contains the specified item + /// + /// Item + /// First element of extent + /// true if item was found in an extent, false otherwise public bool GetStart(uint item, out uint start) { start = 0; diff --git a/Extents/ExtentsULong.cs b/Extents/ExtentsULong.cs index f5cc9eb9c..60e5813a7 100644 --- a/Extents/ExtentsULong.cs +++ b/Extents/ExtentsULong.cs @@ -36,22 +36,39 @@ namespace Extents { + /// + /// Implements extents for + /// public class ExtentsULong { List> backend; + /// + /// Initialize an empty list of extents + /// public ExtentsULong() { backend = new List>(); } + /// + /// Initializes extents with an specific list + /// + /// List of extents as tuples "start, end" public ExtentsULong(IEnumerable> list) { backend = list.OrderBy(t => t.Item1).ToList(); } + /// + /// Gets a count of how many extents are stored + /// public int Count => backend.Count; + /// + /// Adds the specified number to the corresponding extent, or creates a new one + /// + /// public void Add(ulong item) { Tuple removeOne = null; @@ -105,6 +122,12 @@ public void Add(ulong item) backend = backend.OrderBy(t => t.Item1).ToList(); } + /// + /// Adds a new extent + /// + /// First element of the extent + /// Last element of the extent or if is true how many elements the extent runs for + /// If set to true, indicates how many elements the extent runs for public void Add(ulong start, ulong end, bool run = false) { ulong realEnd; @@ -115,16 +138,29 @@ public void Add(ulong start, ulong end, bool run = false) for(ulong t = start; t <= realEnd; t++) Add(t); } + /// + /// Checks if the specified item is contained by an extent on this instance + /// + /// Item to seach for + /// true if any of the extents on this instance contains the item public bool Contains(ulong item) { return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2); } + /// + /// Removes all extents from this instance + /// public void Clear() { backend.Clear(); } + /// + /// Removes an item from the extents in this instance + /// + /// Item to remove + /// true if the item was contained in a known extent and removed, false otherwise public bool Remove(ulong item) { Tuple toRemove = null; @@ -178,11 +214,21 @@ public bool Remove(ulong item) return true; } + /// + /// Converts the list of extents to an array of where T1 is first element of the extent and T2 is last element + /// + /// Array of public Tuple[] ToArray() { return backend.ToArray(); } + /// + /// Gets the first element of the extent that contains the specified item + /// + /// Item + /// First element of extent + /// true if item was found in an extent, false otherwise public bool GetStart(ulong item, out ulong start) { start = 0; diff --git a/Extents/ExtentsUShort.cs b/Extents/ExtentsUShort.cs index 530f7951f..bf01658a9 100644 --- a/Extents/ExtentsUShort.cs +++ b/Extents/ExtentsUShort.cs @@ -36,22 +36,39 @@ namespace Extents { + /// + /// Implements extents for + /// public class ExtentsUShort { List> backend; + /// + /// Initialize an empty list of extents + /// public ExtentsUShort() { backend = new List>(); } + /// + /// Initializes extents with an specific list + /// + /// List of extents as tuples "start, end" public ExtentsUShort(IEnumerable> list) { backend = list.OrderBy(t => t.Item1).ToList(); } + /// + /// Gets a count of how many extents are stored + /// public int Count => backend.Count; + /// + /// Adds the specified number to the corresponding extent, or creates a new one + /// + /// public void Add(ushort item) { Tuple removeOne = null; @@ -105,6 +122,12 @@ public void Add(ushort item) backend = backend.OrderBy(t => t.Item1).ToList(); } + /// + /// Adds a new extent + /// + /// First element of the extent + /// Last element of the extent or if is true how many elements the extent runs for + /// If set to true, indicates how many elements the extent runs for public void Add(ushort start, ushort end, bool run = false) { ushort realEnd; @@ -115,16 +138,29 @@ public void Add(ushort start, ushort end, bool run = false) for(ushort t = start; t <= realEnd; t++) Add(t); } + /// + /// Checks if the specified item is contained by an extent on this instance + /// + /// Item to seach for + /// true if any of the extents on this instance contains the item public bool Contains(ushort item) { return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2); } + /// + /// Removes all extents from this instance + /// public void Clear() { backend.Clear(); } + /// + /// Removes an item from the extents in this instance + /// + /// Item to remove + /// true if the item was contained in a known extent and removed, false otherwise public bool Remove(ushort item) { Tuple toRemove = null; @@ -178,11 +214,21 @@ public bool Remove(ushort item) return true; } + /// + /// Converts the list of extents to an array of where T1 is first element of the extent and T2 is last element + /// + /// Array of public Tuple[] ToArray() { return backend.ToArray(); } + /// + /// Gets the first element of the extent that contains the specified item + /// + /// Item + /// First element of extent + /// true if item was found in an extent, false otherwise public bool GetStart(ushort item, out ushort start) { start = 0; diff --git a/PrintHex.cs b/PrintHex.cs index 291b30154..1d2024386 100644 --- a/PrintHex.cs +++ b/PrintHex.cs @@ -37,11 +37,22 @@ namespace DiscImageChef { public static class PrintHex { + /// + /// Prints a byte array as hexadecimal values to the console + /// + /// Array + /// Width of line public static void PrintHexArray(byte[] array, int width) { DicConsole.WriteLine(ByteArrayToHexArrayString(array, width)); } + /// + /// Prints a byte array as hexadecimal values to a string + /// + /// Array + /// Width of line + /// String containing hexadecimal values public static string ByteArrayToHexArrayString(byte[] array, int width) { StringBuilder sb = new StringBuilder(); From 1219a7bee4da98ec4b09cb801dde1e90f800c387 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sat, 23 Dec 2017 03:52:45 +0000 Subject: [PATCH 070/217] DOCUMENTATION: Removed unused code from DiscImageChef.Helpers. --- DiscImageChef.Helpers.csproj | 3 +- EndianAwareBinaryReader.cs | 141 ----------------------------------- 2 files changed, 1 insertion(+), 143 deletions(-) delete mode 100644 EndianAwareBinaryReader.cs diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index d41be17c2..8bd7bf182 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -1,4 +1,4 @@ - + Debug @@ -38,7 +38,6 @@ - diff --git a/EndianAwareBinaryReader.cs b/EndianAwareBinaryReader.cs deleted file mode 100644 index a108895f7..000000000 --- a/EndianAwareBinaryReader.cs +++ /dev/null @@ -1,141 +0,0 @@ -// /*************************************************************************** -// The Disc Image Chef -// ---------------------------------------------------------------------------- -// -// Filename : EndianAwareBinaryReader.cs -// Author(s) : Natalia Portillo -// -// Component : Helpers. -// -// --[ Description ] ---------------------------------------------------------- -// -// Override for System.IO.Binary.Reader that knows how to handle big-endian. -// -// --[ License ] -------------------------------------------------------------- -// -// This library is free software; you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 2.1 of the -// License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, see . -// -// ---------------------------------------------------------------------------- -// Copyright © 2011-2018 Natalia Portillo -// ****************************************************************************/ - -// TODO: Just remove -using System; -using System.IO; -using System.Linq; -using System.Text; - -namespace DiscImageChef -{ - public class EndianAwareBinaryReader : BinaryReader - { - readonly byte[] buffer = new byte[8]; - - public EndianAwareBinaryReader(Stream input, Encoding encoding, bool isLittleEndian) : base(input, encoding) - { - IsLittleEndian = isLittleEndian; - } - - public EndianAwareBinaryReader(Stream input, bool isLittleEndian) : - this(input, Encoding.UTF8, isLittleEndian) { } - - public bool IsLittleEndian { get; set; } - - public override double ReadDouble() - { - if(IsLittleEndian) return base.ReadDouble(); - - FillMyBuffer(8); - return BitConverter.ToDouble(buffer.Take(8).Reverse().ToArray(), 0); - } - - public override short ReadInt16() - { - if(IsLittleEndian) return base.ReadInt16(); - - FillMyBuffer(2); - return BitConverter.ToInt16(buffer.Take(2).Reverse().ToArray(), 0); - } - - public override int ReadInt32() - { - if(IsLittleEndian) return base.ReadInt32(); - - FillMyBuffer(4); - return BitConverter.ToInt32(buffer.Take(4).Reverse().ToArray(), 0); - } - - public override long ReadInt64() - { - if(IsLittleEndian) return base.ReadInt64(); - - FillMyBuffer(8); - return BitConverter.ToInt64(buffer.Take(8).Reverse().ToArray(), 0); - } - - public override float ReadSingle() - { - if(IsLittleEndian) return base.ReadSingle(); - - FillMyBuffer(4); - return BitConverter.ToSingle(buffer.Take(4).Reverse().ToArray(), 0); - } - - public override ushort ReadUInt16() - { - if(IsLittleEndian) return base.ReadUInt16(); - - FillMyBuffer(2); - return BitConverter.ToUInt16(buffer.Take(2).Reverse().ToArray(), 0); - } - - public override uint ReadUInt32() - { - if(IsLittleEndian) return base.ReadUInt32(); - - FillMyBuffer(4); - return BitConverter.ToUInt32(buffer.Take(4).Reverse().ToArray(), 0); - } - - public override ulong ReadUInt64() - { - if(IsLittleEndian) return base.ReadUInt64(); - - FillMyBuffer(8); - return BitConverter.ToUInt64(buffer.Take(8).Reverse().ToArray(), 0); - } - - void FillMyBuffer(int numBytes) - { - int offset = 0; - int num2; - if(numBytes == 1) - { - num2 = BaseStream.ReadByte(); - if(num2 == -1) throw new EndOfStreamException("Attempted to read past the end of the stream."); - - buffer[0] = (byte)num2; - } - else - do - { - num2 = BaseStream.Read(buffer, offset, numBytes - offset); - if(num2 == 0) throw new EndOfStreamException("Attempted to read past the end of the stream."); - - offset += num2; - } - while(offset < numBytes); - } - } -} \ No newline at end of file From 81034236d0cec98a15a24fc315a2f6fc47a92f79 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sat, 23 Dec 2017 03:58:01 +0000 Subject: [PATCH 071/217] DOCUMENTATION: Removed unneeded AppleDouble DateTime handler. --- DateHandlers.cs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/DateHandlers.cs b/DateHandlers.cs index 56dda5f56..6fb1b5bf6 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -44,7 +44,6 @@ public static class DateHandlers // Day 0 of Julian Date system static readonly DateTime JulianEpoch = new DateTime(1858, 11, 17, 0, 0, 0); static readonly DateTime AmigaEpoch = new DateTime(1978, 1, 1, 0, 0, 0); - static readonly DateTime AppleDoubleEpoch = new DateTime(1970, 1, 1, 0, 0, 0); /// /// Converts a Macintosh timestamp to a .NET DateTime @@ -290,12 +289,6 @@ public static DateTime CPMToDateTime(byte[] timestamp) return temp; } - // TODO: This is unix - public static DateTime AppleDoubleToDateTime(ulong AppleDoubleTimeStamp) - { - return AppleDoubleEpoch.AddSeconds(AppleDoubleTimeStamp); - } - /// /// Converts an ECMA timestamp to a .NET DateTime /// From b986e4c08ebefa4c694bce8ad089b5195872e7df Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sat, 23 Dec 2017 03:59:48 +0000 Subject: [PATCH 072/217] DOCUMENTATION: DateTime handlers. --- DateHandlers.cs | 142 +++++++++++++++++++++++------------------------- 1 file changed, 68 insertions(+), 74 deletions(-) diff --git a/DateHandlers.cs b/DateHandlers.cs index 6fb1b5bf6..87f0b7105 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -40,59 +40,61 @@ 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 UNIXEpoch = new DateTime(1970, 1, 1, 0, 0, 0); - // Day 0 of Julian Date system + static readonly DateTime UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0); + /// + /// Day 0 of Julian Date system + /// static readonly DateTime JulianEpoch = new DateTime(1858, 11, 17, 0, 0, 0); static readonly DateTime AmigaEpoch = new DateTime(1978, 1, 1, 0, 0, 0); /// /// Converts a Macintosh timestamp to a .NET DateTime /// - /// Macintosh timestamp (seconds since 1st Jan. 1904) + /// Macintosh timestamp (seconds since 1st Jan. 1904) /// .NET DateTime - public static DateTime MacToDateTime(ulong MacTimeStamp) + public static DateTime MacToDateTime(ulong macTimeStamp) { - return MacEpoch.AddTicks((long)(MacTimeStamp * 10000000)); + return MacEpoch.AddTicks((long)(macTimeStamp * 10000000)); } /// /// Converts a Lisa timestamp to a .NET DateTime /// - /// Lisa timestamp (seconds since 1st Jan. 1901) + /// Lisa timestamp (seconds since 1st Jan. 1901) /// .NET DateTime - public static DateTime LisaToDateTime(uint LisaTimeStamp) + public static DateTime LisaToDateTime(uint lisaTimeStamp) { - return LisaEpoch.AddSeconds(LisaTimeStamp); + return LisaEpoch.AddSeconds(lisaTimeStamp); } /// /// Converts a UNIX timestamp to a .NET DateTime /// - /// UNIX timestamp (seconds since 1st Jan. 1970) + /// UNIX timestamp (seconds since 1st Jan. 1970) /// .NET DateTime - public static DateTime UNIXToDateTime(int UNIXTimeStamp) + public static DateTime UnixToDateTime(int unixTimeStamp) { - return UNIXEpoch.AddSeconds(UNIXTimeStamp); + return UnixEpoch.AddSeconds(unixTimeStamp); } /// /// Converts a UNIX timestamp to a .NET DateTime /// - /// UNIX timestamp (seconds since 1st Jan. 1970) + /// UNIX timestamp (seconds since 1st Jan. 1970) /// .NET DateTime - public static DateTime UNIXToDateTime(long UNIXTimeStamp) + public static DateTime UnixToDateTime(long unixTimeStamp) { - return UNIXEpoch.AddSeconds(UNIXTimeStamp); + return UnixEpoch.AddSeconds(unixTimeStamp); } /// /// Converts a UNIX timestamp to a .NET DateTime /// - /// UNIX timestamp (seconds since 1st Jan. 1970) + /// UNIX timestamp (seconds since 1st Jan. 1970) /// .NET DateTime - public static DateTime UNIXUnsignedToDateTime(uint UNIXTimeStamp) + public static DateTime UnixUnsignedToDateTime(uint unixTimeStamp) { - return UNIXEpoch.AddSeconds(UNIXTimeStamp); + return UnixEpoch.AddSeconds(unixTimeStamp); } /// @@ -101,103 +103,95 @@ public static DateTime UNIXUnsignedToDateTime(uint UNIXTimeStamp) /// Seconds since 1st Jan. 1970) /// Nanoseconds /// .NET DateTime - public static DateTime UNIXUnsignedToDateTime(uint seconds, uint nanoseconds) + public static DateTime UnixUnsignedToDateTime(uint seconds, uint nanoseconds) { - return UNIXEpoch.AddSeconds(seconds).AddTicks((long)nanoseconds / 100); + return UnixEpoch.AddSeconds(seconds).AddTicks((long)nanoseconds / 100); } /// /// Converts a UNIX timestamp to a .NET DateTime /// - /// UNIX timestamp (seconds since 1st Jan. 1970) + /// UNIX timestamp (seconds since 1st Jan. 1970) /// .NET DateTime - public static DateTime UNIXUnsignedToDateTime(ulong UNIXTimeStamp) + public static DateTime UnixUnsignedToDateTime(ulong unixTimeStamp) { - return UNIXEpoch.AddSeconds(UNIXTimeStamp); + return UnixEpoch.AddSeconds(unixTimeStamp); } /// /// Converts a High Sierra Format timestamp to a .NET DateTime /// - /// High Sierra Format timestamp + /// High Sierra Format timestamp /// .NET DateTime - public static DateTime HighSierraToDateTime(byte[] VDDateTime) + public static DateTime HighSierraToDateTime(byte[] vdDateTime) { byte[] isotime = new byte[17]; - Array.Copy(VDDateTime, 0, isotime, 0, 16); - return ISO9660ToDateTime(isotime); + Array.Copy(vdDateTime, 0, isotime, 0, 16); + return Iso9660ToDateTime(isotime); } // TODO: Timezone /// /// Converts an ISO9660 timestamp to a .NET DateTime /// - /// ISO9660 timestamp + /// ISO9660 timestamp /// .NET DateTime - public static DateTime ISO9660ToDateTime(byte[] VDDateTime) + public static DateTime Iso9660ToDateTime(byte[] vdDateTime) { - int year, month, day, hour, minute, second, hundredths; byte[] twocharvalue = new byte[2]; byte[] fourcharvalue = new byte[4]; - fourcharvalue[0] = VDDateTime[0]; - fourcharvalue[1] = VDDateTime[1]; - fourcharvalue[2] = VDDateTime[2]; - fourcharvalue[3] = VDDateTime[3]; + fourcharvalue[0] = vdDateTime[0]; + fourcharvalue[1] = vdDateTime[1]; + fourcharvalue[2] = vdDateTime[2]; + fourcharvalue[3] = vdDateTime[3]; DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "year = \"{0}\"", StringHandlers.CToString(fourcharvalue, Encoding.ASCII)); - if(!int.TryParse(StringHandlers.CToString(fourcharvalue, Encoding.ASCII), out year)) year = 0; - // year = Convert.ToInt32(StringHandlers.CToString(fourcharvalue, Encoding.ASCII)); + if(!int.TryParse(StringHandlers.CToString(fourcharvalue, Encoding.ASCII), out int year)) year = 0; - twocharvalue[0] = VDDateTime[4]; - twocharvalue[1] = VDDateTime[5]; + twocharvalue[0] = vdDateTime[4]; + twocharvalue[1] = vdDateTime[5]; DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "month = \"{0}\"", StringHandlers.CToString(twocharvalue, Encoding.ASCII)); - if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out month)) month = 0; - // month = Convert.ToInt32(StringHandlers.CToString(twocharvalue, Encoding.ASCII)); + if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out int month)) month = 0; - twocharvalue[0] = VDDateTime[6]; - twocharvalue[1] = VDDateTime[7]; + twocharvalue[0] = vdDateTime[6]; + twocharvalue[1] = vdDateTime[7]; DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "day = \"{0}\"", StringHandlers.CToString(twocharvalue, Encoding.ASCII)); - if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out day)) day = 0; - // day = Convert.ToInt32(StringHandlers.CToString(twocharvalue, Encoding.ASCII)); + if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out int day)) day = 0; - twocharvalue[0] = VDDateTime[8]; - twocharvalue[1] = VDDateTime[9]; + twocharvalue[0] = vdDateTime[8]; + twocharvalue[1] = vdDateTime[9]; DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "hour = \"{0}\"", StringHandlers.CToString(twocharvalue, Encoding.ASCII)); - if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out hour)) hour = 0; - // hour = Convert.ToInt32(StringHandlers.CToString(twocharvalue, Encoding.ASCII)); + if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out int hour)) hour = 0; - twocharvalue[0] = VDDateTime[10]; - twocharvalue[1] = VDDateTime[11]; + twocharvalue[0] = vdDateTime[10]; + twocharvalue[1] = vdDateTime[11]; DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "minute = \"{0}\"", StringHandlers.CToString(twocharvalue, Encoding.ASCII)); - if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out minute)) minute = 0; - // minute = Convert.ToInt32(StringHandlers.CToString(twocharvalue, Encoding.ASCII)); + if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out int minute)) minute = 0; - twocharvalue[0] = VDDateTime[12]; - twocharvalue[1] = VDDateTime[13]; + twocharvalue[0] = vdDateTime[12]; + twocharvalue[1] = vdDateTime[13]; DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "second = \"{0}\"", StringHandlers.CToString(twocharvalue, Encoding.ASCII)); - if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out second)) second = 0; - // second = Convert.ToInt32(StringHandlers.CToString(twocharvalue, Encoding.ASCII)); + if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out int second)) second = 0; - twocharvalue[0] = VDDateTime[14]; - twocharvalue[1] = VDDateTime[15]; + twocharvalue[0] = vdDateTime[14]; + twocharvalue[1] = vdDateTime[15]; DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "hundredths = \"{0}\"", StringHandlers.CToString(twocharvalue, Encoding.ASCII)); - if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out hundredths)) hundredths = 0; - // hundredths = Convert.ToInt32(StringHandlers.CToString(twocharvalue, Encoding.ASCII)); + if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out int hundredths)) hundredths = 0; DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "decodedDT = new DateTime({0}, {1}, {2}, {3}, {4}, {5}, {6}, DateTimeKind.Unspecified);", year, month, day, hour, minute, second, hundredths * 10); - DateTime decodedDT = new DateTime(year, month, day, hour, minute, second, hundredths * 10, + DateTime decodedDt = new DateTime(year, month, day, hour, minute, second, hundredths * 10, DateTimeKind.Unspecified); - return decodedDT; + return decodedDt; } /// @@ -206,7 +200,7 @@ public static DateTime ISO9660ToDateTime(byte[] VDDateTime) /// VMS timestamp (tenths of microseconds since day 0 of the Julian Date) /// .NET DateTime /// C# works in UTC, VMS on Julian Date, some displacement may occur on disks created outside UTC - public static DateTime VMSToDateTime(ulong vmsDate) + public static DateTime VmsToDateTime(ulong vmsDate) { double delta = vmsDate * 0.0001; // Tenths of microseconds to milliseconds, will lose some detail return JulianEpoch.AddMilliseconds(delta); @@ -231,7 +225,7 @@ public static DateTime AmigaToDateTime(uint days, uint minutes, uint ticks) /// /// UCSD Pascal timestamp /// .NET DateTime - public static DateTime UCSDPascalToDateTime(short dateRecord) + public static DateTime UcsdPascalToDateTime(short dateRecord) { int year = ((dateRecord & 0xFE00) >> 9) + 1900; int day = (dateRecord & 0x01F0) >> 4; @@ -249,7 +243,7 @@ public static DateTime UCSDPascalToDateTime(short dateRecord) /// Date /// Time /// .NET DateTime - public static DateTime DOSToDateTime(ushort date, ushort time) + public static DateTime DosToDateTime(ushort date, ushort time) { int year = ((date & 0xFE00) >> 9) + 1980; int month = (date & 0x1E0) >> 5; @@ -276,7 +270,7 @@ public static DateTime DOSToDateTime(ushort date, ushort time) /// /// CP/M timestamp /// .NET DateTime - public static DateTime CPMToDateTime(byte[] timestamp) + public static DateTime CpmToDateTime(byte[] timestamp) { ushort days = BitConverter.ToUInt16(timestamp, 0); int hours = timestamp[2]; @@ -303,7 +297,7 @@ public static DateTime CPMToDateTime(byte[] timestamp) /// Hundreds of microseconds /// Microseconds /// - public static DateTime ECMAToDateTime(ushort typeAndTimeZone, short year, byte month, byte day, byte hour, + public static DateTime EcmaToDateTime(ushort typeAndTimeZone, short year, byte month, byte day, byte hour, byte minute, byte second, byte centiseconds, byte hundredsOfMicroseconds, byte microseconds) { @@ -330,11 +324,11 @@ public static DateTime ECMAToDateTime(ushort typeAndTimeZone, short year, byte m /// /// Convers a Solaris high resolution timestamp to .NET DateTime /// - /// Solaris high resolution timestamp + /// Solaris high resolution timestamp /// .NET DateTime - public static DateTime UNIXHrTimeToDateTime(ulong HRTimeStamp) + public static DateTime UnixHrTimeToDateTime(ulong hrTimeStamp) { - return UNIXEpoch.AddTicks((long)(HRTimeStamp / 100)); + return UnixEpoch.AddTicks((long)(hrTimeStamp / 100)); } /// @@ -342,21 +336,21 @@ public static DateTime UNIXHrTimeToDateTime(ulong HRTimeStamp) /// /// OS-9 timestamp /// .NET DateTime - public static DateTime OS9ToDateTime(byte[] date) + public static DateTime Os9ToDateTime(byte[] date) { if(date == null || date.Length != 3 && date.Length != 5) return DateTime.MinValue; - DateTime os9date; + DateTime os9Date; try { - os9date = date.Length == 5 + 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); } - catch(ArgumentOutOfRangeException) { os9date = new DateTime(1900, 0, 0, 0, 0, 0); } + catch(ArgumentOutOfRangeException) { os9Date = new DateTime(1900, 0, 0, 0, 0, 0); } - return os9date; + return os9Date; } /// From 8a97502c96792c4d78480993dbcf14c9ff9b7581 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 24 Dec 2017 02:46:53 +0000 Subject: [PATCH 073/217] REFACTOR: Final cleanup of DiscImageChef.Helpers. --- ArrayFill.cs | 12 ++- ArrayIsEmpty.cs | 4 +- BigEndianBitConverter.cs | 195 ++++++++++++++++++++++++++------------- BigEndianMarshal.cs | 8 +- CHS.cs | 2 +- CompareBytes.cs | 2 +- CountBits.cs | 2 +- DateHandlers.cs | 43 ++++----- Extents/ExtentsByte.cs | 35 ++++--- Extents/ExtentsInt.cs | 35 ++++--- Extents/ExtentsLong.cs | 35 ++++--- Extents/ExtentsSByte.cs | 35 ++++--- Extents/ExtentsShort.cs | 35 ++++--- Extents/ExtentsUInt.cs | 35 ++++--- Extents/ExtentsULong.cs | 35 ++++--- Extents/ExtentsUShort.cs | 36 +++++--- PrintHex.cs | 4 +- StringHandlers.cs | 14 +-- Swapping.cs | 8 +- 19 files changed, 345 insertions(+), 230 deletions(-) diff --git a/ArrayFill.cs b/ArrayFill.cs index 811b33761..122bccda0 100644 --- a/ArrayFill.cs +++ b/ArrayFill.cs @@ -32,7 +32,7 @@ namespace DiscImageChef public static partial class ArrayHelpers { /// - /// Fills an array with the specified value + /// Fills an array with the specified value /// /// Array /// Value @@ -44,7 +44,7 @@ public static void ArrayFill(T[] destinationArray, T value) } /// - /// Fills an array with the contents of the specified array + /// Fills an array with the contents of the specified array /// /// Array /// Value @@ -53,7 +53,8 @@ public static void ArrayFill(T[] destinationArray, T[] value) { if(destinationArray == null) throw new ArgumentNullException(nameof(destinationArray)); - if(value.Length > destinationArray.Length) throw new ArgumentException("Length of value array must not be more than length of destination"); + if(value.Length > destinationArray.Length) + throw new ArgumentException("Length of value array must not be more than length of destination"); // set the initial array value Array.Copy(value, destinationArray, value.Length); @@ -61,13 +62,14 @@ public static void ArrayFill(T[] destinationArray, T[] value) int arrayToFillHalfLength = destinationArray.Length / 2; int copyLength; - for(copyLength = value.Length; copyLength < arrayToFillHalfLength; copyLength <<= 1) Array.Copy(destinationArray, 0, destinationArray, copyLength, copyLength); + for(copyLength = value.Length; copyLength < arrayToFillHalfLength; copyLength <<= 1) + Array.Copy(destinationArray, 0, destinationArray, copyLength, copyLength); Array.Copy(destinationArray, 0, destinationArray, copyLength, destinationArray.Length - copyLength); } /// - /// Converts a byte array to its hexadecimal representation + /// Converts a byte array to its hexadecimal representation /// /// Byte array /// true to use uppercase diff --git a/ArrayIsEmpty.cs b/ArrayIsEmpty.cs index cec1d9cb8..e22da3767 100644 --- a/ArrayIsEmpty.cs +++ b/ArrayIsEmpty.cs @@ -37,7 +37,7 @@ namespace DiscImageChef public static partial class ArrayHelpers { /// - /// Checks if an array is null, filled with the NULL byte (0x00) or ASCII whitespace (0x20) + /// Checks if an array is null, filled with the NULL byte (0x00) or ASCII whitespace (0x20) /// /// Array /// True if null or whitespace @@ -47,7 +47,7 @@ public static bool ArrayIsNullOrWhiteSpace(byte[] array) } /// - /// Checks if an array is null or filled with the NULL byte (0x00) + /// Checks if an array is null or filled with the NULL byte (0x00) /// /// Array /// True if null diff --git a/BigEndianBitConverter.cs b/BigEndianBitConverter.cs index 53064d00d..b017ce94d 100644 --- a/BigEndianBitConverter.cs +++ b/BigEndianBitConverter.cs @@ -36,21 +36,21 @@ namespace DiscImageChef { /// - /// Converts base data types to an array of bytes, and an array of bytes to base - /// data types. - /// All info taken from the meta data of System.BitConverter. This implementation - /// allows for Endianness consideration. + /// Converts base data types to an array of bytes, and an array of bytes to base + /// data types. + /// All info taken from the meta data of System.BitConverter. This implementation + /// allows for Endianness consideration. /// public static class BigEndianBitConverter { /// - /// Indicates the byte order ("endianess") in which data is stored in this computer - /// architecture. + /// Indicates the byte order ("endianess") in which data is stored in this computer + /// architecture. /// public static bool IsLittleEndian { get; set; } /// - /// Converts the specified double-precision floating point number to a 64-bit signed integer. + /// Converts the specified double-precision floating point number to a 64-bit signed integer. /// /// The number to convert. /// A 64-bit signed integer whose value is equivalent to value. @@ -61,7 +61,7 @@ public static long DoubleToInt64Bits(double value) } /// - /// Returns the specified Boolean value as an array of bytes. + /// Returns the specified Boolean value as an array of bytes. /// /// A Boolean value. /// An array of bytes with length 1. @@ -71,7 +71,7 @@ public static byte[] GetBytes(bool value) } /// - /// Returns the specified Unicode character value as an array of bytes. + /// Returns the specified Unicode character value as an array of bytes. /// /// A character to convert. /// An array of bytes with length 2. @@ -81,7 +81,7 @@ public static byte[] GetBytes(char value) } /// - /// Returns the specified double-precision floating point value as an array of bytes. + /// Returns the specified double-precision floating point value as an array of bytes. /// /// The number to convert. /// An array of bytes with length 8. @@ -91,7 +91,7 @@ public static byte[] GetBytes(double value) } /// - /// Returns the specified single-precision floating point value as an array of bytes. + /// Returns the specified single-precision floating point value as an array of bytes. /// /// The number to convert. /// An array of bytes with length 4. @@ -101,7 +101,7 @@ public static byte[] GetBytes(float value) } /// - /// Returns the specified 32-bit signed integer value as an array of bytes. + /// Returns the specified 32-bit signed integer value as an array of bytes. /// /// The number to convert. /// An array of bytes with length 4. @@ -111,7 +111,7 @@ public static byte[] GetBytes(int value) } /// - /// Returns the specified 64-bit signed integer value as an array of bytes. + /// Returns the specified 64-bit signed integer value as an array of bytes. /// /// The number to convert. /// An array of bytes with length 8. @@ -121,7 +121,7 @@ public static byte[] GetBytes(long value) } /// - /// Returns the specified 16-bit signed integer value as an array of bytes. + /// Returns the specified 16-bit signed integer value as an array of bytes. /// /// The number to convert. /// An array of bytes with length 2. @@ -131,7 +131,7 @@ public static byte[] GetBytes(short value) } /// - /// Returns the specified 32-bit unsigned integer value as an array of bytes. + /// Returns the specified 32-bit unsigned integer value as an array of bytes. /// /// The number to convert. /// An array of bytes with length 4. @@ -141,7 +141,7 @@ public static byte[] GetBytes(uint value) } /// - /// Returns the specified 64-bit unsigned integer value as an array of bytes. + /// Returns the specified 64-bit unsigned integer value as an array of bytes. /// /// The number to convert. /// An array of bytes with length 8. @@ -151,7 +151,7 @@ public static byte[] GetBytes(ulong value) } /// - /// Returns the specified 16-bit unsigned integer value as an array of bytes. + /// Returns the specified 16-bit unsigned integer value as an array of bytes. /// /// The number to convert. /// An array of bytes with length 2. @@ -161,7 +161,7 @@ public static byte[] GetBytes(ushort value) } /// - /// Converts the specified 64-bit signed integer to a double-precision floating point number. + /// Converts the specified 64-bit signed integer to a double-precision floating point number. /// /// The number to convert. /// A double-precision floating point number whose value is equivalent to value. @@ -171,55 +171,71 @@ public static double Int64BitsToDouble(long value) } /// - /// Returns a Boolean value converted from one byte at a specified position in a byte array. + /// Returns a Boolean value converted from one byte at a specified position in a byte array. /// /// An array of bytes. /// The starting position within value. - /// true if the byte at in value is nonzero; otherwise, false. + /// true if the byte at in value is nonzero; otherwise, false. /// value is null. - /// is less than zero or greater than the length of value minus 1. + /// + /// is less than zero or greater than the + /// length of value minus 1. + /// public static bool ToBoolean(byte[] value, int startIndex) { throw new NotImplementedException(); } /// - /// Returns a Unicode character converted from two bytes at a specified position in a byte array. + /// Returns a Unicode character converted from two bytes at a specified position in a byte array. /// /// An array. /// The starting position within value. - /// A character formed by two bytes beginning at . - /// equals the length of value minus 1. + /// A character formed by two bytes beginning at . + /// equals the length of value minus 1. /// value is null. - /// is less than zero or greater than the length of value minus 1. + /// + /// is less than zero or greater than the + /// length of value minus 1. + /// public static char ToChar(byte[] value, int startIndex) { throw new NotImplementedException(); } /// - /// Returns a double-precision floating point number converted from eight bytes at a specified position in a byte array. + /// Returns a double-precision floating point number converted from eight bytes at a specified position in a byte + /// array. /// /// An array of bytes. /// The starting position within value. - /// A double precision floating point number formed by eight bytes beginning at . - /// 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. + /// A double precision floating point number formed by eight bytes beginning at . + /// + /// 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. + /// /// value is null. - /// is less than zero or greater than the length of value minus 1. + /// + /// is less than zero or greater than the + /// length of value minus 1. + /// public static double ToDouble(byte[] value, int startIndex) { throw new NotImplementedException(); } /// - /// Returns a 16-bit signed integer converted from two bytes at a specified position in a byte array. + /// Returns a 16-bit signed integer converted from two bytes at a specified position in a byte array. /// /// An array of bytes. /// The starting position within value. - /// A 16-bit signed integer formed by two bytes beginning at . - /// equals the length of value minus 1. + /// A 16-bit signed integer formed by two bytes beginning at . + /// equals the length of value minus 1. /// value is null. - /// startIndex is less than zero or greater than the length of value minus 1. + /// + /// startIndex is less than zero or greater than the length of value + /// minus 1. + /// public static short ToInt16(byte[] value, int startIndex) { return !IsLittleEndian @@ -228,14 +244,20 @@ public static short ToInt16(byte[] value, int startIndex) } /// - /// Returns a 32-bit signed integer converted from four bytes at a specified position in a byte array. + /// Returns a 32-bit signed integer converted from four bytes at a specified position in a byte array. /// /// An array of bytes. /// The starting position within value. - /// A 32-bit signed integer formed by four bytes beginning at . - /// 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. + /// A 32-bit signed integer formed by four bytes beginning at . + /// + /// 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. + /// /// value is null. - /// startIndex is less than zero or greater than the length of value minus 1. + /// + /// startIndex is less than zero or greater than the length of value + /// minus 1. + /// public static int ToInt32(byte[] value, int startIndex) { return !IsLittleEndian @@ -244,14 +266,20 @@ public static int ToInt32(byte[] value, int startIndex) } /// - /// Returns a 64-bit signed integer converted from eight bytes at a specified position in a byte array. + /// Returns a 64-bit signed integer converted from eight bytes at a specified position in a byte array. /// /// An array of bytes. /// The starting position within value. - /// A 64-bit signed integer formed by eight bytes beginning at . - /// 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. + /// A 64-bit signed integer formed by eight bytes beginning at . + /// + /// 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. + /// /// value is null. - /// is less than zero or greater than the length of value minus 1. + /// + /// is less than zero or greater than the + /// length of value minus 1. + /// public static long ToInt64(byte[] value, int startIndex) { return !IsLittleEndian @@ -260,14 +288,21 @@ public static long ToInt64(byte[] value, int startIndex) } /// - /// Returns a single-precision floating point number converted from four bytes at a specified position in a byte array. + /// Returns a single-precision floating point number converted from four bytes at a specified position in a byte + /// array. /// /// An array of bytes. /// The starting position within value. - /// A single-precision floating point number formed by four bytes beginning at . - /// 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. + /// A single-precision floating point number formed by four bytes beginning at . + /// + /// 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. + /// /// value is null. - /// is less than zero or greater than the length of value minus 1. + /// + /// is less than zero or greater than the + /// length of value minus 1. + /// public static float ToSingle(byte[] value, int startIndex) { return !IsLittleEndian @@ -276,10 +311,14 @@ public static float ToSingle(byte[] value, int startIndex) } /// - /// Converts the numeric value of each element of a specified array of bytes to its equivalent hexadecimal string representation. + /// Converts the numeric value of each element of a specified array of bytes to its equivalent hexadecimal string + /// representation. /// /// An array of bytes. - /// A System.String of hexadecimal pairs separated by hyphens, where each pair represents the corresponding element in value; for example, "7F-2C-4A". + /// + /// A System.String of hexadecimal pairs separated by hyphens, where each pair represents the corresponding + /// element in value; for example, "7F-2C-4A". + /// /// value is null. public static string ToString(byte[] value) { @@ -287,13 +326,20 @@ public static string ToString(byte[] value) } /// - /// Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal string representation. + /// Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal string + /// representation. /// /// An array of bytes. /// The starting position within value. - /// 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". + /// + /// 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". + /// /// value is null. - /// startIndex is less than zero or greater than the length of value minus 1. + /// + /// startIndex is less than zero or greater than the length of value + /// minus 1. + /// public static string ToString(byte[] value, int startIndex) { return !IsLittleEndian @@ -302,15 +348,25 @@ public static string ToString(byte[] value, int startIndex) } /// - /// Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal string representation. + /// Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal string + /// representation. /// /// An array of bytes. /// The starting position within value. /// The number of array elements in value to convert. - /// 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". + /// + /// 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". + /// /// value is null. - /// startIndex or length is less than zero. -or- startIndex is greater than zero and is greater than or equal to the length of value. - /// 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. + /// + /// startIndex or length is less than zero. -or- startIndex is greater + /// than zero and is greater than or equal to the length of value. + /// + /// + /// 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. + /// public static string ToString(byte[] value, int startIndex, int length) { return !IsLittleEndian @@ -319,14 +375,17 @@ public static string ToString(byte[] value, int startIndex, int length) } /// - /// Returns a 16-bit unsigned integer converted from two bytes at a specified position in a byte array. + /// Returns a 16-bit unsigned integer converted from two bytes at a specified position in a byte array. /// /// The array of bytes. /// The starting position within value. /// A 16-bit unsigned integer formed by two bytes beginning at startIndex. /// startIndex equals the length of value minus 1. /// value is null. - /// startIndex is less than zero or greater than the length of value minus 1. + /// + /// startIndex is less than zero or greater than the length of value + /// minus 1. + /// public static ushort ToUInt16(byte[] value, int startIndex) { return !IsLittleEndian @@ -335,14 +394,20 @@ public static ushort ToUInt16(byte[] value, int startIndex) } /// - /// Returns a 32-bit unsigned integer converted from four bytes at a specified position in a byte array. + /// Returns a 32-bit unsigned integer converted from four bytes at a specified position in a byte array. /// /// An array of bytes. /// The starting position within value. /// A 32-bit unsigned integer formed by four bytes beginning at startIndex. - /// 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. + /// + /// 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. + /// /// value is null. - /// startIndex is less than zero or greater than the length of value minus 1. + /// + /// startIndex is less than zero or greater than the length of value + /// minus 1. + /// public static uint ToUInt32(byte[] value, int startIndex) { return !IsLittleEndian @@ -351,14 +416,20 @@ public static uint ToUInt32(byte[] value, int startIndex) } /// - /// Returns a 64-bit unsigned integer converted from eight bytes at a specified position in a byte array. + /// Returns a 64-bit unsigned integer converted from eight bytes at a specified position in a byte array. /// /// An array of bytes. /// The starting position within value. /// A 64-bit unsigned integer formed by the eight bytes beginning at startIndex. - /// 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. + /// + /// 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. + /// /// value is null. - /// startIndex is less than zero or greater than the length of value minus 1. + /// + /// startIndex is less than zero or greater than the length of value + /// minus 1. + /// public static ulong ToUInt64(byte[] value, int startIndex) { return !IsLittleEndian diff --git a/BigEndianMarshal.cs b/BigEndianMarshal.cs index 0fd5c34a3..8b7f8a95d 100644 --- a/BigEndianMarshal.cs +++ b/BigEndianMarshal.cs @@ -40,8 +40,8 @@ namespace DiscImageChef public static class BigEndianMarshal { /// - /// Marshals a big endian structure from a byte array. - /// Nested structures are still marshalled as little endian. + /// Marshals a big endian structure from a byte array. + /// Nested structures are still marshalled as little endian. /// /// The structure. /// Byte array. @@ -55,8 +55,8 @@ public static T ByteArrayToStructureBigEndian(byte[] bytes) where T : struct } /// - /// Swaps endian of structure members that correspond to numerical types. - /// Does not traverse nested structures. + /// Swaps endian of structure members that correspond to numerical types. + /// Does not traverse nested structures. /// /// The structure with its members endian swapped. /// The structure. diff --git a/CHS.cs b/CHS.cs index 5d696ad67..29f69b35d 100644 --- a/CHS.cs +++ b/CHS.cs @@ -35,7 +35,7 @@ namespace DiscImageChef.Helpers public static class CHS { /// - /// Converts a CHS position to a LBA one + /// Converts a CHS position to a LBA one /// /// Cylinder /// Head diff --git a/CompareBytes.cs b/CompareBytes.cs index f10cf41d6..321ce8f1c 100644 --- a/CompareBytes.cs +++ b/CompareBytes.cs @@ -35,7 +35,7 @@ namespace DiscImageChef public static partial class ArrayHelpers { /// - /// Compares two byte arrays + /// Compares two byte arrays /// /// true if they are different in any way /// true if they have the same size diff --git a/CountBits.cs b/CountBits.cs index 7c899f9ff..3c0b926ca 100644 --- a/CountBits.cs +++ b/CountBits.cs @@ -35,7 +35,7 @@ namespace DiscImageChef.Helpers public static class CountBits { /// - /// Counts the number of bits set to true in a number + /// Counts the number of bits set to true in a number /// /// Number /// Bits set to true diff --git a/DateHandlers.cs b/DateHandlers.cs index 87f0b7105..6014650aa 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -42,13 +42,13 @@ public static class DateHandlers static readonly DateTime MacEpoch = new DateTime(1904, 1, 1, 0, 0, 0); static readonly DateTime UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0); /// - /// Day 0 of Julian Date system + /// Day 0 of Julian Date system /// static readonly DateTime JulianEpoch = new DateTime(1858, 11, 17, 0, 0, 0); static readonly DateTime AmigaEpoch = new DateTime(1978, 1, 1, 0, 0, 0); /// - /// Converts a Macintosh timestamp to a .NET DateTime + /// Converts a Macintosh timestamp to a .NET DateTime /// /// Macintosh timestamp (seconds since 1st Jan. 1904) /// .NET DateTime @@ -58,7 +58,7 @@ public static DateTime MacToDateTime(ulong macTimeStamp) } /// - /// Converts a Lisa timestamp to a .NET DateTime + /// Converts a Lisa timestamp to a .NET DateTime /// /// Lisa timestamp (seconds since 1st Jan. 1901) /// .NET DateTime @@ -68,7 +68,7 @@ public static DateTime LisaToDateTime(uint lisaTimeStamp) } /// - /// Converts a UNIX timestamp to a .NET DateTime + /// Converts a UNIX timestamp to a .NET DateTime /// /// UNIX timestamp (seconds since 1st Jan. 1970) /// .NET DateTime @@ -78,7 +78,7 @@ public static DateTime UnixToDateTime(int unixTimeStamp) } /// - /// Converts a UNIX timestamp to a .NET DateTime + /// Converts a UNIX timestamp to a .NET DateTime /// /// UNIX timestamp (seconds since 1st Jan. 1970) /// .NET DateTime @@ -88,7 +88,7 @@ public static DateTime UnixToDateTime(long unixTimeStamp) } /// - /// Converts a UNIX timestamp to a .NET DateTime + /// Converts a UNIX timestamp to a .NET DateTime /// /// UNIX timestamp (seconds since 1st Jan. 1970) /// .NET DateTime @@ -98,7 +98,7 @@ public static DateTime UnixUnsignedToDateTime(uint unixTimeStamp) } /// - /// Converts a UNIX timestamp to a .NET DateTime + /// Converts a UNIX timestamp to a .NET DateTime /// /// Seconds since 1st Jan. 1970) /// Nanoseconds @@ -109,7 +109,7 @@ public static DateTime UnixUnsignedToDateTime(uint seconds, uint nanoseconds) } /// - /// Converts a UNIX timestamp to a .NET DateTime + /// Converts a UNIX timestamp to a .NET DateTime /// /// UNIX timestamp (seconds since 1st Jan. 1970) /// .NET DateTime @@ -119,7 +119,7 @@ public static DateTime UnixUnsignedToDateTime(ulong unixTimeStamp) } /// - /// Converts a High Sierra Format timestamp to a .NET DateTime + /// Converts a High Sierra Format timestamp to a .NET DateTime /// /// High Sierra Format timestamp /// .NET DateTime @@ -132,7 +132,7 @@ public static DateTime HighSierraToDateTime(byte[] vdDateTime) // TODO: Timezone /// - /// Converts an ISO9660 timestamp to a .NET DateTime + /// Converts an ISO9660 timestamp to a .NET DateTime /// /// ISO9660 timestamp /// .NET DateTime @@ -183,7 +183,8 @@ public static DateTime Iso9660ToDateTime(byte[] vdDateTime) twocharvalue[1] = vdDateTime[15]; DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "hundredths = \"{0}\"", StringHandlers.CToString(twocharvalue, Encoding.ASCII)); - if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out int hundredths)) hundredths = 0; + if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out int hundredths)) + hundredths = 0; DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "decodedDT = new DateTime({0}, {1}, {2}, {3}, {4}, {5}, {6}, DateTimeKind.Unspecified);", @@ -195,7 +196,7 @@ public static DateTime Iso9660ToDateTime(byte[] vdDateTime) } /// - /// Converts a VMS timestamp to a .NET DateTime + /// Converts a VMS timestamp to a .NET DateTime /// /// VMS timestamp (tenths of microseconds since day 0 of the Julian Date) /// .NET DateTime @@ -207,7 +208,7 @@ public static DateTime VmsToDateTime(ulong vmsDate) } /// - /// Converts an Amiga timestamp to a .NET DateTime + /// Converts an Amiga timestamp to a .NET DateTime /// /// Days since the 1st Jan. 1978 /// Minutes since o'clock @@ -221,7 +222,7 @@ public static DateTime AmigaToDateTime(uint days, uint minutes, uint ticks) } /// - /// Converts an UCSD Pascal timestamp to a .NET DateTime + /// Converts an UCSD Pascal timestamp to a .NET DateTime /// /// UCSD Pascal timestamp /// .NET DateTime @@ -238,7 +239,7 @@ public static DateTime UcsdPascalToDateTime(short dateRecord) } /// - /// Converts a DOS timestamp to a .NET DateTime + /// Converts a DOS timestamp to a .NET DateTime /// /// Date /// Time @@ -266,7 +267,7 @@ public static DateTime DosToDateTime(ushort date, ushort time) } /// - /// Converts a CP/M timestamp to .NET DateTime + /// Converts a CP/M timestamp to .NET DateTime /// /// CP/M timestamp /// .NET DateTime @@ -284,7 +285,7 @@ public static DateTime CpmToDateTime(byte[] timestamp) } /// - /// Converts an ECMA timestamp to a .NET DateTime + /// Converts an ECMA timestamp to a .NET DateTime /// /// Timezone /// Year @@ -322,7 +323,7 @@ public static DateTime EcmaToDateTime(ushort typeAndTimeZone, short year, byte m } /// - /// Convers a Solaris high resolution timestamp to .NET DateTime + /// Convers a Solaris high resolution timestamp to .NET DateTime /// /// Solaris high resolution timestamp /// .NET DateTime @@ -332,7 +333,7 @@ public static DateTime UnixHrTimeToDateTime(ulong hrTimeStamp) } /// - /// Converts an OS-9 timestamp to .NET DateTime + /// Converts an OS-9 timestamp to .NET DateTime /// /// OS-9 timestamp /// .NET DateTime @@ -354,7 +355,7 @@ public static DateTime Os9ToDateTime(byte[] date) } /// - /// Converts a LIF timestamp to .NET DateTime + /// Converts a LIF timestamp to .NET DateTime /// /// LIF timestamp /// .NET DateTime @@ -366,7 +367,7 @@ public static DateTime LifToDateTime(byte[] date) } /// - /// Converts a LIF timestamp to .NET DateTime + /// Converts a LIF timestamp to .NET DateTime /// /// Yer /// Month diff --git a/Extents/ExtentsByte.cs b/Extents/ExtentsByte.cs index bd0e7b188..7d52a69a9 100644 --- a/Extents/ExtentsByte.cs +++ b/Extents/ExtentsByte.cs @@ -37,14 +37,14 @@ namespace Extents { /// - /// Implements extents for + /// Implements extents for /// public class ExtentsByte { List> backend; /// - /// Initialize an empty list of extents + /// Initialize an empty list of extents /// public ExtentsByte() { @@ -52,7 +52,7 @@ public ExtentsByte() } /// - /// Initializes extents with an specific list + /// Initializes extents with an specific list /// /// List of extents as tuples "start, end" public ExtentsByte(IEnumerable> list) @@ -61,12 +61,12 @@ public ExtentsByte(IEnumerable> list) } /// - /// Gets a count of how many extents are stored + /// Gets a count of how many extents are stored /// public int Count => backend.Count; /// - /// Adds the specified number to the corresponding extent, or creates a new one + /// Adds the specified number to the corresponding extent, or creates a new one /// /// public void Add(byte item) @@ -123,11 +123,14 @@ public void Add(byte item) } /// - /// Adds a new extent + /// Adds a new extent /// /// First element of the extent - /// Last element of the extent or if is true how many elements the extent runs for - /// If set to true, indicates how many elements the extent runs for + /// + /// Last element of the extent or if is true how many elements the extent runs + /// for + /// + /// If set to true, indicates how many elements the extent runs for public void Add(byte start, byte end, bool run = false) { byte realEnd; @@ -139,7 +142,7 @@ public void Add(byte start, byte end, bool run = false) } /// - /// Checks if the specified item is contained by an extent on this instance + /// Checks if the specified item is contained by an extent on this instance /// /// Item to seach for /// true if any of the extents on this instance contains the item @@ -149,7 +152,7 @@ public bool Contains(byte item) } /// - /// Removes all extents from this instance + /// Removes all extents from this instance /// public void Clear() { @@ -157,7 +160,7 @@ public void Clear() } /// - /// Removes an item from the extents in this instance + /// Removes an item from the extents in this instance /// /// Item to remove /// true if the item was contained in a known extent and removed, false otherwise @@ -215,16 +218,17 @@ public bool Remove(byte item) } /// - /// Converts the list of extents to an array of where T1 is first element of the extent and T2 is last element + /// Converts the list of extents to an array of where T1 is first element of the extent and T2 is + /// last element /// - /// Array of + /// Array of public Tuple[] ToArray() { return backend.ToArray(); } /// - /// Gets the first element of the extent that contains the specified item + /// Gets the first element of the extent that contains the specified item /// /// Item /// First element of extent @@ -232,7 +236,8 @@ public Tuple[] ToArray() public bool GetStart(byte item, out byte start) { start = 0; - foreach(Tuple extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) { + foreach(Tuple extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) + { start = extent.Item1; return true; } diff --git a/Extents/ExtentsInt.cs b/Extents/ExtentsInt.cs index d41300106..8d4006347 100644 --- a/Extents/ExtentsInt.cs +++ b/Extents/ExtentsInt.cs @@ -37,14 +37,14 @@ namespace Extents { /// - /// Implements extents for + /// Implements extents for /// public class ExtentsInt { List> backend; /// - /// Initialize an empty list of extents + /// Initialize an empty list of extents /// public ExtentsInt() { @@ -52,7 +52,7 @@ public ExtentsInt() } /// - /// Initializes extents with an specific list + /// Initializes extents with an specific list /// /// List of extents as tuples "start, end" public ExtentsInt(IEnumerable> list) @@ -61,12 +61,12 @@ public ExtentsInt(IEnumerable> list) } /// - /// Gets a count of how many extents are stored + /// Gets a count of how many extents are stored /// public int Count => backend.Count; /// - /// Adds the specified number to the corresponding extent, or creates a new one + /// Adds the specified number to the corresponding extent, or creates a new one /// /// public void Add(int item) @@ -123,11 +123,14 @@ public void Add(int item) } /// - /// Adds a new extent + /// Adds a new extent /// /// First element of the extent - /// Last element of the extent or if is true how many elements the extent runs for - /// If set to true, indicates how many elements the extent runs for + /// + /// Last element of the extent or if is true how many elements the extent runs + /// for + /// + /// If set to true, indicates how many elements the extent runs for public void Add(int start, int end, bool run = false) { int realEnd; @@ -139,7 +142,7 @@ public void Add(int start, int end, bool run = false) } /// - /// Checks if the specified item is contained by an extent on this instance + /// Checks if the specified item is contained by an extent on this instance /// /// Item to seach for /// true if any of the extents on this instance contains the item @@ -149,7 +152,7 @@ public bool Contains(int item) } /// - /// Removes all extents from this instance + /// Removes all extents from this instance /// public void Clear() { @@ -157,7 +160,7 @@ public void Clear() } /// - /// Removes an item from the extents in this instance + /// Removes an item from the extents in this instance /// /// Item to remove /// true if the item was contained in a known extent and removed, false otherwise @@ -215,16 +218,17 @@ public bool Remove(int item) } /// - /// Converts the list of extents to an array of where T1 is first element of the extent and T2 is last element + /// Converts the list of extents to an array of where T1 is first element of the extent and T2 is + /// last element /// - /// Array of + /// Array of public Tuple[] ToArray() { return backend.ToArray(); } /// - /// Gets the first element of the extent that contains the specified item + /// Gets the first element of the extent that contains the specified item /// /// Item /// First element of extent @@ -232,7 +236,8 @@ public Tuple[] ToArray() public bool GetStart(int item, out int start) { start = 0; - foreach(Tuple extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) { + foreach(Tuple extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) + { start = extent.Item1; return true; } diff --git a/Extents/ExtentsLong.cs b/Extents/ExtentsLong.cs index b293e822f..b70c85a98 100644 --- a/Extents/ExtentsLong.cs +++ b/Extents/ExtentsLong.cs @@ -37,14 +37,14 @@ namespace Extents { /// - /// Implements extents for + /// Implements extents for /// public class ExtentsLong { List> backend; /// - /// Initialize an empty list of extents + /// Initialize an empty list of extents /// public ExtentsLong() { @@ -52,7 +52,7 @@ public ExtentsLong() } /// - /// Initializes extents with an specific list + /// Initializes extents with an specific list /// /// List of extents as tuples "start, end" public ExtentsLong(IEnumerable> list) @@ -61,12 +61,12 @@ public ExtentsLong(IEnumerable> list) } /// - /// Gets a count of how many extents are stored + /// Gets a count of how many extents are stored /// public int Count => backend.Count; /// - /// Adds the specified number to the corresponding extent, or creates a new one + /// Adds the specified number to the corresponding extent, or creates a new one /// /// public void Add(long item) @@ -123,11 +123,14 @@ public void Add(long item) } /// - /// Adds a new extent + /// Adds a new extent /// /// First element of the extent - /// Last element of the extent or if is true how many elements the extent runs for - /// If set to true, indicates how many elements the extent runs for + /// + /// Last element of the extent or if is true how many elements the extent runs + /// for + /// + /// If set to true, indicates how many elements the extent runs for public void Add(long start, long end, bool run = false) { long realEnd; @@ -139,7 +142,7 @@ public void Add(long start, long end, bool run = false) } /// - /// Checks if the specified item is contained by an extent on this instance + /// Checks if the specified item is contained by an extent on this instance /// /// Item to seach for /// true if any of the extents on this instance contains the item @@ -149,7 +152,7 @@ public bool Contains(long item) } /// - /// Removes all extents from this instance + /// Removes all extents from this instance /// public void Clear() { @@ -157,7 +160,7 @@ public void Clear() } /// - /// Removes an item from the extents in this instance + /// Removes an item from the extents in this instance /// /// Item to remove /// true if the item was contained in a known extent and removed, false otherwise @@ -215,16 +218,17 @@ public bool Remove(long item) } /// - /// Converts the list of extents to an array of where T1 is first element of the extent and T2 is last element + /// Converts the list of extents to an array of where T1 is first element of the extent and T2 is + /// last element /// - /// Array of + /// Array of public Tuple[] ToArray() { return backend.ToArray(); } /// - /// Gets the first element of the extent that contains the specified item + /// Gets the first element of the extent that contains the specified item /// /// Item /// First element of extent @@ -232,7 +236,8 @@ public Tuple[] ToArray() public bool GetStart(long item, out long start) { start = 0; - foreach(Tuple extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) { + foreach(Tuple extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) + { start = extent.Item1; return true; } diff --git a/Extents/ExtentsSByte.cs b/Extents/ExtentsSByte.cs index ef52740df..b7479683d 100644 --- a/Extents/ExtentsSByte.cs +++ b/Extents/ExtentsSByte.cs @@ -37,14 +37,14 @@ namespace Extents { /// - /// Implements extents for + /// Implements extents for /// public class ExtentsSByte { List> backend; /// - /// Initialize an empty list of extents + /// Initialize an empty list of extents /// public ExtentsSByte() { @@ -52,7 +52,7 @@ public ExtentsSByte() } /// - /// Initializes extents with an specific list + /// Initializes extents with an specific list /// /// List of extents as tuples "start, end" public ExtentsSByte(IEnumerable> list) @@ -61,12 +61,12 @@ public ExtentsSByte(IEnumerable> list) } /// - /// Gets a count of how many extents are stored + /// Gets a count of how many extents are stored /// public int Count => backend.Count; /// - /// Adds the specified number to the corresponding extent, or creates a new one + /// Adds the specified number to the corresponding extent, or creates a new one /// /// public void Add(sbyte item) @@ -123,11 +123,14 @@ public void Add(sbyte item) } /// - /// Adds a new extent + /// Adds a new extent /// /// First element of the extent - /// Last element of the extent or if is true how many elements the extent runs for - /// If set to true, indicates how many elements the extent runs for + /// + /// Last element of the extent or if is true how many elements the extent runs + /// for + /// + /// If set to true, indicates how many elements the extent runs for public void Add(sbyte start, sbyte end, bool run = false) { sbyte realEnd; @@ -139,7 +142,7 @@ public void Add(sbyte start, sbyte end, bool run = false) } /// - /// Checks if the specified item is contained by an extent on this instance + /// Checks if the specified item is contained by an extent on this instance /// /// Item to seach for /// true if any of the extents on this instance contains the item @@ -149,7 +152,7 @@ public bool Contains(sbyte item) } /// - /// Removes all extents from this instance + /// Removes all extents from this instance /// public void Clear() { @@ -157,7 +160,7 @@ public void Clear() } /// - /// Removes an item from the extents in this instance + /// Removes an item from the extents in this instance /// /// Item to remove /// true if the item was contained in a known extent and removed, false otherwise @@ -215,16 +218,17 @@ public bool Remove(sbyte item) } /// - /// Converts the list of extents to an array of where T1 is first element of the extent and T2 is last element + /// Converts the list of extents to an array of where T1 is first element of the extent and T2 is + /// last element /// - /// Array of + /// Array of public Tuple[] ToArray() { return backend.ToArray(); } /// - /// Gets the first element of the extent that contains the specified item + /// Gets the first element of the extent that contains the specified item /// /// Item /// First element of extent @@ -232,7 +236,8 @@ public Tuple[] ToArray() public bool GetStart(sbyte item, out sbyte start) { start = 0; - foreach(Tuple extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) { + foreach(Tuple extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) + { start = extent.Item1; return true; } diff --git a/Extents/ExtentsShort.cs b/Extents/ExtentsShort.cs index 7c47deeb8..0a26ee0b5 100644 --- a/Extents/ExtentsShort.cs +++ b/Extents/ExtentsShort.cs @@ -37,14 +37,14 @@ namespace Extents { /// - /// Implements extents for + /// Implements extents for /// public class ExtentsShort { List> backend; /// - /// Initialize an empty list of extents + /// Initialize an empty list of extents /// public ExtentsShort() { @@ -52,7 +52,7 @@ public ExtentsShort() } /// - /// Initializes extents with an specific list + /// Initializes extents with an specific list /// /// List of extents as tuples "start, end" public ExtentsShort(IEnumerable> list) @@ -61,12 +61,12 @@ public ExtentsShort(IEnumerable> list) } /// - /// Gets a count of how many extents are stored + /// Gets a count of how many extents are stored /// public int Count => backend.Count; /// - /// Adds the specified number to the corresponding extent, or creates a new one + /// Adds the specified number to the corresponding extent, or creates a new one /// /// public void Add(short item) @@ -123,11 +123,14 @@ public void Add(short item) } /// - /// Adds a new extent + /// Adds a new extent /// /// First element of the extent - /// Last element of the extent or if is true how many elements the extent runs for - /// If set to true, indicates how many elements the extent runs for + /// + /// Last element of the extent or if is true how many elements the extent runs + /// for + /// + /// If set to true, indicates how many elements the extent runs for public void Add(short start, short end, bool run = false) { short realEnd; @@ -139,7 +142,7 @@ public void Add(short start, short end, bool run = false) } /// - /// Checks if the specified item is contained by an extent on this instance + /// Checks if the specified item is contained by an extent on this instance /// /// Item to seach for /// true if any of the extents on this instance contains the item @@ -149,7 +152,7 @@ public bool Contains(short item) } /// - /// Removes all extents from this instance + /// Removes all extents from this instance /// public void Clear() { @@ -157,7 +160,7 @@ public void Clear() } /// - /// Removes an item from the extents in this instance + /// Removes an item from the extents in this instance /// /// Item to remove /// true if the item was contained in a known extent and removed, false otherwise @@ -215,16 +218,17 @@ public bool Remove(short item) } /// - /// Converts the list of extents to an array of where T1 is first element of the extent and T2 is last element + /// Converts the list of extents to an array of where T1 is first element of the extent and T2 is + /// last element /// - /// Array of + /// Array of public Tuple[] ToArray() { return backend.ToArray(); } /// - /// Gets the first element of the extent that contains the specified item + /// Gets the first element of the extent that contains the specified item /// /// Item /// First element of extent @@ -232,7 +236,8 @@ public Tuple[] ToArray() public bool GetStart(short item, out short start) { start = 0; - foreach(Tuple extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) { + foreach(Tuple extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) + { start = extent.Item1; return true; } diff --git a/Extents/ExtentsUInt.cs b/Extents/ExtentsUInt.cs index 6ba26e927..874173c0a 100644 --- a/Extents/ExtentsUInt.cs +++ b/Extents/ExtentsUInt.cs @@ -37,14 +37,14 @@ namespace Extents { /// - /// Implements extents for + /// Implements extents for /// public class ExtentsUInt { List> backend; /// - /// Initialize an empty list of extents + /// Initialize an empty list of extents /// public ExtentsUInt() { @@ -52,7 +52,7 @@ public ExtentsUInt() } /// - /// Initializes extents with an specific list + /// Initializes extents with an specific list /// /// List of extents as tuples "start, end" public ExtentsUInt(IEnumerable> list) @@ -61,12 +61,12 @@ public ExtentsUInt(IEnumerable> list) } /// - /// Gets a count of how many extents are stored + /// Gets a count of how many extents are stored /// public int Count => backend.Count; /// - /// Adds the specified number to the corresponding extent, or creates a new one + /// Adds the specified number to the corresponding extent, or creates a new one /// /// public void Add(uint item) @@ -123,11 +123,14 @@ public void Add(uint item) } /// - /// Adds a new extent + /// Adds a new extent /// /// First element of the extent - /// Last element of the extent or if is true how many elements the extent runs for - /// If set to true, indicates how many elements the extent runs for + /// + /// Last element of the extent or if is true how many elements the extent runs + /// for + /// + /// If set to true, indicates how many elements the extent runs for public void Add(uint start, uint end, bool run = false) { uint realEnd; @@ -139,7 +142,7 @@ public void Add(uint start, uint end, bool run = false) } /// - /// Checks if the specified item is contained by an extent on this instance + /// Checks if the specified item is contained by an extent on this instance /// /// Item to seach for /// true if any of the extents on this instance contains the item @@ -149,7 +152,7 @@ public bool Contains(uint item) } /// - /// Removes all extents from this instance + /// Removes all extents from this instance /// public void Clear() { @@ -157,7 +160,7 @@ public void Clear() } /// - /// Removes an item from the extents in this instance + /// Removes an item from the extents in this instance /// /// Item to remove /// true if the item was contained in a known extent and removed, false otherwise @@ -215,16 +218,17 @@ public bool Remove(uint item) } /// - /// Converts the list of extents to an array of where T1 is first element of the extent and T2 is last element + /// Converts the list of extents to an array of where T1 is first element of the extent and T2 is + /// last element /// - /// Array of + /// Array of public Tuple[] ToArray() { return backend.ToArray(); } /// - /// Gets the first element of the extent that contains the specified item + /// Gets the first element of the extent that contains the specified item /// /// Item /// First element of extent @@ -232,7 +236,8 @@ public Tuple[] ToArray() public bool GetStart(uint item, out uint start) { start = 0; - foreach(Tuple extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) { + foreach(Tuple extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) + { start = extent.Item1; return true; } diff --git a/Extents/ExtentsULong.cs b/Extents/ExtentsULong.cs index 60e5813a7..71a82200c 100644 --- a/Extents/ExtentsULong.cs +++ b/Extents/ExtentsULong.cs @@ -37,14 +37,14 @@ namespace Extents { /// - /// Implements extents for + /// Implements extents for /// public class ExtentsULong { List> backend; /// - /// Initialize an empty list of extents + /// Initialize an empty list of extents /// public ExtentsULong() { @@ -52,7 +52,7 @@ public ExtentsULong() } /// - /// Initializes extents with an specific list + /// Initializes extents with an specific list /// /// List of extents as tuples "start, end" public ExtentsULong(IEnumerable> list) @@ -61,12 +61,12 @@ public ExtentsULong(IEnumerable> list) } /// - /// Gets a count of how many extents are stored + /// Gets a count of how many extents are stored /// public int Count => backend.Count; /// - /// Adds the specified number to the corresponding extent, or creates a new one + /// Adds the specified number to the corresponding extent, or creates a new one /// /// public void Add(ulong item) @@ -123,11 +123,14 @@ public void Add(ulong item) } /// - /// Adds a new extent + /// Adds a new extent /// /// First element of the extent - /// Last element of the extent or if is true how many elements the extent runs for - /// If set to true, indicates how many elements the extent runs for + /// + /// Last element of the extent or if is true how many elements the extent runs + /// for + /// + /// If set to true, indicates how many elements the extent runs for public void Add(ulong start, ulong end, bool run = false) { ulong realEnd; @@ -139,7 +142,7 @@ public void Add(ulong start, ulong end, bool run = false) } /// - /// Checks if the specified item is contained by an extent on this instance + /// Checks if the specified item is contained by an extent on this instance /// /// Item to seach for /// true if any of the extents on this instance contains the item @@ -149,7 +152,7 @@ public bool Contains(ulong item) } /// - /// Removes all extents from this instance + /// Removes all extents from this instance /// public void Clear() { @@ -157,7 +160,7 @@ public void Clear() } /// - /// Removes an item from the extents in this instance + /// Removes an item from the extents in this instance /// /// Item to remove /// true if the item was contained in a known extent and removed, false otherwise @@ -215,16 +218,17 @@ public bool Remove(ulong item) } /// - /// Converts the list of extents to an array of where T1 is first element of the extent and T2 is last element + /// Converts the list of extents to an array of where T1 is first element of the extent and T2 is + /// last element /// - /// Array of + /// Array of public Tuple[] ToArray() { return backend.ToArray(); } /// - /// Gets the first element of the extent that contains the specified item + /// Gets the first element of the extent that contains the specified item /// /// Item /// First element of extent @@ -232,7 +236,8 @@ public Tuple[] ToArray() public bool GetStart(ulong item, out ulong start) { start = 0; - foreach(Tuple extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) { + foreach(Tuple extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) + { start = extent.Item1; return true; } diff --git a/Extents/ExtentsUShort.cs b/Extents/ExtentsUShort.cs index bf01658a9..fa6122c1f 100644 --- a/Extents/ExtentsUShort.cs +++ b/Extents/ExtentsUShort.cs @@ -37,14 +37,14 @@ namespace Extents { /// - /// Implements extents for + /// Implements extents for /// public class ExtentsUShort { List> backend; /// - /// Initialize an empty list of extents + /// Initialize an empty list of extents /// public ExtentsUShort() { @@ -52,7 +52,7 @@ public ExtentsUShort() } /// - /// Initializes extents with an specific list + /// Initializes extents with an specific list /// /// List of extents as tuples "start, end" public ExtentsUShort(IEnumerable> list) @@ -61,12 +61,12 @@ public ExtentsUShort(IEnumerable> list) } /// - /// Gets a count of how many extents are stored + /// Gets a count of how many extents are stored /// public int Count => backend.Count; /// - /// Adds the specified number to the corresponding extent, or creates a new one + /// Adds the specified number to the corresponding extent, or creates a new one /// /// public void Add(ushort item) @@ -123,11 +123,14 @@ public void Add(ushort item) } /// - /// Adds a new extent + /// Adds a new extent /// /// First element of the extent - /// Last element of the extent or if is true how many elements the extent runs for - /// If set to true, indicates how many elements the extent runs for + /// + /// Last element of the extent or if is true how many elements the extent runs + /// for + /// + /// If set to true, indicates how many elements the extent runs for public void Add(ushort start, ushort end, bool run = false) { ushort realEnd; @@ -139,7 +142,7 @@ public void Add(ushort start, ushort end, bool run = false) } /// - /// Checks if the specified item is contained by an extent on this instance + /// Checks if the specified item is contained by an extent on this instance /// /// Item to seach for /// true if any of the extents on this instance contains the item @@ -149,7 +152,7 @@ public bool Contains(ushort item) } /// - /// Removes all extents from this instance + /// Removes all extents from this instance /// public void Clear() { @@ -157,7 +160,7 @@ public void Clear() } /// - /// Removes an item from the extents in this instance + /// Removes an item from the extents in this instance /// /// Item to remove /// true if the item was contained in a known extent and removed, false otherwise @@ -215,16 +218,17 @@ public bool Remove(ushort item) } /// - /// Converts the list of extents to an array of where T1 is first element of the extent and T2 is last element + /// Converts the list of extents to an array of where T1 is first element of the extent and T2 is + /// last element /// - /// Array of + /// Array of public Tuple[] ToArray() { return backend.ToArray(); } /// - /// Gets the first element of the extent that contains the specified item + /// Gets the first element of the extent that contains the specified item /// /// Item /// First element of extent @@ -232,7 +236,9 @@ public Tuple[] ToArray() public bool GetStart(ushort item, out ushort start) { start = 0; - foreach(Tuple extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) { + foreach(Tuple extent in + backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) + { start = extent.Item1; return true; } diff --git a/PrintHex.cs b/PrintHex.cs index 1d2024386..0cd4f144b 100644 --- a/PrintHex.cs +++ b/PrintHex.cs @@ -38,7 +38,7 @@ namespace DiscImageChef public static class PrintHex { /// - /// Prints a byte array as hexadecimal values to the console + /// Prints a byte array as hexadecimal values to the console /// /// Array /// Width of line @@ -48,7 +48,7 @@ public static void PrintHexArray(byte[] array, int width) } /// - /// Prints a byte array as hexadecimal values to a string + /// Prints a byte array as hexadecimal values to a string /// /// Array /// Width of line diff --git a/StringHandlers.cs b/StringHandlers.cs index 356568b5d..8ab0e350f 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -38,7 +38,7 @@ namespace DiscImageChef public static class StringHandlers { /// - /// Converts a null-terminated (aka C string) ASCII byte array to a C# string + /// Converts a null-terminated (aka C string) ASCII byte array to a C# string /// /// The corresponding C# string /// A null-terminated (aka C string) ASCII byte array @@ -48,7 +48,7 @@ public static string CToString(byte[] CString) } /// - /// Converts a null-terminated (aka C string) byte array with the specified encoding to a C# string + /// Converts a null-terminated (aka C string) byte array with the specified encoding to a C# string /// /// The corresponding C# string /// A null-terminated (aka C string) byte array in the specified encoding @@ -86,7 +86,7 @@ public static string CToString(byte[] CString, Encoding encoding, bool twoBytes } /// - /// Converts a length-prefixed (aka Pascal string) ASCII byte array to a C# string + /// Converts a length-prefixed (aka Pascal string) ASCII byte array to a C# string /// /// The corresponding C# string /// A length-prefixed (aka Pascal string) ASCII byte array @@ -96,7 +96,7 @@ public static string PascalToString(byte[] PascalString) } /// - /// Converts a length-prefixed (aka Pascal string) ASCII byte array to a C# string + /// Converts a length-prefixed (aka Pascal string) ASCII byte array to a C# string /// /// The corresponding C# string /// A length-prefixed (aka Pascal string) ASCII byte array @@ -123,7 +123,7 @@ public static string PascalToString(byte[] PascalString, Encoding encoding, int } /// - /// Converts a space (' ', 0x20, ASCII SPACE) padded ASCII byte array to a C# string + /// Converts a space (' ', 0x20, ASCII SPACE) padded ASCII byte array to a C# string /// /// The corresponding C# string /// A space (' ', 0x20, ASCII SPACE) padded ASCII byte array @@ -133,7 +133,7 @@ public static string SpacePaddedToString(byte[] SpacePaddedString) } /// - /// Converts a space (' ', 0x20, ASCII SPACE) padded ASCII byte array to a C# string + /// Converts a space (' ', 0x20, ASCII SPACE) padded ASCII byte array to a C# string /// /// The corresponding C# string /// A space (' ', 0x20, ASCII SPACE) padded ASCII byte array @@ -159,7 +159,7 @@ public static string SpacePaddedToString(byte[] SpacePaddedString, Encoding enco } /// - /// Converts an OSTA compressed unicode byte array to a C# string + /// Converts an OSTA compressed unicode byte array to a C# string /// /// The C# string. /// OSTA compressed unicode byte array. diff --git a/Swapping.cs b/Swapping.cs index 75fb4d36f..75bec257e 100644 --- a/Swapping.cs +++ b/Swapping.cs @@ -118,12 +118,12 @@ public static long Swap(long 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) { - return (short) ((x << 8) | ((x >> 8) & 0xFF)); + return (short)((x << 8) | ((x >> 8) & 0xFF)); } public static uint Swap(uint x) @@ -134,8 +134,8 @@ public static uint Swap(uint x) public static int Swap(int x) { - x = (int) (((x << 8) & 0xFF00FF00) | (((uint) x >> 8) & 0xFF00FF)); - return (int) (((uint) x << 16) | (((uint) x >> 16) & 0xFFFF)); + x = (int)(((x << 8) & 0xFF00FF00) | (((uint)x >> 8) & 0xFF00FF)); + return (int)(((uint)x << 16) | (((uint)x >> 16) & 0xFFFF)); } } } \ No newline at end of file From b610f0f6a5da4c59807b558ecf804be80ee76701 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 24 Dec 2017 05:45:43 +0000 Subject: [PATCH 074/217] Version bumped to 4.0.0.0. --- DiscImageChef.Helpers.csproj | 2 +- Properties/AssemblyInfo.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index 8bd7bf182..da8e12ca2 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -9,7 +9,7 @@ Library DiscImageChef.Helpers DiscImageChef.Helpers - 3.99.6.0 + 4.0.0.0 false diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index c6eb046fa..b461ec1d0 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -48,7 +48,7 @@ // The form "{Major}.{Minor}.*" will automatically update the build and revision, // and "{Major}.{Minor}.{Build}.*" will update just the revision. -[assembly: AssemblyVersion("3.99.6.0")] +[assembly: AssemblyVersion("4.0.0.0")] // The following attributes are used to specify the signing key for the assembly, // if desired. See the Mono documentation for more information about signing. From 759c6236dae0234f8d369b692d11387c8b25b554 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sat, 30 Dec 2017 09:09:49 +0000 Subject: [PATCH 075/217] Version up to 4.0.99.0. From now on in-development versions will be X.Y.99.Z, with Z being a published development versions, and X.Y being the latest stable release. --- DiscImageChef.Helpers.csproj | 2 +- Properties/AssemblyInfo.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index da8e12ca2..31f2b9a89 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -9,7 +9,7 @@ Library DiscImageChef.Helpers DiscImageChef.Helpers - 4.0.0.0 + 4.0.99.0 false diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index b461ec1d0..df676f1c8 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -48,7 +48,7 @@ // The form "{Major}.{Minor}.*" will automatically update the build and revision, // and "{Major}.{Minor}.{Build}.*" will update just the revision. -[assembly: AssemblyVersion("4.0.0.0")] +[assembly: AssemblyVersion("4.0.99.0")] // The following attributes are used to specify the signing key for the assembly, // if desired. See the Mono documentation for more information about signing. From abec952daa3b4dc1c2b743958982c00768823206 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sat, 6 Jan 2018 11:57:21 +0000 Subject: [PATCH 076/217] Update copyright year in .NET metadata. --- Properties/AssemblyInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index df676f1c8..29aba7501 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -40,7 +40,7 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Claunia.com")] [assembly: AssemblyProduct("")] -[assembly: AssemblyCopyright("Copyright © 2011-2017 Natalia Portillo")] +[assembly: AssemblyCopyright("Copyright © 2011-2018 Natalia Portillo")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] From b21b7f0a0fb093c8d43233253c0e586e1b74bfb0 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 8 Mar 2018 20:00:01 +0000 Subject: [PATCH 077/217] Add recursiveness to BigEndianMarshal thanks to @darkstar suggestions. --- BigEndianMarshal.cs | 57 ++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/BigEndianMarshal.cs b/BigEndianMarshal.cs index 8b7f8a95d..8dbc654ff 100644 --- a/BigEndianMarshal.cs +++ b/BigEndianMarshal.cs @@ -49,9 +49,9 @@ public static class BigEndianMarshal public static T ByteArrayToStructureBigEndian(byte[] bytes) where T : struct { GCHandle ptr = GCHandle.Alloc(bytes, GCHandleType.Pinned); - T str = (T)Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(T)); + T str = (T)Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(T)); ptr.Free(); - return SwapStructureMembersEndian(str); + return (T)SwapStructureMembersEndian(str); } /// @@ -60,67 +60,82 @@ public static T ByteArrayToStructureBigEndian(byte[] bytes) where T : struct /// /// The structure with its members endian swapped. /// The structure. - /// Structure type. - public static T SwapStructureMembersEndian(T str) where T : struct + public static object SwapStructureMembersEndian(object str) { - Type t = str.GetType(); + Type t = str.GetType(); FieldInfo[] fieldInfo = t.GetFields(); foreach(FieldInfo fi in fieldInfo) if(fi.FieldType == typeof(short)) { - short int16 = (short)fi.GetValue(str); + short int16 = (short)fi.GetValue(str); byte[] int16_b = BitConverter.GetBytes(int16); byte[] int16_r = int16_b.Reverse().ToArray(); - fi.SetValueDirect(__makeref(str), BitConverter.ToInt16(int16_r, 0)); + fi.SetValue(str, BitConverter.ToInt16(int16_r, 0)); } else if(fi.FieldType == typeof(int)) { - int int32 = (int)fi.GetValue(str); + int int32 = (int)fi.GetValue(str); byte[] int32_b = BitConverter.GetBytes(int32); byte[] int32_r = int32_b.Reverse().ToArray(); - fi.SetValueDirect(__makeref(str), BitConverter.ToInt32(int32_r, 0)); + fi.SetValue(str, BitConverter.ToInt32(int32_r, 0)); } else if(fi.FieldType == typeof(long)) { - long int64 = (long)fi.GetValue(str); + long int64 = (long)fi.GetValue(str); byte[] int64_b = BitConverter.GetBytes(int64); byte[] int64_r = int64_b.Reverse().ToArray(); - fi.SetValueDirect(__makeref(str), BitConverter.ToInt64(int64_r, 0)); + fi.SetValue(str, BitConverter.ToInt64(int64_r, 0)); } else if(fi.FieldType == typeof(ushort)) { - ushort uint16 = (ushort)fi.GetValue(str); + ushort uint16 = (ushort)fi.GetValue(str); byte[] uint16_b = BitConverter.GetBytes(uint16); byte[] uint16_r = uint16_b.Reverse().ToArray(); - fi.SetValueDirect(__makeref(str), BitConverter.ToUInt16(uint16_r, 0)); + fi.SetValue(str, BitConverter.ToUInt16(uint16_r, 0)); } else if(fi.FieldType == typeof(uint)) { - uint uint32 = (uint)fi.GetValue(str); + uint uint32 = (uint)fi.GetValue(str); byte[] uint32_b = BitConverter.GetBytes(uint32); byte[] uint32_r = uint32_b.Reverse().ToArray(); - fi.SetValueDirect(__makeref(str), BitConverter.ToUInt32(uint32_r, 0)); + fi.SetValue(str, BitConverter.ToUInt32(uint32_r, 0)); } else if(fi.FieldType == typeof(ulong)) { - ulong uint64 = (ulong)fi.GetValue(str); + ulong uint64 = (ulong)fi.GetValue(str); byte[] uint64_b = BitConverter.GetBytes(uint64); byte[] uint64_r = uint64_b.Reverse().ToArray(); - fi.SetValueDirect(__makeref(str), BitConverter.ToUInt64(uint64_r, 0)); + fi.SetValue(str, BitConverter.ToUInt64(uint64_r, 0)); } else if(fi.FieldType == typeof(float)) { - float flt = (float)fi.GetValue(str); + float flt = (float)fi.GetValue(str); byte[] flt_b = BitConverter.GetBytes(flt); byte[] flt_r = flt_b.Reverse().ToArray(); - fi.SetValueDirect(__makeref(str), BitConverter.ToSingle(flt_r, 0)); + fi.SetValue(str, BitConverter.ToSingle(flt_r, 0)); } else if(fi.FieldType == typeof(double)) { - double dbl = (double)fi.GetValue(str); + double dbl = (double)fi.GetValue(str); byte[] dbl_b = BitConverter.GetBytes(dbl); byte[] dbl_r = dbl_b.Reverse().ToArray(); - fi.SetValueDirect(__makeref(str), BitConverter.ToDouble(dbl_r, 0)); + fi.SetValue(str, BitConverter.ToDouble(dbl_r, 0)); + } + else if(fi.FieldType == typeof(byte) || fi.FieldType == typeof(sbyte)) + { + // Do nothing, can't byteswap them! + } + else if(fi.FieldType == typeof(Guid)) + { + // TODO: Swap GUID + } + // TODO: Swap arrays and enums + else if(fi.FieldType.IsValueType && !fi.FieldType.IsEnum && !fi.FieldType.IsArray) + { + object obj = fi.GetValue(str); + Type ty = obj.GetType(); + object strc = SwapStructureMembersEndian(obj); + fi.SetValue(str, strc); } return str; From 4f15c06b7389eedfe7b50220e36bfcac52f14371 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 11 Apr 2018 08:13:49 +0100 Subject: [PATCH 078/217] Update project schemas. --- DiscImageChef.Helpers.csproj | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index 31f2b9a89..9681c22e2 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -1,5 +1,5 @@  - + Debug AnyCPU @@ -11,6 +11,9 @@ DiscImageChef.Helpers 4.0.99.0 false + false + net45 + false true @@ -55,7 +58,6 @@ - {CCAA7AFE-C094-4D82-A66D-630DE8A3F545} From 87bd45b0e4a759be6969a0ca57f532b5e364bdf5 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 11 Apr 2018 08:28:45 +0100 Subject: [PATCH 079/217] Framework minimum version is v4.6.1. --- DiscImageChef.Helpers.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index 9681c22e2..0f72c2bac 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -12,7 +12,7 @@ 4.0.99.0 false false - net45 + net461 false From e4117abd78cfb25fa5cd0505a1a650b7816b6db5 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 11 Apr 2018 22:56:48 +0100 Subject: [PATCH 080/217] Move version to project files. --- DiscImageChef.Helpers.csproj | 13 ++++---- Properties/AssemblyInfo.cs | 57 ------------------------------------ 2 files changed, 8 insertions(+), 62 deletions(-) delete mode 100644 Properties/AssemblyInfo.cs diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index 0f72c2bac..db6787b98 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -3,17 +3,21 @@ Debug AnyCPU - 8.0.30703 2.0 {F8BDF57B-1571-4CD0-84B3-B422088D359A} Library DiscImageChef.Helpers DiscImageChef.Helpers - 4.0.99.0 - false + $(Version) false net461 - false + true + 4.0.99.1628 + Claunia.com + Copyright © 2011-2018 Natalia Portillo + The Disc Image Chef + DiscImageChef.Helpers + $(Version) true @@ -37,7 +41,6 @@ - diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs deleted file mode 100644 index 29aba7501..000000000 --- a/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,57 +0,0 @@ -// /*************************************************************************** -// The Disc Image Chef -// ---------------------------------------------------------------------------- -// -// Filename : AssemblyInfo.cs -// Author(s) : Natalia Portillo -// -// Component : Helpers. -// -// --[ Description ] ---------------------------------------------------------- -// -// C# assembly definitions. -// -// --[ License ] -------------------------------------------------------------- -// -// This library is free software; you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 2.1 of the -// License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, see . -// -// ---------------------------------------------------------------------------- -// Copyright © 2011-2018 Natalia Portillo -// ****************************************************************************/ - -using System.Reflection; - -// Information about this assembly is defined by the following attributes. -// Change them to the values specific to your project. - -[assembly: AssemblyTitle("DiscImageChef.Helpers")] -[assembly: AssemblyDescription("The Disc Image Chef")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Claunia.com")] -[assembly: AssemblyProduct("")] -[assembly: AssemblyCopyright("Copyright © 2011-2018 Natalia Portillo")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". -// The form "{Major}.{Minor}.*" will automatically update the build and revision, -// and "{Major}.{Minor}.{Build}.*" will update just the revision. - -[assembly: AssemblyVersion("4.0.99.0")] - -// The following attributes are used to specify the signing key for the assembly, -// if desired. See the Mono documentation for more information about signing. - -//[assembly: AssemblyDelaySign(false)] -//[assembly: AssemblyKeyFile("")] \ No newline at end of file From d2850929d66126cca878a017437f4dc985298339 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 12 Apr 2018 00:20:29 +0100 Subject: [PATCH 081/217] Automate version set from git revision. --- DiscImageChef.Helpers.csproj | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index db6787b98..df7c30eb7 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -12,13 +12,18 @@ false net461 true - 4.0.99.1628 + 4.0.99.1629 Claunia.com Copyright © 2011-2018 Natalia Portillo The Disc Image Chef DiscImageChef.Helpers $(Version) + + $(Version)-{chash:8} built by {mname} in $(Configuration){!:, modified} + true + true + true full @@ -75,6 +80,9 @@ + + + From 4c15d8c8cb67ffe745a299ce31e646832d26b271 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Fri, 22 Jun 2018 08:08:38 +0100 Subject: [PATCH 082/217] Code cleanup. --- BigEndianBitConverter.cs | 27 +++++++++++--------- CHS.cs | 2 +- CompareBytes.cs | 8 +++--- CountBits.cs | 2 +- DateHandlers.cs | 53 +++++++++++++++++++++------------------- Extents/ExtentsByte.cs | 4 +-- Extents/ExtentsInt.cs | 4 +-- Extents/ExtentsLong.cs | 4 +-- Extents/ExtentsSByte.cs | 4 +-- Extents/ExtentsShort.cs | 4 +-- Extents/ExtentsUInt.cs | 4 +-- Extents/ExtentsULong.cs | 4 +-- Extents/ExtentsUShort.cs | 4 +-- PrintHex.cs | 4 +-- StringHandlers.cs | 12 +++++---- Swapping.cs | 2 +- 16 files changed, 75 insertions(+), 67 deletions(-) diff --git a/BigEndianBitConverter.cs b/BigEndianBitConverter.cs index b017ce94d..33e2e713c 100644 --- a/BigEndianBitConverter.cs +++ b/BigEndianBitConverter.cs @@ -239,7 +239,7 @@ public static double ToDouble(byte[] value, int startIndex) 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 @@ public static short ToInt16(byte[] value, int startIndex) 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 @@ public static int ToInt32(byte[] value, int startIndex) 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 @@ public static long ToInt64(byte[] value, int startIndex) 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 @@ public static string ToString(byte[] value) 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 @@ public static string ToString(byte[] value, int startIndex) 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 @@ public static string ToString(byte[] value, int startIndex, int length) 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 @@ public static ushort ToUInt16(byte[] value, int startIndex) 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 @@ public static uint ToUInt32(byte[] value, int startIndex) 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]); } } } \ No newline at end of file diff --git a/CHS.cs b/CHS.cs index 29f69b35d..5f7aca7ac 100644 --- a/CHS.cs +++ b/CHS.cs @@ -46,7 +46,7 @@ public static class CHS 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; } } diff --git a/CompareBytes.cs b/CompareBytes.cs index 321ce8f1c..e5953b81e 100644 --- a/CompareBytes.cs +++ b/CompareBytes.cs @@ -42,20 +42,20 @@ public static partial class ArrayHelpers /// Left array /// Right array 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; diff --git a/CountBits.cs b/CountBits.cs index 3c0b926ca..e2aae95de 100644 --- a/CountBits.cs +++ b/CountBits.cs @@ -42,7 +42,7 @@ public static class CountBits 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); } } diff --git a/DateHandlers.cs b/DateHandlers.cs index 6014650aa..4d3345432 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -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); /// /// Day 0 of Julian Date system @@ -138,7 +138,7 @@ public static DateTime HighSierraToDateTime(byte[] vdDateTime) /// .NET DateTime 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 @@ public static DateTime AmigaToDateTime(uint days, uint minutes, uint ticks) /// .NET DateTime 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 @@ public static DateTime UcsdPascalToDateTime(short dateRecord) /// .NET DateTime 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 @@ public static DateTime DosToDateTime(ushort date, ushort time) /// .NET DateTime 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 @@ public static DateTime CpmToDateTime(byte[] timestamp) /// Hundreds of microseconds /// 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) + 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 @@ public static DateTime EcmaToDateTime(ushort typeAndTimeZone, short year, byte m 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; } /// @@ -347,7 +350,7 @@ public static DateTime Os9ToDateTime(byte[] date) { 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 @@ public static DateTime LifToDateTime(byte year, byte month, byte day, byte hour, { 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); } diff --git a/Extents/ExtentsByte.cs b/Extents/ExtentsByte.cs index 7d52a69a9..ba2b3c678 100644 --- a/Extents/ExtentsByte.cs +++ b/Extents/ExtentsByte.cs @@ -135,7 +135,7 @@ public void Add(byte start, byte end, bool run = false) { 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 @@ public bool Remove(byte item) { toRemove = extent; toAddOne = new Tuple(extent.Item1, (byte)(item - 1)); - toAddTwo = new Tuple((byte)(item + 1), extent.Item2); + toAddTwo = new Tuple((byte)(item + 1), extent.Item2); break; } diff --git a/Extents/ExtentsInt.cs b/Extents/ExtentsInt.cs index 8d4006347..39b8dbae6 100644 --- a/Extents/ExtentsInt.cs +++ b/Extents/ExtentsInt.cs @@ -135,7 +135,7 @@ public void Add(int start, int end, bool run = false) { 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 @@ public bool Remove(int item) { toRemove = extent; toAddOne = new Tuple(extent.Item1, item - 1); - toAddTwo = new Tuple(item + 1, extent.Item2); + toAddTwo = new Tuple(item + 1, extent.Item2); break; } diff --git a/Extents/ExtentsLong.cs b/Extents/ExtentsLong.cs index b70c85a98..5ccef4389 100644 --- a/Extents/ExtentsLong.cs +++ b/Extents/ExtentsLong.cs @@ -135,7 +135,7 @@ public void Add(long start, long end, bool run = false) { 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 @@ public bool Remove(long item) { toRemove = extent; toAddOne = new Tuple(extent.Item1, item - 1); - toAddTwo = new Tuple(item + 1, extent.Item2); + toAddTwo = new Tuple(item + 1, extent.Item2); break; } diff --git a/Extents/ExtentsSByte.cs b/Extents/ExtentsSByte.cs index b7479683d..f77c2848e 100644 --- a/Extents/ExtentsSByte.cs +++ b/Extents/ExtentsSByte.cs @@ -135,7 +135,7 @@ public void Add(sbyte start, sbyte end, bool run = false) { 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 @@ public bool Remove(sbyte item) { toRemove = extent; toAddOne = new Tuple(extent.Item1, (sbyte)(item - 1)); - toAddTwo = new Tuple((sbyte)(item + 1), extent.Item2); + toAddTwo = new Tuple((sbyte)(item + 1), extent.Item2); break; } diff --git a/Extents/ExtentsShort.cs b/Extents/ExtentsShort.cs index 0a26ee0b5..ae92ee891 100644 --- a/Extents/ExtentsShort.cs +++ b/Extents/ExtentsShort.cs @@ -135,7 +135,7 @@ public void Add(short start, short end, bool run = false) { 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 @@ public bool Remove(short item) { toRemove = extent; toAddOne = new Tuple(extent.Item1, (short)(item - 1)); - toAddTwo = new Tuple((short)(item + 1), extent.Item2); + toAddTwo = new Tuple((short)(item + 1), extent.Item2); break; } diff --git a/Extents/ExtentsUInt.cs b/Extents/ExtentsUInt.cs index 874173c0a..6a917d69d 100644 --- a/Extents/ExtentsUInt.cs +++ b/Extents/ExtentsUInt.cs @@ -135,7 +135,7 @@ public void Add(uint start, uint end, bool run = false) { 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 @@ public bool Remove(uint item) { toRemove = extent; toAddOne = new Tuple(extent.Item1, item - 1); - toAddTwo = new Tuple(item + 1, extent.Item2); + toAddTwo = new Tuple(item + 1, extent.Item2); break; } diff --git a/Extents/ExtentsULong.cs b/Extents/ExtentsULong.cs index 71a82200c..09c76e8c8 100644 --- a/Extents/ExtentsULong.cs +++ b/Extents/ExtentsULong.cs @@ -135,7 +135,7 @@ public void Add(ulong start, ulong end, bool run = false) { 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 @@ public bool Remove(ulong item) { toRemove = extent; toAddOne = new Tuple(extent.Item1, item - 1); - toAddTwo = new Tuple(item + 1, extent.Item2); + toAddTwo = new Tuple(item + 1, extent.Item2); break; } diff --git a/Extents/ExtentsUShort.cs b/Extents/ExtentsUShort.cs index fa6122c1f..6a8689cf0 100644 --- a/Extents/ExtentsUShort.cs +++ b/Extents/ExtentsUShort.cs @@ -135,7 +135,7 @@ public void Add(ushort start, ushort end, bool run = false) { 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 @@ public bool Remove(ushort item) { toRemove = extent; toAddOne = new Tuple(extent.Item1, (ushort)(item - 1)); - toAddTwo = new Tuple((ushort)(item + 1), extent.Item2); + toAddTwo = new Tuple((ushort)(item + 1), extent.Item2); break; } diff --git a/PrintHex.cs b/PrintHex.cs index 0cd4f144b..551beefaa 100644 --- a/PrintHex.cs +++ b/PrintHex.cs @@ -57,7 +57,7 @@ public static string ByteArrayToHexArrayString(byte[] array, int width) { 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 @@ public static string ByteArrayToHexArrayString(byte[] array, int width) if(counter == width - 1) { - counter = 0; + counter = 0; subcounter = 0; } else counter++; diff --git a/StringHandlers.cs b/StringHandlers.cs index 8ab0e350f..ad2fb0cb5 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -71,10 +71,12 @@ public static string CToString(byte[] CString, Encoding encoding, bool twoBytes len++; break; } + // if((i + 1) == CString.Length) // break; } - else break; + else + break; len++; } @@ -107,7 +109,7 @@ public static string PascalToString(byte[] PascalString, Encoding encoding, int 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 @@ public static string SpacePaddedToString(byte[] SpacePaddedString, Encoding enco 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++]; diff --git a/Swapping.cs b/Swapping.cs index 75bec257e..cf52121eb 100644 --- a/Swapping.cs +++ b/Swapping.cs @@ -107,7 +107,7 @@ public static ulong Swap(ulong x) { 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; } From 7ad5b1c5b62aa3e21dfb633eba050c2e1c8726c1 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sat, 23 Jun 2018 20:41:04 +0100 Subject: [PATCH 083/217] Remove old and abandoned per-project changelogs. --- ChangeLog | 149 ------------------------------------------------------ 1 file changed, 149 deletions(-) delete mode 100644 ChangeLog diff --git a/ChangeLog b/ChangeLog deleted file mode 100644 index 5234cf643..000000000 --- a/ChangeLog +++ /dev/null @@ -1,149 +0,0 @@ -2017-05-27 Natalia Portillo - - * CompareBytes.cs: - * DiscImageChef.Helpers.csproj: Refactor: Moved CompareBytes - to Helpers. - -2017-05-19 Natalia Portillo - - * Swapping.cs: - * PrintHex.cs: - * ArrayFill.cs: - * ArrayIsEmpty.cs: - * DateHandlers.cs: - * StringHandlers.cs: - * BigEndianMarshal.cs: - * BigEndianBitConverter.cs: - * AssemblyInfo.cs: - * EndianAwareBinaryReader.cs: Updated copyright string. - -2017-05-19 Natalia Portillo - - * AssemblyInfo.cs: Bumped version to 3.3.99.0. - -2017-05-19 Natalia Portillo - - * DiscImageChef.Helpers.csproj: Upped version to 3.3.99.0. Do - not use version from solution on library projects. - -2016-09-05 Natalia Portillo - - * DateHandlers.cs: Added AppleSingle and AppleDouble filters. - -2016-09-02 Natalia Portillo - - * DateHandlers.cs: Adds support for NILFS2 filesystem. - -2016-09-02 Natalia Portillo - - * DateHandlers.cs: Add supports for UNIX timestamps divided in - seconds+nanoseconds. - -2016-08-26 Natalia Portillo - - * DateHandlers.cs: Added CP/M timestamp converter. - -2016-08-22 Natalia Portillo - - * BigEndianMarshal.cs: - * BigEndianStructure.cs: - * DiscImageChef.Helpers.csproj: Reworked big endian marshal. - Does not traverse nested structures. - -2016-08-21 Natalia Portillo - - * BigEndianStructure.cs: - * DiscImageChef.Helpers.csproj: Added code that directly - marshals from a big-endian byte array. But untested with - nested structures. - -2016-08-09 Natalia Portillo - - * DiscImageChef.Helpers.csproj: Bumped version to 3.2.99.2. - -2016-08-07 Natalia Portillo - - * DiscImageChef.Helpers.csproj: Public beta release 3.2.99.1. - -2016-08-07 Natalia Portillo - - * DateHandlers.cs: Added DOS to C# date converter. - -2016-08-01 Natalia Portillo - - * AssemblyInfo.cs: - * DiscImageChef.Helpers.csproj: Bumped to version 3.2.1. - -2016-08-01 Natalia Portillo - - * AssemblyInfo.cs: - * DiscImageChef.Helpers.csproj: Bump to version 3.2.0 - -2016-07-31 Natalia Portillo - - * DateHandlers.cs: Added support for U.C.S.D. Pascal - filesystem, closes #31 - -2016-07-29 Natalia Portillo - - * DiscImageChef.Helpers.csproj: Bump to version 3.1.0. - -2016-07-28 Natalia Portillo - - * DiscImageChef.Helpers.csproj: Code re-styling. - -2016-07-28 Natalia Portillo - - * Swapping.cs: - * PrintHex.cs: - * ArrayFill.cs: - * ArrayIsEmpty.cs: - * DateHandlers.cs: - * StringHandlers.cs: - * BigEndianBitConverter.cs: - * EndianAwareBinaryReader.cs: Refactor and code cleanup. - -2016-01-13 Natalia Portillo - - * ArrayFill.cs: - * ArrayIsEmpty.cs: - * DiscImageChef.Helpers.csproj: - Implemented Certance, Fujitsu and Hewlett-Packard vendor - commands. - -2015-12-30 Natalia Portillo - - * StringHandlers.cs: - Fixed string conversion when input byte array is null. - -2015-12-04 Natalia Portillo - - * StringHandlers.cs: - Finally CD-Text on lead-in is getting decoded correctly... - -2015-10-19 Natalia Portillo - - * DiscImageChef.Helpers.csproj: - Upgrade .NET version to 4.0. - -2015-10-18 Natalia Portillo - - * PrintHex.cs: - * DateHandlers.cs: - * DiscImageChef.Helpers.csproj: - Added specific console handling for standard, verbose, debug - and error outputs. - -2015-10-05 Natalia Portillo - - * PrintHex.cs: - * Swapping.cs: - * ArrayFill.cs: - * DateHandlers.cs: - * StringHandlers.cs: - * BigEndianBitConverter.cs: - * EndianAwareBinaryReader.cs: - * Properties/AssemblyInfo.cs: - * DiscImageChef.Helpers.csproj: - Move helpers to a separate library. - From 61d8d9dfefdaf9d4917fb19527eb515187329197 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 24 Jun 2018 12:46:08 +0100 Subject: [PATCH 084/217] Bump version to 4.5.0.1663. --- DiscImageChef.Helpers.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index df7c30eb7..ca33b5231 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -12,7 +12,7 @@ false net461 true - 4.0.99.1629 + 4.5.0.1663 Claunia.com Copyright © 2011-2018 Natalia Portillo The Disc Image Chef From c067124dae3038f01d7d2684eca010ba060f8582 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 24 Jun 2018 21:35:04 +0100 Subject: [PATCH 085/217] Move to development version 4.5.99.1663. --- DiscImageChef.Helpers.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index ca33b5231..a6eb4c5e1 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -12,7 +12,7 @@ false net461 true - 4.5.0.1663 + 4.5.99.1663 Claunia.com Copyright © 2011-2018 Natalia Portillo The Disc Image Chef From 88a8697f48c3757271846867a63438d7e5896e07 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 25 Jun 2018 19:08:16 +0100 Subject: [PATCH 086/217] Move all interfaces, extents, interop and metadata to DiscImageChef.CommonTypes. --- DiscImageChef.Helpers.csproj | 11 -- Extents/ExtentsByte.cs | 248 ---------------------------------- Extents/ExtentsInt.cs | 248 ---------------------------------- Extents/ExtentsLong.cs | 248 ---------------------------------- Extents/ExtentsSByte.cs | 248 ---------------------------------- Extents/ExtentsShort.cs | 248 ---------------------------------- Extents/ExtentsUInt.cs | 248 ---------------------------------- Extents/ExtentsULong.cs | 248 ---------------------------------- Extents/ExtentsUShort.cs | 249 ----------------------------------- 9 files changed, 1996 deletions(-) delete mode 100644 Extents/ExtentsByte.cs delete mode 100644 Extents/ExtentsInt.cs delete mode 100644 Extents/ExtentsLong.cs delete mode 100644 Extents/ExtentsSByte.cs delete mode 100644 Extents/ExtentsShort.cs delete mode 100644 Extents/ExtentsUInt.cs delete mode 100644 Extents/ExtentsULong.cs delete mode 100644 Extents/ExtentsUShort.cs diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index a6eb4c5e1..35eed0b02 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -55,14 +55,6 @@ - - - - - - - - @@ -77,9 +69,6 @@ LICENSE.LGPL - - - diff --git a/Extents/ExtentsByte.cs b/Extents/ExtentsByte.cs deleted file mode 100644 index ba2b3c678..000000000 --- a/Extents/ExtentsByte.cs +++ /dev/null @@ -1,248 +0,0 @@ -// /*************************************************************************** -// The Disc Image Chef -// ---------------------------------------------------------------------------- -// -// Filename : ExtentsByte.cs -// Author(s) : Natalia Portillo -// -// Component : Extent helpers. -// -// --[ Description ] ---------------------------------------------------------- -// -// Provides extents for byte types. -// -// --[ License ] -------------------------------------------------------------- -// -// This library is free software; you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 2.1 of the -// License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, see . -// -// ---------------------------------------------------------------------------- -// Copyright © 2011-2018 Natalia Portillo -// ****************************************************************************/ - -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Extents -{ - /// - /// Implements extents for - /// - public class ExtentsByte - { - List> backend; - - /// - /// Initialize an empty list of extents - /// - public ExtentsByte() - { - backend = new List>(); - } - - /// - /// Initializes extents with an specific list - /// - /// List of extents as tuples "start, end" - public ExtentsByte(IEnumerable> list) - { - backend = list.OrderBy(t => t.Item1).ToList(); - } - - /// - /// Gets a count of how many extents are stored - /// - public int Count => backend.Count; - - /// - /// Adds the specified number to the corresponding extent, or creates a new one - /// - /// - public void Add(byte item) - { - Tuple removeOne = null; - Tuple removeTwo = null; - Tuple itemToAdd = null; - - for(int i = 0; i < backend.Count; i++) - { - // Already contained in an extent - if(item >= backend[i].Item1 && item <= backend[i].Item2) return; - - // Expands existing extent start - if(item == backend[i].Item1 - 1) - { - removeOne = backend[i]; - - if(i > 0 && item == backend[i - 1].Item2 + 1) - { - removeTwo = backend[i - 1]; - itemToAdd = new Tuple(backend[i - 1].Item1, backend[i].Item2); - } - else itemToAdd = new Tuple(item, backend[i].Item2); - - break; - } - - // Expands existing extent end - if(item != backend[i].Item2 + 1) continue; - - removeOne = backend[i]; - - if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) - { - removeTwo = backend[i + 1]; - itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); - } - else itemToAdd = new Tuple(backend[i].Item1, item); - - break; - } - - if(itemToAdd != null) - { - backend.Remove(removeOne); - backend.Remove(removeTwo); - backend.Add(itemToAdd); - } - else backend.Add(new Tuple(item, item)); - - // Sort - backend = backend.OrderBy(t => t.Item1).ToList(); - } - - /// - /// Adds a new extent - /// - /// First element of the extent - /// - /// Last element of the extent or if is true how many elements the extent runs - /// for - /// - /// If set to true, indicates how many elements the extent runs for - public void Add(byte start, byte end, bool run = false) - { - byte realEnd; - if(run) realEnd = (byte)(start + end - 1); - else realEnd = end; - - // TODO: Optimize this - for(byte t = start; t <= realEnd; t++) Add(t); - } - - /// - /// Checks if the specified item is contained by an extent on this instance - /// - /// Item to seach for - /// true if any of the extents on this instance contains the item - public bool Contains(byte item) - { - return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2); - } - - /// - /// Removes all extents from this instance - /// - public void Clear() - { - backend.Clear(); - } - - /// - /// Removes an item from the extents in this instance - /// - /// Item to remove - /// true if the item was contained in a known extent and removed, false otherwise - public bool Remove(byte item) - { - Tuple toRemove = null; - Tuple toAddOne = null; - Tuple toAddTwo = null; - - foreach(Tuple extent in backend) - { - // Extent is contained and not a border - if(item > extent.Item1 && item < extent.Item2) - { - toRemove = extent; - toAddOne = new Tuple(extent.Item1, (byte)(item - 1)); - toAddTwo = new Tuple((byte)(item + 1), extent.Item2); - break; - } - - // Extent is left border, but not only element - if(item == extent.Item1 && item != extent.Item2) - { - toRemove = extent; - toAddOne = new Tuple((byte)(item + 1), extent.Item2); - break; - } - - // Extent is right border, but not only element - if(item != extent.Item1 && item == extent.Item2) - { - toRemove = extent; - toAddOne = new Tuple(extent.Item1, (byte)(item - 1)); - break; - } - - // Extent is only element - if(item != extent.Item1 || item != extent.Item2) continue; - - toRemove = extent; - break; - } - - // Item not found - if(toRemove == null) return false; - - backend.Remove(toRemove); - if(toAddOne != null) backend.Add(toAddOne); - if(toAddTwo != null) backend.Add(toAddTwo); - - // Sort - backend = backend.OrderBy(t => t.Item1).ToList(); - - return true; - } - - /// - /// Converts the list of extents to an array of where T1 is first element of the extent and T2 is - /// last element - /// - /// Array of - public Tuple[] ToArray() - { - return backend.ToArray(); - } - - /// - /// Gets the first element of the extent that contains the specified item - /// - /// Item - /// First element of extent - /// true if item was found in an extent, false otherwise - public bool GetStart(byte item, out byte start) - { - start = 0; - foreach(Tuple extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) - { - start = extent.Item1; - return true; - } - - return false; - } - } -} \ No newline at end of file diff --git a/Extents/ExtentsInt.cs b/Extents/ExtentsInt.cs deleted file mode 100644 index 39b8dbae6..000000000 --- a/Extents/ExtentsInt.cs +++ /dev/null @@ -1,248 +0,0 @@ -// /*************************************************************************** -// The Disc Image Chef -// ---------------------------------------------------------------------------- -// -// Filename : ExtentsInt.cs -// Author(s) : Natalia Portillo -// -// Component : Extent helpers. -// -// --[ Description ] ---------------------------------------------------------- -// -// Provides extents for int types. -// -// --[ License ] -------------------------------------------------------------- -// -// This library is free software; you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 2.1 of the -// License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License aint with this library; if not, see . -// -// ---------------------------------------------------------------------------- -// Copyright © 2011-2018 Natalia Portillo -// ****************************************************************************/ - -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Extents -{ - /// - /// Implements extents for - /// - public class ExtentsInt - { - List> backend; - - /// - /// Initialize an empty list of extents - /// - public ExtentsInt() - { - backend = new List>(); - } - - /// - /// Initializes extents with an specific list - /// - /// List of extents as tuples "start, end" - public ExtentsInt(IEnumerable> list) - { - backend = list.OrderBy(t => t.Item1).ToList(); - } - - /// - /// Gets a count of how many extents are stored - /// - public int Count => backend.Count; - - /// - /// Adds the specified number to the corresponding extent, or creates a new one - /// - /// - public void Add(int item) - { - Tuple removeOne = null; - Tuple removeTwo = null; - Tuple itemToAdd = null; - - for(int i = 0; i < backend.Count; i++) - { - // Already contained in an extent - if(item >= backend[i].Item1 && item <= backend[i].Item2) return; - - // Expands existing extent start - if(item == backend[i].Item1 - 1) - { - removeOne = backend[i]; - - if(i > 0 && item == backend[i - 1].Item2 + 1) - { - removeTwo = backend[i - 1]; - itemToAdd = new Tuple(backend[i - 1].Item1, backend[i].Item2); - } - else itemToAdd = new Tuple(item, backend[i].Item2); - - break; - } - - // Expands existing extent end - if(item != backend[i].Item2 + 1) continue; - - removeOne = backend[i]; - - if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) - { - removeTwo = backend[i + 1]; - itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); - } - else itemToAdd = new Tuple(backend[i].Item1, item); - - break; - } - - if(itemToAdd != null) - { - backend.Remove(removeOne); - backend.Remove(removeTwo); - backend.Add(itemToAdd); - } - else backend.Add(new Tuple(item, item)); - - // Sort - backend = backend.OrderBy(t => t.Item1).ToList(); - } - - /// - /// Adds a new extent - /// - /// First element of the extent - /// - /// Last element of the extent or if is true how many elements the extent runs - /// for - /// - /// If set to true, indicates how many elements the extent runs for - public void Add(int start, int end, bool run = false) - { - int realEnd; - if(run) realEnd = start + end - 1; - else realEnd = end; - - // TODO: Optimize this - for(int t = start; t <= realEnd; t++) Add(t); - } - - /// - /// Checks if the specified item is contained by an extent on this instance - /// - /// Item to seach for - /// true if any of the extents on this instance contains the item - public bool Contains(int item) - { - return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2); - } - - /// - /// Removes all extents from this instance - /// - public void Clear() - { - backend.Clear(); - } - - /// - /// Removes an item from the extents in this instance - /// - /// Item to remove - /// true if the item was contained in a known extent and removed, false otherwise - public bool Remove(int item) - { - Tuple toRemove = null; - Tuple toAddOne = null; - Tuple toAddTwo = null; - - foreach(Tuple extent in backend) - { - // Extent is contained and not a border - if(item > extent.Item1 && item < extent.Item2) - { - toRemove = extent; - toAddOne = new Tuple(extent.Item1, item - 1); - toAddTwo = new Tuple(item + 1, extent.Item2); - break; - } - - // Extent is left border, but not only element - if(item == extent.Item1 && item != extent.Item2) - { - toRemove = extent; - toAddOne = new Tuple(item + 1, extent.Item2); - break; - } - - // Extent is right border, but not only element - if(item != extent.Item1 && item == extent.Item2) - { - toRemove = extent; - toAddOne = new Tuple(extent.Item1, item - 1); - break; - } - - // Extent is only element - if(item != extent.Item1 || item != extent.Item2) continue; - - toRemove = extent; - break; - } - - // Item not found - if(toRemove == null) return false; - - backend.Remove(toRemove); - if(toAddOne != null) backend.Add(toAddOne); - if(toAddTwo != null) backend.Add(toAddTwo); - - // Sort - backend = backend.OrderBy(t => t.Item1).ToList(); - - return true; - } - - /// - /// Converts the list of extents to an array of where T1 is first element of the extent and T2 is - /// last element - /// - /// Array of - public Tuple[] ToArray() - { - return backend.ToArray(); - } - - /// - /// Gets the first element of the extent that contains the specified item - /// - /// Item - /// First element of extent - /// true if item was found in an extent, false otherwise - public bool GetStart(int item, out int start) - { - start = 0; - foreach(Tuple extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) - { - start = extent.Item1; - return true; - } - - return false; - } - } -} \ No newline at end of file diff --git a/Extents/ExtentsLong.cs b/Extents/ExtentsLong.cs deleted file mode 100644 index 5ccef4389..000000000 --- a/Extents/ExtentsLong.cs +++ /dev/null @@ -1,248 +0,0 @@ -// /*************************************************************************** -// The Disc Image Chef -// ---------------------------------------------------------------------------- -// -// Filename : ExtentsLong.cs -// Author(s) : Natalia Portillo -// -// Component : Extent helpers. -// -// --[ Description ] ---------------------------------------------------------- -// -// Provides extents for long types. -// -// --[ License ] -------------------------------------------------------------- -// -// This library is free software; you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 2.1 of the -// License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, see . -// -// ---------------------------------------------------------------------------- -// Copyright © 2011-2018 Natalia Portillo -// ****************************************************************************/ - -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Extents -{ - /// - /// Implements extents for - /// - public class ExtentsLong - { - List> backend; - - /// - /// Initialize an empty list of extents - /// - public ExtentsLong() - { - backend = new List>(); - } - - /// - /// Initializes extents with an specific list - /// - /// List of extents as tuples "start, end" - public ExtentsLong(IEnumerable> list) - { - backend = list.OrderBy(t => t.Item1).ToList(); - } - - /// - /// Gets a count of how many extents are stored - /// - public int Count => backend.Count; - - /// - /// Adds the specified number to the corresponding extent, or creates a new one - /// - /// - public void Add(long item) - { - Tuple removeOne = null; - Tuple removeTwo = null; - Tuple itemToAdd = null; - - for(int i = 0; i < backend.Count; i++) - { - // Already contained in an extent - if(item >= backend[i].Item1 && item <= backend[i].Item2) return; - - // Expands existing extent start - if(item == backend[i].Item1 - 1) - { - removeOne = backend[i]; - - if(i > 0 && item == backend[i - 1].Item2 + 1) - { - removeTwo = backend[i - 1]; - itemToAdd = new Tuple(backend[i - 1].Item1, backend[i].Item2); - } - else itemToAdd = new Tuple(item, backend[i].Item2); - - break; - } - - // Expands existing extent end - if(item != backend[i].Item2 + 1) continue; - - removeOne = backend[i]; - - if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) - { - removeTwo = backend[i + 1]; - itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); - } - else itemToAdd = new Tuple(backend[i].Item1, item); - - break; - } - - if(itemToAdd != null) - { - backend.Remove(removeOne); - backend.Remove(removeTwo); - backend.Add(itemToAdd); - } - else backend.Add(new Tuple(item, item)); - - // Sort - backend = backend.OrderBy(t => t.Item1).ToList(); - } - - /// - /// Adds a new extent - /// - /// First element of the extent - /// - /// Last element of the extent or if is true how many elements the extent runs - /// for - /// - /// If set to true, indicates how many elements the extent runs for - public void Add(long start, long end, bool run = false) - { - long realEnd; - if(run) realEnd = start + end - 1; - else realEnd = end; - - // TODO: Optimize this - for(long t = start; t <= realEnd; t++) Add(t); - } - - /// - /// Checks if the specified item is contained by an extent on this instance - /// - /// Item to seach for - /// true if any of the extents on this instance contains the item - public bool Contains(long item) - { - return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2); - } - - /// - /// Removes all extents from this instance - /// - public void Clear() - { - backend.Clear(); - } - - /// - /// Removes an item from the extents in this instance - /// - /// Item to remove - /// true if the item was contained in a known extent and removed, false otherwise - public bool Remove(long item) - { - Tuple toRemove = null; - Tuple toAddOne = null; - Tuple toAddTwo = null; - - foreach(Tuple extent in backend) - { - // Extent is contained and not a border - if(item > extent.Item1 && item < extent.Item2) - { - toRemove = extent; - toAddOne = new Tuple(extent.Item1, item - 1); - toAddTwo = new Tuple(item + 1, extent.Item2); - break; - } - - // Extent is left border, but not only element - if(item == extent.Item1 && item != extent.Item2) - { - toRemove = extent; - toAddOne = new Tuple(item + 1, extent.Item2); - break; - } - - // Extent is right border, but not only element - if(item != extent.Item1 && item == extent.Item2) - { - toRemove = extent; - toAddOne = new Tuple(extent.Item1, item - 1); - break; - } - - // Extent is only element - if(item != extent.Item1 || item != extent.Item2) continue; - - toRemove = extent; - break; - } - - // Item not found - if(toRemove == null) return false; - - backend.Remove(toRemove); - if(toAddOne != null) backend.Add(toAddOne); - if(toAddTwo != null) backend.Add(toAddTwo); - - // Sort - backend = backend.OrderBy(t => t.Item1).ToList(); - - return true; - } - - /// - /// Converts the list of extents to an array of where T1 is first element of the extent and T2 is - /// last element - /// - /// Array of - public Tuple[] ToArray() - { - return backend.ToArray(); - } - - /// - /// Gets the first element of the extent that contains the specified item - /// - /// Item - /// First element of extent - /// true if item was found in an extent, false otherwise - public bool GetStart(long item, out long start) - { - start = 0; - foreach(Tuple extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) - { - start = extent.Item1; - return true; - } - - return false; - } - } -} \ No newline at end of file diff --git a/Extents/ExtentsSByte.cs b/Extents/ExtentsSByte.cs deleted file mode 100644 index f77c2848e..000000000 --- a/Extents/ExtentsSByte.cs +++ /dev/null @@ -1,248 +0,0 @@ -// /*************************************************************************** -// The Disc Image Chef -// ---------------------------------------------------------------------------- -// -// Filename : ExtentsSByte.cs -// Author(s) : Natalia Portillo -// -// Component : Extent helpers. -// -// --[ Description ] ---------------------------------------------------------- -// -// Provides extents for sbyte types. -// -// --[ License ] -------------------------------------------------------------- -// -// This library is free software; you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 2.1 of the -// License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, see . -// -// ---------------------------------------------------------------------------- -// Copyright © 2011-2018 Natalia Portillo -// ****************************************************************************/ - -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Extents -{ - /// - /// Implements extents for - /// - public class ExtentsSByte - { - List> backend; - - /// - /// Initialize an empty list of extents - /// - public ExtentsSByte() - { - backend = new List>(); - } - - /// - /// Initializes extents with an specific list - /// - /// List of extents as tuples "start, end" - public ExtentsSByte(IEnumerable> list) - { - backend = list.OrderBy(t => t.Item1).ToList(); - } - - /// - /// Gets a count of how many extents are stored - /// - public int Count => backend.Count; - - /// - /// Adds the specified number to the corresponding extent, or creates a new one - /// - /// - public void Add(sbyte item) - { - Tuple removeOne = null; - Tuple removeTwo = null; - Tuple itemToAdd = null; - - for(int i = 0; i < backend.Count; i++) - { - // Already contained in an extent - if(item >= backend[i].Item1 && item <= backend[i].Item2) return; - - // Expands existing extent start - if(item == backend[i].Item1 - 1) - { - removeOne = backend[i]; - - if(i > 0 && item == backend[i - 1].Item2 + 1) - { - removeTwo = backend[i - 1]; - itemToAdd = new Tuple(backend[i - 1].Item1, backend[i].Item2); - } - else itemToAdd = new Tuple(item, backend[i].Item2); - - break; - } - - // Expands existing extent end - if(item != backend[i].Item2 + 1) continue; - - removeOne = backend[i]; - - if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) - { - removeTwo = backend[i + 1]; - itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); - } - else itemToAdd = new Tuple(backend[i].Item1, item); - - break; - } - - if(itemToAdd != null) - { - backend.Remove(removeOne); - backend.Remove(removeTwo); - backend.Add(itemToAdd); - } - else backend.Add(new Tuple(item, item)); - - // Sort - backend = backend.OrderBy(t => t.Item1).ToList(); - } - - /// - /// Adds a new extent - /// - /// First element of the extent - /// - /// Last element of the extent or if is true how many elements the extent runs - /// for - /// - /// If set to true, indicates how many elements the extent runs for - public void Add(sbyte start, sbyte end, bool run = false) - { - sbyte realEnd; - if(run) realEnd = (sbyte)(start + end - 1); - else realEnd = end; - - // TODO: Optimize this - for(sbyte t = start; t <= realEnd; t++) Add(t); - } - - /// - /// Checks if the specified item is contained by an extent on this instance - /// - /// Item to seach for - /// true if any of the extents on this instance contains the item - public bool Contains(sbyte item) - { - return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2); - } - - /// - /// Removes all extents from this instance - /// - public void Clear() - { - backend.Clear(); - } - - /// - /// Removes an item from the extents in this instance - /// - /// Item to remove - /// true if the item was contained in a known extent and removed, false otherwise - public bool Remove(sbyte item) - { - Tuple toRemove = null; - Tuple toAddOne = null; - Tuple toAddTwo = null; - - foreach(Tuple extent in backend) - { - // Extent is contained and not a border - if(item > extent.Item1 && item < extent.Item2) - { - toRemove = extent; - toAddOne = new Tuple(extent.Item1, (sbyte)(item - 1)); - toAddTwo = new Tuple((sbyte)(item + 1), extent.Item2); - break; - } - - // Extent is left border, but not only element - if(item == extent.Item1 && item != extent.Item2) - { - toRemove = extent; - toAddOne = new Tuple((sbyte)(item + 1), extent.Item2); - break; - } - - // Extent is right border, but not only element - if(item != extent.Item1 && item == extent.Item2) - { - toRemove = extent; - toAddOne = new Tuple(extent.Item1, (sbyte)(item - 1)); - break; - } - - // Extent is only element - if(item != extent.Item1 || item != extent.Item2) continue; - - toRemove = extent; - break; - } - - // Item not found - if(toRemove == null) return false; - - backend.Remove(toRemove); - if(toAddOne != null) backend.Add(toAddOne); - if(toAddTwo != null) backend.Add(toAddTwo); - - // Sort - backend = backend.OrderBy(t => t.Item1).ToList(); - - return true; - } - - /// - /// Converts the list of extents to an array of where T1 is first element of the extent and T2 is - /// last element - /// - /// Array of - public Tuple[] ToArray() - { - return backend.ToArray(); - } - - /// - /// Gets the first element of the extent that contains the specified item - /// - /// Item - /// First element of extent - /// true if item was found in an extent, false otherwise - public bool GetStart(sbyte item, out sbyte start) - { - start = 0; - foreach(Tuple extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) - { - start = extent.Item1; - return true; - } - - return false; - } - } -} \ No newline at end of file diff --git a/Extents/ExtentsShort.cs b/Extents/ExtentsShort.cs deleted file mode 100644 index ae92ee891..000000000 --- a/Extents/ExtentsShort.cs +++ /dev/null @@ -1,248 +0,0 @@ -// /*************************************************************************** -// The Disc Image Chef -// ---------------------------------------------------------------------------- -// -// Filename : ExtentsShort.cs -// Author(s) : Natalia Portillo -// -// Component : Extent helpers. -// -// --[ Description ] ---------------------------------------------------------- -// -// Provides extents for short types. -// -// --[ License ] -------------------------------------------------------------- -// -// This library is free software; you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 2.1 of the -// License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License ashort with this library; if not, see . -// -// ---------------------------------------------------------------------------- -// Copyright © 2011-2018 Natalia Portillo -// ****************************************************************************/ - -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Extents -{ - /// - /// Implements extents for - /// - public class ExtentsShort - { - List> backend; - - /// - /// Initialize an empty list of extents - /// - public ExtentsShort() - { - backend = new List>(); - } - - /// - /// Initializes extents with an specific list - /// - /// List of extents as tuples "start, end" - public ExtentsShort(IEnumerable> list) - { - backend = list.OrderBy(t => t.Item1).ToList(); - } - - /// - /// Gets a count of how many extents are stored - /// - public int Count => backend.Count; - - /// - /// Adds the specified number to the corresponding extent, or creates a new one - /// - /// - public void Add(short item) - { - Tuple removeOne = null; - Tuple removeTwo = null; - Tuple itemToAdd = null; - - for(int i = 0; i < backend.Count; i++) - { - // Already contained in an extent - if(item >= backend[i].Item1 && item <= backend[i].Item2) return; - - // Expands existing extent start - if(item == backend[i].Item1 - 1) - { - removeOne = backend[i]; - - if(i > 0 && item == backend[i - 1].Item2 + 1) - { - removeTwo = backend[i - 1]; - itemToAdd = new Tuple(backend[i - 1].Item1, backend[i].Item2); - } - else itemToAdd = new Tuple(item, backend[i].Item2); - - break; - } - - // Expands existing extent end - if(item != backend[i].Item2 + 1) continue; - - removeOne = backend[i]; - - if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) - { - removeTwo = backend[i + 1]; - itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); - } - else itemToAdd = new Tuple(backend[i].Item1, item); - - break; - } - - if(itemToAdd != null) - { - backend.Remove(removeOne); - backend.Remove(removeTwo); - backend.Add(itemToAdd); - } - else backend.Add(new Tuple(item, item)); - - // Sort - backend = backend.OrderBy(t => t.Item1).ToList(); - } - - /// - /// Adds a new extent - /// - /// First element of the extent - /// - /// Last element of the extent or if is true how many elements the extent runs - /// for - /// - /// If set to true, indicates how many elements the extent runs for - public void Add(short start, short end, bool run = false) - { - short realEnd; - if(run) realEnd = (short)(start + end - 1); - else realEnd = end; - - // TODO: Optimize this - for(short t = start; t <= realEnd; t++) Add(t); - } - - /// - /// Checks if the specified item is contained by an extent on this instance - /// - /// Item to seach for - /// true if any of the extents on this instance contains the item - public bool Contains(short item) - { - return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2); - } - - /// - /// Removes all extents from this instance - /// - public void Clear() - { - backend.Clear(); - } - - /// - /// Removes an item from the extents in this instance - /// - /// Item to remove - /// true if the item was contained in a known extent and removed, false otherwise - public bool Remove(short item) - { - Tuple toRemove = null; - Tuple toAddOne = null; - Tuple toAddTwo = null; - - foreach(Tuple extent in backend) - { - // Extent is contained and not a border - if(item > extent.Item1 && item < extent.Item2) - { - toRemove = extent; - toAddOne = new Tuple(extent.Item1, (short)(item - 1)); - toAddTwo = new Tuple((short)(item + 1), extent.Item2); - break; - } - - // Extent is left border, but not only element - if(item == extent.Item1 && item != extent.Item2) - { - toRemove = extent; - toAddOne = new Tuple((short)(item + 1), extent.Item2); - break; - } - - // Extent is right border, but not only element - if(item != extent.Item1 && item == extent.Item2) - { - toRemove = extent; - toAddOne = new Tuple(extent.Item1, (short)(item - 1)); - break; - } - - // Extent is only element - if(item != extent.Item1 || item != extent.Item2) continue; - - toRemove = extent; - break; - } - - // Item not found - if(toRemove == null) return false; - - backend.Remove(toRemove); - if(toAddOne != null) backend.Add(toAddOne); - if(toAddTwo != null) backend.Add(toAddTwo); - - // Sort - backend = backend.OrderBy(t => t.Item1).ToList(); - - return true; - } - - /// - /// Converts the list of extents to an array of where T1 is first element of the extent and T2 is - /// last element - /// - /// Array of - public Tuple[] ToArray() - { - return backend.ToArray(); - } - - /// - /// Gets the first element of the extent that contains the specified item - /// - /// Item - /// First element of extent - /// true if item was found in an extent, false otherwise - public bool GetStart(short item, out short start) - { - start = 0; - foreach(Tuple extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) - { - start = extent.Item1; - return true; - } - - return false; - } - } -} \ No newline at end of file diff --git a/Extents/ExtentsUInt.cs b/Extents/ExtentsUInt.cs deleted file mode 100644 index 6a917d69d..000000000 --- a/Extents/ExtentsUInt.cs +++ /dev/null @@ -1,248 +0,0 @@ -// /*************************************************************************** -// The Disc Image Chef -// ---------------------------------------------------------------------------- -// -// Filename : ExtentsUInt.cs -// Author(s) : Natalia Portillo -// -// Component : Extent helpers. -// -// --[ Description ] ---------------------------------------------------------- -// -// Provides extents for uint types. -// -// --[ License ] -------------------------------------------------------------- -// -// This library is free software; you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 2.1 of the -// License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License auint with this library; if not, see . -// -// ---------------------------------------------------------------------------- -// Copyright © 2011-2018 Natalia Portillo -// ****************************************************************************/ - -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Extents -{ - /// - /// Implements extents for - /// - public class ExtentsUInt - { - List> backend; - - /// - /// Initialize an empty list of extents - /// - public ExtentsUInt() - { - backend = new List>(); - } - - /// - /// Initializes extents with an specific list - /// - /// List of extents as tuples "start, end" - public ExtentsUInt(IEnumerable> list) - { - backend = list.OrderBy(t => t.Item1).ToList(); - } - - /// - /// Gets a count of how many extents are stored - /// - public int Count => backend.Count; - - /// - /// Adds the specified number to the corresponding extent, or creates a new one - /// - /// - public void Add(uint item) - { - Tuple removeOne = null; - Tuple removeTwo = null; - Tuple itemToAdd = null; - - for(int i = 0; i < backend.Count; i++) - { - // Already contained in an extent - if(item >= backend[i].Item1 && item <= backend[i].Item2) return; - - // Expands existing extent start - if(item == backend[i].Item1 - 1) - { - removeOne = backend[i]; - - if(i > 0 && item == backend[i - 1].Item2 + 1) - { - removeTwo = backend[i - 1]; - itemToAdd = new Tuple(backend[i - 1].Item1, backend[i].Item2); - } - else itemToAdd = new Tuple(item, backend[i].Item2); - - break; - } - - // Expands existing extent end - if(item != backend[i].Item2 + 1) continue; - - removeOne = backend[i]; - - if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) - { - removeTwo = backend[i + 1]; - itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); - } - else itemToAdd = new Tuple(backend[i].Item1, item); - - break; - } - - if(itemToAdd != null) - { - backend.Remove(removeOne); - backend.Remove(removeTwo); - backend.Add(itemToAdd); - } - else backend.Add(new Tuple(item, item)); - - // Sort - backend = backend.OrderBy(t => t.Item1).ToList(); - } - - /// - /// Adds a new extent - /// - /// First element of the extent - /// - /// Last element of the extent or if is true how many elements the extent runs - /// for - /// - /// If set to true, indicates how many elements the extent runs for - public void Add(uint start, uint end, bool run = false) - { - uint realEnd; - if(run) realEnd = start + end - 1; - else realEnd = end; - - // TODO: Optimize this - for(uint t = start; t <= realEnd; t++) Add(t); - } - - /// - /// Checks if the specified item is contained by an extent on this instance - /// - /// Item to seach for - /// true if any of the extents on this instance contains the item - public bool Contains(uint item) - { - return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2); - } - - /// - /// Removes all extents from this instance - /// - public void Clear() - { - backend.Clear(); - } - - /// - /// Removes an item from the extents in this instance - /// - /// Item to remove - /// true if the item was contained in a known extent and removed, false otherwise - public bool Remove(uint item) - { - Tuple toRemove = null; - Tuple toAddOne = null; - Tuple toAddTwo = null; - - foreach(Tuple extent in backend) - { - // Extent is contained and not a border - if(item > extent.Item1 && item < extent.Item2) - { - toRemove = extent; - toAddOne = new Tuple(extent.Item1, item - 1); - toAddTwo = new Tuple(item + 1, extent.Item2); - break; - } - - // Extent is left border, but not only element - if(item == extent.Item1 && item != extent.Item2) - { - toRemove = extent; - toAddOne = new Tuple(item + 1, extent.Item2); - break; - } - - // Extent is right border, but not only element - if(item != extent.Item1 && item == extent.Item2) - { - toRemove = extent; - toAddOne = new Tuple(extent.Item1, item - 1); - break; - } - - // Extent is only element - if(item != extent.Item1 || item != extent.Item2) continue; - - toRemove = extent; - break; - } - - // Item not found - if(toRemove == null) return false; - - backend.Remove(toRemove); - if(toAddOne != null) backend.Add(toAddOne); - if(toAddTwo != null) backend.Add(toAddTwo); - - // Sort - backend = backend.OrderBy(t => t.Item1).ToList(); - - return true; - } - - /// - /// Converts the list of extents to an array of where T1 is first element of the extent and T2 is - /// last element - /// - /// Array of - public Tuple[] ToArray() - { - return backend.ToArray(); - } - - /// - /// Gets the first element of the extent that contains the specified item - /// - /// Item - /// First element of extent - /// true if item was found in an extent, false otherwise - public bool GetStart(uint item, out uint start) - { - start = 0; - foreach(Tuple extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) - { - start = extent.Item1; - return true; - } - - return false; - } - } -} \ No newline at end of file diff --git a/Extents/ExtentsULong.cs b/Extents/ExtentsULong.cs deleted file mode 100644 index 09c76e8c8..000000000 --- a/Extents/ExtentsULong.cs +++ /dev/null @@ -1,248 +0,0 @@ -// /*************************************************************************** -// The Disc Image Chef -// ---------------------------------------------------------------------------- -// -// Filename : ExtentsULong.cs -// Author(s) : Natalia Portillo -// -// Component : Extent helpers. -// -// --[ Description ] ---------------------------------------------------------- -// -// Provides extents for ulong types. -// -// --[ License ] -------------------------------------------------------------- -// -// This library is free software; you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 2.1 of the -// License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License aulong with this library; if not, see . -// -// ---------------------------------------------------------------------------- -// Copyright © 2011-2018 Natalia Portillo -// ****************************************************************************/ - -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Extents -{ - /// - /// Implements extents for - /// - public class ExtentsULong - { - List> backend; - - /// - /// Initialize an empty list of extents - /// - public ExtentsULong() - { - backend = new List>(); - } - - /// - /// Initializes extents with an specific list - /// - /// List of extents as tuples "start, end" - public ExtentsULong(IEnumerable> list) - { - backend = list.OrderBy(t => t.Item1).ToList(); - } - - /// - /// Gets a count of how many extents are stored - /// - public int Count => backend.Count; - - /// - /// Adds the specified number to the corresponding extent, or creates a new one - /// - /// - public void Add(ulong item) - { - Tuple removeOne = null; - Tuple removeTwo = null; - Tuple itemToAdd = null; - - for(int i = 0; i < backend.Count; i++) - { - // Already contained in an extent - if(item >= backend[i].Item1 && item <= backend[i].Item2) return; - - // Expands existing extent start - if(item == backend[i].Item1 - 1) - { - removeOne = backend[i]; - - if(i > 0 && item == backend[i - 1].Item2 + 1) - { - removeTwo = backend[i - 1]; - itemToAdd = new Tuple(backend[i - 1].Item1, backend[i].Item2); - } - else itemToAdd = new Tuple(item, backend[i].Item2); - - break; - } - - // Expands existing extent end - if(item != backend[i].Item2 + 1) continue; - - removeOne = backend[i]; - - if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) - { - removeTwo = backend[i + 1]; - itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); - } - else itemToAdd = new Tuple(backend[i].Item1, item); - - break; - } - - if(itemToAdd != null) - { - backend.Remove(removeOne); - backend.Remove(removeTwo); - backend.Add(itemToAdd); - } - else backend.Add(new Tuple(item, item)); - - // Sort - backend = backend.OrderBy(t => t.Item1).ToList(); - } - - /// - /// Adds a new extent - /// - /// First element of the extent - /// - /// Last element of the extent or if is true how many elements the extent runs - /// for - /// - /// If set to true, indicates how many elements the extent runs for - public void Add(ulong start, ulong end, bool run = false) - { - ulong realEnd; - if(run) realEnd = start + end - 1; - else realEnd = end; - - // TODO: Optimize this - for(ulong t = start; t <= realEnd; t++) Add(t); - } - - /// - /// Checks if the specified item is contained by an extent on this instance - /// - /// Item to seach for - /// true if any of the extents on this instance contains the item - public bool Contains(ulong item) - { - return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2); - } - - /// - /// Removes all extents from this instance - /// - public void Clear() - { - backend.Clear(); - } - - /// - /// Removes an item from the extents in this instance - /// - /// Item to remove - /// true if the item was contained in a known extent and removed, false otherwise - public bool Remove(ulong item) - { - Tuple toRemove = null; - Tuple toAddOne = null; - Tuple toAddTwo = null; - - foreach(Tuple extent in backend) - { - // Extent is contained and not a border - if(item > extent.Item1 && item < extent.Item2) - { - toRemove = extent; - toAddOne = new Tuple(extent.Item1, item - 1); - toAddTwo = new Tuple(item + 1, extent.Item2); - break; - } - - // Extent is left border, but not only element - if(item == extent.Item1 && item != extent.Item2) - { - toRemove = extent; - toAddOne = new Tuple(item + 1, extent.Item2); - break; - } - - // Extent is right border, but not only element - if(item != extent.Item1 && item == extent.Item2) - { - toRemove = extent; - toAddOne = new Tuple(extent.Item1, item - 1); - break; - } - - // Extent is only element - if(item != extent.Item1 || item != extent.Item2) continue; - - toRemove = extent; - break; - } - - // Item not found - if(toRemove == null) return false; - - backend.Remove(toRemove); - if(toAddOne != null) backend.Add(toAddOne); - if(toAddTwo != null) backend.Add(toAddTwo); - - // Sort - backend = backend.OrderBy(t => t.Item1).ToList(); - - return true; - } - - /// - /// Converts the list of extents to an array of where T1 is first element of the extent and T2 is - /// last element - /// - /// Array of - public Tuple[] ToArray() - { - return backend.ToArray(); - } - - /// - /// Gets the first element of the extent that contains the specified item - /// - /// Item - /// First element of extent - /// true if item was found in an extent, false otherwise - public bool GetStart(ulong item, out ulong start) - { - start = 0; - foreach(Tuple extent in backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) - { - start = extent.Item1; - return true; - } - - return false; - } - } -} \ No newline at end of file diff --git a/Extents/ExtentsUShort.cs b/Extents/ExtentsUShort.cs deleted file mode 100644 index 6a8689cf0..000000000 --- a/Extents/ExtentsUShort.cs +++ /dev/null @@ -1,249 +0,0 @@ -// /*************************************************************************** -// The Disc Image Chef -// ---------------------------------------------------------------------------- -// -// Filename : ExtentsUShort.cs -// Author(s) : Natalia Portillo -// -// Component : Extent helpers. -// -// --[ Description ] ---------------------------------------------------------- -// -// Provides extents for ushort types. -// -// --[ License ] -------------------------------------------------------------- -// -// This library is free software; you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 2.1 of the -// License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License aushort with this library; if not, see . -// -// ---------------------------------------------------------------------------- -// Copyright © 2011-2018 Natalia Portillo -// ****************************************************************************/ - -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Extents -{ - /// - /// Implements extents for - /// - public class ExtentsUShort - { - List> backend; - - /// - /// Initialize an empty list of extents - /// - public ExtentsUShort() - { - backend = new List>(); - } - - /// - /// Initializes extents with an specific list - /// - /// List of extents as tuples "start, end" - public ExtentsUShort(IEnumerable> list) - { - backend = list.OrderBy(t => t.Item1).ToList(); - } - - /// - /// Gets a count of how many extents are stored - /// - public int Count => backend.Count; - - /// - /// Adds the specified number to the corresponding extent, or creates a new one - /// - /// - public void Add(ushort item) - { - Tuple removeOne = null; - Tuple removeTwo = null; - Tuple itemToAdd = null; - - for(int i = 0; i < backend.Count; i++) - { - // Already contained in an extent - if(item >= backend[i].Item1 && item <= backend[i].Item2) return; - - // Expands existing extent start - if(item == backend[i].Item1 - 1) - { - removeOne = backend[i]; - - if(i > 0 && item == backend[i - 1].Item2 + 1) - { - removeTwo = backend[i - 1]; - itemToAdd = new Tuple(backend[i - 1].Item1, backend[i].Item2); - } - else itemToAdd = new Tuple(item, backend[i].Item2); - - break; - } - - // Expands existing extent end - if(item != backend[i].Item2 + 1) continue; - - removeOne = backend[i]; - - if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) - { - removeTwo = backend[i + 1]; - itemToAdd = new Tuple(backend[i].Item1, backend[i + 1].Item2); - } - else itemToAdd = new Tuple(backend[i].Item1, item); - - break; - } - - if(itemToAdd != null) - { - backend.Remove(removeOne); - backend.Remove(removeTwo); - backend.Add(itemToAdd); - } - else backend.Add(new Tuple(item, item)); - - // Sort - backend = backend.OrderBy(t => t.Item1).ToList(); - } - - /// - /// Adds a new extent - /// - /// First element of the extent - /// - /// Last element of the extent or if is true how many elements the extent runs - /// for - /// - /// If set to true, indicates how many elements the extent runs for - public void Add(ushort start, ushort end, bool run = false) - { - ushort realEnd; - if(run) realEnd = (ushort)(start + end - 1); - else realEnd = end; - - // TODO: Optimize this - for(ushort t = start; t <= realEnd; t++) Add(t); - } - - /// - /// Checks if the specified item is contained by an extent on this instance - /// - /// Item to seach for - /// true if any of the extents on this instance contains the item - public bool Contains(ushort item) - { - return backend.Any(extent => item >= extent.Item1 && item <= extent.Item2); - } - - /// - /// Removes all extents from this instance - /// - public void Clear() - { - backend.Clear(); - } - - /// - /// Removes an item from the extents in this instance - /// - /// Item to remove - /// true if the item was contained in a known extent and removed, false otherwise - public bool Remove(ushort item) - { - Tuple toRemove = null; - Tuple toAddOne = null; - Tuple toAddTwo = null; - - foreach(Tuple extent in backend) - { - // Extent is contained and not a border - if(item > extent.Item1 && item < extent.Item2) - { - toRemove = extent; - toAddOne = new Tuple(extent.Item1, (ushort)(item - 1)); - toAddTwo = new Tuple((ushort)(item + 1), extent.Item2); - break; - } - - // Extent is left border, but not only element - if(item == extent.Item1 && item != extent.Item2) - { - toRemove = extent; - toAddOne = new Tuple((ushort)(item + 1), extent.Item2); - break; - } - - // Extent is right border, but not only element - if(item != extent.Item1 && item == extent.Item2) - { - toRemove = extent; - toAddOne = new Tuple(extent.Item1, (ushort)(item - 1)); - break; - } - - // Extent is only element - if(item != extent.Item1 || item != extent.Item2) continue; - - toRemove = extent; - break; - } - - // Item not found - if(toRemove == null) return false; - - backend.Remove(toRemove); - if(toAddOne != null) backend.Add(toAddOne); - if(toAddTwo != null) backend.Add(toAddTwo); - - // Sort - backend = backend.OrderBy(t => t.Item1).ToList(); - - return true; - } - - /// - /// Converts the list of extents to an array of where T1 is first element of the extent and T2 is - /// last element - /// - /// Array of - public Tuple[] ToArray() - { - return backend.ToArray(); - } - - /// - /// Gets the first element of the extent that contains the specified item - /// - /// Item - /// First element of extent - /// true if item was found in an extent, false otherwise - public bool GetStart(ushort item, out ushort start) - { - start = 0; - foreach(Tuple extent in - backend.Where(extent => item >= extent.Item1 && item <= extent.Item2)) - { - start = extent.Item1; - return true; - } - - return false; - } - } -} \ No newline at end of file From 6bf3f9557e9fd48de0dd9b51d67effa414c5a200 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 19 Jul 2018 23:15:51 +0100 Subject: [PATCH 087/217] Bump version to 4.5.1.1692. --- DiscImageChef.Helpers.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index ca33b5231..07d0ea1ff 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -12,7 +12,7 @@ false net461 true - 4.5.0.1663 + 4.5.1.1692 Claunia.com Copyright © 2011-2018 Natalia Portillo The Disc Image Chef From b160dc70bfb27e3cce52dae2bfced81da54b4e43 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 27 Aug 2018 22:03:20 +0100 Subject: [PATCH 088/217] Move libraries to .NET Standard, allowing Xamarin.macOS GUI to compile. --- DiscImageChef.Helpers.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index 5bf150a71..e4ad1d465 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -10,7 +10,6 @@ DiscImageChef.Helpers $(Version) false - net461 true 4.5.99.1693 Claunia.com @@ -18,6 +17,7 @@ The Disc Image Chef DiscImageChef.Helpers $(Version) + net461;netstandard2.0 $(Version)-{chash:8} built by {mname} in $(Configuration){!:, modified} From caab5d65401425119607d0dc67d18166e1cb2fc1 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 20 Dec 2018 21:02:05 +0000 Subject: [PATCH 089/217] Update dependency to Unclassified.NetRevisionTask --- DiscImageChef.Helpers.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index e4ad1d465..063345ef2 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -70,7 +70,7 @@ - + From 23e6efc863c32613a7a84af09f30a6d1aa2c66a8 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sat, 29 Dec 2018 17:34:38 +0000 Subject: [PATCH 090/217] Update copyright year. --- ArrayFill.cs | 2 +- ArrayIsEmpty.cs | 2 +- BigEndianBitConverter.cs | 2 +- BigEndianMarshal.cs | 2 +- CHS.cs | 2 +- CompareBytes.cs | 2 +- CountBits.cs | 2 +- DateHandlers.cs | 2 +- DiscImageChef.Helpers.csproj | 2 +- PrintHex.cs | 2 +- StringHandlers.cs | 2 +- Swapping.cs | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/ArrayFill.cs b/ArrayFill.cs index 122bccda0..af29d5b82 100644 --- a/ArrayFill.cs +++ b/ArrayFill.cs @@ -20,7 +20,7 @@ // Assuming open source. // // ---------------------------------------------------------------------------- -// Copyright © 2011-2018 Natalia Portillo +// Copyright © 2011-2019 Natalia Portillo // Copyright(C) 2014 mykohsu // ****************************************************************************/ diff --git a/ArrayIsEmpty.cs b/ArrayIsEmpty.cs index e22da3767..51ffd7a06 100644 --- a/ArrayIsEmpty.cs +++ b/ArrayIsEmpty.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2018 Natalia Portillo +// Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ using System.Linq; diff --git a/BigEndianBitConverter.cs b/BigEndianBitConverter.cs index 33e2e713c..3e1f3fb84 100644 --- a/BigEndianBitConverter.cs +++ b/BigEndianBitConverter.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2018 Natalia Portillo +// Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ using System; diff --git a/BigEndianMarshal.cs b/BigEndianMarshal.cs index 8dbc654ff..15cdb208e 100644 --- a/BigEndianMarshal.cs +++ b/BigEndianMarshal.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2018 Natalia Portillo +// Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ using System; diff --git a/CHS.cs b/CHS.cs index 5f7aca7ac..ae4c0fa5d 100644 --- a/CHS.cs +++ b/CHS.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2018 Natalia Portillo +// Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ namespace DiscImageChef.Helpers diff --git a/CompareBytes.cs b/CompareBytes.cs index e5953b81e..8101b2a48 100644 --- a/CompareBytes.cs +++ b/CompareBytes.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2018 Natalia Portillo +// Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ namespace DiscImageChef diff --git a/CountBits.cs b/CountBits.cs index e2aae95de..f7fe42eed 100644 --- a/CountBits.cs +++ b/CountBits.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2018 Natalia Portillo +// Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ namespace DiscImageChef.Helpers diff --git a/DateHandlers.cs b/DateHandlers.cs index 4d3345432..8cc4d71a9 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2018 Natalia Portillo +// Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ using System; diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index 063345ef2..789bb5bf5 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -13,7 +13,7 @@ true 4.5.99.1693 Claunia.com - Copyright © 2011-2018 Natalia Portillo + Copyright © 2011-2019 Natalia Portillo The Disc Image Chef DiscImageChef.Helpers $(Version) diff --git a/PrintHex.cs b/PrintHex.cs index 551beefaa..3256a1978 100644 --- a/PrintHex.cs +++ b/PrintHex.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2018 Natalia Portillo +// Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ using System.Text; diff --git a/StringHandlers.cs b/StringHandlers.cs index ad2fb0cb5..805238270 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2018 Natalia Portillo +// Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ using System; diff --git a/Swapping.cs b/Swapping.cs index cf52121eb..db5dbf634 100644 --- a/Swapping.cs +++ b/Swapping.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2018 Natalia Portillo +// Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ using System; From 38c8e0672d2a14dfd3277081b4334dcbf22eaf93 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 31 Dec 2018 13:17:27 +0000 Subject: [PATCH 091/217] General code refactor and reformat. --- BigEndianBitConverter.cs | 197 ++++++++++++++------------------------- CHS.cs | 10 +- DateHandlers.cs | 41 ++------ StringHandlers.cs | 16 +--- Swapping.cs | 25 +---- 5 files changed, 91 insertions(+), 198 deletions(-) diff --git a/BigEndianBitConverter.cs b/BigEndianBitConverter.cs index 3e1f3fb84..b68c19a74 100644 --- a/BigEndianBitConverter.cs +++ b/BigEndianBitConverter.cs @@ -55,120 +55,94 @@ public static class BigEndianBitConverter /// The number to convert. /// A 64-bit signed integer whose value is equivalent to value. /// It is not currently implemented - public static long DoubleToInt64Bits(double value) - { - throw new NotImplementedException(); - } + public static long DoubleToInt64Bits(double value) => throw new NotImplementedException(); /// /// Returns the specified Boolean value as an array of bytes. /// /// A Boolean value. /// An array of bytes with length 1. - public static byte[] GetBytes(bool value) - { - return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); - } + public static byte[] GetBytes(bool value) => + !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); /// /// Returns the specified Unicode character value as an array of bytes. /// /// A character to convert. /// An array of bytes with length 2. - public static byte[] GetBytes(char value) - { - return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); - } + public static byte[] GetBytes(char value) => + !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); /// /// Returns the specified double-precision floating point value as an array of bytes. /// /// The number to convert. /// An array of bytes with length 8. - public static byte[] GetBytes(double value) - { - return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); - } + public static byte[] GetBytes(double value) => + !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); /// /// Returns the specified single-precision floating point value as an array of bytes. /// /// The number to convert. /// An array of bytes with length 4. - public static byte[] GetBytes(float value) - { - return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); - } + public static byte[] GetBytes(float value) => + !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); /// /// Returns the specified 32-bit signed integer value as an array of bytes. /// /// The number to convert. /// An array of bytes with length 4. - public static byte[] GetBytes(int value) - { - return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); - } + public static byte[] GetBytes(int value) => + !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); /// /// Returns the specified 64-bit signed integer value as an array of bytes. /// /// The number to convert. /// An array of bytes with length 8. - public static byte[] GetBytes(long value) - { - return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); - } + public static byte[] GetBytes(long value) => + !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); /// /// Returns the specified 16-bit signed integer value as an array of bytes. /// /// The number to convert. /// An array of bytes with length 2. - public static byte[] GetBytes(short value) - { - return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); - } + public static byte[] GetBytes(short value) => + !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); /// /// Returns the specified 32-bit unsigned integer value as an array of bytes. /// /// The number to convert. /// An array of bytes with length 4. - public static byte[] GetBytes(uint value) - { - return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); - } + public static byte[] GetBytes(uint value) => + !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); /// /// Returns the specified 64-bit unsigned integer value as an array of bytes. /// /// The number to convert. /// An array of bytes with length 8. - public static byte[] GetBytes(ulong value) - { - return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); - } + public static byte[] GetBytes(ulong value) => + !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); /// /// Returns the specified 16-bit unsigned integer value as an array of bytes. /// /// The number to convert. /// An array of bytes with length 2. - public static byte[] GetBytes(ushort value) - { - return !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); - } + public static byte[] GetBytes(ushort value) => + !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); /// /// Converts the specified 64-bit signed integer to a double-precision floating point number. /// /// The number to convert. /// A double-precision floating point number whose value is equivalent to value. - public static double Int64BitsToDouble(long value) - { - throw new NotImplementedException(); - } + public static double Int64BitsToDouble(long value) => throw new NotImplementedException(); /// /// Returns a Boolean value converted from one byte at a specified position in a byte array. @@ -181,10 +155,7 @@ public static double Int64BitsToDouble(long value) /// is less than zero or greater than the /// length of value minus 1. /// - public static bool ToBoolean(byte[] value, int startIndex) - { - throw new NotImplementedException(); - } + public static bool ToBoolean(byte[] value, int startIndex) => throw new NotImplementedException(); /// /// Returns a Unicode character converted from two bytes at a specified position in a byte array. @@ -198,10 +169,7 @@ public static bool ToBoolean(byte[] value, int startIndex) /// is less than zero or greater than the /// length of value minus 1. /// - public static char ToChar(byte[] value, int startIndex) - { - throw new NotImplementedException(); - } + public static char ToChar(byte[] value, int startIndex) => throw new NotImplementedException(); /// /// Returns a double-precision floating point number converted from eight bytes at a specified position in a byte @@ -219,10 +187,7 @@ public static char ToChar(byte[] value, int startIndex) /// is less than zero or greater than the /// length of value minus 1. /// - public static double ToDouble(byte[] value, int startIndex) - { - throw new NotImplementedException(); - } + public static double ToDouble(byte[] value, int startIndex) => throw new NotImplementedException(); /// /// Returns a 16-bit signed integer converted from two bytes at a specified position in a byte array. @@ -236,12 +201,10 @@ public static double ToDouble(byte[] value, int startIndex) /// startIndex is less than zero or greater than the length of value /// minus 1. /// - public static short ToInt16(byte[] value, int startIndex) - { - return !IsLittleEndian - ? BitConverter.ToInt16(value, startIndex) - : BitConverter.ToInt16(value.Reverse().ToArray(), value.Length - sizeof(short) - startIndex); - } + public static short ToInt16(byte[] value, int startIndex) => + !IsLittleEndian + ? BitConverter.ToInt16(value, startIndex) + : BitConverter.ToInt16(value.Reverse().ToArray(), value.Length - sizeof(short) - startIndex); /// /// Returns a 32-bit signed integer converted from four bytes at a specified position in a byte array. @@ -258,12 +221,10 @@ public static short ToInt16(byte[] value, int startIndex) /// startIndex is less than zero or greater than the length of value /// minus 1. /// - public static int ToInt32(byte[] value, int startIndex) - { - return !IsLittleEndian - ? BitConverter.ToInt32(value, startIndex) - : BitConverter.ToInt32(value.Reverse().ToArray(), value.Length - sizeof(int) - startIndex); - } + public static int ToInt32(byte[] value, int startIndex) => + !IsLittleEndian + ? BitConverter.ToInt32(value, startIndex) + : BitConverter.ToInt32(value.Reverse().ToArray(), value.Length - sizeof(int) - startIndex); /// /// Returns a 64-bit signed integer converted from eight bytes at a specified position in a byte array. @@ -280,12 +241,10 @@ public static int ToInt32(byte[] value, int startIndex) /// is less than zero or greater than the /// length of value minus 1. /// - public static long ToInt64(byte[] value, int startIndex) - { - return !IsLittleEndian - ? BitConverter.ToInt64(value, startIndex) - : BitConverter.ToInt64(value.Reverse().ToArray(), value.Length - sizeof(long) - startIndex); - } + public static long ToInt64(byte[] value, int startIndex) => + !IsLittleEndian + ? BitConverter.ToInt64(value, startIndex) + : BitConverter.ToInt64(value.Reverse().ToArray(), value.Length - sizeof(long) - startIndex); /// /// Returns a single-precision floating point number converted from four bytes at a specified position in a byte @@ -303,12 +262,10 @@ public static long ToInt64(byte[] value, int startIndex) /// is less than zero or greater than the /// length of value minus 1. /// - public static float ToSingle(byte[] value, int startIndex) - { - return !IsLittleEndian - ? BitConverter.ToSingle(value, startIndex) - : BitConverter.ToSingle(value.Reverse().ToArray(), value.Length - sizeof(float) - startIndex); - } + public static float ToSingle(byte[] value, int startIndex) => + !IsLittleEndian + ? BitConverter.ToSingle(value, startIndex) + : BitConverter.ToSingle(value.Reverse().ToArray(), value.Length - sizeof(float) - startIndex); /// /// Converts the numeric value of each element of a specified array of bytes to its equivalent hexadecimal string @@ -320,10 +277,8 @@ public static float ToSingle(byte[] value, int startIndex) /// element in value; for example, "7F-2C-4A". /// /// value is null. - public static string ToString(byte[] value) - { - return !IsLittleEndian ? BitConverter.ToString(value) : BitConverter.ToString(value.Reverse().ToArray()); - } + public static string ToString(byte[] value) => + !IsLittleEndian ? BitConverter.ToString(value) : BitConverter.ToString(value.Reverse().ToArray()); /// /// Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal string @@ -340,12 +295,10 @@ public static string ToString(byte[] value) /// startIndex is less than zero or greater than the length of value /// minus 1. /// - public static string ToString(byte[] value, int startIndex) - { - return !IsLittleEndian - ? BitConverter.ToString(value, startIndex) - : BitConverter.ToString(value.Reverse().ToArray(), startIndex); - } + public static string ToString(byte[] value, int startIndex) => + !IsLittleEndian + ? BitConverter.ToString(value, startIndex) + : BitConverter.ToString(value.Reverse().ToArray(), startIndex); /// /// Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal string @@ -367,12 +320,10 @@ public static string ToString(byte[] value, int startIndex) /// 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. /// - public static string ToString(byte[] value, int startIndex, int length) - { - return !IsLittleEndian - ? BitConverter.ToString(value, startIndex, length) - : BitConverter.ToString(value.Reverse().ToArray(), startIndex, length); - } + public static string ToString(byte[] value, int startIndex, int length) => + !IsLittleEndian + ? BitConverter.ToString(value, startIndex, length) + : BitConverter.ToString(value.Reverse().ToArray(), startIndex, length); /// /// Returns a 16-bit unsigned integer converted from two bytes at a specified position in a byte array. @@ -386,12 +337,10 @@ public static string ToString(byte[] value, int startIndex, int length) /// startIndex is less than zero or greater than the length of value /// minus 1. /// - public static ushort ToUInt16(byte[] value, int startIndex) - { - return !IsLittleEndian - ? BitConverter.ToUInt16(value, startIndex) - : BitConverter.ToUInt16(value.Reverse().ToArray(), value.Length - sizeof(ushort) - startIndex); - } + public static ushort ToUInt16(byte[] value, int startIndex) => + !IsLittleEndian + ? BitConverter.ToUInt16(value, startIndex) + : BitConverter.ToUInt16(value.Reverse().ToArray(), value.Length - sizeof(ushort) - startIndex); /// /// Returns a 32-bit unsigned integer converted from four bytes at a specified position in a byte array. @@ -408,12 +357,10 @@ public static ushort ToUInt16(byte[] value, int startIndex) /// startIndex is less than zero or greater than the length of value /// minus 1. /// - public static uint ToUInt32(byte[] value, int startIndex) - { - return !IsLittleEndian - ? BitConverter.ToUInt32(value, startIndex) - : BitConverter.ToUInt32(value.Reverse().ToArray(), value.Length - sizeof(uint) - startIndex); - } + public static uint ToUInt32(byte[] value, int startIndex) => + !IsLittleEndian + ? BitConverter.ToUInt32(value, startIndex) + : BitConverter.ToUInt32(value.Reverse().ToArray(), value.Length - sizeof(uint) - startIndex); /// /// Returns a 64-bit unsigned integer converted from eight bytes at a specified position in a byte array. @@ -430,22 +377,16 @@ public static uint ToUInt32(byte[] value, int startIndex) /// startIndex is less than zero or greater than the length of value /// minus 1. /// - public static ulong ToUInt64(byte[] value, int startIndex) - { - return !IsLittleEndian - ? BitConverter.ToUInt64(value, startIndex) - : BitConverter.ToUInt64(value.Reverse().ToArray(), value.Length - sizeof(ulong) - startIndex); - } + public static ulong ToUInt64(byte[] value, int startIndex) => + !IsLittleEndian + ? 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]); - } + public static Guid ToGuid(byte[] value, int startIndex) => + 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]); } } \ No newline at end of file diff --git a/CHS.cs b/CHS.cs index ae4c0fa5d..7d933bd3b 100644 --- a/CHS.cs +++ b/CHS.cs @@ -43,11 +43,9 @@ public static class CHS /// Number of heads /// Number of sectors per track /// - 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 * maxHead + head) * maxSector + sector - 1; - } + public static uint ToLBA(uint cyl, uint head, uint sector, uint maxHead, uint maxSector) => + maxHead == 0 || maxSector == 0 + ? (cyl * 16 + head) * 63 + sector - 1 + : (cyl * maxHead + head) * maxSector + sector - 1; } } \ No newline at end of file diff --git a/DateHandlers.cs b/DateHandlers.cs index 8cc4d71a9..5ee2db94f 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -52,50 +52,35 @@ public static class DateHandlers /// /// Macintosh timestamp (seconds since 1st Jan. 1904) /// .NET DateTime - public static DateTime MacToDateTime(ulong macTimeStamp) - { - return MacEpoch.AddTicks((long)(macTimeStamp * 10000000)); - } + public static DateTime MacToDateTime(ulong macTimeStamp) => MacEpoch.AddTicks((long)(macTimeStamp * 10000000)); /// /// Converts a Lisa timestamp to a .NET DateTime /// /// Lisa timestamp (seconds since 1st Jan. 1901) /// .NET DateTime - public static DateTime LisaToDateTime(uint lisaTimeStamp) - { - return LisaEpoch.AddSeconds(lisaTimeStamp); - } + public static DateTime LisaToDateTime(uint lisaTimeStamp) => LisaEpoch.AddSeconds(lisaTimeStamp); /// /// Converts a UNIX timestamp to a .NET DateTime /// /// UNIX timestamp (seconds since 1st Jan. 1970) /// .NET DateTime - public static DateTime UnixToDateTime(int unixTimeStamp) - { - return UnixEpoch.AddSeconds(unixTimeStamp); - } + public static DateTime UnixToDateTime(int unixTimeStamp) => UnixEpoch.AddSeconds(unixTimeStamp); /// /// Converts a UNIX timestamp to a .NET DateTime /// /// UNIX timestamp (seconds since 1st Jan. 1970) /// .NET DateTime - public static DateTime UnixToDateTime(long unixTimeStamp) - { - return UnixEpoch.AddSeconds(unixTimeStamp); - } + public static DateTime UnixToDateTime(long unixTimeStamp) => UnixEpoch.AddSeconds(unixTimeStamp); /// /// Converts a UNIX timestamp to a .NET DateTime /// /// UNIX timestamp (seconds since 1st Jan. 1970) /// .NET DateTime - public static DateTime UnixUnsignedToDateTime(uint unixTimeStamp) - { - return UnixEpoch.AddSeconds(unixTimeStamp); - } + public static DateTime UnixUnsignedToDateTime(uint unixTimeStamp) => UnixEpoch.AddSeconds(unixTimeStamp); /// /// Converts a UNIX timestamp to a .NET DateTime @@ -103,20 +88,15 @@ public static DateTime UnixUnsignedToDateTime(uint unixTimeStamp) /// Seconds since 1st Jan. 1970) /// Nanoseconds /// .NET DateTime - public static DateTime UnixUnsignedToDateTime(uint seconds, uint nanoseconds) - { - return UnixEpoch.AddSeconds(seconds).AddTicks((long)nanoseconds / 100); - } + public static DateTime UnixUnsignedToDateTime(uint seconds, uint nanoseconds) => + UnixEpoch.AddSeconds(seconds).AddTicks((long)nanoseconds / 100); /// /// Converts a UNIX timestamp to a .NET DateTime /// /// UNIX timestamp (seconds since 1st Jan. 1970) /// .NET DateTime - public static DateTime UnixUnsignedToDateTime(ulong unixTimeStamp) - { - return UnixEpoch.AddSeconds(unixTimeStamp); - } + public static DateTime UnixUnsignedToDateTime(ulong unixTimeStamp) => UnixEpoch.AddSeconds(unixTimeStamp); /// /// Converts a High Sierra Format timestamp to a .NET DateTime @@ -330,10 +310,7 @@ public static DateTime EcmaToDateTime(ushort typeAndTimeZone, short year, byte m /// /// Solaris high resolution timestamp /// .NET DateTime - public static DateTime UnixHrTimeToDateTime(ulong hrTimeStamp) - { - return UnixEpoch.AddTicks((long)(hrTimeStamp / 100)); - } + public static DateTime UnixHrTimeToDateTime(ulong hrTimeStamp) => UnixEpoch.AddTicks((long)(hrTimeStamp / 100)); /// /// Converts an OS-9 timestamp to .NET DateTime diff --git a/StringHandlers.cs b/StringHandlers.cs index 805238270..67a314a54 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -42,10 +42,7 @@ public static class StringHandlers /// /// The corresponding C# string /// A null-terminated (aka C string) ASCII byte array - public static string CToString(byte[] CString) - { - return CToString(CString, Encoding.ASCII); - } + public static string CToString(byte[] CString) => CToString(CString, Encoding.ASCII); /// /// Converts a null-terminated (aka C string) byte array with the specified encoding to a C# string @@ -92,10 +89,7 @@ public static string CToString(byte[] CString, Encoding encoding, bool twoBytes /// /// The corresponding C# string /// A length-prefixed (aka Pascal string) ASCII byte array - public static string PascalToString(byte[] PascalString) - { - return PascalToString(PascalString, Encoding.ASCII); - } + public static string PascalToString(byte[] PascalString) => PascalToString(PascalString, Encoding.ASCII); /// /// Converts a length-prefixed (aka Pascal string) ASCII byte array to a C# string @@ -129,10 +123,8 @@ public static string PascalToString(byte[] PascalString, Encoding encoding, int /// /// The corresponding C# string /// A space (' ', 0x20, ASCII SPACE) padded ASCII byte array - public static string SpacePaddedToString(byte[] SpacePaddedString) - { - return SpacePaddedToString(SpacePaddedString, Encoding.ASCII); - } + public static string SpacePaddedToString(byte[] SpacePaddedString) => + SpacePaddedToString(SpacePaddedString, Encoding.ASCII); /// /// Converts a space (' ', 0x20, ASCII SPACE) padded ASCII byte array to a C# string diff --git a/Swapping.cs b/Swapping.cs index db5dbf634..b8defbbe8 100644 --- a/Swapping.cs +++ b/Swapping.cs @@ -93,15 +93,9 @@ public static byte[] SwapTwoBytes(byte[] source) return destination; } - public static uint PDPFromLittleEndian(uint x) - { - return ((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16); - } + public static uint PDPFromLittleEndian(uint x) => ((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16); - public static uint PDPFromBigEndian(uint x) - { - return ((x & 0xff00ff) << 8) | ((x & 0xff00ff00) >> 8); - } + public static uint PDPFromBigEndian(uint x) => ((x & 0xff00ff) << 8) | ((x & 0xff00ff00) >> 8); public static ulong Swap(ulong x) { @@ -111,20 +105,11 @@ public static ulong Swap(ulong x) return x; } - public static long Swap(long x) - { - return BitConverter.ToInt64(BitConverter.GetBytes(x).Reverse().ToArray(), 0); - } + public static long Swap(long x) => BitConverter.ToInt64(BitConverter.GetBytes(x).Reverse().ToArray(), 0); - public static ushort Swap(ushort x) - { - return (ushort)((x << 8) | (x >> 8)); - } + public static ushort Swap(ushort x) => (ushort)((x << 8) | (x >> 8)); - public static short Swap(short x) - { - return (short)((x << 8) | ((x >> 8) & 0xFF)); - } + public static short Swap(short x) => (short)((x << 8) | ((x >> 8) & 0xFF)); public static uint Swap(uint x) { From e489740bcbbb3cfea97c34d5f34ebff46de653a6 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 24 Feb 2019 21:59:46 +0000 Subject: [PATCH 092/217] Optimize big endian marshalling. --- BigEndianMarshal.cs | 55 ++++++++++++++---------------- Swapping.cs | 83 ++++++++------------------------------------- 2 files changed, 41 insertions(+), 97 deletions(-) diff --git a/BigEndianMarshal.cs b/BigEndianMarshal.cs index 15cdb208e..a4c5569c7 100644 --- a/BigEndianMarshal.cs +++ b/BigEndianMarshal.cs @@ -31,7 +31,6 @@ // ****************************************************************************/ using System; -using System.Linq; using System.Reflection; using System.Runtime.InteropServices; @@ -67,59 +66,57 @@ public static object SwapStructureMembersEndian(object str) foreach(FieldInfo fi in fieldInfo) if(fi.FieldType == typeof(short)) { - short int16 = (short)fi.GetValue(str); - byte[] int16_b = BitConverter.GetBytes(int16); - byte[] int16_r = int16_b.Reverse().ToArray(); - fi.SetValue(str, BitConverter.ToInt16(int16_r, 0)); + short x = (short)fi.GetValue(str); + fi.SetValue(str, (short)((x << 8) | ((x >> 8) & 0xFF))); } else if(fi.FieldType == typeof(int)) { - int int32 = (int)fi.GetValue(str); - byte[] int32_b = BitConverter.GetBytes(int32); - byte[] int32_r = int32_b.Reverse().ToArray(); - fi.SetValue(str, BitConverter.ToInt32(int32_r, 0)); + int x = (int)fi.GetValue(str); + x = (int)(((x << 8) & 0xFF00FF00) | (((uint)x >> 8) & 0xFF00FF)); + fi.SetValue(str, (int)(((uint)x << 16) | (((uint)x >> 16) & 0xFFFF))); } else if(fi.FieldType == typeof(long)) { - long int64 = (long)fi.GetValue(str); - byte[] int64_b = BitConverter.GetBytes(int64); - byte[] int64_r = int64_b.Reverse().ToArray(); - fi.SetValue(str, BitConverter.ToInt64(int64_r, 0)); + long x = (long)fi.GetValue(str); + x = ((x & 0x00000000FFFFFFFF) << 32) | (long)(((ulong)x & 0xFFFFFFFF00000000) >> 32); + x = ((x & 0x0000FFFF0000FFFF) << 16) | (long)(((ulong)x & 0xFFFF0000FFFF0000) >> 16); + x = ((x & 0x00FF00FF00FF00FF) << 8) | (long)(((ulong)x & 0xFF00FF00FF00FF00) >> 8); + + fi.SetValue(str, x); } else if(fi.FieldType == typeof(ushort)) { - ushort uint16 = (ushort)fi.GetValue(str); - byte[] uint16_b = BitConverter.GetBytes(uint16); - byte[] uint16_r = uint16_b.Reverse().ToArray(); - fi.SetValue(str, BitConverter.ToUInt16(uint16_r, 0)); + ushort x = (ushort)fi.GetValue(str); + fi.SetValue(str, (ushort)((x << 8) | (x >> 8))); } else if(fi.FieldType == typeof(uint)) { - uint uint32 = (uint)fi.GetValue(str); - byte[] uint32_b = BitConverter.GetBytes(uint32); - byte[] uint32_r = uint32_b.Reverse().ToArray(); - fi.SetValue(str, BitConverter.ToUInt32(uint32_r, 0)); + uint x = (uint)fi.GetValue(str); + x = ((x << 8) & 0xFF00FF00) | ((x >> 8) & 0xFF00FF); + fi.SetValue(str, (x << 16) | (x >> 16)); } else if(fi.FieldType == typeof(ulong)) { - ulong uint64 = (ulong)fi.GetValue(str); - byte[] uint64_b = BitConverter.GetBytes(uint64); - byte[] uint64_r = uint64_b.Reverse().ToArray(); - fi.SetValue(str, BitConverter.ToUInt64(uint64_r, 0)); + ulong x = (ulong)fi.GetValue(str); + x = ((x & 0x00000000FFFFFFFF) << 32) | ((x & 0xFFFFFFFF00000000) >> 32); + x = ((x & 0x0000FFFF0000FFFF) << 16) | ((x & 0xFFFF0000FFFF0000) >> 16); + x = ((x & 0x00FF00FF00FF00FF) << 8) | ((x & 0xFF00FF00FF00FF00) >> 8); + fi.SetValue(str, x); } else if(fi.FieldType == typeof(float)) { float flt = (float)fi.GetValue(str); byte[] flt_b = BitConverter.GetBytes(flt); - byte[] flt_r = flt_b.Reverse().ToArray(); - fi.SetValue(str, BitConverter.ToSingle(flt_r, 0)); + fi.SetValue(str, BitConverter.ToSingle(new[] {flt_b[3], flt_b[2], flt_b[1], flt_b[0]}, 0)); } else if(fi.FieldType == typeof(double)) { double dbl = (double)fi.GetValue(str); byte[] dbl_b = BitConverter.GetBytes(dbl); - byte[] dbl_r = dbl_b.Reverse().ToArray(); - fi.SetValue(str, BitConverter.ToDouble(dbl_r, 0)); + fi.SetValue(str, + BitConverter + .ToDouble(new[] {dbl_b[7], dbl_b[6], dbl_b[5], dbl_b[4], dbl_b[3], dbl_b[2], dbl_b[1], dbl_b[0]}, + 0)); } else if(fi.FieldType == typeof(byte) || fi.FieldType == typeof(sbyte)) { diff --git a/Swapping.cs b/Swapping.cs index b8defbbe8..962305042 100644 --- a/Swapping.cs +++ b/Swapping.cs @@ -30,73 +30,30 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ -using System; -using System.Linq; - namespace DiscImageChef { public static class Swapping { - public static byte[] SwapTenBytes(byte[] source) - { - byte[] destination = new byte[8]; - - destination[0] = source[9]; - destination[1] = source[8]; - destination[2] = source[7]; - destination[3] = source[6]; - destination[4] = source[5]; - destination[5] = source[4]; - destination[6] = source[3]; - destination[7] = source[2]; - destination[8] = source[1]; - destination[9] = source[0]; - - return destination; - } + public static uint PDPFromLittleEndian(uint x) => ((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16); - public static byte[] SwapEightBytes(byte[] source) - { - byte[] destination = new byte[8]; + public static uint PDPFromBigEndian(uint x) => ((x & 0xff00ff) << 8) | ((x & 0xff00ff00) >> 8); - destination[0] = source[7]; - destination[1] = source[6]; - destination[2] = source[5]; - destination[3] = source[4]; - destination[4] = source[3]; - destination[5] = source[2]; - destination[6] = source[1]; - destination[7] = source[0]; + public static ushort Swap(ushort x) => (ushort)((x << 8) | (x >> 8)); - return destination; - } + public static short Swap(short x) => (short)((x << 8) | ((x >> 8) & 0xFF)); - public static byte[] SwapFourBytes(byte[] source) + public static uint Swap(uint x) { - byte[] destination = new byte[4]; - - destination[0] = source[3]; - destination[1] = source[2]; - destination[2] = source[1]; - destination[3] = source[0]; - - return destination; + x = ((x << 8) & 0xFF00FF00) | ((x >> 8) & 0xFF00FF); + return (x << 16) | (x >> 16); } - public static byte[] SwapTwoBytes(byte[] source) + public static int Swap(int x) { - byte[] destination = new byte[2]; - - destination[0] = source[1]; - destination[1] = source[0]; - - return destination; + x = (int)(((x << 8) & 0xFF00FF00) | (((uint)x >> 8) & 0xFF00FF)); + return (int)(((uint)x << 16) | (((uint)x >> 16) & 0xFFFF)); } - public static uint PDPFromLittleEndian(uint x) => ((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16); - - public static uint PDPFromBigEndian(uint x) => ((x & 0xff00ff) << 8) | ((x & 0xff00ff00) >> 8); - public static ulong Swap(ulong x) { x = ((x & 0x00000000FFFFFFFF) << 32) | ((x & 0xFFFFFFFF00000000) >> 32); @@ -105,22 +62,12 @@ public static ulong Swap(ulong x) return x; } - public static long Swap(long x) => BitConverter.ToInt64(BitConverter.GetBytes(x).Reverse().ToArray(), 0); - - public static ushort Swap(ushort x) => (ushort)((x << 8) | (x >> 8)); - - public static short Swap(short x) => (short)((x << 8) | ((x >> 8) & 0xFF)); - - public static uint Swap(uint x) - { - x = ((x << 8) & 0xFF00FF00) | ((x >> 8) & 0xFF00FF); - return (x << 16) | (x >> 16); - } - - public static int Swap(int x) + public static long Swap(long x) { - x = (int)(((x << 8) & 0xFF00FF00) | (((uint)x >> 8) & 0xFF00FF)); - return (int)(((uint)x << 16) | (((uint)x >> 16) & 0xFFFF)); + x = ((x & 0x00000000FFFFFFFF) << 32) | (long)(((ulong)x & 0xFFFFFFFF00000000) >> 32); + x = ((x & 0x0000FFFF0000FFFF) << 16) | (long)(((ulong)x & 0xFFFF0000FFFF0000) >> 16); + x = ((x & 0x00FF00FF00FF00FF) << 8) | (long)(((ulong)x & 0xFF00FF00FF00FF00) >> 8); + return x; } } } \ No newline at end of file From adfd41d931b66e2e52c5e59fc33f659787321f88 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 27 Feb 2019 08:49:42 +0000 Subject: [PATCH 093/217] Add more optimized marshallers. --- BigEndianMarshal.cs | 141 --------------- BitEndian.cs | 51 ++++++ DiscImageChef.Helpers.csproj | 5 +- Marshal.cs | 283 ++++++++++++++++++++++++++++++ MarshallingPropertiesAttribute.cs | 64 +++++++ 5 files changed, 402 insertions(+), 142 deletions(-) delete mode 100644 BigEndianMarshal.cs create mode 100644 BitEndian.cs create mode 100644 Marshal.cs create mode 100644 MarshallingPropertiesAttribute.cs diff --git a/BigEndianMarshal.cs b/BigEndianMarshal.cs deleted file mode 100644 index a4c5569c7..000000000 --- a/BigEndianMarshal.cs +++ /dev/null @@ -1,141 +0,0 @@ -// /*************************************************************************** -// The Disc Image Chef -// ---------------------------------------------------------------------------- -// -// Filename : BigEndianMarshal.cs -// Author(s) : Natalia Portillo -// -// Component : Helpers. -// -// --[ Description ] ---------------------------------------------------------- -// -// Provides marshalling for big-endian data. -// -// --[ License ] -------------------------------------------------------------- -// -// This library is free software; you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 2.1 of the -// License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, see . -// -// ---------------------------------------------------------------------------- -// Copyright © 2011-2019 Natalia Portillo -// ****************************************************************************/ - -using System; -using System.Reflection; -using System.Runtime.InteropServices; - -namespace DiscImageChef -{ - public static class BigEndianMarshal - { - /// - /// Marshals a big endian structure from a byte array. - /// Nested structures are still marshalled as little endian. - /// - /// The structure. - /// Byte array. - /// Structure type. - public static T ByteArrayToStructureBigEndian(byte[] bytes) where T : struct - { - GCHandle ptr = GCHandle.Alloc(bytes, GCHandleType.Pinned); - T str = (T)Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(T)); - ptr.Free(); - return (T)SwapStructureMembersEndian(str); - } - - /// - /// Swaps endian of structure members that correspond to numerical types. - /// Does not traverse nested structures. - /// - /// The structure with its members endian swapped. - /// The structure. - public static object SwapStructureMembersEndian(object str) - { - Type t = str.GetType(); - FieldInfo[] fieldInfo = t.GetFields(); - foreach(FieldInfo fi in fieldInfo) - if(fi.FieldType == typeof(short)) - { - short x = (short)fi.GetValue(str); - fi.SetValue(str, (short)((x << 8) | ((x >> 8) & 0xFF))); - } - else if(fi.FieldType == typeof(int)) - { - int x = (int)fi.GetValue(str); - x = (int)(((x << 8) & 0xFF00FF00) | (((uint)x >> 8) & 0xFF00FF)); - fi.SetValue(str, (int)(((uint)x << 16) | (((uint)x >> 16) & 0xFFFF))); - } - else if(fi.FieldType == typeof(long)) - { - long x = (long)fi.GetValue(str); - x = ((x & 0x00000000FFFFFFFF) << 32) | (long)(((ulong)x & 0xFFFFFFFF00000000) >> 32); - x = ((x & 0x0000FFFF0000FFFF) << 16) | (long)(((ulong)x & 0xFFFF0000FFFF0000) >> 16); - x = ((x & 0x00FF00FF00FF00FF) << 8) | (long)(((ulong)x & 0xFF00FF00FF00FF00) >> 8); - - fi.SetValue(str, x); - } - else if(fi.FieldType == typeof(ushort)) - { - ushort x = (ushort)fi.GetValue(str); - fi.SetValue(str, (ushort)((x << 8) | (x >> 8))); - } - else if(fi.FieldType == typeof(uint)) - { - uint x = (uint)fi.GetValue(str); - x = ((x << 8) & 0xFF00FF00) | ((x >> 8) & 0xFF00FF); - fi.SetValue(str, (x << 16) | (x >> 16)); - } - else if(fi.FieldType == typeof(ulong)) - { - ulong x = (ulong)fi.GetValue(str); - x = ((x & 0x00000000FFFFFFFF) << 32) | ((x & 0xFFFFFFFF00000000) >> 32); - x = ((x & 0x0000FFFF0000FFFF) << 16) | ((x & 0xFFFF0000FFFF0000) >> 16); - x = ((x & 0x00FF00FF00FF00FF) << 8) | ((x & 0xFF00FF00FF00FF00) >> 8); - fi.SetValue(str, x); - } - else if(fi.FieldType == typeof(float)) - { - float flt = (float)fi.GetValue(str); - byte[] flt_b = BitConverter.GetBytes(flt); - fi.SetValue(str, BitConverter.ToSingle(new[] {flt_b[3], flt_b[2], flt_b[1], flt_b[0]}, 0)); - } - else if(fi.FieldType == typeof(double)) - { - double dbl = (double)fi.GetValue(str); - byte[] dbl_b = BitConverter.GetBytes(dbl); - fi.SetValue(str, - BitConverter - .ToDouble(new[] {dbl_b[7], dbl_b[6], dbl_b[5], dbl_b[4], dbl_b[3], dbl_b[2], dbl_b[1], dbl_b[0]}, - 0)); - } - else if(fi.FieldType == typeof(byte) || fi.FieldType == typeof(sbyte)) - { - // Do nothing, can't byteswap them! - } - else if(fi.FieldType == typeof(Guid)) - { - // TODO: Swap GUID - } - // TODO: Swap arrays and enums - else if(fi.FieldType.IsValueType && !fi.FieldType.IsEnum && !fi.FieldType.IsArray) - { - object obj = fi.GetValue(str); - Type ty = obj.GetType(); - object strc = SwapStructureMembersEndian(obj); - fi.SetValue(str, strc); - } - - return str; - } - } -} \ No newline at end of file diff --git a/BitEndian.cs b/BitEndian.cs new file mode 100644 index 000000000..af0324e5e --- /dev/null +++ b/BitEndian.cs @@ -0,0 +1,51 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : BitEndian.cs +// Author(s) : Natalia Portillo +// +// Component : Common types. +// +// --[ Description ] ---------------------------------------------------------- +// +// Defines enumerations of bit endianness. +// +// --[ License ] -------------------------------------------------------------- +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2019 Natalia Portillo +// ****************************************************************************/ + +namespace DiscImageChef.Helpers +{ + /// Describes the endianness of bits on a data structure + public enum BitEndian + { + /// Little-endian, or least significant bit + Little, + /// Big-endian, or most significant bit + Big, + /// PDP-11 endian, little endian except for 32-bit integers where the 16 halves are swapped between them + Pdp + } +} \ No newline at end of file diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index 789bb5bf5..3ccae7500 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -48,12 +48,14 @@ + + + - @@ -70,6 +72,7 @@ + diff --git a/Marshal.cs b/Marshal.cs new file mode 100644 index 000000000..bc0863473 --- /dev/null +++ b/Marshal.cs @@ -0,0 +1,283 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : Marshal.cs +// Author(s) : Natalia Portillo +// +// Component : Helpers. +// +// --[ Description ] ---------------------------------------------------------- +// +// Provides marshalling for binary data. +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2019 Natalia Portillo +// ****************************************************************************/ + +using System; +using System.Reflection; +using System.Runtime.InteropServices; + +namespace DiscImageChef.Helpers +{ + /// Provides methods to marshal binary data into C# structs + public static class Marshal + { + static int count; + + /// + /// Marshal little-endian binary data to a structure + /// + /// Byte array containing the binary data + /// Type of the structure to marshal + /// The binary data marshalled in a structure with the specified type + public static T ByteArrayToStructureLittleEndian(byte[] bytes) where T : struct + { + GCHandle ptr = GCHandle.Alloc(bytes, GCHandleType.Pinned); + T str = + (T)System.Runtime.InteropServices.Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(T)); + ptr.Free(); + return str; + } + + /// + /// Marshal big-endian binary data to a structure + /// + /// Byte array containing the binary data + /// Type of the structure to marshal + /// The binary data marshalled in a structure with the specified type + public static T ByteArrayToStructureBigEndian(byte[] bytes) where T : struct + { + GCHandle ptr = GCHandle.Alloc(bytes, GCHandleType.Pinned); + object str = + (T)System.Runtime.InteropServices.Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(T)); + ptr.Free(); + return (T)SwapStructureMembersEndian(str); + } + + /// + /// Marshal PDP-11 binary data to a structure + /// + /// Byte array containing the binary data + /// Type of the structure to marshal + /// The binary data marshalled in a structure with the specified type + public static T ByteArrayToStructurePdpEndian(byte[] bytes) where T : struct + { + { + GCHandle ptr = GCHandle.Alloc(bytes, GCHandleType.Pinned); + object str = + (T)System.Runtime.InteropServices.Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(T)); + ptr.Free(); + return (T)SwapStructureMembersEndianPdp(str); + } + } + + /// + /// Marshal little-endian binary data to a structure. If the structure type contains any non value type, this method + /// will crash. + /// + /// Byte array containing the binary data + /// Type of the structure to marshal + /// The binary data marshalled in a structure with the specified type + public static T SpanToStructureLittleEndian(ReadOnlySpan bytes) where T : struct => + MemoryMarshal.Read(bytes); + + /// + /// Marshal big-endian binary data to a structure. If the structure type contains any non value type, this method will + /// crash. + /// + /// Byte array containing the binary data + /// Type of the structure to marshal + /// The binary data marshalled in a structure with the specified type + public static T SpanToStructureBigEndian(ReadOnlySpan bytes) where T : struct + { + T str = SpanToStructureLittleEndian(bytes); + return (T)SwapStructureMembersEndian(str); + } + + /// + /// Marshal PDP-11 binary data to a structure. If the structure type contains any non value type, this method will + /// crash. + /// + /// Byte array containing the binary data + /// Type of the structure to marshal + /// The binary data marshalled in a structure with the specified type + public static T SpanToStructurePdpEndian(ReadOnlySpan bytes) where T : struct + { + object str = SpanToStructureLittleEndian(bytes); + return (T)SwapStructureMembersEndianPdp(str); + } + + /// + /// Marshal a structure depending on the decoration of . If the decoration + /// is not present it will marshal as a reference type containing little endian structure. + /// + /// Byte array containing the binary data + /// Type of the structure to marshal + /// The binary data marshalled in a structure with the specified type + /// + /// The contains an unsupported + /// endian + /// + public static T MarshalStructure(byte[] bytes) where T : struct + { + if(!(typeof(T).GetCustomAttribute(typeof(MarshallingPropertiesAttribute)) is MarshallingPropertiesAttribute + properties)) return ByteArrayToStructureLittleEndian(bytes); + + switch(properties.Endian) + { + case BitEndian.Little: + return properties.HasReferences + ? ByteArrayToStructureLittleEndian(bytes) + : SpanToStructureLittleEndian(bytes); + + break; + case BitEndian.Big: + return properties.HasReferences + ? ByteArrayToStructureBigEndian(bytes) + : SpanToStructureBigEndian(bytes); + + break; + + case BitEndian.Pdp: + return properties.HasReferences + ? ByteArrayToStructurePdpEndian(bytes) + : SpanToStructurePdpEndian(bytes); + default: throw new ArgumentOutOfRangeException(); + } + } + + /// + /// Swaps all members of a structure + /// + /// + /// + public static object SwapStructureMembersEndian(object str) + { + Type t = str.GetType(); + FieldInfo[] fieldInfo = t.GetFields(); + foreach(FieldInfo fi in fieldInfo) + if(fi.FieldType == typeof(short)) + { + short x = (short)fi.GetValue(str); + fi.SetValue(str, (short)((x << 8) | ((x >> 8) & 0xFF))); + } + else if(fi.FieldType == typeof(int)) + { + int x = (int)fi.GetValue(str); + x = (int)(((x << 8) & 0xFF00FF00) | (((uint)x >> 8) & 0xFF00FF)); + fi.SetValue(str, (int)(((uint)x << 16) | (((uint)x >> 16) & 0xFFFF))); + } + else if(fi.FieldType == typeof(long)) + { + long x = (long)fi.GetValue(str); + x = ((x & 0x00000000FFFFFFFF) << 32) | (long)(((ulong)x & 0xFFFFFFFF00000000) >> 32); + x = ((x & 0x0000FFFF0000FFFF) << 16) | (long)(((ulong)x & 0xFFFF0000FFFF0000) >> 16); + x = ((x & 0x00FF00FF00FF00FF) << 8) | (long)(((ulong)x & 0xFF00FF00FF00FF00) >> 8); + + fi.SetValue(str, x); + } + else if(fi.FieldType == typeof(ushort)) + { + ushort x = (ushort)fi.GetValue(str); + fi.SetValue(str, (ushort)((x << 8) | (x >> 8))); + } + else if(fi.FieldType == typeof(uint)) + { + uint x = (uint)fi.GetValue(str); + x = ((x << 8) & 0xFF00FF00) | ((x >> 8) & 0xFF00FF); + fi.SetValue(str, (x << 16) | (x >> 16)); + } + else if(fi.FieldType == typeof(ulong)) + { + ulong x = (ulong)fi.GetValue(str); + x = ((x & 0x00000000FFFFFFFF) << 32) | ((x & 0xFFFFFFFF00000000) >> 32); + x = ((x & 0x0000FFFF0000FFFF) << 16) | ((x & 0xFFFF0000FFFF0000) >> 16); + x = ((x & 0x00FF00FF00FF00FF) << 8) | ((x & 0xFF00FF00FF00FF00) >> 8); + fi.SetValue(str, x); + } + else if(fi.FieldType == typeof(float)) + { + float flt = (float)fi.GetValue(str); + byte[] flt_b = BitConverter.GetBytes(flt); + fi.SetValue(str, BitConverter.ToSingle(new[] {flt_b[3], flt_b[2], flt_b[1], flt_b[0]}, 0)); + } + else if(fi.FieldType == typeof(double)) + { + double dbl = (double)fi.GetValue(str); + byte[] dbl_b = BitConverter.GetBytes(dbl); + fi.SetValue(str, + BitConverter + .ToDouble(new[] {dbl_b[7], dbl_b[6], dbl_b[5], dbl_b[4], dbl_b[3], dbl_b[2], dbl_b[1], dbl_b[0]}, + 0)); + } + else if(fi.FieldType == typeof(byte) || fi.FieldType == typeof(sbyte)) + { + // Do nothing, can't byteswap them! + } + else if(fi.FieldType == typeof(Guid)) + { + // TODO: Swap GUID + } + // TODO: Swap arrays and enums + else if(fi.FieldType.IsValueType && !fi.FieldType.IsEnum && !fi.FieldType.IsArray) + { + object obj = fi.GetValue(str); + object strc = SwapStructureMembersEndian(obj); + fi.SetValue(str, strc); + } + + return str; + } + + public static object SwapStructureMembersEndianPdp(object str) + { + Type t = str.GetType(); + FieldInfo[] fieldInfo = t.GetFields(); + foreach(FieldInfo fi in fieldInfo) + if(fi.FieldType == typeof(short) || fi.FieldType == typeof(long) || fi.FieldType == typeof(ushort) || + fi.FieldType == typeof(ulong) || fi.FieldType == typeof(float) || fi.FieldType == typeof(double) || + fi.FieldType == typeof(byte) || fi.FieldType == typeof(sbyte) || fi.FieldType == typeof(Guid)) + { + // Do nothing + } + else if(fi.FieldType == typeof(int)) + { + int x = (int)fi.GetValue(str); + fi.SetValue(str, ((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16)); + } + else if(fi.FieldType == typeof(uint)) + { + uint x = (uint)fi.GetValue(str); + fi.SetValue(str, ((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16)); + } + // TODO: Swap arrays and enums + else if(fi.FieldType.IsValueType && !fi.FieldType.IsEnum && !fi.FieldType.IsArray) + { + System.Console.WriteLine("PDP {0}", count++); + + object obj = fi.GetValue(str); + object strc = SwapStructureMembersEndianPdp(obj); + fi.SetValue(str, strc); + } + + return str; + } + } +} \ No newline at end of file diff --git a/MarshallingPropertiesAttribute.cs b/MarshallingPropertiesAttribute.cs new file mode 100644 index 000000000..110185a80 --- /dev/null +++ b/MarshallingPropertiesAttribute.cs @@ -0,0 +1,64 @@ +// /*************************************************************************** +// The Disc Image Chef +// ---------------------------------------------------------------------------- +// +// Filename : MarshallingPropertiesAttribute.cs +// Author(s) : Natalia Portillo +// +// Component : Common types. +// +// --[ Description ] ---------------------------------------------------------- +// +// Declares properties of structs for marshalling. +// +// --[ License ] -------------------------------------------------------------- +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2019 Natalia Portillo +// ****************************************************************************/ + +using System; + +namespace DiscImageChef.Helpers +{ + /// + /// Defines properties to help marshalling structs from binary data + /// + [AttributeUsage(AttributeTargets.Struct)] + public class MarshallingPropertiesAttribute : Attribute + { + /// c + public BitEndian Endian { get; } + /// + /// Tells if the structure, or any nested structure, has any non-value type (e.g. arrays, strings, etc). + /// + public bool HasReferences { get; set; } + + /// Defines properties to help marshalling structs from binary data + /// Defines properties to help marshalling structs from binary data + public MarshallingPropertiesAttribute(BitEndian endian) + { + Endian = endian; + HasReferences = true; + } + } +} \ No newline at end of file From 32539630319e95c1307e0c0a028c265c58bcb225 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 28 Feb 2019 10:35:40 +0000 Subject: [PATCH 094/217] Add overrides to marshal with offset and length. --- Marshal.cs | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 83 insertions(+), 4 deletions(-) diff --git a/Marshal.cs b/Marshal.cs index bc0863473..86f6987ed 100644 --- a/Marshal.cs +++ b/Marshal.cs @@ -39,8 +39,6 @@ namespace DiscImageChef.Helpers /// Provides methods to marshal binary data into C# structs public static class Marshal { - static int count; - /// /// Marshal little-endian binary data to a structure /// @@ -56,6 +54,20 @@ public static T ByteArrayToStructureLittleEndian(byte[] bytes) where T : stru return str; } + /// + /// Marshal little-endian binary data to a structure + /// + /// Byte array containing the binary data + /// Start on the array where the structure begins + /// Length of the structure in bytes + /// Type of the structure to marshal + /// The binary data marshalled in a structure with the specified type + public static T ByteArrayToStructureLittleEndian(byte[] bytes, int start, int length) where T : struct + { + Span span = bytes; + return ByteArrayToStructureLittleEndian(span.Slice(start, length).ToArray()); + } + /// /// Marshal big-endian binary data to a structure /// @@ -71,6 +83,20 @@ public static T ByteArrayToStructureBigEndian(byte[] bytes) where T : struct return (T)SwapStructureMembersEndian(str); } + /// + /// Marshal big-endian binary data to a structure + /// + /// Byte array containing the binary data + /// Start on the array where the structure begins + /// Length of the structure in bytes + /// Type of the structure to marshal + /// The binary data marshalled in a structure with the specified type + public static T ByteArrayToStructureBigEndian(byte[] bytes, int start, int length) where T : struct + { + Span span = bytes; + return ByteArrayToStructureBigEndian(span.Slice(start, length).ToArray()); + } + /// /// Marshal PDP-11 binary data to a structure /// @@ -88,6 +114,20 @@ public static T ByteArrayToStructurePdpEndian(byte[] bytes) where T : struct } } + /// + /// Marshal PDP-11 binary data to a structure + /// + /// Byte array containing the binary data + /// Start on the array where the structure begins + /// Length of the structure in bytes + /// Type of the structure to marshal + /// The binary data marshalled in a structure with the specified type + public static T ByteArrayToStructurePdpEndian(byte[] bytes, int start, int length) where T : struct + { + Span span = bytes; + return ByteArrayToStructurePdpEndian(span.Slice(start, length).ToArray()); + } + /// /// Marshal little-endian binary data to a structure. If the structure type contains any non value type, this method /// will crash. @@ -98,6 +138,19 @@ public static T ByteArrayToStructurePdpEndian(byte[] bytes) where T : struct public static T SpanToStructureLittleEndian(ReadOnlySpan bytes) where T : struct => MemoryMarshal.Read(bytes); + /// + /// Marshal little-endian binary data to a structure. If the structure type contains any non value type, this method + /// will crash. + /// + /// Byte span containing the binary data + /// Start on the span where the structure begins + /// Length of the structure in bytes + /// Type of the structure to marshal + /// The binary data marshalled in a structure with the specified type + public static T SpanToStructureLittleEndian(ReadOnlySpan bytes, int start, int length) + where T : struct => + MemoryMarshal.Read(bytes.Slice(start, length)); + /// /// Marshal big-endian binary data to a structure. If the structure type contains any non value type, this method will /// crash. @@ -111,6 +164,21 @@ public static T SpanToStructureBigEndian(ReadOnlySpan bytes) where T : return (T)SwapStructureMembersEndian(str); } + /// + /// Marshal big-endian binary data to a structure. If the structure type contains any non value type, this method will + /// crash. + /// + /// Byte span containing the binary data + /// Start on the span where the structure begins + /// Length of the structure in bytes + /// Type of the structure to marshal + /// The binary data marshalled in a structure with the specified type + public static T SpanToStructureBigEndian(ReadOnlySpan bytes, int start, int length) where T : struct + { + T str = SpanToStructureLittleEndian(bytes.Slice(start, length)); + return (T)SwapStructureMembersEndian(str); + } + /// /// Marshal PDP-11 binary data to a structure. If the structure type contains any non value type, this method will /// crash. @@ -124,6 +192,19 @@ public static T SpanToStructurePdpEndian(ReadOnlySpan bytes) where T : return (T)SwapStructureMembersEndianPdp(str); } + /// + /// Marshal PDP-11 binary data to a structure. If the structure type contains any non value type, this method will + /// crash. + /// + /// Byte array containing the binary data + /// Type of the structure to marshal + /// The binary data marshalled in a structure with the specified type + public static T SpanToStructurePdpEndian(ReadOnlySpan bytes, int start, int length) where T : struct + { + object str = SpanToStructureLittleEndian(bytes.Slice(start, length)); + return (T)SwapStructureMembersEndianPdp(str); + } + /// /// Marshal a structure depending on the decoration of . If the decoration /// is not present it will marshal as a reference type containing little endian structure. @@ -270,8 +351,6 @@ public static object SwapStructureMembersEndianPdp(object str) // TODO: Swap arrays and enums else if(fi.FieldType.IsValueType && !fi.FieldType.IsEnum && !fi.FieldType.IsArray) { - System.Console.WriteLine("PDP {0}", count++); - object obj = fi.GetValue(str); object strc = SwapStructureMembersEndianPdp(obj); fi.SetValue(str, strc); From 2dac60cdce8f279540d22a590bb11dc0ed7721ee Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Fri, 1 Mar 2019 07:35:22 +0000 Subject: [PATCH 095/217] Override Marshal.SizeOf in Helpers and use it instead of System's. --- Marshal.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Marshal.cs b/Marshal.cs index 86f6987ed..869c67dc1 100644 --- a/Marshal.cs +++ b/Marshal.cs @@ -39,6 +39,13 @@ namespace DiscImageChef.Helpers /// Provides methods to marshal binary data into C# structs public static class Marshal { + /// + /// Returns the size of an unmanaged type in bytes. + /// + /// The type whose size is to be returned. + /// The size, in bytes, of the type that is specified by the generic type parameter. + public static int SizeOf() => System.Runtime.InteropServices.Marshal.SizeOf(); + /// /// Marshal little-endian binary data to a structure /// From 7c7930ff3083723cc7c1a4671fe45738d05b777c Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 11 Mar 2019 19:24:06 +0000 Subject: [PATCH 096/217] Aggressively inline marshalling methods. --- Marshal.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Marshal.cs b/Marshal.cs index 869c67dc1..48fba483f 100644 --- a/Marshal.cs +++ b/Marshal.cs @@ -32,6 +32,7 @@ using System; using System.Reflection; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace DiscImageChef.Helpers @@ -44,6 +45,7 @@ public static class Marshal /// /// The type whose size is to be returned. /// The size, in bytes, of the type that is specified by the generic type parameter. + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int SizeOf() => System.Runtime.InteropServices.Marshal.SizeOf(); /// @@ -52,6 +54,7 @@ public static class Marshal /// Byte array containing the binary data /// Type of the structure to marshal /// The binary data marshalled in a structure with the specified type + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T ByteArrayToStructureLittleEndian(byte[] bytes) where T : struct { GCHandle ptr = GCHandle.Alloc(bytes, GCHandleType.Pinned); @@ -69,6 +72,7 @@ public static T ByteArrayToStructureLittleEndian(byte[] bytes) where T : stru /// Length of the structure in bytes /// Type of the structure to marshal /// The binary data marshalled in a structure with the specified type + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T ByteArrayToStructureLittleEndian(byte[] bytes, int start, int length) where T : struct { Span span = bytes; @@ -81,6 +85,7 @@ public static T ByteArrayToStructureLittleEndian(byte[] bytes, int start, int /// Byte array containing the binary data /// Type of the structure to marshal /// The binary data marshalled in a structure with the specified type + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T ByteArrayToStructureBigEndian(byte[] bytes) where T : struct { GCHandle ptr = GCHandle.Alloc(bytes, GCHandleType.Pinned); @@ -98,6 +103,7 @@ public static T ByteArrayToStructureBigEndian(byte[] bytes) where T : struct /// Length of the structure in bytes /// Type of the structure to marshal /// The binary data marshalled in a structure with the specified type + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T ByteArrayToStructureBigEndian(byte[] bytes, int start, int length) where T : struct { Span span = bytes; @@ -110,6 +116,7 @@ public static T ByteArrayToStructureBigEndian(byte[] bytes, int start, int le /// Byte array containing the binary data /// Type of the structure to marshal /// The binary data marshalled in a structure with the specified type + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T ByteArrayToStructurePdpEndian(byte[] bytes) where T : struct { { @@ -129,6 +136,7 @@ public static T ByteArrayToStructurePdpEndian(byte[] bytes) where T : struct /// Length of the structure in bytes /// Type of the structure to marshal /// The binary data marshalled in a structure with the specified type + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T ByteArrayToStructurePdpEndian(byte[] bytes, int start, int length) where T : struct { Span span = bytes; @@ -142,6 +150,7 @@ public static T ByteArrayToStructurePdpEndian(byte[] bytes, int start, int le /// Byte array containing the binary data /// Type of the structure to marshal /// The binary data marshalled in a structure with the specified type + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T SpanToStructureLittleEndian(ReadOnlySpan bytes) where T : struct => MemoryMarshal.Read(bytes); @@ -154,6 +163,7 @@ public static T SpanToStructureLittleEndian(ReadOnlySpan bytes) where T /// Length of the structure in bytes /// Type of the structure to marshal /// The binary data marshalled in a structure with the specified type + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T SpanToStructureLittleEndian(ReadOnlySpan bytes, int start, int length) where T : struct => MemoryMarshal.Read(bytes.Slice(start, length)); @@ -165,6 +175,7 @@ public static T SpanToStructureLittleEndian(ReadOnlySpan bytes, int sta /// Byte array containing the binary data /// Type of the structure to marshal /// The binary data marshalled in a structure with the specified type + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T SpanToStructureBigEndian(ReadOnlySpan bytes) where T : struct { T str = SpanToStructureLittleEndian(bytes); @@ -180,6 +191,7 @@ public static T SpanToStructureBigEndian(ReadOnlySpan bytes) where T : /// Length of the structure in bytes /// Type of the structure to marshal /// The binary data marshalled in a structure with the specified type + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T SpanToStructureBigEndian(ReadOnlySpan bytes, int start, int length) where T : struct { T str = SpanToStructureLittleEndian(bytes.Slice(start, length)); @@ -193,6 +205,7 @@ public static T SpanToStructureBigEndian(ReadOnlySpan bytes, int start, /// Byte array containing the binary data /// Type of the structure to marshal /// The binary data marshalled in a structure with the specified type + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T SpanToStructurePdpEndian(ReadOnlySpan bytes) where T : struct { object str = SpanToStructureLittleEndian(bytes); @@ -206,6 +219,7 @@ public static T SpanToStructurePdpEndian(ReadOnlySpan bytes) where T : /// Byte array containing the binary data /// Type of the structure to marshal /// The binary data marshalled in a structure with the specified type + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T SpanToStructurePdpEndian(ReadOnlySpan bytes, int start, int length) where T : struct { object str = SpanToStructureLittleEndian(bytes.Slice(start, length)); @@ -223,6 +237,7 @@ public static T SpanToStructurePdpEndian(ReadOnlySpan bytes, int start, /// The contains an unsupported /// endian /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T MarshalStructure(byte[] bytes) where T : struct { if(!(typeof(T).GetCustomAttribute(typeof(MarshallingPropertiesAttribute)) is MarshallingPropertiesAttribute @@ -256,6 +271,7 @@ public static T MarshalStructure(byte[] bytes) where T : struct /// /// /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static object SwapStructureMembersEndian(object str) { Type t = str.GetType(); @@ -334,6 +350,7 @@ public static object SwapStructureMembersEndian(object str) return str; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static object SwapStructureMembersEndianPdp(object str) { Type t = str.GetType(); From 804060b86bdf26bf94c1c152a6f3a42b840c8511 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 12 Mar 2019 01:00:45 +0000 Subject: [PATCH 097/217] Inline methods in swapping class. --- Swapping.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Swapping.cs b/Swapping.cs index 962305042..2b0103680 100644 --- a/Swapping.cs +++ b/Swapping.cs @@ -30,30 +30,39 @@ // Copyright © 2011-2019 Natalia Portillo // ****************************************************************************/ +using System.Runtime.CompilerServices; + namespace DiscImageChef { public static class Swapping { + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint PDPFromLittleEndian(uint x) => ((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint PDPFromBigEndian(uint x) => ((x & 0xff00ff) << 8) | ((x & 0xff00ff00) >> 8); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ushort Swap(ushort x) => (ushort)((x << 8) | (x >> 8)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static short Swap(short x) => (short)((x << 8) | ((x >> 8) & 0xFF)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint Swap(uint x) { x = ((x << 8) & 0xFF00FF00) | ((x >> 8) & 0xFF00FF); return (x << 16) | (x >> 16); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Swap(int x) { x = (int)(((x << 8) & 0xFF00FF00) | (((uint)x >> 8) & 0xFF00FF)); return (int)(((uint)x << 16) | (((uint)x >> 16) & 0xFFFF)); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ulong Swap(ulong x) { x = ((x & 0x00000000FFFFFFFF) << 32) | ((x & 0xFFFFFFFF00000000) >> 32); @@ -62,6 +71,7 @@ public static ulong Swap(ulong x) return x; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Swap(long x) { x = ((x & 0x00000000FFFFFFFF) << 32) | (long)(((ulong)x & 0xFFFFFFFF00000000) >> 32); From 8a8a22dd493a8ddf816b55e820fd797e6dc97949 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 14 Apr 2019 16:36:43 +0100 Subject: [PATCH 098/217] Fix converting C to string when passing an empty two byte string. --- StringHandlers.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/StringHandlers.cs b/StringHandlers.cs index 67a314a54..7046e1d3f 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -68,9 +68,6 @@ public static string CToString(byte[] CString, Encoding encoding, bool twoBytes len++; break; } - - // if((i + 1) == CString.Length) - // break; } else break; @@ -78,6 +75,8 @@ public static string CToString(byte[] CString, Encoding encoding, bool twoBytes len++; } + if(twoBytes && len % 2 > 0) len--; + byte[] dest = new byte[len]; Array.Copy(CString, start, dest, 0, len); From 742295d275782f354a91427b4ce9e41803031ae2 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sat, 11 May 2019 20:49:32 +0100 Subject: [PATCH 099/217] Remove the ability to support little endian from BigEndianBitConverter. --- BigEndianBitConverter.cs | 75 +++++++++++----------------------------- 1 file changed, 20 insertions(+), 55 deletions(-) diff --git a/BigEndianBitConverter.cs b/BigEndianBitConverter.cs index b68c19a74..317da4860 100644 --- a/BigEndianBitConverter.cs +++ b/BigEndianBitConverter.cs @@ -43,12 +43,6 @@ namespace DiscImageChef /// public static class BigEndianBitConverter { - /// - /// Indicates the byte order ("endianess") in which data is stored in this computer - /// architecture. - /// - public static bool IsLittleEndian { get; set; } - /// /// Converts the specified double-precision floating point number to a 64-bit signed integer. /// @@ -62,80 +56,70 @@ public static class BigEndianBitConverter /// /// A Boolean value. /// An array of bytes with length 1. - public static byte[] GetBytes(bool value) => - !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); + public static byte[] GetBytes(bool value) => BitConverter.GetBytes(value).Reverse().ToArray(); /// /// Returns the specified Unicode character value as an array of bytes. /// /// A character to convert. /// An array of bytes with length 2. - public static byte[] GetBytes(char value) => - !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); + public static byte[] GetBytes(char value) => BitConverter.GetBytes(value).Reverse().ToArray(); /// /// Returns the specified double-precision floating point value as an array of bytes. /// /// The number to convert. /// An array of bytes with length 8. - public static byte[] GetBytes(double value) => - !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); + public static byte[] GetBytes(double value) => BitConverter.GetBytes(value).Reverse().ToArray(); /// /// Returns the specified single-precision floating point value as an array of bytes. /// /// The number to convert. /// An array of bytes with length 4. - public static byte[] GetBytes(float value) => - !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); + public static byte[] GetBytes(float value) => BitConverter.GetBytes(value).Reverse().ToArray(); /// /// Returns the specified 32-bit signed integer value as an array of bytes. /// /// The number to convert. /// An array of bytes with length 4. - public static byte[] GetBytes(int value) => - !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); + public static byte[] GetBytes(int value) => BitConverter.GetBytes(value).Reverse().ToArray(); /// /// Returns the specified 64-bit signed integer value as an array of bytes. /// /// The number to convert. /// An array of bytes with length 8. - public static byte[] GetBytes(long value) => - !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); + public static byte[] GetBytes(long value) => BitConverter.GetBytes(value).Reverse().ToArray(); /// /// Returns the specified 16-bit signed integer value as an array of bytes. /// /// The number to convert. /// An array of bytes with length 2. - public static byte[] GetBytes(short value) => - !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); + public static byte[] GetBytes(short value) => BitConverter.GetBytes(value).Reverse().ToArray(); /// /// Returns the specified 32-bit unsigned integer value as an array of bytes. /// /// The number to convert. /// An array of bytes with length 4. - public static byte[] GetBytes(uint value) => - !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); + public static byte[] GetBytes(uint value) => BitConverter.GetBytes(value).Reverse().ToArray(); /// /// Returns the specified 64-bit unsigned integer value as an array of bytes. /// /// The number to convert. /// An array of bytes with length 8. - public static byte[] GetBytes(ulong value) => - !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); + public static byte[] GetBytes(ulong value) => BitConverter.GetBytes(value).Reverse().ToArray(); /// /// Returns the specified 16-bit unsigned integer value as an array of bytes. /// /// The number to convert. /// An array of bytes with length 2. - public static byte[] GetBytes(ushort value) => - !IsLittleEndian ? BitConverter.GetBytes(value) : BitConverter.GetBytes(value).Reverse().ToArray(); + public static byte[] GetBytes(ushort value) => BitConverter.GetBytes(value).Reverse().ToArray(); /// /// Converts the specified 64-bit signed integer to a double-precision floating point number. @@ -202,9 +186,7 @@ public static byte[] GetBytes(ushort value) => /// minus 1. /// public static short ToInt16(byte[] value, int startIndex) => - !IsLittleEndian - ? BitConverter.ToInt16(value, startIndex) - : BitConverter.ToInt16(value.Reverse().ToArray(), value.Length - sizeof(short) - startIndex); + BitConverter.ToInt16(value.Reverse().ToArray(), value.Length - sizeof(short) - startIndex); /// /// Returns a 32-bit signed integer converted from four bytes at a specified position in a byte array. @@ -222,9 +204,7 @@ public static short ToInt16(byte[] value, int startIndex) => /// minus 1. /// public static int ToInt32(byte[] value, int startIndex) => - !IsLittleEndian - ? BitConverter.ToInt32(value, startIndex) - : BitConverter.ToInt32(value.Reverse().ToArray(), value.Length - sizeof(int) - startIndex); + BitConverter.ToInt32(value.Reverse().ToArray(), value.Length - sizeof(int) - startIndex); /// /// Returns a 64-bit signed integer converted from eight bytes at a specified position in a byte array. @@ -242,9 +222,7 @@ public static int ToInt32(byte[] value, int startIndex) => /// length of value minus 1. /// public static long ToInt64(byte[] value, int startIndex) => - !IsLittleEndian - ? BitConverter.ToInt64(value, startIndex) - : BitConverter.ToInt64(value.Reverse().ToArray(), value.Length - sizeof(long) - startIndex); + BitConverter.ToInt64(value.Reverse().ToArray(), value.Length - sizeof(long) - startIndex); /// /// Returns a single-precision floating point number converted from four bytes at a specified position in a byte @@ -263,9 +241,7 @@ public static long ToInt64(byte[] value, int startIndex) => /// length of value minus 1. /// public static float ToSingle(byte[] value, int startIndex) => - !IsLittleEndian - ? BitConverter.ToSingle(value, startIndex) - : BitConverter.ToSingle(value.Reverse().ToArray(), value.Length - sizeof(float) - startIndex); + BitConverter.ToSingle(value.Reverse().ToArray(), value.Length - sizeof(float) - startIndex); /// /// Converts the numeric value of each element of a specified array of bytes to its equivalent hexadecimal string @@ -277,8 +253,7 @@ public static float ToSingle(byte[] value, int startIndex) => /// element in value; for example, "7F-2C-4A". /// /// value is null. - public static string ToString(byte[] value) => - !IsLittleEndian ? BitConverter.ToString(value) : BitConverter.ToString(value.Reverse().ToArray()); + public static string ToString(byte[] value) => BitConverter.ToString(value.Reverse().ToArray()); /// /// Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal string @@ -296,9 +271,7 @@ public static string ToString(byte[] value) => /// minus 1. /// public static string ToString(byte[] value, int startIndex) => - !IsLittleEndian - ? BitConverter.ToString(value, startIndex) - : BitConverter.ToString(value.Reverse().ToArray(), startIndex); + BitConverter.ToString(value.Reverse().ToArray(), startIndex); /// /// Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal string @@ -321,9 +294,7 @@ public static string ToString(byte[] value, int startIndex) => /// value; that is, the startIndex parameter is greater than the length of value minus the length parameter. /// public static string ToString(byte[] value, int startIndex, int length) => - !IsLittleEndian - ? BitConverter.ToString(value, startIndex, length) - : BitConverter.ToString(value.Reverse().ToArray(), startIndex, length); + BitConverter.ToString(value.Reverse().ToArray(), startIndex, length); /// /// Returns a 16-bit unsigned integer converted from two bytes at a specified position in a byte array. @@ -338,9 +309,7 @@ public static string ToString(byte[] value, int startIndex, int length) => /// minus 1. /// public static ushort ToUInt16(byte[] value, int startIndex) => - !IsLittleEndian - ? BitConverter.ToUInt16(value, startIndex) - : BitConverter.ToUInt16(value.Reverse().ToArray(), value.Length - sizeof(ushort) - startIndex); + BitConverter.ToUInt16(value.Reverse().ToArray(), value.Length - sizeof(ushort) - startIndex); /// /// Returns a 32-bit unsigned integer converted from four bytes at a specified position in a byte array. @@ -358,9 +327,7 @@ public static ushort ToUInt16(byte[] value, int startIndex) => /// minus 1. /// public static uint ToUInt32(byte[] value, int startIndex) => - !IsLittleEndian - ? BitConverter.ToUInt32(value, startIndex) - : BitConverter.ToUInt32(value.Reverse().ToArray(), value.Length - sizeof(uint) - startIndex); + BitConverter.ToUInt32(value.Reverse().ToArray(), value.Length - sizeof(uint) - startIndex); /// /// Returns a 64-bit unsigned integer converted from eight bytes at a specified position in a byte array. @@ -378,9 +345,7 @@ public static uint ToUInt32(byte[] value, int startIndex) => /// minus 1. /// public static ulong ToUInt64(byte[] value, int startIndex) => - !IsLittleEndian - ? BitConverter.ToUInt64(value, startIndex) - : BitConverter.ToUInt64(value.Reverse().ToArray(), value.Length - sizeof(ulong) - startIndex); + BitConverter.ToUInt64(value.Reverse().ToArray(), value.Length - sizeof(ulong) - startIndex); public static Guid ToGuid(byte[] value, int startIndex) => new Guid(ToUInt32(value, 0 + startIndex), ToUInt16(value, 4 + startIndex), From 6a50adfa34430b01d1a95641bee105932ebfd3a9 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Fri, 13 Sep 2019 19:21:25 +0100 Subject: [PATCH 100/217] Fix compiling .NET 4.5 using .NET Core msbuild. --- DiscImageChef.Helpers.csproj | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index 3ccae7500..c341fa89e 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -86,4 +86,25 @@ + + + + + /Library/Frameworks/Mono.framework/Versions/Current/lib/mono + /usr/lib/mono + /usr/local/lib/mono + + $(BaseFrameworkPathOverrideForMono)/4.0-api + $(BaseFrameworkPathOverrideForMono)/4.5-api + $(BaseFrameworkPathOverrideForMono)/4.5.1-api + $(BaseFrameworkPathOverrideForMono)/4.5.2-api + $(BaseFrameworkPathOverrideForMono)/4.6-api + $(BaseFrameworkPathOverrideForMono)/4.6.1-api + $(BaseFrameworkPathOverrideForMono)/4.6.2-api + $(BaseFrameworkPathOverrideForMono)/4.7-api + $(BaseFrameworkPathOverrideForMono)/4.7.1-api + true + + $(FrameworkPathOverride)/Facades;$(AssemblySearchPaths) + \ No newline at end of file From 19f00379c5da58a3ee279cf13bcd895f95f71514 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 19 Sep 2019 15:02:21 +0100 Subject: [PATCH 101/217] Update dependencies. --- DiscImageChef.Helpers.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index c341fa89e..c6d767d00 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -72,8 +72,8 @@ - - + + From f7c0d6fffb3dce13e914ed0f64d0c48ec24ca58e Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sat, 12 Oct 2019 22:13:33 +0100 Subject: [PATCH 102/217] Send hello packet. --- Marshal.cs | 186 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 105 insertions(+), 81 deletions(-) diff --git a/Marshal.cs b/Marshal.cs index 48fba483f..2a54e64fd 100644 --- a/Marshal.cs +++ b/Marshal.cs @@ -46,7 +46,10 @@ public static class Marshal /// The type whose size is to be returned. /// The size, in bytes, of the type that is specified by the generic type parameter. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int SizeOf() => System.Runtime.InteropServices.Marshal.SizeOf(); + public static int SizeOf() + { + return System.Runtime.InteropServices.Marshal.SizeOf(); + } /// /// Marshal little-endian binary data to a structure @@ -57,9 +60,9 @@ public static class Marshal [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T ByteArrayToStructureLittleEndian(byte[] bytes) where T : struct { - GCHandle ptr = GCHandle.Alloc(bytes, GCHandleType.Pinned); - T str = - (T)System.Runtime.InteropServices.Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(T)); + var ptr = GCHandle.Alloc(bytes, GCHandleType.Pinned); + var str = + (T) System.Runtime.InteropServices.Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(T)); ptr.Free(); return str; } @@ -88,11 +91,11 @@ public static T ByteArrayToStructureLittleEndian(byte[] bytes, int start, int [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T ByteArrayToStructureBigEndian(byte[] bytes) where T : struct { - GCHandle ptr = GCHandle.Alloc(bytes, GCHandleType.Pinned); + var ptr = GCHandle.Alloc(bytes, GCHandleType.Pinned); object str = - (T)System.Runtime.InteropServices.Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(T)); + (T) System.Runtime.InteropServices.Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(T)); ptr.Free(); - return (T)SwapStructureMembersEndian(str); + return (T) SwapStructureMembersEndian(str); } /// @@ -120,11 +123,11 @@ public static T ByteArrayToStructureBigEndian(byte[] bytes, int start, int le public static T ByteArrayToStructurePdpEndian(byte[] bytes) where T : struct { { - GCHandle ptr = GCHandle.Alloc(bytes, GCHandleType.Pinned); + var ptr = GCHandle.Alloc(bytes, GCHandleType.Pinned); object str = - (T)System.Runtime.InteropServices.Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(T)); + (T) System.Runtime.InteropServices.Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(T)); ptr.Free(); - return (T)SwapStructureMembersEndianPdp(str); + return (T) SwapStructureMembersEndianPdp(str); } } @@ -151,8 +154,10 @@ public static T ByteArrayToStructurePdpEndian(byte[] bytes, int start, int le /// Type of the structure to marshal /// The binary data marshalled in a structure with the specified type [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static T SpanToStructureLittleEndian(ReadOnlySpan bytes) where T : struct => - MemoryMarshal.Read(bytes); + public static T SpanToStructureLittleEndian(ReadOnlySpan bytes) where T : struct + { + return MemoryMarshal.Read(bytes); + } /// /// Marshal little-endian binary data to a structure. If the structure type contains any non value type, this method @@ -165,8 +170,10 @@ public static T SpanToStructureLittleEndian(ReadOnlySpan bytes) where T /// The binary data marshalled in a structure with the specified type [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T SpanToStructureLittleEndian(ReadOnlySpan bytes, int start, int length) - where T : struct => - MemoryMarshal.Read(bytes.Slice(start, length)); + where T : struct + { + return MemoryMarshal.Read(bytes.Slice(start, length)); + } /// /// Marshal big-endian binary data to a structure. If the structure type contains any non value type, this method will @@ -178,8 +185,8 @@ public static T SpanToStructureLittleEndian(ReadOnlySpan bytes, int sta [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T SpanToStructureBigEndian(ReadOnlySpan bytes) where T : struct { - T str = SpanToStructureLittleEndian(bytes); - return (T)SwapStructureMembersEndian(str); + var str = SpanToStructureLittleEndian(bytes); + return (T) SwapStructureMembersEndian(str); } /// @@ -194,8 +201,8 @@ public static T SpanToStructureBigEndian(ReadOnlySpan bytes) where T : [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T SpanToStructureBigEndian(ReadOnlySpan bytes, int start, int length) where T : struct { - T str = SpanToStructureLittleEndian(bytes.Slice(start, length)); - return (T)SwapStructureMembersEndian(str); + var str = SpanToStructureLittleEndian(bytes.Slice(start, length)); + return (T) SwapStructureMembersEndian(str); } /// @@ -209,7 +216,7 @@ public static T SpanToStructureBigEndian(ReadOnlySpan bytes, int start, public static T SpanToStructurePdpEndian(ReadOnlySpan bytes) where T : struct { object str = SpanToStructureLittleEndian(bytes); - return (T)SwapStructureMembersEndianPdp(str); + return (T) SwapStructureMembersEndianPdp(str); } /// @@ -223,7 +230,7 @@ public static T SpanToStructurePdpEndian(ReadOnlySpan bytes) where T : public static T SpanToStructurePdpEndian(ReadOnlySpan bytes, int start, int length) where T : struct { object str = SpanToStructureLittleEndian(bytes.Slice(start, length)); - return (T)SwapStructureMembersEndianPdp(str); + return (T) SwapStructureMembersEndianPdp(str); } /// @@ -240,28 +247,28 @@ public static T SpanToStructurePdpEndian(ReadOnlySpan bytes, int start, [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T MarshalStructure(byte[] bytes) where T : struct { - if(!(typeof(T).GetCustomAttribute(typeof(MarshallingPropertiesAttribute)) is MarshallingPropertiesAttribute - properties)) return ByteArrayToStructureLittleEndian(bytes); + if (!(typeof(T).GetCustomAttribute(typeof(MarshallingPropertiesAttribute)) is MarshallingPropertiesAttribute + properties)) return ByteArrayToStructureLittleEndian(bytes); - switch(properties.Endian) + switch (properties.Endian) { case BitEndian.Little: return properties.HasReferences - ? ByteArrayToStructureLittleEndian(bytes) - : SpanToStructureLittleEndian(bytes); + ? ByteArrayToStructureLittleEndian(bytes) + : SpanToStructureLittleEndian(bytes); break; case BitEndian.Big: return properties.HasReferences - ? ByteArrayToStructureBigEndian(bytes) - : SpanToStructureBigEndian(bytes); + ? ByteArrayToStructureBigEndian(bytes) + : SpanToStructureBigEndian(bytes); break; case BitEndian.Pdp: return properties.HasReferences - ? ByteArrayToStructurePdpEndian(bytes) - : SpanToStructurePdpEndian(bytes); + ? ByteArrayToStructurePdpEndian(bytes) + : SpanToStructurePdpEndian(bytes); default: throw new ArgumentOutOfRangeException(); } } @@ -274,76 +281,77 @@ public static T MarshalStructure(byte[] bytes) where T : struct [MethodImpl(MethodImplOptions.AggressiveInlining)] public static object SwapStructureMembersEndian(object str) { - Type t = str.GetType(); - FieldInfo[] fieldInfo = t.GetFields(); - foreach(FieldInfo fi in fieldInfo) - if(fi.FieldType == typeof(short)) + var t = str.GetType(); + var fieldInfo = t.GetFields(); + foreach (var fi in fieldInfo) + if (fi.FieldType == typeof(short)) { - short x = (short)fi.GetValue(str); - fi.SetValue(str, (short)((x << 8) | ((x >> 8) & 0xFF))); + var x = (short) fi.GetValue(str); + fi.SetValue(str, (short) ((x << 8) | ((x >> 8) & 0xFF))); } - else if(fi.FieldType == typeof(int)) + else if (fi.FieldType == typeof(int)) { - int x = (int)fi.GetValue(str); - x = (int)(((x << 8) & 0xFF00FF00) | (((uint)x >> 8) & 0xFF00FF)); - fi.SetValue(str, (int)(((uint)x << 16) | (((uint)x >> 16) & 0xFFFF))); + var x = (int) fi.GetValue(str); + x = (int) (((x << 8) & 0xFF00FF00) | (((uint) x >> 8) & 0xFF00FF)); + fi.SetValue(str, (int) (((uint) x << 16) | (((uint) x >> 16) & 0xFFFF))); } - else if(fi.FieldType == typeof(long)) + else if (fi.FieldType == typeof(long)) { - long x = (long)fi.GetValue(str); - x = ((x & 0x00000000FFFFFFFF) << 32) | (long)(((ulong)x & 0xFFFFFFFF00000000) >> 32); - x = ((x & 0x0000FFFF0000FFFF) << 16) | (long)(((ulong)x & 0xFFFF0000FFFF0000) >> 16); - x = ((x & 0x00FF00FF00FF00FF) << 8) | (long)(((ulong)x & 0xFF00FF00FF00FF00) >> 8); + var x = (long) fi.GetValue(str); + x = ((x & 0x00000000FFFFFFFF) << 32) | (long) (((ulong) x & 0xFFFFFFFF00000000) >> 32); + x = ((x & 0x0000FFFF0000FFFF) << 16) | (long) (((ulong) x & 0xFFFF0000FFFF0000) >> 16); + x = ((x & 0x00FF00FF00FF00FF) << 8) | (long) (((ulong) x & 0xFF00FF00FF00FF00) >> 8); fi.SetValue(str, x); } - else if(fi.FieldType == typeof(ushort)) + else if (fi.FieldType == typeof(ushort)) { - ushort x = (ushort)fi.GetValue(str); - fi.SetValue(str, (ushort)((x << 8) | (x >> 8))); + var x = (ushort) fi.GetValue(str); + fi.SetValue(str, (ushort) ((x << 8) | (x >> 8))); } - else if(fi.FieldType == typeof(uint)) + else if (fi.FieldType == typeof(uint)) { - uint x = (uint)fi.GetValue(str); - x = ((x << 8) & 0xFF00FF00) | ((x >> 8) & 0xFF00FF); - fi.SetValue(str, (x << 16) | (x >> 16)); + var x = (uint) fi.GetValue(str); + x = ((x << 8) & 0xFF00FF00) | ((x >> 8) & 0xFF00FF); + fi.SetValue(str, (x << 16) | (x >> 16)); } - else if(fi.FieldType == typeof(ulong)) + else if (fi.FieldType == typeof(ulong)) { - ulong x = (ulong)fi.GetValue(str); + var x = (ulong) fi.GetValue(str); 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); fi.SetValue(str, x); } - else if(fi.FieldType == typeof(float)) + else if (fi.FieldType == typeof(float)) { - float flt = (float)fi.GetValue(str); - byte[] flt_b = BitConverter.GetBytes(flt); + var flt = (float) fi.GetValue(str); + var flt_b = BitConverter.GetBytes(flt); fi.SetValue(str, BitConverter.ToSingle(new[] {flt_b[3], flt_b[2], flt_b[1], flt_b[0]}, 0)); } - else if(fi.FieldType == typeof(double)) + else if (fi.FieldType == typeof(double)) { - double dbl = (double)fi.GetValue(str); - byte[] dbl_b = BitConverter.GetBytes(dbl); + var dbl = (double) fi.GetValue(str); + var dbl_b = BitConverter.GetBytes(dbl); fi.SetValue(str, - BitConverter - .ToDouble(new[] {dbl_b[7], dbl_b[6], dbl_b[5], dbl_b[4], dbl_b[3], dbl_b[2], dbl_b[1], dbl_b[0]}, - 0)); + BitConverter + .ToDouble( + new[] {dbl_b[7], dbl_b[6], dbl_b[5], dbl_b[4], dbl_b[3], dbl_b[2], dbl_b[1], dbl_b[0]}, + 0)); } - else if(fi.FieldType == typeof(byte) || fi.FieldType == typeof(sbyte)) + else if (fi.FieldType == typeof(byte) || fi.FieldType == typeof(sbyte)) { // Do nothing, can't byteswap them! } - else if(fi.FieldType == typeof(Guid)) + else if (fi.FieldType == typeof(Guid)) { // TODO: Swap GUID } // TODO: Swap arrays and enums - else if(fi.FieldType.IsValueType && !fi.FieldType.IsEnum && !fi.FieldType.IsArray) + else if (fi.FieldType.IsValueType && !fi.FieldType.IsEnum && !fi.FieldType.IsArray) { - object obj = fi.GetValue(str); - object strc = SwapStructureMembersEndian(obj); + var obj = fi.GetValue(str); + var strc = SwapStructureMembersEndian(obj); fi.SetValue(str, strc); } @@ -353,34 +361,50 @@ public static object SwapStructureMembersEndian(object str) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static object SwapStructureMembersEndianPdp(object str) { - Type t = str.GetType(); - FieldInfo[] fieldInfo = t.GetFields(); - foreach(FieldInfo fi in fieldInfo) - if(fi.FieldType == typeof(short) || fi.FieldType == typeof(long) || fi.FieldType == typeof(ushort) || - fi.FieldType == typeof(ulong) || fi.FieldType == typeof(float) || fi.FieldType == typeof(double) || - fi.FieldType == typeof(byte) || fi.FieldType == typeof(sbyte) || fi.FieldType == typeof(Guid)) + var t = str.GetType(); + var fieldInfo = t.GetFields(); + foreach (var fi in fieldInfo) + if (fi.FieldType == typeof(short) || fi.FieldType == typeof(long) || fi.FieldType == typeof(ushort) || + fi.FieldType == typeof(ulong) || fi.FieldType == typeof(float) || fi.FieldType == typeof(double) || + fi.FieldType == typeof(byte) || fi.FieldType == typeof(sbyte) || fi.FieldType == typeof(Guid)) { // Do nothing } - else if(fi.FieldType == typeof(int)) + else if (fi.FieldType == typeof(int)) { - int x = (int)fi.GetValue(str); + var x = (int) fi.GetValue(str); fi.SetValue(str, ((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16)); } - else if(fi.FieldType == typeof(uint)) + else if (fi.FieldType == typeof(uint)) { - uint x = (uint)fi.GetValue(str); + var x = (uint) fi.GetValue(str); fi.SetValue(str, ((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16)); } // TODO: Swap arrays and enums - else if(fi.FieldType.IsValueType && !fi.FieldType.IsEnum && !fi.FieldType.IsArray) + else if (fi.FieldType.IsValueType && !fi.FieldType.IsEnum && !fi.FieldType.IsArray) { - object obj = fi.GetValue(str); - object strc = SwapStructureMembersEndianPdp(obj); + var obj = fi.GetValue(str); + var strc = SwapStructureMembersEndianPdp(obj); fi.SetValue(str, strc); } return str; } + + /// + /// Marshal a structure to little-endian binary data + /// + /// Byte array containing the binary data + /// Type of the structure to marshal + /// The binary data marshalled in a structure with the specified type + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static byte[] StructureToByteArrayLittleEndian(T str) where T : struct + { + var buf = new byte[SizeOf()]; + var ptr = GCHandle.Alloc(buf, GCHandleType.Pinned); + System.Runtime.InteropServices.Marshal.StructureToPtr(str, ptr.AddrOfPinnedObject(), false); + ptr.Free(); + return buf; + } } } \ No newline at end of file From fffcc4f0fb862756ca285286b0dc734a029fa9c2 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Fri, 25 Oct 2019 23:20:16 +0100 Subject: [PATCH 103/217] Make everything compile with .NET Core 2.2. --- DiscImageChef.Helpers.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index c6d767d00..5a1ddf17a 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -17,7 +17,7 @@ The Disc Image Chef DiscImageChef.Helpers $(Version) - net461;netstandard2.0 + net461;netstandard2.0;netcoreapp2.0 $(Version)-{chash:8} built by {mname} in $(Configuration){!:, modified} From d6f8938721c0381498ba32a4026021048e7c4ae7 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sat, 2 Nov 2019 02:16:39 +0000 Subject: [PATCH 104/217] Added gitignore --- .gitignore | 595 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 595 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..2ad9e5199 --- /dev/null +++ b/.gitignore @@ -0,0 +1,595 @@ +### VisualStudio template +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ +### Linux template + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* +### Xcode template +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## User settings +xcuserdata/ + +## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) +*.xcscmblueprint +*.xccheckout + +## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) +build/ +DerivedData/ +*.moved-aside +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +### VisualStudioCode template +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +### C++ template +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o + +# Precompiled Headers +*.gch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app +### MonoDevelop template +#User Specific +*.usertasks + +#Mono Project Files +*.resources +test-results/ +### GPG template +secring.* + +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/modules.xml +# .idea/*.iml +# .idea/modules + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests +### CMake template +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +### C template +# Object files +*.ko +*.elf + +# Linker output +*.map +*.exp + +*.so.* + +# Executables +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf +### Windows template +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# NuGet Packages Directory +packages/ +## TODO: If the tool you use requires repositories.config uncomment the next line +#!packages/repositories.config + +# Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets +# This line needs to be after the ignore of the build folder (and the packages folder if the line above has been uncommented) +!packages/build/ + + +# Others +sql/ +*.Cache + +# Visual Studio 2017 +.vs + +workspace.xml +cmake-build-debug +### macOS template +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +pkg/**/pkg +pkg/**/src +pkg/**/*.asc +pkg/**/*.sig +pkg/**/*.tar.xz +pkg/**/*.zip +pkg/**/discimagechef + +.sonarqube \ No newline at end of file From 4959cce56510066a1e195df5582e7ae15de1e818 Mon Sep 17 00:00:00 2001 From: SilasLaspada Date: Thu, 14 Nov 2019 21:12:18 -0700 Subject: [PATCH 105/217] Remove some unreachable code Because these will always return something, the break statements can never be reached. Fixes some warnings. --- Marshal.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/Marshal.cs b/Marshal.cs index 2a54e64fd..6c1f29e95 100644 --- a/Marshal.cs +++ b/Marshal.cs @@ -257,13 +257,11 @@ public static T MarshalStructure(byte[] bytes) where T : struct ? ByteArrayToStructureLittleEndian(bytes) : SpanToStructureLittleEndian(bytes); - break; case BitEndian.Big: return properties.HasReferences ? ByteArrayToStructureBigEndian(bytes) : SpanToStructureBigEndian(bytes); - break; case BitEndian.Pdp: return properties.HasReferences From 38e59c15191acda3487bb11cfdc1f3c95b13ffcd Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 19 Nov 2019 01:19:03 +0000 Subject: [PATCH 106/217] Change algorithm for print hex. --- PrintHex.cs | 106 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 68 insertions(+), 38 deletions(-) diff --git a/PrintHex.cs b/PrintHex.cs index 3256a1978..fd605d043 100644 --- a/PrintHex.cs +++ b/PrintHex.cs @@ -37,61 +37,91 @@ namespace DiscImageChef { public static class PrintHex { - /// - /// Prints a byte array as hexadecimal values to the console - /// + /// Prints a byte array as hexadecimal values to the console /// Array /// Width of line - public static void PrintHexArray(byte[] array, int width) - { + public static void PrintHexArray(byte[] array, int width = 16) => DicConsole.WriteLine(ByteArrayToHexArrayString(array, width)); - } - /// - /// Prints a byte array as hexadecimal values to a string - /// + /// Prints a byte array as hexadecimal values to a string /// Array /// Width of line + /// Use ANSI escape colors for sections /// String containing hexadecimal values - public static string ByteArrayToHexArrayString(byte[] array, int width) + public static string ByteArrayToHexArrayString(byte[] array, int width = 16, bool color = false) { - StringBuilder sb = new StringBuilder(); + // TODO: Color list + // TODO: Allow to change width + string str = "Offset"; + int rows = array.Length / 16; + int last = array.Length % 16; + int offsetLength = $"{array.Length:X}".Length; + var sb = new StringBuilder(); + + if(last == 0) + last = 16; + + if(offsetLength < str.Length) + offsetLength = str.Length; + + while(str.Length < offsetLength) + str += ' '; + + if(color) + sb.Append("\u001b[36m"); + + sb.Append(str); + sb.Append(" "); - int counter = 0; - int subcounter = 0; - for(long i = 0; i < array.LongLength; i++) + for(int i = 0; i < 16; i++) { - if(counter == 0) - { - sb.AppendLine(); - sb.AppendFormat("{0:X16} ", i); - } - else + sb.AppendFormat(" {0:X2}", i); + } + + if(color) + sb.Append("\u001b[0m"); + + sb.AppendLine(); + + int b = 0; + + string format = $"{{0:X{offsetLength}}}"; + + for(int i = 0; i < rows; i++) + { + if(color) + sb.Append("\u001b[36m"); + + sb.AppendFormat(format, b); + + if(color) + sb.Append("\u001b[0m"); + + sb.Append(" "); + int lastBytes = i == rows - 1 ? last : 16; + int lastSpaces = 16 - lastBytes; + + for(int j = 0; j < lastBytes; j++) { - if(subcounter == 3) - { - sb.Append(" "); - subcounter = 0; - } - else - { - sb.Append(" "); - subcounter++; - } + sb.AppendFormat(" {0:X2}", array[b]); + b++; } - sb.AppendFormat("{0:X2}", array[i]); + for(int j = 0; j < lastSpaces; j++) + sb.Append(" "); + + b -= lastBytes; + sb.Append(" "); - if(counter == width - 1) + for(int j = 0; j < lastBytes; j++) { - counter = 0; - subcounter = 0; + int v = array[b]; + sb.Append(v > 31 && v < 127 || v > 159 ? (char)v : '.'); + b++; } - else counter++; - } - sb.AppendLine(); - sb.AppendLine(); + sb.AppendLine(); + } return sb.ToString(); } From 693746872823edaab18c33137c72afcb2163c9f9 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 20 Nov 2019 00:13:35 +0000 Subject: [PATCH 107/217] Show decoded and hex view of data taken from tested media. --- PrintHex.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/PrintHex.cs b/PrintHex.cs index fd605d043..9f79092b3 100644 --- a/PrintHex.cs +++ b/PrintHex.cs @@ -50,6 +50,9 @@ public static void PrintHexArray(byte[] array, int width = 16) => /// String containing hexadecimal values public static string ByteArrayToHexArrayString(byte[] array, int width = 16, bool color = false) { + if(array is null) + return null; + // TODO: Color list // TODO: Allow to change width string str = "Offset"; From a7d7c673a1dd992e490d7531d23bea717de1069d Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 25 Nov 2019 00:54:39 +0000 Subject: [PATCH 108/217] Code reformat. --- ArrayFill.cs | 28 ++-- ArrayIsEmpty.cs | 19 +-- BigEndianBitConverter.cs | 111 +++++-------- BitEndian.cs | 3 +- CHS.cs | 9 +- CompareBytes.cs | 11 +- CountBits.cs | 7 +- DateHandlers.cs | 186 +++++++++++---------- Marshal.cs | 268 +++++++++++++++--------------- MarshallingPropertiesAttribute.cs | 16 +- PrintHex.cs | 12 +- StringHandlers.cs | 70 ++++---- Swapping.cs | 8 +- 13 files changed, 356 insertions(+), 392 deletions(-) diff --git a/ArrayFill.cs b/ArrayFill.cs index af29d5b82..7435ce9d9 100644 --- a/ArrayFill.cs +++ b/ArrayFill.cs @@ -31,27 +31,23 @@ namespace DiscImageChef { public static partial class ArrayHelpers { - /// - /// Fills an array with the specified value - /// + /// Fills an array with the specified value /// Array /// Value /// Array type - public static void ArrayFill(T[] destinationArray, T value) + public static void ArrayFill(T[] destinationArray, T value) => ArrayFill(destinationArray, new[] { - // if called with a single value, wrap the value in an array and call the main function - ArrayFill(destinationArray, new[] {value}); - } + value + }); - /// - /// Fills an array with the contents of the specified array - /// + /// Fills an array with the contents of the specified array /// Array /// Value /// Array type public static void ArrayFill(T[] destinationArray, T[] value) { - if(destinationArray == null) throw new ArgumentNullException(nameof(destinationArray)); + if(destinationArray == null) + throw new ArgumentNullException(nameof(destinationArray)); if(value.Length > destinationArray.Length) throw new ArgumentException("Length of value array must not be more than length of destination"); @@ -68,16 +64,16 @@ public static void ArrayFill(T[] destinationArray, T[] value) Array.Copy(destinationArray, 0, destinationArray, copyLength, destinationArray.Length - copyLength); } - /// - /// Converts a byte array to its hexadecimal representation - /// + /// Converts a byte array to its hexadecimal representation /// Byte array /// true to use uppercase /// public static string ByteArrayToHex(byte[] array, bool upper = false) { - StringBuilder sb = new StringBuilder(); - for(long i = 0; i < array.LongLength; i++) sb.AppendFormat("{0:x2}", array[i]); + var sb = new StringBuilder(); + + for(long i = 0; i < array.LongLength; i++) + sb.AppendFormat("{0:x2}", array[i]); return upper ? sb.ToString().ToUpper() : sb.ToString(); } diff --git a/ArrayIsEmpty.cs b/ArrayIsEmpty.cs index 51ffd7a06..5d2ed6d06 100644 --- a/ArrayIsEmpty.cs +++ b/ArrayIsEmpty.cs @@ -36,24 +36,15 @@ namespace DiscImageChef { public static partial class ArrayHelpers { - /// - /// Checks if an array is null, filled with the NULL byte (0x00) or ASCII whitespace (0x20) - /// + /// Checks if an array is null, filled with the NULL byte (0x00) or ASCII whitespace (0x20) /// Array /// True if null or whitespace - public static bool ArrayIsNullOrWhiteSpace(byte[] array) - { - return array == null || array.All(b => b == 0x00 || b == 0x20); - } + public static bool ArrayIsNullOrWhiteSpace(byte[] array) => + array == null || array.All(b => b == 0x00 || b == 0x20); - /// - /// Checks if an array is null or filled with the NULL byte (0x00) - /// + /// Checks if an array is null or filled with the NULL byte (0x00) /// Array /// True if null - public static bool ArrayIsNullOrEmpty(byte[] array) - { - return array == null || array.All(b => b == 0x00); - } + public static bool ArrayIsNullOrEmpty(byte[] array) => array == null || array.All(b => b == 0x00); } } \ No newline at end of file diff --git a/BigEndianBitConverter.cs b/BigEndianBitConverter.cs index 317da4860..c71f188c3 100644 --- a/BigEndianBitConverter.cs +++ b/BigEndianBitConverter.cs @@ -36,101 +36,73 @@ namespace DiscImageChef { /// - /// Converts base data types to an array of bytes, and an array of bytes to base - /// data types. - /// All info taken from the meta data of System.BitConverter. This implementation - /// allows for Endianness consideration. + /// Converts base data types to an array of bytes, and an array of bytes to base data types. All info taken from + /// the meta data of System.BitConverter. This implementation allows for Endianness consideration. /// public static class BigEndianBitConverter { - /// - /// Converts the specified double-precision floating point number to a 64-bit signed integer. - /// + /// Converts the specified double-precision floating point number to a 64-bit signed integer. /// The number to convert. /// A 64-bit signed integer whose value is equivalent to value. /// It is not currently implemented public static long DoubleToInt64Bits(double value) => throw new NotImplementedException(); - /// - /// Returns the specified Boolean value as an array of bytes. - /// + /// Returns the specified Boolean value as an array of bytes. /// A Boolean value. /// An array of bytes with length 1. public static byte[] GetBytes(bool value) => BitConverter.GetBytes(value).Reverse().ToArray(); - /// - /// Returns the specified Unicode character value as an array of bytes. - /// + /// Returns the specified Unicode character value as an array of bytes. /// A character to convert. /// An array of bytes with length 2. public static byte[] GetBytes(char value) => BitConverter.GetBytes(value).Reverse().ToArray(); - /// - /// Returns the specified double-precision floating point value as an array of bytes. - /// + /// Returns the specified double-precision floating point value as an array of bytes. /// The number to convert. /// An array of bytes with length 8. public static byte[] GetBytes(double value) => BitConverter.GetBytes(value).Reverse().ToArray(); - /// - /// Returns the specified single-precision floating point value as an array of bytes. - /// + /// Returns the specified single-precision floating point value as an array of bytes. /// The number to convert. /// An array of bytes with length 4. public static byte[] GetBytes(float value) => BitConverter.GetBytes(value).Reverse().ToArray(); - /// - /// Returns the specified 32-bit signed integer value as an array of bytes. - /// + /// Returns the specified 32-bit signed integer value as an array of bytes. /// The number to convert. /// An array of bytes with length 4. public static byte[] GetBytes(int value) => BitConverter.GetBytes(value).Reverse().ToArray(); - /// - /// Returns the specified 64-bit signed integer value as an array of bytes. - /// + /// Returns the specified 64-bit signed integer value as an array of bytes. /// The number to convert. /// An array of bytes with length 8. public static byte[] GetBytes(long value) => BitConverter.GetBytes(value).Reverse().ToArray(); - /// - /// Returns the specified 16-bit signed integer value as an array of bytes. - /// + /// Returns the specified 16-bit signed integer value as an array of bytes. /// The number to convert. /// An array of bytes with length 2. public static byte[] GetBytes(short value) => BitConverter.GetBytes(value).Reverse().ToArray(); - /// - /// Returns the specified 32-bit unsigned integer value as an array of bytes. - /// + /// Returns the specified 32-bit unsigned integer value as an array of bytes. /// The number to convert. /// An array of bytes with length 4. public static byte[] GetBytes(uint value) => BitConverter.GetBytes(value).Reverse().ToArray(); - /// - /// Returns the specified 64-bit unsigned integer value as an array of bytes. - /// + /// Returns the specified 64-bit unsigned integer value as an array of bytes. /// The number to convert. /// An array of bytes with length 8. public static byte[] GetBytes(ulong value) => BitConverter.GetBytes(value).Reverse().ToArray(); - /// - /// Returns the specified 16-bit unsigned integer value as an array of bytes. - /// + /// Returns the specified 16-bit unsigned integer value as an array of bytes. /// The number to convert. /// An array of bytes with length 2. public static byte[] GetBytes(ushort value) => BitConverter.GetBytes(value).Reverse().ToArray(); - /// - /// Converts the specified 64-bit signed integer to a double-precision floating point number. - /// + /// Converts the specified 64-bit signed integer to a double-precision floating point number. /// The number to convert. /// A double-precision floating point number whose value is equivalent to value. public static double Int64BitsToDouble(long value) => throw new NotImplementedException(); - /// - /// Returns a Boolean value converted from one byte at a specified position in a byte array. - /// + /// Returns a Boolean value converted from one byte at a specified position in a byte array. /// An array of bytes. /// The starting position within value. /// true if the byte at in value is nonzero; otherwise, false. @@ -141,9 +113,7 @@ public static class BigEndianBitConverter /// public static bool ToBoolean(byte[] value, int startIndex) => throw new NotImplementedException(); - /// - /// Returns a Unicode character converted from two bytes at a specified position in a byte array. - /// + /// Returns a Unicode character converted from two bytes at a specified position in a byte array. /// An array. /// The starting position within value. /// A character formed by two bytes beginning at . @@ -173,9 +143,7 @@ public static class BigEndianBitConverter /// public static double ToDouble(byte[] value, int startIndex) => throw new NotImplementedException(); - /// - /// Returns a 16-bit signed integer converted from two bytes at a specified position in a byte array. - /// + /// Returns a 16-bit signed integer converted from two bytes at a specified position in a byte array. /// An array of bytes. /// The starting position within value. /// A 16-bit signed integer formed by two bytes beginning at . @@ -188,9 +156,7 @@ public static class BigEndianBitConverter public static short ToInt16(byte[] value, int startIndex) => BitConverter.ToInt16(value.Reverse().ToArray(), value.Length - sizeof(short) - startIndex); - /// - /// Returns a 32-bit signed integer converted from four bytes at a specified position in a byte array. - /// + /// Returns a 32-bit signed integer converted from four bytes at a specified position in a byte array. /// An array of bytes. /// The starting position within value. /// A 32-bit signed integer formed by four bytes beginning at . @@ -206,9 +172,7 @@ public static short ToInt16(byte[] value, int startIndex) => public static int ToInt32(byte[] value, int startIndex) => BitConverter.ToInt32(value.Reverse().ToArray(), value.Length - sizeof(int) - startIndex); - /// - /// Returns a 64-bit signed integer converted from eight bytes at a specified position in a byte array. - /// + /// Returns a 64-bit signed integer converted from eight bytes at a specified position in a byte array. /// An array of bytes. /// The starting position within value. /// A 64-bit signed integer formed by eight bytes beginning at . @@ -256,8 +220,8 @@ public static float ToSingle(byte[] value, int startIndex) => public static string ToString(byte[] value) => BitConverter.ToString(value.Reverse().ToArray()); /// - /// Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal string - /// representation. + /// Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal + /// string representation. /// /// An array of bytes. /// The starting position within value. @@ -274,8 +238,8 @@ public static string ToString(byte[] value, int startIndex) => BitConverter.ToString(value.Reverse().ToArray(), startIndex); /// - /// Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal string - /// representation. + /// Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal + /// string representation. /// /// An array of bytes. /// The starting position within value. @@ -296,9 +260,7 @@ public static string ToString(byte[] value, int startIndex) => public static string ToString(byte[] value, int startIndex, int length) => BitConverter.ToString(value.Reverse().ToArray(), startIndex, length); - /// - /// Returns a 16-bit unsigned integer converted from two bytes at a specified position in a byte array. - /// + /// Returns a 16-bit unsigned integer converted from two bytes at a specified position in a byte array. /// The array of bytes. /// The starting position within value. /// A 16-bit unsigned integer formed by two bytes beginning at startIndex. @@ -311,9 +273,7 @@ public static string ToString(byte[] value, int startIndex, int length) => public static ushort ToUInt16(byte[] value, int startIndex) => BitConverter.ToUInt16(value.Reverse().ToArray(), value.Length - sizeof(ushort) - startIndex); - /// - /// Returns a 32-bit unsigned integer converted from four bytes at a specified position in a byte array. - /// + /// Returns a 32-bit unsigned integer converted from four bytes at a specified position in a byte array. /// An array of bytes. /// The starting position within value. /// A 32-bit unsigned integer formed by four bytes beginning at startIndex. @@ -329,9 +289,7 @@ public static ushort ToUInt16(byte[] value, int startIndex) => public static uint ToUInt32(byte[] value, int startIndex) => BitConverter.ToUInt32(value.Reverse().ToArray(), value.Length - sizeof(uint) - startIndex); - /// - /// Returns a 64-bit unsigned integer converted from eight bytes at a specified position in a byte array. - /// + /// Returns a 64-bit unsigned integer converted from eight bytes at a specified position in a byte array. /// An array of bytes. /// The starting position within value. /// A 64-bit unsigned integer formed by the eight bytes beginning at startIndex. @@ -347,11 +305,16 @@ public static uint ToUInt32(byte[] value, int startIndex) => public static ulong ToUInt64(byte[] value, int startIndex) => BitConverter.ToUInt64(value.Reverse().ToArray(), value.Length - sizeof(ulong) - startIndex); - public static Guid ToGuid(byte[] value, int startIndex) => - 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]); + public static Guid ToGuid(byte[] value, int startIndex) => 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]); } } \ No newline at end of file diff --git a/BitEndian.cs b/BitEndian.cs index af0324e5e..c6e7aaf00 100644 --- a/BitEndian.cs +++ b/BitEndian.cs @@ -42,8 +42,7 @@ namespace DiscImageChef.Helpers public enum BitEndian { /// Little-endian, or least significant bit - Little, - /// Big-endian, or most significant bit + Little, /// Big-endian, or most significant bit Big, /// PDP-11 endian, little endian except for 32-bit integers where the 16 halves are swapped between them Pdp diff --git a/CHS.cs b/CHS.cs index 7d933bd3b..ef1e29944 100644 --- a/CHS.cs +++ b/CHS.cs @@ -34,9 +34,7 @@ namespace DiscImageChef.Helpers { public static class CHS { - /// - /// Converts a CHS position to a LBA one - /// + /// Converts a CHS position to a LBA one /// Cylinder /// Head /// Sector @@ -44,8 +42,7 @@ public static class CHS /// Number of sectors per track /// public static uint ToLBA(uint cyl, uint head, uint sector, uint maxHead, uint maxSector) => - maxHead == 0 || maxSector == 0 - ? (cyl * 16 + head) * 63 + sector - 1 - : (cyl * maxHead + head) * maxSector + sector - 1; + maxHead == 0 || maxSector == 0 ? (cyl * 16 + head) * 63 + sector - 1 + : (cyl * maxHead + head) * maxSector + sector - 1; } } \ No newline at end of file diff --git a/CompareBytes.cs b/CompareBytes.cs index 8101b2a48..c8970253e 100644 --- a/CompareBytes.cs +++ b/CompareBytes.cs @@ -34,20 +34,19 @@ namespace DiscImageChef { public static partial class ArrayHelpers { - /// - /// Compares two byte arrays - /// + /// Compares two byte arrays /// true if they are different in any way /// true if they have the same size /// Left array /// Right array public static void CompareBytes(out bool different, out bool sameSize, byte[] compareArray1, - byte[] compareArray2) + byte[] compareArray2) { different = false; sameSize = true; long leastBytes; + if(compareArray1.LongLength < compareArray2.LongLength) { sameSize = false; @@ -58,12 +57,14 @@ public static void CompareBytes(out bool different, out bool sameSize, byte[] co sameSize = false; leastBytes = compareArray2.LongLength; } - else leastBytes = compareArray1.LongLength; + else + leastBytes = compareArray1.LongLength; for(long i = 0; i < leastBytes; i++) if(compareArray1[i] != compareArray2[i]) { different = true; + return; } } diff --git a/CountBits.cs b/CountBits.cs index f7fe42eed..f85254bc6 100644 --- a/CountBits.cs +++ b/CountBits.cs @@ -34,16 +34,15 @@ namespace DiscImageChef.Helpers { public static class CountBits { - /// - /// Counts the number of bits set to true in a number - /// + /// Counts the number of bits set to true in a number /// Number /// Bits set to true public static int Count(uint number) { number = number - ((number >> 1) & 0x55555555); number = (number & 0x33333333) + ((number >> 2) & 0x33333333); - return (int)((((number + (number >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24); + + return(int)((((number + (number >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24); } } } \ No newline at end of file diff --git a/DateHandlers.cs b/DateHandlers.cs index 5ee2db94f..e0ed69056 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -41,79 +41,60 @@ 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 UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0); - /// - /// Day 0 of Julian Date system - /// + /// Day 0 of Julian Date system static readonly DateTime JulianEpoch = new DateTime(1858, 11, 17, 0, 0, 0); static readonly DateTime AmigaEpoch = new DateTime(1978, 1, 1, 0, 0, 0); - /// - /// Converts a Macintosh timestamp to a .NET DateTime - /// + /// Converts a Macintosh timestamp to a .NET DateTime /// Macintosh timestamp (seconds since 1st Jan. 1904) /// .NET DateTime public static DateTime MacToDateTime(ulong macTimeStamp) => MacEpoch.AddTicks((long)(macTimeStamp * 10000000)); - /// - /// Converts a Lisa timestamp to a .NET DateTime - /// + /// Converts a Lisa timestamp to a .NET DateTime /// Lisa timestamp (seconds since 1st Jan. 1901) /// .NET DateTime public static DateTime LisaToDateTime(uint lisaTimeStamp) => LisaEpoch.AddSeconds(lisaTimeStamp); - /// - /// Converts a UNIX timestamp to a .NET DateTime - /// + /// Converts a UNIX timestamp to a .NET DateTime /// UNIX timestamp (seconds since 1st Jan. 1970) /// .NET DateTime public static DateTime UnixToDateTime(int unixTimeStamp) => UnixEpoch.AddSeconds(unixTimeStamp); - /// - /// Converts a UNIX timestamp to a .NET DateTime - /// + /// Converts a UNIX timestamp to a .NET DateTime /// UNIX timestamp (seconds since 1st Jan. 1970) /// .NET DateTime public static DateTime UnixToDateTime(long unixTimeStamp) => UnixEpoch.AddSeconds(unixTimeStamp); - /// - /// Converts a UNIX timestamp to a .NET DateTime - /// + /// Converts a UNIX timestamp to a .NET DateTime /// UNIX timestamp (seconds since 1st Jan. 1970) /// .NET DateTime public static DateTime UnixUnsignedToDateTime(uint unixTimeStamp) => UnixEpoch.AddSeconds(unixTimeStamp); - /// - /// Converts a UNIX timestamp to a .NET DateTime - /// + /// Converts a UNIX timestamp to a .NET DateTime /// Seconds since 1st Jan. 1970) /// Nanoseconds /// .NET DateTime public static DateTime UnixUnsignedToDateTime(uint seconds, uint nanoseconds) => UnixEpoch.AddSeconds(seconds).AddTicks((long)nanoseconds / 100); - /// - /// Converts a UNIX timestamp to a .NET DateTime - /// + /// Converts a UNIX timestamp to a .NET DateTime /// UNIX timestamp (seconds since 1st Jan. 1970) /// .NET DateTime public static DateTime UnixUnsignedToDateTime(ulong unixTimeStamp) => UnixEpoch.AddSeconds(unixTimeStamp); - /// - /// Converts a High Sierra Format timestamp to a .NET DateTime - /// + /// Converts a High Sierra Format timestamp to a .NET DateTime /// High Sierra Format timestamp /// .NET DateTime public static DateTime HighSierraToDateTime(byte[] vdDateTime) { byte[] isotime = new byte[17]; Array.Copy(vdDateTime, 0, isotime, 0, 16); + return Iso9660ToDateTime(isotime); } // TODO: Timezone - /// - /// Converts an ISO9660 timestamp to a .NET DateTime - /// + /// Converts an ISO9660 timestamp to a .NET DateTime /// ISO9660 timestamp /// .NET DateTime public static DateTime Iso9660ToDateTime(byte[] vdDateTime) @@ -125,71 +106,89 @@ public static DateTime Iso9660ToDateTime(byte[] vdDateTime) fourcharvalue[1] = vdDateTime[1]; fourcharvalue[2] = vdDateTime[2]; fourcharvalue[3] = vdDateTime[3]; + DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "year = \"{0}\"", StringHandlers.CToString(fourcharvalue, Encoding.ASCII)); - if(!int.TryParse(StringHandlers.CToString(fourcharvalue, Encoding.ASCII), out int year)) year = 0; + + if(!int.TryParse(StringHandlers.CToString(fourcharvalue, Encoding.ASCII), out int year)) + year = 0; twocharvalue[0] = vdDateTime[4]; twocharvalue[1] = vdDateTime[5]; + DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "month = \"{0}\"", StringHandlers.CToString(twocharvalue, Encoding.ASCII)); - if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out int month)) month = 0; + + if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out int month)) + month = 0; twocharvalue[0] = vdDateTime[6]; twocharvalue[1] = vdDateTime[7]; + DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "day = \"{0}\"", StringHandlers.CToString(twocharvalue, Encoding.ASCII)); - if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out int day)) day = 0; + + if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out int day)) + day = 0; twocharvalue[0] = vdDateTime[8]; twocharvalue[1] = vdDateTime[9]; + DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "hour = \"{0}\"", StringHandlers.CToString(twocharvalue, Encoding.ASCII)); - if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out int hour)) hour = 0; + + if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out int hour)) + hour = 0; twocharvalue[0] = vdDateTime[10]; twocharvalue[1] = vdDateTime[11]; + DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "minute = \"{0}\"", StringHandlers.CToString(twocharvalue, Encoding.ASCII)); - if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out int minute)) minute = 0; + + if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out int minute)) + minute = 0; twocharvalue[0] = vdDateTime[12]; twocharvalue[1] = vdDateTime[13]; + DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "second = \"{0}\"", StringHandlers.CToString(twocharvalue, Encoding.ASCII)); - if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out int second)) second = 0; + + if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out int second)) + second = 0; twocharvalue[0] = vdDateTime[14]; twocharvalue[1] = vdDateTime[15]; + DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "hundredths = \"{0}\"", StringHandlers.CToString(twocharvalue, Encoding.ASCII)); + if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out int hundredths)) hundredths = 0; DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "decodedDT = new DateTime({0}, {1}, {2}, {3}, {4}, {5}, {6}, DateTimeKind.Unspecified);", year, month, day, hour, minute, second, hundredths * 10); - DateTime decodedDt = new DateTime(year, month, day, hour, minute, second, hundredths * 10, - DateTimeKind.Unspecified); + + var decodedDt = new DateTime(year, month, day, hour, minute, second, hundredths * 10, + DateTimeKind.Unspecified); return decodedDt; } - /// - /// Converts a VMS timestamp to a .NET DateTime - /// + /// Converts a VMS timestamp to a .NET DateTime /// VMS timestamp (tenths of microseconds since day 0 of the Julian Date) /// .NET DateTime /// C# works in UTC, VMS on Julian Date, some displacement may occur on disks created outside UTC public static DateTime VmsToDateTime(ulong vmsDate) { double delta = vmsDate * 0.0001; // Tenths of microseconds to milliseconds, will lose some detail + return JulianEpoch.AddMilliseconds(delta); } - /// - /// Converts an Amiga timestamp to a .NET DateTime - /// + /// Converts an Amiga timestamp to a .NET DateTime /// Days since the 1st Jan. 1978 /// Minutes since o'clock /// Ticks @@ -198,12 +197,11 @@ public static DateTime AmigaToDateTime(uint days, uint minutes, uint ticks) { DateTime temp = AmigaEpoch.AddDays(days); temp = temp.AddMinutes(minutes); + return temp.AddMilliseconds(ticks * 20); } - /// - /// Converts an UCSD Pascal timestamp to a .NET DateTime - /// + /// Converts an UCSD Pascal timestamp to a .NET DateTime /// UCSD Pascal timestamp /// .NET DateTime public static DateTime UcsdPascalToDateTime(short dateRecord) @@ -215,12 +213,11 @@ public static DateTime UcsdPascalToDateTime(short dateRecord) DicConsole.DebugWriteLine("UCSDPascalToDateTime handler", "dateRecord = 0x{0:X4}, year = {1}, month = {2}, day = {3}", dateRecord, year, month, day); + return new DateTime(year, month, day); } - /// - /// Converts a DOS timestamp to a .NET DateTime - /// + /// Converts a DOS timestamp to a .NET DateTime /// Date /// Time /// .NET DateTime @@ -235,20 +232,26 @@ public static DateTime DosToDateTime(ushort date, ushort time) DicConsole.DebugWriteLine("DOSToDateTime handler", "date = 0x{0:X4}, year = {1}, month = {2}, day = {3}", date, year, month, day); + DicConsole.DebugWriteLine("DOSToDateTime handler", "time = 0x{0:X4}, hour = {1}, minute = {2}, second = {3}", time, hour, minute, second); DateTime dosdate; - try { dosdate = new DateTime(year, month, day, hour, minute, second); } - catch(ArgumentOutOfRangeException) { dosdate = new DateTime(1980, 1, 1, 0, 0, 0); } + + try + { + dosdate = new DateTime(year, month, day, hour, minute, second); + } + catch(ArgumentOutOfRangeException) + { + dosdate = new DateTime(1980, 1, 1, 0, 0, 0); + } return dosdate; } - /// - /// Converts a CP/M timestamp to .NET DateTime - /// + /// Converts a CP/M timestamp to .NET DateTime /// CP/M timestamp /// .NET DateTime public static DateTime CpmToDateTime(byte[] timestamp) @@ -264,9 +267,7 @@ public static DateTime CpmToDateTime(byte[] timestamp) return temp; } - /// - /// Converts an ECMA timestamp to a .NET DateTime - /// + /// Converts an ECMA timestamp to a .NET DateTime /// Timezone /// Year /// Month @@ -278,77 +279,79 @@ public static DateTime CpmToDateTime(byte[] timestamp) /// Hundreds of microseconds /// 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) + 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; + if(specification == 0) return new DateTime(year, month, day, hour, minute, second, DateTimeKind.Utc).AddTicks(ticks); ushort preOffset = (ushort)(typeAndTimeZone & 0xFFF); short offset; - if((preOffset & 0x800) == 0x800) offset = (short)(preOffset | 0xF000); - else offset = (short)(preOffset & 0x7FF); + if((preOffset & 0x800) == 0x800) + offset = (short)(preOffset | 0xF000); + else + offset = (short)(preOffset & 0x7FF); if(offset == -2047) return new DateTime(year, month, day, hour, minute, second, DateTimeKind.Unspecified).AddTicks(ticks); - if(offset < -1440 || offset > 1440) offset = 0; + if(offset < -1440 || + offset > 1440) + offset = 0; - return new DateTimeOffset(year, month, day, hour, minute, second, new TimeSpan(0, offset, 0)) - .AddTicks(ticks).DateTime; + return new DateTimeOffset(year, month, day, hour, minute, second, new TimeSpan(0, offset, 0)). + AddTicks(ticks).DateTime; } - /// - /// Convers a Solaris high resolution timestamp to .NET DateTime - /// + /// Convers a Solaris high resolution timestamp to .NET DateTime /// Solaris high resolution timestamp /// .NET DateTime public static DateTime UnixHrTimeToDateTime(ulong hrTimeStamp) => UnixEpoch.AddTicks((long)(hrTimeStamp / 100)); - /// - /// Converts an OS-9 timestamp to .NET DateTime - /// + /// Converts an OS-9 timestamp to .NET DateTime /// OS-9 timestamp /// .NET DateTime public static DateTime Os9ToDateTime(byte[] date) { - if(date == null || date.Length != 3 && date.Length != 5) return DateTime.MinValue; + if(date == null || + date.Length != 3 && date.Length != 5) + return DateTime.MinValue; DateTime os9Date; try { - 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); + 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); + } + catch(ArgumentOutOfRangeException) + { + os9Date = new DateTime(1900, 0, 0, 0, 0, 0); } - catch(ArgumentOutOfRangeException) { os9Date = new DateTime(1900, 0, 0, 0, 0, 0); } return os9Date; } - /// - /// Converts a LIF timestamp to .NET DateTime - /// + /// Converts a LIF timestamp to .NET DateTime /// LIF timestamp /// .NET DateTime public static DateTime LifToDateTime(byte[] date) { - if(date == null || date.Length != 6) return new DateTime(1970, 1, 1, 0, 0, 0); + if(date == null || + date.Length != 6) + return new DateTime(1970, 1, 1, 0, 0, 0); return LifToDateTime(date[0], date[1], date[2], date[3], date[4], date[5]); } - /// - /// Converts a LIF timestamp to .NET DateTime - /// + /// Converts a LIF timestamp to .NET DateTime /// Yer /// Month /// Day @@ -367,12 +370,17 @@ public static DateTime LifToDateTime(byte year, byte month, byte day, byte hour, int ihour = (hour >> 4) * 10 + (hour & 0xF); int isecond = (second >> 4) * 10 + (second & 0xF); - if(iyear >= 70) iyear += 1900; - else iyear += 2000; + if(iyear >= 70) + iyear += 1900; + else + iyear += 2000; return new DateTime(iyear, imonth, iday, ihour, iminute, isecond); } - catch(ArgumentOutOfRangeException) { return new DateTime(1970, 1, 1, 0, 0, 0); } + catch(ArgumentOutOfRangeException) + { + return new DateTime(1970, 1, 1, 0, 0, 0); + } } } } \ No newline at end of file diff --git a/Marshal.cs b/Marshal.cs index 2a54e64fd..0a3a50c88 100644 --- a/Marshal.cs +++ b/Marshal.cs @@ -40,36 +40,30 @@ namespace DiscImageChef.Helpers /// Provides methods to marshal binary data into C# structs public static class Marshal { - /// - /// Returns the size of an unmanaged type in bytes. - /// + /// Returns the size of an unmanaged type in bytes. /// The type whose size is to be returned. /// The size, in bytes, of the type that is specified by the generic type parameter. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int SizeOf() - { - return System.Runtime.InteropServices.Marshal.SizeOf(); - } + public static int SizeOf() => System.Runtime.InteropServices.Marshal.SizeOf(); - /// - /// Marshal little-endian binary data to a structure - /// + /// Marshal little-endian binary data to a structure /// Byte array containing the binary data /// Type of the structure to marshal /// The binary data marshalled in a structure with the specified type [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T ByteArrayToStructureLittleEndian(byte[] bytes) where T : struct { - var ptr = GCHandle.Alloc(bytes, GCHandleType.Pinned); + GCHandle ptr = GCHandle.Alloc(bytes, GCHandleType.Pinned); + var str = - (T) System.Runtime.InteropServices.Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(T)); + (T)System.Runtime.InteropServices.Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(T)); + ptr.Free(); + return str; } - /// - /// Marshal little-endian binary data to a structure - /// + /// Marshal little-endian binary data to a structure /// Byte array containing the binary data /// Start on the array where the structure begins /// Length of the structure in bytes @@ -79,28 +73,28 @@ public static T ByteArrayToStructureLittleEndian(byte[] bytes) where T : stru public static T ByteArrayToStructureLittleEndian(byte[] bytes, int start, int length) where T : struct { Span span = bytes; + return ByteArrayToStructureLittleEndian(span.Slice(start, length).ToArray()); } - /// - /// Marshal big-endian binary data to a structure - /// + /// Marshal big-endian binary data to a structure /// Byte array containing the binary data /// Type of the structure to marshal /// The binary data marshalled in a structure with the specified type [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T ByteArrayToStructureBigEndian(byte[] bytes) where T : struct { - var ptr = GCHandle.Alloc(bytes, GCHandleType.Pinned); + GCHandle ptr = GCHandle.Alloc(bytes, GCHandleType.Pinned); + object str = - (T) System.Runtime.InteropServices.Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(T)); + (T)System.Runtime.InteropServices.Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(T)); + ptr.Free(); - return (T) SwapStructureMembersEndian(str); + + return(T)SwapStructureMembersEndian(str); } - /// - /// Marshal big-endian binary data to a structure - /// + /// Marshal big-endian binary data to a structure /// Byte array containing the binary data /// Start on the array where the structure begins /// Length of the structure in bytes @@ -110,12 +104,11 @@ public static T ByteArrayToStructureBigEndian(byte[] bytes) where T : struct public static T ByteArrayToStructureBigEndian(byte[] bytes, int start, int length) where T : struct { Span span = bytes; + return ByteArrayToStructureBigEndian(span.Slice(start, length).ToArray()); } - /// - /// Marshal PDP-11 binary data to a structure - /// + /// Marshal PDP-11 binary data to a structure /// Byte array containing the binary data /// Type of the structure to marshal /// The binary data marshalled in a structure with the specified type @@ -123,17 +116,18 @@ public static T ByteArrayToStructureBigEndian(byte[] bytes, int start, int le public static T ByteArrayToStructurePdpEndian(byte[] bytes) where T : struct { { - var ptr = GCHandle.Alloc(bytes, GCHandleType.Pinned); + GCHandle ptr = GCHandle.Alloc(bytes, GCHandleType.Pinned); + object str = - (T) System.Runtime.InteropServices.Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(T)); + (T)System.Runtime.InteropServices.Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(T)); + ptr.Free(); - return (T) SwapStructureMembersEndianPdp(str); + + return(T)SwapStructureMembersEndianPdp(str); } } - /// - /// Marshal PDP-11 binary data to a structure - /// + /// Marshal PDP-11 binary data to a structure /// Byte array containing the binary data /// Start on the array where the structure begins /// Length of the structure in bytes @@ -143,25 +137,24 @@ public static T ByteArrayToStructurePdpEndian(byte[] bytes) where T : struct public static T ByteArrayToStructurePdpEndian(byte[] bytes, int start, int length) where T : struct { Span span = bytes; + return ByteArrayToStructurePdpEndian(span.Slice(start, length).ToArray()); } /// - /// Marshal little-endian binary data to a structure. If the structure type contains any non value type, this method - /// will crash. + /// Marshal little-endian binary data to a structure. If the structure type contains any non value type, this + /// method will crash. /// /// Byte array containing the binary data /// Type of the structure to marshal /// The binary data marshalled in a structure with the specified type [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static T SpanToStructureLittleEndian(ReadOnlySpan bytes) where T : struct - { - return MemoryMarshal.Read(bytes); - } + public static T SpanToStructureLittleEndian(ReadOnlySpan bytes) where T : struct => + MemoryMarshal.Read(bytes); /// - /// Marshal little-endian binary data to a structure. If the structure type contains any non value type, this method - /// will crash. + /// Marshal little-endian binary data to a structure. If the structure type contains any non value type, this + /// method will crash. /// /// Byte span containing the binary data /// Start on the span where the structure begins @@ -170,14 +163,11 @@ public static T SpanToStructureLittleEndian(ReadOnlySpan bytes) where T /// The binary data marshalled in a structure with the specified type [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T SpanToStructureLittleEndian(ReadOnlySpan bytes, int start, int length) - where T : struct - { - return MemoryMarshal.Read(bytes.Slice(start, length)); - } + where T : struct => MemoryMarshal.Read(bytes.Slice(start, length)); /// - /// Marshal big-endian binary data to a structure. If the structure type contains any non value type, this method will - /// crash. + /// Marshal big-endian binary data to a structure. If the structure type contains any non value type, this method + /// will crash. /// /// Byte array containing the binary data /// Type of the structure to marshal @@ -186,12 +176,13 @@ public static T SpanToStructureLittleEndian(ReadOnlySpan bytes, int sta public static T SpanToStructureBigEndian(ReadOnlySpan bytes) where T : struct { var str = SpanToStructureLittleEndian(bytes); - return (T) SwapStructureMembersEndian(str); + + return(T)SwapStructureMembersEndian(str); } /// - /// Marshal big-endian binary data to a structure. If the structure type contains any non value type, this method will - /// crash. + /// Marshal big-endian binary data to a structure. If the structure type contains any non value type, this method + /// will crash. /// /// Byte span containing the binary data /// Start on the span where the structure begins @@ -202,7 +193,8 @@ public static T SpanToStructureBigEndian(ReadOnlySpan bytes) where T : public static T SpanToStructureBigEndian(ReadOnlySpan bytes, int start, int length) where T : struct { var str = SpanToStructureLittleEndian(bytes.Slice(start, length)); - return (T) SwapStructureMembersEndian(str); + + return(T)SwapStructureMembersEndian(str); } /// @@ -216,7 +208,8 @@ public static T SpanToStructureBigEndian(ReadOnlySpan bytes, int start, public static T SpanToStructurePdpEndian(ReadOnlySpan bytes) where T : struct { object str = SpanToStructureLittleEndian(bytes); - return (T) SwapStructureMembersEndianPdp(str); + + return(T)SwapStructureMembersEndianPdp(str); } /// @@ -230,12 +223,13 @@ public static T SpanToStructurePdpEndian(ReadOnlySpan bytes) where T : public static T SpanToStructurePdpEndian(ReadOnlySpan bytes, int start, int length) where T : struct { object str = SpanToStructureLittleEndian(bytes.Slice(start, length)); - return (T) SwapStructureMembersEndianPdp(str); + + return(T)SwapStructureMembersEndianPdp(str); } /// - /// Marshal a structure depending on the decoration of . If the decoration - /// is not present it will marshal as a reference type containing little endian structure. + /// Marshal a structure depending on the decoration of . If the + /// decoration is not present it will marshal as a reference type containing little endian structure. /// /// Byte array containing the binary data /// Type of the structure to marshal @@ -247,111 +241,116 @@ public static T SpanToStructurePdpEndian(ReadOnlySpan bytes, int start, [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T MarshalStructure(byte[] bytes) where T : struct { - if (!(typeof(T).GetCustomAttribute(typeof(MarshallingPropertiesAttribute)) is MarshallingPropertiesAttribute - properties)) return ByteArrayToStructureLittleEndian(bytes); + if(!(typeof(T).GetCustomAttribute(typeof(MarshallingPropertiesAttribute)) is MarshallingPropertiesAttribute + properties)) + return ByteArrayToStructureLittleEndian(bytes); - switch (properties.Endian) + switch(properties.Endian) { case BitEndian.Little: - return properties.HasReferences - ? ByteArrayToStructureLittleEndian(bytes) - : SpanToStructureLittleEndian(bytes); + return properties.HasReferences ? ByteArrayToStructureLittleEndian(bytes) + : SpanToStructureLittleEndian(bytes); break; case BitEndian.Big: - return properties.HasReferences - ? ByteArrayToStructureBigEndian(bytes) - : SpanToStructureBigEndian(bytes); + return properties.HasReferences ? ByteArrayToStructureBigEndian(bytes) + : SpanToStructureBigEndian(bytes); break; case BitEndian.Pdp: - return properties.HasReferences - ? ByteArrayToStructurePdpEndian(bytes) - : SpanToStructurePdpEndian(bytes); + return properties.HasReferences ? ByteArrayToStructurePdpEndian(bytes) + : SpanToStructurePdpEndian(bytes); default: throw new ArgumentOutOfRangeException(); } } - /// - /// Swaps all members of a structure - /// + /// Swaps all members of a structure /// /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static object SwapStructureMembersEndian(object str) { - var t = str.GetType(); - var fieldInfo = t.GetFields(); - foreach (var fi in fieldInfo) - if (fi.FieldType == typeof(short)) + Type t = str.GetType(); + FieldInfo[] fieldInfo = t.GetFields(); + + foreach(FieldInfo fi in fieldInfo) + if(fi.FieldType == typeof(short)) { - var x = (short) fi.GetValue(str); - fi.SetValue(str, (short) ((x << 8) | ((x >> 8) & 0xFF))); + short x = (short)fi.GetValue(str); + fi.SetValue(str, (short)((x << 8) | ((x >> 8) & 0xFF))); } - else if (fi.FieldType == typeof(int)) + else if(fi.FieldType == typeof(int)) { - var x = (int) fi.GetValue(str); - x = (int) (((x << 8) & 0xFF00FF00) | (((uint) x >> 8) & 0xFF00FF)); - fi.SetValue(str, (int) (((uint) x << 16) | (((uint) x >> 16) & 0xFFFF))); + int x = (int)fi.GetValue(str); + x = (int)(((x << 8) & 0xFF00FF00) | (((uint)x >> 8) & 0xFF00FF)); + fi.SetValue(str, (int)(((uint)x << 16) | (((uint)x >> 16) & 0xFFFF))); } - else if (fi.FieldType == typeof(long)) + else if(fi.FieldType == typeof(long)) { - var x = (long) fi.GetValue(str); - x = ((x & 0x00000000FFFFFFFF) << 32) | (long) (((ulong) x & 0xFFFFFFFF00000000) >> 32); - x = ((x & 0x0000FFFF0000FFFF) << 16) | (long) (((ulong) x & 0xFFFF0000FFFF0000) >> 16); - x = ((x & 0x00FF00FF00FF00FF) << 8) | (long) (((ulong) x & 0xFF00FF00FF00FF00) >> 8); + long x = (long)fi.GetValue(str); + x = ((x & 0x00000000FFFFFFFF) << 32) | (long)(((ulong)x & 0xFFFFFFFF00000000) >> 32); + x = ((x & 0x0000FFFF0000FFFF) << 16) | (long)(((ulong)x & 0xFFFF0000FFFF0000) >> 16); + x = ((x & 0x00FF00FF00FF00FF) << 8) | (long)(((ulong)x & 0xFF00FF00FF00FF00) >> 8); fi.SetValue(str, x); } - else if (fi.FieldType == typeof(ushort)) + else if(fi.FieldType == typeof(ushort)) { - var x = (ushort) fi.GetValue(str); - fi.SetValue(str, (ushort) ((x << 8) | (x >> 8))); + ushort x = (ushort)fi.GetValue(str); + fi.SetValue(str, (ushort)((x << 8) | (x >> 8))); } - else if (fi.FieldType == typeof(uint)) + else if(fi.FieldType == typeof(uint)) { - var x = (uint) fi.GetValue(str); - x = ((x << 8) & 0xFF00FF00) | ((x >> 8) & 0xFF00FF); - fi.SetValue(str, (x << 16) | (x >> 16)); + uint x = (uint)fi.GetValue(str); + x = ((x << 8) & 0xFF00FF00) | ((x >> 8) & 0xFF00FF); + fi.SetValue(str, (x << 16) | (x >> 16)); } - else if (fi.FieldType == typeof(ulong)) + else if(fi.FieldType == typeof(ulong)) { - var x = (ulong) fi.GetValue(str); + ulong x = (ulong)fi.GetValue(str); 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); fi.SetValue(str, x); } - else if (fi.FieldType == typeof(float)) + else if(fi.FieldType == typeof(float)) { - var flt = (float) fi.GetValue(str); - var flt_b = BitConverter.GetBytes(flt); - fi.SetValue(str, BitConverter.ToSingle(new[] {flt_b[3], flt_b[2], flt_b[1], flt_b[0]}, 0)); + float flt = (float)fi.GetValue(str); + byte[] flt_b = BitConverter.GetBytes(flt); + + fi.SetValue(str, BitConverter.ToSingle(new[] + { + flt_b[3], flt_b[2], flt_b[1], flt_b[0] + }, 0)); } - else if (fi.FieldType == typeof(double)) + else if(fi.FieldType == typeof(double)) { - var dbl = (double) fi.GetValue(str); - var dbl_b = BitConverter.GetBytes(dbl); - fi.SetValue(str, - BitConverter - .ToDouble( - new[] {dbl_b[7], dbl_b[6], dbl_b[5], dbl_b[4], dbl_b[3], dbl_b[2], dbl_b[1], dbl_b[0]}, - 0)); + double dbl = (double)fi.GetValue(str); + byte[] dbl_b = BitConverter.GetBytes(dbl); + + fi.SetValue(str, BitConverter.ToDouble(new[] + { + dbl_b[7], dbl_b[6], dbl_b[5], dbl_b[4], dbl_b[3], dbl_b[2], dbl_b[1], dbl_b[0] + }, 0)); } - else if (fi.FieldType == typeof(byte) || fi.FieldType == typeof(sbyte)) + else if(fi.FieldType == typeof(byte) || + fi.FieldType == typeof(sbyte)) { // Do nothing, can't byteswap them! } - else if (fi.FieldType == typeof(Guid)) + else if(fi.FieldType == typeof(Guid)) { // TODO: Swap GUID } + // TODO: Swap arrays and enums - else if (fi.FieldType.IsValueType && !fi.FieldType.IsEnum && !fi.FieldType.IsArray) + else if(fi.FieldType.IsValueType && + !fi.FieldType.IsEnum && + !fi.FieldType.IsArray) { - var obj = fi.GetValue(str); - var strc = SwapStructureMembersEndian(obj); + object obj = fi.GetValue(str); + object strc = SwapStructureMembersEndian(obj); fi.SetValue(str, strc); } @@ -361,49 +360,58 @@ public static object SwapStructureMembersEndian(object str) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static object SwapStructureMembersEndianPdp(object str) { - var t = str.GetType(); - var fieldInfo = t.GetFields(); - foreach (var fi in fieldInfo) - if (fi.FieldType == typeof(short) || fi.FieldType == typeof(long) || fi.FieldType == typeof(ushort) || - fi.FieldType == typeof(ulong) || fi.FieldType == typeof(float) || fi.FieldType == typeof(double) || - fi.FieldType == typeof(byte) || fi.FieldType == typeof(sbyte) || fi.FieldType == typeof(Guid)) + Type t = str.GetType(); + FieldInfo[] fieldInfo = t.GetFields(); + + foreach(FieldInfo fi in fieldInfo) + if(fi.FieldType == typeof(short) || + fi.FieldType == typeof(long) || + fi.FieldType == typeof(ushort) || + fi.FieldType == typeof(ulong) || + fi.FieldType == typeof(float) || + fi.FieldType == typeof(double) || + fi.FieldType == typeof(byte) || + fi.FieldType == typeof(sbyte) || + fi.FieldType == typeof(Guid)) { // Do nothing } - else if (fi.FieldType == typeof(int)) + else if(fi.FieldType == typeof(int)) { - var x = (int) fi.GetValue(str); + int x = (int)fi.GetValue(str); fi.SetValue(str, ((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16)); } - else if (fi.FieldType == typeof(uint)) + else if(fi.FieldType == typeof(uint)) { - var x = (uint) fi.GetValue(str); + uint x = (uint)fi.GetValue(str); fi.SetValue(str, ((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16)); } + // TODO: Swap arrays and enums - else if (fi.FieldType.IsValueType && !fi.FieldType.IsEnum && !fi.FieldType.IsArray) + else if(fi.FieldType.IsValueType && + !fi.FieldType.IsEnum && + !fi.FieldType.IsArray) { - var obj = fi.GetValue(str); - var strc = SwapStructureMembersEndianPdp(obj); + object obj = fi.GetValue(str); + object strc = SwapStructureMembersEndianPdp(obj); fi.SetValue(str, strc); } return str; } - /// - /// Marshal a structure to little-endian binary data - /// + /// Marshal a structure to little-endian binary data /// Byte array containing the binary data /// Type of the structure to marshal /// The binary data marshalled in a structure with the specified type [MethodImpl(MethodImplOptions.AggressiveInlining)] public static byte[] StructureToByteArrayLittleEndian(T str) where T : struct { - var buf = new byte[SizeOf()]; - var ptr = GCHandle.Alloc(buf, GCHandleType.Pinned); + byte[] buf = new byte[SizeOf()]; + GCHandle ptr = GCHandle.Alloc(buf, GCHandleType.Pinned); System.Runtime.InteropServices.Marshal.StructureToPtr(str, ptr.AddrOfPinnedObject(), false); ptr.Free(); + return buf; } } diff --git a/MarshallingPropertiesAttribute.cs b/MarshallingPropertiesAttribute.cs index 110185a80..e131e720d 100644 --- a/MarshallingPropertiesAttribute.cs +++ b/MarshallingPropertiesAttribute.cs @@ -40,19 +40,10 @@ namespace DiscImageChef.Helpers { - /// - /// Defines properties to help marshalling structs from binary data - /// + /// Defines properties to help marshalling structs from binary data [AttributeUsage(AttributeTargets.Struct)] public class MarshallingPropertiesAttribute : Attribute { - /// c - public BitEndian Endian { get; } - /// - /// Tells if the structure, or any nested structure, has any non-value type (e.g. arrays, strings, etc). - /// - public bool HasReferences { get; set; } - /// Defines properties to help marshalling structs from binary data /// Defines properties to help marshalling structs from binary data public MarshallingPropertiesAttribute(BitEndian endian) @@ -60,5 +51,10 @@ public MarshallingPropertiesAttribute(BitEndian endian) Endian = endian; HasReferences = true; } + + /// c + public BitEndian Endian { get; } + /// Tells if the structure, or any nested structure, has any non-value type (e.g. arrays, strings, etc). + public bool HasReferences { get; set; } } } \ No newline at end of file diff --git a/PrintHex.cs b/PrintHex.cs index 9f79092b3..8a5e583b4 100644 --- a/PrintHex.cs +++ b/PrintHex.cs @@ -55,11 +55,11 @@ public static string ByteArrayToHexArrayString(byte[] array, int width = 16, boo // TODO: Color list // TODO: Allow to change width - string str = "Offset"; - int rows = array.Length / 16; - int last = array.Length % 16; - int offsetLength = $"{array.Length:X}".Length; - var sb = new StringBuilder(); + string str = "Offset"; + int rows = array.Length / 16; + int last = array.Length % 16; + int offsetLength = $"{array.Length:X}".Length; + var sb = new StringBuilder(); if(last == 0) last = 16; @@ -101,7 +101,7 @@ public static string ByteArrayToHexArrayString(byte[] array, int width = 16, boo sb.Append("\u001b[0m"); sb.Append(" "); - int lastBytes = i == rows - 1 ? last : 16; + int lastBytes = i == rows - 1 ? last : 16; int lastSpaces = 16 - lastBytes; for(int j = 0; j < lastBytes; j++) diff --git a/StringHandlers.cs b/StringHandlers.cs index 7046e1d3f..b32d8664e 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -37,16 +37,12 @@ namespace DiscImageChef { public static class StringHandlers { - /// - /// Converts a null-terminated (aka C string) ASCII byte array to a C# string - /// + /// Converts a null-terminated (aka C string) ASCII byte array to a C# string /// The corresponding C# string /// A null-terminated (aka C string) ASCII byte array public static string CToString(byte[] CString) => CToString(CString, Encoding.ASCII); - /// - /// Converts a null-terminated (aka C string) byte array with the specified encoding to a C# string - /// + /// Converts a null-terminated (aka C string) byte array with the specified encoding to a C# string /// The corresponding C# string /// A null-terminated (aka C string) byte array in the specified encoding /// Encoding. @@ -54,7 +50,8 @@ public static class StringHandlers /// Start decodint at this position public static string CToString(byte[] CString, Encoding encoding, bool twoBytes = false, int start = 0) { - if(CString == null) return null; + if(CString == null) + return null; int len = 0; @@ -63,9 +60,11 @@ public static string CToString(byte[] CString, Encoding encoding, bool twoBytes if(CString[i] == 0) if(twoBytes) { - if(i + 1 < CString.Length && CString[i + 1] == 0) + if(i + 1 < CString.Length && + CString[i + 1] == 0) { len++; + break; } } @@ -75,7 +74,8 @@ public static string CToString(byte[] CString, Encoding encoding, bool twoBytes len++; } - if(twoBytes && len % 2 > 0) len--; + if(twoBytes && len % 2 > 0) + len--; byte[] dest = new byte[len]; Array.Copy(CString, start, dest, 0, len); @@ -83,30 +83,28 @@ public static string CToString(byte[] CString, Encoding encoding, bool twoBytes return len == 0 ? "" : encoding.GetString(dest); } - /// - /// Converts a length-prefixed (aka Pascal string) ASCII byte array to a C# string - /// + /// Converts a length-prefixed (aka Pascal string) ASCII byte array to a C# string /// The corresponding C# string /// A length-prefixed (aka Pascal string) ASCII byte array public static string PascalToString(byte[] PascalString) => PascalToString(PascalString, Encoding.ASCII); - /// - /// Converts a length-prefixed (aka Pascal string) ASCII byte array to a C# string - /// + /// Converts a length-prefixed (aka Pascal string) ASCII byte array to a C# string /// The corresponding C# string /// A length-prefixed (aka Pascal string) ASCII byte array /// Encoding. /// Start decodint at this position public static string PascalToString(byte[] PascalString, Encoding encoding, int start = 0) { - if(PascalString == null) return null; + if(PascalString == null) + return null; byte length = PascalString[start]; int len = 0; for(int i = start + 1; i < length + 1 && i < PascalString.Length; i++) { - if(PascalString[i] == 0) break; + if(PascalString[i] == 0) + break; len++; } @@ -117,43 +115,41 @@ public static string PascalToString(byte[] PascalString, Encoding encoding, int return len == 0 ? "" : encoding.GetString(dest); } - /// - /// Converts a space (' ', 0x20, ASCII SPACE) padded ASCII byte array to a C# string - /// + /// Converts a space (' ', 0x20, ASCII SPACE) padded ASCII byte array to a C# string /// The corresponding C# string /// A space (' ', 0x20, ASCII SPACE) padded ASCII byte array public static string SpacePaddedToString(byte[] SpacePaddedString) => SpacePaddedToString(SpacePaddedString, Encoding.ASCII); - /// - /// Converts a space (' ', 0x20, ASCII SPACE) padded ASCII byte array to a C# string - /// + /// Converts a space (' ', 0x20, ASCII SPACE) padded ASCII byte array to a C# string /// The corresponding C# string /// A space (' ', 0x20, ASCII SPACE) padded ASCII byte array /// Encoding. /// Start decodint at this position public static string SpacePaddedToString(byte[] SpacePaddedString, Encoding encoding, int start = 0) { - if(SpacePaddedString == null) return null; + if(SpacePaddedString == null) + return null; int len = start; for(int i = SpacePaddedString.Length; i >= start; i--) { - if(i == start) return ""; + if(i == start) + return""; - if(SpacePaddedString[i - 1] == 0x20) continue; + if(SpacePaddedString[i - 1] == 0x20) + continue; len = i; + break; } return len == 0 ? "" : encoding.GetString(SpacePaddedString, start, len); } - /// - /// Converts an OSTA compressed unicode byte array to a C# string - /// + /// Converts an OSTA compressed unicode byte array to a C# string /// The C# string. /// OSTA compressed unicode byte array. public static string DecompressUnicode(byte[] dstring) @@ -162,16 +158,22 @@ public static string DecompressUnicode(byte[] dstring) byte compId = dstring[0]; string temp = ""; - if(compId != 8 && compId != 16) return null; + 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; + if(compId == 16) + unicode = (ushort)(dstring[byteIndex++] << 8); + else + unicode = 0; - if(byteIndex < dstring.Length) unicode |= dstring[byteIndex++]; + if(byteIndex < dstring.Length) + unicode |= dstring[byteIndex++]; - if(unicode == 0) break; + if(unicode == 0) + break; temp += Encoding.Unicode.GetString(BitConverter.GetBytes(unicode)); } diff --git a/Swapping.cs b/Swapping.cs index 2b0103680..51c884276 100644 --- a/Swapping.cs +++ b/Swapping.cs @@ -52,14 +52,16 @@ public static class Swapping public static uint Swap(uint x) { x = ((x << 8) & 0xFF00FF00) | ((x >> 8) & 0xFF00FF); - return (x << 16) | (x >> 16); + + return(x << 16) | (x >> 16); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Swap(int x) { 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)); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -68,6 +70,7 @@ public static ulong Swap(ulong x) x = ((x & 0x00000000FFFFFFFF) << 32) | ((x & 0xFFFFFFFF00000000) >> 32); x = ((x & 0x0000FFFF0000FFFF) << 16) | ((x & 0xFFFF0000FFFF0000) >> 16); x = ((x & 0x00FF00FF00FF00FF) << 8) | ((x & 0xFF00FF00FF00FF00) >> 8); + return x; } @@ -77,6 +80,7 @@ public static long Swap(long x) x = ((x & 0x00000000FFFFFFFF) << 32) | (long)(((ulong)x & 0xFFFFFFFF00000000) >> 32); x = ((x & 0x0000FFFF0000FFFF) << 16) | (long)(((ulong)x & 0xFFFF0000FFFF0000) >> 16); x = ((x & 0x00FF00FF00FF00FF) << 8) | (long)(((ulong)x & 0xFF00FF00FF00FF00) >> 8); + return x; } } From 0fb1781ca217228819338e94f82989633fd40aba Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Fri, 3 Jan 2020 17:51:29 +0000 Subject: [PATCH 109/217] Update copyright date. --- ArrayFill.cs | 2 +- ArrayIsEmpty.cs | 2 +- BigEndianBitConverter.cs | 2 +- BitEndian.cs | 2 +- CHS.cs | 2 +- CompareBytes.cs | 2 +- CountBits.cs | 2 +- DateHandlers.cs | 2 +- DiscImageChef.Helpers.csproj | 2 +- Marshal.cs | 2 +- MarshallingPropertiesAttribute.cs | 2 +- PrintHex.cs | 2 +- StringHandlers.cs | 2 +- Swapping.cs | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ArrayFill.cs b/ArrayFill.cs index 7435ce9d9..1e38eab2e 100644 --- a/ArrayFill.cs +++ b/ArrayFill.cs @@ -20,7 +20,7 @@ // Assuming open source. // // ---------------------------------------------------------------------------- -// Copyright © 2011-2019 Natalia Portillo +// Copyright © 2011-2020 Natalia Portillo // Copyright(C) 2014 mykohsu // ****************************************************************************/ diff --git a/ArrayIsEmpty.cs b/ArrayIsEmpty.cs index 5d2ed6d06..e2e583730 100644 --- a/ArrayIsEmpty.cs +++ b/ArrayIsEmpty.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2019 Natalia Portillo +// Copyright © 2011-2020 Natalia Portillo // ****************************************************************************/ using System.Linq; diff --git a/BigEndianBitConverter.cs b/BigEndianBitConverter.cs index c71f188c3..8167082bf 100644 --- a/BigEndianBitConverter.cs +++ b/BigEndianBitConverter.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2019 Natalia Portillo +// Copyright © 2011-2020 Natalia Portillo // ****************************************************************************/ using System; diff --git a/BitEndian.cs b/BitEndian.cs index c6e7aaf00..3008cbb85 100644 --- a/BitEndian.cs +++ b/BitEndian.cs @@ -33,7 +33,7 @@ // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // ---------------------------------------------------------------------------- -// Copyright © 2011-2019 Natalia Portillo +// Copyright © 2011-2020 Natalia Portillo // ****************************************************************************/ namespace DiscImageChef.Helpers diff --git a/CHS.cs b/CHS.cs index ef1e29944..0ca41482c 100644 --- a/CHS.cs +++ b/CHS.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2019 Natalia Portillo +// Copyright © 2011-2020 Natalia Portillo // ****************************************************************************/ namespace DiscImageChef.Helpers diff --git a/CompareBytes.cs b/CompareBytes.cs index c8970253e..5cd42099f 100644 --- a/CompareBytes.cs +++ b/CompareBytes.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2019 Natalia Portillo +// Copyright © 2011-2020 Natalia Portillo // ****************************************************************************/ namespace DiscImageChef diff --git a/CountBits.cs b/CountBits.cs index f85254bc6..d583d658c 100644 --- a/CountBits.cs +++ b/CountBits.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2019 Natalia Portillo +// Copyright © 2011-2020 Natalia Portillo // ****************************************************************************/ namespace DiscImageChef.Helpers diff --git a/DateHandlers.cs b/DateHandlers.cs index e0ed69056..ddfdf28c7 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2019 Natalia Portillo +// Copyright © 2011-2020 Natalia Portillo // ****************************************************************************/ using System; diff --git a/DiscImageChef.Helpers.csproj b/DiscImageChef.Helpers.csproj index 5a1ddf17a..44f9c257c 100644 --- a/DiscImageChef.Helpers.csproj +++ b/DiscImageChef.Helpers.csproj @@ -13,7 +13,7 @@ true 4.5.99.1693 Claunia.com - Copyright © 2011-2019 Natalia Portillo + Copyright © 2011-2020 Natalia Portillo The Disc Image Chef DiscImageChef.Helpers $(Version) diff --git a/Marshal.cs b/Marshal.cs index a62abd2d2..6beaa1855 100644 --- a/Marshal.cs +++ b/Marshal.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2019 Natalia Portillo +// Copyright © 2011-2020 Natalia Portillo // ****************************************************************************/ using System; diff --git a/MarshallingPropertiesAttribute.cs b/MarshallingPropertiesAttribute.cs index e131e720d..abc10695b 100644 --- a/MarshallingPropertiesAttribute.cs +++ b/MarshallingPropertiesAttribute.cs @@ -33,7 +33,7 @@ // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // ---------------------------------------------------------------------------- -// Copyright © 2011-2019 Natalia Portillo +// Copyright © 2011-2020 Natalia Portillo // ****************************************************************************/ using System; diff --git a/PrintHex.cs b/PrintHex.cs index 8a5e583b4..34069abff 100644 --- a/PrintHex.cs +++ b/PrintHex.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2019 Natalia Portillo +// Copyright © 2011-2020 Natalia Portillo // ****************************************************************************/ using System.Text; diff --git a/StringHandlers.cs b/StringHandlers.cs index b32d8664e..3f2bcce7d 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2019 Natalia Portillo +// Copyright © 2011-2020 Natalia Portillo // ****************************************************************************/ using System; diff --git a/Swapping.cs b/Swapping.cs index 51c884276..e1389eff1 100644 --- a/Swapping.cs +++ b/Swapping.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2019 Natalia Portillo +// Copyright © 2011-2020 Natalia Portillo // ****************************************************************************/ using System.Runtime.CompilerServices; From 0f4820e123c5af1f8780f9bf53366ae36f7e60aa Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 30 Jan 2020 21:51:04 +0000 Subject: [PATCH 110/217] Fix hex printing of non-16-byte multiple data. --- PrintHex.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/PrintHex.cs b/PrintHex.cs index 34069abff..4669b6ee1 100644 --- a/PrintHex.cs +++ b/PrintHex.cs @@ -61,6 +61,9 @@ public static string ByteArrayToHexArrayString(byte[] array, int width = 16, boo int offsetLength = $"{array.Length:X}".Length; var sb = new StringBuilder(); + if(last > 0) + rows++; + if(last == 0) last = 16; @@ -119,7 +122,7 @@ public static string ByteArrayToHexArrayString(byte[] array, int width = 16, boo for(int j = 0; j < lastBytes; j++) { int v = array[b]; - sb.Append(v > 31 && v < 127 || v > 159 ? (char)v : '.'); + sb.Append((v > 31 && v < 127) || v > 159 ? (char)v : '.'); b++; } From 035605d86937ca36b399938bf4f8f8a271fa66bb Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 19 Feb 2020 01:08:34 +0000 Subject: [PATCH 111/217] Add support to swap endian of struct enums. --- Marshal.cs | 49 +++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/Marshal.cs b/Marshal.cs index 6beaa1855..f59d0925a 100644 --- a/Marshal.cs +++ b/Marshal.cs @@ -53,10 +53,9 @@ public static class Marshal [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T ByteArrayToStructureLittleEndian(byte[] bytes) where T : struct { - GCHandle ptr = GCHandle.Alloc(bytes, GCHandleType.Pinned); + var ptr = GCHandle.Alloc(bytes, GCHandleType.Pinned); - var str = - (T)System.Runtime.InteropServices.Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(T)); + var str = (T)System.Runtime.InteropServices.Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(T)); ptr.Free(); @@ -84,10 +83,9 @@ public static T ByteArrayToStructureLittleEndian(byte[] bytes, int start, int [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T ByteArrayToStructureBigEndian(byte[] bytes) where T : struct { - GCHandle ptr = GCHandle.Alloc(bytes, GCHandleType.Pinned); + var ptr = GCHandle.Alloc(bytes, GCHandleType.Pinned); - object str = - (T)System.Runtime.InteropServices.Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(T)); + object str = (T)System.Runtime.InteropServices.Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(T)); ptr.Free(); @@ -116,7 +114,7 @@ public static T ByteArrayToStructureBigEndian(byte[] bytes, int start, int le public static T ByteArrayToStructurePdpEndian(byte[] bytes) where T : struct { { - GCHandle ptr = GCHandle.Alloc(bytes, GCHandleType.Pinned); + var ptr = GCHandle.Alloc(bytes, GCHandleType.Pinned); object str = (T)System.Runtime.InteropServices.Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(T)); @@ -175,7 +173,7 @@ public static T SpanToStructureLittleEndian(ReadOnlySpan bytes, int sta [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T SpanToStructureBigEndian(ReadOnlySpan bytes) where T : struct { - var str = SpanToStructureLittleEndian(bytes); + T str = SpanToStructureLittleEndian(bytes); return(T)SwapStructureMembersEndian(str); } @@ -192,7 +190,7 @@ public static T SpanToStructureBigEndian(ReadOnlySpan bytes) where T : [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T SpanToStructureBigEndian(ReadOnlySpan bytes, int start, int length) where T : struct { - var str = SpanToStructureLittleEndian(bytes.Slice(start, length)); + T str = SpanToStructureLittleEndian(bytes.Slice(start, length)); return(T)SwapStructureMembersEndian(str); } @@ -255,7 +253,6 @@ public static T MarshalStructure(byte[] bytes) where T : struct return properties.HasReferences ? ByteArrayToStructureBigEndian(bytes) : SpanToStructureBigEndian(bytes); - case BitEndian.Pdp: return properties.HasReferences ? ByteArrayToStructurePdpEndian(bytes) : SpanToStructurePdpEndian(bytes); @@ -273,18 +270,21 @@ public static object SwapStructureMembersEndian(object str) FieldInfo[] fieldInfo = t.GetFields(); foreach(FieldInfo fi in fieldInfo) - if(fi.FieldType == typeof(short)) + if(fi.FieldType == typeof(short) || + (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(short))) { short x = (short)fi.GetValue(str); fi.SetValue(str, (short)((x << 8) | ((x >> 8) & 0xFF))); } - else if(fi.FieldType == typeof(int)) + else if(fi.FieldType == typeof(int) || + (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(int))) { int x = (int)fi.GetValue(str); x = (int)(((x << 8) & 0xFF00FF00) | (((uint)x >> 8) & 0xFF00FF)); fi.SetValue(str, (int)(((uint)x << 16) | (((uint)x >> 16) & 0xFFFF))); } - else if(fi.FieldType == typeof(long)) + else if(fi.FieldType == typeof(long) || + (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(long))) { long x = (long)fi.GetValue(str); x = ((x & 0x00000000FFFFFFFF) << 32) | (long)(((ulong)x & 0xFFFFFFFF00000000) >> 32); @@ -293,18 +293,21 @@ public static object SwapStructureMembersEndian(object str) fi.SetValue(str, x); } - else if(fi.FieldType == typeof(ushort)) + else if(fi.FieldType == typeof(ushort) || + (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(ushort))) { ushort x = (ushort)fi.GetValue(str); fi.SetValue(str, (ushort)((x << 8) | (x >> 8))); } - else if(fi.FieldType == typeof(uint)) + else if(fi.FieldType == typeof(uint) || + (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(uint))) { uint x = (uint)fi.GetValue(str); x = ((x << 8) & 0xFF00FF00) | ((x >> 8) & 0xFF00FF); fi.SetValue(str, (x << 16) | (x >> 16)); } - else if(fi.FieldType == typeof(ulong)) + else if(fi.FieldType == typeof(ulong) || + (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(ulong))) { ulong x = (ulong)fi.GetValue(str); x = ((x & 0x00000000FFFFFFFF) << 32) | ((x & 0xFFFFFFFF00000000) >> 32); @@ -342,7 +345,7 @@ public static object SwapStructureMembersEndian(object str) // TODO: Swap GUID } - // TODO: Swap arrays and enums + // TODO: Swap arrays else if(fi.FieldType.IsValueType && !fi.FieldType.IsEnum && !fi.FieldType.IsArray) @@ -374,18 +377,20 @@ public static object SwapStructureMembersEndianPdp(object str) { // Do nothing } - else if(fi.FieldType == typeof(int)) + else if(fi.FieldType == typeof(int) || + (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(int))) { int x = (int)fi.GetValue(str); fi.SetValue(str, ((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16)); } - else if(fi.FieldType == typeof(uint)) + else if(fi.FieldType == typeof(uint) || + (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(uint))) { uint x = (uint)fi.GetValue(str); fi.SetValue(str, ((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16)); } - // TODO: Swap arrays and enums + // TODO: Swap arrays else if(fi.FieldType.IsValueType && !fi.FieldType.IsEnum && !fi.FieldType.IsArray) @@ -405,8 +410,8 @@ public static object SwapStructureMembersEndianPdp(object str) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static byte[] StructureToByteArrayLittleEndian(T str) where T : struct { - byte[] buf = new byte[SizeOf()]; - GCHandle ptr = GCHandle.Alloc(buf, GCHandleType.Pinned); + byte[] buf = new byte[SizeOf()]; + var ptr = GCHandle.Alloc(buf, GCHandleType.Pinned); System.Runtime.InteropServices.Marshal.StructureToPtr(str, ptr.AddrOfPinnedObject(), false); ptr.Free(); From f277078318aed643dc8e3289eadaa77aee8f4a2b Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 19 Feb 2020 03:30:39 +0000 Subject: [PATCH 112/217] Add method to marshal big-endian structure into byte array. --- Marshal.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Marshal.cs b/Marshal.cs index f59d0925a..4070a0dad 100644 --- a/Marshal.cs +++ b/Marshal.cs @@ -417,5 +417,13 @@ public static byte[] StructureToByteArrayLittleEndian(T str) where T : struct return buf; } + + /// Marshal a structure to little-endian binary data + /// Byte array containing the binary data + /// Type of the structure to marshal + /// The binary data marshalled in a structure with the specified type + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static byte[] StructureToByteArrayBigEndian(T str) where T : struct => + StructureToByteArrayLittleEndian((T)SwapStructureMembersEndian(str)); } } \ No newline at end of file From 13010087fbcacbffae7a61c283552a39c4c2c11f Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 26 Feb 2020 19:10:08 +0000 Subject: [PATCH 113/217] Renamed project file --- DiscImageChef.Helpers.csproj => Aaru.Helpers.csproj | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename DiscImageChef.Helpers.csproj => Aaru.Helpers.csproj (100%) diff --git a/DiscImageChef.Helpers.csproj b/Aaru.Helpers.csproj similarity index 100% rename from DiscImageChef.Helpers.csproj rename to Aaru.Helpers.csproj From 85407751cbe0d8dd843b5e6dcb5ffe3c3f509614 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 26 Feb 2020 19:19:26 +0000 Subject: [PATCH 114/217] Fix references. --- Aaru.Helpers.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index 44f9c257c..599cce53f 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -61,7 +61,7 @@ - + {CCAA7AFE-C094-4D82-A66D-630DE8A3F545} DiscImageChef.Console From bce9d5b1dc8b2591262f6a5664fcf79f3ef75312 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 26 Feb 2020 19:24:05 +0000 Subject: [PATCH 115/217] Rename assemblies. --- Aaru.Helpers.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index 599cce53f..552f664cb 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -7,7 +7,7 @@ {F8BDF57B-1571-4CD0-84B3-B422088D359A} Library DiscImageChef.Helpers - DiscImageChef.Helpers + Aaru.Helpers $(Version) false true From c8e7a167b73c115586d790e377ddab015e7616cd Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 27 Feb 2020 00:33:24 +0000 Subject: [PATCH 116/217] Rename namespace. --- Aaru.Helpers.csproj | 2 +- ArrayFill.cs | 2 +- ArrayIsEmpty.cs | 2 +- BigEndianBitConverter.cs | 2 +- BitEndian.cs | 2 +- CHS.cs | 2 +- CompareBytes.cs | 2 +- CountBits.cs | 2 +- DateHandlers.cs | 4 ++-- Marshal.cs | 2 +- MarshallingPropertiesAttribute.cs | 2 +- PrintHex.cs | 4 ++-- StringHandlers.cs | 2 +- Swapping.cs | 2 +- 14 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index 552f664cb..f8cc5d7c6 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -6,7 +6,7 @@ 2.0 {F8BDF57B-1571-4CD0-84B3-B422088D359A} Library - DiscImageChef.Helpers + Aaru.Helpers Aaru.Helpers $(Version) false diff --git a/ArrayFill.cs b/ArrayFill.cs index 1e38eab2e..8967c98b7 100644 --- a/ArrayFill.cs +++ b/ArrayFill.cs @@ -27,7 +27,7 @@ using System; using System.Text; -namespace DiscImageChef +namespace Aaru { public static partial class ArrayHelpers { diff --git a/ArrayIsEmpty.cs b/ArrayIsEmpty.cs index e2e583730..01819ce76 100644 --- a/ArrayIsEmpty.cs +++ b/ArrayIsEmpty.cs @@ -32,7 +32,7 @@ using System.Linq; -namespace DiscImageChef +namespace Aaru { public static partial class ArrayHelpers { diff --git a/BigEndianBitConverter.cs b/BigEndianBitConverter.cs index 8167082bf..323ae7d1f 100644 --- a/BigEndianBitConverter.cs +++ b/BigEndianBitConverter.cs @@ -33,7 +33,7 @@ using System; using System.Linq; -namespace DiscImageChef +namespace Aaru { /// /// Converts base data types to an array of bytes, and an array of bytes to base data types. All info taken from diff --git a/BitEndian.cs b/BitEndian.cs index 3008cbb85..8a3d3fd0c 100644 --- a/BitEndian.cs +++ b/BitEndian.cs @@ -36,7 +36,7 @@ // Copyright © 2011-2020 Natalia Portillo // ****************************************************************************/ -namespace DiscImageChef.Helpers +namespace Aaru.Helpers { /// Describes the endianness of bits on a data structure public enum BitEndian diff --git a/CHS.cs b/CHS.cs index 0ca41482c..211f5be6a 100644 --- a/CHS.cs +++ b/CHS.cs @@ -30,7 +30,7 @@ // Copyright © 2011-2020 Natalia Portillo // ****************************************************************************/ -namespace DiscImageChef.Helpers +namespace Aaru.Helpers { public static class CHS { diff --git a/CompareBytes.cs b/CompareBytes.cs index 5cd42099f..c6c1e6e1b 100644 --- a/CompareBytes.cs +++ b/CompareBytes.cs @@ -30,7 +30,7 @@ // Copyright © 2011-2020 Natalia Portillo // ****************************************************************************/ -namespace DiscImageChef +namespace Aaru { public static partial class ArrayHelpers { diff --git a/CountBits.cs b/CountBits.cs index d583d658c..6fb66298f 100644 --- a/CountBits.cs +++ b/CountBits.cs @@ -30,7 +30,7 @@ // Copyright © 2011-2020 Natalia Portillo // ****************************************************************************/ -namespace DiscImageChef.Helpers +namespace Aaru.Helpers { public static class CountBits { diff --git a/DateHandlers.cs b/DateHandlers.cs index ddfdf28c7..ad5805ba7 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -32,9 +32,9 @@ using System; using System.Text; -using DiscImageChef.Console; +using Aaru.Console; -namespace DiscImageChef +namespace Aaru { public static class DateHandlers { diff --git a/Marshal.cs b/Marshal.cs index 4070a0dad..62c1e633d 100644 --- a/Marshal.cs +++ b/Marshal.cs @@ -35,7 +35,7 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -namespace DiscImageChef.Helpers +namespace Aaru.Helpers { /// Provides methods to marshal binary data into C# structs public static class Marshal diff --git a/MarshallingPropertiesAttribute.cs b/MarshallingPropertiesAttribute.cs index abc10695b..ca014382f 100644 --- a/MarshallingPropertiesAttribute.cs +++ b/MarshallingPropertiesAttribute.cs @@ -38,7 +38,7 @@ using System; -namespace DiscImageChef.Helpers +namespace Aaru.Helpers { /// Defines properties to help marshalling structs from binary data [AttributeUsage(AttributeTargets.Struct)] diff --git a/PrintHex.cs b/PrintHex.cs index 4669b6ee1..9771ed027 100644 --- a/PrintHex.cs +++ b/PrintHex.cs @@ -31,9 +31,9 @@ // ****************************************************************************/ using System.Text; -using DiscImageChef.Console; +using Aaru.Console; -namespace DiscImageChef +namespace Aaru { public static class PrintHex { diff --git a/StringHandlers.cs b/StringHandlers.cs index 3f2bcce7d..a3cd1d39c 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -33,7 +33,7 @@ using System; using System.Text; -namespace DiscImageChef +namespace Aaru { public static class StringHandlers { diff --git a/Swapping.cs b/Swapping.cs index e1389eff1..af22c4da6 100644 --- a/Swapping.cs +++ b/Swapping.cs @@ -32,7 +32,7 @@ using System.Runtime.CompilerServices; -namespace DiscImageChef +namespace Aaru { public static class Swapping { From 9f2dfcf4a378054acdc72d0ebcadf27af613fef6 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 27 Feb 2020 00:39:32 +0000 Subject: [PATCH 117/217] Rename references in project files. --- Aaru.Helpers.csproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index f8cc5d7c6..ecdf6c67c 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -14,8 +14,8 @@ 4.5.99.1693 Claunia.com Copyright © 2011-2020 Natalia Portillo - The Disc Image Chef - DiscImageChef.Helpers + Aaru Media Preservation Suite + Aaru.Helpers $(Version) net461;netstandard2.0;netcoreapp2.0 @@ -63,7 +63,7 @@ {CCAA7AFE-C094-4D82-A66D-630DE8A3F545} - DiscImageChef.Console + Aaru.Console @@ -79,7 +79,7 @@ - + From 6814431be469dc2ca38afd785ec67152f11e7acf Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 27 Feb 2020 11:27:51 +0000 Subject: [PATCH 118/217] Rename media to data. --- Aaru.Helpers.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index ecdf6c67c..8bfe4df7d 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -14,7 +14,7 @@ 4.5.99.1693 Claunia.com Copyright © 2011-2020 Natalia Portillo - Aaru Media Preservation Suite + Aaru Data Preservation Suite Aaru.Helpers $(Version) net461;netstandard2.0;netcoreapp2.0 @@ -79,7 +79,7 @@ - + From feead08c5ecfc886b40f6e605d77fa9c007d85af Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 27 Feb 2020 12:31:23 +0000 Subject: [PATCH 119/217] Rename comment header. --- ArrayFill.cs | 2 +- ArrayIsEmpty.cs | 2 +- BigEndianBitConverter.cs | 2 +- BitEndian.cs | 2 +- CHS.cs | 2 +- CompareBytes.cs | 2 +- CountBits.cs | 2 +- DateHandlers.cs | 2 +- Marshal.cs | 2 +- MarshallingPropertiesAttribute.cs | 2 +- PrintHex.cs | 2 +- StringHandlers.cs | 2 +- Swapping.cs | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/ArrayFill.cs b/ArrayFill.cs index 8967c98b7..cc4091dca 100644 --- a/ArrayFill.cs +++ b/ArrayFill.cs @@ -1,5 +1,5 @@ // /*************************************************************************** -// The Disc Image Chef +// Aaru Data Preservation Suite // ---------------------------------------------------------------------------- // // Filename : ArrayFill.cs diff --git a/ArrayIsEmpty.cs b/ArrayIsEmpty.cs index 01819ce76..eb6fbb141 100644 --- a/ArrayIsEmpty.cs +++ b/ArrayIsEmpty.cs @@ -1,5 +1,5 @@ // /*************************************************************************** -// The Disc Image Chef +// Aaru Data Preservation Suite // ---------------------------------------------------------------------------- // // Filename : ArrayIsEmpty.cs diff --git a/BigEndianBitConverter.cs b/BigEndianBitConverter.cs index 323ae7d1f..157e67717 100644 --- a/BigEndianBitConverter.cs +++ b/BigEndianBitConverter.cs @@ -1,5 +1,5 @@ // /*************************************************************************** -// The Disc Image Chef +// Aaru Data Preservation Suite // ---------------------------------------------------------------------------- // // Filename : BigEndianBitConverter.cs diff --git a/BitEndian.cs b/BitEndian.cs index 8a3d3fd0c..73c3869ce 100644 --- a/BitEndian.cs +++ b/BitEndian.cs @@ -1,5 +1,5 @@ // /*************************************************************************** -// The Disc Image Chef +// Aaru Data Preservation Suite // ---------------------------------------------------------------------------- // // Filename : BitEndian.cs diff --git a/CHS.cs b/CHS.cs index 211f5be6a..a7e411159 100644 --- a/CHS.cs +++ b/CHS.cs @@ -1,5 +1,5 @@ // /*************************************************************************** -// The Disc Image Chef +// Aaru Data Preservation Suite // ---------------------------------------------------------------------------- // // Filename : CHS.cs diff --git a/CompareBytes.cs b/CompareBytes.cs index c6c1e6e1b..d250c70c1 100644 --- a/CompareBytes.cs +++ b/CompareBytes.cs @@ -1,5 +1,5 @@ // /*************************************************************************** -// The Disc Image Chef +// Aaru Data Preservation Suite // ---------------------------------------------------------------------------- // // Filename : CompareBytes.cs diff --git a/CountBits.cs b/CountBits.cs index 6fb66298f..80f64b560 100644 --- a/CountBits.cs +++ b/CountBits.cs @@ -1,5 +1,5 @@ // /*************************************************************************** -// The Disc Image Chef +// Aaru Data Preservation Suite // ---------------------------------------------------------------------------- // // Filename : CountBits.cs diff --git a/DateHandlers.cs b/DateHandlers.cs index ad5805ba7..f650c4ecf 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -1,5 +1,5 @@ // /*************************************************************************** -// The Disc Image Chef +// Aaru Data Preservation Suite // ---------------------------------------------------------------------------- // // Filename : DateHandlers.cs diff --git a/Marshal.cs b/Marshal.cs index 62c1e633d..9da983d82 100644 --- a/Marshal.cs +++ b/Marshal.cs @@ -1,5 +1,5 @@ // /*************************************************************************** -// The Disc Image Chef +// Aaru Data Preservation Suite // ---------------------------------------------------------------------------- // // Filename : Marshal.cs diff --git a/MarshallingPropertiesAttribute.cs b/MarshallingPropertiesAttribute.cs index ca014382f..954488341 100644 --- a/MarshallingPropertiesAttribute.cs +++ b/MarshallingPropertiesAttribute.cs @@ -1,5 +1,5 @@ // /*************************************************************************** -// The Disc Image Chef +// Aaru Data Preservation Suite // ---------------------------------------------------------------------------- // // Filename : MarshallingPropertiesAttribute.cs diff --git a/PrintHex.cs b/PrintHex.cs index 9771ed027..71f7dac8d 100644 --- a/PrintHex.cs +++ b/PrintHex.cs @@ -1,5 +1,5 @@ // /*************************************************************************** -// The Disc Image Chef +// Aaru Data Preservation Suite // ---------------------------------------------------------------------------- // // Filename : PrintHex.cs diff --git a/StringHandlers.cs b/StringHandlers.cs index a3cd1d39c..6f7bc75a1 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -1,5 +1,5 @@ // /*************************************************************************** -// The Disc Image Chef +// Aaru Data Preservation Suite // ---------------------------------------------------------------------------- // // Filename : StringHandlers.cs diff --git a/Swapping.cs b/Swapping.cs index af22c4da6..8ba7cf6b9 100644 --- a/Swapping.cs +++ b/Swapping.cs @@ -1,5 +1,5 @@ // /*************************************************************************** -// The Disc Image Chef +// Aaru Data Preservation Suite // ---------------------------------------------------------------------------- // // Filename : Swapping.cs From e355423de626d7f22237706842f5ee8fa570b7a5 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 27 Feb 2020 23:48:40 +0000 Subject: [PATCH 120/217] Rename DicConsole to AaruConsole. --- DateHandlers.cs | 22 +++++++++++----------- PrintHex.cs | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/DateHandlers.cs b/DateHandlers.cs index f650c4ecf..afed05c88 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -107,7 +107,7 @@ public static DateTime Iso9660ToDateTime(byte[] vdDateTime) fourcharvalue[2] = vdDateTime[2]; fourcharvalue[3] = vdDateTime[3]; - DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "year = \"{0}\"", + AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "year = \"{0}\"", StringHandlers.CToString(fourcharvalue, Encoding.ASCII)); if(!int.TryParse(StringHandlers.CToString(fourcharvalue, Encoding.ASCII), out int year)) @@ -116,7 +116,7 @@ public static DateTime Iso9660ToDateTime(byte[] vdDateTime) twocharvalue[0] = vdDateTime[4]; twocharvalue[1] = vdDateTime[5]; - DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "month = \"{0}\"", + AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "month = \"{0}\"", StringHandlers.CToString(twocharvalue, Encoding.ASCII)); if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out int month)) @@ -125,7 +125,7 @@ public static DateTime Iso9660ToDateTime(byte[] vdDateTime) twocharvalue[0] = vdDateTime[6]; twocharvalue[1] = vdDateTime[7]; - DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "day = \"{0}\"", + AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "day = \"{0}\"", StringHandlers.CToString(twocharvalue, Encoding.ASCII)); if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out int day)) @@ -134,7 +134,7 @@ public static DateTime Iso9660ToDateTime(byte[] vdDateTime) twocharvalue[0] = vdDateTime[8]; twocharvalue[1] = vdDateTime[9]; - DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "hour = \"{0}\"", + AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "hour = \"{0}\"", StringHandlers.CToString(twocharvalue, Encoding.ASCII)); if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out int hour)) @@ -143,7 +143,7 @@ public static DateTime Iso9660ToDateTime(byte[] vdDateTime) twocharvalue[0] = vdDateTime[10]; twocharvalue[1] = vdDateTime[11]; - DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "minute = \"{0}\"", + AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "minute = \"{0}\"", StringHandlers.CToString(twocharvalue, Encoding.ASCII)); if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out int minute)) @@ -152,7 +152,7 @@ public static DateTime Iso9660ToDateTime(byte[] vdDateTime) twocharvalue[0] = vdDateTime[12]; twocharvalue[1] = vdDateTime[13]; - DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "second = \"{0}\"", + AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "second = \"{0}\"", StringHandlers.CToString(twocharvalue, Encoding.ASCII)); if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out int second)) @@ -161,13 +161,13 @@ public static DateTime Iso9660ToDateTime(byte[] vdDateTime) twocharvalue[0] = vdDateTime[14]; twocharvalue[1] = vdDateTime[15]; - DicConsole.DebugWriteLine("ISO9600ToDateTime handler", "hundredths = \"{0}\"", + AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "hundredths = \"{0}\"", StringHandlers.CToString(twocharvalue, Encoding.ASCII)); if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out int hundredths)) hundredths = 0; - DicConsole.DebugWriteLine("ISO9600ToDateTime handler", + AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "decodedDT = new DateTime({0}, {1}, {2}, {3}, {4}, {5}, {6}, DateTimeKind.Unspecified);", year, month, day, hour, minute, second, hundredths * 10); @@ -210,7 +210,7 @@ public static DateTime UcsdPascalToDateTime(short dateRecord) int day = (dateRecord & 0x01F0) >> 4; int month = dateRecord & 0x000F; - DicConsole.DebugWriteLine("UCSDPascalToDateTime handler", + AaruConsole.DebugWriteLine("UCSDPascalToDateTime handler", "dateRecord = 0x{0:X4}, year = {1}, month = {2}, day = {3}", dateRecord, year, month, day); @@ -230,10 +230,10 @@ public static DateTime DosToDateTime(ushort date, ushort time) int minute = (time & 0x7E0) >> 5; int second = (time & 0x1F) * 2; - DicConsole.DebugWriteLine("DOSToDateTime handler", "date = 0x{0:X4}, year = {1}, month = {2}, day = {3}", + AaruConsole.DebugWriteLine("DOSToDateTime handler", "date = 0x{0:X4}, year = {1}, month = {2}, day = {3}", date, year, month, day); - DicConsole.DebugWriteLine("DOSToDateTime handler", + AaruConsole.DebugWriteLine("DOSToDateTime handler", "time = 0x{0:X4}, hour = {1}, minute = {2}, second = {3}", time, hour, minute, second); diff --git a/PrintHex.cs b/PrintHex.cs index 71f7dac8d..95f116619 100644 --- a/PrintHex.cs +++ b/PrintHex.cs @@ -41,7 +41,7 @@ public static class PrintHex /// Array /// Width of line public static void PrintHexArray(byte[] array, int width = 16) => - DicConsole.WriteLine(ByteArrayToHexArrayString(array, width)); + AaruConsole.WriteLine(ByteArrayToHexArrayString(array, width)); /// Prints a byte array as hexadecimal values to a string /// Array From ad4bfdc0b5b678b819512dc1ce537859cc096b3c Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Fri, 28 Feb 2020 00:28:32 +0000 Subject: [PATCH 121/217] Rename references in gitignore. --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 2ad9e5199..05c540d38 100644 --- a/.gitignore +++ b/.gitignore @@ -590,6 +590,6 @@ pkg/**/*.asc pkg/**/*.sig pkg/**/*.tar.xz pkg/**/*.zip -pkg/**/discimagechef +pkg/**/aaru .sonarqube \ No newline at end of file From 0bc3b5c1fe21fe6cdad3d8a23b7db34f09aa8a2a Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sat, 29 Feb 2020 18:03:33 +0000 Subject: [PATCH 122/217] Code restyling. --- BitEndian.cs | 3 ++- CHS.cs | 4 ++-- CountBits.cs | 2 +- DateHandlers.cs | 46 +++++++++++++++++++++++----------------------- Marshal.cs | 12 ++++++------ StringHandlers.cs | 2 +- Swapping.cs | 4 ++-- 7 files changed, 37 insertions(+), 36 deletions(-) diff --git a/BitEndian.cs b/BitEndian.cs index 73c3869ce..96a35d563 100644 --- a/BitEndian.cs +++ b/BitEndian.cs @@ -42,7 +42,8 @@ namespace Aaru.Helpers public enum BitEndian { /// Little-endian, or least significant bit - Little, /// Big-endian, or most significant bit + Little, + /// Big-endian, or most significant bit Big, /// PDP-11 endian, little endian except for 32-bit integers where the 16 halves are swapped between them Pdp diff --git a/CHS.cs b/CHS.cs index a7e411159..f02554873 100644 --- a/CHS.cs +++ b/CHS.cs @@ -42,7 +42,7 @@ public static class CHS /// Number of sectors per track /// public static uint ToLBA(uint cyl, uint head, uint sector, uint maxHead, uint maxSector) => - maxHead == 0 || maxSector == 0 ? (cyl * 16 + head) * 63 + sector - 1 - : (cyl * maxHead + head) * maxSector + sector - 1; + maxHead == 0 || maxSector == 0 ? ((((cyl * 16) + head) * 63) + sector) - 1 + : ((((cyl * maxHead) + head) * maxSector) + sector) - 1; } } \ No newline at end of file diff --git a/CountBits.cs b/CountBits.cs index 80f64b560..60704df73 100644 --- a/CountBits.cs +++ b/CountBits.cs @@ -42,7 +42,7 @@ public static int Count(uint number) number = number - ((number >> 1) & 0x55555555); number = (number & 0x33333333) + ((number >> 2) & 0x33333333); - return(int)((((number + (number >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24); + return (int)((((number + (number >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24); } } } \ No newline at end of file diff --git a/DateHandlers.cs b/DateHandlers.cs index afed05c88..0b227c8a1 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -108,7 +108,7 @@ public static DateTime Iso9660ToDateTime(byte[] vdDateTime) fourcharvalue[3] = vdDateTime[3]; AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "year = \"{0}\"", - StringHandlers.CToString(fourcharvalue, Encoding.ASCII)); + StringHandlers.CToString(fourcharvalue, Encoding.ASCII)); if(!int.TryParse(StringHandlers.CToString(fourcharvalue, Encoding.ASCII), out int year)) year = 0; @@ -117,7 +117,7 @@ public static DateTime Iso9660ToDateTime(byte[] vdDateTime) twocharvalue[1] = vdDateTime[5]; AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "month = \"{0}\"", - StringHandlers.CToString(twocharvalue, Encoding.ASCII)); + StringHandlers.CToString(twocharvalue, Encoding.ASCII)); if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out int month)) month = 0; @@ -126,7 +126,7 @@ public static DateTime Iso9660ToDateTime(byte[] vdDateTime) twocharvalue[1] = vdDateTime[7]; AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "day = \"{0}\"", - StringHandlers.CToString(twocharvalue, Encoding.ASCII)); + StringHandlers.CToString(twocharvalue, Encoding.ASCII)); if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out int day)) day = 0; @@ -135,7 +135,7 @@ public static DateTime Iso9660ToDateTime(byte[] vdDateTime) twocharvalue[1] = vdDateTime[9]; AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "hour = \"{0}\"", - StringHandlers.CToString(twocharvalue, Encoding.ASCII)); + StringHandlers.CToString(twocharvalue, Encoding.ASCII)); if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out int hour)) hour = 0; @@ -144,7 +144,7 @@ public static DateTime Iso9660ToDateTime(byte[] vdDateTime) twocharvalue[1] = vdDateTime[11]; AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "minute = \"{0}\"", - StringHandlers.CToString(twocharvalue, Encoding.ASCII)); + StringHandlers.CToString(twocharvalue, Encoding.ASCII)); if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out int minute)) minute = 0; @@ -153,7 +153,7 @@ public static DateTime Iso9660ToDateTime(byte[] vdDateTime) twocharvalue[1] = vdDateTime[13]; AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "second = \"{0}\"", - StringHandlers.CToString(twocharvalue, Encoding.ASCII)); + StringHandlers.CToString(twocharvalue, Encoding.ASCII)); if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out int second)) second = 0; @@ -162,14 +162,14 @@ public static DateTime Iso9660ToDateTime(byte[] vdDateTime) twocharvalue[1] = vdDateTime[15]; AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "hundredths = \"{0}\"", - StringHandlers.CToString(twocharvalue, Encoding.ASCII)); + StringHandlers.CToString(twocharvalue, Encoding.ASCII)); if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out int hundredths)) hundredths = 0; AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", - "decodedDT = new DateTime({0}, {1}, {2}, {3}, {4}, {5}, {6}, DateTimeKind.Unspecified);", - year, month, day, hour, minute, second, hundredths * 10); + "decodedDT = new DateTime({0}, {1}, {2}, {3}, {4}, {5}, {6}, DateTimeKind.Unspecified);", + year, month, day, hour, minute, second, hundredths * 10); var decodedDt = new DateTime(year, month, day, hour, minute, second, hundredths * 10, DateTimeKind.Unspecified); @@ -211,8 +211,8 @@ public static DateTime UcsdPascalToDateTime(short dateRecord) int month = dateRecord & 0x000F; AaruConsole.DebugWriteLine("UCSDPascalToDateTime handler", - "dateRecord = 0x{0:X4}, year = {1}, month = {2}, day = {3}", dateRecord, year, - month, day); + "dateRecord = 0x{0:X4}, year = {1}, month = {2}, day = {3}", dateRecord, year, + month, day); return new DateTime(year, month, day); } @@ -231,11 +231,11 @@ public static DateTime DosToDateTime(ushort date, ushort time) int second = (time & 0x1F) * 2; AaruConsole.DebugWriteLine("DOSToDateTime handler", "date = 0x{0:X4}, year = {1}, month = {2}, day = {3}", - date, year, month, day); + date, year, month, day); AaruConsole.DebugWriteLine("DOSToDateTime handler", - "time = 0x{0:X4}, hour = {1}, minute = {2}, second = {3}", time, hour, minute, - second); + "time = 0x{0:X4}, hour = {1}, minute = {2}, second = {3}", time, hour, minute, + second); DateTime dosdate; @@ -285,8 +285,8 @@ public static DateTime EcmaToDateTime(ushort typeAndTimeZone, short year, byte m { 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); @@ -321,7 +321,7 @@ public static DateTime EcmaToDateTime(ushort typeAndTimeZone, short year, byte m public static DateTime Os9ToDateTime(byte[] date) { if(date == null || - date.Length != 3 && date.Length != 5) + (date.Length != 3 && date.Length != 5)) return DateTime.MinValue; DateTime os9Date; @@ -363,12 +363,12 @@ public static DateTime LifToDateTime(byte year, byte month, byte day, byte hour, { try { - 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 isecond = (second >> 4) * 10 + (second & 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 isecond = ((second >> 4) * 10) + (second & 0xF); if(iyear >= 70) iyear += 1900; diff --git a/Marshal.cs b/Marshal.cs index 9da983d82..58b449779 100644 --- a/Marshal.cs +++ b/Marshal.cs @@ -89,7 +89,7 @@ public static T ByteArrayToStructureBigEndian(byte[] bytes) where T : struct ptr.Free(); - return(T)SwapStructureMembersEndian(str); + return (T)SwapStructureMembersEndian(str); } /// Marshal big-endian binary data to a structure @@ -121,7 +121,7 @@ public static T ByteArrayToStructurePdpEndian(byte[] bytes) where T : struct ptr.Free(); - return(T)SwapStructureMembersEndianPdp(str); + return (T)SwapStructureMembersEndianPdp(str); } } @@ -175,7 +175,7 @@ public static T SpanToStructureBigEndian(ReadOnlySpan bytes) where T : { T str = SpanToStructureLittleEndian(bytes); - return(T)SwapStructureMembersEndian(str); + return (T)SwapStructureMembersEndian(str); } /// @@ -192,7 +192,7 @@ public static T SpanToStructureBigEndian(ReadOnlySpan bytes, int start, { T str = SpanToStructureLittleEndian(bytes.Slice(start, length)); - return(T)SwapStructureMembersEndian(str); + return (T)SwapStructureMembersEndian(str); } /// @@ -207,7 +207,7 @@ public static T SpanToStructurePdpEndian(ReadOnlySpan bytes) where T : { object str = SpanToStructureLittleEndian(bytes); - return(T)SwapStructureMembersEndianPdp(str); + return (T)SwapStructureMembersEndianPdp(str); } /// @@ -222,7 +222,7 @@ public static T SpanToStructurePdpEndian(ReadOnlySpan bytes, int start, { object str = SpanToStructureLittleEndian(bytes.Slice(start, length)); - return(T)SwapStructureMembersEndianPdp(str); + return (T)SwapStructureMembersEndianPdp(str); } /// diff --git a/StringHandlers.cs b/StringHandlers.cs index 6f7bc75a1..59e0a2567 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -136,7 +136,7 @@ public static string SpacePaddedToString(byte[] SpacePaddedString, Encoding enco for(int i = SpacePaddedString.Length; i >= start; i--) { if(i == start) - return""; + return ""; if(SpacePaddedString[i - 1] == 0x20) continue; diff --git a/Swapping.cs b/Swapping.cs index 8ba7cf6b9..d59117667 100644 --- a/Swapping.cs +++ b/Swapping.cs @@ -53,7 +53,7 @@ public static uint Swap(uint x) { x = ((x << 8) & 0xFF00FF00) | ((x >> 8) & 0xFF00FF); - return(x << 16) | (x >> 16); + return (x << 16) | (x >> 16); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -61,7 +61,7 @@ public static int Swap(int x) { 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)); } [MethodImpl(MethodImplOptions.AggressiveInlining)] From 397dfcd3929b85ebce7d340365075c7ad7e1cffd Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sat, 29 Feb 2020 18:33:56 +0000 Subject: [PATCH 123/217] Added editorconfig --- .editorconfig | 631 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 631 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..940c62067 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,631 @@ +root = true + +[*] +charset=utf-8 +next_line=crlf +insert_final_newline=false +indent_style=space +indent_size=4 + +# Generic non-language specific ones for Resharper and friends +brace_style=next_line +int_align=true +keep_existing_arrangement=false +place_simple_blocks_on_single_line=true +place_simple_declaration_blocks_on_single_line=true +place_attribute_on_same_line=false +space_after_unary_operator=false +space_after_comma=true +space_around_ternary_operator=true +space_around_binary_operator=true +space_around_member_access_operator=false +space_before_open_square_brackets=false +space_after_keywords_in_control_flow_statements=true +space_before_comma=false +space_between_method_call_name_and_opening_parenthesis=false +space_between_method_declaration_name_and_open_parenthesis=false +space_between_square_brackets=false +space_between_parentheses_of_control_flow_statements=false +accessor_owner_declaration_braces=next_line +accessor_declaration_braces=next_line +case_block_braces=next_line +initializer_braces=next_line +other_braces=next_line +allow_comment_after_lbrace=false +empty_block_style=together_same_line +braces_for_ifelse=not_required +braces_for_for=not_required +braces_for_foreach=not_required +braces_for_while=not_required +braces_for_dowhile=not_required +braces_for_using=not_required +braces_for_lock=not_required +braces_for_fixed=not_required +method_or_operator_body=expression_body +local_function_body=expression_body +constructor_or_destructor_body=expression_body +accessor_owner_body=expression_body +force_attribute_style=join +function_braces=next_line +force_control_statements_braces=always_remove +space_in_singleline_accessorholder=true +type_declaration_braces=next_line +invocable_declaration_braces=next_line +anonymous_method_declaration_braces=next_line +space_between_accessors_in_singleline_property=true +indent_nested_usings_stmt=true +space_within_empty_braces=false +indent_nested_fixed_stmt=true +indent_nested_lock_stmt=true +indent_nested_for_stmt=true +indent_nested_foreach_stmt=true +indent_nested_while_stmt=true +use_continuous_indent_inside_parens=true +indent_method_decl_pars=inside +indent_invocation_pars=inside +indent_statement_pars=inside +indent_typeparam_angles=inside +indent_typearg_angles=inside +indent_pars=inside +indent_preprocessor_if=outdent +indent_preprocessor_region=usual_indent +indent_preprocessor_other=usual_indent +indent_switch_labels=true +indent_type_constraints=true +stick_comment=false +alignment_tab_fill_style=use_spaces +align_multiline_parameter=true +align_multiline_extends_list=true +align_linq_query=true +align_multiline_binary_expressions_chain=true +outdent_binary_ops=true +align_multiline_calls_chain=true +outdent_dots=true +align_multiline_array_and_object_initializer=false +indent_anonymous_method_block=false +align_first_arg_by_paren=true +align_multiline_argument=true +align_tuple_components=true +align_multiline_expression=true +align_multiline_for_stmt=true +align_multiple_declaration=true +align_multline_type_parameter_list=true +align_multline_type_parameter_constrains=true +int_align_fields=true +int_align_properties=true +int_align_methods=true +int_align_parameters=false +int_align_variables=true +int_align_assignments=true +int_align_nested_ternary=true +int_align_invocations=false +int_align_binary_expressions=true +int_align_comments=true +int_align_switch_sections=true +keep_user_linebreaks=false +keep_existing_arrangement=false +keep_existing_linebreaks=false +max_line_length=120 +wrap_before_comma=false +special_else_if_treatment=true +place_type_attribute_on_same_line=never +place_method_attribute_on_same_line=never +place_accessorholder_attribute_on_same_line=never +place_attribute_on_same_line=never +place_accessor_attribute_on_same_line=never +place_attribute_on_same_line=never +place_field_attribute_on_same_line=never +place_attribute_on_same_line=never +wrap_parameters_style=wrap_if_long +keep_existing_declaration_parens_arrangement=false +wrap_before_declaration_lpar=false +wrap_after_declaration_lpar=false +wrap_before_declaration_rpar=false +place_constructor_initializer_on_same_line=true +keep_existing_expr_member_arrangement=false +place_expr_method_on_single_line=true +place_expr_property_on_single_line=true +place_expr_accessor_on_single_line=true +wrap_before_arrow_with_expressions=false +place_type_constraints_on_same_line=true +wrap_before_first_type_parameter_constraint=true +wrap_multiple_type_parameter_constraints_style=wrap_if_long +wrap_before_type_parameter_langle=true +wrap_before_extends_colon=false +wrap_extends_list_style=wrap_if_long +keep_existing_declaration_block_arrangement=false +place_abstract_accessorholder_on_single_line=true +place_simple_accessorholder_on_single_line=false +place_accessor_with_attrs_holder_on_single_line=false +place_simple_accessor_on_single_line=true +place_simple_method_on_single_line=false +keep_existing_enum_arrangement=false +place_simple_enum_on_single_line=false +wrap_enum_declaration=wrap_if_long +new_line_before_else=true +new_line_before_while=false +wrap_for_stmt_header_style=wrap_if_long +wrap_multiple_declaration_style=wrap_if_long +keep_existing_embedded_arrangement=false +place_simple_embedded_statement_on_same_line=false +place_simple_case_statement_on_same_line=true +keep_existing_embedded_block_arrangement=false +place_simple_embedded_block_on_same_line=false +place_simple_anonymousmethod_on_single_line=false +keep_existing_initializer_arrangement=false +place_simple_initializer_on_single_line=false +wrap_object_and_collection_initializer_style=wrap_if_long +wrap_array_initializer_style=wrap_if_long +wrap_arguments_style=wrap_if_long +keep_existing_invocation_parens_arrangement=false +wrap_after_invocation_lpar=false +wrap_before_invocation_rpar=false +wrap_after_dot_in_method_calls=true +wrap_chained_method_calls=wrap_if_long +wrap_before_binary_opsign=false +wrap_chained_binary_expressions=wrap_if_long +force_chop_compound_if_expression=true +force_chop_compound_while_expression=true +force_chop_compound_do_expression=true +wrap_before_ternary_opsigns=true +wrap_ternary_expr_style=wrap_if_long +nested_ternary_style=expanded +wrap_linq_expressions=wrap_if_long +wrap_before_linq_expression=false +place_linq_into_on_new_line=false +wrap_verbatim_interpolated_strings=wrap_if_long +extra_spaces=remove_all +space_after_keywords_in_control_flow_statements=false +space_between_method_call_name_and_opening_parenthesis=false +space_between_method_declaration_name_and_open_parenthesis=false +space_before_typeof_parentheses=false +space_before_checked_parentheses=false +space_before_sizeof_parentheses=false +space_before_nameof_parentheses=false +space_between_keyword_and_expression=true +space_between_keyword_and_type=true +space_around_assignment_op=true +space_around_logical_op=true +space_around_binary_operator=true +space_around_equality_op=true +space_around_relational_op=true +space_around_bitwise_op=true +space_around_additive_op=true +space_around_multiplicative_op=true +space_around_shift_op=true +space_around_nullcoalescing_op=true +space_around_arrow_op=false +space_after_logical_not_op=false +space_after_unary_operator=false +space_after_cast=false +space_around_dot=false +space_around_lambda_arrow=true +space_before_pointer_asterik_declaration=false +space_before_nullable_mark=false +blank_lines_around_class_definition=1 +namespace_indentation=all +space_within_template_argument=false +align_union_type_usage=true +space_in_singleline_method=true +space_in_singleline_anonymous_method=true +space_within_single_line_array_initializer_braces=true +space_around_arrow_op=false + +# These are for markup languages (HTML, XML, etc) +spaces_around_eq_in_pi_attribute=false +space_after_last_pi_attribute=true +pi_attributes_indent=align_by_first_attribute +blank_line_after_pi=true +spaces_around_eq_in_attribute=false +space_after_last_attribute=false +space_before_self_closing=true +attribute_style=on_single_line +attribute_indent=align_by_first_attribute +sort_attributes=true +sort_class_selectors=true +max_blank_lines_between_tags=0 +linebreak_before_all_elements=true +linebreak_before_multiline_elements=true +quote_style=doublequoted +delete_quotes_from_solid_values=false +normalize_tag_names=true + + +[{.babelrc,.stylelintrc,jest.config,.eslintrc,.prettierrc,*.json,*.jsb3,*.jsb2,*.bowerrc}] +indent_size=2 + +[*.js.map] +indent_size=2 + +[*.{css,scss}] +indent_size=2 +declarations_style=separate_lines_for_nonsingle +media_query_style=separate_lines +selector_style=same_line +properties_style=separate_lines_for_nonsingle +brace_style=next_line + +[{.analysis_options,*.yml,*.yaml}] +indent_size=2 + +# Xml project files +[*.{csproj,vcxproj,vcxproj.filters,proj,nativeproj,locproj}] +indent_size = 2 + +# Xml files +[*.{xml,stylecop,resx,ruleset}] +indent_size = 2 + +# Xml config files +[*.{props,targets,config,nuspec}] +indent_size = 2 + +# .net files +[*.{cs,vb}] +# These set the this. / Me. +dotnet_style_qualification_for_field=false:warning +dotnet_style_qualification_for_property=false:warning +dotnet_style_qualification_for_method=false:warning +dotnet_style_qualification_for_event=false:warning + +# These make it suggest Int32 instead of int, etc. +dotnet_style_predefined_type_for_locals_parameters_members=true:suggestion +dotnet_style_predefined_type_for_member_access=true:suggestion + +# This controls implicit access modifiers +dotnet_style_require_accessibility_modifiers=never:suggestion + +# Prefer non modified fields to be marked readonly +dotnet_style_readonly_field=true:warning + +# Parenthesis settings +dotnet_style_parentheses_in_arithmetic_binary_operators=always_for_clarity:warning +dotnet_style_parentheses_in_relational_binary_operators=always_for_clarity:warning +dotnet_style_parentheses_in_other_binary_operators=always_for_clarity:warning +dotnet_style_parentheses_in_other_operators=always_for_clarity:warning + +dotnet_style_object_initializer=true:suggestion +dotnet_style_collection_initializer=true:suggestion +dotnet_style_explicit_tuple_names=true:error +dotnet_style_prefer_inferred_tuple_names=true:warning +dotnet_style_prefer_inferred_anonymous_type_member_names=true:warning +dotnet_style_prefer_is_null_check_over_reference_equality_method=true:warning +dotnet_style_prefer_conditional_expression_over_return=true:warning +dotnet_style_coalesce_expression=true:warning +dotnet_style_null_propagation=true:error + +dotnet_sort_system_directives_first=true + +# Constants in C style, all-caps +dotnet_naming_rule.constant_fields_caps.symbols = constant_fields +dotnet_naming_rule.constant_fields_caps.severity = suggestion +dotnet_naming_rule.constant_fields_caps.style = caps_style +dotnet_naming_symbols.constant_fields.applicable_kinds = field +dotnet_naming_symbols.constant_fields.required_modifiers = const +dotnet_naming_style.caps_style.capitalization = all_upper + +# interfaces should be prefixed with I +dotnet_naming_rule.pascal_case_for_interface.severity = error +dotnet_naming_rule.pascal_case_for_interface.symbols = interfaces_fields +dotnet_naming_rule.pascal_case_for_interface.style = pascal_case_interface_style +dotnet_naming_symbols.interfaces_fields.applicable_kinds = interface +dotnet_naming_style.pascal_case_interface_style.required_prefix = I +dotnet_naming_style.pascal_case_interface_style.capitalization = pascal_case + +## internal and private fields should be _camelCase +dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion +dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields +dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style +dotnet_naming_symbols.private_internal_fields.applicable_kinds = field +dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal +dotnet_naming_style.camel_case_underscore_style.required_prefix = _ +dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case + +# 2018-12-07 NP: This is not yet working in VS2017 +# local variables should be camelCase +#dotnet_naming_rule.camel_case_for_locals.severity = suggestion +#dotnet_naming_rule.camel_case_for_locals.symbols = local_fields +#dotnet_naming_rule.camel_case_for_locals.style = camel_case_style +#dotnet_naming_symbols.local_fields.applicable_kinds = local +#dotnet_naming_style.camel_case_style.capitalization = camel_case + +[*.cs] +# var var var +csharp_style_var_for_built_in_types=false:warning +csharp_style_var_when_type_is_apparent=true:suggestion +csharp_style_var_elsewhere=false:warning + +csharp_style_expression_bodied_methods=when_on_single_line:suggestion +csharp_style_expression_bodied_constructors=when_on_single_line:suggestion +csharp_style_expression_bodied_operators=when_on_single_line:suggestion +csharp_style_expression_bodied_properties=when_on_single_line:suggestion +csharp_style_expression_bodied_indexers=when_on_single_line:suggestion +csharp_style_expression_bodied_accessors=when_on_single_line:suggestion + +csharp_style_pattern_matching_over_is_with_cast_check=true:warning +csharp_style_pattern_matching_over_as_with_null_check=when_on_single_line:warning + +csharp_style_inlined_variable_declaration=true:warning + +csharp_prefer_simple_default_expression=true:warning +csharp_style_deconstructed_variable_declaration=false:warning + +csharp_style_throw_expression=true:warning +csharp_style_conditional_delegate_call=true:warning + +csharp_prefer_braces=false + +csharp_new_line_before_open_brace=all +csharp_new_line_before_else=true +csharp_new_line_before_catch=true +csharp_new_line_before_finally=true +csharp_new_line_before_members_in_object_initializers=true +csharp_new_line_before_members_in_anonymous_types=true +csharp_new_line_between_query_expression_clauses=true + +csharp_indent_case_contents=true +csharp_indent_switch_labels=true +csharp_indent_labels=flush_left + +csharp_space_after_cast=false +csharp_space_after_keywords_in_control_flow_statements=false +csharp_space_between_method_declaration_parameter_list_parentheses=false +csharp_space_between_parentheses=none +csharp_space_before_colon_in_inheritance_clause=true +csharp_space_after_colon_in_inheritance_clause=true +csharp_space_around_binary_operators=before_and_after +csharp_space_between_method_declaration_empty_parameter_list_parentheses=false +csharp_space_between_method_call_name_and_opening_parenthesis=false +csharp_space_between_method_call_empty_parameter_list_parentheses=false + +csharp_preserve_single_line_statements=false +csharp_preserve_single_line_blocks=true + +csharp_blank_lines_around_region=0 +csharp_blank_lines_inside_region=0 +csharp_blank_lines_before_single_line_comment=1 +csharp_keep_blank_lines_in_declarations=1 +csharp_remove_blank_lines_near_braces_in_declarations=true +csharp_blank_lines_after_start_comment=false +csharp_blank_lines_between_using_groups=0 +csharp_blank_lines_after_using_list=1 +csharp_blank_lines_around_namespace=1 +csharp_blank_lines_inside_namespace=0 +csharp_blank_lines_around_type=1 +csharp_blank_lines_inside_type=0 +csharp_blank_lines_around_field=0 +csharp_blank_lines_around_single_line_field=0 +csharp_blank_lines_around_property=1 +csharp_blank_lines_around_single_line_property=0 +csharp_blank_lines_around_auto_property=0 +csharp_blank_lines_around_single_line_auto_property=0 +csharp_blank_lines_around_invocable=1 +csharp_blank_lines_around_single_line_invocable=1 +csharp_keep_blank_lines_in_code=1 +csharp_remove_blank_lines_near_braces_in_code=true +csharp_blank_lines_around_local_method=1 +csharp_blank_lines_around_single_line_local_method=1 +csharp_blank_lines_before_control_transfer_statements=1 +csharp_blank_lines_after_control_transfer_statements=1 +csharp_blank_lines_before_block_statements=1 +csharp_blank_lines_after_block_statements=1 +csharp_blank_lines_before_multiline_statements=1 +csharp_blank_lines_after_multiline_statements=1 + +csharp_type_declaration_braces=next_line +csharp_brace_style=next_line +csharp_indent_inside_namespace=true +csharp_invocable_declaration_braces=next_line +csharp_anonymous_method_declaration_braces=next_line +csharp_accessor_owner_declaration_braces=next_line +csharp_accessor_declaration_braces=next_line +csharp_case_block_braces=next_line +csharp_initializer_braces=next_line +csharp_other_braces=next_line +csharp_allow_comment_after_lbrace=false +csharp_empty_block_style=together_same_line + +csharp_for_built_in_types=use_explicit_type +csharp_for_simple_types=use_var_when_evident +csharp_for_other_types=use_explicit_type +csharp_prefer_separate_deconstructed_variables_declaration=true +csharp_prefer_explicit_discard_declaration=false + +csharp_instance_members_qualify_members=none +csharp_builtin_type_reference_style=use_keyword +csharp_prefer_qualified_reference=false +csharp_add_imports_to_deepest_scope=false +csharp_allow_alias=true +csharp_default_private_modifier=implicit +csharp_default_internal_modifier=explicit +csharp_arguments_literal=positional +csharp_arguments_string_literal=positional +csharp_arguments_named=positional +csharp_arguments_anonymous_function=positional +csharp_arguments_other=positional +csharp_braces_for_ifelse=not_required +csharp_braces_for_for=not_required +csharp_braces_for_foreach=not_required +csharp_braces_for_while=not_required +csharp_braces_for_dowhile=not_required +csharp_braces_for_using=not_required +csharp_braces_for_lock=not_required +csharp_braces_for_fixed=not_required +csharp_method_or_operator_body=expression_body +csharp_local_function_body=expression_body +csharp_constructor_or_destructor_body=expression_body +csharp_accessor_owner_body=expression_body +csharp_force_attribute_style=join +csharp_indent_nested_usings_stmt=true + +csharp_builtin_type_reference_for_member_access_style=use_keyword +csharp_indent_nested_fixed_stmt=true +csharp_indent_nested_lock_stmt=true +csharp_indent_nested_for_stmt=true +csharp_indent_nested_foreach_stmt=true +csharp_indent_nested_while_stmt=true +csharp_use_continuous_indent_inside_parens=true +csharp_indent_method_decl_pars=inside +csharp_indent_invocation_pars=inside +csharp_indent_statement_pars=inside +csharp_indent_typeparam_angles=inside +csharp_indent_typearg_angles=inside +csharp_indent_pars=inside +csharp_indent_preprocessor_if=outdent +csharp_indent_preprocessor_region=usual_indent +csharp_indent_preprocessor_other=usual_indent +csharp_indent_switch_labels=true +csharp_indent_type_constraints=true +csharp_stick_comment=false +csharp_alignment_tab_fill_style=use_spaces +csharp_align_multiline_parameter=true +csharp_align_multiline_extends_list=true +csharp_align_linq_query=true +csharp_align_multiline_binary_expressions_chain=true +csharp_outdent_binary_ops=true +csharp_align_multiline_calls_chain=true +csharp_outdent_dots=true +csharp_align_multiline_array_and_object_initializer=false +csharp_indent_anonymous_method_block=false +csharp_align_first_arg_by_paren=true +csharp_align_multiline_argument=true +csharp_align_tuple_components=true +csharp_align_multiline_expression=true +csharp_align_multiline_for_stmt=true +csharp_align_multiple_declaration=true +csharp_align_multline_type_parameter_list=true +csharp_align_multline_type_parameter_constrains=true +csharp_int_align_fields=true +csharp_int_align_properties=true +csharp_int_align_methods=true +csharp_int_align_parameters=false +csharp_int_align_variables=true +csharp_int_align_assignments=true +csharp_int_align_nested_ternary=true +csharp_int_align_invocations=false +csharp_int_align_binary_expressions=true +csharp_int_align_comments=true +csharp_int_align_switch_sections=true +csharp_keep_user_linebreaks=false +csharp_keep_existing_arrangement=false +csharp_keep_existing_linebreaks=false +csharp_max_line_length=120 +csharp_wrap_before_comma=false +csharp_special_else_if_treatment=true +csharp_insert_final_newline=false +csharp_place_type_attribute_on_same_line=never +csharp_place_method_attribute_on_same_line=never +csharp_place_accessorholder_attribute_on_same_line=never +csharp_place_attribute_on_same_line=never +csharp_place_accessor_attribute_on_same_line=never +csharp_place_attribute_on_same_line=never +csharp_place_field_attribute_on_same_line=never +csharp_place_attribute_on_same_line=never +csharp_wrap_parameters_style=wrap_if_long +csharp_keep_existing_declaration_parens_arrangement=false +csharp_wrap_before_declaration_lpar=false +csharp_wrap_after_declaration_lpar=false +csharp_wrap_before_declaration_rpar=false +csharp_place_constructor_initializer_on_same_line=true +csharp_keep_existing_expr_member_arrangement=false +csharp_place_expr_method_on_single_line=true +csharp_place_expr_property_on_single_line=true +csharp_place_expr_accessor_on_single_line=true +csharp_wrap_before_arrow_with_expressions=false +csharp_place_type_constraints_on_same_line=true +csharp_wrap_before_first_type_parameter_constraint=true +csharp_wrap_multiple_type_parameter_constraints_style=wrap_if_long +csharp_wrap_before_type_parameter_langle=true +csharp_wrap_before_extends_colon=false +csharp_wrap_extends_list_style=wrap_if_long +csharp_keep_existing_declaration_block_arrangement=false +csharp_place_abstract_accessorholder_on_single_line=true +csharp_place_simple_accessorholder_on_single_line=false +csharp_place_accessor_with_attrs_holder_on_single_line=false +csharp_place_simple_accessor_on_single_line=true +csharp_place_simple_method_on_single_line=false +csharp_keep_existing_enum_arrangement=false +csharp_place_simple_enum_on_single_line=false +csharp_wrap_enum_declaration=wrap_if_long +csharp_new_line_before_else=true +csharp_new_line_before_while=false +csharp_wrap_for_stmt_header_style=wrap_if_long +csharp_wrap_multiple_declaration_style=wrap_if_long +csharp_keep_existing_embedded_arrangement=false +csharp_place_simple_embedded_statement_on_same_line=false +csharp_place_simple_case_statement_on_same_line=true +csharp_keep_existing_embedded_block_arrangement=false +csharp_place_simple_embedded_block_on_same_line=false +csharp_place_simple_anonymousmethod_on_single_line=false +csharp_keep_existing_initializer_arrangement=false +csharp_place_simple_initializer_on_single_line=false +csharp_wrap_object_and_collection_initializer_style=wrap_if_long +csharp_wrap_array_initializer_style=wrap_if_long +csharp_wrap_arguments_style=wrap_if_long +csharp_keep_existing_invocation_parens_arrangement=false +csharp_wrap_after_invocation_lpar=false +csharp_wrap_before_invocation_rpar=false +csharp_wrap_after_dot_in_method_calls=true +csharp_wrap_chained_method_calls=wrap_if_long +csharp_wrap_before_binary_opsign=false +csharp_wrap_chained_binary_expressions=wrap_if_long +csharp_force_chop_compound_if_expression=true +csharp_force_chop_compound_while_expression=true +csharp_force_chop_compound_do_expression=true +csharp_wrap_before_ternary_opsigns=true +csharp_wrap_ternary_expr_style=wrap_if_long +csharp_nested_ternary_style=expanded +csharp_wrap_linq_expressions=wrap_if_long +csharp_wrap_before_linq_expression=false +csharp_place_linq_into_on_new_line=false +csharp_wrap_verbatim_interpolated_strings=wrap_if_long +csharp_extra_spaces=remove_all +csharp_space_after_keywords_in_control_flow_statements=false +csharp_space_between_method_call_name_and_opening_parenthesis=false +csharp_space_between_method_declaration_name_and_open_parenthesis=false +csharp_space_before_typeof_parentheses=false +csharp_space_before_checked_parentheses=false +csharp_space_before_sizeof_parentheses=false +csharp_space_before_nameof_parentheses=false +csharp_space_between_keyword_and_expression=true +csharp_space_between_keyword_and_type=true +csharp_space_around_assignment_op=true +csharp_space_around_logical_op=true +csharp_space_around_binary_operator=true +csharp_space_around_equality_op=true +csharp_space_around_relational_op=true +csharp_space_around_bitwise_op=true +csharp_space_around_additive_op=true +csharp_space_around_multiplicative_op=true +csharp_space_around_shift_op=true +csharp_space_around_nullcoalescing_op=true +csharp_space_around_arrow_op=false +csharp_space_after_logical_not_op=false +csharp_space_after_unary_operator=false +csharp_space_after_cast=false +csharp_space_around_dot=false +csharp_space_around_lambda_arrow=true +csharp_space_before_pointer_asterik_declaration=false +csharp_space_before_nullable_mark=false + +[*.cshtml] +linebreaks_around_razor_statements=true +blank_lines_around_razor_functions=true +blank_lines_around_razor_helpers=true +blank_lines_around_razor_sections=true + +# C++ +[*.{cc,cpp,cxx,h,hpp,hxx}] +cpp_indent_access_specifiers_from_class=true +cpp_indent_wrapped_function_names=false +cpp_align_multiline_type_argument=true + +# C, C++ and ObjectiveC +[*.{c,h,cc,cpp,cxx,m,hpp,hxx}] +indent_preprocessor_directives=normal +indent_type_constraints=true + +# Javascript and Typescript +[*.{js,js.map,ts}] +quote_style=doublequoted +termination_style=ensure_semicolon \ No newline at end of file From afa99999a8b9b668d79a539925240e222ff90bfa Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sat, 29 Feb 2020 18:41:35 +0000 Subject: [PATCH 124/217] UP version. --- Aaru.Helpers.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index 8bfe4df7d..a3efe2ae3 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -11,7 +11,7 @@ $(Version) false true - 4.5.99.1693 + 4.5.99.2020 Claunia.com Copyright © 2011-2020 Natalia Portillo Aaru Data Preservation Suite From ee1d5973e55c0682f214deb4601d97528c394a46 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 12 Mar 2020 00:09:30 +0000 Subject: [PATCH 125/217] Remove netstandard2.0 target. --- Aaru.Helpers.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index a3efe2ae3..914132a1c 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -17,7 +17,7 @@ Aaru Data Preservation Suite Aaru.Helpers $(Version) - net461;netstandard2.0;netcoreapp2.0 + net461;netcoreapp2.0 $(Version)-{chash:8} built by {mname} in $(Configuration){!:, modified} From 5de0e8a5e7a22cfffec62366b97fce361a8b67b0 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 12 Mar 2020 00:14:42 +0000 Subject: [PATCH 126/217] Move to .NET Core 2.1. --- Aaru.Helpers.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index 914132a1c..69998379f 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -17,7 +17,7 @@ Aaru Data Preservation Suite Aaru.Helpers $(Version) - net461;netcoreapp2.0 + net461;netcoreapp2.1 $(Version)-{chash:8} built by {mname} in $(Configuration){!:, modified} From cd3fe08e076225869c619009f33307a3f4eed390 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 12 Mar 2020 00:29:38 +0000 Subject: [PATCH 127/217] Fix warnings. --- Marshal.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Marshal.cs b/Marshal.cs index 58b449779..0f8899de7 100644 --- a/Marshal.cs +++ b/Marshal.cs @@ -381,13 +381,13 @@ public static object SwapStructureMembersEndianPdp(object str) (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(int))) { int x = (int)fi.GetValue(str); - fi.SetValue(str, ((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16)); + fi.SetValue(str, ((x & 0xffffu) << 16) | ((x & 0xffff0000u) >> 16)); } else if(fi.FieldType == typeof(uint) || (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(uint))) { uint x = (uint)fi.GetValue(str); - fi.SetValue(str, ((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16)); + fi.SetValue(str, ((x & 0xffffu) << 16) | ((x & 0xffff0000u) >> 16)); } // TODO: Swap arrays From 6899a92169fade4659dce3149e57fa15e4046d28 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 12 Mar 2020 00:32:53 +0000 Subject: [PATCH 128/217] Remove support for .NET Framework. --- Aaru.Helpers.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index 69998379f..c704b0487 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -17,7 +17,7 @@ Aaru Data Preservation Suite Aaru.Helpers $(Version) - net461;netcoreapp2.1 + netcoreapp2.1 $(Version)-{chash:8} built by {mname} in $(Configuration){!:, modified} From ad7314e234b7da1d847a99aeaf68ca65b3901fbe Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 15 Mar 2020 20:50:44 +0000 Subject: [PATCH 129/217] Release 5.0.0.2879. --- Aaru.Helpers.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index c704b0487..219ce7fca 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -11,7 +11,7 @@ $(Version) false true - 4.5.99.2020 + 5.0.0.2879 Claunia.com Copyright © 2011-2020 Natalia Portillo Aaru Data Preservation Suite From 97d450220a8208be0f782c6105811e82172fff2d Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 15 Mar 2020 22:02:33 +0000 Subject: [PATCH 130/217] Up version. --- Aaru.Helpers.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index 219ce7fca..c186aff34 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -11,7 +11,7 @@ $(Version) false true - 5.0.0.2879 + 5.1.99.2880 Claunia.com Copyright © 2011-2020 Natalia Portillo Aaru Data Preservation Suite From c3ab7ac7526c6821ff1856c7b5d3d9704230e24f Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 9 Apr 2020 01:30:40 +0100 Subject: [PATCH 131/217] Move to .NET Core 3.0. --- Aaru.Helpers.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index c186aff34..be0b8877b 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -17,7 +17,7 @@ Aaru Data Preservation Suite Aaru.Helpers $(Version) - netcoreapp2.1 + netcoreapp3.0 $(Version)-{chash:8} built by {mname} in $(Configuration){!:, modified} From e7c0f1b7f74c25695c1c893282e15f473be261d6 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Fri, 17 Apr 2020 23:30:12 +0100 Subject: [PATCH 132/217] Up version. --- Aaru.Helpers.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index be0b8877b..b8432025e 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -11,7 +11,7 @@ $(Version) false true - 5.1.99.2880 + 5.1.99.2967 Claunia.com Copyright © 2011-2020 Natalia Portillo Aaru Data Preservation Suite @@ -20,7 +20,7 @@ netcoreapp3.0 - $(Version)-{chash:8} built by {mname} in $(Configuration){!:, modified} + $(Version)+{chash:8} built by {mname} in $(Configuration){!:, modified} true true From 58540f76045cae710730dc5b64ae6c5c2d677563 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 23 Apr 2020 02:55:04 +0100 Subject: [PATCH 133/217] Up version to 5.1.99.2990. --- Aaru.Helpers.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index b8432025e..1684f3656 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -11,7 +11,7 @@ $(Version) false true - 5.1.99.2967 + 5.1.99.2990 Claunia.com Copyright © 2011-2020 Natalia Portillo Aaru Data Preservation Suite From f2b5d64d4ecce7223476483cd8e39280cefbf4e4 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 23 Apr 2020 02:58:26 +0100 Subject: [PATCH 134/217] Up version. --- Aaru.Helpers.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index 1684f3656..563dc0948 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -11,7 +11,7 @@ $(Version) false true - 5.1.99.2990 + 5.0.99.2991 Claunia.com Copyright © 2011-2020 Natalia Portillo Aaru Data Preservation Suite From 9abb9f23bc4796f908a71dc8b8baee2fd60963d5 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 14 Jun 2020 16:13:47 +0100 Subject: [PATCH 135/217] Update to .NET Core 3.1. --- Aaru.Helpers.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index 563dc0948..055c8cce7 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -17,7 +17,7 @@ Aaru Data Preservation Suite Aaru.Helpers $(Version) - netcoreapp3.0 + netcoreapp3.1 $(Version)+{chash:8} built by {mname} in $(Configuration){!:, modified} From 3bd05336bd339f3b82f710b4c445485d6d01d41c Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 14 Jun 2020 17:47:46 +0100 Subject: [PATCH 136/217] Update dependencies. --- Aaru.Helpers.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index 055c8cce7..b17e475c0 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -72,7 +72,7 @@ - + From a90513f70c16fc912149cd163616f8bd139d1377 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 12 Jul 2020 21:25:43 +0100 Subject: [PATCH 137/217] Fix conversion of ISO9660 to UTC. Fixes #366. --- DateHandlers.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/DateHandlers.cs b/DateHandlers.cs index 0b227c8a1..12fc10462 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -171,10 +171,13 @@ public static DateTime Iso9660ToDateTime(byte[] vdDateTime) "decodedDT = new DateTime({0}, {1}, {2}, {3}, {4}, {5}, {6}, DateTimeKind.Unspecified);", year, month, day, hour, minute, second, hundredths * 10); + sbyte difference = (sbyte)vdDateTime[16]; + var decodedDt = new DateTime(year, month, day, hour, minute, second, hundredths * 10, DateTimeKind.Unspecified); - return decodedDt; + // Convert ISO9660 time from GMT to UTC and remove the difference from GMT. Doing the removal first could cause problems if that makes it cross over a leap day, or a leap second + return TimeZoneInfo.ConvertTimeBySystemTimeZoneId(decodedDt, "GMT", "UTC").AddMinutes(difference * -15); } /// Converts a VMS timestamp to a .NET DateTime From 2e464b00e2fd66e05623b2e134d98071748c2f40 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 19 Jul 2020 21:44:31 +0100 Subject: [PATCH 138/217] Set language version to C# 8.0. --- Aaru.Helpers.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index b17e475c0..f33991510 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -18,6 +18,7 @@ Aaru.Helpers $(Version) netcoreapp3.1 + 8 $(Version)+{chash:8} built by {mname} in $(Configuration){!:, modified} From 9f8ef78cf492932cfb42b96add69890ff9ae4170 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 20 Jul 2020 04:33:39 +0100 Subject: [PATCH 139/217] Update editorconfig file. --- .editorconfig | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.editorconfig b/.editorconfig index 940c62067..c1ebeb20a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -154,7 +154,7 @@ place_simple_embedded_block_on_same_line=false place_simple_anonymousmethod_on_single_line=false keep_existing_initializer_arrangement=false place_simple_initializer_on_single_line=false -wrap_object_and_collection_initializer_style=wrap_if_long +wrap_object_and_collection_initializer_style=chop_always wrap_array_initializer_style=wrap_if_long wrap_arguments_style=wrap_if_long keep_existing_invocation_parens_arrangement=false @@ -506,6 +506,7 @@ csharp_int_align_invocations=false csharp_int_align_binary_expressions=true csharp_int_align_comments=true csharp_int_align_switch_sections=true +csharp_int_align=true csharp_keep_user_linebreaks=false csharp_keep_existing_arrangement=false csharp_keep_existing_linebreaks=false @@ -559,7 +560,7 @@ csharp_place_simple_embedded_block_on_same_line=false csharp_place_simple_anonymousmethod_on_single_line=false csharp_keep_existing_initializer_arrangement=false csharp_place_simple_initializer_on_single_line=false -csharp_wrap_object_and_collection_initializer_style=wrap_if_long +csharp_wrap_object_and_collection_initializer_style=chop_always csharp_wrap_array_initializer_style=wrap_if_long csharp_wrap_arguments_style=wrap_if_long csharp_keep_existing_invocation_parens_arrangement=false From 6c2685afbfa36b206954809b14e1c238a975a505 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 20 Jul 2020 05:57:36 +0100 Subject: [PATCH 140/217] Add missing XML documentation. --- Marshal.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Marshal.cs b/Marshal.cs index 0f8899de7..872b274b5 100644 --- a/Marshal.cs +++ b/Marshal.cs @@ -215,6 +215,8 @@ public static T SpanToStructurePdpEndian(ReadOnlySpan bytes) where T : /// crash. /// /// Byte array containing the binary data + /// Start on the span where the structure begins + /// Length of the structure in bytes /// Type of the structure to marshal /// The binary data marshalled in a structure with the specified type [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -404,9 +406,9 @@ public static object SwapStructureMembersEndianPdp(object str) } /// Marshal a structure to little-endian binary data - /// Byte array containing the binary data + /// The structure you want to marshal to binary /// Type of the structure to marshal - /// The binary data marshalled in a structure with the specified type + /// The byte array representing the given structure [MethodImpl(MethodImplOptions.AggressiveInlining)] public static byte[] StructureToByteArrayLittleEndian(T str) where T : struct { @@ -419,9 +421,9 @@ public static byte[] StructureToByteArrayLittleEndian(T str) where T : struct } /// Marshal a structure to little-endian binary data - /// Byte array containing the binary data + /// The structure you want to marshal to binary /// Type of the structure to marshal - /// The binary data marshalled in a structure with the specified type + /// The byte array representing the given structure [MethodImpl(MethodImplOptions.AggressiveInlining)] public static byte[] StructureToByteArrayBigEndian(T str) where T : struct => StructureToByteArrayLittleEndian((T)SwapStructureMembersEndian(str)); From 2f3b76cf5c06e9613bcdbab4b59fd96d0a6084cf Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 20 Jul 2020 15:43:52 +0100 Subject: [PATCH 141/217] Fix namespaces. --- ArrayFill.cs | 2 +- ArrayIsEmpty.cs | 2 +- BigEndianBitConverter.cs | 2 +- CompareBytes.cs | 2 +- DateHandlers.cs | 2 +- PrintHex.cs | 2 +- StringHandlers.cs | 2 +- Swapping.cs | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ArrayFill.cs b/ArrayFill.cs index cc4091dca..edd2545b4 100644 --- a/ArrayFill.cs +++ b/ArrayFill.cs @@ -27,7 +27,7 @@ using System; using System.Text; -namespace Aaru +namespace Aaru.Helpers { public static partial class ArrayHelpers { diff --git a/ArrayIsEmpty.cs b/ArrayIsEmpty.cs index eb6fbb141..a51f90079 100644 --- a/ArrayIsEmpty.cs +++ b/ArrayIsEmpty.cs @@ -32,7 +32,7 @@ using System.Linq; -namespace Aaru +namespace Aaru.Helpers { public static partial class ArrayHelpers { diff --git a/BigEndianBitConverter.cs b/BigEndianBitConverter.cs index 157e67717..30da968e9 100644 --- a/BigEndianBitConverter.cs +++ b/BigEndianBitConverter.cs @@ -33,7 +33,7 @@ using System; using System.Linq; -namespace Aaru +namespace Aaru.Helpers { /// /// Converts base data types to an array of bytes, and an array of bytes to base data types. All info taken from diff --git a/CompareBytes.cs b/CompareBytes.cs index d250c70c1..27da03745 100644 --- a/CompareBytes.cs +++ b/CompareBytes.cs @@ -30,7 +30,7 @@ // Copyright © 2011-2020 Natalia Portillo // ****************************************************************************/ -namespace Aaru +namespace Aaru.Helpers { public static partial class ArrayHelpers { diff --git a/DateHandlers.cs b/DateHandlers.cs index 12fc10462..aef3d4973 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -34,7 +34,7 @@ using System.Text; using Aaru.Console; -namespace Aaru +namespace Aaru.Helpers { public static class DateHandlers { diff --git a/PrintHex.cs b/PrintHex.cs index 95f116619..f62d304a8 100644 --- a/PrintHex.cs +++ b/PrintHex.cs @@ -33,7 +33,7 @@ using System.Text; using Aaru.Console; -namespace Aaru +namespace Aaru.Helpers { public static class PrintHex { diff --git a/StringHandlers.cs b/StringHandlers.cs index 59e0a2567..798ca6377 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -33,7 +33,7 @@ using System; using System.Text; -namespace Aaru +namespace Aaru.Helpers { public static class StringHandlers { diff --git a/Swapping.cs b/Swapping.cs index d59117667..19710f6f6 100644 --- a/Swapping.cs +++ b/Swapping.cs @@ -32,7 +32,7 @@ using System.Runtime.CompilerServices; -namespace Aaru +namespace Aaru.Helpers { public static class Swapping { From e64f731a55babbbaea9d7a83c9723310f614b9a5 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 20 Jul 2020 16:21:32 +0100 Subject: [PATCH 142/217] Update editorconfig file. --- .editorconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.editorconfig b/.editorconfig index c1ebeb20a..8b506dabe 100644 --- a/.editorconfig +++ b/.editorconfig @@ -298,7 +298,7 @@ dotnet_sort_system_directives_first=true # Constants in C style, all-caps dotnet_naming_rule.constant_fields_caps.symbols = constant_fields -dotnet_naming_rule.constant_fields_caps.severity = suggestion +dotnet_naming_rule.constant_fields_caps.severity = warning dotnet_naming_rule.constant_fields_caps.style = caps_style dotnet_naming_symbols.constant_fields.applicable_kinds = field dotnet_naming_symbols.constant_fields.required_modifiers = const @@ -313,7 +313,7 @@ dotnet_naming_style.pascal_case_interface_style.required_prefix = I dotnet_naming_style.pascal_case_interface_style.capitalization = pascal_case ## internal and private fields should be _camelCase -dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion +dotnet_naming_rule.camel_case_for_private_internal_fields.severity = warning dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style dotnet_naming_symbols.private_internal_fields.applicable_kinds = field From bc471c3ff84134692081cd89f85f6f49df9de28a Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 20 Jul 2020 21:11:31 +0100 Subject: [PATCH 143/217] Naming fixes. --- DateHandlers.cs | 33 ++++++++++++++-------------- StringHandlers.cs | 56 +++++++++++++++++++++++------------------------ 2 files changed, 45 insertions(+), 44 deletions(-) diff --git a/DateHandlers.cs b/DateHandlers.cs index aef3d4973..28fd153ca 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -38,49 +38,49 @@ namespace Aaru.Helpers { 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 UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0); + 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 _unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0); /// Day 0 of Julian Date system - static readonly DateTime JulianEpoch = new DateTime(1858, 11, 17, 0, 0, 0); - static readonly DateTime AmigaEpoch = new DateTime(1978, 1, 1, 0, 0, 0); + static readonly DateTime _julianEpoch = new DateTime(1858, 11, 17, 0, 0, 0); + static readonly DateTime _amigaEpoch = new DateTime(1978, 1, 1, 0, 0, 0); /// Converts a Macintosh timestamp to a .NET DateTime /// Macintosh timestamp (seconds since 1st Jan. 1904) /// .NET DateTime - public static DateTime MacToDateTime(ulong macTimeStamp) => MacEpoch.AddTicks((long)(macTimeStamp * 10000000)); + public static DateTime MacToDateTime(ulong macTimeStamp) => _macEpoch.AddTicks((long)(macTimeStamp * 10000000)); /// Converts a Lisa timestamp to a .NET DateTime /// Lisa timestamp (seconds since 1st Jan. 1901) /// .NET DateTime - public static DateTime LisaToDateTime(uint lisaTimeStamp) => LisaEpoch.AddSeconds(lisaTimeStamp); + public static DateTime LisaToDateTime(uint lisaTimeStamp) => _lisaEpoch.AddSeconds(lisaTimeStamp); /// Converts a UNIX timestamp to a .NET DateTime /// UNIX timestamp (seconds since 1st Jan. 1970) /// .NET DateTime - public static DateTime UnixToDateTime(int unixTimeStamp) => UnixEpoch.AddSeconds(unixTimeStamp); + public static DateTime UnixToDateTime(int unixTimeStamp) => _unixEpoch.AddSeconds(unixTimeStamp); /// Converts a UNIX timestamp to a .NET DateTime /// UNIX timestamp (seconds since 1st Jan. 1970) /// .NET DateTime - public static DateTime UnixToDateTime(long unixTimeStamp) => UnixEpoch.AddSeconds(unixTimeStamp); + public static DateTime UnixToDateTime(long unixTimeStamp) => _unixEpoch.AddSeconds(unixTimeStamp); /// Converts a UNIX timestamp to a .NET DateTime /// UNIX timestamp (seconds since 1st Jan. 1970) /// .NET DateTime - public static DateTime UnixUnsignedToDateTime(uint unixTimeStamp) => UnixEpoch.AddSeconds(unixTimeStamp); + public static DateTime UnixUnsignedToDateTime(uint unixTimeStamp) => _unixEpoch.AddSeconds(unixTimeStamp); /// Converts a UNIX timestamp to a .NET DateTime /// Seconds since 1st Jan. 1970) /// Nanoseconds /// .NET DateTime public static DateTime UnixUnsignedToDateTime(uint seconds, uint nanoseconds) => - UnixEpoch.AddSeconds(seconds).AddTicks((long)nanoseconds / 100); + _unixEpoch.AddSeconds(seconds).AddTicks((long)nanoseconds / 100); /// Converts a UNIX timestamp to a .NET DateTime /// UNIX timestamp (seconds since 1st Jan. 1970) /// .NET DateTime - public static DateTime UnixUnsignedToDateTime(ulong unixTimeStamp) => UnixEpoch.AddSeconds(unixTimeStamp); + public static DateTime UnixUnsignedToDateTime(ulong unixTimeStamp) => _unixEpoch.AddSeconds(unixTimeStamp); /// Converts a High Sierra Format timestamp to a .NET DateTime /// High Sierra Format timestamp @@ -188,7 +188,7 @@ public static DateTime VmsToDateTime(ulong vmsDate) { double delta = vmsDate * 0.0001; // Tenths of microseconds to milliseconds, will lose some detail - return JulianEpoch.AddMilliseconds(delta); + return _julianEpoch.AddMilliseconds(delta); } /// Converts an Amiga timestamp to a .NET DateTime @@ -198,7 +198,7 @@ public static DateTime VmsToDateTime(ulong vmsDate) /// .NET DateTime public static DateTime AmigaToDateTime(uint days, uint minutes, uint ticks) { - DateTime temp = AmigaEpoch.AddDays(days); + DateTime temp = _amigaEpoch.AddDays(days); temp = temp.AddMinutes(minutes); return temp.AddMilliseconds(ticks * 20); @@ -263,7 +263,7 @@ public static DateTime CpmToDateTime(byte[] timestamp) int hours = timestamp[2]; int minutes = timestamp[3]; - DateTime temp = AmigaEpoch.AddDays(days); + DateTime temp = _amigaEpoch.AddDays(days); temp = temp.AddHours(hours); temp = temp.AddMinutes(minutes); @@ -316,7 +316,8 @@ public static DateTime EcmaToDateTime(ushort typeAndTimeZone, short year, byte m /// Convers a Solaris high resolution timestamp to .NET DateTime /// Solaris high resolution timestamp /// .NET DateTime - public static DateTime UnixHrTimeToDateTime(ulong hrTimeStamp) => UnixEpoch.AddTicks((long)(hrTimeStamp / 100)); + public static DateTime UnixHrTimeToDateTime(ulong hrTimeStamp) => + _unixEpoch.AddTicks((long)(hrTimeStamp / 100)); /// Converts an OS-9 timestamp to .NET DateTime /// OS-9 timestamp diff --git a/StringHandlers.cs b/StringHandlers.cs index 798ca6377..d2128cd72 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -39,29 +39,29 @@ public static class StringHandlers { /// Converts a null-terminated (aka C string) ASCII byte array to a C# string /// The corresponding C# string - /// A null-terminated (aka C string) ASCII byte array - public static string CToString(byte[] CString) => CToString(CString, Encoding.ASCII); + /// A null-terminated (aka C string) ASCII byte array + public static string CToString(byte[] cString) => CToString(cString, Encoding.ASCII); /// Converts a null-terminated (aka C string) byte array with the specified encoding to a C# string /// The corresponding C# string - /// A null-terminated (aka C string) byte array in the specified encoding + /// A null-terminated (aka C string) byte array in the specified encoding /// Encoding. /// Set if encoding uses 16-bit characters. /// Start decodint at this position - public static string CToString(byte[] CString, Encoding encoding, bool twoBytes = false, int start = 0) + public static string CToString(byte[] cString, Encoding encoding, bool twoBytes = false, int start = 0) { - if(CString == null) + if(cString == null) return null; int len = 0; - for(int i = start; i < CString.Length; i++) + for(int i = start; i < cString.Length; i++) { - if(CString[i] == 0) + if(cString[i] == 0) if(twoBytes) { - if(i + 1 < CString.Length && - CString[i + 1] == 0) + if(i + 1 < cString.Length && + cString[i + 1] == 0) { len++; @@ -78,67 +78,67 @@ public static string CToString(byte[] CString, Encoding encoding, bool twoBytes len--; byte[] dest = new byte[len]; - Array.Copy(CString, start, dest, 0, len); + Array.Copy(cString, start, dest, 0, len); return len == 0 ? "" : encoding.GetString(dest); } /// Converts a length-prefixed (aka Pascal string) ASCII byte array to a C# string /// The corresponding C# string - /// A length-prefixed (aka Pascal string) ASCII byte array - public static string PascalToString(byte[] PascalString) => PascalToString(PascalString, Encoding.ASCII); + /// A length-prefixed (aka Pascal string) ASCII byte array + public static string PascalToString(byte[] pascalString) => PascalToString(pascalString, Encoding.ASCII); /// Converts a length-prefixed (aka Pascal string) ASCII byte array to a C# string /// The corresponding C# string - /// A length-prefixed (aka Pascal string) ASCII byte array + /// A length-prefixed (aka Pascal string) ASCII byte array /// Encoding. /// Start decodint at this position - public static string PascalToString(byte[] PascalString, Encoding encoding, int start = 0) + public static string PascalToString(byte[] pascalString, Encoding encoding, int start = 0) { - if(PascalString == null) + if(pascalString == null) return null; - byte length = PascalString[start]; + byte length = pascalString[start]; int len = 0; - for(int i = start + 1; i < length + 1 && i < PascalString.Length; i++) + for(int i = start + 1; i < length + 1 && i < pascalString.Length; i++) { - if(PascalString[i] == 0) + if(pascalString[i] == 0) break; len++; } byte[] dest = new byte[len]; - Array.Copy(PascalString, start + 1, dest, 0, len); + Array.Copy(pascalString, start + 1, dest, 0, len); return len == 0 ? "" : encoding.GetString(dest); } /// Converts a space (' ', 0x20, ASCII SPACE) padded ASCII byte array to a C# string /// The corresponding C# string - /// A space (' ', 0x20, ASCII SPACE) padded ASCII byte array - public static string SpacePaddedToString(byte[] SpacePaddedString) => - SpacePaddedToString(SpacePaddedString, Encoding.ASCII); + /// A space (' ', 0x20, ASCII SPACE) padded ASCII byte array + public static string SpacePaddedToString(byte[] spacePaddedString) => + SpacePaddedToString(spacePaddedString, Encoding.ASCII); /// Converts a space (' ', 0x20, ASCII SPACE) padded ASCII byte array to a C# string /// The corresponding C# string - /// A space (' ', 0x20, ASCII SPACE) padded ASCII byte array + /// A space (' ', 0x20, ASCII SPACE) padded ASCII byte array /// Encoding. /// Start decodint at this position - public static string SpacePaddedToString(byte[] SpacePaddedString, Encoding encoding, int start = 0) + public static string SpacePaddedToString(byte[] spacePaddedString, Encoding encoding, int start = 0) { - if(SpacePaddedString == null) + if(spacePaddedString == null) return null; int len = start; - for(int i = SpacePaddedString.Length; i >= start; i--) + for(int i = spacePaddedString.Length; i >= start; i--) { if(i == start) return ""; - if(SpacePaddedString[i - 1] == 0x20) + if(spacePaddedString[i - 1] == 0x20) continue; len = i; @@ -146,7 +146,7 @@ public static string SpacePaddedToString(byte[] SpacePaddedString, Encoding enco break; } - return len == 0 ? "" : encoding.GetString(SpacePaddedString, start, len); + return len == 0 ? "" : encoding.GetString(spacePaddedString, start, len); } /// Converts an OSTA compressed unicode byte array to a C# string From b23d976f9334f0bc2e59e4d61f047be65cc47500 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 22 Jul 2020 13:20:25 +0100 Subject: [PATCH 144/217] Code style fixes. --- ArrayIsEmpty.cs | 5 ++--- CountBits.cs | 4 ++-- DateHandlers.cs | 2 +- MarshallingPropertiesAttribute.cs | 2 +- StringHandlers.cs | 6 +++--- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/ArrayIsEmpty.cs b/ArrayIsEmpty.cs index a51f90079..d04586f71 100644 --- a/ArrayIsEmpty.cs +++ b/ArrayIsEmpty.cs @@ -39,12 +39,11 @@ public static partial class ArrayHelpers /// Checks if an array is null, filled with the NULL byte (0x00) or ASCII whitespace (0x20) /// Array /// True if null or whitespace - public static bool ArrayIsNullOrWhiteSpace(byte[] array) => - array == null || array.All(b => b == 0x00 || b == 0x20); + public static bool ArrayIsNullOrWhiteSpace(byte[] array) => array?.All(b => b == 0x00 || b == 0x20) != false; /// Checks if an array is null or filled with the NULL byte (0x00) /// Array /// True if null - public static bool ArrayIsNullOrEmpty(byte[] array) => array == null || array.All(b => b == 0x00); + public static bool ArrayIsNullOrEmpty(byte[] array) => array?.All(b => b == 0x00) != false; } } \ No newline at end of file diff --git a/CountBits.cs b/CountBits.cs index 60704df73..54914f3f5 100644 --- a/CountBits.cs +++ b/CountBits.cs @@ -39,8 +39,8 @@ public static class CountBits /// Bits set to true public static int Count(uint number) { - number = number - ((number >> 1) & 0x55555555); - number = (number & 0x33333333) + ((number >> 2) & 0x33333333); + number -= (number >> 1) & 0x55555555; + number = (number & 0x33333333) + ((number >> 2) & 0x33333333); return (int)((((number + (number >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24); } diff --git a/DateHandlers.cs b/DateHandlers.cs index 28fd153ca..6bca1e341 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -313,7 +313,7 @@ public static DateTime EcmaToDateTime(ushort typeAndTimeZone, short year, byte m AddTicks(ticks).DateTime; } - /// Convers a Solaris high resolution timestamp to .NET DateTime + /// Converts a Solaris high resolution timestamp to .NET DateTime /// Solaris high resolution timestamp /// .NET DateTime public static DateTime UnixHrTimeToDateTime(ulong hrTimeStamp) => diff --git a/MarshallingPropertiesAttribute.cs b/MarshallingPropertiesAttribute.cs index 954488341..bb91ac3c7 100644 --- a/MarshallingPropertiesAttribute.cs +++ b/MarshallingPropertiesAttribute.cs @@ -42,7 +42,7 @@ namespace Aaru.Helpers { /// Defines properties to help marshalling structs from binary data [AttributeUsage(AttributeTargets.Struct)] - public class MarshallingPropertiesAttribute : Attribute + public sealed class MarshallingPropertiesAttribute : Attribute { /// Defines properties to help marshalling structs from binary data /// Defines properties to help marshalling structs from binary data diff --git a/StringHandlers.cs b/StringHandlers.cs index d2128cd72..f99eceada 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -47,7 +47,7 @@ public static class StringHandlers /// A null-terminated (aka C string) byte array in the specified encoding /// Encoding. /// Set if encoding uses 16-bit characters. - /// Start decodint at this position + /// Start decoding at this position public static string CToString(byte[] cString, Encoding encoding, bool twoBytes = false, int start = 0) { if(cString == null) @@ -92,7 +92,7 @@ public static string CToString(byte[] cString, Encoding encoding, bool twoBytes /// The corresponding C# string /// A length-prefixed (aka Pascal string) ASCII byte array /// Encoding. - /// Start decodint at this position + /// Start decoding at this position public static string PascalToString(byte[] pascalString, Encoding encoding, int start = 0) { if(pascalString == null) @@ -125,7 +125,7 @@ public static string SpacePaddedToString(byte[] spacePaddedString) => /// The corresponding C# string /// A space (' ', 0x20, ASCII SPACE) padded ASCII byte array /// Encoding. - /// Start decodint at this position + /// Start decoding at this position public static string SpacePaddedToString(byte[] spacePaddedString, Encoding encoding, int start = 0) { if(spacePaddedString == null) From 430db71b374e4e65cb74a2db5d3fcc92bf6276fe Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 23 Jul 2020 22:09:40 +0100 Subject: [PATCH 145/217] Use UTC as starting point for ISO9660, leap seconds should only cause a problem when UTC time is assumed to be GMT and not reverse. --- DateHandlers.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/DateHandlers.cs b/DateHandlers.cs index 6bca1e341..7dad8dffb 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -174,10 +174,9 @@ public static DateTime Iso9660ToDateTime(byte[] vdDateTime) sbyte difference = (sbyte)vdDateTime[16]; var decodedDt = new DateTime(year, month, day, hour, minute, second, hundredths * 10, - DateTimeKind.Unspecified); + DateTimeKind.Utc); - // Convert ISO9660 time from GMT to UTC and remove the difference from GMT. Doing the removal first could cause problems if that makes it cross over a leap day, or a leap second - return TimeZoneInfo.ConvertTimeBySystemTimeZoneId(decodedDt, "GMT", "UTC").AddMinutes(difference * -15); + return decodedDt.AddMinutes(difference * -15); } /// Converts a VMS timestamp to a .NET DateTime From 48929629bdddc02b493653177def673d5ddacc93 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sat, 25 Jul 2020 03:31:27 +0100 Subject: [PATCH 146/217] Bump version and fix Arch Linux package building scripts. --- Aaru.Helpers.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index f33991510..6b8f0fc33 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -11,7 +11,7 @@ $(Version) false true - 5.0.99.2991 + 5.1.0.3214 Claunia.com Copyright © 2011-2020 Natalia Portillo Aaru Data Preservation Suite From d2bd48e95db3ca3917da6e085e10090915264e31 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sat, 25 Jul 2020 04:12:38 +0100 Subject: [PATCH 147/217] Bump version. --- Aaru.Helpers.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index 6b8f0fc33..cd23019c8 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -11,7 +11,7 @@ $(Version) false true - 5.1.0.3214 + 5.99.3.3215 Claunia.com Copyright © 2011-2020 Natalia Portillo Aaru Data Preservation Suite From 9aad86a6707ccf18950e2958e0a5a7447b378a22 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sat, 25 Jul 2020 04:16:53 +0100 Subject: [PATCH 148/217] Bump version. --- Aaru.Helpers.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index cd23019c8..05d35fe5b 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -11,7 +11,7 @@ $(Version) false true - 5.99.3.3215 + 5.1.99.3216 Claunia.com Copyright © 2011-2020 Natalia Portillo Aaru Data Preservation Suite From 8dfdfafcb366196aa132a247d3dfbfe23639912f Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 11 Nov 2020 04:19:13 +0000 Subject: [PATCH 149/217] General code clean-up, refactor and commenting. --- BigEndianBitConverter.cs | 22 +++++------ DateHandlers.cs | 81 ++++++++++++++++++++-------------------- 2 files changed, 51 insertions(+), 52 deletions(-) diff --git a/BigEndianBitConverter.cs b/BigEndianBitConverter.cs index 30da968e9..a4179c32d 100644 --- a/BigEndianBitConverter.cs +++ b/BigEndianBitConverter.cs @@ -305,16 +305,16 @@ public static uint ToUInt32(byte[] value, int startIndex) => public static ulong ToUInt64(byte[] value, int startIndex) => BitConverter.ToUInt64(value.Reverse().ToArray(), value.Length - sizeof(ulong) - startIndex); - public static Guid ToGuid(byte[] value, int startIndex) => 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]); + public static Guid ToGuid(byte[] value, int startIndex) => 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]); } } \ No newline at end of file diff --git a/DateHandlers.cs b/DateHandlers.cs index 7dad8dffb..43dc895cc 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -87,10 +87,10 @@ public static DateTime UnixUnsignedToDateTime(uint seconds, uint nanoseconds) => /// .NET DateTime public static DateTime HighSierraToDateTime(byte[] vdDateTime) { - byte[] isotime = new byte[17]; - Array.Copy(vdDateTime, 0, isotime, 0, 16); + byte[] isoTime = new byte[17]; + Array.Copy(vdDateTime, 0, isoTime, 0, 16); - return Iso9660ToDateTime(isotime); + return Iso9660ToDateTime(isoTime); } // TODO: Timezone @@ -99,72 +99,72 @@ public static DateTime HighSierraToDateTime(byte[] vdDateTime) /// .NET DateTime public static DateTime Iso9660ToDateTime(byte[] vdDateTime) { - byte[] twocharvalue = new byte[2]; - byte[] fourcharvalue = new byte[4]; + byte[] twoCharValue = new byte[2]; + byte[] fourCharValue = new byte[4]; - fourcharvalue[0] = vdDateTime[0]; - fourcharvalue[1] = vdDateTime[1]; - fourcharvalue[2] = vdDateTime[2]; - fourcharvalue[3] = vdDateTime[3]; + fourCharValue[0] = vdDateTime[0]; + fourCharValue[1] = vdDateTime[1]; + fourCharValue[2] = vdDateTime[2]; + fourCharValue[3] = vdDateTime[3]; AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "year = \"{0}\"", - StringHandlers.CToString(fourcharvalue, Encoding.ASCII)); + StringHandlers.CToString(fourCharValue, Encoding.ASCII)); - if(!int.TryParse(StringHandlers.CToString(fourcharvalue, Encoding.ASCII), out int year)) + if(!int.TryParse(StringHandlers.CToString(fourCharValue, Encoding.ASCII), out int year)) year = 0; - twocharvalue[0] = vdDateTime[4]; - twocharvalue[1] = vdDateTime[5]; + twoCharValue[0] = vdDateTime[4]; + twoCharValue[1] = vdDateTime[5]; AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "month = \"{0}\"", - StringHandlers.CToString(twocharvalue, Encoding.ASCII)); + StringHandlers.CToString(twoCharValue, Encoding.ASCII)); - if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out int month)) + if(!int.TryParse(StringHandlers.CToString(twoCharValue, Encoding.ASCII), out int month)) month = 0; - twocharvalue[0] = vdDateTime[6]; - twocharvalue[1] = vdDateTime[7]; + twoCharValue[0] = vdDateTime[6]; + twoCharValue[1] = vdDateTime[7]; AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "day = \"{0}\"", - StringHandlers.CToString(twocharvalue, Encoding.ASCII)); + StringHandlers.CToString(twoCharValue, Encoding.ASCII)); - if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out int day)) + if(!int.TryParse(StringHandlers.CToString(twoCharValue, Encoding.ASCII), out int day)) day = 0; - twocharvalue[0] = vdDateTime[8]; - twocharvalue[1] = vdDateTime[9]; + twoCharValue[0] = vdDateTime[8]; + twoCharValue[1] = vdDateTime[9]; AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "hour = \"{0}\"", - StringHandlers.CToString(twocharvalue, Encoding.ASCII)); + StringHandlers.CToString(twoCharValue, Encoding.ASCII)); - if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out int hour)) + if(!int.TryParse(StringHandlers.CToString(twoCharValue, Encoding.ASCII), out int hour)) hour = 0; - twocharvalue[0] = vdDateTime[10]; - twocharvalue[1] = vdDateTime[11]; + twoCharValue[0] = vdDateTime[10]; + twoCharValue[1] = vdDateTime[11]; AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "minute = \"{0}\"", - StringHandlers.CToString(twocharvalue, Encoding.ASCII)); + StringHandlers.CToString(twoCharValue, Encoding.ASCII)); - if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out int minute)) + if(!int.TryParse(StringHandlers.CToString(twoCharValue, Encoding.ASCII), out int minute)) minute = 0; - twocharvalue[0] = vdDateTime[12]; - twocharvalue[1] = vdDateTime[13]; + twoCharValue[0] = vdDateTime[12]; + twoCharValue[1] = vdDateTime[13]; AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "second = \"{0}\"", - StringHandlers.CToString(twocharvalue, Encoding.ASCII)); + StringHandlers.CToString(twoCharValue, Encoding.ASCII)); - if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out int second)) + if(!int.TryParse(StringHandlers.CToString(twoCharValue, Encoding.ASCII), out int second)) second = 0; - twocharvalue[0] = vdDateTime[14]; - twocharvalue[1] = vdDateTime[15]; + twoCharValue[0] = vdDateTime[14]; + twoCharValue[1] = vdDateTime[15]; AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "hundredths = \"{0}\"", - StringHandlers.CToString(twocharvalue, Encoding.ASCII)); + StringHandlers.CToString(twoCharValue, Encoding.ASCII)); - if(!int.TryParse(StringHandlers.CToString(twocharvalue, Encoding.ASCII), out int hundredths)) + if(!int.TryParse(StringHandlers.CToString(twoCharValue, Encoding.ASCII), out int hundredths)) hundredths = 0; AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", @@ -173,8 +173,7 @@ public static DateTime Iso9660ToDateTime(byte[] vdDateTime) sbyte difference = (sbyte)vdDateTime[16]; - var decodedDt = new DateTime(year, month, day, hour, minute, second, hundredths * 10, - DateTimeKind.Utc); + var decodedDt = new DateTime(year, month, day, hour, minute, second, hundredths * 10, DateTimeKind.Utc); return decodedDt.AddMinutes(difference * -15); } @@ -239,18 +238,18 @@ public static DateTime DosToDateTime(ushort date, ushort time) "time = 0x{0:X4}, hour = {1}, minute = {2}, second = {3}", time, hour, minute, second); - DateTime dosdate; + DateTime dosDate; try { - dosdate = new DateTime(year, month, day, hour, minute, second); + dosDate = new DateTime(year, month, day, hour, minute, second); } catch(ArgumentOutOfRangeException) { - dosdate = new DateTime(1980, 1, 1, 0, 0, 0); + dosDate = new DateTime(1980, 1, 1, 0, 0, 0); } - return dosdate; + return dosDate; } /// Converts a CP/M timestamp to .NET DateTime From 59a58346cde09a158829b1a9c1cd86696d04ab98 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 3 Dec 2020 02:09:17 +0000 Subject: [PATCH 150/217] Bump version to 5.2.0.3330. --- Aaru.Helpers.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index 05d35fe5b..158b08e79 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -11,7 +11,7 @@ $(Version) false true - 5.1.99.3216 + 5.2.0.3330 Claunia.com Copyright © 2011-2020 Natalia Portillo Aaru Data Preservation Suite From cba0fc8d979b6e72c60ecc141df9589e79b551ca Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 3 Dec 2020 02:37:39 +0000 Subject: [PATCH 151/217] Bump version. --- Aaru.Helpers.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index 158b08e79..1e9e83af3 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -11,7 +11,7 @@ $(Version) false true - 5.2.0.3330 + 5.2.99.3331 Claunia.com Copyright © 2011-2020 Natalia Portillo Aaru Data Preservation Suite From 4fe08ed66891242664eb01df1cfbedbd365a7818 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 8 Dec 2020 00:56:31 +0000 Subject: [PATCH 152/217] Move hex string to byte array converter to helpers. --- CHS.cs | 4 ++-- Marshal.cs | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/CHS.cs b/CHS.cs index f02554873..684811e52 100644 --- a/CHS.cs +++ b/CHS.cs @@ -42,7 +42,7 @@ public static class CHS /// Number of sectors per track /// public static uint ToLBA(uint cyl, uint head, uint sector, uint maxHead, uint maxSector) => - maxHead == 0 || maxSector == 0 ? ((((cyl * 16) + head) * 63) + sector) - 1 - : ((((cyl * maxHead) + head) * maxSector) + sector) - 1; + maxHead == 0 || maxSector == 0 ? (((cyl * 16) + head) * 63) + sector - 1 + : (((cyl * maxHead) + head) * maxSector) + sector - 1; } } \ No newline at end of file diff --git a/Marshal.cs b/Marshal.cs index 872b274b5..f982a04da 100644 --- a/Marshal.cs +++ b/Marshal.cs @@ -427,5 +427,29 @@ public static byte[] StructureToByteArrayLittleEndian(T str) where T : struct [MethodImpl(MethodImplOptions.AggressiveInlining)] public static byte[] StructureToByteArrayBigEndian(T str) where T : struct => StructureToByteArrayLittleEndian((T)SwapStructureMembersEndian(str)); + + public static int ConvertFromHexAscii(string hex, out byte[] outBuf) + { + if(hex.StartsWith("0x", StringComparison.InvariantCultureIgnoreCase)) + hex = hex.Substring(2); + + outBuf = new byte[hex.Length / 2]; + int count = 0; + + try + { + for(int i = 0; i < hex.Length; i += 2) + { + outBuf[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16); + count++; + } + } + catch + { + count = 0; + } + + return count; + } } } \ No newline at end of file From 65296b6ccceeccb83c2a03d72e0a50f473664042 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 8 Dec 2020 01:18:44 +0000 Subject: [PATCH 153/217] Optimize hex string to byte array marshaller. --- Marshal.cs | 59 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 47 insertions(+), 12 deletions(-) diff --git a/Marshal.cs b/Marshal.cs index f982a04da..b724764a7 100644 --- a/Marshal.cs +++ b/Marshal.cs @@ -430,23 +430,58 @@ public static byte[] StructureToByteArrayBigEndian(T str) where T : struct => public static int ConvertFromHexAscii(string hex, out byte[] outBuf) { - if(hex.StartsWith("0x", StringComparison.InvariantCultureIgnoreCase)) - hex = hex.Substring(2); + outBuf = null; - outBuf = new byte[hex.Length / 2]; - int count = 0; + if(hex is null || + hex == "") + return -1; + + int off = 0; - try + if(hex[0] == '0' && + (hex[1] == 'x' || hex[1] == 'X')) { - for(int i = 0; i < hex.Length; i += 2) - { - outBuf[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16); - count++; - } + off = 2; } - catch + + outBuf = new byte[(hex.Length - off) / 2]; + int count = 0; + + for(int i = off; i < hex.Length; i += 2) { - count = 0; + char c = hex[i]; + + if(c < '0' || + (c > '9' && c < 'A') || + (c > 'F' && c < 'a') || + c > 'f') + break; + + c -= c >= 'a' && c <= 'f' + ? '\u0057' + : c >= 'A' && c <= 'F' + ? '\u0037' + : '\u0030'; + + outBuf[(i - off) / 2] = (byte)(c << 4); + + c = hex[i + 1]; + + if(c < '0' || + (c > '9' && c < 'A') || + (c > 'F' && c < 'a') || + c > 'f') + break; + + c -= c >= 'a' && c <= 'f' + ? '\u0057' + : c >= 'A' && c <= 'F' + ? '\u0037' + : '\u0030'; + + outBuf[(i - off) / 2] += (byte)c; + + count++; } return count; From 38110655618fb25532b47a502561ba30dae3bdc2 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 20 Dec 2020 22:59:31 +0000 Subject: [PATCH 154/217] Prepare nuget packages. --- Aaru.Helpers.csproj | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index 1e9e83af3..8ee7bbfbd 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -11,7 +11,7 @@ $(Version) false true - 5.2.99.3331 + 5.2.99.3380-alpha Claunia.com Copyright © 2011-2020 Natalia Portillo Aaru Data Preservation Suite @@ -19,9 +19,19 @@ $(Version) netcoreapp3.1 8 + Contains helpers used by the Aaru Data Preservation Suite. + https://github.com/aaru-dps/ + LGPL-2.1-only + https://github.com/aaru-dps/Aaru.Helpers + true + en-US + true + true + snupkg + Natalia Portillo <claunia@claunia.com> - $(Version)+{chash:8} built by {mname} in $(Configuration){!:, modified} + $(Version)+{chash:8} true true @@ -74,7 +84,7 @@ - + From d7db55d5f229eec69e05bde6ac91202e6cbcfec0 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 31 Dec 2020 23:08:22 +0000 Subject: [PATCH 155/217] Update copyright year. --- Aaru.Helpers.csproj | 2 +- ArrayFill.cs | 2 +- ArrayIsEmpty.cs | 2 +- BigEndianBitConverter.cs | 2 +- BitEndian.cs | 2 +- CHS.cs | 2 +- CompareBytes.cs | 2 +- CountBits.cs | 2 +- DateHandlers.cs | 2 +- Marshal.cs | 2 +- MarshallingPropertiesAttribute.cs | 2 +- PrintHex.cs | 2 +- StringHandlers.cs | 2 +- Swapping.cs | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index 8ee7bbfbd..aa32335ae 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -13,7 +13,7 @@ true 5.2.99.3380-alpha Claunia.com - Copyright © 2011-2020 Natalia Portillo + Copyright © 2011-2021 Natalia Portillo Aaru Data Preservation Suite Aaru.Helpers $(Version) diff --git a/ArrayFill.cs b/ArrayFill.cs index edd2545b4..ff3ab5a3e 100644 --- a/ArrayFill.cs +++ b/ArrayFill.cs @@ -20,7 +20,7 @@ // Assuming open source. // // ---------------------------------------------------------------------------- -// Copyright © 2011-2020 Natalia Portillo +// Copyright © 2011-2021 Natalia Portillo // Copyright(C) 2014 mykohsu // ****************************************************************************/ diff --git a/ArrayIsEmpty.cs b/ArrayIsEmpty.cs index d04586f71..087955f3c 100644 --- a/ArrayIsEmpty.cs +++ b/ArrayIsEmpty.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2020 Natalia Portillo +// Copyright © 2011-2021 Natalia Portillo // ****************************************************************************/ using System.Linq; diff --git a/BigEndianBitConverter.cs b/BigEndianBitConverter.cs index a4179c32d..b7b20b083 100644 --- a/BigEndianBitConverter.cs +++ b/BigEndianBitConverter.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2020 Natalia Portillo +// Copyright © 2011-2021 Natalia Portillo // ****************************************************************************/ using System; diff --git a/BitEndian.cs b/BitEndian.cs index 96a35d563..0205652e7 100644 --- a/BitEndian.cs +++ b/BitEndian.cs @@ -33,7 +33,7 @@ // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // ---------------------------------------------------------------------------- -// Copyright © 2011-2020 Natalia Portillo +// Copyright © 2011-2021 Natalia Portillo // ****************************************************************************/ namespace Aaru.Helpers diff --git a/CHS.cs b/CHS.cs index 684811e52..448c73e4e 100644 --- a/CHS.cs +++ b/CHS.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2020 Natalia Portillo +// Copyright © 2011-2021 Natalia Portillo // ****************************************************************************/ namespace Aaru.Helpers diff --git a/CompareBytes.cs b/CompareBytes.cs index 27da03745..18acac965 100644 --- a/CompareBytes.cs +++ b/CompareBytes.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2020 Natalia Portillo +// Copyright © 2011-2021 Natalia Portillo // ****************************************************************************/ namespace Aaru.Helpers diff --git a/CountBits.cs b/CountBits.cs index 54914f3f5..92bac63c1 100644 --- a/CountBits.cs +++ b/CountBits.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2020 Natalia Portillo +// Copyright © 2011-2021 Natalia Portillo // ****************************************************************************/ namespace Aaru.Helpers diff --git a/DateHandlers.cs b/DateHandlers.cs index 43dc895cc..58e963c18 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2020 Natalia Portillo +// Copyright © 2011-2021 Natalia Portillo // ****************************************************************************/ using System; diff --git a/Marshal.cs b/Marshal.cs index b724764a7..8b3c3a0ae 100644 --- a/Marshal.cs +++ b/Marshal.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2020 Natalia Portillo +// Copyright © 2011-2021 Natalia Portillo // ****************************************************************************/ using System; diff --git a/MarshallingPropertiesAttribute.cs b/MarshallingPropertiesAttribute.cs index bb91ac3c7..c5781e90b 100644 --- a/MarshallingPropertiesAttribute.cs +++ b/MarshallingPropertiesAttribute.cs @@ -33,7 +33,7 @@ // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // ---------------------------------------------------------------------------- -// Copyright © 2011-2020 Natalia Portillo +// Copyright © 2011-2021 Natalia Portillo // ****************************************************************************/ using System; diff --git a/PrintHex.cs b/PrintHex.cs index f62d304a8..08b242acf 100644 --- a/PrintHex.cs +++ b/PrintHex.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2020 Natalia Portillo +// Copyright © 2011-2021 Natalia Portillo // ****************************************************************************/ using System.Text; diff --git a/StringHandlers.cs b/StringHandlers.cs index f99eceada..d9abc45b5 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2020 Natalia Portillo +// Copyright © 2011-2021 Natalia Portillo // ****************************************************************************/ using System; diff --git a/Swapping.cs b/Swapping.cs index 19710f6f6..8b0e4b636 100644 --- a/Swapping.cs +++ b/Swapping.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2020 Natalia Portillo +// Copyright © 2011-2021 Natalia Portillo // ****************************************************************************/ using System.Runtime.CompilerServices; From 138c6c1f4585d6c6a971aeffa691ec99e5629ef1 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 17 Aug 2021 13:56:05 +0100 Subject: [PATCH 156/217] Add XML comments to public entities. --- ArrayIsEmpty.cs | 3 +++ BigEndianBitConverter.cs | 6 ++++++ CHS.cs | 3 +++ CountBits.cs | 3 +++ DateHandlers.cs | 3 +++ Marshal.cs | 11 ++++++++++ PrintHex.cs | 3 +++ StringHandlers.cs | 3 +++ Swapping.cs | 43 ++++++++++++++++++++++++++++++++++++++++ 9 files changed, 78 insertions(+) diff --git a/ArrayIsEmpty.cs b/ArrayIsEmpty.cs index 087955f3c..11688c667 100644 --- a/ArrayIsEmpty.cs +++ b/ArrayIsEmpty.cs @@ -34,6 +34,9 @@ namespace Aaru.Helpers { + /// + /// Helper operations to work with arrays + /// public static partial class ArrayHelpers { /// Checks if an array is null, filled with the NULL byte (0x00) or ASCII whitespace (0x20) diff --git a/BigEndianBitConverter.cs b/BigEndianBitConverter.cs index b7b20b083..54b2b4e30 100644 --- a/BigEndianBitConverter.cs +++ b/BigEndianBitConverter.cs @@ -305,6 +305,12 @@ public static uint ToUInt32(byte[] value, int startIndex) => public static ulong ToUInt64(byte[] value, int startIndex) => BitConverter.ToUInt64(value.Reverse().ToArray(), value.Length - sizeof(ulong) - startIndex); + /// + /// Converts a big endian byte array representation of a GUID into the .NET Guid structure + /// + /// Byte array containing a GUID in big endian + /// Start of the byte array to process + /// Processed Guid public static Guid ToGuid(byte[] value, int startIndex) => new Guid(ToUInt32(value, 0 + startIndex), ToUInt16(value, 4 + startIndex), ToUInt16(value, 6 + startIndex), diff --git a/CHS.cs b/CHS.cs index 448c73e4e..85600e3f9 100644 --- a/CHS.cs +++ b/CHS.cs @@ -32,6 +32,9 @@ namespace Aaru.Helpers { + /// + /// Helper operations to work with CHS values + /// public static class CHS { /// Converts a CHS position to a LBA one diff --git a/CountBits.cs b/CountBits.cs index 92bac63c1..e8dfcdb02 100644 --- a/CountBits.cs +++ b/CountBits.cs @@ -32,6 +32,9 @@ namespace Aaru.Helpers { + /// + /// Helper operations to count bits + /// public static class CountBits { /// Counts the number of bits set to true in a number diff --git a/DateHandlers.cs b/DateHandlers.cs index 58e963c18..e3ec874bc 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -36,6 +36,9 @@ namespace Aaru.Helpers { + /// + /// Helper operations for timestamp management (date and time) + /// public static class DateHandlers { static readonly DateTime _lisaEpoch = new DateTime(1901, 1, 1, 0, 0, 0); diff --git a/Marshal.cs b/Marshal.cs index 8b3c3a0ae..db2739589 100644 --- a/Marshal.cs +++ b/Marshal.cs @@ -360,6 +360,11 @@ public static object SwapStructureMembersEndian(object str) return str; } + /// + /// Swaps all fields in an structure considering them to follow PDP endian conventions + /// + /// Source structure + /// Resulting structure [MethodImpl(MethodImplOptions.AggressiveInlining)] public static object SwapStructureMembersEndianPdp(object str) { @@ -428,6 +433,12 @@ public static byte[] StructureToByteArrayLittleEndian(T str) where T : struct public static byte[] StructureToByteArrayBigEndian(T str) where T : struct => StructureToByteArrayLittleEndian((T)SwapStructureMembersEndian(str)); + /// + /// Converts a hexadecimal string into a byte array + /// + /// Hexadecimal string + /// Resulting byte array + /// Number of output bytes processed public static int ConvertFromHexAscii(string hex, out byte[] outBuf) { outBuf = null; diff --git a/PrintHex.cs b/PrintHex.cs index 08b242acf..943399704 100644 --- a/PrintHex.cs +++ b/PrintHex.cs @@ -35,6 +35,9 @@ namespace Aaru.Helpers { + /// + /// Helper operations to get hexadecimal representations of byte arrays + /// public static class PrintHex { /// Prints a byte array as hexadecimal values to the console diff --git a/StringHandlers.cs b/StringHandlers.cs index d9abc45b5..85fd2bddf 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -35,6 +35,9 @@ namespace Aaru.Helpers { + /// + /// Helper operations to work with strings + /// public static class StringHandlers { /// Converts a null-terminated (aka C string) ASCII byte array to a C# string diff --git a/Swapping.cs b/Swapping.cs index 8b0e4b636..71ff96848 100644 --- a/Swapping.cs +++ b/Swapping.cs @@ -34,20 +34,48 @@ namespace Aaru.Helpers { + /// + /// Helper operations to work with swapping endians + /// public static class Swapping { + /// + /// Gets the PDP endian equivalent of the given little endian unsigned integer + /// + /// Little endian unsigned integer + /// PDP unsigned integer [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint PDPFromLittleEndian(uint x) => ((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16); + /// + /// Gets the PDP endian equivalent of the given big endian unsigned integer + /// + /// Big endian unsigned integer + /// PDP unsigned integer [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint PDPFromBigEndian(uint x) => ((x & 0xff00ff) << 8) | ((x & 0xff00ff00) >> 8); + /// + /// Swaps the endian of the specified unsigned short integer + /// + /// Unsigned short integer + /// Swapped unsigned short integer [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ushort Swap(ushort x) => (ushort)((x << 8) | (x >> 8)); + /// + /// Swaps the endian of the specified signed short integer + /// + /// Signed short integer + /// Swapped signed short integer [MethodImpl(MethodImplOptions.AggressiveInlining)] public static short Swap(short x) => (short)((x << 8) | ((x >> 8) & 0xFF)); + /// + /// Swaps the endian of the specified unsigned integer + /// + /// Unsigned integer + /// Swapped unsigned integer [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint Swap(uint x) { @@ -56,6 +84,11 @@ public static uint Swap(uint x) return (x << 16) | (x >> 16); } + /// + /// Swaps the endian of the specified signed integer + /// + /// Signed integer + /// Swapped signed integer [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Swap(int x) { @@ -64,6 +97,11 @@ public static int Swap(int x) return (int)(((uint)x << 16) | (((uint)x >> 16) & 0xFFFF)); } + /// + /// Swaps the endian of the specified unsigned long integer + /// + /// Unsigned long integer + /// Swapped unsigned long integer [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ulong Swap(ulong x) { @@ -74,6 +112,11 @@ public static ulong Swap(ulong x) return x; } + /// + /// Swaps the endian of the specified signed long integer + /// + /// Signed long integer + /// Swapped signed long integer [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Swap(long x) { From 8e58e082af1b95ac098ff7de08ad3284bf25bef4 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 17 Aug 2021 14:40:37 +0100 Subject: [PATCH 157/217] Add XML comments to public entities. --- MarshallingPropertiesAttribute.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MarshallingPropertiesAttribute.cs b/MarshallingPropertiesAttribute.cs index c5781e90b..c148ac91e 100644 --- a/MarshallingPropertiesAttribute.cs +++ b/MarshallingPropertiesAttribute.cs @@ -40,10 +40,12 @@ namespace Aaru.Helpers { + /// /// Defines properties to help marshalling structs from binary data [AttributeUsage(AttributeTargets.Struct)] public sealed class MarshallingPropertiesAttribute : Attribute { + /// /// Defines properties to help marshalling structs from binary data /// Defines properties to help marshalling structs from binary data public MarshallingPropertiesAttribute(BitEndian endian) From e1a7abc1a61d3a9c934dd8b6489d0023bc08893e Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 17 Aug 2021 16:27:42 +0100 Subject: [PATCH 158/217] Fix inconsistent naming. --- Marshal.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Marshal.cs b/Marshal.cs index db2739589..5985b9192 100644 --- a/Marshal.cs +++ b/Marshal.cs @@ -31,6 +31,7 @@ // ****************************************************************************/ using System; +using System.Diagnostics.CodeAnalysis; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -266,6 +267,7 @@ public static T MarshalStructure(byte[] bytes) where T : struct /// /// [MethodImpl(MethodImplOptions.AggressiveInlining)] + [SuppressMessage("ReSharper", "InconsistentNaming")] public static object SwapStructureMembersEndian(object str) { Type t = str.GetType(); From f173fb5d7075fcb33f1caabff745a0beb97d6963 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 17 Aug 2021 21:22:58 +0100 Subject: [PATCH 159/217] General code refactor. --- .editorconfig | 1098 +++++++++++++++++++------------------- Aaru.Helpers.csproj | 80 +-- ArrayIsEmpty.cs | 4 +- BigEndianBitConverter.cs | 4 +- CHS.cs | 4 +- CountBits.cs | 4 +- DateHandlers.cs | 4 +- Marshal.cs | 11 +- PrintHex.cs | 4 +- StringHandlers.cs | 4 +- Swapping.cs | 36 +- 11 files changed, 608 insertions(+), 645 deletions(-) diff --git a/.editorconfig b/.editorconfig index 8b506dabe..9181fe501 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,252 +1,252 @@ root = true [*] -charset=utf-8 -next_line=crlf -insert_final_newline=false -indent_style=space -indent_size=4 +charset = utf-8 +next_line = crlf +insert_final_newline = false +indent_style = space +indent_size = 4 # Generic non-language specific ones for Resharper and friends -brace_style=next_line -int_align=true -keep_existing_arrangement=false -place_simple_blocks_on_single_line=true -place_simple_declaration_blocks_on_single_line=true -place_attribute_on_same_line=false -space_after_unary_operator=false -space_after_comma=true -space_around_ternary_operator=true -space_around_binary_operator=true -space_around_member_access_operator=false -space_before_open_square_brackets=false -space_after_keywords_in_control_flow_statements=true -space_before_comma=false -space_between_method_call_name_and_opening_parenthesis=false -space_between_method_declaration_name_and_open_parenthesis=false -space_between_square_brackets=false -space_between_parentheses_of_control_flow_statements=false -accessor_owner_declaration_braces=next_line -accessor_declaration_braces=next_line -case_block_braces=next_line -initializer_braces=next_line -other_braces=next_line -allow_comment_after_lbrace=false -empty_block_style=together_same_line -braces_for_ifelse=not_required -braces_for_for=not_required -braces_for_foreach=not_required -braces_for_while=not_required -braces_for_dowhile=not_required -braces_for_using=not_required -braces_for_lock=not_required -braces_for_fixed=not_required -method_or_operator_body=expression_body -local_function_body=expression_body -constructor_or_destructor_body=expression_body -accessor_owner_body=expression_body -force_attribute_style=join -function_braces=next_line -force_control_statements_braces=always_remove -space_in_singleline_accessorholder=true -type_declaration_braces=next_line -invocable_declaration_braces=next_line -anonymous_method_declaration_braces=next_line -space_between_accessors_in_singleline_property=true -indent_nested_usings_stmt=true -space_within_empty_braces=false -indent_nested_fixed_stmt=true -indent_nested_lock_stmt=true -indent_nested_for_stmt=true -indent_nested_foreach_stmt=true -indent_nested_while_stmt=true -use_continuous_indent_inside_parens=true -indent_method_decl_pars=inside -indent_invocation_pars=inside -indent_statement_pars=inside -indent_typeparam_angles=inside -indent_typearg_angles=inside -indent_pars=inside -indent_preprocessor_if=outdent -indent_preprocessor_region=usual_indent -indent_preprocessor_other=usual_indent -indent_switch_labels=true -indent_type_constraints=true -stick_comment=false -alignment_tab_fill_style=use_spaces -align_multiline_parameter=true -align_multiline_extends_list=true -align_linq_query=true -align_multiline_binary_expressions_chain=true -outdent_binary_ops=true -align_multiline_calls_chain=true -outdent_dots=true -align_multiline_array_and_object_initializer=false -indent_anonymous_method_block=false -align_first_arg_by_paren=true -align_multiline_argument=true -align_tuple_components=true -align_multiline_expression=true -align_multiline_for_stmt=true -align_multiple_declaration=true -align_multline_type_parameter_list=true -align_multline_type_parameter_constrains=true -int_align_fields=true -int_align_properties=true -int_align_methods=true -int_align_parameters=false -int_align_variables=true -int_align_assignments=true -int_align_nested_ternary=true -int_align_invocations=false -int_align_binary_expressions=true -int_align_comments=true -int_align_switch_sections=true -keep_user_linebreaks=false -keep_existing_arrangement=false -keep_existing_linebreaks=false -max_line_length=120 -wrap_before_comma=false -special_else_if_treatment=true -place_type_attribute_on_same_line=never -place_method_attribute_on_same_line=never -place_accessorholder_attribute_on_same_line=never -place_attribute_on_same_line=never -place_accessor_attribute_on_same_line=never -place_attribute_on_same_line=never -place_field_attribute_on_same_line=never -place_attribute_on_same_line=never -wrap_parameters_style=wrap_if_long -keep_existing_declaration_parens_arrangement=false -wrap_before_declaration_lpar=false -wrap_after_declaration_lpar=false -wrap_before_declaration_rpar=false -place_constructor_initializer_on_same_line=true -keep_existing_expr_member_arrangement=false -place_expr_method_on_single_line=true -place_expr_property_on_single_line=true -place_expr_accessor_on_single_line=true -wrap_before_arrow_with_expressions=false -place_type_constraints_on_same_line=true -wrap_before_first_type_parameter_constraint=true -wrap_multiple_type_parameter_constraints_style=wrap_if_long -wrap_before_type_parameter_langle=true -wrap_before_extends_colon=false -wrap_extends_list_style=wrap_if_long -keep_existing_declaration_block_arrangement=false -place_abstract_accessorholder_on_single_line=true -place_simple_accessorholder_on_single_line=false -place_accessor_with_attrs_holder_on_single_line=false -place_simple_accessor_on_single_line=true -place_simple_method_on_single_line=false -keep_existing_enum_arrangement=false -place_simple_enum_on_single_line=false -wrap_enum_declaration=wrap_if_long -new_line_before_else=true -new_line_before_while=false -wrap_for_stmt_header_style=wrap_if_long -wrap_multiple_declaration_style=wrap_if_long -keep_existing_embedded_arrangement=false -place_simple_embedded_statement_on_same_line=false -place_simple_case_statement_on_same_line=true -keep_existing_embedded_block_arrangement=false -place_simple_embedded_block_on_same_line=false -place_simple_anonymousmethod_on_single_line=false -keep_existing_initializer_arrangement=false -place_simple_initializer_on_single_line=false -wrap_object_and_collection_initializer_style=chop_always -wrap_array_initializer_style=wrap_if_long -wrap_arguments_style=wrap_if_long -keep_existing_invocation_parens_arrangement=false -wrap_after_invocation_lpar=false -wrap_before_invocation_rpar=false -wrap_after_dot_in_method_calls=true -wrap_chained_method_calls=wrap_if_long -wrap_before_binary_opsign=false -wrap_chained_binary_expressions=wrap_if_long -force_chop_compound_if_expression=true -force_chop_compound_while_expression=true -force_chop_compound_do_expression=true -wrap_before_ternary_opsigns=true -wrap_ternary_expr_style=wrap_if_long -nested_ternary_style=expanded -wrap_linq_expressions=wrap_if_long -wrap_before_linq_expression=false -place_linq_into_on_new_line=false -wrap_verbatim_interpolated_strings=wrap_if_long -extra_spaces=remove_all -space_after_keywords_in_control_flow_statements=false -space_between_method_call_name_and_opening_parenthesis=false -space_between_method_declaration_name_and_open_parenthesis=false -space_before_typeof_parentheses=false -space_before_checked_parentheses=false -space_before_sizeof_parentheses=false -space_before_nameof_parentheses=false -space_between_keyword_and_expression=true -space_between_keyword_and_type=true -space_around_assignment_op=true -space_around_logical_op=true -space_around_binary_operator=true -space_around_equality_op=true -space_around_relational_op=true -space_around_bitwise_op=true -space_around_additive_op=true -space_around_multiplicative_op=true -space_around_shift_op=true -space_around_nullcoalescing_op=true -space_around_arrow_op=false -space_after_logical_not_op=false -space_after_unary_operator=false -space_after_cast=false -space_around_dot=false -space_around_lambda_arrow=true -space_before_pointer_asterik_declaration=false -space_before_nullable_mark=false -blank_lines_around_class_definition=1 -namespace_indentation=all -space_within_template_argument=false -align_union_type_usage=true -space_in_singleline_method=true -space_in_singleline_anonymous_method=true -space_within_single_line_array_initializer_braces=true -space_around_arrow_op=false +brace_style = next_line +int_align = true +keep_existing_arrangement = false +place_simple_blocks_on_single_line = true +place_simple_declaration_blocks_on_single_line = true +place_attribute_on_same_line = false +space_after_unary_operator = false +space_after_comma = true +space_around_ternary_operator = true +space_around_binary_operator = true +space_around_member_access_operator = false +space_before_open_square_brackets = false +space_after_keywords_in_control_flow_statements = true +space_before_comma = false +space_between_method_call_name_and_opening_parenthesis = false +space_between_method_declaration_name_and_open_parenthesis = false +space_between_square_brackets = false +space_between_parentheses_of_control_flow_statements = false +accessor_owner_declaration_braces = next_line +accessor_declaration_braces = next_line +case_block_braces = next_line +initializer_braces = next_line +other_braces = next_line +allow_comment_after_lbrace = false +empty_block_style = together_same_line +braces_for_ifelse = not_required +braces_for_for = not_required +braces_for_foreach = not_required +braces_for_while = not_required +braces_for_dowhile = not_required +braces_for_using = not_required +braces_for_lock = not_required +braces_for_fixed = not_required +method_or_operator_body = expression_body +local_function_body = expression_body +constructor_or_destructor_body = expression_body +accessor_owner_body = expression_body +force_attribute_style = join +function_braces = next_line +force_control_statements_braces = always_remove +space_in_singleline_accessorholder = true +type_declaration_braces = next_line +invocable_declaration_braces = next_line +anonymous_method_declaration_braces = next_line +space_between_accessors_in_singleline_property = true +indent_nested_usings_stmt = true +space_within_empty_braces = false +indent_nested_fixed_stmt = true +indent_nested_lock_stmt = true +indent_nested_for_stmt = true +indent_nested_foreach_stmt = true +indent_nested_while_stmt = true +use_continuous_indent_inside_parens = true +indent_method_decl_pars = inside +indent_invocation_pars = inside +indent_statement_pars = inside +indent_typeparam_angles = inside +indent_typearg_angles = inside +indent_pars = inside +indent_preprocessor_if = outdent +indent_preprocessor_region = usual_indent +indent_preprocessor_other = usual_indent +indent_switch_labels = true +indent_type_constraints = true +stick_comment = false +alignment_tab_fill_style = use_spaces +align_multiline_parameter = true +align_multiline_extends_list = true +align_linq_query = true +align_multiline_binary_expressions_chain = true +outdent_binary_ops = true +align_multiline_calls_chain = true +outdent_dots = true +align_multiline_array_and_object_initializer = false +indent_anonymous_method_block = false +align_first_arg_by_paren = true +align_multiline_argument = true +align_tuple_components = true +align_multiline_expression = true +align_multiline_for_stmt = true +align_multiple_declaration = true +align_multline_type_parameter_list = true +align_multline_type_parameter_constrains = true +int_align_fields = true +int_align_properties = true +int_align_methods = true +int_align_parameters = false +int_align_variables = true +int_align_assignments = true +int_align_nested_ternary = true +int_align_invocations = false +int_align_binary_expressions = true +int_align_comments = true +int_align_switch_sections = true +keep_user_linebreaks = false +keep_existing_arrangement = false +keep_existing_linebreaks = false +max_line_length = 120 +wrap_before_comma = false +special_else_if_treatment = true +place_type_attribute_on_same_line = never +place_method_attribute_on_same_line = never +place_accessorholder_attribute_on_same_line = never +place_attribute_on_same_line = never +place_accessor_attribute_on_same_line = never +place_attribute_on_same_line = never +place_field_attribute_on_same_line = never +place_attribute_on_same_line = never +wrap_parameters_style = wrap_if_long +keep_existing_declaration_parens_arrangement = false +wrap_before_declaration_lpar = false +wrap_after_declaration_lpar = false +wrap_before_declaration_rpar = false +place_constructor_initializer_on_same_line = true +keep_existing_expr_member_arrangement = false +place_expr_method_on_single_line = true +place_expr_property_on_single_line = true +place_expr_accessor_on_single_line = true +wrap_before_arrow_with_expressions = false +place_type_constraints_on_same_line = true +wrap_before_first_type_parameter_constraint = true +wrap_multiple_type_parameter_constraints_style = wrap_if_long +wrap_before_type_parameter_langle = true +wrap_before_extends_colon = false +wrap_extends_list_style = wrap_if_long +keep_existing_declaration_block_arrangement = false +place_abstract_accessorholder_on_single_line = true +place_simple_accessorholder_on_single_line = false +place_accessor_with_attrs_holder_on_single_line = false +place_simple_accessor_on_single_line = true +place_simple_method_on_single_line = false +keep_existing_enum_arrangement = false +place_simple_enum_on_single_line = false +wrap_enum_declaration = wrap_if_long +new_line_before_else = true +new_line_before_while = false +wrap_for_stmt_header_style = wrap_if_long +wrap_multiple_declaration_style = wrap_if_long +keep_existing_embedded_arrangement = false +place_simple_embedded_statement_on_same_line = false +place_simple_case_statement_on_same_line = true +keep_existing_embedded_block_arrangement = false +place_simple_embedded_block_on_same_line = false +place_simple_anonymousmethod_on_single_line = false +keep_existing_initializer_arrangement = false +place_simple_initializer_on_single_line = false +wrap_object_and_collection_initializer_style = chop_always +wrap_array_initializer_style = wrap_if_long +wrap_arguments_style = wrap_if_long +keep_existing_invocation_parens_arrangement = false +wrap_after_invocation_lpar = false +wrap_before_invocation_rpar = false +wrap_after_dot_in_method_calls = true +wrap_chained_method_calls = wrap_if_long +wrap_before_binary_opsign = false +wrap_chained_binary_expressions = wrap_if_long +force_chop_compound_if_expression = true +force_chop_compound_while_expression = true +force_chop_compound_do_expression = true +wrap_before_ternary_opsigns = true +wrap_ternary_expr_style = wrap_if_long +nested_ternary_style = expanded +wrap_linq_expressions = wrap_if_long +wrap_before_linq_expression = false +place_linq_into_on_new_line = false +wrap_verbatim_interpolated_strings = wrap_if_long +extra_spaces = remove_all +space_after_keywords_in_control_flow_statements = false +space_between_method_call_name_and_opening_parenthesis = false +space_between_method_declaration_name_and_open_parenthesis = false +space_before_typeof_parentheses = false +space_before_checked_parentheses = false +space_before_sizeof_parentheses = false +space_before_nameof_parentheses = false +space_between_keyword_and_expression = true +space_between_keyword_and_type = true +space_around_assignment_op = true +space_around_logical_op = true +space_around_binary_operator = true +space_around_equality_op = true +space_around_relational_op = true +space_around_bitwise_op = true +space_around_additive_op = true +space_around_multiplicative_op = true +space_around_shift_op = true +space_around_nullcoalescing_op = true +space_around_arrow_op = false +space_after_logical_not_op = false +space_after_unary_operator = false +space_after_cast = false +space_around_dot = false +space_around_lambda_arrow = true +space_before_pointer_asterik_declaration = false +space_before_nullable_mark = false +blank_lines_around_class_definition = 1 +namespace_indentation = all +space_within_template_argument = false +align_union_type_usage = true +space_in_singleline_method = true +space_in_singleline_anonymous_method = true +space_within_single_line_array_initializer_braces = true +space_around_arrow_op = false # These are for markup languages (HTML, XML, etc) -spaces_around_eq_in_pi_attribute=false -space_after_last_pi_attribute=true -pi_attributes_indent=align_by_first_attribute -blank_line_after_pi=true -spaces_around_eq_in_attribute=false -space_after_last_attribute=false -space_before_self_closing=true -attribute_style=on_single_line -attribute_indent=align_by_first_attribute -sort_attributes=true -sort_class_selectors=true -max_blank_lines_between_tags=0 -linebreak_before_all_elements=true -linebreak_before_multiline_elements=true -quote_style=doublequoted -delete_quotes_from_solid_values=false -normalize_tag_names=true +spaces_around_eq_in_pi_attribute = false +space_after_last_pi_attribute = true +pi_attributes_indent = align_by_first_attribute +blank_line_after_pi = true +spaces_around_eq_in_attribute = false +space_after_last_attribute = false +space_before_self_closing = true +attribute_style = on_single_line +attribute_indent = align_by_first_attribute +sort_attributes = true +sort_class_selectors = true +max_blank_lines_between_tags = 0 +linebreak_before_all_elements = true +linebreak_before_multiline_elements = true +quote_style = doublequoted +delete_quotes_from_solid_values = false +normalize_tag_names = true [{.babelrc,.stylelintrc,jest.config,.eslintrc,.prettierrc,*.json,*.jsb3,*.jsb2,*.bowerrc}] -indent_size=2 +indent_size = 2 [*.js.map] -indent_size=2 +indent_size = 2 [*.{css,scss}] -indent_size=2 -declarations_style=separate_lines_for_nonsingle -media_query_style=separate_lines -selector_style=same_line -properties_style=separate_lines_for_nonsingle -brace_style=next_line +indent_size = 2 +declarations_style = separate_lines_for_nonsingle +media_query_style = separate_lines +selector_style = same_line +properties_style = separate_lines_for_nonsingle +brace_style = next_line [{.analysis_options,*.yml,*.yaml}] -indent_size=2 +indent_size = 2 # Xml project files [*.{csproj,vcxproj,vcxproj.filters,proj,nativeproj,locproj}] @@ -263,38 +263,38 @@ indent_size = 2 # .net files [*.{cs,vb}] # These set the this. / Me. -dotnet_style_qualification_for_field=false:warning -dotnet_style_qualification_for_property=false:warning -dotnet_style_qualification_for_method=false:warning -dotnet_style_qualification_for_event=false:warning +dotnet_style_qualification_for_field = false:warning +dotnet_style_qualification_for_property = false:warning +dotnet_style_qualification_for_method = false:warning +dotnet_style_qualification_for_event = false:warning # These make it suggest Int32 instead of int, etc. -dotnet_style_predefined_type_for_locals_parameters_members=true:suggestion -dotnet_style_predefined_type_for_member_access=true:suggestion +dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion +dotnet_style_predefined_type_for_member_access = true:suggestion # This controls implicit access modifiers -dotnet_style_require_accessibility_modifiers=never:suggestion +dotnet_style_require_accessibility_modifiers = never:suggestion # Prefer non modified fields to be marked readonly -dotnet_style_readonly_field=true:warning +dotnet_style_readonly_field = true:warning # Parenthesis settings -dotnet_style_parentheses_in_arithmetic_binary_operators=always_for_clarity:warning -dotnet_style_parentheses_in_relational_binary_operators=always_for_clarity:warning -dotnet_style_parentheses_in_other_binary_operators=always_for_clarity:warning -dotnet_style_parentheses_in_other_operators=always_for_clarity:warning - -dotnet_style_object_initializer=true:suggestion -dotnet_style_collection_initializer=true:suggestion -dotnet_style_explicit_tuple_names=true:error -dotnet_style_prefer_inferred_tuple_names=true:warning -dotnet_style_prefer_inferred_anonymous_type_member_names=true:warning -dotnet_style_prefer_is_null_check_over_reference_equality_method=true:warning -dotnet_style_prefer_conditional_expression_over_return=true:warning -dotnet_style_coalesce_expression=true:warning -dotnet_style_null_propagation=true:error - -dotnet_sort_system_directives_first=true +dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:warning +dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:warning +dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:warning +dotnet_style_parentheses_in_other_operators = always_for_clarity:warning + +dotnet_style_object_initializer = true:suggestion +dotnet_style_collection_initializer = true:suggestion +dotnet_style_explicit_tuple_names = true:error +dotnet_style_prefer_inferred_tuple_names = true:warning +dotnet_style_prefer_inferred_anonymous_type_member_names = true:warning +dotnet_style_prefer_is_null_check_over_reference_equality_method = true:warning +dotnet_style_prefer_conditional_expression_over_return = true:warning +dotnet_style_coalesce_expression = true:warning +dotnet_style_null_propagation = true:error + +dotnet_sort_system_directives_first = true # Constants in C style, all-caps dotnet_naming_rule.constant_fields_caps.symbols = constant_fields @@ -306,16 +306,16 @@ dotnet_naming_style.caps_style.capitalization = all_upper # interfaces should be prefixed with I dotnet_naming_rule.pascal_case_for_interface.severity = error -dotnet_naming_rule.pascal_case_for_interface.symbols = interfaces_fields -dotnet_naming_rule.pascal_case_for_interface.style = pascal_case_interface_style +dotnet_naming_rule.pascal_case_for_interface.symbols = interfaces_fields +dotnet_naming_rule.pascal_case_for_interface.style = pascal_case_interface_style dotnet_naming_symbols.interfaces_fields.applicable_kinds = interface dotnet_naming_style.pascal_case_interface_style.required_prefix = I dotnet_naming_style.pascal_case_interface_style.capitalization = pascal_case ## internal and private fields should be _camelCase dotnet_naming_rule.camel_case_for_private_internal_fields.severity = warning -dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields -dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style +dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields +dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style dotnet_naming_symbols.private_internal_fields.applicable_kinds = field dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal dotnet_naming_style.camel_case_underscore_style.required_prefix = _ @@ -331,302 +331,302 @@ dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case [*.cs] # var var var -csharp_style_var_for_built_in_types=false:warning -csharp_style_var_when_type_is_apparent=true:suggestion -csharp_style_var_elsewhere=false:warning - -csharp_style_expression_bodied_methods=when_on_single_line:suggestion -csharp_style_expression_bodied_constructors=when_on_single_line:suggestion -csharp_style_expression_bodied_operators=when_on_single_line:suggestion -csharp_style_expression_bodied_properties=when_on_single_line:suggestion -csharp_style_expression_bodied_indexers=when_on_single_line:suggestion -csharp_style_expression_bodied_accessors=when_on_single_line:suggestion - -csharp_style_pattern_matching_over_is_with_cast_check=true:warning -csharp_style_pattern_matching_over_as_with_null_check=when_on_single_line:warning - -csharp_style_inlined_variable_declaration=true:warning - -csharp_prefer_simple_default_expression=true:warning -csharp_style_deconstructed_variable_declaration=false:warning - -csharp_style_throw_expression=true:warning -csharp_style_conditional_delegate_call=true:warning - -csharp_prefer_braces=false - -csharp_new_line_before_open_brace=all -csharp_new_line_before_else=true -csharp_new_line_before_catch=true -csharp_new_line_before_finally=true -csharp_new_line_before_members_in_object_initializers=true -csharp_new_line_before_members_in_anonymous_types=true -csharp_new_line_between_query_expression_clauses=true - -csharp_indent_case_contents=true -csharp_indent_switch_labels=true -csharp_indent_labels=flush_left - -csharp_space_after_cast=false -csharp_space_after_keywords_in_control_flow_statements=false -csharp_space_between_method_declaration_parameter_list_parentheses=false -csharp_space_between_parentheses=none -csharp_space_before_colon_in_inheritance_clause=true -csharp_space_after_colon_in_inheritance_clause=true -csharp_space_around_binary_operators=before_and_after -csharp_space_between_method_declaration_empty_parameter_list_parentheses=false -csharp_space_between_method_call_name_and_opening_parenthesis=false -csharp_space_between_method_call_empty_parameter_list_parentheses=false - -csharp_preserve_single_line_statements=false -csharp_preserve_single_line_blocks=true - -csharp_blank_lines_around_region=0 -csharp_blank_lines_inside_region=0 -csharp_blank_lines_before_single_line_comment=1 -csharp_keep_blank_lines_in_declarations=1 -csharp_remove_blank_lines_near_braces_in_declarations=true -csharp_blank_lines_after_start_comment=false -csharp_blank_lines_between_using_groups=0 -csharp_blank_lines_after_using_list=1 -csharp_blank_lines_around_namespace=1 -csharp_blank_lines_inside_namespace=0 -csharp_blank_lines_around_type=1 -csharp_blank_lines_inside_type=0 -csharp_blank_lines_around_field=0 -csharp_blank_lines_around_single_line_field=0 -csharp_blank_lines_around_property=1 -csharp_blank_lines_around_single_line_property=0 -csharp_blank_lines_around_auto_property=0 -csharp_blank_lines_around_single_line_auto_property=0 -csharp_blank_lines_around_invocable=1 -csharp_blank_lines_around_single_line_invocable=1 -csharp_keep_blank_lines_in_code=1 -csharp_remove_blank_lines_near_braces_in_code=true -csharp_blank_lines_around_local_method=1 -csharp_blank_lines_around_single_line_local_method=1 -csharp_blank_lines_before_control_transfer_statements=1 -csharp_blank_lines_after_control_transfer_statements=1 -csharp_blank_lines_before_block_statements=1 -csharp_blank_lines_after_block_statements=1 -csharp_blank_lines_before_multiline_statements=1 -csharp_blank_lines_after_multiline_statements=1 - -csharp_type_declaration_braces=next_line -csharp_brace_style=next_line -csharp_indent_inside_namespace=true -csharp_invocable_declaration_braces=next_line -csharp_anonymous_method_declaration_braces=next_line -csharp_accessor_owner_declaration_braces=next_line -csharp_accessor_declaration_braces=next_line -csharp_case_block_braces=next_line -csharp_initializer_braces=next_line -csharp_other_braces=next_line -csharp_allow_comment_after_lbrace=false -csharp_empty_block_style=together_same_line - -csharp_for_built_in_types=use_explicit_type -csharp_for_simple_types=use_var_when_evident -csharp_for_other_types=use_explicit_type -csharp_prefer_separate_deconstructed_variables_declaration=true -csharp_prefer_explicit_discard_declaration=false - -csharp_instance_members_qualify_members=none -csharp_builtin_type_reference_style=use_keyword -csharp_prefer_qualified_reference=false -csharp_add_imports_to_deepest_scope=false -csharp_allow_alias=true -csharp_default_private_modifier=implicit -csharp_default_internal_modifier=explicit -csharp_arguments_literal=positional -csharp_arguments_string_literal=positional -csharp_arguments_named=positional -csharp_arguments_anonymous_function=positional -csharp_arguments_other=positional -csharp_braces_for_ifelse=not_required -csharp_braces_for_for=not_required -csharp_braces_for_foreach=not_required -csharp_braces_for_while=not_required -csharp_braces_for_dowhile=not_required -csharp_braces_for_using=not_required -csharp_braces_for_lock=not_required -csharp_braces_for_fixed=not_required -csharp_method_or_operator_body=expression_body -csharp_local_function_body=expression_body -csharp_constructor_or_destructor_body=expression_body -csharp_accessor_owner_body=expression_body -csharp_force_attribute_style=join -csharp_indent_nested_usings_stmt=true - -csharp_builtin_type_reference_for_member_access_style=use_keyword -csharp_indent_nested_fixed_stmt=true -csharp_indent_nested_lock_stmt=true -csharp_indent_nested_for_stmt=true -csharp_indent_nested_foreach_stmt=true -csharp_indent_nested_while_stmt=true -csharp_use_continuous_indent_inside_parens=true -csharp_indent_method_decl_pars=inside -csharp_indent_invocation_pars=inside -csharp_indent_statement_pars=inside -csharp_indent_typeparam_angles=inside -csharp_indent_typearg_angles=inside -csharp_indent_pars=inside -csharp_indent_preprocessor_if=outdent -csharp_indent_preprocessor_region=usual_indent -csharp_indent_preprocessor_other=usual_indent -csharp_indent_switch_labels=true -csharp_indent_type_constraints=true -csharp_stick_comment=false -csharp_alignment_tab_fill_style=use_spaces -csharp_align_multiline_parameter=true -csharp_align_multiline_extends_list=true -csharp_align_linq_query=true -csharp_align_multiline_binary_expressions_chain=true -csharp_outdent_binary_ops=true -csharp_align_multiline_calls_chain=true -csharp_outdent_dots=true -csharp_align_multiline_array_and_object_initializer=false -csharp_indent_anonymous_method_block=false -csharp_align_first_arg_by_paren=true -csharp_align_multiline_argument=true -csharp_align_tuple_components=true -csharp_align_multiline_expression=true -csharp_align_multiline_for_stmt=true -csharp_align_multiple_declaration=true -csharp_align_multline_type_parameter_list=true -csharp_align_multline_type_parameter_constrains=true -csharp_int_align_fields=true -csharp_int_align_properties=true -csharp_int_align_methods=true -csharp_int_align_parameters=false -csharp_int_align_variables=true -csharp_int_align_assignments=true -csharp_int_align_nested_ternary=true -csharp_int_align_invocations=false -csharp_int_align_binary_expressions=true -csharp_int_align_comments=true -csharp_int_align_switch_sections=true -csharp_int_align=true -csharp_keep_user_linebreaks=false -csharp_keep_existing_arrangement=false -csharp_keep_existing_linebreaks=false -csharp_max_line_length=120 -csharp_wrap_before_comma=false -csharp_special_else_if_treatment=true -csharp_insert_final_newline=false -csharp_place_type_attribute_on_same_line=never -csharp_place_method_attribute_on_same_line=never -csharp_place_accessorholder_attribute_on_same_line=never -csharp_place_attribute_on_same_line=never -csharp_place_accessor_attribute_on_same_line=never -csharp_place_attribute_on_same_line=never -csharp_place_field_attribute_on_same_line=never -csharp_place_attribute_on_same_line=never -csharp_wrap_parameters_style=wrap_if_long -csharp_keep_existing_declaration_parens_arrangement=false -csharp_wrap_before_declaration_lpar=false -csharp_wrap_after_declaration_lpar=false -csharp_wrap_before_declaration_rpar=false -csharp_place_constructor_initializer_on_same_line=true -csharp_keep_existing_expr_member_arrangement=false -csharp_place_expr_method_on_single_line=true -csharp_place_expr_property_on_single_line=true -csharp_place_expr_accessor_on_single_line=true -csharp_wrap_before_arrow_with_expressions=false -csharp_place_type_constraints_on_same_line=true -csharp_wrap_before_first_type_parameter_constraint=true -csharp_wrap_multiple_type_parameter_constraints_style=wrap_if_long -csharp_wrap_before_type_parameter_langle=true -csharp_wrap_before_extends_colon=false -csharp_wrap_extends_list_style=wrap_if_long -csharp_keep_existing_declaration_block_arrangement=false -csharp_place_abstract_accessorholder_on_single_line=true -csharp_place_simple_accessorholder_on_single_line=false -csharp_place_accessor_with_attrs_holder_on_single_line=false -csharp_place_simple_accessor_on_single_line=true -csharp_place_simple_method_on_single_line=false -csharp_keep_existing_enum_arrangement=false -csharp_place_simple_enum_on_single_line=false -csharp_wrap_enum_declaration=wrap_if_long -csharp_new_line_before_else=true -csharp_new_line_before_while=false -csharp_wrap_for_stmt_header_style=wrap_if_long -csharp_wrap_multiple_declaration_style=wrap_if_long -csharp_keep_existing_embedded_arrangement=false -csharp_place_simple_embedded_statement_on_same_line=false -csharp_place_simple_case_statement_on_same_line=true -csharp_keep_existing_embedded_block_arrangement=false -csharp_place_simple_embedded_block_on_same_line=false -csharp_place_simple_anonymousmethod_on_single_line=false -csharp_keep_existing_initializer_arrangement=false -csharp_place_simple_initializer_on_single_line=false -csharp_wrap_object_and_collection_initializer_style=chop_always -csharp_wrap_array_initializer_style=wrap_if_long -csharp_wrap_arguments_style=wrap_if_long -csharp_keep_existing_invocation_parens_arrangement=false -csharp_wrap_after_invocation_lpar=false -csharp_wrap_before_invocation_rpar=false -csharp_wrap_after_dot_in_method_calls=true -csharp_wrap_chained_method_calls=wrap_if_long -csharp_wrap_before_binary_opsign=false -csharp_wrap_chained_binary_expressions=wrap_if_long -csharp_force_chop_compound_if_expression=true -csharp_force_chop_compound_while_expression=true -csharp_force_chop_compound_do_expression=true -csharp_wrap_before_ternary_opsigns=true -csharp_wrap_ternary_expr_style=wrap_if_long -csharp_nested_ternary_style=expanded -csharp_wrap_linq_expressions=wrap_if_long -csharp_wrap_before_linq_expression=false -csharp_place_linq_into_on_new_line=false -csharp_wrap_verbatim_interpolated_strings=wrap_if_long -csharp_extra_spaces=remove_all -csharp_space_after_keywords_in_control_flow_statements=false -csharp_space_between_method_call_name_and_opening_parenthesis=false -csharp_space_between_method_declaration_name_and_open_parenthesis=false -csharp_space_before_typeof_parentheses=false -csharp_space_before_checked_parentheses=false -csharp_space_before_sizeof_parentheses=false -csharp_space_before_nameof_parentheses=false -csharp_space_between_keyword_and_expression=true -csharp_space_between_keyword_and_type=true -csharp_space_around_assignment_op=true -csharp_space_around_logical_op=true -csharp_space_around_binary_operator=true -csharp_space_around_equality_op=true -csharp_space_around_relational_op=true -csharp_space_around_bitwise_op=true -csharp_space_around_additive_op=true -csharp_space_around_multiplicative_op=true -csharp_space_around_shift_op=true -csharp_space_around_nullcoalescing_op=true -csharp_space_around_arrow_op=false -csharp_space_after_logical_not_op=false -csharp_space_after_unary_operator=false -csharp_space_after_cast=false -csharp_space_around_dot=false -csharp_space_around_lambda_arrow=true -csharp_space_before_pointer_asterik_declaration=false -csharp_space_before_nullable_mark=false +csharp_style_var_for_built_in_types = false:warning +csharp_style_var_when_type_is_apparent = true:suggestion +csharp_style_var_elsewhere = false:warning + +csharp_style_expression_bodied_methods = when_on_single_line:suggestion +csharp_style_expression_bodied_constructors = when_on_single_line:suggestion +csharp_style_expression_bodied_operators = when_on_single_line:suggestion +csharp_style_expression_bodied_properties = when_on_single_line:suggestion +csharp_style_expression_bodied_indexers = when_on_single_line:suggestion +csharp_style_expression_bodied_accessors = when_on_single_line:suggestion + +csharp_style_pattern_matching_over_is_with_cast_check = true:warning +csharp_style_pattern_matching_over_as_with_null_check = when_on_single_line:warning + +csharp_style_inlined_variable_declaration = true:warning + +csharp_prefer_simple_default_expression = true:warning +csharp_style_deconstructed_variable_declaration = false:warning + +csharp_style_throw_expression = true:warning +csharp_style_conditional_delegate_call = true:warning + +csharp_prefer_braces = false + +csharp_new_line_before_open_brace = all +csharp_new_line_before_else = true +csharp_new_line_before_catch = true +csharp_new_line_before_finally = true +csharp_new_line_before_members_in_object_initializers = true +csharp_new_line_before_members_in_anonymous_types = true +csharp_new_line_between_query_expression_clauses = true + +csharp_indent_case_contents = true +csharp_indent_switch_labels = true +csharp_indent_labels = flush_left + +csharp_space_after_cast = false +csharp_space_after_keywords_in_control_flow_statements = false +csharp_space_between_method_declaration_parameter_list_parentheses = false +csharp_space_between_parentheses = none +csharp_space_before_colon_in_inheritance_clause = true +csharp_space_after_colon_in_inheritance_clause = true +csharp_space_around_binary_operators = before_and_after +csharp_space_between_method_declaration_empty_parameter_list_parentheses = false +csharp_space_between_method_call_name_and_opening_parenthesis = false +csharp_space_between_method_call_empty_parameter_list_parentheses = false + +csharp_preserve_single_line_statements = false +csharp_preserve_single_line_blocks = true + +csharp_blank_lines_around_region = 0 +csharp_blank_lines_inside_region = 0 +csharp_blank_lines_before_single_line_comment = 1 +csharp_keep_blank_lines_in_declarations = 1 +csharp_remove_blank_lines_near_braces_in_declarations = true +csharp_blank_lines_after_start_comment = false +csharp_blank_lines_between_using_groups = 0 +csharp_blank_lines_after_using_list = 1 +csharp_blank_lines_around_namespace = 1 +csharp_blank_lines_inside_namespace = 0 +csharp_blank_lines_around_type = 1 +csharp_blank_lines_inside_type = 0 +csharp_blank_lines_around_field = 0 +csharp_blank_lines_around_single_line_field = 0 +csharp_blank_lines_around_property = 1 +csharp_blank_lines_around_single_line_property = 0 +csharp_blank_lines_around_auto_property = 0 +csharp_blank_lines_around_single_line_auto_property = 0 +csharp_blank_lines_around_invocable = 1 +csharp_blank_lines_around_single_line_invocable = 1 +csharp_keep_blank_lines_in_code = 1 +csharp_remove_blank_lines_near_braces_in_code = true +csharp_blank_lines_around_local_method = 1 +csharp_blank_lines_around_single_line_local_method = 1 +csharp_blank_lines_before_control_transfer_statements = 1 +csharp_blank_lines_after_control_transfer_statements = 1 +csharp_blank_lines_before_block_statements = 1 +csharp_blank_lines_after_block_statements = 1 +csharp_blank_lines_before_multiline_statements = 1 +csharp_blank_lines_after_multiline_statements = 1 + +csharp_type_declaration_braces = next_line +csharp_brace_style = next_line +csharp_indent_inside_namespace = true +csharp_invocable_declaration_braces = next_line +csharp_anonymous_method_declaration_braces = next_line +csharp_accessor_owner_declaration_braces = next_line +csharp_accessor_declaration_braces = next_line +csharp_case_block_braces = next_line +csharp_initializer_braces = next_line +csharp_other_braces = next_line +csharp_allow_comment_after_lbrace = false +csharp_empty_block_style = together_same_line + +csharp_for_built_in_types = use_explicit_type +csharp_for_simple_types = use_var_when_evident +csharp_for_other_types = use_explicit_type +csharp_prefer_separate_deconstructed_variables_declaration = true +csharp_prefer_explicit_discard_declaration = false + +csharp_instance_members_qualify_members = none +csharp_builtin_type_reference_style = use_keyword +csharp_prefer_qualified_reference = false +csharp_add_imports_to_deepest_scope = false +csharp_allow_alias = true +csharp_default_private_modifier = implicit +csharp_default_internal_modifier = explicit +csharp_arguments_literal = positional +csharp_arguments_string_literal = positional +csharp_arguments_named = positional +csharp_arguments_anonymous_function = positional +csharp_arguments_other = positional +csharp_braces_for_ifelse = not_required +csharp_braces_for_for = not_required +csharp_braces_for_foreach = not_required +csharp_braces_for_while = not_required +csharp_braces_for_dowhile = not_required +csharp_braces_for_using = not_required +csharp_braces_for_lock = not_required +csharp_braces_for_fixed = not_required +csharp_method_or_operator_body = expression_body +csharp_local_function_body = expression_body +csharp_constructor_or_destructor_body = expression_body +csharp_accessor_owner_body = expression_body +csharp_force_attribute_style = join +csharp_indent_nested_usings_stmt = true + +csharp_builtin_type_reference_for_member_access_style = use_keyword +csharp_indent_nested_fixed_stmt = true +csharp_indent_nested_lock_stmt = true +csharp_indent_nested_for_stmt = true +csharp_indent_nested_foreach_stmt = true +csharp_indent_nested_while_stmt = true +csharp_use_continuous_indent_inside_parens = true +csharp_indent_method_decl_pars = inside +csharp_indent_invocation_pars = inside +csharp_indent_statement_pars = inside +csharp_indent_typeparam_angles = inside +csharp_indent_typearg_angles = inside +csharp_indent_pars = inside +csharp_indent_preprocessor_if = outdent +csharp_indent_preprocessor_region = usual_indent +csharp_indent_preprocessor_other = usual_indent +csharp_indent_switch_labels = true +csharp_indent_type_constraints = true +csharp_stick_comment = false +csharp_alignment_tab_fill_style = use_spaces +csharp_align_multiline_parameter = true +csharp_align_multiline_extends_list = true +csharp_align_linq_query = true +csharp_align_multiline_binary_expressions_chain = true +csharp_outdent_binary_ops = true +csharp_align_multiline_calls_chain = true +csharp_outdent_dots = true +csharp_align_multiline_array_and_object_initializer = false +csharp_indent_anonymous_method_block = false +csharp_align_first_arg_by_paren = true +csharp_align_multiline_argument = true +csharp_align_tuple_components = true +csharp_align_multiline_expression = true +csharp_align_multiline_for_stmt = true +csharp_align_multiple_declaration = true +csharp_align_multline_type_parameter_list = true +csharp_align_multline_type_parameter_constrains = true +csharp_int_align_fields = true +csharp_int_align_properties = true +csharp_int_align_methods = true +csharp_int_align_parameters = false +csharp_int_align_variables = true +csharp_int_align_assignments = true +csharp_int_align_nested_ternary = true +csharp_int_align_invocations = false +csharp_int_align_binary_expressions = true +csharp_int_align_comments = true +csharp_int_align_switch_sections = true +csharp_int_align = true +csharp_keep_user_linebreaks = false +csharp_keep_existing_arrangement = false +csharp_keep_existing_linebreaks = false +csharp_max_line_length = 120 +csharp_wrap_before_comma = false +csharp_special_else_if_treatment = true +csharp_insert_final_newline = false +csharp_place_type_attribute_on_same_line = never +csharp_place_method_attribute_on_same_line = never +csharp_place_accessorholder_attribute_on_same_line = never +csharp_place_attribute_on_same_line = never +csharp_place_accessor_attribute_on_same_line = never +csharp_place_attribute_on_same_line = never +csharp_place_field_attribute_on_same_line = never +csharp_place_attribute_on_same_line = never +csharp_wrap_parameters_style = wrap_if_long +csharp_keep_existing_declaration_parens_arrangement = false +csharp_wrap_before_declaration_lpar = false +csharp_wrap_after_declaration_lpar = false +csharp_wrap_before_declaration_rpar = false +csharp_place_constructor_initializer_on_same_line = true +csharp_keep_existing_expr_member_arrangement = false +csharp_place_expr_method_on_single_line = true +csharp_place_expr_property_on_single_line = true +csharp_place_expr_accessor_on_single_line = true +csharp_wrap_before_arrow_with_expressions = false +csharp_place_type_constraints_on_same_line = true +csharp_wrap_before_first_type_parameter_constraint = true +csharp_wrap_multiple_type_parameter_constraints_style = wrap_if_long +csharp_wrap_before_type_parameter_langle = true +csharp_wrap_before_extends_colon = false +csharp_wrap_extends_list_style = wrap_if_long +csharp_keep_existing_declaration_block_arrangement = false +csharp_place_abstract_accessorholder_on_single_line = true +csharp_place_simple_accessorholder_on_single_line = false +csharp_place_accessor_with_attrs_holder_on_single_line = false +csharp_place_simple_accessor_on_single_line = true +csharp_place_simple_method_on_single_line = false +csharp_keep_existing_enum_arrangement = false +csharp_place_simple_enum_on_single_line = false +csharp_wrap_enum_declaration = wrap_if_long +csharp_new_line_before_else = true +csharp_new_line_before_while = false +csharp_wrap_for_stmt_header_style = wrap_if_long +csharp_wrap_multiple_declaration_style = wrap_if_long +csharp_keep_existing_embedded_arrangement = false +csharp_place_simple_embedded_statement_on_same_line = false +csharp_place_simple_case_statement_on_same_line = true +csharp_keep_existing_embedded_block_arrangement = false +csharp_place_simple_embedded_block_on_same_line = false +csharp_place_simple_anonymousmethod_on_single_line = false +csharp_keep_existing_initializer_arrangement = false +csharp_place_simple_initializer_on_single_line = false +csharp_wrap_object_and_collection_initializer_style = chop_always +csharp_wrap_array_initializer_style = wrap_if_long +csharp_wrap_arguments_style = wrap_if_long +csharp_keep_existing_invocation_parens_arrangement = false +csharp_wrap_after_invocation_lpar = false +csharp_wrap_before_invocation_rpar = false +csharp_wrap_after_dot_in_method_calls = true +csharp_wrap_chained_method_calls = wrap_if_long +csharp_wrap_before_binary_opsign = false +csharp_wrap_chained_binary_expressions = wrap_if_long +csharp_force_chop_compound_if_expression = true +csharp_force_chop_compound_while_expression = true +csharp_force_chop_compound_do_expression = true +csharp_wrap_before_ternary_opsigns = true +csharp_wrap_ternary_expr_style = wrap_if_long +csharp_nested_ternary_style = expanded +csharp_wrap_linq_expressions = wrap_if_long +csharp_wrap_before_linq_expression = false +csharp_place_linq_into_on_new_line = false +csharp_wrap_verbatim_interpolated_strings = wrap_if_long +csharp_extra_spaces = remove_all +csharp_space_after_keywords_in_control_flow_statements = false +csharp_space_between_method_call_name_and_opening_parenthesis = false +csharp_space_between_method_declaration_name_and_open_parenthesis = false +csharp_space_before_typeof_parentheses = false +csharp_space_before_checked_parentheses = false +csharp_space_before_sizeof_parentheses = false +csharp_space_before_nameof_parentheses = false +csharp_space_between_keyword_and_expression = true +csharp_space_between_keyword_and_type = true +csharp_space_around_assignment_op = true +csharp_space_around_logical_op = true +csharp_space_around_binary_operator = true +csharp_space_around_equality_op = true +csharp_space_around_relational_op = true +csharp_space_around_bitwise_op = true +csharp_space_around_additive_op = true +csharp_space_around_multiplicative_op = true +csharp_space_around_shift_op = true +csharp_space_around_nullcoalescing_op = true +csharp_space_around_arrow_op = false +csharp_space_after_logical_not_op = false +csharp_space_after_unary_operator = false +csharp_space_after_cast = false +csharp_space_around_dot = false +csharp_space_around_lambda_arrow = true +csharp_space_before_pointer_asterik_declaration = false +csharp_space_before_nullable_mark = false [*.cshtml] -linebreaks_around_razor_statements=true -blank_lines_around_razor_functions=true -blank_lines_around_razor_helpers=true -blank_lines_around_razor_sections=true +linebreaks_around_razor_statements = true +blank_lines_around_razor_functions = true +blank_lines_around_razor_helpers = true +blank_lines_around_razor_sections = true # C++ [*.{cc,cpp,cxx,h,hpp,hxx}] -cpp_indent_access_specifiers_from_class=true -cpp_indent_wrapped_function_names=false -cpp_align_multiline_type_argument=true +cpp_indent_access_specifiers_from_class = true +cpp_indent_wrapped_function_names = false +cpp_align_multiline_type_argument = true # C, C++ and ObjectiveC [*.{c,h,cc,cpp,cxx,m,hpp,hxx}] -indent_preprocessor_directives=normal -indent_type_constraints=true +indent_preprocessor_directives = normal +indent_type_constraints = true # Javascript and Typescript [*.{js,js.map,ts}] -quote_style=doublequoted -termination_style=ensure_semicolon \ No newline at end of file +quote_style = doublequoted +termination_style = ensure_semicolon \ No newline at end of file diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index aa32335ae..2de97d708 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -54,22 +54,22 @@ false - + - - - - - - - - - - - - - + + + + + + + + + + + + + @@ -83,39 +83,39 @@ - - + + - - - + + + - - - - - /Library/Frameworks/Mono.framework/Versions/Current/lib/mono - /usr/lib/mono - /usr/local/lib/mono - - $(BaseFrameworkPathOverrideForMono)/4.0-api - $(BaseFrameworkPathOverrideForMono)/4.5-api - $(BaseFrameworkPathOverrideForMono)/4.5.1-api - $(BaseFrameworkPathOverrideForMono)/4.5.2-api - $(BaseFrameworkPathOverrideForMono)/4.6-api - $(BaseFrameworkPathOverrideForMono)/4.6.1-api - $(BaseFrameworkPathOverrideForMono)/4.6.2-api - $(BaseFrameworkPathOverrideForMono)/4.7-api - $(BaseFrameworkPathOverrideForMono)/4.7.1-api - true - - $(FrameworkPathOverride)/Facades;$(AssemblySearchPaths) - + + + + + /Library/Frameworks/Mono.framework/Versions/Current/lib/mono + /usr/lib/mono + /usr/local/lib/mono + + $(BaseFrameworkPathOverrideForMono)/4.0-api + $(BaseFrameworkPathOverrideForMono)/4.5-api + $(BaseFrameworkPathOverrideForMono)/4.5.1-api + $(BaseFrameworkPathOverrideForMono)/4.5.2-api + $(BaseFrameworkPathOverrideForMono)/4.6-api + $(BaseFrameworkPathOverrideForMono)/4.6.1-api + $(BaseFrameworkPathOverrideForMono)/4.6.2-api + $(BaseFrameworkPathOverrideForMono)/4.7-api + $(BaseFrameworkPathOverrideForMono)/4.7.1-api + true + + $(FrameworkPathOverride)/Facades;$(AssemblySearchPaths) + \ No newline at end of file diff --git a/ArrayIsEmpty.cs b/ArrayIsEmpty.cs index 11688c667..100ac96c0 100644 --- a/ArrayIsEmpty.cs +++ b/ArrayIsEmpty.cs @@ -34,9 +34,7 @@ namespace Aaru.Helpers { - /// - /// Helper operations to work with arrays - /// + /// Helper operations to work with arrays public static partial class ArrayHelpers { /// Checks if an array is null, filled with the NULL byte (0x00) or ASCII whitespace (0x20) diff --git a/BigEndianBitConverter.cs b/BigEndianBitConverter.cs index 54b2b4e30..b2345b311 100644 --- a/BigEndianBitConverter.cs +++ b/BigEndianBitConverter.cs @@ -305,9 +305,7 @@ public static uint ToUInt32(byte[] value, int startIndex) => public static ulong ToUInt64(byte[] value, int startIndex) => BitConverter.ToUInt64(value.Reverse().ToArray(), value.Length - sizeof(ulong) - startIndex); - /// - /// Converts a big endian byte array representation of a GUID into the .NET Guid structure - /// + /// Converts a big endian byte array representation of a GUID into the .NET Guid structure /// Byte array containing a GUID in big endian /// Start of the byte array to process /// Processed Guid diff --git a/CHS.cs b/CHS.cs index 85600e3f9..166e70259 100644 --- a/CHS.cs +++ b/CHS.cs @@ -32,9 +32,7 @@ namespace Aaru.Helpers { - /// - /// Helper operations to work with CHS values - /// + /// Helper operations to work with CHS values public static class CHS { /// Converts a CHS position to a LBA one diff --git a/CountBits.cs b/CountBits.cs index e8dfcdb02..7351d536c 100644 --- a/CountBits.cs +++ b/CountBits.cs @@ -32,9 +32,7 @@ namespace Aaru.Helpers { - /// - /// Helper operations to count bits - /// + /// Helper operations to count bits public static class CountBits { /// Counts the number of bits set to true in a number diff --git a/DateHandlers.cs b/DateHandlers.cs index e3ec874bc..73ae942d8 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -36,9 +36,7 @@ namespace Aaru.Helpers { - /// - /// Helper operations for timestamp management (date and time) - /// + /// Helper operations for timestamp management (date and time) public static class DateHandlers { static readonly DateTime _lisaEpoch = new DateTime(1901, 1, 1, 0, 0, 0); diff --git a/Marshal.cs b/Marshal.cs index 5985b9192..3bbc09947 100644 --- a/Marshal.cs +++ b/Marshal.cs @@ -266,8 +266,7 @@ public static T MarshalStructure(byte[] bytes) where T : struct /// Swaps all members of a structure /// /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [SuppressMessage("ReSharper", "InconsistentNaming")] + [MethodImpl(MethodImplOptions.AggressiveInlining), SuppressMessage("ReSharper", "InconsistentNaming")] public static object SwapStructureMembersEndian(object str) { Type t = str.GetType(); @@ -362,9 +361,7 @@ public static object SwapStructureMembersEndian(object str) return str; } - /// - /// Swaps all fields in an structure considering them to follow PDP endian conventions - /// + /// Swaps all fields in an structure considering them to follow PDP endian conventions /// Source structure /// Resulting structure [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -435,9 +432,7 @@ public static byte[] StructureToByteArrayLittleEndian(T str) where T : struct public static byte[] StructureToByteArrayBigEndian(T str) where T : struct => StructureToByteArrayLittleEndian((T)SwapStructureMembersEndian(str)); - /// - /// Converts a hexadecimal string into a byte array - /// + /// Converts a hexadecimal string into a byte array /// Hexadecimal string /// Resulting byte array /// Number of output bytes processed diff --git a/PrintHex.cs b/PrintHex.cs index 943399704..a06870bd3 100644 --- a/PrintHex.cs +++ b/PrintHex.cs @@ -35,9 +35,7 @@ namespace Aaru.Helpers { - /// - /// Helper operations to get hexadecimal representations of byte arrays - /// + /// Helper operations to get hexadecimal representations of byte arrays public static class PrintHex { /// Prints a byte array as hexadecimal values to the console diff --git a/StringHandlers.cs b/StringHandlers.cs index 85fd2bddf..42fb176f3 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -35,9 +35,7 @@ namespace Aaru.Helpers { - /// - /// Helper operations to work with strings - /// + /// Helper operations to work with strings public static class StringHandlers { /// Converts a null-terminated (aka C string) ASCII byte array to a C# string diff --git a/Swapping.cs b/Swapping.cs index 71ff96848..29134cac5 100644 --- a/Swapping.cs +++ b/Swapping.cs @@ -34,46 +34,34 @@ namespace Aaru.Helpers { - /// - /// Helper operations to work with swapping endians - /// + /// Helper operations to work with swapping endians public static class Swapping { - /// - /// Gets the PDP endian equivalent of the given little endian unsigned integer - /// + /// Gets the PDP endian equivalent of the given little endian unsigned integer /// Little endian unsigned integer /// PDP unsigned integer [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint PDPFromLittleEndian(uint x) => ((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16); - /// - /// Gets the PDP endian equivalent of the given big endian unsigned integer - /// + /// Gets the PDP endian equivalent of the given big endian unsigned integer /// Big endian unsigned integer /// PDP unsigned integer [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint PDPFromBigEndian(uint x) => ((x & 0xff00ff) << 8) | ((x & 0xff00ff00) >> 8); - /// - /// Swaps the endian of the specified unsigned short integer - /// + /// Swaps the endian of the specified unsigned short integer /// Unsigned short integer /// Swapped unsigned short integer [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ushort Swap(ushort x) => (ushort)((x << 8) | (x >> 8)); - /// - /// Swaps the endian of the specified signed short integer - /// + /// Swaps the endian of the specified signed short integer /// Signed short integer /// Swapped signed short integer [MethodImpl(MethodImplOptions.AggressiveInlining)] public static short Swap(short x) => (short)((x << 8) | ((x >> 8) & 0xFF)); - /// - /// Swaps the endian of the specified unsigned integer - /// + /// Swaps the endian of the specified unsigned integer /// Unsigned integer /// Swapped unsigned integer [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -84,9 +72,7 @@ public static uint Swap(uint x) return (x << 16) | (x >> 16); } - /// - /// Swaps the endian of the specified signed integer - /// + /// Swaps the endian of the specified signed integer /// Signed integer /// Swapped signed integer [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -97,9 +83,7 @@ public static int Swap(int x) return (int)(((uint)x << 16) | (((uint)x >> 16) & 0xFFFF)); } - /// - /// Swaps the endian of the specified unsigned long integer - /// + /// Swaps the endian of the specified unsigned long integer /// Unsigned long integer /// Swapped unsigned long integer [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -112,9 +96,7 @@ public static ulong Swap(ulong x) return x; } - /// - /// Swaps the endian of the specified signed long integer - /// + /// Swaps the endian of the specified signed long integer /// Signed long integer /// Swapped signed long integer [MethodImpl(MethodImplOptions.AggressiveInlining)] From bbd634f686da43f0c4968f04be056fc139b4daf1 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 12 Sep 2021 21:34:23 +0100 Subject: [PATCH 160/217] Bump version to 6.0.0-alpha6. --- Aaru.Helpers.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index 2de97d708..2241d65ea 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -11,7 +11,7 @@ $(Version) false true - 5.2.99.3380-alpha + 6.0.0-alpha6 Claunia.com Copyright © 2011-2021 Natalia Portillo Aaru Data Preservation Suite From c01b2bd3e697c186fec0920a5bd163b29b56f955 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 12 Sep 2021 22:25:59 +0100 Subject: [PATCH 161/217] Upgrade to .NET 6. --- Aaru.Helpers.csproj | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index 2241d65ea..cdc1029f8 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -17,8 +17,8 @@ Aaru Data Preservation Suite Aaru.Helpers $(Version) - netcoreapp3.1 - 8 + net6 + 10 Contains helpers used by the Aaru Data Preservation Suite. https://github.com/aaru-dps/ LGPL-2.1-only @@ -29,6 +29,7 @@ true snupkg Natalia Portillo <claunia@claunia.com> + true $(Version)+{chash:8} From 15ae1080e0d5af2f745e3409adddf4a3c11b11ec Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 12 Sep 2021 22:53:19 +0100 Subject: [PATCH 162/217] Upgrade dependencies. --- Aaru.Helpers.csproj | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index cdc1029f8..9650e64bd 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -55,22 +55,22 @@ false - + - - - - - - - - - - - - - + + + + + + + + + + + + + @@ -84,16 +84,16 @@ - - + + - - - + + + From aabda1134c6a405e4b8a943f0f2064fc48a42693 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 8 Dec 2021 20:39:48 +0000 Subject: [PATCH 163/217] Bump version to 6.0.0-alpha7. --- Aaru.Helpers.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index 9650e64bd..63c05e99b 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -11,7 +11,7 @@ $(Version) false true - 6.0.0-alpha6 + 6.0.0-alpha7 Claunia.com Copyright © 2011-2021 Natalia Portillo Aaru Data Preservation Suite From 4640bb88d3eb907d0f0617d5ee5159fbc13c5653 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 8 Dec 2021 21:48:35 +0000 Subject: [PATCH 164/217] Bump version to 6.0.0-alpha8. --- Aaru.Helpers.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index 63c05e99b..5f1795dfc 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -11,7 +11,7 @@ $(Version) false true - 6.0.0-alpha7 + 6.0.0-alpha8 Claunia.com Copyright © 2011-2021 Natalia Portillo Aaru Data Preservation Suite From 22dab929067fb0e3072188c32ebac7e253a8e0d7 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 15 Feb 2022 10:19:15 +0000 Subject: [PATCH 165/217] Updated dependencies. --- Aaru.Helpers.csproj | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index 5f1795dfc..adfcd3f8e 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -8,7 +8,7 @@ Library Aaru.Helpers Aaru.Helpers - $(Version) + 4.0.99.0 false true 6.0.0-alpha8 @@ -40,7 +40,7 @@ true full false - bin\Debug + bin\Debug\net6 DEBUG; prompt 4 @@ -49,7 +49,7 @@ full true - bin\Release + bin\Release\net6 prompt 4 false @@ -74,8 +74,6 @@ - {CCAA7AFE-C094-4D82-A66D-630DE8A3F545} - Aaru.Console @@ -85,7 +83,7 @@ - + @@ -93,7 +91,7 @@ - + From 1095f36c86cbe26e3feac328c6c6d142327a726e Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 15 Feb 2022 11:03:18 +0000 Subject: [PATCH 166/217] Fix MSBuild project change made by VSMac. --- Aaru.Helpers.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index adfcd3f8e..5c060a663 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -8,7 +8,7 @@ Library Aaru.Helpers Aaru.Helpers - 4.0.99.0 + $(Version) false true 6.0.0-alpha8 From 31750d5978227626f2f6020e0eca17189e6ed5d4 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Fri, 18 Feb 2022 10:02:41 +0000 Subject: [PATCH 167/217] Update copyright year. --- Aaru.Helpers.csproj | 2 +- ArrayFill.cs | 2 +- ArrayIsEmpty.cs | 2 +- BigEndianBitConverter.cs | 2 +- BitEndian.cs | 2 +- CHS.cs | 2 +- CompareBytes.cs | 2 +- CountBits.cs | 2 +- DateHandlers.cs | 2 +- Marshal.cs | 2 +- MarshallingPropertiesAttribute.cs | 2 +- PrintHex.cs | 2 +- StringHandlers.cs | 2 +- Swapping.cs | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index 5c060a663..2fd832faa 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -13,7 +13,7 @@ true 6.0.0-alpha8 Claunia.com - Copyright © 2011-2021 Natalia Portillo + Copyright © 2011-2022 Natalia Portillo Aaru Data Preservation Suite Aaru.Helpers $(Version) diff --git a/ArrayFill.cs b/ArrayFill.cs index ff3ab5a3e..a0c3687ac 100644 --- a/ArrayFill.cs +++ b/ArrayFill.cs @@ -20,7 +20,7 @@ // Assuming open source. // // ---------------------------------------------------------------------------- -// Copyright © 2011-2021 Natalia Portillo +// Copyright © 2011-2022 Natalia Portillo // Copyright(C) 2014 mykohsu // ****************************************************************************/ diff --git a/ArrayIsEmpty.cs b/ArrayIsEmpty.cs index 100ac96c0..77a6f23f8 100644 --- a/ArrayIsEmpty.cs +++ b/ArrayIsEmpty.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2021 Natalia Portillo +// Copyright © 2011-2022 Natalia Portillo // ****************************************************************************/ using System.Linq; diff --git a/BigEndianBitConverter.cs b/BigEndianBitConverter.cs index b2345b311..34e683989 100644 --- a/BigEndianBitConverter.cs +++ b/BigEndianBitConverter.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2021 Natalia Portillo +// Copyright © 2011-2022 Natalia Portillo // ****************************************************************************/ using System; diff --git a/BitEndian.cs b/BitEndian.cs index 0205652e7..857a35a30 100644 --- a/BitEndian.cs +++ b/BitEndian.cs @@ -33,7 +33,7 @@ // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // ---------------------------------------------------------------------------- -// Copyright © 2011-2021 Natalia Portillo +// Copyright © 2011-2022 Natalia Portillo // ****************************************************************************/ namespace Aaru.Helpers diff --git a/CHS.cs b/CHS.cs index 166e70259..b31d37dfb 100644 --- a/CHS.cs +++ b/CHS.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2021 Natalia Portillo +// Copyright © 2011-2022 Natalia Portillo // ****************************************************************************/ namespace Aaru.Helpers diff --git a/CompareBytes.cs b/CompareBytes.cs index 18acac965..96dff9cec 100644 --- a/CompareBytes.cs +++ b/CompareBytes.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2021 Natalia Portillo +// Copyright © 2011-2022 Natalia Portillo // ****************************************************************************/ namespace Aaru.Helpers diff --git a/CountBits.cs b/CountBits.cs index 7351d536c..88cd8d473 100644 --- a/CountBits.cs +++ b/CountBits.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2021 Natalia Portillo +// Copyright © 2011-2022 Natalia Portillo // ****************************************************************************/ namespace Aaru.Helpers diff --git a/DateHandlers.cs b/DateHandlers.cs index 73ae942d8..c86b3d233 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2021 Natalia Portillo +// Copyright © 2011-2022 Natalia Portillo // ****************************************************************************/ using System; diff --git a/Marshal.cs b/Marshal.cs index 3bbc09947..d2c03e90f 100644 --- a/Marshal.cs +++ b/Marshal.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2021 Natalia Portillo +// Copyright © 2011-2022 Natalia Portillo // ****************************************************************************/ using System; diff --git a/MarshallingPropertiesAttribute.cs b/MarshallingPropertiesAttribute.cs index c148ac91e..3110674cb 100644 --- a/MarshallingPropertiesAttribute.cs +++ b/MarshallingPropertiesAttribute.cs @@ -33,7 +33,7 @@ // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // ---------------------------------------------------------------------------- -// Copyright © 2011-2021 Natalia Portillo +// Copyright © 2011-2022 Natalia Portillo // ****************************************************************************/ using System; diff --git a/PrintHex.cs b/PrintHex.cs index a06870bd3..c3ca7cd6a 100644 --- a/PrintHex.cs +++ b/PrintHex.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2021 Natalia Portillo +// Copyright © 2011-2022 Natalia Portillo // ****************************************************************************/ using System.Text; diff --git a/StringHandlers.cs b/StringHandlers.cs index 42fb176f3..560c662c7 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2021 Natalia Portillo +// Copyright © 2011-2022 Natalia Portillo // ****************************************************************************/ using System; diff --git a/Swapping.cs b/Swapping.cs index 29134cac5..39498721e 100644 --- a/Swapping.cs +++ b/Swapping.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2021 Natalia Portillo +// Copyright © 2011-2022 Natalia Portillo // ****************************************************************************/ using System.Runtime.CompilerServices; From cb79ff60d68d61eed2b0f3f0e880d7f0bffb655c Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 6 Mar 2022 13:29:37 +0000 Subject: [PATCH 168/217] Move to file scoped namespaces. --- ArrayFill.cs | 77 ++- ArrayIsEmpty.cs | 25 +- BigEndianBitConverter.cs | 523 ++++++++++---------- BitEndian.cs | 21 +- CHS.cs | 29 +- CompareBytes.cs | 63 ++- CountBits.cs | 23 +- DateHandlers.cs | 581 +++++++++++----------- Marshal.cs | 795 +++++++++++++++--------------- MarshallingPropertiesAttribute.cs | 31 +- PrintHex.cs | 145 +++--- StringHandlers.cs | 231 +++++---- Swapping.cs | 127 +++-- 13 files changed, 1329 insertions(+), 1342 deletions(-) diff --git a/ArrayFill.cs b/ArrayFill.cs index a0c3687ac..53edd1498 100644 --- a/ArrayFill.cs +++ b/ArrayFill.cs @@ -27,55 +27,54 @@ using System; using System.Text; -namespace Aaru.Helpers +namespace Aaru.Helpers; + +public static partial class ArrayHelpers { - public static partial class ArrayHelpers + /// Fills an array with the specified value + /// Array + /// Value + /// Array type + public static void ArrayFill(T[] destinationArray, T value) => ArrayFill(destinationArray, new[] { - /// Fills an array with the specified value - /// Array - /// Value - /// Array type - public static void ArrayFill(T[] destinationArray, T value) => ArrayFill(destinationArray, new[] - { - value - }); + value + }); - /// Fills an array with the contents of the specified array - /// Array - /// Value - /// Array type - public static void ArrayFill(T[] destinationArray, T[] value) - { - if(destinationArray == null) - throw new ArgumentNullException(nameof(destinationArray)); + /// Fills an array with the contents of the specified array + /// Array + /// Value + /// Array type + public static void ArrayFill(T[] destinationArray, T[] value) + { + if(destinationArray == null) + throw new ArgumentNullException(nameof(destinationArray)); - if(value.Length > destinationArray.Length) - throw new ArgumentException("Length of value array must not be more than length of destination"); + if(value.Length > destinationArray.Length) + throw new ArgumentException("Length of value array must not be more than length of destination"); - // set the initial array value - Array.Copy(value, destinationArray, value.Length); + // set the initial array value + Array.Copy(value, destinationArray, value.Length); - int arrayToFillHalfLength = destinationArray.Length / 2; - int copyLength; + int arrayToFillHalfLength = destinationArray.Length / 2; + int copyLength; - for(copyLength = value.Length; copyLength < arrayToFillHalfLength; copyLength <<= 1) - Array.Copy(destinationArray, 0, destinationArray, copyLength, copyLength); + for(copyLength = value.Length; copyLength < arrayToFillHalfLength; copyLength <<= 1) + Array.Copy(destinationArray, 0, destinationArray, copyLength, copyLength); - Array.Copy(destinationArray, 0, destinationArray, copyLength, destinationArray.Length - copyLength); - } + Array.Copy(destinationArray, 0, destinationArray, copyLength, destinationArray.Length - copyLength); + } - /// Converts a byte array to its hexadecimal representation - /// Byte array - /// true to use uppercase - /// - public static string ByteArrayToHex(byte[] array, bool upper = false) - { - var sb = new StringBuilder(); + /// Converts a byte array to its hexadecimal representation + /// Byte array + /// true to use uppercase + /// + public static string ByteArrayToHex(byte[] array, bool upper = false) + { + var 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]); - return upper ? sb.ToString().ToUpper() : sb.ToString(); - } + return upper ? sb.ToString().ToUpper() : sb.ToString(); } } \ No newline at end of file diff --git a/ArrayIsEmpty.cs b/ArrayIsEmpty.cs index 77a6f23f8..93aa33011 100644 --- a/ArrayIsEmpty.cs +++ b/ArrayIsEmpty.cs @@ -32,19 +32,18 @@ using System.Linq; -namespace Aaru.Helpers +namespace Aaru.Helpers; + +/// Helper operations to work with arrays +public static partial class ArrayHelpers { - /// Helper operations to work with arrays - public static partial class ArrayHelpers - { - /// Checks if an array is null, filled with the NULL byte (0x00) or ASCII whitespace (0x20) - /// Array - /// True if null or whitespace - public static bool ArrayIsNullOrWhiteSpace(byte[] array) => array?.All(b => b == 0x00 || b == 0x20) != false; + /// Checks if an array is null, filled with the NULL byte (0x00) or ASCII whitespace (0x20) + /// Array + /// True if null or whitespace + public static bool ArrayIsNullOrWhiteSpace(byte[] array) => array?.All(b => b == 0x00 || b == 0x20) != false; - /// Checks if an array is null or filled with the NULL byte (0x00) - /// Array - /// True if null - public static bool ArrayIsNullOrEmpty(byte[] array) => array?.All(b => b == 0x00) != false; - } + /// Checks if an array is null or filled with the NULL byte (0x00) + /// Array + /// True if null + public static bool ArrayIsNullOrEmpty(byte[] array) => array?.All(b => b == 0x00) != false; } \ No newline at end of file diff --git a/BigEndianBitConverter.cs b/BigEndianBitConverter.cs index 34e683989..03cf0add6 100644 --- a/BigEndianBitConverter.cs +++ b/BigEndianBitConverter.cs @@ -33,292 +33,291 @@ using System; using System.Linq; -namespace Aaru.Helpers +namespace Aaru.Helpers; + +/// +/// Converts base data types to an array of bytes, and an array of bytes to base data types. All info taken from +/// the meta data of System.BitConverter. This implementation allows for Endianness consideration. +/// +public static class BigEndianBitConverter { - /// - /// Converts base data types to an array of bytes, and an array of bytes to base data types. All info taken from - /// the meta data of System.BitConverter. This implementation allows for Endianness consideration. - /// - public static class BigEndianBitConverter - { - /// Converts the specified double-precision floating point number to a 64-bit signed integer. - /// The number to convert. - /// A 64-bit signed integer whose value is equivalent to value. - /// It is not currently implemented - public static long DoubleToInt64Bits(double value) => throw new NotImplementedException(); + /// Converts the specified double-precision floating point number to a 64-bit signed integer. + /// The number to convert. + /// A 64-bit signed integer whose value is equivalent to value. + /// It is not currently implemented + public static long DoubleToInt64Bits(double value) => throw new NotImplementedException(); - /// Returns the specified Boolean value as an array of bytes. - /// A Boolean value. - /// An array of bytes with length 1. - public static byte[] GetBytes(bool value) => BitConverter.GetBytes(value).Reverse().ToArray(); + /// Returns the specified Boolean value as an array of bytes. + /// A Boolean value. + /// An array of bytes with length 1. + public static byte[] GetBytes(bool value) => BitConverter.GetBytes(value).Reverse().ToArray(); - /// Returns the specified Unicode character value as an array of bytes. - /// A character to convert. - /// An array of bytes with length 2. - public static byte[] GetBytes(char value) => BitConverter.GetBytes(value).Reverse().ToArray(); + /// Returns the specified Unicode character value as an array of bytes. + /// A character to convert. + /// An array of bytes with length 2. + public static byte[] GetBytes(char value) => BitConverter.GetBytes(value).Reverse().ToArray(); - /// Returns the specified double-precision floating point value as an array of bytes. - /// The number to convert. - /// An array of bytes with length 8. - public static byte[] GetBytes(double value) => BitConverter.GetBytes(value).Reverse().ToArray(); + /// Returns the specified double-precision floating point value as an array of bytes. + /// The number to convert. + /// An array of bytes with length 8. + public static byte[] GetBytes(double value) => BitConverter.GetBytes(value).Reverse().ToArray(); - /// Returns the specified single-precision floating point value as an array of bytes. - /// The number to convert. - /// An array of bytes with length 4. - public static byte[] GetBytes(float value) => BitConverter.GetBytes(value).Reverse().ToArray(); + /// Returns the specified single-precision floating point value as an array of bytes. + /// The number to convert. + /// An array of bytes with length 4. + public static byte[] GetBytes(float value) => BitConverter.GetBytes(value).Reverse().ToArray(); - /// Returns the specified 32-bit signed integer value as an array of bytes. - /// The number to convert. - /// An array of bytes with length 4. - public static byte[] GetBytes(int value) => BitConverter.GetBytes(value).Reverse().ToArray(); + /// Returns the specified 32-bit signed integer value as an array of bytes. + /// The number to convert. + /// An array of bytes with length 4. + public static byte[] GetBytes(int value) => BitConverter.GetBytes(value).Reverse().ToArray(); - /// Returns the specified 64-bit signed integer value as an array of bytes. - /// The number to convert. - /// An array of bytes with length 8. - public static byte[] GetBytes(long value) => BitConverter.GetBytes(value).Reverse().ToArray(); + /// Returns the specified 64-bit signed integer value as an array of bytes. + /// The number to convert. + /// An array of bytes with length 8. + public static byte[] GetBytes(long value) => BitConverter.GetBytes(value).Reverse().ToArray(); - /// Returns the specified 16-bit signed integer value as an array of bytes. - /// The number to convert. - /// An array of bytes with length 2. - public static byte[] GetBytes(short value) => BitConverter.GetBytes(value).Reverse().ToArray(); + /// Returns the specified 16-bit signed integer value as an array of bytes. + /// The number to convert. + /// An array of bytes with length 2. + public static byte[] GetBytes(short value) => BitConverter.GetBytes(value).Reverse().ToArray(); - /// Returns the specified 32-bit unsigned integer value as an array of bytes. - /// The number to convert. - /// An array of bytes with length 4. - public static byte[] GetBytes(uint value) => BitConverter.GetBytes(value).Reverse().ToArray(); + /// Returns the specified 32-bit unsigned integer value as an array of bytes. + /// The number to convert. + /// An array of bytes with length 4. + public static byte[] GetBytes(uint value) => BitConverter.GetBytes(value).Reverse().ToArray(); - /// Returns the specified 64-bit unsigned integer value as an array of bytes. - /// The number to convert. - /// An array of bytes with length 8. - public static byte[] GetBytes(ulong value) => BitConverter.GetBytes(value).Reverse().ToArray(); + /// Returns the specified 64-bit unsigned integer value as an array of bytes. + /// The number to convert. + /// An array of bytes with length 8. + public static byte[] GetBytes(ulong value) => BitConverter.GetBytes(value).Reverse().ToArray(); - /// Returns the specified 16-bit unsigned integer value as an array of bytes. - /// The number to convert. - /// An array of bytes with length 2. - public static byte[] GetBytes(ushort value) => BitConverter.GetBytes(value).Reverse().ToArray(); + /// Returns the specified 16-bit unsigned integer value as an array of bytes. + /// The number to convert. + /// An array of bytes with length 2. + public static byte[] GetBytes(ushort value) => BitConverter.GetBytes(value).Reverse().ToArray(); - /// Converts the specified 64-bit signed integer to a double-precision floating point number. - /// The number to convert. - /// A double-precision floating point number whose value is equivalent to value. - public static double Int64BitsToDouble(long value) => throw new NotImplementedException(); + /// Converts the specified 64-bit signed integer to a double-precision floating point number. + /// The number to convert. + /// A double-precision floating point number whose value is equivalent to value. + public static double Int64BitsToDouble(long value) => throw new NotImplementedException(); - /// Returns a Boolean value converted from one byte at a specified position in a byte array. - /// An array of bytes. - /// The starting position within value. - /// true if the byte at in value is nonzero; otherwise, false. - /// value is null. - /// - /// is less than zero or greater than the - /// length of value minus 1. - /// - public static bool ToBoolean(byte[] value, int startIndex) => throw new NotImplementedException(); + /// Returns a Boolean value converted from one byte at a specified position in a byte array. + /// An array of bytes. + /// The starting position within value. + /// true if the byte at in value is nonzero; otherwise, false. + /// value is null. + /// + /// is less than zero or greater than the + /// length of value minus 1. + /// + public static bool ToBoolean(byte[] value, int startIndex) => throw new NotImplementedException(); - /// Returns a Unicode character converted from two bytes at a specified position in a byte array. - /// An array. - /// The starting position within value. - /// A character formed by two bytes beginning at . - /// equals the length of value minus 1. - /// value is null. - /// - /// is less than zero or greater than the - /// length of value minus 1. - /// - public static char ToChar(byte[] value, int startIndex) => throw new NotImplementedException(); + /// Returns a Unicode character converted from two bytes at a specified position in a byte array. + /// An array. + /// The starting position within value. + /// A character formed by two bytes beginning at . + /// equals the length of value minus 1. + /// value is null. + /// + /// is less than zero or greater than the + /// length of value minus 1. + /// + public static char ToChar(byte[] value, int startIndex) => throw new NotImplementedException(); - /// - /// Returns a double-precision floating point number converted from eight bytes at a specified position in a byte - /// array. - /// - /// An array of bytes. - /// The starting position within value. - /// A double precision floating point number formed by eight bytes beginning at . - /// - /// 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. - /// - /// value is null. - /// - /// is less than zero or greater than the - /// length of value minus 1. - /// - public static double ToDouble(byte[] value, int startIndex) => throw new NotImplementedException(); + /// + /// Returns a double-precision floating point number converted from eight bytes at a specified position in a byte + /// array. + /// + /// An array of bytes. + /// The starting position within value. + /// A double precision floating point number formed by eight bytes beginning at . + /// + /// 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. + /// + /// value is null. + /// + /// is less than zero or greater than the + /// length of value minus 1. + /// + public static double ToDouble(byte[] value, int startIndex) => throw new NotImplementedException(); - /// Returns a 16-bit signed integer converted from two bytes at a specified position in a byte array. - /// An array of bytes. - /// The starting position within value. - /// A 16-bit signed integer formed by two bytes beginning at . - /// equals the length of value minus 1. - /// value is null. - /// - /// startIndex is less than zero or greater than the length of value - /// minus 1. - /// - public static short ToInt16(byte[] value, int startIndex) => - BitConverter.ToInt16(value.Reverse().ToArray(), value.Length - sizeof(short) - startIndex); + /// Returns a 16-bit signed integer converted from two bytes at a specified position in a byte array. + /// An array of bytes. + /// The starting position within value. + /// A 16-bit signed integer formed by two bytes beginning at . + /// equals the length of value minus 1. + /// value is null. + /// + /// startIndex is less than zero or greater than the length of value + /// minus 1. + /// + public static short ToInt16(byte[] value, int startIndex) => + BitConverter.ToInt16(value.Reverse().ToArray(), value.Length - sizeof(short) - startIndex); - /// Returns a 32-bit signed integer converted from four bytes at a specified position in a byte array. - /// An array of bytes. - /// The starting position within value. - /// A 32-bit signed integer formed by four bytes beginning at . - /// - /// 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. - /// - /// value is null. - /// - /// startIndex is less than zero or greater than the length of value - /// minus 1. - /// - public static int ToInt32(byte[] value, int startIndex) => - BitConverter.ToInt32(value.Reverse().ToArray(), value.Length - sizeof(int) - startIndex); + /// Returns a 32-bit signed integer converted from four bytes at a specified position in a byte array. + /// An array of bytes. + /// The starting position within value. + /// A 32-bit signed integer formed by four bytes beginning at . + /// + /// 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. + /// + /// value is null. + /// + /// startIndex is less than zero or greater than the length of value + /// minus 1. + /// + public static int ToInt32(byte[] value, int startIndex) => + BitConverter.ToInt32(value.Reverse().ToArray(), value.Length - sizeof(int) - startIndex); - /// Returns a 64-bit signed integer converted from eight bytes at a specified position in a byte array. - /// An array of bytes. - /// The starting position within value. - /// A 64-bit signed integer formed by eight bytes beginning at . - /// - /// 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. - /// - /// value is null. - /// - /// is less than zero or greater than the - /// length of value minus 1. - /// - public static long ToInt64(byte[] value, int startIndex) => - BitConverter.ToInt64(value.Reverse().ToArray(), value.Length - sizeof(long) - startIndex); + /// Returns a 64-bit signed integer converted from eight bytes at a specified position in a byte array. + /// An array of bytes. + /// The starting position within value. + /// A 64-bit signed integer formed by eight bytes beginning at . + /// + /// 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. + /// + /// value is null. + /// + /// is less than zero or greater than the + /// length of value minus 1. + /// + public static long ToInt64(byte[] value, int startIndex) => + BitConverter.ToInt64(value.Reverse().ToArray(), value.Length - sizeof(long) - startIndex); - /// - /// Returns a single-precision floating point number converted from four bytes at a specified position in a byte - /// array. - /// - /// An array of bytes. - /// The starting position within value. - /// A single-precision floating point number formed by four bytes beginning at . - /// - /// 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. - /// - /// value is null. - /// - /// is less than zero or greater than the - /// length of value minus 1. - /// - public static float ToSingle(byte[] value, int startIndex) => - BitConverter.ToSingle(value.Reverse().ToArray(), value.Length - sizeof(float) - startIndex); + /// + /// Returns a single-precision floating point number converted from four bytes at a specified position in a byte + /// array. + /// + /// An array of bytes. + /// The starting position within value. + /// A single-precision floating point number formed by four bytes beginning at . + /// + /// 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. + /// + /// value is null. + /// + /// is less than zero or greater than the + /// length of value minus 1. + /// + public static float ToSingle(byte[] value, int startIndex) => + BitConverter.ToSingle(value.Reverse().ToArray(), value.Length - sizeof(float) - startIndex); - /// - /// Converts the numeric value of each element of a specified array of bytes to its equivalent hexadecimal string - /// representation. - /// - /// An array of bytes. - /// - /// A System.String of hexadecimal pairs separated by hyphens, where each pair represents the corresponding - /// element in value; for example, "7F-2C-4A". - /// - /// value is null. - public static string ToString(byte[] value) => BitConverter.ToString(value.Reverse().ToArray()); + /// + /// Converts the numeric value of each element of a specified array of bytes to its equivalent hexadecimal string + /// representation. + /// + /// An array of bytes. + /// + /// A System.String of hexadecimal pairs separated by hyphens, where each pair represents the corresponding + /// element in value; for example, "7F-2C-4A". + /// + /// value is null. + public static string ToString(byte[] value) => BitConverter.ToString(value.Reverse().ToArray()); - /// - /// Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal - /// string representation. - /// - /// An array of bytes. - /// The starting position within value. - /// - /// 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". - /// - /// value is null. - /// - /// startIndex is less than zero or greater than the length of value - /// minus 1. - /// - public static string ToString(byte[] value, int startIndex) => - BitConverter.ToString(value.Reverse().ToArray(), startIndex); + /// + /// Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal + /// string representation. + /// + /// An array of bytes. + /// The starting position within value. + /// + /// 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". + /// + /// value is null. + /// + /// startIndex is less than zero or greater than the length of value + /// minus 1. + /// + public static string ToString(byte[] value, int startIndex) => + BitConverter.ToString(value.Reverse().ToArray(), startIndex); - /// - /// Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal - /// string representation. - /// - /// An array of bytes. - /// The starting position within value. - /// The number of array elements in value to convert. - /// - /// 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". - /// - /// value is null. - /// - /// startIndex or length is less than zero. -or- startIndex is greater - /// than zero and is greater than or equal to the length of value. - /// - /// - /// 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. - /// - public static string ToString(byte[] value, int startIndex, int length) => - BitConverter.ToString(value.Reverse().ToArray(), startIndex, length); + /// + /// Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal + /// string representation. + /// + /// An array of bytes. + /// The starting position within value. + /// The number of array elements in value to convert. + /// + /// 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". + /// + /// value is null. + /// + /// startIndex or length is less than zero. -or- startIndex is greater + /// than zero and is greater than or equal to the length of value. + /// + /// + /// 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. + /// + public static string ToString(byte[] value, int startIndex, int length) => + BitConverter.ToString(value.Reverse().ToArray(), startIndex, length); - /// Returns a 16-bit unsigned integer converted from two bytes at a specified position in a byte array. - /// The array of bytes. - /// The starting position within value. - /// A 16-bit unsigned integer formed by two bytes beginning at startIndex. - /// startIndex equals the length of value minus 1. - /// value is null. - /// - /// startIndex is less than zero or greater than the length of value - /// minus 1. - /// - public static ushort ToUInt16(byte[] value, int startIndex) => - BitConverter.ToUInt16(value.Reverse().ToArray(), value.Length - sizeof(ushort) - startIndex); + /// Returns a 16-bit unsigned integer converted from two bytes at a specified position in a byte array. + /// The array of bytes. + /// The starting position within value. + /// A 16-bit unsigned integer formed by two bytes beginning at startIndex. + /// startIndex equals the length of value minus 1. + /// value is null. + /// + /// startIndex is less than zero or greater than the length of value + /// minus 1. + /// + public static ushort ToUInt16(byte[] value, int startIndex) => + BitConverter.ToUInt16(value.Reverse().ToArray(), value.Length - sizeof(ushort) - startIndex); - /// Returns a 32-bit unsigned integer converted from four bytes at a specified position in a byte array. - /// An array of bytes. - /// The starting position within value. - /// A 32-bit unsigned integer formed by four bytes beginning at startIndex. - /// - /// 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. - /// - /// value is null. - /// - /// startIndex is less than zero or greater than the length of value - /// minus 1. - /// - public static uint ToUInt32(byte[] value, int startIndex) => - BitConverter.ToUInt32(value.Reverse().ToArray(), value.Length - sizeof(uint) - startIndex); + /// Returns a 32-bit unsigned integer converted from four bytes at a specified position in a byte array. + /// An array of bytes. + /// The starting position within value. + /// A 32-bit unsigned integer formed by four bytes beginning at startIndex. + /// + /// 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. + /// + /// value is null. + /// + /// startIndex is less than zero or greater than the length of value + /// minus 1. + /// + public static uint ToUInt32(byte[] value, int startIndex) => + BitConverter.ToUInt32(value.Reverse().ToArray(), value.Length - sizeof(uint) - startIndex); - /// Returns a 64-bit unsigned integer converted from eight bytes at a specified position in a byte array. - /// An array of bytes. - /// The starting position within value. - /// A 64-bit unsigned integer formed by the eight bytes beginning at startIndex. - /// - /// 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. - /// - /// value is null. - /// - /// startIndex is less than zero or greater than the length of value - /// minus 1. - /// - public static ulong ToUInt64(byte[] value, int startIndex) => - BitConverter.ToUInt64(value.Reverse().ToArray(), value.Length - sizeof(ulong) - startIndex); + /// Returns a 64-bit unsigned integer converted from eight bytes at a specified position in a byte array. + /// An array of bytes. + /// The starting position within value. + /// A 64-bit unsigned integer formed by the eight bytes beginning at startIndex. + /// + /// 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. + /// + /// value is null. + /// + /// startIndex is less than zero or greater than the length of value + /// minus 1. + /// + public static ulong ToUInt64(byte[] value, int startIndex) => + BitConverter.ToUInt64(value.Reverse().ToArray(), value.Length - sizeof(ulong) - startIndex); - /// Converts a big endian byte array representation of a GUID into the .NET Guid structure - /// Byte array containing a GUID in big endian - /// Start of the byte array to process - /// Processed Guid - public static Guid ToGuid(byte[] value, int startIndex) => 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]); - } + /// Converts a big endian byte array representation of a GUID into the .NET Guid structure + /// Byte array containing a GUID in big endian + /// Start of the byte array to process + /// Processed Guid + public static Guid ToGuid(byte[] value, int startIndex) => 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]); } \ No newline at end of file diff --git a/BitEndian.cs b/BitEndian.cs index 857a35a30..f85dccc6b 100644 --- a/BitEndian.cs +++ b/BitEndian.cs @@ -36,16 +36,15 @@ // Copyright © 2011-2022 Natalia Portillo // ****************************************************************************/ -namespace Aaru.Helpers +namespace Aaru.Helpers; + +/// Describes the endianness of bits on a data structure +public enum BitEndian { - /// Describes the endianness of bits on a data structure - public enum BitEndian - { - /// Little-endian, or least significant bit - Little, - /// Big-endian, or most significant bit - Big, - /// PDP-11 endian, little endian except for 32-bit integers where the 16 halves are swapped between them - Pdp - } + /// Little-endian, or least significant bit + Little, + /// Big-endian, or most significant bit + Big, + /// PDP-11 endian, little endian except for 32-bit integers where the 16 halves are swapped between them + Pdp } \ No newline at end of file diff --git a/CHS.cs b/CHS.cs index b31d37dfb..aa58ff396 100644 --- a/CHS.cs +++ b/CHS.cs @@ -30,20 +30,19 @@ // Copyright © 2011-2022 Natalia Portillo // ****************************************************************************/ -namespace Aaru.Helpers +namespace Aaru.Helpers; + +/// Helper operations to work with CHS values +public static class CHS { - /// Helper operations to work with CHS values - public static class CHS - { - /// Converts a CHS position to a LBA one - /// Cylinder - /// Head - /// Sector - /// Number of heads - /// Number of sectors per track - /// - public static uint ToLBA(uint cyl, uint head, uint sector, uint maxHead, uint maxSector) => - maxHead == 0 || maxSector == 0 ? (((cyl * 16) + head) * 63) + sector - 1 - : (((cyl * maxHead) + head) * maxSector) + sector - 1; - } + /// Converts a CHS position to a LBA one + /// Cylinder + /// Head + /// Sector + /// Number of heads + /// Number of sectors per track + /// + public static uint ToLBA(uint cyl, uint head, uint sector, uint maxHead, uint maxSector) => + maxHead == 0 || maxSector == 0 ? (((cyl * 16) + head) * 63) + sector - 1 + : (((cyl * maxHead) + head) * maxSector) + sector - 1; } \ No newline at end of file diff --git a/CompareBytes.cs b/CompareBytes.cs index 96dff9cec..b868d4e2e 100644 --- a/CompareBytes.cs +++ b/CompareBytes.cs @@ -30,43 +30,42 @@ // Copyright © 2011-2022 Natalia Portillo // ****************************************************************************/ -namespace Aaru.Helpers +namespace Aaru.Helpers; + +public static partial class ArrayHelpers { - public static partial class ArrayHelpers + /// Compares two byte arrays + /// true if they are different in any way + /// true if they have the same size + /// Left array + /// Right array + public static void CompareBytes(out bool different, out bool sameSize, byte[] compareArray1, + byte[] compareArray2) { - /// Compares two byte arrays - /// true if they are different in any way - /// true if they have the same size - /// Left array - /// Right array - public static void CompareBytes(out bool different, out bool sameSize, byte[] compareArray1, - byte[] compareArray2) - { - different = false; - sameSize = true; + different = false; + sameSize = true; - long leastBytes; + long leastBytes; - if(compareArray1.LongLength < compareArray2.LongLength) - { - sameSize = false; - leastBytes = compareArray1.LongLength; - } - else if(compareArray1.LongLength > compareArray2.LongLength) - { - sameSize = false; - leastBytes = compareArray2.LongLength; - } - else - leastBytes = compareArray1.LongLength; + if(compareArray1.LongLength < compareArray2.LongLength) + { + sameSize = false; + leastBytes = compareArray1.LongLength; + } + else if(compareArray1.LongLength > compareArray2.LongLength) + { + sameSize = false; + leastBytes = compareArray2.LongLength; + } + else + leastBytes = compareArray1.LongLength; - for(long i = 0; i < leastBytes; i++) - if(compareArray1[i] != compareArray2[i]) - { - different = true; + for(long i = 0; i < leastBytes; i++) + if(compareArray1[i] != compareArray2[i]) + { + different = true; - return; - } - } + return; + } } } \ No newline at end of file diff --git a/CountBits.cs b/CountBits.cs index 88cd8d473..ba50fe767 100644 --- a/CountBits.cs +++ b/CountBits.cs @@ -30,20 +30,19 @@ // Copyright © 2011-2022 Natalia Portillo // ****************************************************************************/ -namespace Aaru.Helpers +namespace Aaru.Helpers; + +/// Helper operations to count bits +public static class CountBits { - /// Helper operations to count bits - public static class CountBits + /// Counts the number of bits set to true in a number + /// Number + /// Bits set to true + public static int Count(uint number) { - /// Counts the number of bits set to true in a number - /// Number - /// Bits set to true - public static int Count(uint number) - { - number -= (number >> 1) & 0x55555555; - number = (number & 0x33333333) + ((number >> 2) & 0x33333333); + number -= (number >> 1) & 0x55555555; + number = (number & 0x33333333) + ((number >> 2) & 0x33333333); - return (int)((((number + (number >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24); - } + return (int)((((number + (number >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24); } } \ No newline at end of file diff --git a/DateHandlers.cs b/DateHandlers.cs index c86b3d233..7fc047ce7 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -34,356 +34,355 @@ using System.Text; using Aaru.Console; -namespace Aaru.Helpers +namespace Aaru.Helpers; + +/// Helper operations for timestamp management (date and time) +public static class DateHandlers { - /// Helper operations for timestamp management (date and time) - 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 _unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0); + /// Day 0 of Julian Date system + static readonly DateTime _julianEpoch = new DateTime(1858, 11, 17, 0, 0, 0); + static readonly DateTime _amigaEpoch = new DateTime(1978, 1, 1, 0, 0, 0); + + /// Converts a Macintosh timestamp to a .NET DateTime + /// Macintosh timestamp (seconds since 1st Jan. 1904) + /// .NET DateTime + public static DateTime MacToDateTime(ulong macTimeStamp) => _macEpoch.AddTicks((long)(macTimeStamp * 10000000)); + + /// Converts a Lisa timestamp to a .NET DateTime + /// Lisa timestamp (seconds since 1st Jan. 1901) + /// .NET DateTime + public static DateTime LisaToDateTime(uint lisaTimeStamp) => _lisaEpoch.AddSeconds(lisaTimeStamp); + + /// Converts a UNIX timestamp to a .NET DateTime + /// UNIX timestamp (seconds since 1st Jan. 1970) + /// .NET DateTime + public static DateTime UnixToDateTime(int unixTimeStamp) => _unixEpoch.AddSeconds(unixTimeStamp); + + /// Converts a UNIX timestamp to a .NET DateTime + /// UNIX timestamp (seconds since 1st Jan. 1970) + /// .NET DateTime + public static DateTime UnixToDateTime(long unixTimeStamp) => _unixEpoch.AddSeconds(unixTimeStamp); + + /// Converts a UNIX timestamp to a .NET DateTime + /// UNIX timestamp (seconds since 1st Jan. 1970) + /// .NET DateTime + public static DateTime UnixUnsignedToDateTime(uint unixTimeStamp) => _unixEpoch.AddSeconds(unixTimeStamp); + + /// Converts a UNIX timestamp to a .NET DateTime + /// Seconds since 1st Jan. 1970) + /// Nanoseconds + /// .NET DateTime + public static DateTime UnixUnsignedToDateTime(uint seconds, uint nanoseconds) => + _unixEpoch.AddSeconds(seconds).AddTicks((long)nanoseconds / 100); + + /// Converts a UNIX timestamp to a .NET DateTime + /// UNIX timestamp (seconds since 1st Jan. 1970) + /// .NET DateTime + public static DateTime UnixUnsignedToDateTime(ulong unixTimeStamp) => _unixEpoch.AddSeconds(unixTimeStamp); + + /// Converts a High Sierra Format timestamp to a .NET DateTime + /// High Sierra Format timestamp + /// .NET DateTime + public static DateTime HighSierraToDateTime(byte[] vdDateTime) { - 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 _unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0); - /// Day 0 of Julian Date system - static readonly DateTime _julianEpoch = new DateTime(1858, 11, 17, 0, 0, 0); - static readonly DateTime _amigaEpoch = new DateTime(1978, 1, 1, 0, 0, 0); - - /// Converts a Macintosh timestamp to a .NET DateTime - /// Macintosh timestamp (seconds since 1st Jan. 1904) - /// .NET DateTime - public static DateTime MacToDateTime(ulong macTimeStamp) => _macEpoch.AddTicks((long)(macTimeStamp * 10000000)); - - /// Converts a Lisa timestamp to a .NET DateTime - /// Lisa timestamp (seconds since 1st Jan. 1901) - /// .NET DateTime - public static DateTime LisaToDateTime(uint lisaTimeStamp) => _lisaEpoch.AddSeconds(lisaTimeStamp); - - /// Converts a UNIX timestamp to a .NET DateTime - /// UNIX timestamp (seconds since 1st Jan. 1970) - /// .NET DateTime - public static DateTime UnixToDateTime(int unixTimeStamp) => _unixEpoch.AddSeconds(unixTimeStamp); - - /// Converts a UNIX timestamp to a .NET DateTime - /// UNIX timestamp (seconds since 1st Jan. 1970) - /// .NET DateTime - public static DateTime UnixToDateTime(long unixTimeStamp) => _unixEpoch.AddSeconds(unixTimeStamp); - - /// Converts a UNIX timestamp to a .NET DateTime - /// UNIX timestamp (seconds since 1st Jan. 1970) - /// .NET DateTime - public static DateTime UnixUnsignedToDateTime(uint unixTimeStamp) => _unixEpoch.AddSeconds(unixTimeStamp); - - /// Converts a UNIX timestamp to a .NET DateTime - /// Seconds since 1st Jan. 1970) - /// Nanoseconds - /// .NET DateTime - public static DateTime UnixUnsignedToDateTime(uint seconds, uint nanoseconds) => - _unixEpoch.AddSeconds(seconds).AddTicks((long)nanoseconds / 100); - - /// Converts a UNIX timestamp to a .NET DateTime - /// UNIX timestamp (seconds since 1st Jan. 1970) - /// .NET DateTime - public static DateTime UnixUnsignedToDateTime(ulong unixTimeStamp) => _unixEpoch.AddSeconds(unixTimeStamp); - - /// Converts a High Sierra Format timestamp to a .NET DateTime - /// High Sierra Format timestamp - /// .NET DateTime - public static DateTime HighSierraToDateTime(byte[] vdDateTime) - { - byte[] isoTime = new byte[17]; - Array.Copy(vdDateTime, 0, isoTime, 0, 16); + byte[] isoTime = new byte[17]; + Array.Copy(vdDateTime, 0, isoTime, 0, 16); - return Iso9660ToDateTime(isoTime); - } + return Iso9660ToDateTime(isoTime); + } - // TODO: Timezone - /// Converts an ISO9660 timestamp to a .NET DateTime - /// ISO9660 timestamp - /// .NET DateTime - public static DateTime Iso9660ToDateTime(byte[] vdDateTime) - { - byte[] twoCharValue = new byte[2]; - byte[] fourCharValue = new byte[4]; + // TODO: Timezone + /// Converts an ISO9660 timestamp to a .NET DateTime + /// ISO9660 timestamp + /// .NET DateTime + public static DateTime Iso9660ToDateTime(byte[] vdDateTime) + { + byte[] twoCharValue = new byte[2]; + byte[] fourCharValue = new byte[4]; - fourCharValue[0] = vdDateTime[0]; - fourCharValue[1] = vdDateTime[1]; - fourCharValue[2] = vdDateTime[2]; - fourCharValue[3] = vdDateTime[3]; + fourCharValue[0] = vdDateTime[0]; + fourCharValue[1] = vdDateTime[1]; + fourCharValue[2] = vdDateTime[2]; + fourCharValue[3] = vdDateTime[3]; - AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "year = \"{0}\"", - StringHandlers.CToString(fourCharValue, Encoding.ASCII)); + AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "year = \"{0}\"", + StringHandlers.CToString(fourCharValue, Encoding.ASCII)); - if(!int.TryParse(StringHandlers.CToString(fourCharValue, Encoding.ASCII), out int year)) - year = 0; + if(!int.TryParse(StringHandlers.CToString(fourCharValue, Encoding.ASCII), out int year)) + year = 0; - twoCharValue[0] = vdDateTime[4]; - twoCharValue[1] = vdDateTime[5]; + twoCharValue[0] = vdDateTime[4]; + twoCharValue[1] = vdDateTime[5]; - AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "month = \"{0}\"", - StringHandlers.CToString(twoCharValue, Encoding.ASCII)); + AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "month = \"{0}\"", + StringHandlers.CToString(twoCharValue, Encoding.ASCII)); - if(!int.TryParse(StringHandlers.CToString(twoCharValue, Encoding.ASCII), out int month)) - month = 0; + if(!int.TryParse(StringHandlers.CToString(twoCharValue, Encoding.ASCII), out int month)) + month = 0; - twoCharValue[0] = vdDateTime[6]; - twoCharValue[1] = vdDateTime[7]; + twoCharValue[0] = vdDateTime[6]; + twoCharValue[1] = vdDateTime[7]; - AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "day = \"{0}\"", - StringHandlers.CToString(twoCharValue, Encoding.ASCII)); + AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "day = \"{0}\"", + StringHandlers.CToString(twoCharValue, Encoding.ASCII)); - if(!int.TryParse(StringHandlers.CToString(twoCharValue, Encoding.ASCII), out int day)) - day = 0; + if(!int.TryParse(StringHandlers.CToString(twoCharValue, Encoding.ASCII), out int day)) + day = 0; - twoCharValue[0] = vdDateTime[8]; - twoCharValue[1] = vdDateTime[9]; + twoCharValue[0] = vdDateTime[8]; + twoCharValue[1] = vdDateTime[9]; - AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "hour = \"{0}\"", - StringHandlers.CToString(twoCharValue, Encoding.ASCII)); + AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "hour = \"{0}\"", + StringHandlers.CToString(twoCharValue, Encoding.ASCII)); - if(!int.TryParse(StringHandlers.CToString(twoCharValue, Encoding.ASCII), out int hour)) - hour = 0; + if(!int.TryParse(StringHandlers.CToString(twoCharValue, Encoding.ASCII), out int hour)) + hour = 0; - twoCharValue[0] = vdDateTime[10]; - twoCharValue[1] = vdDateTime[11]; + twoCharValue[0] = vdDateTime[10]; + twoCharValue[1] = vdDateTime[11]; - AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "minute = \"{0}\"", - StringHandlers.CToString(twoCharValue, Encoding.ASCII)); + AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "minute = \"{0}\"", + StringHandlers.CToString(twoCharValue, Encoding.ASCII)); - if(!int.TryParse(StringHandlers.CToString(twoCharValue, Encoding.ASCII), out int minute)) - minute = 0; + if(!int.TryParse(StringHandlers.CToString(twoCharValue, Encoding.ASCII), out int minute)) + minute = 0; - twoCharValue[0] = vdDateTime[12]; - twoCharValue[1] = vdDateTime[13]; + twoCharValue[0] = vdDateTime[12]; + twoCharValue[1] = vdDateTime[13]; - AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "second = \"{0}\"", - StringHandlers.CToString(twoCharValue, Encoding.ASCII)); + AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "second = \"{0}\"", + StringHandlers.CToString(twoCharValue, Encoding.ASCII)); - if(!int.TryParse(StringHandlers.CToString(twoCharValue, Encoding.ASCII), out int second)) - second = 0; + if(!int.TryParse(StringHandlers.CToString(twoCharValue, Encoding.ASCII), out int second)) + second = 0; - twoCharValue[0] = vdDateTime[14]; - twoCharValue[1] = vdDateTime[15]; + twoCharValue[0] = vdDateTime[14]; + twoCharValue[1] = vdDateTime[15]; - AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "hundredths = \"{0}\"", - StringHandlers.CToString(twoCharValue, Encoding.ASCII)); + AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "hundredths = \"{0}\"", + StringHandlers.CToString(twoCharValue, Encoding.ASCII)); - if(!int.TryParse(StringHandlers.CToString(twoCharValue, Encoding.ASCII), out int hundredths)) - hundredths = 0; + if(!int.TryParse(StringHandlers.CToString(twoCharValue, Encoding.ASCII), out int hundredths)) + hundredths = 0; - AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", - "decodedDT = new DateTime({0}, {1}, {2}, {3}, {4}, {5}, {6}, DateTimeKind.Unspecified);", - year, month, day, hour, minute, second, hundredths * 10); + AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", + "decodedDT = new DateTime({0}, {1}, {2}, {3}, {4}, {5}, {6}, DateTimeKind.Unspecified);", + year, month, day, hour, minute, second, hundredths * 10); - sbyte difference = (sbyte)vdDateTime[16]; + sbyte difference = (sbyte)vdDateTime[16]; - var decodedDt = new DateTime(year, month, day, hour, minute, second, hundredths * 10, DateTimeKind.Utc); + var decodedDt = new DateTime(year, month, day, hour, minute, second, hundredths * 10, DateTimeKind.Utc); - return decodedDt.AddMinutes(difference * -15); - } + return decodedDt.AddMinutes(difference * -15); + } - /// Converts a VMS timestamp to a .NET DateTime - /// VMS timestamp (tenths of microseconds since day 0 of the Julian Date) - /// .NET DateTime - /// C# works in UTC, VMS on Julian Date, some displacement may occur on disks created outside UTC - public static DateTime VmsToDateTime(ulong vmsDate) - { - double delta = vmsDate * 0.0001; // Tenths of microseconds to milliseconds, will lose some detail + /// Converts a VMS timestamp to a .NET DateTime + /// VMS timestamp (tenths of microseconds since day 0 of the Julian Date) + /// .NET DateTime + /// C# works in UTC, VMS on Julian Date, some displacement may occur on disks created outside UTC + public static DateTime VmsToDateTime(ulong vmsDate) + { + double delta = vmsDate * 0.0001; // Tenths of microseconds to milliseconds, will lose some detail - return _julianEpoch.AddMilliseconds(delta); - } + return _julianEpoch.AddMilliseconds(delta); + } - /// Converts an Amiga timestamp to a .NET DateTime - /// Days since the 1st Jan. 1978 - /// Minutes since o'clock - /// Ticks - /// .NET DateTime - public static DateTime AmigaToDateTime(uint days, uint minutes, uint ticks) - { - DateTime temp = _amigaEpoch.AddDays(days); - temp = temp.AddMinutes(minutes); + /// Converts an Amiga timestamp to a .NET DateTime + /// Days since the 1st Jan. 1978 + /// Minutes since o'clock + /// Ticks + /// .NET DateTime + public static DateTime AmigaToDateTime(uint days, uint minutes, uint ticks) + { + DateTime temp = _amigaEpoch.AddDays(days); + temp = temp.AddMinutes(minutes); - return temp.AddMilliseconds(ticks * 20); - } + return temp.AddMilliseconds(ticks * 20); + } - /// Converts an UCSD Pascal timestamp to a .NET DateTime - /// UCSD Pascal timestamp - /// .NET DateTime - public static DateTime UcsdPascalToDateTime(short dateRecord) - { - int year = ((dateRecord & 0xFE00) >> 9) + 1900; - int day = (dateRecord & 0x01F0) >> 4; - int month = dateRecord & 0x000F; + /// Converts an UCSD Pascal timestamp to a .NET DateTime + /// UCSD Pascal timestamp + /// .NET DateTime + public static DateTime UcsdPascalToDateTime(short dateRecord) + { + int year = ((dateRecord & 0xFE00) >> 9) + 1900; + int day = (dateRecord & 0x01F0) >> 4; + int month = dateRecord & 0x000F; - AaruConsole.DebugWriteLine("UCSDPascalToDateTime handler", - "dateRecord = 0x{0:X4}, year = {1}, month = {2}, day = {3}", dateRecord, year, - month, day); + AaruConsole.DebugWriteLine("UCSDPascalToDateTime handler", + "dateRecord = 0x{0:X4}, year = {1}, month = {2}, day = {3}", dateRecord, year, + month, day); - return new DateTime(year, month, day); - } + return new DateTime(year, month, day); + } - /// Converts a DOS timestamp to a .NET DateTime - /// Date - /// Time - /// .NET DateTime - public static DateTime DosToDateTime(ushort date, ushort time) + /// Converts a DOS timestamp to a .NET DateTime + /// Date + /// Time + /// .NET DateTime + 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 second = (time & 0x1F) * 2; + + AaruConsole.DebugWriteLine("DOSToDateTime handler", "date = 0x{0:X4}, year = {1}, month = {2}, day = {3}", + date, year, month, day); + + AaruConsole.DebugWriteLine("DOSToDateTime handler", + "time = 0x{0:X4}, hour = {1}, minute = {2}, second = {3}", time, hour, minute, + second); + + DateTime dosDate; + + try { - 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; - - AaruConsole.DebugWriteLine("DOSToDateTime handler", "date = 0x{0:X4}, year = {1}, month = {2}, day = {3}", - date, year, month, day); - - AaruConsole.DebugWriteLine("DOSToDateTime handler", - "time = 0x{0:X4}, hour = {1}, minute = {2}, second = {3}", time, hour, minute, - second); - - DateTime dosDate; - - try - { - dosDate = new DateTime(year, month, day, hour, minute, second); - } - catch(ArgumentOutOfRangeException) - { - dosDate = new DateTime(1980, 1, 1, 0, 0, 0); - } - - return dosDate; + dosDate = new DateTime(year, month, day, hour, minute, second); } - - /// Converts a CP/M timestamp to .NET DateTime - /// CP/M timestamp - /// .NET DateTime - public static DateTime CpmToDateTime(byte[] timestamp) + catch(ArgumentOutOfRangeException) { - ushort days = BitConverter.ToUInt16(timestamp, 0); - int hours = timestamp[2]; - int minutes = timestamp[3]; + dosDate = new DateTime(1980, 1, 1, 0, 0, 0); + } - DateTime temp = _amigaEpoch.AddDays(days); - temp = temp.AddHours(hours); - temp = temp.AddMinutes(minutes); + return dosDate; + } - return temp; - } + /// Converts a CP/M timestamp to .NET DateTime + /// CP/M timestamp + /// .NET DateTime + public static DateTime CpmToDateTime(byte[] timestamp) + { + ushort days = BitConverter.ToUInt16(timestamp, 0); + int hours = timestamp[2]; + int minutes = timestamp[3]; - /// Converts an ECMA timestamp to a .NET DateTime - /// Timezone - /// Year - /// Month - /// Day - /// Hour - /// Minute - /// Second - /// Centiseconds - /// Hundreds of microseconds - /// 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); + DateTime temp = _amigaEpoch.AddDays(days); + temp = temp.AddHours(hours); + temp = temp.AddMinutes(minutes); - long ticks = ((long)centiseconds * 100000) + ((long)hundredsOfMicroseconds * 1000) + - ((long)microseconds * 10); + return temp; + } - if(specification == 0) - return new DateTime(year, month, day, hour, minute, second, DateTimeKind.Utc).AddTicks(ticks); + /// Converts an ECMA timestamp to a .NET DateTime + /// Timezone + /// Year + /// Month + /// Day + /// Hour + /// Minute + /// Second + /// Centiseconds + /// Hundreds of microseconds + /// 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); - ushort preOffset = (ushort)(typeAndTimeZone & 0xFFF); - short offset; + long ticks = ((long)centiseconds * 100000) + ((long)hundredsOfMicroseconds * 1000) + + ((long)microseconds * 10); - if((preOffset & 0x800) == 0x800) - offset = (short)(preOffset | 0xF000); - else - offset = (short)(preOffset & 0x7FF); + if(specification == 0) + return new DateTime(year, month, day, hour, minute, second, DateTimeKind.Utc).AddTicks(ticks); - if(offset == -2047) - return new DateTime(year, month, day, hour, minute, second, DateTimeKind.Unspecified).AddTicks(ticks); + ushort preOffset = (ushort)(typeAndTimeZone & 0xFFF); + short offset; - if(offset < -1440 || - offset > 1440) - offset = 0; + if((preOffset & 0x800) == 0x800) + offset = (short)(preOffset | 0xF000); + else + offset = (short)(preOffset & 0x7FF); - return new DateTimeOffset(year, month, day, hour, minute, second, new TimeSpan(0, offset, 0)). - AddTicks(ticks).DateTime; - } + if(offset == -2047) + return new DateTime(year, month, day, hour, minute, second, DateTimeKind.Unspecified).AddTicks(ticks); + + if(offset < -1440 || + offset > 1440) + offset = 0; + + return new DateTimeOffset(year, month, day, hour, minute, second, new TimeSpan(0, offset, 0)). + AddTicks(ticks).DateTime; + } + + /// Converts a Solaris high resolution timestamp to .NET DateTime + /// Solaris high resolution timestamp + /// .NET DateTime + public static DateTime UnixHrTimeToDateTime(ulong hrTimeStamp) => + _unixEpoch.AddTicks((long)(hrTimeStamp / 100)); - /// Converts a Solaris high resolution timestamp to .NET DateTime - /// Solaris high resolution timestamp - /// .NET DateTime - public static DateTime UnixHrTimeToDateTime(ulong hrTimeStamp) => - _unixEpoch.AddTicks((long)(hrTimeStamp / 100)); + /// Converts an OS-9 timestamp to .NET DateTime + /// OS-9 timestamp + /// .NET DateTime + public static DateTime Os9ToDateTime(byte[] date) + { + if(date == null || + (date.Length != 3 && date.Length != 5)) + return DateTime.MinValue; + + DateTime os9Date; - /// Converts an OS-9 timestamp to .NET DateTime - /// OS-9 timestamp - /// .NET DateTime - public static DateTime Os9ToDateTime(byte[] date) + try + { + 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); + } + catch(ArgumentOutOfRangeException) { - if(date == null || - (date.Length != 3 && date.Length != 5)) - return DateTime.MinValue; - - DateTime os9Date; - - try - { - 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); - } - catch(ArgumentOutOfRangeException) - { - os9Date = new DateTime(1900, 0, 0, 0, 0, 0); - } - - return os9Date; + os9Date = new DateTime(1900, 0, 0, 0, 0, 0); } - /// Converts a LIF timestamp to .NET DateTime - /// LIF timestamp - /// .NET DateTime - public static DateTime LifToDateTime(byte[] date) + return os9Date; + } + + /// Converts a LIF timestamp to .NET DateTime + /// LIF timestamp + /// .NET DateTime + public static DateTime LifToDateTime(byte[] date) + { + if(date == null || + date.Length != 6) + return new DateTime(1970, 1, 1, 0, 0, 0); + + return LifToDateTime(date[0], date[1], date[2], date[3], date[4], date[5]); + } + + /// Converts a LIF timestamp to .NET DateTime + /// Yer + /// Month + /// Day + /// Hour + /// Minute + /// Second + /// .NET DateTime + public static DateTime LifToDateTime(byte year, byte month, byte day, byte hour, byte minute, byte second) + { + try { - if(date == null || - date.Length != 6) - return new DateTime(1970, 1, 1, 0, 0, 0); + 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 isecond = ((second >> 4) * 10) + (second & 0xF); + + if(iyear >= 70) + iyear += 1900; + else + iyear += 2000; - return LifToDateTime(date[0], date[1], date[2], date[3], date[4], date[5]); + return new DateTime(iyear, imonth, iday, ihour, iminute, isecond); } - - /// Converts a LIF timestamp to .NET DateTime - /// Yer - /// Month - /// Day - /// Hour - /// Minute - /// Second - /// .NET DateTime - public static DateTime LifToDateTime(byte year, byte month, byte day, byte hour, byte minute, byte second) + catch(ArgumentOutOfRangeException) { - try - { - 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 isecond = ((second >> 4) * 10) + (second & 0xF); - - if(iyear >= 70) - iyear += 1900; - else - iyear += 2000; - - return new DateTime(iyear, imonth, iday, ihour, iminute, isecond); - } - catch(ArgumentOutOfRangeException) - { - return new DateTime(1970, 1, 1, 0, 0, 0); - } + return new DateTime(1970, 1, 1, 0, 0, 0); } } } \ No newline at end of file diff --git a/Marshal.cs b/Marshal.cs index d2c03e90f..8a1c3bf6b 100644 --- a/Marshal.cs +++ b/Marshal.cs @@ -36,463 +36,462 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -namespace Aaru.Helpers +namespace Aaru.Helpers; + +/// Provides methods to marshal binary data into C# structs +public static class Marshal { - /// Provides methods to marshal binary data into C# structs - public static class Marshal + /// Returns the size of an unmanaged type in bytes. + /// The type whose size is to be returned. + /// The size, in bytes, of the type that is specified by the generic type parameter. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int SizeOf() => System.Runtime.InteropServices.Marshal.SizeOf(); + + /// Marshal little-endian binary data to a structure + /// Byte array containing the binary data + /// Type of the structure to marshal + /// The binary data marshalled in a structure with the specified type + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static T ByteArrayToStructureLittleEndian(byte[] bytes) where T : struct { - /// Returns the size of an unmanaged type in bytes. - /// The type whose size is to be returned. - /// The size, in bytes, of the type that is specified by the generic type parameter. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int SizeOf() => System.Runtime.InteropServices.Marshal.SizeOf(); - - /// Marshal little-endian binary data to a structure - /// Byte array containing the binary data - /// Type of the structure to marshal - /// The binary data marshalled in a structure with the specified type - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static T ByteArrayToStructureLittleEndian(byte[] bytes) where T : struct - { - var ptr = GCHandle.Alloc(bytes, GCHandleType.Pinned); + var ptr = GCHandle.Alloc(bytes, GCHandleType.Pinned); - var str = (T)System.Runtime.InteropServices.Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(T)); + var str = (T)System.Runtime.InteropServices.Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(T)); - ptr.Free(); + ptr.Free(); - return str; - } + return str; + } - /// Marshal little-endian binary data to a structure - /// Byte array containing the binary data - /// Start on the array where the structure begins - /// Length of the structure in bytes - /// Type of the structure to marshal - /// The binary data marshalled in a structure with the specified type - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static T ByteArrayToStructureLittleEndian(byte[] bytes, int start, int length) where T : struct - { - Span span = bytes; + /// Marshal little-endian binary data to a structure + /// Byte array containing the binary data + /// Start on the array where the structure begins + /// Length of the structure in bytes + /// Type of the structure to marshal + /// The binary data marshalled in a structure with the specified type + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static T ByteArrayToStructureLittleEndian(byte[] bytes, int start, int length) where T : struct + { + Span span = bytes; - return ByteArrayToStructureLittleEndian(span.Slice(start, length).ToArray()); - } + return ByteArrayToStructureLittleEndian(span.Slice(start, length).ToArray()); + } - /// Marshal big-endian binary data to a structure - /// Byte array containing the binary data - /// Type of the structure to marshal - /// The binary data marshalled in a structure with the specified type - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static T ByteArrayToStructureBigEndian(byte[] bytes) where T : struct - { - var ptr = GCHandle.Alloc(bytes, GCHandleType.Pinned); + /// Marshal big-endian binary data to a structure + /// Byte array containing the binary data + /// Type of the structure to marshal + /// The binary data marshalled in a structure with the specified type + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static T ByteArrayToStructureBigEndian(byte[] bytes) where T : struct + { + var ptr = GCHandle.Alloc(bytes, GCHandleType.Pinned); - object str = (T)System.Runtime.InteropServices.Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(T)); + object str = (T)System.Runtime.InteropServices.Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(T)); - ptr.Free(); + ptr.Free(); - return (T)SwapStructureMembersEndian(str); - } + return (T)SwapStructureMembersEndian(str); + } - /// Marshal big-endian binary data to a structure - /// Byte array containing the binary data - /// Start on the array where the structure begins - /// Length of the structure in bytes - /// Type of the structure to marshal - /// The binary data marshalled in a structure with the specified type - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static T ByteArrayToStructureBigEndian(byte[] bytes, int start, int length) where T : struct - { - Span span = bytes; + /// Marshal big-endian binary data to a structure + /// Byte array containing the binary data + /// Start on the array where the structure begins + /// Length of the structure in bytes + /// Type of the structure to marshal + /// The binary data marshalled in a structure with the specified type + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static T ByteArrayToStructureBigEndian(byte[] bytes, int start, int length) where T : struct + { + Span span = bytes; - return ByteArrayToStructureBigEndian(span.Slice(start, length).ToArray()); - } + return ByteArrayToStructureBigEndian(span.Slice(start, length).ToArray()); + } - /// Marshal PDP-11 binary data to a structure - /// Byte array containing the binary data - /// Type of the structure to marshal - /// The binary data marshalled in a structure with the specified type - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static T ByteArrayToStructurePdpEndian(byte[] bytes) where T : struct + /// Marshal PDP-11 binary data to a structure + /// Byte array containing the binary data + /// Type of the structure to marshal + /// The binary data marshalled in a structure with the specified type + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static T ByteArrayToStructurePdpEndian(byte[] bytes) where T : struct + { { - { - var ptr = GCHandle.Alloc(bytes, GCHandleType.Pinned); + var ptr = GCHandle.Alloc(bytes, GCHandleType.Pinned); - object str = - (T)System.Runtime.InteropServices.Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(T)); + object str = + (T)System.Runtime.InteropServices.Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(T)); - ptr.Free(); + ptr.Free(); - return (T)SwapStructureMembersEndianPdp(str); - } + return (T)SwapStructureMembersEndianPdp(str); } + } - /// Marshal PDP-11 binary data to a structure - /// Byte array containing the binary data - /// Start on the array where the structure begins - /// Length of the structure in bytes - /// Type of the structure to marshal - /// The binary data marshalled in a structure with the specified type - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static T ByteArrayToStructurePdpEndian(byte[] bytes, int start, int length) where T : struct - { - Span span = bytes; + /// Marshal PDP-11 binary data to a structure + /// Byte array containing the binary data + /// Start on the array where the structure begins + /// Length of the structure in bytes + /// Type of the structure to marshal + /// The binary data marshalled in a structure with the specified type + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static T ByteArrayToStructurePdpEndian(byte[] bytes, int start, int length) where T : struct + { + Span span = bytes; - return ByteArrayToStructurePdpEndian(span.Slice(start, length).ToArray()); - } + return ByteArrayToStructurePdpEndian(span.Slice(start, length).ToArray()); + } - /// - /// Marshal little-endian binary data to a structure. If the structure type contains any non value type, this - /// method will crash. - /// - /// Byte array containing the binary data - /// Type of the structure to marshal - /// The binary data marshalled in a structure with the specified type - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static T SpanToStructureLittleEndian(ReadOnlySpan bytes) where T : struct => - MemoryMarshal.Read(bytes); - - /// - /// Marshal little-endian binary data to a structure. If the structure type contains any non value type, this - /// method will crash. - /// - /// Byte span containing the binary data - /// Start on the span where the structure begins - /// Length of the structure in bytes - /// Type of the structure to marshal - /// The binary data marshalled in a structure with the specified type - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static T SpanToStructureLittleEndian(ReadOnlySpan bytes, int start, int length) - where T : struct => MemoryMarshal.Read(bytes.Slice(start, length)); - - /// - /// Marshal big-endian binary data to a structure. If the structure type contains any non value type, this method - /// will crash. - /// - /// Byte array containing the binary data - /// Type of the structure to marshal - /// The binary data marshalled in a structure with the specified type - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static T SpanToStructureBigEndian(ReadOnlySpan bytes) where T : struct - { - T str = SpanToStructureLittleEndian(bytes); + /// + /// Marshal little-endian binary data to a structure. If the structure type contains any non value type, this + /// method will crash. + /// + /// Byte array containing the binary data + /// Type of the structure to marshal + /// The binary data marshalled in a structure with the specified type + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static T SpanToStructureLittleEndian(ReadOnlySpan bytes) where T : struct => + MemoryMarshal.Read(bytes); + + /// + /// Marshal little-endian binary data to a structure. If the structure type contains any non value type, this + /// method will crash. + /// + /// Byte span containing the binary data + /// Start on the span where the structure begins + /// Length of the structure in bytes + /// Type of the structure to marshal + /// The binary data marshalled in a structure with the specified type + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static T SpanToStructureLittleEndian(ReadOnlySpan bytes, int start, int length) + where T : struct => MemoryMarshal.Read(bytes.Slice(start, length)); + + /// + /// Marshal big-endian binary data to a structure. If the structure type contains any non value type, this method + /// will crash. + /// + /// Byte array containing the binary data + /// Type of the structure to marshal + /// The binary data marshalled in a structure with the specified type + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static T SpanToStructureBigEndian(ReadOnlySpan bytes) where T : struct + { + T str = SpanToStructureLittleEndian(bytes); - return (T)SwapStructureMembersEndian(str); - } + return (T)SwapStructureMembersEndian(str); + } - /// - /// Marshal big-endian binary data to a structure. If the structure type contains any non value type, this method - /// will crash. - /// - /// Byte span containing the binary data - /// Start on the span where the structure begins - /// Length of the structure in bytes - /// Type of the structure to marshal - /// The binary data marshalled in a structure with the specified type - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static T SpanToStructureBigEndian(ReadOnlySpan bytes, int start, int length) where T : struct - { - T str = SpanToStructureLittleEndian(bytes.Slice(start, length)); + /// + /// Marshal big-endian binary data to a structure. If the structure type contains any non value type, this method + /// will crash. + /// + /// Byte span containing the binary data + /// Start on the span where the structure begins + /// Length of the structure in bytes + /// Type of the structure to marshal + /// The binary data marshalled in a structure with the specified type + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static T SpanToStructureBigEndian(ReadOnlySpan bytes, int start, int length) where T : struct + { + T str = SpanToStructureLittleEndian(bytes.Slice(start, length)); - return (T)SwapStructureMembersEndian(str); - } + return (T)SwapStructureMembersEndian(str); + } - /// - /// Marshal PDP-11 binary data to a structure. If the structure type contains any non value type, this method will - /// crash. - /// - /// Byte array containing the binary data - /// Type of the structure to marshal - /// The binary data marshalled in a structure with the specified type - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static T SpanToStructurePdpEndian(ReadOnlySpan bytes) where T : struct - { - object str = SpanToStructureLittleEndian(bytes); + /// + /// Marshal PDP-11 binary data to a structure. If the structure type contains any non value type, this method will + /// crash. + /// + /// Byte array containing the binary data + /// Type of the structure to marshal + /// The binary data marshalled in a structure with the specified type + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static T SpanToStructurePdpEndian(ReadOnlySpan bytes) where T : struct + { + object str = SpanToStructureLittleEndian(bytes); - return (T)SwapStructureMembersEndianPdp(str); - } + return (T)SwapStructureMembersEndianPdp(str); + } - /// - /// Marshal PDP-11 binary data to a structure. If the structure type contains any non value type, this method will - /// crash. - /// - /// Byte array containing the binary data - /// Start on the span where the structure begins - /// Length of the structure in bytes - /// Type of the structure to marshal - /// The binary data marshalled in a structure with the specified type - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static T SpanToStructurePdpEndian(ReadOnlySpan bytes, int start, int length) where T : struct - { - object str = SpanToStructureLittleEndian(bytes.Slice(start, length)); + /// + /// Marshal PDP-11 binary data to a structure. If the structure type contains any non value type, this method will + /// crash. + /// + /// Byte array containing the binary data + /// Start on the span where the structure begins + /// Length of the structure in bytes + /// Type of the structure to marshal + /// The binary data marshalled in a structure with the specified type + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static T SpanToStructurePdpEndian(ReadOnlySpan bytes, int start, int length) where T : struct + { + object str = SpanToStructureLittleEndian(bytes.Slice(start, length)); - return (T)SwapStructureMembersEndianPdp(str); - } + return (T)SwapStructureMembersEndianPdp(str); + } - /// - /// Marshal a structure depending on the decoration of . If the - /// decoration is not present it will marshal as a reference type containing little endian structure. - /// - /// Byte array containing the binary data - /// Type of the structure to marshal - /// The binary data marshalled in a structure with the specified type - /// - /// The contains an unsupported - /// endian - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static T MarshalStructure(byte[] bytes) where T : struct + /// + /// Marshal a structure depending on the decoration of . If the + /// decoration is not present it will marshal as a reference type containing little endian structure. + /// + /// Byte array containing the binary data + /// Type of the structure to marshal + /// The binary data marshalled in a structure with the specified type + /// + /// The contains an unsupported + /// endian + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static T MarshalStructure(byte[] bytes) where T : struct + { + if(!(typeof(T).GetCustomAttribute(typeof(MarshallingPropertiesAttribute)) is MarshallingPropertiesAttribute + properties)) + return ByteArrayToStructureLittleEndian(bytes); + + switch(properties.Endian) { - if(!(typeof(T).GetCustomAttribute(typeof(MarshallingPropertiesAttribute)) is MarshallingPropertiesAttribute - properties)) - return ByteArrayToStructureLittleEndian(bytes); + case BitEndian.Little: + return properties.HasReferences ? ByteArrayToStructureLittleEndian(bytes) + : SpanToStructureLittleEndian(bytes); + + case BitEndian.Big: + return properties.HasReferences ? ByteArrayToStructureBigEndian(bytes) + : SpanToStructureBigEndian(bytes); + + case BitEndian.Pdp: + return properties.HasReferences ? ByteArrayToStructurePdpEndian(bytes) + : SpanToStructurePdpEndian(bytes); + default: throw new ArgumentOutOfRangeException(); + } + } - switch(properties.Endian) + /// Swaps all members of a structure + /// + /// + [MethodImpl(MethodImplOptions.AggressiveInlining), SuppressMessage("ReSharper", "InconsistentNaming")] + public static object SwapStructureMembersEndian(object str) + { + Type t = str.GetType(); + FieldInfo[] fieldInfo = t.GetFields(); + + foreach(FieldInfo fi in fieldInfo) + if(fi.FieldType == typeof(short) || + (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(short))) { - case BitEndian.Little: - return properties.HasReferences ? ByteArrayToStructureLittleEndian(bytes) - : SpanToStructureLittleEndian(bytes); - - case BitEndian.Big: - return properties.HasReferences ? ByteArrayToStructureBigEndian(bytes) - : SpanToStructureBigEndian(bytes); - - case BitEndian.Pdp: - return properties.HasReferences ? ByteArrayToStructurePdpEndian(bytes) - : SpanToStructurePdpEndian(bytes); - default: throw new ArgumentOutOfRangeException(); + short x = (short)fi.GetValue(str); + fi.SetValue(str, (short)((x << 8) | ((x >> 8) & 0xFF))); } - } + else if(fi.FieldType == typeof(int) || + (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(int))) + { + int x = (int)fi.GetValue(str); + x = (int)(((x << 8) & 0xFF00FF00) | (((uint)x >> 8) & 0xFF00FF)); + fi.SetValue(str, (int)(((uint)x << 16) | (((uint)x >> 16) & 0xFFFF))); + } + else if(fi.FieldType == typeof(long) || + (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(long))) + { + long x = (long)fi.GetValue(str); + x = ((x & 0x00000000FFFFFFFF) << 32) | (long)(((ulong)x & 0xFFFFFFFF00000000) >> 32); + x = ((x & 0x0000FFFF0000FFFF) << 16) | (long)(((ulong)x & 0xFFFF0000FFFF0000) >> 16); + x = ((x & 0x00FF00FF00FF00FF) << 8) | (long)(((ulong)x & 0xFF00FF00FF00FF00) >> 8); - /// Swaps all members of a structure - /// - /// - [MethodImpl(MethodImplOptions.AggressiveInlining), SuppressMessage("ReSharper", "InconsistentNaming")] - public static object SwapStructureMembersEndian(object str) - { - Type t = str.GetType(); - FieldInfo[] fieldInfo = t.GetFields(); + fi.SetValue(str, x); + } + else if(fi.FieldType == typeof(ushort) || + (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(ushort))) + { + ushort x = (ushort)fi.GetValue(str); + fi.SetValue(str, (ushort)((x << 8) | (x >> 8))); + } + else if(fi.FieldType == typeof(uint) || + (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(uint))) + { + uint x = (uint)fi.GetValue(str); + x = ((x << 8) & 0xFF00FF00) | ((x >> 8) & 0xFF00FF); + fi.SetValue(str, (x << 16) | (x >> 16)); + } + else if(fi.FieldType == typeof(ulong) || + (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(ulong))) + { + ulong x = (ulong)fi.GetValue(str); + x = ((x & 0x00000000FFFFFFFF) << 32) | ((x & 0xFFFFFFFF00000000) >> 32); + x = ((x & 0x0000FFFF0000FFFF) << 16) | ((x & 0xFFFF0000FFFF0000) >> 16); + x = ((x & 0x00FF00FF00FF00FF) << 8) | ((x & 0xFF00FF00FF00FF00) >> 8); + fi.SetValue(str, x); + } + else if(fi.FieldType == typeof(float)) + { + float flt = (float)fi.GetValue(str); + byte[] flt_b = BitConverter.GetBytes(flt); - foreach(FieldInfo fi in fieldInfo) - if(fi.FieldType == typeof(short) || - (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(short))) - { - short x = (short)fi.GetValue(str); - fi.SetValue(str, (short)((x << 8) | ((x >> 8) & 0xFF))); - } - else if(fi.FieldType == typeof(int) || - (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(int))) - { - int x = (int)fi.GetValue(str); - x = (int)(((x << 8) & 0xFF00FF00) | (((uint)x >> 8) & 0xFF00FF)); - fi.SetValue(str, (int)(((uint)x << 16) | (((uint)x >> 16) & 0xFFFF))); - } - else if(fi.FieldType == typeof(long) || - (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(long))) - { - long x = (long)fi.GetValue(str); - x = ((x & 0x00000000FFFFFFFF) << 32) | (long)(((ulong)x & 0xFFFFFFFF00000000) >> 32); - x = ((x & 0x0000FFFF0000FFFF) << 16) | (long)(((ulong)x & 0xFFFF0000FFFF0000) >> 16); - x = ((x & 0x00FF00FF00FF00FF) << 8) | (long)(((ulong)x & 0xFF00FF00FF00FF00) >> 8); - - fi.SetValue(str, x); - } - else if(fi.FieldType == typeof(ushort) || - (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(ushort))) - { - ushort x = (ushort)fi.GetValue(str); - fi.SetValue(str, (ushort)((x << 8) | (x >> 8))); - } - else if(fi.FieldType == typeof(uint) || - (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(uint))) - { - uint x = (uint)fi.GetValue(str); - x = ((x << 8) & 0xFF00FF00) | ((x >> 8) & 0xFF00FF); - fi.SetValue(str, (x << 16) | (x >> 16)); - } - else if(fi.FieldType == typeof(ulong) || - (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(ulong))) - { - ulong x = (ulong)fi.GetValue(str); - x = ((x & 0x00000000FFFFFFFF) << 32) | ((x & 0xFFFFFFFF00000000) >> 32); - x = ((x & 0x0000FFFF0000FFFF) << 16) | ((x & 0xFFFF0000FFFF0000) >> 16); - x = ((x & 0x00FF00FF00FF00FF) << 8) | ((x & 0xFF00FF00FF00FF00) >> 8); - fi.SetValue(str, x); - } - else if(fi.FieldType == typeof(float)) - { - float flt = (float)fi.GetValue(str); - byte[] flt_b = BitConverter.GetBytes(flt); - - fi.SetValue(str, BitConverter.ToSingle(new[] - { - flt_b[3], flt_b[2], flt_b[1], flt_b[0] - }, 0)); - } - else if(fi.FieldType == typeof(double)) + fi.SetValue(str, BitConverter.ToSingle(new[] { - double dbl = (double)fi.GetValue(str); - byte[] dbl_b = BitConverter.GetBytes(dbl); - - fi.SetValue(str, BitConverter.ToDouble(new[] - { - dbl_b[7], dbl_b[6], dbl_b[5], dbl_b[4], dbl_b[3], dbl_b[2], dbl_b[1], dbl_b[0] - }, 0)); - } - else if(fi.FieldType == typeof(byte) || - fi.FieldType == typeof(sbyte)) - { - // Do nothing, can't byteswap them! - } - else if(fi.FieldType == typeof(Guid)) - { - // TODO: Swap GUID - } + flt_b[3], flt_b[2], flt_b[1], flt_b[0] + }, 0)); + } + else if(fi.FieldType == typeof(double)) + { + double dbl = (double)fi.GetValue(str); + byte[] dbl_b = BitConverter.GetBytes(dbl); - // TODO: Swap arrays - else if(fi.FieldType.IsValueType && - !fi.FieldType.IsEnum && - !fi.FieldType.IsArray) + fi.SetValue(str, BitConverter.ToDouble(new[] { - object obj = fi.GetValue(str); - object strc = SwapStructureMembersEndian(obj); - fi.SetValue(str, strc); - } + dbl_b[7], dbl_b[6], dbl_b[5], dbl_b[4], dbl_b[3], dbl_b[2], dbl_b[1], dbl_b[0] + }, 0)); + } + else if(fi.FieldType == typeof(byte) || + fi.FieldType == typeof(sbyte)) + { + // Do nothing, can't byteswap them! + } + else if(fi.FieldType == typeof(Guid)) + { + // TODO: Swap GUID + } - return str; - } + // TODO: Swap arrays + else if(fi.FieldType.IsValueType && + !fi.FieldType.IsEnum && + !fi.FieldType.IsArray) + { + object obj = fi.GetValue(str); + object strc = SwapStructureMembersEndian(obj); + fi.SetValue(str, strc); + } - /// Swaps all fields in an structure considering them to follow PDP endian conventions - /// Source structure - /// Resulting structure - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static object SwapStructureMembersEndianPdp(object str) - { - Type t = str.GetType(); - FieldInfo[] fieldInfo = t.GetFields(); - - foreach(FieldInfo fi in fieldInfo) - if(fi.FieldType == typeof(short) || - fi.FieldType == typeof(long) || - fi.FieldType == typeof(ushort) || - fi.FieldType == typeof(ulong) || - fi.FieldType == typeof(float) || - fi.FieldType == typeof(double) || - fi.FieldType == typeof(byte) || - fi.FieldType == typeof(sbyte) || - fi.FieldType == typeof(Guid)) - { - // Do nothing - } - else if(fi.FieldType == typeof(int) || - (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(int))) - { - int x = (int)fi.GetValue(str); - fi.SetValue(str, ((x & 0xffffu) << 16) | ((x & 0xffff0000u) >> 16)); - } - else if(fi.FieldType == typeof(uint) || - (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(uint))) - { - uint x = (uint)fi.GetValue(str); - fi.SetValue(str, ((x & 0xffffu) << 16) | ((x & 0xffff0000u) >> 16)); - } - - // TODO: Swap arrays - else if(fi.FieldType.IsValueType && - !fi.FieldType.IsEnum && - !fi.FieldType.IsArray) - { - object obj = fi.GetValue(str); - object strc = SwapStructureMembersEndianPdp(obj); - fi.SetValue(str, strc); - } + return str; + } - return str; - } + /// Swaps all fields in an structure considering them to follow PDP endian conventions + /// Source structure + /// Resulting structure + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static object SwapStructureMembersEndianPdp(object str) + { + Type t = str.GetType(); + FieldInfo[] fieldInfo = t.GetFields(); + + foreach(FieldInfo fi in fieldInfo) + if(fi.FieldType == typeof(short) || + fi.FieldType == typeof(long) || + fi.FieldType == typeof(ushort) || + fi.FieldType == typeof(ulong) || + fi.FieldType == typeof(float) || + fi.FieldType == typeof(double) || + fi.FieldType == typeof(byte) || + fi.FieldType == typeof(sbyte) || + fi.FieldType == typeof(Guid)) + { + // Do nothing + } + else if(fi.FieldType == typeof(int) || + (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(int))) + { + int x = (int)fi.GetValue(str); + fi.SetValue(str, ((x & 0xffffu) << 16) | ((x & 0xffff0000u) >> 16)); + } + else if(fi.FieldType == typeof(uint) || + (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(uint))) + { + uint x = (uint)fi.GetValue(str); + fi.SetValue(str, ((x & 0xffffu) << 16) | ((x & 0xffff0000u) >> 16)); + } - /// Marshal a structure to little-endian binary data - /// The structure you want to marshal to binary - /// Type of the structure to marshal - /// The byte array representing the given structure - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static byte[] StructureToByteArrayLittleEndian(T str) where T : struct - { - byte[] buf = new byte[SizeOf()]; - var ptr = GCHandle.Alloc(buf, GCHandleType.Pinned); - System.Runtime.InteropServices.Marshal.StructureToPtr(str, ptr.AddrOfPinnedObject(), false); - ptr.Free(); + // TODO: Swap arrays + else if(fi.FieldType.IsValueType && + !fi.FieldType.IsEnum && + !fi.FieldType.IsArray) + { + object obj = fi.GetValue(str); + object strc = SwapStructureMembersEndianPdp(obj); + fi.SetValue(str, strc); + } - return buf; - } + return str; + } - /// Marshal a structure to little-endian binary data - /// The structure you want to marshal to binary - /// Type of the structure to marshal - /// The byte array representing the given structure - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static byte[] StructureToByteArrayBigEndian(T str) where T : struct => - StructureToByteArrayLittleEndian((T)SwapStructureMembersEndian(str)); - - /// Converts a hexadecimal string into a byte array - /// Hexadecimal string - /// Resulting byte array - /// Number of output bytes processed - public static int ConvertFromHexAscii(string hex, out byte[] outBuf) - { - outBuf = null; + /// Marshal a structure to little-endian binary data + /// The structure you want to marshal to binary + /// Type of the structure to marshal + /// The byte array representing the given structure + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static byte[] StructureToByteArrayLittleEndian(T str) where T : struct + { + byte[] buf = new byte[SizeOf()]; + var ptr = GCHandle.Alloc(buf, GCHandleType.Pinned); + System.Runtime.InteropServices.Marshal.StructureToPtr(str, ptr.AddrOfPinnedObject(), false); + ptr.Free(); - if(hex is null || - hex == "") - return -1; + return buf; + } - int off = 0; + /// Marshal a structure to little-endian binary data + /// The structure you want to marshal to binary + /// Type of the structure to marshal + /// The byte array representing the given structure + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static byte[] StructureToByteArrayBigEndian(T str) where T : struct => + StructureToByteArrayLittleEndian((T)SwapStructureMembersEndian(str)); + + /// Converts a hexadecimal string into a byte array + /// Hexadecimal string + /// Resulting byte array + /// Number of output bytes processed + public static int ConvertFromHexAscii(string hex, out byte[] outBuf) + { + outBuf = null; - if(hex[0] == '0' && - (hex[1] == 'x' || hex[1] == 'X')) - { - off = 2; - } + if(hex is null || + hex == "") + return -1; - outBuf = new byte[(hex.Length - off) / 2]; - int count = 0; + int off = 0; - for(int i = off; i < hex.Length; i += 2) - { - char c = hex[i]; + if(hex[0] == '0' && + (hex[1] == 'x' || hex[1] == 'X')) + { + off = 2; + } - if(c < '0' || - (c > '9' && c < 'A') || - (c > 'F' && c < 'a') || - c > 'f') - break; + outBuf = new byte[(hex.Length - off) / 2]; + int count = 0; - c -= c >= 'a' && c <= 'f' - ? '\u0057' - : c >= 'A' && c <= 'F' - ? '\u0037' - : '\u0030'; + for(int i = off; i < hex.Length; i += 2) + { + char c = hex[i]; - outBuf[(i - off) / 2] = (byte)(c << 4); + if(c < '0' || + (c > '9' && c < 'A') || + (c > 'F' && c < 'a') || + c > 'f') + break; - c = hex[i + 1]; + c -= c >= 'a' && c <= 'f' + ? '\u0057' + : c >= 'A' && c <= 'F' + ? '\u0037' + : '\u0030'; - if(c < '0' || - (c > '9' && c < 'A') || - (c > 'F' && c < 'a') || - c > 'f') - break; + outBuf[(i - off) / 2] = (byte)(c << 4); - c -= c >= 'a' && c <= 'f' - ? '\u0057' - : c >= 'A' && c <= 'F' - ? '\u0037' - : '\u0030'; + c = hex[i + 1]; - outBuf[(i - off) / 2] += (byte)c; + if(c < '0' || + (c > '9' && c < 'A') || + (c > 'F' && c < 'a') || + c > 'f') + break; - count++; - } + c -= c >= 'a' && c <= 'f' + ? '\u0057' + : c >= 'A' && c <= 'F' + ? '\u0037' + : '\u0030'; + + outBuf[(i - off) / 2] += (byte)c; - return count; + count++; } + + return count; } } \ No newline at end of file diff --git a/MarshallingPropertiesAttribute.cs b/MarshallingPropertiesAttribute.cs index 3110674cb..bb9f7c35c 100644 --- a/MarshallingPropertiesAttribute.cs +++ b/MarshallingPropertiesAttribute.cs @@ -38,25 +38,24 @@ using System; -namespace Aaru.Helpers +namespace Aaru.Helpers; + +/// +/// Defines properties to help marshalling structs from binary data +[AttributeUsage(AttributeTargets.Struct)] +public sealed class MarshallingPropertiesAttribute : Attribute { /// /// Defines properties to help marshalling structs from binary data - [AttributeUsage(AttributeTargets.Struct)] - public sealed class MarshallingPropertiesAttribute : Attribute + /// Defines properties to help marshalling structs from binary data + public MarshallingPropertiesAttribute(BitEndian endian) { - /// - /// Defines properties to help marshalling structs from binary data - /// Defines properties to help marshalling structs from binary data - public MarshallingPropertiesAttribute(BitEndian endian) - { - Endian = endian; - HasReferences = true; - } - - /// c - public BitEndian Endian { get; } - /// Tells if the structure, or any nested structure, has any non-value type (e.g. arrays, strings, etc). - public bool HasReferences { get; set; } + Endian = endian; + HasReferences = true; } + + /// c + public BitEndian Endian { get; } + /// Tells if the structure, or any nested structure, has any non-value type (e.g. arrays, strings, etc). + public bool HasReferences { get; set; } } \ No newline at end of file diff --git a/PrintHex.cs b/PrintHex.cs index c3ca7cd6a..85476c8a9 100644 --- a/PrintHex.cs +++ b/PrintHex.cs @@ -33,104 +33,103 @@ using System.Text; using Aaru.Console; -namespace Aaru.Helpers +namespace Aaru.Helpers; + +/// Helper operations to get hexadecimal representations of byte arrays +public static class PrintHex { - /// Helper operations to get hexadecimal representations of byte arrays - public static class PrintHex + /// Prints a byte array as hexadecimal values to the console + /// Array + /// Width of line + public static void PrintHexArray(byte[] array, int width = 16) => + AaruConsole.WriteLine(ByteArrayToHexArrayString(array, width)); + + /// Prints a byte array as hexadecimal values to a string + /// Array + /// Width of line + /// Use ANSI escape colors for sections + /// String containing hexadecimal values + public static string ByteArrayToHexArrayString(byte[] array, int width = 16, bool color = false) { - /// Prints a byte array as hexadecimal values to the console - /// Array - /// Width of line - public static void PrintHexArray(byte[] array, int width = 16) => - AaruConsole.WriteLine(ByteArrayToHexArrayString(array, width)); - - /// Prints a byte array as hexadecimal values to a string - /// Array - /// Width of line - /// Use ANSI escape colors for sections - /// String containing hexadecimal values - public static string ByteArrayToHexArrayString(byte[] array, int width = 16, bool color = false) - { - if(array is null) - return null; + if(array is null) + return null; - // TODO: Color list - // TODO: Allow to change width - string str = "Offset"; - int rows = array.Length / 16; - int last = array.Length % 16; - int offsetLength = $"{array.Length:X}".Length; - var sb = new StringBuilder(); + // TODO: Color list + // TODO: Allow to change width + string str = "Offset"; + int rows = array.Length / 16; + int last = array.Length % 16; + int offsetLength = $"{array.Length:X}".Length; + var sb = new StringBuilder(); - if(last > 0) - rows++; + if(last > 0) + rows++; - if(last == 0) - last = 16; + if(last == 0) + last = 16; - if(offsetLength < str.Length) - offsetLength = str.Length; + if(offsetLength < str.Length) + offsetLength = str.Length; - while(str.Length < offsetLength) - str += ' '; + while(str.Length < offsetLength) + str += ' '; - if(color) - sb.Append("\u001b[36m"); + if(color) + sb.Append("\u001b[36m"); - sb.Append(str); - sb.Append(" "); + sb.Append(str); + sb.Append(" "); - for(int i = 0; i < 16; i++) - { - sb.AppendFormat(" {0:X2}", i); - } + for(int i = 0; i < 16; i++) + { + sb.AppendFormat(" {0:X2}", i); + } - if(color) - sb.Append("\u001b[0m"); + if(color) + sb.Append("\u001b[0m"); - sb.AppendLine(); + sb.AppendLine(); - int b = 0; + int b = 0; - string format = $"{{0:X{offsetLength}}}"; + string format = $"{{0:X{offsetLength}}}"; - for(int i = 0; i < rows; i++) - { - if(color) - sb.Append("\u001b[36m"); - - sb.AppendFormat(format, b); + for(int i = 0; i < rows; i++) + { + if(color) + sb.Append("\u001b[36m"); - if(color) - sb.Append("\u001b[0m"); + sb.AppendFormat(format, b); - sb.Append(" "); - int lastBytes = i == rows - 1 ? last : 16; - int lastSpaces = 16 - lastBytes; + if(color) + sb.Append("\u001b[0m"); - for(int j = 0; j < lastBytes; j++) - { - sb.AppendFormat(" {0:X2}", array[b]); - b++; - } + sb.Append(" "); + int lastBytes = i == rows - 1 ? last : 16; + int lastSpaces = 16 - lastBytes; - for(int j = 0; j < lastSpaces; j++) - sb.Append(" "); + for(int j = 0; j < lastBytes; j++) + { + sb.AppendFormat(" {0:X2}", array[b]); + b++; + } - b -= lastBytes; + for(int j = 0; j < lastSpaces; j++) sb.Append(" "); - for(int j = 0; j < lastBytes; j++) - { - int v = array[b]; - sb.Append((v > 31 && v < 127) || v > 159 ? (char)v : '.'); - b++; - } + b -= lastBytes; + sb.Append(" "); - sb.AppendLine(); + for(int j = 0; j < lastBytes; j++) + { + int v = array[b]; + sb.Append((v > 31 && v < 127) || v > 159 ? (char)v : '.'); + b++; } - return sb.ToString(); + sb.AppendLine(); } + + return sb.ToString(); } } \ No newline at end of file diff --git a/StringHandlers.cs b/StringHandlers.cs index 560c662c7..21a877560 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -33,153 +33,152 @@ using System; using System.Text; -namespace Aaru.Helpers +namespace Aaru.Helpers; + +/// Helper operations to work with strings +public static class StringHandlers { - /// Helper operations to work with strings - public static class StringHandlers + /// Converts a null-terminated (aka C string) ASCII byte array to a C# string + /// The corresponding C# string + /// A null-terminated (aka C string) ASCII byte array + public static string CToString(byte[] cString) => CToString(cString, Encoding.ASCII); + + /// Converts a null-terminated (aka C string) byte array with the specified encoding to a C# string + /// The corresponding C# string + /// A null-terminated (aka C string) byte array in the specified encoding + /// Encoding. + /// Set if encoding uses 16-bit characters. + /// Start decoding at this position + public static string CToString(byte[] cString, Encoding encoding, bool twoBytes = false, int start = 0) { - /// Converts a null-terminated (aka C string) ASCII byte array to a C# string - /// The corresponding C# string - /// A null-terminated (aka C string) ASCII byte array - public static string CToString(byte[] cString) => CToString(cString, Encoding.ASCII); - - /// Converts a null-terminated (aka C string) byte array with the specified encoding to a C# string - /// The corresponding C# string - /// A null-terminated (aka C string) byte array in the specified encoding - /// Encoding. - /// Set if encoding uses 16-bit characters. - /// Start decoding at this position - public static string CToString(byte[] cString, Encoding encoding, bool twoBytes = false, int start = 0) - { - if(cString == null) - return null; + if(cString == null) + return null; - int len = 0; + int len = 0; - for(int i = start; i < cString.Length; i++) - { - if(cString[i] == 0) - if(twoBytes) + for(int i = start; i < cString.Length; i++) + { + if(cString[i] == 0) + if(twoBytes) + { + if(i + 1 < cString.Length && + cString[i + 1] == 0) { - if(i + 1 < cString.Length && - cString[i + 1] == 0) - { - len++; + len++; - break; - } - } - else break; + } + } + else + break; - len++; - } + len++; + } - if(twoBytes && len % 2 > 0) - len--; + if(twoBytes && len % 2 > 0) + len--; - byte[] dest = new byte[len]; - Array.Copy(cString, start, dest, 0, len); + byte[] dest = new byte[len]; + Array.Copy(cString, start, dest, 0, len); - return len == 0 ? "" : encoding.GetString(dest); - } + return len == 0 ? "" : encoding.GetString(dest); + } + + /// Converts a length-prefixed (aka Pascal string) ASCII byte array to a C# string + /// The corresponding C# string + /// A length-prefixed (aka Pascal string) ASCII byte array + public static string PascalToString(byte[] pascalString) => PascalToString(pascalString, Encoding.ASCII); + + /// Converts a length-prefixed (aka Pascal string) ASCII byte array to a C# string + /// The corresponding C# string + /// A length-prefixed (aka Pascal string) ASCII byte array + /// Encoding. + /// Start decoding at this position + public static string PascalToString(byte[] pascalString, Encoding encoding, int start = 0) + { + if(pascalString == null) + return null; - /// Converts a length-prefixed (aka Pascal string) ASCII byte array to a C# string - /// The corresponding C# string - /// A length-prefixed (aka Pascal string) ASCII byte array - public static string PascalToString(byte[] pascalString) => PascalToString(pascalString, Encoding.ASCII); - - /// Converts a length-prefixed (aka Pascal string) ASCII byte array to a C# string - /// The corresponding C# string - /// A length-prefixed (aka Pascal string) ASCII byte array - /// Encoding. - /// Start decoding at this position - public static string PascalToString(byte[] pascalString, Encoding encoding, int start = 0) + byte length = pascalString[start]; + int len = 0; + + for(int i = start + 1; i < length + 1 && i < pascalString.Length; i++) { - if(pascalString == null) - return null; + if(pascalString[i] == 0) + break; - byte length = pascalString[start]; - int len = 0; + len++; + } - for(int i = start + 1; i < length + 1 && i < pascalString.Length; i++) - { - if(pascalString[i] == 0) - break; + byte[] dest = new byte[len]; + Array.Copy(pascalString, start + 1, dest, 0, len); - len++; - } + return len == 0 ? "" : encoding.GetString(dest); + } - byte[] dest = new byte[len]; - Array.Copy(pascalString, start + 1, dest, 0, len); + /// Converts a space (' ', 0x20, ASCII SPACE) padded ASCII byte array to a C# string + /// The corresponding C# string + /// A space (' ', 0x20, ASCII SPACE) padded ASCII byte array + public static string SpacePaddedToString(byte[] spacePaddedString) => + SpacePaddedToString(spacePaddedString, Encoding.ASCII); + + /// Converts a space (' ', 0x20, ASCII SPACE) padded ASCII byte array to a C# string + /// The corresponding C# string + /// A space (' ', 0x20, ASCII SPACE) padded ASCII byte array + /// Encoding. + /// Start decoding at this position + public static string SpacePaddedToString(byte[] spacePaddedString, Encoding encoding, int start = 0) + { + if(spacePaddedString == null) + return null; - return len == 0 ? "" : encoding.GetString(dest); - } + int len = start; - /// Converts a space (' ', 0x20, ASCII SPACE) padded ASCII byte array to a C# string - /// The corresponding C# string - /// A space (' ', 0x20, ASCII SPACE) padded ASCII byte array - public static string SpacePaddedToString(byte[] spacePaddedString) => - SpacePaddedToString(spacePaddedString, Encoding.ASCII); - - /// Converts a space (' ', 0x20, ASCII SPACE) padded ASCII byte array to a C# string - /// The corresponding C# string - /// A space (' ', 0x20, ASCII SPACE) padded ASCII byte array - /// Encoding. - /// Start decoding at this position - public static string SpacePaddedToString(byte[] spacePaddedString, Encoding encoding, int start = 0) + for(int i = spacePaddedString.Length; i >= start; i--) { - if(spacePaddedString == null) - return null; + if(i == start) + return ""; - int len = start; + if(spacePaddedString[i - 1] == 0x20) + continue; - for(int i = spacePaddedString.Length; i >= start; i--) - { - if(i == start) - return ""; + len = i; - if(spacePaddedString[i - 1] == 0x20) - continue; + break; + } - len = i; + return len == 0 ? "" : encoding.GetString(spacePaddedString, start, len); + } - break; - } + /// Converts an OSTA compressed unicode byte array to a C# string + /// The C# string. + /// OSTA compressed unicode byte array. + public static string DecompressUnicode(byte[] dstring) + { + ushort unicode; + byte compId = dstring[0]; + string temp = ""; - return len == 0 ? "" : encoding.GetString(spacePaddedString, start, len); - } + if(compId != 8 && + compId != 16) + return null; - /// Converts an OSTA compressed unicode byte array to a C# string - /// The C# string. - /// OSTA compressed unicode byte array. - public static string DecompressUnicode(byte[] dstring) + for(int byteIndex = 1; byteIndex < dstring.Length;) { - ushort unicode; - 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; + if(compId == 16) + unicode = (ushort)(dstring[byteIndex++] << 8); + else + unicode = 0; - if(byteIndex < dstring.Length) - unicode |= dstring[byteIndex++]; + if(byteIndex < dstring.Length) + unicode |= dstring[byteIndex++]; - if(unicode == 0) - break; - - temp += Encoding.Unicode.GetString(BitConverter.GetBytes(unicode)); - } + if(unicode == 0) + break; - return temp; + temp += Encoding.Unicode.GetString(BitConverter.GetBytes(unicode)); } + + return temp; } } \ No newline at end of file diff --git a/Swapping.cs b/Swapping.cs index 39498721e..3bc76eefc 100644 --- a/Swapping.cs +++ b/Swapping.cs @@ -32,81 +32,80 @@ using System.Runtime.CompilerServices; -namespace Aaru.Helpers +namespace Aaru.Helpers; + +/// Helper operations to work with swapping endians +public static class Swapping { - /// Helper operations to work with swapping endians - public static class Swapping - { - /// Gets the PDP endian equivalent of the given little endian unsigned integer - /// Little endian unsigned integer - /// PDP unsigned integer - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static uint PDPFromLittleEndian(uint x) => ((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16); + /// Gets the PDP endian equivalent of the given little endian unsigned integer + /// Little endian unsigned integer + /// PDP unsigned integer + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static uint PDPFromLittleEndian(uint x) => ((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16); - /// Gets the PDP endian equivalent of the given big endian unsigned integer - /// Big endian unsigned integer - /// PDP unsigned integer - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static uint PDPFromBigEndian(uint x) => ((x & 0xff00ff) << 8) | ((x & 0xff00ff00) >> 8); + /// Gets the PDP endian equivalent of the given big endian unsigned integer + /// Big endian unsigned integer + /// PDP unsigned integer + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static uint PDPFromBigEndian(uint x) => ((x & 0xff00ff) << 8) | ((x & 0xff00ff00) >> 8); - /// Swaps the endian of the specified unsigned short integer - /// Unsigned short integer - /// Swapped unsigned short integer - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ushort Swap(ushort x) => (ushort)((x << 8) | (x >> 8)); + /// Swaps the endian of the specified unsigned short integer + /// Unsigned short integer + /// Swapped unsigned short integer + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ushort Swap(ushort x) => (ushort)((x << 8) | (x >> 8)); - /// Swaps the endian of the specified signed short integer - /// Signed short integer - /// Swapped signed short integer - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static short Swap(short x) => (short)((x << 8) | ((x >> 8) & 0xFF)); + /// Swaps the endian of the specified signed short integer + /// Signed short integer + /// Swapped signed short integer + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static short Swap(short x) => (short)((x << 8) | ((x >> 8) & 0xFF)); - /// Swaps the endian of the specified unsigned integer - /// Unsigned integer - /// Swapped unsigned integer - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static uint Swap(uint x) - { - x = ((x << 8) & 0xFF00FF00) | ((x >> 8) & 0xFF00FF); + /// Swaps the endian of the specified unsigned integer + /// Unsigned integer + /// Swapped unsigned integer + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static uint Swap(uint x) + { + x = ((x << 8) & 0xFF00FF00) | ((x >> 8) & 0xFF00FF); - return (x << 16) | (x >> 16); - } + return (x << 16) | (x >> 16); + } - /// Swaps the endian of the specified signed integer - /// Signed integer - /// Swapped signed integer - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Swap(int x) - { - x = (int)(((x << 8) & 0xFF00FF00) | (((uint)x >> 8) & 0xFF00FF)); + /// Swaps the endian of the specified signed integer + /// Signed integer + /// Swapped signed integer + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int Swap(int x) + { + 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)); + } - /// Swaps the endian of the specified unsigned long integer - /// Unsigned long integer - /// Swapped unsigned long integer - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ulong Swap(ulong x) - { - x = ((x & 0x00000000FFFFFFFF) << 32) | ((x & 0xFFFFFFFF00000000) >> 32); - x = ((x & 0x0000FFFF0000FFFF) << 16) | ((x & 0xFFFF0000FFFF0000) >> 16); - x = ((x & 0x00FF00FF00FF00FF) << 8) | ((x & 0xFF00FF00FF00FF00) >> 8); + /// Swaps the endian of the specified unsigned long integer + /// Unsigned long integer + /// Swapped unsigned long integer + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ulong Swap(ulong x) + { + x = ((x & 0x00000000FFFFFFFF) << 32) | ((x & 0xFFFFFFFF00000000) >> 32); + x = ((x & 0x0000FFFF0000FFFF) << 16) | ((x & 0xFFFF0000FFFF0000) >> 16); + x = ((x & 0x00FF00FF00FF00FF) << 8) | ((x & 0xFF00FF00FF00FF00) >> 8); - return x; - } + return x; + } - /// Swaps the endian of the specified signed long integer - /// Signed long integer - /// Swapped signed long integer - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static long Swap(long x) - { - x = ((x & 0x00000000FFFFFFFF) << 32) | (long)(((ulong)x & 0xFFFFFFFF00000000) >> 32); - x = ((x & 0x0000FFFF0000FFFF) << 16) | (long)(((ulong)x & 0xFFFF0000FFFF0000) >> 16); - x = ((x & 0x00FF00FF00FF00FF) << 8) | (long)(((ulong)x & 0xFF00FF00FF00FF00) >> 8); + /// Swaps the endian of the specified signed long integer + /// Signed long integer + /// Swapped signed long integer + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long Swap(long x) + { + x = ((x & 0x00000000FFFFFFFF) << 32) | (long)(((ulong)x & 0xFFFFFFFF00000000) >> 32); + x = ((x & 0x0000FFFF0000FFFF) << 16) | (long)(((ulong)x & 0xFFFF0000FFFF0000) >> 16); + x = ((x & 0x00FF00FF00FF00FF) << 8) | (long)(((ulong)x & 0xFF00FF00FF00FF00) >> 8); - return x; - } + return x; } } \ No newline at end of file From bfca01481a2448fd6f15b5bc8591710885e6a2ec Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 6 Mar 2022 14:07:02 +0000 Subject: [PATCH 169/217] Fix MSBuild warnings. --- Aaru.Helpers.csproj | 3 --- 1 file changed, 3 deletions(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index 2fd832faa..3a588cc04 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -54,9 +54,6 @@ 4 false - - - From 1502ea91c1658b635f89789893ecd56eb0048a9e Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 7 Mar 2022 07:36:42 +0000 Subject: [PATCH 170/217] General cleanup and refactor. --- .editorconfig | 820 ++++++++---------------------- Aaru.Helpers.csproj | 227 ++++----- ArrayFill.cs | 4 +- ArrayIsEmpty.cs | 4 +- BigEndianBitConverter.cs | 23 +- CHS.cs | 4 +- CompareBytes.cs | 3 +- DateHandlers.cs | 71 ++- Marshal.cs | 69 ++- MarshallingPropertiesAttribute.cs | 4 +- PrintHex.cs | 30 +- StringHandlers.cs | 16 +- Swapping.cs | 4 +- 13 files changed, 425 insertions(+), 854 deletions(-) diff --git a/.editorconfig b/.editorconfig index 9181fe501..25aaa3207 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,632 +1,216 @@ -root = true - [*] charset = utf-8 -next_line = crlf +end_of_line = lf +trim_trailing_whitespace = false insert_final_newline = false indent_style = space indent_size = 4 -# Generic non-language specific ones for Resharper and friends -brace_style = next_line -int_align = true -keep_existing_arrangement = false -place_simple_blocks_on_single_line = true -place_simple_declaration_blocks_on_single_line = true -place_attribute_on_same_line = false -space_after_unary_operator = false -space_after_comma = true -space_around_ternary_operator = true -space_around_binary_operator = true -space_around_member_access_operator = false -space_before_open_square_brackets = false -space_after_keywords_in_control_flow_statements = true -space_before_comma = false -space_between_method_call_name_and_opening_parenthesis = false -space_between_method_declaration_name_and_open_parenthesis = false -space_between_square_brackets = false -space_between_parentheses_of_control_flow_statements = false -accessor_owner_declaration_braces = next_line -accessor_declaration_braces = next_line -case_block_braces = next_line -initializer_braces = next_line -other_braces = next_line -allow_comment_after_lbrace = false -empty_block_style = together_same_line -braces_for_ifelse = not_required -braces_for_for = not_required -braces_for_foreach = not_required -braces_for_while = not_required -braces_for_dowhile = not_required -braces_for_using = not_required -braces_for_lock = not_required -braces_for_fixed = not_required -method_or_operator_body = expression_body -local_function_body = expression_body -constructor_or_destructor_body = expression_body -accessor_owner_body = expression_body -force_attribute_style = join -function_braces = next_line -force_control_statements_braces = always_remove -space_in_singleline_accessorholder = true -type_declaration_braces = next_line -invocable_declaration_braces = next_line -anonymous_method_declaration_braces = next_line -space_between_accessors_in_singleline_property = true -indent_nested_usings_stmt = true -space_within_empty_braces = false -indent_nested_fixed_stmt = true -indent_nested_lock_stmt = true -indent_nested_for_stmt = true -indent_nested_foreach_stmt = true -indent_nested_while_stmt = true -use_continuous_indent_inside_parens = true -indent_method_decl_pars = inside -indent_invocation_pars = inside -indent_statement_pars = inside -indent_typeparam_angles = inside -indent_typearg_angles = inside -indent_pars = inside -indent_preprocessor_if = outdent -indent_preprocessor_region = usual_indent -indent_preprocessor_other = usual_indent -indent_switch_labels = true -indent_type_constraints = true -stick_comment = false -alignment_tab_fill_style = use_spaces -align_multiline_parameter = true -align_multiline_extends_list = true -align_linq_query = true -align_multiline_binary_expressions_chain = true -outdent_binary_ops = true -align_multiline_calls_chain = true -outdent_dots = true -align_multiline_array_and_object_initializer = false -indent_anonymous_method_block = false -align_first_arg_by_paren = true -align_multiline_argument = true -align_tuple_components = true -align_multiline_expression = true -align_multiline_for_stmt = true -align_multiple_declaration = true -align_multline_type_parameter_list = true -align_multline_type_parameter_constrains = true -int_align_fields = true -int_align_properties = true -int_align_methods = true -int_align_parameters = false -int_align_variables = true -int_align_assignments = true -int_align_nested_ternary = true -int_align_invocations = false -int_align_binary_expressions = true -int_align_comments = true -int_align_switch_sections = true -keep_user_linebreaks = false -keep_existing_arrangement = false -keep_existing_linebreaks = false -max_line_length = 120 -wrap_before_comma = false -special_else_if_treatment = true -place_type_attribute_on_same_line = never -place_method_attribute_on_same_line = never -place_accessorholder_attribute_on_same_line = never -place_attribute_on_same_line = never -place_accessor_attribute_on_same_line = never -place_attribute_on_same_line = never -place_field_attribute_on_same_line = never -place_attribute_on_same_line = never -wrap_parameters_style = wrap_if_long -keep_existing_declaration_parens_arrangement = false -wrap_before_declaration_lpar = false -wrap_after_declaration_lpar = false -wrap_before_declaration_rpar = false -place_constructor_initializer_on_same_line = true -keep_existing_expr_member_arrangement = false -place_expr_method_on_single_line = true -place_expr_property_on_single_line = true -place_expr_accessor_on_single_line = true -wrap_before_arrow_with_expressions = false -place_type_constraints_on_same_line = true -wrap_before_first_type_parameter_constraint = true -wrap_multiple_type_parameter_constraints_style = wrap_if_long -wrap_before_type_parameter_langle = true -wrap_before_extends_colon = false -wrap_extends_list_style = wrap_if_long -keep_existing_declaration_block_arrangement = false -place_abstract_accessorholder_on_single_line = true -place_simple_accessorholder_on_single_line = false -place_accessor_with_attrs_holder_on_single_line = false -place_simple_accessor_on_single_line = true -place_simple_method_on_single_line = false -keep_existing_enum_arrangement = false -place_simple_enum_on_single_line = false -wrap_enum_declaration = wrap_if_long -new_line_before_else = true -new_line_before_while = false -wrap_for_stmt_header_style = wrap_if_long -wrap_multiple_declaration_style = wrap_if_long -keep_existing_embedded_arrangement = false -place_simple_embedded_statement_on_same_line = false -place_simple_case_statement_on_same_line = true -keep_existing_embedded_block_arrangement = false -place_simple_embedded_block_on_same_line = false -place_simple_anonymousmethod_on_single_line = false -keep_existing_initializer_arrangement = false -place_simple_initializer_on_single_line = false -wrap_object_and_collection_initializer_style = chop_always -wrap_array_initializer_style = wrap_if_long -wrap_arguments_style = wrap_if_long -keep_existing_invocation_parens_arrangement = false -wrap_after_invocation_lpar = false -wrap_before_invocation_rpar = false -wrap_after_dot_in_method_calls = true -wrap_chained_method_calls = wrap_if_long -wrap_before_binary_opsign = false -wrap_chained_binary_expressions = wrap_if_long -force_chop_compound_if_expression = true -force_chop_compound_while_expression = true -force_chop_compound_do_expression = true -wrap_before_ternary_opsigns = true -wrap_ternary_expr_style = wrap_if_long -nested_ternary_style = expanded -wrap_linq_expressions = wrap_if_long -wrap_before_linq_expression = false -place_linq_into_on_new_line = false -wrap_verbatim_interpolated_strings = wrap_if_long -extra_spaces = remove_all -space_after_keywords_in_control_flow_statements = false -space_between_method_call_name_and_opening_parenthesis = false -space_between_method_declaration_name_and_open_parenthesis = false -space_before_typeof_parentheses = false -space_before_checked_parentheses = false -space_before_sizeof_parentheses = false -space_before_nameof_parentheses = false -space_between_keyword_and_expression = true -space_between_keyword_and_type = true -space_around_assignment_op = true -space_around_logical_op = true -space_around_binary_operator = true -space_around_equality_op = true -space_around_relational_op = true -space_around_bitwise_op = true -space_around_additive_op = true -space_around_multiplicative_op = true -space_around_shift_op = true -space_around_nullcoalescing_op = true -space_around_arrow_op = false -space_after_logical_not_op = false -space_after_unary_operator = false -space_after_cast = false -space_around_dot = false -space_around_lambda_arrow = true -space_before_pointer_asterik_declaration = false -space_before_nullable_mark = false -blank_lines_around_class_definition = 1 -namespace_indentation = all -space_within_template_argument = false -align_union_type_usage = true -space_in_singleline_method = true -space_in_singleline_anonymous_method = true -space_within_single_line_array_initializer_braces = true -space_around_arrow_op = false - -# These are for markup languages (HTML, XML, etc) -spaces_around_eq_in_pi_attribute = false -space_after_last_pi_attribute = true -pi_attributes_indent = align_by_first_attribute -blank_line_after_pi = true -spaces_around_eq_in_attribute = false -space_after_last_attribute = false -space_before_self_closing = true -attribute_style = on_single_line -attribute_indent = align_by_first_attribute -sort_attributes = true -sort_class_selectors = true -max_blank_lines_between_tags = 0 -linebreak_before_all_elements = true -linebreak_before_multiline_elements = true -quote_style = doublequoted -delete_quotes_from_solid_values = false -normalize_tag_names = true - - -[{.babelrc,.stylelintrc,jest.config,.eslintrc,.prettierrc,*.json,*.jsb3,*.jsb2,*.bowerrc}] -indent_size = 2 - -[*.js.map] -indent_size = 2 - -[*.{css,scss}] -indent_size = 2 -declarations_style = separate_lines_for_nonsingle -media_query_style = separate_lines -selector_style = same_line -properties_style = separate_lines_for_nonsingle -brace_style = next_line - -[{.analysis_options,*.yml,*.yaml}] -indent_size = 2 - -# Xml project files -[*.{csproj,vcxproj,vcxproj.filters,proj,nativeproj,locproj}] -indent_size = 2 - -# Xml files -[*.{xml,stylecop,resx,ruleset}] -indent_size = 2 - -# Xml config files -[*.{props,targets,config,nuspec}] -indent_size = 2 - -# .net files -[*.{cs,vb}] -# These set the this. / Me. -dotnet_style_qualification_for_field = false:warning -dotnet_style_qualification_for_property = false:warning -dotnet_style_qualification_for_method = false:warning -dotnet_style_qualification_for_event = false:warning - -# These make it suggest Int32 instead of int, etc. +# Microsoft .NET properties +csharp_new_line_between_query_expression_clauses = false +csharp_preferred_modifier_order = public, private, protected, internal, new, static, abstract, virtual, sealed, readonly, override, extern, unsafe, volatile, async:suggestion +csharp_prefer_braces = false:warning +csharp_space_after_keywords_in_control_flow_statements = false +csharp_style_var_elsewhere = false:suggestion +csharp_style_var_for_built_in_types = false:suggestion +csharp_style_var_when_type_is_apparent = true:suggestion +csharp_using_directive_placement = inside_namespace:silent +dotnet_naming_rule.unity_serialized_field_rule.import_to_resharper = True +dotnet_naming_rule.unity_serialized_field_rule.resharper_description = Unity serialized field +dotnet_naming_rule.unity_serialized_field_rule.resharper_guid = 5f0fdb63-c892-4d2c-9324-15c80b22a7ef +dotnet_naming_rule.unity_serialized_field_rule.severity = warning +dotnet_naming_rule.unity_serialized_field_rule.style = lower_camel_case_style +dotnet_naming_rule.unity_serialized_field_rule.symbols = unity_serialized_field_symbols +dotnet_naming_rule.unity_serialized_field_rule_1.import_to_resharper = True +dotnet_naming_rule.unity_serialized_field_rule_1.resharper_description = Unity serialized field +dotnet_naming_rule.unity_serialized_field_rule_1.resharper_guid = 5f0fdb63-c892-4d2c-9324-15c80b22a7ef +dotnet_naming_rule.unity_serialized_field_rule_1.severity = warning +dotnet_naming_rule.unity_serialized_field_rule_1.style = lower_camel_case_style +dotnet_naming_rule.unity_serialized_field_rule_1.symbols = unity_serialized_field_symbols_1 +dotnet_naming_style.lower_camel_case_style.capitalization = camel_case +dotnet_naming_symbols.unity_serialized_field_symbols.applicable_accessibilities = * +dotnet_naming_symbols.unity_serialized_field_symbols.applicable_kinds = +dotnet_naming_symbols.unity_serialized_field_symbols.resharper_applicable_kinds = unity_serialised_field +dotnet_naming_symbols.unity_serialized_field_symbols.resharper_required_modifiers = instance +dotnet_naming_symbols.unity_serialized_field_symbols_1.applicable_accessibilities = * +dotnet_naming_symbols.unity_serialized_field_symbols_1.applicable_kinds = +dotnet_naming_symbols.unity_serialized_field_symbols_1.resharper_applicable_kinds = unity_serialised_field +dotnet_naming_symbols.unity_serialized_field_symbols_1.resharper_required_modifiers = instance +dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:warning +dotnet_style_parentheses_in_other_binary_operators = never_if_unnecessary:warning +dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary:warning dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion dotnet_style_predefined_type_for_member_access = true:suggestion - -# This controls implicit access modifiers +dotnet_style_qualification_for_event = false:suggestion +dotnet_style_qualification_for_field = false:suggestion +dotnet_style_qualification_for_method = false:suggestion +dotnet_style_qualification_for_property = false:suggestion dotnet_style_require_accessibility_modifiers = never:suggestion -# Prefer non modified fields to be marked readonly -dotnet_style_readonly_field = true:warning - -# Parenthesis settings -dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:warning -dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:warning -dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:warning -dotnet_style_parentheses_in_other_operators = always_for_clarity:warning - -dotnet_style_object_initializer = true:suggestion -dotnet_style_collection_initializer = true:suggestion -dotnet_style_explicit_tuple_names = true:error -dotnet_style_prefer_inferred_tuple_names = true:warning -dotnet_style_prefer_inferred_anonymous_type_member_names = true:warning -dotnet_style_prefer_is_null_check_over_reference_equality_method = true:warning -dotnet_style_prefer_conditional_expression_over_return = true:warning -dotnet_style_coalesce_expression = true:warning -dotnet_style_null_propagation = true:error - -dotnet_sort_system_directives_first = true - -# Constants in C style, all-caps -dotnet_naming_rule.constant_fields_caps.symbols = constant_fields -dotnet_naming_rule.constant_fields_caps.severity = warning -dotnet_naming_rule.constant_fields_caps.style = caps_style -dotnet_naming_symbols.constant_fields.applicable_kinds = field -dotnet_naming_symbols.constant_fields.required_modifiers = const -dotnet_naming_style.caps_style.capitalization = all_upper - -# interfaces should be prefixed with I -dotnet_naming_rule.pascal_case_for_interface.severity = error -dotnet_naming_rule.pascal_case_for_interface.symbols = interfaces_fields -dotnet_naming_rule.pascal_case_for_interface.style = pascal_case_interface_style -dotnet_naming_symbols.interfaces_fields.applicable_kinds = interface -dotnet_naming_style.pascal_case_interface_style.required_prefix = I -dotnet_naming_style.pascal_case_interface_style.capitalization = pascal_case - -## internal and private fields should be _camelCase -dotnet_naming_rule.camel_case_for_private_internal_fields.severity = warning -dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields -dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style -dotnet_naming_symbols.private_internal_fields.applicable_kinds = field -dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal -dotnet_naming_style.camel_case_underscore_style.required_prefix = _ -dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case - -# 2018-12-07 NP: This is not yet working in VS2017 -# local variables should be camelCase -#dotnet_naming_rule.camel_case_for_locals.severity = suggestion -#dotnet_naming_rule.camel_case_for_locals.symbols = local_fields -#dotnet_naming_rule.camel_case_for_locals.style = camel_case_style -#dotnet_naming_symbols.local_fields.applicable_kinds = local -#dotnet_naming_style.camel_case_style.capitalization = camel_case - -[*.cs] -# var var var -csharp_style_var_for_built_in_types = false:warning -csharp_style_var_when_type_is_apparent = true:suggestion -csharp_style_var_elsewhere = false:warning - -csharp_style_expression_bodied_methods = when_on_single_line:suggestion -csharp_style_expression_bodied_constructors = when_on_single_line:suggestion -csharp_style_expression_bodied_operators = when_on_single_line:suggestion -csharp_style_expression_bodied_properties = when_on_single_line:suggestion -csharp_style_expression_bodied_indexers = when_on_single_line:suggestion -csharp_style_expression_bodied_accessors = when_on_single_line:suggestion - -csharp_style_pattern_matching_over_is_with_cast_check = true:warning -csharp_style_pattern_matching_over_as_with_null_check = when_on_single_line:warning - -csharp_style_inlined_variable_declaration = true:warning - -csharp_prefer_simple_default_expression = true:warning -csharp_style_deconstructed_variable_declaration = false:warning - -csharp_style_throw_expression = true:warning -csharp_style_conditional_delegate_call = true:warning - -csharp_prefer_braces = false - -csharp_new_line_before_open_brace = all -csharp_new_line_before_else = true -csharp_new_line_before_catch = true -csharp_new_line_before_finally = true -csharp_new_line_before_members_in_object_initializers = true -csharp_new_line_before_members_in_anonymous_types = true -csharp_new_line_between_query_expression_clauses = true - -csharp_indent_case_contents = true -csharp_indent_switch_labels = true -csharp_indent_labels = flush_left - -csharp_space_after_cast = false -csharp_space_after_keywords_in_control_flow_statements = false -csharp_space_between_method_declaration_parameter_list_parentheses = false -csharp_space_between_parentheses = none -csharp_space_before_colon_in_inheritance_clause = true -csharp_space_after_colon_in_inheritance_clause = true -csharp_space_around_binary_operators = before_and_after -csharp_space_between_method_declaration_empty_parameter_list_parentheses = false -csharp_space_between_method_call_name_and_opening_parenthesis = false -csharp_space_between_method_call_empty_parameter_list_parentheses = false - -csharp_preserve_single_line_statements = false -csharp_preserve_single_line_blocks = true - -csharp_blank_lines_around_region = 0 -csharp_blank_lines_inside_region = 0 -csharp_blank_lines_before_single_line_comment = 1 -csharp_keep_blank_lines_in_declarations = 1 -csharp_remove_blank_lines_near_braces_in_declarations = true -csharp_blank_lines_after_start_comment = false -csharp_blank_lines_between_using_groups = 0 -csharp_blank_lines_after_using_list = 1 -csharp_blank_lines_around_namespace = 1 -csharp_blank_lines_inside_namespace = 0 -csharp_blank_lines_around_type = 1 -csharp_blank_lines_inside_type = 0 -csharp_blank_lines_around_field = 0 -csharp_blank_lines_around_single_line_field = 0 -csharp_blank_lines_around_property = 1 -csharp_blank_lines_around_single_line_property = 0 -csharp_blank_lines_around_auto_property = 0 -csharp_blank_lines_around_single_line_auto_property = 0 -csharp_blank_lines_around_invocable = 1 -csharp_blank_lines_around_single_line_invocable = 1 -csharp_keep_blank_lines_in_code = 1 -csharp_remove_blank_lines_near_braces_in_code = true -csharp_blank_lines_around_local_method = 1 -csharp_blank_lines_around_single_line_local_method = 1 -csharp_blank_lines_before_control_transfer_statements = 1 -csharp_blank_lines_after_control_transfer_statements = 1 -csharp_blank_lines_before_block_statements = 1 -csharp_blank_lines_after_block_statements = 1 -csharp_blank_lines_before_multiline_statements = 1 -csharp_blank_lines_after_multiline_statements = 1 - -csharp_type_declaration_braces = next_line -csharp_brace_style = next_line -csharp_indent_inside_namespace = true -csharp_invocable_declaration_braces = next_line -csharp_anonymous_method_declaration_braces = next_line -csharp_accessor_owner_declaration_braces = next_line -csharp_accessor_declaration_braces = next_line -csharp_case_block_braces = next_line -csharp_initializer_braces = next_line -csharp_other_braces = next_line -csharp_allow_comment_after_lbrace = false -csharp_empty_block_style = together_same_line - -csharp_for_built_in_types = use_explicit_type -csharp_for_simple_types = use_var_when_evident -csharp_for_other_types = use_explicit_type -csharp_prefer_separate_deconstructed_variables_declaration = true -csharp_prefer_explicit_discard_declaration = false - -csharp_instance_members_qualify_members = none -csharp_builtin_type_reference_style = use_keyword -csharp_prefer_qualified_reference = false -csharp_add_imports_to_deepest_scope = false -csharp_allow_alias = true -csharp_default_private_modifier = implicit -csharp_default_internal_modifier = explicit -csharp_arguments_literal = positional -csharp_arguments_string_literal = positional -csharp_arguments_named = positional -csharp_arguments_anonymous_function = positional -csharp_arguments_other = positional -csharp_braces_for_ifelse = not_required -csharp_braces_for_for = not_required -csharp_braces_for_foreach = not_required -csharp_braces_for_while = not_required -csharp_braces_for_dowhile = not_required -csharp_braces_for_using = not_required -csharp_braces_for_lock = not_required -csharp_braces_for_fixed = not_required -csharp_method_or_operator_body = expression_body -csharp_local_function_body = expression_body -csharp_constructor_or_destructor_body = expression_body -csharp_accessor_owner_body = expression_body -csharp_force_attribute_style = join -csharp_indent_nested_usings_stmt = true - -csharp_builtin_type_reference_for_member_access_style = use_keyword -csharp_indent_nested_fixed_stmt = true -csharp_indent_nested_lock_stmt = true -csharp_indent_nested_for_stmt = true -csharp_indent_nested_foreach_stmt = true -csharp_indent_nested_while_stmt = true -csharp_use_continuous_indent_inside_parens = true -csharp_indent_method_decl_pars = inside -csharp_indent_invocation_pars = inside -csharp_indent_statement_pars = inside -csharp_indent_typeparam_angles = inside -csharp_indent_typearg_angles = inside -csharp_indent_pars = inside -csharp_indent_preprocessor_if = outdent -csharp_indent_preprocessor_region = usual_indent -csharp_indent_preprocessor_other = usual_indent -csharp_indent_switch_labels = true -csharp_indent_type_constraints = true -csharp_stick_comment = false -csharp_alignment_tab_fill_style = use_spaces -csharp_align_multiline_parameter = true -csharp_align_multiline_extends_list = true -csharp_align_linq_query = true -csharp_align_multiline_binary_expressions_chain = true -csharp_outdent_binary_ops = true -csharp_align_multiline_calls_chain = true -csharp_outdent_dots = true -csharp_align_multiline_array_and_object_initializer = false -csharp_indent_anonymous_method_block = false -csharp_align_first_arg_by_paren = true -csharp_align_multiline_argument = true -csharp_align_tuple_components = true -csharp_align_multiline_expression = true -csharp_align_multiline_for_stmt = true -csharp_align_multiple_declaration = true -csharp_align_multline_type_parameter_list = true -csharp_align_multline_type_parameter_constrains = true -csharp_int_align_fields = true -csharp_int_align_properties = true -csharp_int_align_methods = true -csharp_int_align_parameters = false -csharp_int_align_variables = true -csharp_int_align_assignments = true -csharp_int_align_nested_ternary = true -csharp_int_align_invocations = false -csharp_int_align_binary_expressions = true -csharp_int_align_comments = true -csharp_int_align_switch_sections = true -csharp_int_align = true -csharp_keep_user_linebreaks = false -csharp_keep_existing_arrangement = false -csharp_keep_existing_linebreaks = false -csharp_max_line_length = 120 -csharp_wrap_before_comma = false -csharp_special_else_if_treatment = true -csharp_insert_final_newline = false -csharp_place_type_attribute_on_same_line = never -csharp_place_method_attribute_on_same_line = never -csharp_place_accessorholder_attribute_on_same_line = never -csharp_place_attribute_on_same_line = never -csharp_place_accessor_attribute_on_same_line = never -csharp_place_attribute_on_same_line = never -csharp_place_field_attribute_on_same_line = never -csharp_place_attribute_on_same_line = never -csharp_wrap_parameters_style = wrap_if_long -csharp_keep_existing_declaration_parens_arrangement = false -csharp_wrap_before_declaration_lpar = false -csharp_wrap_after_declaration_lpar = false -csharp_wrap_before_declaration_rpar = false -csharp_place_constructor_initializer_on_same_line = true -csharp_keep_existing_expr_member_arrangement = false -csharp_place_expr_method_on_single_line = true -csharp_place_expr_property_on_single_line = true -csharp_place_expr_accessor_on_single_line = true -csharp_wrap_before_arrow_with_expressions = false -csharp_place_type_constraints_on_same_line = true -csharp_wrap_before_first_type_parameter_constraint = true -csharp_wrap_multiple_type_parameter_constraints_style = wrap_if_long -csharp_wrap_before_type_parameter_langle = true -csharp_wrap_before_extends_colon = false -csharp_wrap_extends_list_style = wrap_if_long -csharp_keep_existing_declaration_block_arrangement = false -csharp_place_abstract_accessorholder_on_single_line = true -csharp_place_simple_accessorholder_on_single_line = false -csharp_place_accessor_with_attrs_holder_on_single_line = false -csharp_place_simple_accessor_on_single_line = true -csharp_place_simple_method_on_single_line = false -csharp_keep_existing_enum_arrangement = false -csharp_place_simple_enum_on_single_line = false -csharp_wrap_enum_declaration = wrap_if_long -csharp_new_line_before_else = true -csharp_new_line_before_while = false -csharp_wrap_for_stmt_header_style = wrap_if_long -csharp_wrap_multiple_declaration_style = wrap_if_long -csharp_keep_existing_embedded_arrangement = false -csharp_place_simple_embedded_statement_on_same_line = false -csharp_place_simple_case_statement_on_same_line = true -csharp_keep_existing_embedded_block_arrangement = false -csharp_place_simple_embedded_block_on_same_line = false -csharp_place_simple_anonymousmethod_on_single_line = false -csharp_keep_existing_initializer_arrangement = false -csharp_place_simple_initializer_on_single_line = false -csharp_wrap_object_and_collection_initializer_style = chop_always -csharp_wrap_array_initializer_style = wrap_if_long -csharp_wrap_arguments_style = wrap_if_long -csharp_keep_existing_invocation_parens_arrangement = false -csharp_wrap_after_invocation_lpar = false -csharp_wrap_before_invocation_rpar = false -csharp_wrap_after_dot_in_method_calls = true -csharp_wrap_chained_method_calls = wrap_if_long -csharp_wrap_before_binary_opsign = false -csharp_wrap_chained_binary_expressions = wrap_if_long -csharp_force_chop_compound_if_expression = true -csharp_force_chop_compound_while_expression = true -csharp_force_chop_compound_do_expression = true -csharp_wrap_before_ternary_opsigns = true -csharp_wrap_ternary_expr_style = wrap_if_long -csharp_nested_ternary_style = expanded -csharp_wrap_linq_expressions = wrap_if_long -csharp_wrap_before_linq_expression = false -csharp_place_linq_into_on_new_line = false -csharp_wrap_verbatim_interpolated_strings = wrap_if_long -csharp_extra_spaces = remove_all -csharp_space_after_keywords_in_control_flow_statements = false -csharp_space_between_method_call_name_and_opening_parenthesis = false -csharp_space_between_method_declaration_name_and_open_parenthesis = false -csharp_space_before_typeof_parentheses = false -csharp_space_before_checked_parentheses = false -csharp_space_before_sizeof_parentheses = false -csharp_space_before_nameof_parentheses = false -csharp_space_between_keyword_and_expression = true -csharp_space_between_keyword_and_type = true -csharp_space_around_assignment_op = true -csharp_space_around_logical_op = true -csharp_space_around_binary_operator = true -csharp_space_around_equality_op = true -csharp_space_around_relational_op = true -csharp_space_around_bitwise_op = true -csharp_space_around_additive_op = true -csharp_space_around_multiplicative_op = true -csharp_space_around_shift_op = true -csharp_space_around_nullcoalescing_op = true -csharp_space_around_arrow_op = false -csharp_space_after_logical_not_op = false -csharp_space_after_unary_operator = false -csharp_space_after_cast = false -csharp_space_around_dot = false -csharp_space_around_lambda_arrow = true -csharp_space_before_pointer_asterik_declaration = false -csharp_space_before_nullable_mark = false +# ReSharper properties +resharper_align_first_arg_by_paren = true +resharper_align_linq_query = true +resharper_align_multiline_argument = true +resharper_align_multiline_binary_expressions_chain = true +resharper_align_multiline_binary_patterns = true +resharper_align_multiline_calls_chain = true +resharper_align_multiline_expression = true +resharper_align_multiline_extends_list = true +resharper_align_multiline_for_stmt = true +resharper_align_multiline_parameter = true +resharper_align_multiline_property_pattern = true +resharper_align_multiline_switch_expression = true +resharper_align_multiple_declaration = true +resharper_align_multline_type_parameter_constrains = true +resharper_align_multline_type_parameter_list = true +resharper_align_tuple_components = true +resharper_attribute_indent = align_by_first_attribute +resharper_attribute_style = on_single_line +resharper_autodetect_indent_settings = true +resharper_constructor_or_destructor_body = expression_body +resharper_cpp_brace_style = next_line +resharper_csharp_outdent_commas = true +resharper_default_value_when_type_not_evident = default_expression +resharper_empty_block_style = together_same_line +resharper_force_attribute_style = join +resharper_force_chop_compound_do_expression = true +resharper_force_chop_compound_if_expression = true +resharper_force_chop_compound_while_expression = true +resharper_for_built_in_types = use_var_when_evident +resharper_fsharp_type_declaration_braces = next_line +resharper_indent_nested_fixed_stmt = true +resharper_indent_nested_foreach_stmt = true +resharper_indent_nested_for_stmt = true +resharper_indent_nested_lock_stmt = true +resharper_indent_nested_usings_stmt = true +resharper_indent_nested_while_stmt = true +resharper_indent_preprocessor_if = outdent +resharper_indent_preprocessor_other = usual_indent +resharper_indent_switch_labels = true +resharper_int_align_assignments = true +resharper_int_align_binary_expressions = true +resharper_int_align_comments = true +resharper_int_align_fields = true +resharper_int_align_methods = true +resharper_int_align_nested_ternary = true +resharper_int_align_properties = true +resharper_int_align_property_patterns = true +resharper_int_align_switch_expressions = true +resharper_int_align_switch_sections = true +resharper_int_align_variables = true +resharper_keep_existing_arrangement = false +resharper_keep_user_linebreaks = false +resharper_linebreak_before_all_elements = true +resharper_local_function_body = expression_body +resharper_max_blank_lines_between_tags = 0 +resharper_max_enum_members_on_line = 1 +resharper_method_or_operator_body = expression_body +resharper_nested_ternary_style = expanded +resharper_new_line_before_while = false +resharper_normalize_tag_names = true +resharper_outdent_binary_ops = true +resharper_outdent_binary_pattern_ops = true +resharper_outdent_dots = true +resharper_outdent_statement_labels = true +resharper_place_attribute_on_same_line = false +resharper_place_expr_accessor_on_single_line = true +resharper_place_expr_method_on_single_line = true +resharper_place_expr_property_on_single_line = true +resharper_place_linq_into_on_new_line = false +resharper_place_simple_anonymousmethod_on_single_line = false +resharper_place_simple_case_statement_on_same_line = true +resharper_place_simple_embedded_statement_on_same_line = false +resharper_place_simple_initializer_on_single_line = false +resharper_place_simple_switch_expression_on_single_line = true +resharper_prefer_explicit_discard_declaration = true +resharper_qualified_using_at_nested_scope = true +resharper_show_autodetect_configure_formatting_tip = false +resharper_sort_attributes = true +resharper_sort_class_selectors = true +resharper_space_after_keywords_in_control_flow_statements = false +resharper_space_after_last_pi_attribute = true +resharper_space_after_unary_operator = false +resharper_space_around_binary_operator = true +resharper_space_before_self_closing = true +resharper_space_within_empty_braces = false +resharper_stick_comment = false +resharper_use_indent_from_vs = false +resharper_wrap_after_dot_in_method_calls = true +resharper_wrap_before_first_type_parameter_constraint = true +resharper_wrap_before_type_parameter_langle = true +resharper_wrap_enum_declaration = wrap_if_long +resharper_wrap_for_stmt_header_style = wrap_if_long +resharper_wrap_lines = true +resharper_wrap_multiple_declaration_style = wrap_if_long +resharper_wrap_multiple_type_parameter_constraints_style = wrap_if_long +resharper_wrap_object_and_collection_initializer_style = chop_always +resharper_wrap_ternary_expr_style = wrap_if_long +resharper_wrap_verbatim_interpolated_strings = wrap_if_long + +# ReSharper inspection severities +resharper_annotate_can_be_null_parameter_highlighting = warning +resharper_annotate_can_be_null_type_member_highlighting = warning +resharper_annotate_not_null_parameter_highlighting = warning +resharper_annotate_not_null_type_member_highlighting = warning +resharper_arrange_attributes_highlighting = hint +resharper_arrange_constructor_or_destructor_body_highlighting = warning +resharper_arrange_default_value_when_type_evident_highlighting = warning +resharper_arrange_default_value_when_type_not_evident_highlighting = warning +resharper_arrange_local_function_body_highlighting = warning +resharper_arrange_method_or_operator_body_highlighting = warning +resharper_arrange_object_creation_when_type_evident_highlighting = warning +resharper_arrange_object_creation_when_type_not_evident_highlighting = warning +resharper_arrange_redundant_parentheses_highlighting = hint +resharper_arrange_this_qualifier_highlighting = hint +resharper_arrange_type_member_modifiers_highlighting = hint +resharper_arrange_type_modifiers_highlighting = hint +resharper_async_void_method_highlighting = warning +resharper_built_in_type_reference_style_for_member_access_highlighting = hint +resharper_built_in_type_reference_style_highlighting = hint +resharper_compare_non_constrained_generic_with_null_highlighting = warning +resharper_heap_view_boxing_allocation_highlighting = none +resharper_heap_view_delegate_allocation_highlighting = none +resharper_heap_view_object_allocation_evident_highlighting = none +resharper_heap_view_object_allocation_highlighting = none +resharper_inheritdoc_consider_usage_highlighting = warning +resharper_local_function_can_be_made_static_highlighting = warning +resharper_loop_can_be_partly_converted_to_query_highlighting = warning +resharper_member_can_be_internal_highlighting = warning +resharper_nullable_warning_suppression_is_used_highlighting = warning +resharper_redundant_base_qualifier_highlighting = warning +resharper_remove_constructor_invocation_highlighting = warning +resharper_separate_control_transfer_statement_highlighting = warning +resharper_string_ends_with_is_culture_specific_highlighting = warning +resharper_string_starts_with_is_culture_specific_highlighting = warning +resharper_struct_member_can_be_made_read_only_highlighting = warning +resharper_suggest_var_or_type_built_in_types_highlighting = hint +resharper_suggest_var_or_type_elsewhere_highlighting = hint +resharper_suggest_var_or_type_simple_types_highlighting = hint +resharper_tabs_are_disallowed_highlighting = warning +resharper_unnecessary_whitespace_highlighting = warning +resharper_use_nameof_expression_for_part_of_the_string_highlighting = warning +resharper_use_positional_deconstruction_pattern_highlighting = warning +resharper_web_config_module_not_resolved_highlighting = warning +resharper_web_config_type_not_resolved_highlighting = warning +resharper_web_config_wrong_module_highlighting = warning + +[{*.har,*.inputactions,*.jsb2,*.jsb3,*.json,.babelrc,.eslintrc,.stylelintrc,bowerrc,jest.config}] +indent_style = space +indent_size = 2 -[*.cshtml] -linebreaks_around_razor_statements = true -blank_lines_around_razor_functions = true -blank_lines_around_razor_helpers = true -blank_lines_around_razor_sections = true +[{*.yaml,*.yml,.analysis_options}] +indent_style = space +indent_size = 2 -# C++ -[*.{cc,cpp,cxx,h,hpp,hxx}] -cpp_indent_access_specifiers_from_class = true -cpp_indent_wrapped_function_names = false -cpp_align_multiline_type_argument = true +[*.csv] +indent_style = tab +tab_width = 1 -# C, C++ and ObjectiveC -[*.{c,h,cc,cpp,cxx,m,hpp,hxx}] -indent_preprocessor_directives = normal -indent_type_constraints = true +[{*.bash,*.sh,*.tool,*.zsh}] +indent_style = space +indent_size = 2 -# Javascript and Typescript -[*.{js,js.map,ts}] -quote_style = doublequoted -termination_style = ensure_semicolon \ No newline at end of file +[*.{appxmanifest,asax,ascx,aspx,axaml,build,cg,cginc,compute,cs,cshtml,dtd,fs,fsi,fsscript,fsx,hlsl,hlsli,hlslinc,master,ml,mli,nuspec,paml,razor,resw,resx,shader,skin,usf,ush,vb,xaml,xamlx,xoml,xsd}] +indent_style = space +indent_size = 4 +tab_width = 4 diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index 3a588cc04..a94b4377d 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -1,117 +1,116 @@  - - Debug - AnyCPU - 2.0 - {F8BDF57B-1571-4CD0-84B3-B422088D359A} - Library - Aaru.Helpers - Aaru.Helpers - $(Version) - false - true - 6.0.0-alpha8 - Claunia.com - Copyright © 2011-2022 Natalia Portillo - Aaru Data Preservation Suite - Aaru.Helpers - $(Version) - net6 - 10 - Contains helpers used by the Aaru Data Preservation Suite. - https://github.com/aaru-dps/ - LGPL-2.1-only - https://github.com/aaru-dps/Aaru.Helpers - true - en-US - true - true - snupkg - Natalia Portillo <claunia@claunia.com> - true - - - $(Version)+{chash:8} - true - true - - - true - full - false - bin\Debug\net6 - DEBUG; - prompt - 4 - false - - - full - true - bin\Release\net6 - prompt - 4 - false - - - - - - - - - - - - - - - - - - - - - - - LICENSE.LGPL - - - - - - - - - - - - - - - - - - - - - - /Library/Frameworks/Mono.framework/Versions/Current/lib/mono - /usr/lib/mono - /usr/local/lib/mono - - $(BaseFrameworkPathOverrideForMono)/4.0-api - $(BaseFrameworkPathOverrideForMono)/4.5-api - $(BaseFrameworkPathOverrideForMono)/4.5.1-api - $(BaseFrameworkPathOverrideForMono)/4.5.2-api - $(BaseFrameworkPathOverrideForMono)/4.6-api - $(BaseFrameworkPathOverrideForMono)/4.6.1-api - $(BaseFrameworkPathOverrideForMono)/4.6.2-api - $(BaseFrameworkPathOverrideForMono)/4.7-api - $(BaseFrameworkPathOverrideForMono)/4.7.1-api - true - - $(FrameworkPathOverride)/Facades;$(AssemblySearchPaths) - + + Debug + AnyCPU + 2.0 + {F8BDF57B-1571-4CD0-84B3-B422088D359A} + Library + Aaru.Helpers + Aaru.Helpers + $(Version) + false + true + 6.0.0-alpha8 + Claunia.com + Copyright © 2011-2022 Natalia Portillo + Aaru Data Preservation Suite + Aaru.Helpers + $(Version) + net6 + 10 + Contains helpers used by the Aaru Data Preservation Suite. + https://github.com/aaru-dps/ + LGPL-2.1-only + https://github.com/aaru-dps/Aaru.Helpers + true + en-US + true + true + snupkg + Natalia Portillo <claunia@claunia.com> + true + + + $(Version)+{chash:8} + true + true + + + true + full + false + bin\Debug\net6 + DEBUG; + prompt + 4 + false + + + full + true + bin\Release\net6 + prompt + 4 + false + + + + + + + + + + + + + + + + + + + + + + LICENSE.LGPL + + + + + + + + + + + + + + + + + + + + + + /Library/Frameworks/Mono.framework/Versions/Current/lib/mono + /usr/lib/mono + /usr/local/lib/mono + + $(BaseFrameworkPathOverrideForMono)/4.0-api + $(BaseFrameworkPathOverrideForMono)/4.5-api + $(BaseFrameworkPathOverrideForMono)/4.5.1-api + $(BaseFrameworkPathOverrideForMono)/4.5.2-api + $(BaseFrameworkPathOverrideForMono)/4.6-api + $(BaseFrameworkPathOverrideForMono)/4.6.1-api + $(BaseFrameworkPathOverrideForMono)/4.6.2-api + $(BaseFrameworkPathOverrideForMono)/4.7-api + $(BaseFrameworkPathOverrideForMono)/4.7.1-api + true + + $(FrameworkPathOverride)/Facades;$(AssemblySearchPaths) + \ No newline at end of file diff --git a/ArrayFill.cs b/ArrayFill.cs index 53edd1498..9f3e72206 100644 --- a/ArrayFill.cs +++ b/ArrayFill.cs @@ -24,11 +24,11 @@ // Copyright(C) 2014 mykohsu // ****************************************************************************/ +namespace Aaru.Helpers; + using System; using System.Text; -namespace Aaru.Helpers; - public static partial class ArrayHelpers { /// Fills an array with the specified value diff --git a/ArrayIsEmpty.cs b/ArrayIsEmpty.cs index 93aa33011..07d6ec5da 100644 --- a/ArrayIsEmpty.cs +++ b/ArrayIsEmpty.cs @@ -30,10 +30,10 @@ // Copyright © 2011-2022 Natalia Portillo // ****************************************************************************/ -using System.Linq; - namespace Aaru.Helpers; +using System.Linq; + /// Helper operations to work with arrays public static partial class ArrayHelpers { diff --git a/BigEndianBitConverter.cs b/BigEndianBitConverter.cs index 03cf0add6..4c180a5af 100644 --- a/BigEndianBitConverter.cs +++ b/BigEndianBitConverter.cs @@ -30,11 +30,11 @@ // Copyright © 2011-2022 Natalia Portillo // ****************************************************************************/ +namespace Aaru.Helpers; + using System; using System.Linq; -namespace Aaru.Helpers; - /// /// Converts base data types to an array of bytes, and an array of bytes to base data types. All info taken from /// the meta data of System.BitConverter. This implementation allows for Endianness consideration. @@ -309,15 +309,12 @@ public static ulong ToUInt64(byte[] value, int startIndex) => /// Byte array containing a GUID in big endian /// Start of the byte array to process /// Processed Guid - public static Guid ToGuid(byte[] value, int startIndex) => 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]); + public static Guid ToGuid(byte[] value, int startIndex) => new(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]); } \ No newline at end of file diff --git a/CHS.cs b/CHS.cs index aa58ff396..ad9945014 100644 --- a/CHS.cs +++ b/CHS.cs @@ -43,6 +43,6 @@ public static class CHS /// Number of sectors per track /// public static uint ToLBA(uint cyl, uint head, uint sector, uint maxHead, uint maxSector) => - maxHead == 0 || maxSector == 0 ? (((cyl * 16) + head) * 63) + sector - 1 - : (((cyl * maxHead) + head) * maxSector) + sector - 1; + maxHead == 0 || maxSector == 0 ? (cyl * 16 + head) * 63 + sector - 1 + : (cyl * maxHead + head) * maxSector + sector - 1; } \ No newline at end of file diff --git a/CompareBytes.cs b/CompareBytes.cs index b868d4e2e..b52a6f774 100644 --- a/CompareBytes.cs +++ b/CompareBytes.cs @@ -39,8 +39,7 @@ public static partial class ArrayHelpers /// true if they have the same size /// Left array /// Right array - public static void CompareBytes(out bool different, out bool sameSize, byte[] compareArray1, - byte[] compareArray2) + public static void CompareBytes(out bool different, out bool sameSize, byte[] compareArray1, byte[] compareArray2) { different = false; sameSize = true; diff --git a/DateHandlers.cs b/DateHandlers.cs index 7fc047ce7..3c7ee083f 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -30,21 +30,21 @@ // Copyright © 2011-2022 Natalia Portillo // ****************************************************************************/ +namespace Aaru.Helpers; + using System; using System.Text; using Aaru.Console; -namespace Aaru.Helpers; - /// Helper operations for timestamp management (date and time) 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 _unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0); + static readonly DateTime _lisaEpoch = new(1901, 1, 1, 0, 0, 0); + static readonly DateTime _macEpoch = new(1904, 1, 1, 0, 0, 0); + static readonly DateTime _unixEpoch = new(1970, 1, 1, 0, 0, 0); /// Day 0 of Julian Date system - static readonly DateTime _julianEpoch = new DateTime(1858, 11, 17, 0, 0, 0); - static readonly DateTime _amigaEpoch = new DateTime(1978, 1, 1, 0, 0, 0); + static readonly DateTime _julianEpoch = new(1858, 11, 17, 0, 0, 0); + static readonly DateTime _amigaEpoch = new(1978, 1, 1, 0, 0, 0); /// Converts a Macintosh timestamp to a .NET DateTime /// Macintosh timestamp (seconds since 1st Jan. 1904) @@ -88,7 +88,7 @@ public static DateTime UnixUnsignedToDateTime(uint seconds, uint nanoseconds) => /// .NET DateTime public static DateTime HighSierraToDateTime(byte[] vdDateTime) { - byte[] isoTime = new byte[17]; + var isoTime = new byte[17]; Array.Copy(vdDateTime, 0, isoTime, 0, 16); return Iso9660ToDateTime(isoTime); @@ -100,8 +100,8 @@ public static DateTime HighSierraToDateTime(byte[] vdDateTime) /// .NET DateTime public static DateTime Iso9660ToDateTime(byte[] vdDateTime) { - byte[] twoCharValue = new byte[2]; - byte[] fourCharValue = new byte[4]; + var twoCharValue = new byte[2]; + var fourCharValue = new byte[4]; fourCharValue[0] = vdDateTime[0]; fourCharValue[1] = vdDateTime[1]; @@ -172,7 +172,7 @@ public static DateTime Iso9660ToDateTime(byte[] vdDateTime) "decodedDT = new DateTime({0}, {1}, {2}, {3}, {4}, {5}, {6}, DateTimeKind.Unspecified);", year, month, day, hour, minute, second, hundredths * 10); - sbyte difference = (sbyte)vdDateTime[16]; + var difference = (sbyte)vdDateTime[16]; var decodedDt = new DateTime(year, month, day, hour, minute, second, hundredths * 10, DateTimeKind.Utc); @@ -213,8 +213,8 @@ public static DateTime UcsdPascalToDateTime(short dateRecord) int month = dateRecord & 0x000F; AaruConsole.DebugWriteLine("UCSDPascalToDateTime handler", - "dateRecord = 0x{0:X4}, year = {1}, month = {2}, day = {3}", dateRecord, year, - month, day); + "dateRecord = 0x{0:X4}, year = {1}, month = {2}, day = {3}", dateRecord, year, month, + day); return new DateTime(year, month, day); } @@ -232,12 +232,11 @@ public static DateTime DosToDateTime(ushort date, ushort time) int minute = (time & 0x7E0) >> 5; int second = (time & 0x1F) * 2; - AaruConsole.DebugWriteLine("DOSToDateTime handler", "date = 0x{0:X4}, year = {1}, month = {2}, day = {3}", - date, year, month, day); + AaruConsole.DebugWriteLine("DOSToDateTime handler", "date = 0x{0:X4}, year = {1}, month = {2}, day = {3}", date, + year, month, day); - AaruConsole.DebugWriteLine("DOSToDateTime handler", - "time = 0x{0:X4}, hour = {1}, minute = {2}, second = {3}", time, hour, minute, - second); + AaruConsole.DebugWriteLine("DOSToDateTime handler", "time = 0x{0:X4}, hour = {1}, minute = {2}, second = {3}", + time, hour, minute, second); DateTime dosDate; @@ -258,9 +257,9 @@ public static DateTime DosToDateTime(ushort date, ushort time) /// .NET DateTime public static DateTime CpmToDateTime(byte[] timestamp) { - ushort days = BitConverter.ToUInt16(timestamp, 0); - int hours = timestamp[2]; - int minutes = timestamp[3]; + var days = BitConverter.ToUInt16(timestamp, 0); + int hours = timestamp[2]; + int minutes = timestamp[3]; DateTime temp = _amigaEpoch.AddDays(days); temp = temp.AddHours(hours); @@ -285,16 +284,15 @@ public static DateTime EcmaToDateTime(ushort typeAndTimeZone, short year, byte m byte minute, byte second, byte centiseconds, byte hundredsOfMicroseconds, byte microseconds) { - byte specification = (byte)((typeAndTimeZone & 0xF000) >> 12); + var 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; + var preOffset = (ushort)(typeAndTimeZone & 0xFFF); + short offset; if((preOffset & 0x800) == 0x800) offset = (short)(preOffset | 0xF000); @@ -308,15 +306,14 @@ public static DateTime EcmaToDateTime(ushort typeAndTimeZone, short year, byte m offset > 1440) offset = 0; - return new DateTimeOffset(year, month, day, hour, minute, second, new TimeSpan(0, offset, 0)). - AddTicks(ticks).DateTime; + return new DateTimeOffset(year, month, day, hour, minute, second, new TimeSpan(0, offset, 0)).AddTicks(ticks). + DateTime; } /// Converts a Solaris high resolution timestamp to .NET DateTime /// Solaris high resolution timestamp /// .NET DateTime - public static DateTime UnixHrTimeToDateTime(ulong hrTimeStamp) => - _unixEpoch.AddTicks((long)(hrTimeStamp / 100)); + public static DateTime UnixHrTimeToDateTime(ulong hrTimeStamp) => _unixEpoch.AddTicks((long)(hrTimeStamp / 100)); /// Converts an OS-9 timestamp to .NET DateTime /// OS-9 timestamp @@ -324,7 +321,7 @@ public static DateTime UnixHrTimeToDateTime(ulong hrTimeStamp) => public static DateTime Os9ToDateTime(byte[] date) { if(date == null || - (date.Length != 3 && date.Length != 5)) + date.Length != 3 && date.Length != 5) return DateTime.MinValue; DateTime os9Date; @@ -366,12 +363,12 @@ public static DateTime LifToDateTime(byte year, byte month, byte day, byte hour, { try { - 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 isecond = ((second >> 4) * 10) + (second & 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 isecond = (second >> 4) * 10 + (second & 0xF); if(iyear >= 70) iyear += 1900; diff --git a/Marshal.cs b/Marshal.cs index 8a1c3bf6b..bdb31c793 100644 --- a/Marshal.cs +++ b/Marshal.cs @@ -30,14 +30,14 @@ // Copyright © 2011-2022 Natalia Portillo // ****************************************************************************/ +namespace Aaru.Helpers; + using System; using System.Diagnostics.CodeAnalysis; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -namespace Aaru.Helpers; - /// Provides methods to marshal binary data into C# structs public static class Marshal { @@ -117,8 +117,7 @@ public static T ByteArrayToStructurePdpEndian(byte[] bytes) where T : struct { var ptr = GCHandle.Alloc(bytes, GCHandleType.Pinned); - object str = - (T)System.Runtime.InteropServices.Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(T)); + object str = (T)System.Runtime.InteropServices.Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(T)); ptr.Free(); @@ -161,8 +160,8 @@ public static T SpanToStructureLittleEndian(ReadOnlySpan bytes) where T /// Type of the structure to marshal /// The binary data marshalled in a structure with the specified type [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static T SpanToStructureLittleEndian(ReadOnlySpan bytes, int start, int length) - where T : struct => MemoryMarshal.Read(bytes.Slice(start, length)); + public static T SpanToStructureLittleEndian(ReadOnlySpan bytes, int start, int length) where T : struct => + MemoryMarshal.Read(bytes.Slice(start, length)); /// /// Marshal big-endian binary data to a structure. If the structure type contains any non value type, this method @@ -274,22 +273,22 @@ public static object SwapStructureMembersEndian(object str) foreach(FieldInfo fi in fieldInfo) if(fi.FieldType == typeof(short) || - (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(short))) + fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(short)) { - short x = (short)fi.GetValue(str); + var x = (short)fi.GetValue(str); fi.SetValue(str, (short)((x << 8) | ((x >> 8) & 0xFF))); } else if(fi.FieldType == typeof(int) || - (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(int))) + fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(int)) { - int x = (int)fi.GetValue(str); + var x = (int)fi.GetValue(str); x = (int)(((x << 8) & 0xFF00FF00) | (((uint)x >> 8) & 0xFF00FF)); fi.SetValue(str, (int)(((uint)x << 16) | (((uint)x >> 16) & 0xFFFF))); } else if(fi.FieldType == typeof(long) || - (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(long))) + fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(long)) { - long x = (long)fi.GetValue(str); + var x = (long)fi.GetValue(str); x = ((x & 0x00000000FFFFFFFF) << 32) | (long)(((ulong)x & 0xFFFFFFFF00000000) >> 32); x = ((x & 0x0000FFFF0000FFFF) << 16) | (long)(((ulong)x & 0xFFFF0000FFFF0000) >> 16); x = ((x & 0x00FF00FF00FF00FF) << 8) | (long)(((ulong)x & 0xFF00FF00FF00FF00) >> 8); @@ -297,22 +296,22 @@ public static object SwapStructureMembersEndian(object str) fi.SetValue(str, x); } else if(fi.FieldType == typeof(ushort) || - (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(ushort))) + fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(ushort)) { - ushort x = (ushort)fi.GetValue(str); + var x = (ushort)fi.GetValue(str); fi.SetValue(str, (ushort)((x << 8) | (x >> 8))); } else if(fi.FieldType == typeof(uint) || - (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(uint))) + fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(uint)) { - uint x = (uint)fi.GetValue(str); + var x = (uint)fi.GetValue(str); x = ((x << 8) & 0xFF00FF00) | ((x >> 8) & 0xFF00FF); fi.SetValue(str, (x << 16) | (x >> 16)); } else if(fi.FieldType == typeof(ulong) || - (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(ulong))) + fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(ulong)) { - ulong x = (ulong)fi.GetValue(str); + var x = (ulong)fi.GetValue(str); x = ((x & 0x00000000FFFFFFFF) << 32) | ((x & 0xFFFFFFFF00000000) >> 32); x = ((x & 0x0000FFFF0000FFFF) << 16) | ((x & 0xFFFF0000FFFF0000) >> 16); x = ((x & 0x00FF00FF00FF00FF) << 8) | ((x & 0xFF00FF00FF00FF00) >> 8); @@ -320,7 +319,7 @@ public static object SwapStructureMembersEndian(object str) } else if(fi.FieldType == typeof(float)) { - float flt = (float)fi.GetValue(str); + var flt = (float)fi.GetValue(str); byte[] flt_b = BitConverter.GetBytes(flt); fi.SetValue(str, BitConverter.ToSingle(new[] @@ -330,7 +329,7 @@ public static object SwapStructureMembersEndian(object str) } else if(fi.FieldType == typeof(double)) { - double dbl = (double)fi.GetValue(str); + var dbl = (double)fi.GetValue(str); byte[] dbl_b = BitConverter.GetBytes(dbl); fi.SetValue(str, BitConverter.ToDouble(new[] @@ -384,15 +383,15 @@ public static object SwapStructureMembersEndianPdp(object str) // Do nothing } else if(fi.FieldType == typeof(int) || - (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(int))) + fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(int)) { - int x = (int)fi.GetValue(str); + var x = (int)fi.GetValue(str); fi.SetValue(str, ((x & 0xffffu) << 16) | ((x & 0xffff0000u) >> 16)); } else if(fi.FieldType == typeof(uint) || - (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(uint))) + fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(uint)) { - uint x = (uint)fi.GetValue(str); + var x = (uint)fi.GetValue(str); fi.SetValue(str, ((x & 0xffffu) << 16) | ((x & 0xffff0000u) >> 16)); } @@ -416,8 +415,8 @@ public static object SwapStructureMembersEndianPdp(object str) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static byte[] StructureToByteArrayLittleEndian(T str) where T : struct { - byte[] buf = new byte[SizeOf()]; - var ptr = GCHandle.Alloc(buf, GCHandleType.Pinned); + var buf = new byte[SizeOf()]; + var ptr = GCHandle.Alloc(buf, GCHandleType.Pinned); System.Runtime.InteropServices.Marshal.StructureToPtr(str, ptr.AddrOfPinnedObject(), false); ptr.Free(); @@ -444,24 +443,22 @@ public static int ConvertFromHexAscii(string hex, out byte[] outBuf) hex == "") return -1; - int off = 0; + var off = 0; if(hex[0] == '0' && (hex[1] == 'x' || hex[1] == 'X')) - { off = 2; - } outBuf = new byte[(hex.Length - off) / 2]; - int count = 0; + var count = 0; for(int i = off; i < hex.Length; i += 2) { char c = hex[i]; - if(c < '0' || - (c > '9' && c < 'A') || - (c > 'F' && c < 'a') || + if(c < '0' || + c > '9' && c < 'A' || + c > 'F' && c < 'a' || c > 'f') break; @@ -475,9 +472,9 @@ public static int ConvertFromHexAscii(string hex, out byte[] outBuf) c = hex[i + 1]; - if(c < '0' || - (c > '9' && c < 'A') || - (c > 'F' && c < 'a') || + if(c < '0' || + c > '9' && c < 'A' || + c > 'F' && c < 'a' || c > 'f') break; diff --git a/MarshallingPropertiesAttribute.cs b/MarshallingPropertiesAttribute.cs index bb9f7c35c..ac96c2592 100644 --- a/MarshallingPropertiesAttribute.cs +++ b/MarshallingPropertiesAttribute.cs @@ -36,10 +36,10 @@ // Copyright © 2011-2022 Natalia Portillo // ****************************************************************************/ -using System; - namespace Aaru.Helpers; +using System; + /// /// Defines properties to help marshalling structs from binary data [AttributeUsage(AttributeTargets.Struct)] diff --git a/PrintHex.cs b/PrintHex.cs index 85476c8a9..3046fa553 100644 --- a/PrintHex.cs +++ b/PrintHex.cs @@ -30,11 +30,11 @@ // Copyright © 2011-2022 Natalia Portillo // ****************************************************************************/ +namespace Aaru.Helpers; + using System.Text; using Aaru.Console; -namespace Aaru.Helpers; - /// Helper operations to get hexadecimal representations of byte arrays public static class PrintHex { @@ -56,11 +56,11 @@ public static string ByteArrayToHexArrayString(byte[] array, int width = 16, boo // TODO: Color list // TODO: Allow to change width - string str = "Offset"; - int rows = array.Length / 16; - int last = array.Length % 16; - int offsetLength = $"{array.Length:X}".Length; - var sb = new StringBuilder(); + var str = "Offset"; + int rows = array.Length / 16; + int last = array.Length % 16; + int offsetLength = $"{array.Length:X}".Length; + var sb = new StringBuilder(); if(last > 0) rows++; @@ -80,21 +80,19 @@ public static string ByteArrayToHexArrayString(byte[] array, int width = 16, boo sb.Append(str); sb.Append(" "); - for(int i = 0; i < 16; i++) - { + for(var i = 0; i < 16; i++) sb.AppendFormat(" {0:X2}", i); - } if(color) sb.Append("\u001b[0m"); sb.AppendLine(); - int b = 0; + var b = 0; string format = $"{{0:X{offsetLength}}}"; - for(int i = 0; i < rows; i++) + for(var i = 0; i < rows; i++) { if(color) sb.Append("\u001b[36m"); @@ -108,22 +106,22 @@ public static string ByteArrayToHexArrayString(byte[] array, int width = 16, boo int lastBytes = i == rows - 1 ? last : 16; int lastSpaces = 16 - lastBytes; - for(int j = 0; j < lastBytes; j++) + for(var j = 0; j < lastBytes; j++) { sb.AppendFormat(" {0:X2}", array[b]); b++; } - for(int j = 0; j < lastSpaces; j++) + for(var j = 0; j < lastSpaces; j++) sb.Append(" "); b -= lastBytes; sb.Append(" "); - for(int j = 0; j < lastBytes; j++) + for(var j = 0; j < lastBytes; j++) { int v = array[b]; - sb.Append((v > 31 && v < 127) || v > 159 ? (char)v : '.'); + sb.Append(v > 31 && v < 127 || v > 159 ? (char)v : '.'); b++; } diff --git a/StringHandlers.cs b/StringHandlers.cs index 21a877560..ca316fd17 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -30,11 +30,11 @@ // Copyright © 2011-2022 Natalia Portillo // ****************************************************************************/ +namespace Aaru.Helpers; + using System; using System.Text; -namespace Aaru.Helpers; - /// Helper operations to work with strings public static class StringHandlers { @@ -54,7 +54,7 @@ public static string CToString(byte[] cString, Encoding encoding, bool twoBytes if(cString == null) return null; - int len = 0; + var len = 0; for(int i = start; i < cString.Length; i++) { @@ -78,7 +78,7 @@ public static string CToString(byte[] cString, Encoding encoding, bool twoBytes if(twoBytes && len % 2 > 0) len--; - byte[] dest = new byte[len]; + var dest = new byte[len]; Array.Copy(cString, start, dest, 0, len); return len == 0 ? "" : encoding.GetString(dest); @@ -100,7 +100,7 @@ public static string PascalToString(byte[] pascalString, Encoding encoding, int return null; byte length = pascalString[start]; - int len = 0; + var len = 0; for(int i = start + 1; i < length + 1 && i < pascalString.Length; i++) { @@ -110,7 +110,7 @@ public static string PascalToString(byte[] pascalString, Encoding encoding, int len++; } - byte[] dest = new byte[len]; + var dest = new byte[len]; Array.Copy(pascalString, start + 1, dest, 0, len); return len == 0 ? "" : encoding.GetString(dest); @@ -157,13 +157,13 @@ public static string DecompressUnicode(byte[] dstring) { ushort unicode; byte compId = dstring[0]; - string temp = ""; + var temp = ""; if(compId != 8 && compId != 16) return null; - for(int byteIndex = 1; byteIndex < dstring.Length;) + for(var byteIndex = 1; byteIndex < dstring.Length;) { if(compId == 16) unicode = (ushort)(dstring[byteIndex++] << 8); diff --git a/Swapping.cs b/Swapping.cs index 3bc76eefc..cf713265a 100644 --- a/Swapping.cs +++ b/Swapping.cs @@ -30,10 +30,10 @@ // Copyright © 2011-2022 Natalia Portillo // ****************************************************************************/ -using System.Runtime.CompilerServices; - namespace Aaru.Helpers; +using System.Runtime.CompilerServices; + /// Helper operations to work with swapping endians public static class Swapping { From 0462eaac5ef31084ca7c031858caeae358adcb42 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 16 Mar 2022 11:47:00 +0000 Subject: [PATCH 171/217] Use merge pattern. --- ArrayIsEmpty.cs | 2 +- DateHandlers.cs | 3 +-- Marshal.cs | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/ArrayIsEmpty.cs b/ArrayIsEmpty.cs index 07d6ec5da..7df593cf6 100644 --- a/ArrayIsEmpty.cs +++ b/ArrayIsEmpty.cs @@ -40,7 +40,7 @@ public static partial class ArrayHelpers /// Checks if an array is null, filled with the NULL byte (0x00) or ASCII whitespace (0x20) /// Array /// True if null or whitespace - public static bool ArrayIsNullOrWhiteSpace(byte[] array) => array?.All(b => b == 0x00 || b == 0x20) != false; + public static bool ArrayIsNullOrWhiteSpace(byte[] array) => array?.All(b => b is 0x00 or 0x20) != false; /// Checks if an array is null or filled with the NULL byte (0x00) /// Array diff --git a/DateHandlers.cs b/DateHandlers.cs index 3c7ee083f..9925a16b9 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -302,8 +302,7 @@ public static DateTime EcmaToDateTime(ushort typeAndTimeZone, short year, byte m if(offset == -2047) return new DateTime(year, month, day, hour, minute, second, DateTimeKind.Unspecified).AddTicks(ticks); - if(offset < -1440 || - offset > 1440) + if(offset is < -1440 or > 1440) offset = 0; return new DateTimeOffset(year, month, day, hour, minute, second, new TimeSpan(0, offset, 0)).AddTicks(ticks). diff --git a/Marshal.cs b/Marshal.cs index bdb31c793..28ba11214 100644 --- a/Marshal.cs +++ b/Marshal.cs @@ -439,8 +439,7 @@ public static int ConvertFromHexAscii(string hex, out byte[] outBuf) { outBuf = null; - if(hex is null || - hex == "") + if(hex is null or "") return -1; var off = 0; From af338014d5ccc4c008de4bfc927aa78952dda752 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 17 Mar 2022 00:46:26 +0000 Subject: [PATCH 172/217] Add null reference checks. --- Marshal.cs | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/Marshal.cs b/Marshal.cs index 28ba11214..49a8651ef 100644 --- a/Marshal.cs +++ b/Marshal.cs @@ -56,7 +56,8 @@ public static T ByteArrayToStructureLittleEndian(byte[] bytes) where T : stru { var ptr = GCHandle.Alloc(bytes, GCHandleType.Pinned); - var str = (T)System.Runtime.InteropServices.Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(T)); + var str = (T)(System.Runtime.InteropServices.Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(T)) ?? + default(T)); ptr.Free(); @@ -86,7 +87,8 @@ public static T ByteArrayToStructureBigEndian(byte[] bytes) where T : struct { var ptr = GCHandle.Alloc(bytes, GCHandleType.Pinned); - object str = (T)System.Runtime.InteropServices.Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(T)); + object str = (T)(System.Runtime.InteropServices.Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(T)) ?? + default(T)); ptr.Free(); @@ -117,7 +119,9 @@ public static T ByteArrayToStructurePdpEndian(byte[] bytes) where T : struct { var ptr = GCHandle.Alloc(bytes, GCHandleType.Pinned); - object str = (T)System.Runtime.InteropServices.Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(T)); + object str = + (T)(System.Runtime.InteropServices.Marshal.PtrToStructure(ptr.AddrOfPinnedObject(), typeof(T)) ?? + default(T)); ptr.Free(); @@ -275,20 +279,20 @@ public static object SwapStructureMembersEndian(object str) if(fi.FieldType == typeof(short) || fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(short)) { - var x = (short)fi.GetValue(str); + var x = (short)(fi.GetValue(str) ?? default(short)); fi.SetValue(str, (short)((x << 8) | ((x >> 8) & 0xFF))); } else if(fi.FieldType == typeof(int) || fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(int)) { - var x = (int)fi.GetValue(str); + var x = (int)(fi.GetValue(str) ?? default(int)); x = (int)(((x << 8) & 0xFF00FF00) | (((uint)x >> 8) & 0xFF00FF)); fi.SetValue(str, (int)(((uint)x << 16) | (((uint)x >> 16) & 0xFFFF))); } else if(fi.FieldType == typeof(long) || fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(long)) { - var x = (long)fi.GetValue(str); + var x = (long)(fi.GetValue(str) ?? default(long)); x = ((x & 0x00000000FFFFFFFF) << 32) | (long)(((ulong)x & 0xFFFFFFFF00000000) >> 32); x = ((x & 0x0000FFFF0000FFFF) << 16) | (long)(((ulong)x & 0xFFFF0000FFFF0000) >> 16); x = ((x & 0x00FF00FF00FF00FF) << 8) | (long)(((ulong)x & 0xFF00FF00FF00FF00) >> 8); @@ -298,20 +302,20 @@ public static object SwapStructureMembersEndian(object str) else if(fi.FieldType == typeof(ushort) || fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(ushort)) { - var x = (ushort)fi.GetValue(str); + var x = (ushort)(fi.GetValue(str) ?? default(ushort)); fi.SetValue(str, (ushort)((x << 8) | (x >> 8))); } else if(fi.FieldType == typeof(uint) || fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(uint)) { - var x = (uint)fi.GetValue(str); + var x = (uint)(fi.GetValue(str) ?? default(uint)); x = ((x << 8) & 0xFF00FF00) | ((x >> 8) & 0xFF00FF); fi.SetValue(str, (x << 16) | (x >> 16)); } else if(fi.FieldType == typeof(ulong) || fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(ulong)) { - var x = (ulong)fi.GetValue(str); + var x = (ulong)(fi.GetValue(str) ?? default(ulong)); x = ((x & 0x00000000FFFFFFFF) << 32) | ((x & 0xFFFFFFFF00000000) >> 32); x = ((x & 0x0000FFFF0000FFFF) << 16) | ((x & 0xFFFF0000FFFF0000) >> 16); x = ((x & 0x00FF00FF00FF00FF) << 8) | ((x & 0xFF00FF00FF00FF00) >> 8); @@ -319,7 +323,7 @@ public static object SwapStructureMembersEndian(object str) } else if(fi.FieldType == typeof(float)) { - var flt = (float)fi.GetValue(str); + var flt = (float)(fi.GetValue(str) ?? default(float)); byte[] flt_b = BitConverter.GetBytes(flt); fi.SetValue(str, BitConverter.ToSingle(new[] @@ -329,7 +333,7 @@ public static object SwapStructureMembersEndian(object str) } else if(fi.FieldType == typeof(double)) { - var dbl = (double)fi.GetValue(str); + var dbl = (double)(fi.GetValue(str) ?? default(double)); byte[] dbl_b = BitConverter.GetBytes(dbl); fi.SetValue(str, BitConverter.ToDouble(new[] @@ -385,13 +389,13 @@ public static object SwapStructureMembersEndianPdp(object str) else if(fi.FieldType == typeof(int) || fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(int)) { - var x = (int)fi.GetValue(str); + var x = (int)(fi.GetValue(str) ?? default(int)); fi.SetValue(str, ((x & 0xffffu) << 16) | ((x & 0xffff0000u) >> 16)); } else if(fi.FieldType == typeof(uint) || fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(uint)) { - var x = (uint)fi.GetValue(str); + var x = (uint)(fi.GetValue(str) ?? default(uint)); fi.SetValue(str, ((x & 0xffffu) << 16) | ((x & 0xffff0000u) >> 16)); } From ccdf48ec0a7a3a416befaed06872cdab63cef48b Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 18 Apr 2022 09:45:18 +0100 Subject: [PATCH 173/217] Fix .NET 6 TFM. --- Aaru.Helpers.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index a94b4377d..389890434 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -17,7 +17,7 @@ Aaru Data Preservation Suite Aaru.Helpers $(Version) - net6 + net6.0 10 Contains helpers used by the Aaru Data Preservation Suite. https://github.com/aaru-dps/ From 248a808e4960162208889ce7d1abec1eea44781e Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 18 Apr 2022 12:34:34 +0100 Subject: [PATCH 174/217] Remove net6 string from output path. --- Aaru.Helpers.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index 389890434..593f15c24 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -40,7 +40,7 @@ true full false - bin\Debug\net6 + bin\Debug DEBUG; prompt 4 @@ -49,7 +49,7 @@ full true - bin\Release\net6 + bin\Release prompt 4 false From 118563e086fa2c8234a3c95f586fde090e8eee6a Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 12 Oct 2022 14:18:38 +0100 Subject: [PATCH 175/217] Fix printhex helper ignoring width parameter. --- PrintHex.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/PrintHex.cs b/PrintHex.cs index 3046fa553..999be0225 100644 --- a/PrintHex.cs +++ b/PrintHex.cs @@ -57,8 +57,8 @@ public static string ByteArrayToHexArrayString(byte[] array, int width = 16, boo // TODO: Color list // TODO: Allow to change width var str = "Offset"; - int rows = array.Length / 16; - int last = array.Length % 16; + int rows = array.Length / width; + int last = array.Length % width; int offsetLength = $"{array.Length:X}".Length; var sb = new StringBuilder(); @@ -66,7 +66,7 @@ public static string ByteArrayToHexArrayString(byte[] array, int width = 16, boo rows++; if(last == 0) - last = 16; + last = width; if(offsetLength < str.Length) offsetLength = str.Length; @@ -80,7 +80,7 @@ public static string ByteArrayToHexArrayString(byte[] array, int width = 16, boo sb.Append(str); sb.Append(" "); - for(var i = 0; i < 16; i++) + for(var i = 0; i < width; i++) sb.AppendFormat(" {0:X2}", i); if(color) @@ -103,8 +103,8 @@ public static string ByteArrayToHexArrayString(byte[] array, int width = 16, boo sb.Append("\u001b[0m"); sb.Append(" "); - int lastBytes = i == rows - 1 ? last : 16; - int lastSpaces = 16 - lastBytes; + int lastBytes = i == rows - 1 ? last : width; + int lastSpaces = width - lastBytes; for(var j = 0; j < lastBytes; j++) { @@ -121,7 +121,7 @@ public static string ByteArrayToHexArrayString(byte[] array, int width = 16, boo for(var j = 0; j < lastBytes; j++) { int v = array[b]; - sb.Append(v > 31 && v < 127 || v > 159 ? (char)v : '.'); + sb.Append(v is > 31 and < 127 or > 159 ? (char)v : '.'); b++; } From 3953606644318dd314c79c154d63b67a98f8871b Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 13 Nov 2022 12:46:18 +0000 Subject: [PATCH 176/217] Bump framework to .NET 7 --- Aaru.Helpers.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index 593f15c24..1af7b2b71 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -17,7 +17,7 @@ Aaru Data Preservation Suite Aaru.Helpers $(Version) - net6.0 + net7.0 10 Contains helpers used by the Aaru Data Preservation Suite. https://github.com/aaru-dps/ From 3cbe3c075383d0c67b8991ea1236a792c642a0c9 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 13 Nov 2022 12:48:41 +0000 Subject: [PATCH 177/217] Bump C# to 11.0. --- Aaru.Helpers.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index 1af7b2b71..254761f0a 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -18,7 +18,7 @@ Aaru.Helpers $(Version) net7.0 - 10 + 11 Contains helpers used by the Aaru Data Preservation Suite. https://github.com/aaru-dps/ LGPL-2.1-only From 4cf36f4cc78254ef121c955b19f36a7e4e2c339d Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 13 Nov 2022 12:58:36 +0000 Subject: [PATCH 178/217] Remove archaic unused MonoDevelop project extensions. --- Aaru.Helpers.csproj | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index 254761f0a..62701d375 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -81,17 +81,6 @@ - - - - - - - - - - - From 504391f37313675f71d8721502223dec46289cee Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 13 Nov 2022 13:08:18 +0000 Subject: [PATCH 179/217] Remove .NET Framework building conditions. --- Aaru.Helpers.csproj | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index 62701d375..f8fd1b621 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -81,25 +81,4 @@ - - - - - /Library/Frameworks/Mono.framework/Versions/Current/lib/mono - /usr/lib/mono - /usr/local/lib/mono - - $(BaseFrameworkPathOverrideForMono)/4.0-api - $(BaseFrameworkPathOverrideForMono)/4.5-api - $(BaseFrameworkPathOverrideForMono)/4.5.1-api - $(BaseFrameworkPathOverrideForMono)/4.5.2-api - $(BaseFrameworkPathOverrideForMono)/4.6-api - $(BaseFrameworkPathOverrideForMono)/4.6.1-api - $(BaseFrameworkPathOverrideForMono)/4.6.2-api - $(BaseFrameworkPathOverrideForMono)/4.7-api - $(BaseFrameworkPathOverrideForMono)/4.7.1-api - true - - $(FrameworkPathOverride)/Facades;$(AssemblySearchPaths) - \ No newline at end of file From ef97c835d825167daed02fe37e017431fdb5d28e Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 13 Nov 2022 13:19:56 +0000 Subject: [PATCH 180/217] Ignore XML comment warnings when building in DEBUG. --- Aaru.Helpers.csproj | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index f8fd1b621..15e50f665 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -31,6 +31,9 @@ Natalia Portillo <claunia@claunia.com> true + + CS1591;CS1574 + $(Version)+{chash:8} true From e5c3cb73be28fb2e8df7215fe548fd538541994f Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 13 Nov 2022 13:32:01 +0000 Subject: [PATCH 181/217] Remove output configuration from projects. --- Aaru.Helpers.csproj | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index 15e50f665..a8350c658 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -39,24 +39,6 @@ true true - - true - full - false - bin\Debug - DEBUG; - prompt - 4 - false - - - full - true - bin\Release - prompt - 4 - false - From e0faab484688089c1f82d6f3ee0c144497a43dc1 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 13 Nov 2022 13:38:04 +0000 Subject: [PATCH 182/217] Remove useless parameters in projects. --- Aaru.Helpers.csproj | 2 -- 1 file changed, 2 deletions(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index a8350c658..8b78c5d89 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -1,8 +1,6 @@  - Debug - AnyCPU 2.0 {F8BDF57B-1571-4CD0-84B3-B422088D359A} Library From 11fbaecdf35641d0ed83dbd57a04b6e09d36c916 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 13 Nov 2022 13:44:46 +0000 Subject: [PATCH 183/217] Fix XML validity of projects. --- Aaru.Helpers.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index 8b78c5d89..0fa0d425b 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -53,7 +53,7 @@ - + From 8926cec1665b45552ab01269917b794b7df62cd4 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 13 Nov 2022 14:35:49 +0000 Subject: [PATCH 184/217] Update system dependencies. --- Aaru.Helpers.csproj | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index 0fa0d425b..0a8498451 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -38,22 +38,22 @@ true - - - - - - - - - - - - - + + + + + + + + + + + + + - + @@ -61,7 +61,7 @@ - - + + \ No newline at end of file From b87ca30d971cfd332ea6178264b9d6ecbf2da46c Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 13 Nov 2022 14:50:26 +0000 Subject: [PATCH 185/217] Update dependencies. --- Aaru.Helpers.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index 0a8498451..193830b12 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -62,6 +62,6 @@ - + \ No newline at end of file From c9514f169fc9595793a5530965f34568c02c9b4b Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 13 Nov 2022 16:38:17 +0000 Subject: [PATCH 186/217] Make classes visible to tests. --- Aaru.Helpers.csproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index 193830b12..d74cd32f5 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -32,6 +32,10 @@ CS1591;CS1574 + + + + $(Version)+{chash:8} true From 70e03d4efbe416e87420aa22435f194295fe2cec Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 13 Nov 2022 17:13:09 +0000 Subject: [PATCH 187/217] Enable trim analyzer. --- Aaru.Helpers.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index d74cd32f5..e4eecd899 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -28,6 +28,7 @@ snupkg Natalia Portillo <claunia@claunia.com> true + true CS1591;CS1574 From c1196f636d12431c3c3637cffa7a3b2585ed9a7a Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 13 Nov 2022 19:16:13 +0000 Subject: [PATCH 188/217] Move declaration closer to usage. --- StringHandlers.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/StringHandlers.cs b/StringHandlers.cs index ca316fd17..d00e1e089 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -155,7 +155,6 @@ public static string SpacePaddedToString(byte[] spacePaddedString, Encoding enco /// OSTA compressed unicode byte array. public static string DecompressUnicode(byte[] dstring) { - ushort unicode; byte compId = dstring[0]; var temp = ""; @@ -165,6 +164,8 @@ public static string DecompressUnicode(byte[] dstring) for(var byteIndex = 1; byteIndex < dstring.Length;) { + ushort unicode; + if(compId == 16) unicode = (ushort)(dstring[byteIndex++] << 8); else From cd2d27c2cfe5db9974bdd35f8488833cbb2d03f8 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 13 Nov 2022 19:38:02 +0000 Subject: [PATCH 189/217] Convert if to switch statement. --- DateHandlers.cs | 12 ++++++++---- PrintHex.cs | 14 ++++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/DateHandlers.cs b/DateHandlers.cs index 9925a16b9..af21162d6 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -299,11 +299,15 @@ public static DateTime EcmaToDateTime(ushort typeAndTimeZone, short year, byte m else offset = (short)(preOffset & 0x7FF); - if(offset == -2047) - return new DateTime(year, month, day, hour, minute, second, DateTimeKind.Unspecified).AddTicks(ticks); + switch(offset) + { + case -2047: + return new DateTime(year, month, day, hour, minute, second, DateTimeKind.Unspecified).AddTicks(ticks); + case < -1440 or > 1440: + offset = 0; - if(offset is < -1440 or > 1440) - offset = 0; + break; + } return new DateTimeOffset(year, month, day, hour, minute, second, new TimeSpan(0, offset, 0)).AddTicks(ticks). DateTime; diff --git a/PrintHex.cs b/PrintHex.cs index 999be0225..0d193e95a 100644 --- a/PrintHex.cs +++ b/PrintHex.cs @@ -62,11 +62,17 @@ public static string ByteArrayToHexArrayString(byte[] array, int width = 16, boo int offsetLength = $"{array.Length:X}".Length; var sb = new StringBuilder(); - if(last > 0) - rows++; + switch(last) + { + case > 0: + rows++; + + break; + case 0: + last = width; - if(last == 0) - last = width; + break; + } if(offsetLength < str.Length) offsetLength = str.Length; From 98f08919d6b06ce0240843ddd7c984fcfd44711c Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 13 Nov 2022 19:59:23 +0000 Subject: [PATCH 190/217] Convert to switch expression. --- Marshal.cs | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/Marshal.cs b/Marshal.cs index 49a8651ef..6611d97ca 100644 --- a/Marshal.cs +++ b/Marshal.cs @@ -249,21 +249,16 @@ public static T MarshalStructure(byte[] bytes) where T : struct properties)) return ByteArrayToStructureLittleEndian(bytes); - switch(properties.Endian) - { - case BitEndian.Little: - return properties.HasReferences ? ByteArrayToStructureLittleEndian(bytes) - : SpanToStructureLittleEndian(bytes); - - case BitEndian.Big: - return properties.HasReferences ? ByteArrayToStructureBigEndian(bytes) - : SpanToStructureBigEndian(bytes); - - case BitEndian.Pdp: - return properties.HasReferences ? ByteArrayToStructurePdpEndian(bytes) - : SpanToStructurePdpEndian(bytes); - default: throw new ArgumentOutOfRangeException(); - } + return properties.Endian switch + { + BitEndian.Little => properties.HasReferences ? ByteArrayToStructureLittleEndian(bytes) + : SpanToStructureLittleEndian(bytes), + BitEndian.Big => properties.HasReferences ? ByteArrayToStructureBigEndian(bytes) + : SpanToStructureBigEndian(bytes), + BitEndian.Pdp => properties.HasReferences ? ByteArrayToStructurePdpEndian(bytes) + : SpanToStructurePdpEndian(bytes), + _ => throw new ArgumentOutOfRangeException() + }; } /// Swaps all members of a structure From 7fbeaebfd3564d26268fecb9f85d0a41bf6ebf65 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 13 Nov 2022 20:46:23 +0000 Subject: [PATCH 191/217] Merge null/pattern checks into complex pattern. --- Marshal.cs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Marshal.cs b/Marshal.cs index 6611d97ca..cca9efb27 100644 --- a/Marshal.cs +++ b/Marshal.cs @@ -454,15 +454,15 @@ public static int ConvertFromHexAscii(string hex, out byte[] outBuf) { char c = hex[i]; - if(c < '0' || - c > '9' && c < 'A' || - c > 'F' && c < 'a' || + if(c < '0' || + c is > '9' and < 'A' || + c is > 'F' and < 'a' || c > 'f') break; - c -= c >= 'a' && c <= 'f' + c -= c is >= 'a' and <= 'f' ? '\u0057' - : c >= 'A' && c <= 'F' + : c is >= 'A' and <= 'F' ? '\u0037' : '\u0030'; @@ -470,15 +470,15 @@ public static int ConvertFromHexAscii(string hex, out byte[] outBuf) c = hex[i + 1]; - if(c < '0' || - c > '9' && c < 'A' || - c > 'F' && c < 'a' || + if(c < '0' || + c is > '9' and < 'A' || + c is > 'F' and < 'a' || c > 'f') break; - c -= c >= 'a' && c <= 'f' + c -= c is >= 'a' and <= 'f' ? '\u0057' - : c >= 'A' && c <= 'F' + : c is >= 'A' and <= 'F' ? '\u0037' : '\u0030'; From a17a6e1788b4ef7395dcb17c6ab744d13e56c65d Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 14 Nov 2022 01:06:06 +0000 Subject: [PATCH 192/217] Convert chain of conditional expressions into switch expressions. --- Marshal.cs | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/Marshal.cs b/Marshal.cs index cca9efb27..64ee7be3f 100644 --- a/Marshal.cs +++ b/Marshal.cs @@ -454,33 +454,29 @@ public static int ConvertFromHexAscii(string hex, out byte[] outBuf) { char c = hex[i]; - if(c < '0' || - c is > '9' and < 'A' || - c is > 'F' and < 'a' || - c > 'f') + if(c is < '0' or > '9' and < 'A' or > 'F' and < 'a' or > 'f') break; - c -= c is >= 'a' and <= 'f' - ? '\u0057' - : c is >= 'A' and <= 'F' - ? '\u0037' - : '\u0030'; + c -= c switch + { + >= 'a' and <= 'f' => '\u0057', + >= 'A' and <= 'F' => '\u0037', + _ => '\u0030' + }; outBuf[(i - off) / 2] = (byte)(c << 4); c = hex[i + 1]; - if(c < '0' || - c is > '9' and < 'A' || - c is > 'F' and < 'a' || - c > 'f') + if(c is < '0' or > '9' and < 'A' or > 'F' and < 'a' or > 'f') break; - c -= c is >= 'a' and <= 'f' - ? '\u0057' - : c is >= 'A' and <= 'F' - ? '\u0037' - : '\u0030'; + c -= c switch + { + >= 'a' and <= 'f' => '\u0057', + >= 'A' and <= 'F' => '\u0037', + _ => '\u0030' + }; outBuf[(i - off) / 2] += (byte)c; From c2878f9a42b85dc7894dcacad0e86e54b23680a5 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 14 Nov 2022 01:20:28 +0000 Subject: [PATCH 193/217] Use negated pattern. --- Marshal.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Marshal.cs b/Marshal.cs index 64ee7be3f..90b09f7e1 100644 --- a/Marshal.cs +++ b/Marshal.cs @@ -245,8 +245,8 @@ public static T SpanToStructurePdpEndian(ReadOnlySpan bytes, int start, [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T MarshalStructure(byte[] bytes) where T : struct { - if(!(typeof(T).GetCustomAttribute(typeof(MarshallingPropertiesAttribute)) is MarshallingPropertiesAttribute - properties)) + if(typeof(T).GetCustomAttribute(typeof(MarshallingPropertiesAttribute)) is not MarshallingPropertiesAttribute + properties) return ByteArrayToStructureLittleEndian(bytes); return properties.Endian switch From 368e40d7bd9e2d7ec307e1babef1df3fbf9b2da9 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 14 Nov 2022 01:49:10 +0000 Subject: [PATCH 194/217] More pattern matching. --- DateHandlers.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/DateHandlers.cs b/DateHandlers.cs index af21162d6..30ad7496d 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -347,8 +347,7 @@ public static DateTime Os9ToDateTime(byte[] date) /// .NET DateTime public static DateTime LifToDateTime(byte[] date) { - if(date == null || - date.Length != 6) + if(date is not { Length: 6 }) return new DateTime(1970, 1, 1, 0, 0, 0); return LifToDateTime(date[0], date[1], date[2], date[3], date[4], date[5]); From f44172edb9be5513611691ccf16f7ff6d7bf9db6 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 14 Nov 2022 09:43:15 +0000 Subject: [PATCH 195/217] Use Stream extension to ensure read operations return the requested number of bytes (unless EOF arrives first). --- Aaru.Helpers.csproj | 1 + Extensions.cs | 72 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 Extensions.cs diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index e4eecd899..604834a5c 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -47,6 +47,7 @@ + diff --git a/Extensions.cs b/Extensions.cs new file mode 100644 index 000000000..c1b8479c0 --- /dev/null +++ b/Extensions.cs @@ -0,0 +1,72 @@ +// /*************************************************************************** +// Aaru Data Preservation Suite +// ---------------------------------------------------------------------------- +// +// Filename : Extensions.cs +// Author(s) : Natalia Portillo +// +// Component : Helpers. +// +// --[ Description ] ---------------------------------------------------------- +// +// Provides class extensions. +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2022 Natalia Portillo +// ****************************************************************************/ + +namespace Aaru.Helpers; + +using System.IO; + +public static class Extensions +{ + /// + /// When overridden in a derived class, reads a sequence of bytes from the current stream and advances the + /// position within the stream by the number of bytes read.
Guarantees the whole count of bytes is read or EOF is + /// found + ///
+ /// Stream to extend + /// + /// An array of bytes. When this method returns, the buffer contains the specified byte array with the + /// values between and ( + - 1) replaced by the bytes + /// read from the current source. + /// + /// + /// The zero-based byte offset in at which to begin storing the data read from + /// the current stream. + /// + /// The maximum number of bytes to be read from the current stream. + /// + /// The total number of bytes read into the buffer. This can be less than the number of bytes requested if the end + /// of the stream has been reached. + /// + public static int EnsureRead(this Stream s, byte[] buffer, int offset, int count) + { + var pos = 0; + int read; + + do + { + read = s.Read(buffer, pos + offset, count - pos); + pos += read; + } while(read > 0); + + return pos; + } +} \ No newline at end of file From 8b24f6ed00439d0cae092da443e3dcd5fa77e68c Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 15 Nov 2022 01:35:06 +0000 Subject: [PATCH 196/217] General code style and feature fixes. --- ArrayFill.cs | 3 +-- DateHandlers.cs | 10 +++------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/ArrayFill.cs b/ArrayFill.cs index 9f3e72206..f4e440cbc 100644 --- a/ArrayFill.cs +++ b/ArrayFill.cs @@ -46,8 +46,7 @@ public static void ArrayFill(T[] destinationArray, T value) => ArrayFill(dest /// Array type public static void ArrayFill(T[] destinationArray, T[] value) { - if(destinationArray == null) - throw new ArgumentNullException(nameof(destinationArray)); + ArgumentNullException.ThrowIfNull(destinationArray); if(value.Length > destinationArray.Length) throw new ArgumentException("Length of value array must not be more than length of destination"); diff --git a/DateHandlers.cs b/DateHandlers.cs index 30ad7496d..b01dd0ddd 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -345,13 +345,9 @@ public static DateTime Os9ToDateTime(byte[] date) /// Converts a LIF timestamp to .NET DateTime /// LIF timestamp /// .NET DateTime - public static DateTime LifToDateTime(byte[] date) - { - if(date is not { Length: 6 }) - return new DateTime(1970, 1, 1, 0, 0, 0); - - return LifToDateTime(date[0], date[1], date[2], date[3], date[4], date[5]); - } + public static DateTime LifToDateTime(byte[] date) => date is not { Length: 6 } ? new DateTime(1970, 1, 1, 0, 0, 0) + : LifToDateTime(date[0], date[1], date[2], date[3], + date[4], date[5]); /// Converts a LIF timestamp to .NET DateTime /// Yer From eaea8b3332ea92a9fca4ea91f66f2ed89bd6b266 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 15 Nov 2022 15:58:00 +0000 Subject: [PATCH 197/217] Fix editorconfig. --- .editorconfig | 819 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 617 insertions(+), 202 deletions(-) diff --git a/.editorconfig b/.editorconfig index 25aaa3207..7586c80d3 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,216 +1,631 @@ [*] charset = utf-8 -end_of_line = lf -trim_trailing_whitespace = false +next_line = crlf insert_final_newline = false indent_style = space indent_size = 4 -# Microsoft .NET properties -csharp_new_line_between_query_expression_clauses = false -csharp_preferred_modifier_order = public, private, protected, internal, new, static, abstract, virtual, sealed, readonly, override, extern, unsafe, volatile, async:suggestion -csharp_prefer_braces = false:warning -csharp_space_after_keywords_in_control_flow_statements = false -csharp_style_var_elsewhere = false:suggestion -csharp_style_var_for_built_in_types = false:suggestion -csharp_style_var_when_type_is_apparent = true:suggestion -csharp_using_directive_placement = inside_namespace:silent -dotnet_naming_rule.unity_serialized_field_rule.import_to_resharper = True -dotnet_naming_rule.unity_serialized_field_rule.resharper_description = Unity serialized field -dotnet_naming_rule.unity_serialized_field_rule.resharper_guid = 5f0fdb63-c892-4d2c-9324-15c80b22a7ef -dotnet_naming_rule.unity_serialized_field_rule.severity = warning -dotnet_naming_rule.unity_serialized_field_rule.style = lower_camel_case_style -dotnet_naming_rule.unity_serialized_field_rule.symbols = unity_serialized_field_symbols -dotnet_naming_rule.unity_serialized_field_rule_1.import_to_resharper = True -dotnet_naming_rule.unity_serialized_field_rule_1.resharper_description = Unity serialized field -dotnet_naming_rule.unity_serialized_field_rule_1.resharper_guid = 5f0fdb63-c892-4d2c-9324-15c80b22a7ef -dotnet_naming_rule.unity_serialized_field_rule_1.severity = warning -dotnet_naming_rule.unity_serialized_field_rule_1.style = lower_camel_case_style -dotnet_naming_rule.unity_serialized_field_rule_1.symbols = unity_serialized_field_symbols_1 -dotnet_naming_style.lower_camel_case_style.capitalization = camel_case -dotnet_naming_symbols.unity_serialized_field_symbols.applicable_accessibilities = * -dotnet_naming_symbols.unity_serialized_field_symbols.applicable_kinds = -dotnet_naming_symbols.unity_serialized_field_symbols.resharper_applicable_kinds = unity_serialised_field -dotnet_naming_symbols.unity_serialized_field_symbols.resharper_required_modifiers = instance -dotnet_naming_symbols.unity_serialized_field_symbols_1.applicable_accessibilities = * -dotnet_naming_symbols.unity_serialized_field_symbols_1.applicable_kinds = -dotnet_naming_symbols.unity_serialized_field_symbols_1.resharper_applicable_kinds = unity_serialised_field -dotnet_naming_symbols.unity_serialized_field_symbols_1.resharper_required_modifiers = instance -dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:warning -dotnet_style_parentheses_in_other_binary_operators = never_if_unnecessary:warning -dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary:warning -dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion -dotnet_style_predefined_type_for_member_access = true:suggestion -dotnet_style_qualification_for_event = false:suggestion -dotnet_style_qualification_for_field = false:suggestion -dotnet_style_qualification_for_method = false:suggestion -dotnet_style_qualification_for_property = false:suggestion -dotnet_style_require_accessibility_modifiers = never:suggestion +# Generic non-language specific ones for Resharper and friends +brace_style = next_line +int_align = true +keep_existing_arrangement = false +place_simple_blocks_on_single_line = true +place_simple_declaration_blocks_on_single_line = true +place_attribute_on_same_line = false +space_after_unary_operator = false +space_after_comma = true +space_around_ternary_operator = true +space_around_binary_operator = true +space_around_member_access_operator = false +space_before_open_square_brackets = false +space_after_keywords_in_control_flow_statements = true +space_before_comma = false +space_between_method_call_name_and_opening_parenthesis = false +space_between_method_declaration_name_and_open_parenthesis = false +space_between_square_brackets = false +space_between_parentheses_of_control_flow_statements = false +accessor_owner_declaration_braces = next_line +accessor_declaration_braces = next_line +case_block_braces = next_line +initializer_braces = next_line +other_braces = next_line +allow_comment_after_lbrace = false +empty_block_style = together_same_line +braces_for_ifelse = not_required +braces_for_for = not_required +braces_for_foreach = not_required +braces_for_while = not_required +braces_for_dowhile = not_required +braces_for_using = not_required +braces_for_lock = not_required +braces_for_fixed = not_required +method_or_operator_body = expression_body +local_function_body = expression_body +constructor_or_destructor_body = expression_body +accessor_owner_body = expression_body +force_attribute_style = join +function_braces = next_line +force_control_statements_braces = always_remove +space_in_singleline_accessorholder = true +type_declaration_braces = next_line +invocable_declaration_braces = next_line +anonymous_method_declaration_braces = next_line +space_between_accessors_in_singleline_property = true +indent_nested_usings_stmt = true +space_within_empty_braces = false +indent_nested_fixed_stmt = true +indent_nested_lock_stmt = true +indent_nested_for_stmt = true +indent_nested_foreach_stmt = true +indent_nested_while_stmt = true +use_continuous_indent_inside_parens = true +indent_method_decl_pars = inside +indent_invocation_pars = inside +indent_statement_pars = inside +indent_typeparam_angles = inside +indent_typearg_angles = inside +indent_pars = inside +indent_preprocessor_if = outdent +indent_preprocessor_region = usual_indent +indent_preprocessor_other = usual_indent +indent_switch_labels = true +indent_type_constraints = true +stick_comment = false +alignment_tab_fill_style = use_spaces +align_multiline_parameter = true +align_multiline_extends_list = true +align_linq_query = true +align_multiline_binary_expressions_chain = true +outdent_binary_ops = true +align_multiline_calls_chain = true +outdent_dots = true +align_multiline_array_and_object_initializer = false +indent_anonymous_method_block = false +align_first_arg_by_paren = true +align_multiline_argument = true +align_tuple_components = true +align_multiline_expression = true +align_multiline_for_stmt = true +align_multiple_declaration = true +align_multline_type_parameter_list = true +align_multline_type_parameter_constrains = true +int_align_fields = true +int_align_properties = true +int_align_methods = true +int_align_parameters = false +int_align_variables = true +int_align_assignments = true +int_align_nested_ternary = true +int_align_invocations = false +int_align_binary_expressions = true +int_align_comments = true +int_align_switch_sections = true +keep_user_linebreaks = false +keep_existing_arrangement = false +keep_existing_linebreaks = false +max_line_length = 120 +wrap_before_comma = false +special_else_if_treatment = true +place_type_attribute_on_same_line = never +place_method_attribute_on_same_line = never +place_accessorholder_attribute_on_same_line = never +place_attribute_on_same_line = never +place_accessor_attribute_on_same_line = never +place_attribute_on_same_line = never +place_field_attribute_on_same_line = never +place_attribute_on_same_line = never +wrap_parameters_style = wrap_if_long +keep_existing_declaration_parens_arrangement = false +wrap_before_declaration_lpar = false +wrap_after_declaration_lpar = false +wrap_before_declaration_rpar = false +place_constructor_initializer_on_same_line = true +keep_existing_expr_member_arrangement = false +place_expr_method_on_single_line = true +place_expr_property_on_single_line = true +place_expr_accessor_on_single_line = true +wrap_before_arrow_with_expressions = false +place_type_constraints_on_same_line = true +wrap_before_first_type_parameter_constraint = true +wrap_multiple_type_parameter_constraints_style = wrap_if_long +wrap_before_type_parameter_langle = true +wrap_before_extends_colon = false +wrap_extends_list_style = wrap_if_long +keep_existing_declaration_block_arrangement = false +place_abstract_accessorholder_on_single_line = true +place_simple_accessorholder_on_single_line = false +place_accessor_with_attrs_holder_on_single_line = false +place_simple_accessor_on_single_line = true +place_simple_method_on_single_line = false +keep_existing_enum_arrangement = false +place_simple_enum_on_single_line = false +wrap_enum_declaration = wrap_if_long +new_line_before_else = true +new_line_before_while = false +wrap_for_stmt_header_style = wrap_if_long +wrap_multiple_declaration_style = wrap_if_long +keep_existing_embedded_arrangement = false +place_simple_embedded_statement_on_same_line = false +place_simple_case_statement_on_same_line = true +keep_existing_embedded_block_arrangement = false +place_simple_embedded_block_on_same_line = false +place_simple_anonymousmethod_on_single_line = false +keep_existing_initializer_arrangement = false +place_simple_initializer_on_single_line = false +wrap_object_and_collection_initializer_style = chop_always +wrap_array_initializer_style = wrap_if_long +wrap_arguments_style = wrap_if_long +keep_existing_invocation_parens_arrangement = false +wrap_after_invocation_lpar = false +wrap_before_invocation_rpar = false +wrap_after_dot_in_method_calls = true +wrap_chained_method_calls = wrap_if_long +wrap_before_binary_opsign = false +wrap_chained_binary_expressions = wrap_if_long +force_chop_compound_if_expression = true +force_chop_compound_while_expression = true +force_chop_compound_do_expression = true +wrap_before_ternary_opsigns = true +wrap_ternary_expr_style = wrap_if_long +nested_ternary_style = expanded +wrap_linq_expressions = wrap_if_long +wrap_before_linq_expression = false +place_linq_into_on_new_line = false +wrap_verbatim_interpolated_strings = wrap_if_long +extra_spaces = remove_all +space_after_keywords_in_control_flow_statements = false +space_between_method_call_name_and_opening_parenthesis = false +space_between_method_declaration_name_and_open_parenthesis = false +space_before_typeof_parentheses = false +space_before_checked_parentheses = false +space_before_sizeof_parentheses = false +space_before_nameof_parentheses = false +space_between_keyword_and_expression = true +space_between_keyword_and_type = true +space_around_assignment_op = true +space_around_logical_op = true +space_around_binary_operator = true +space_around_equality_op = true +space_around_relational_op = true +space_around_bitwise_op = true +space_around_additive_op = true +space_around_multiplicative_op = true +space_around_shift_op = true +space_around_nullcoalescing_op = true +space_around_arrow_op = false +space_after_logical_not_op = false +space_after_unary_operator = false +space_after_cast = false +space_around_dot = false +space_around_lambda_arrow = true +space_before_pointer_asterik_declaration = false +space_before_nullable_mark = false +blank_lines_around_class_definition = 1 +namespace_indentation = all +space_within_template_argument = false +align_union_type_usage = true +space_in_singleline_method = true +space_in_singleline_anonymous_method = true +space_within_single_line_array_initializer_braces = true +space_around_arrow_op = false -# ReSharper properties -resharper_align_first_arg_by_paren = true -resharper_align_linq_query = true -resharper_align_multiline_argument = true -resharper_align_multiline_binary_expressions_chain = true -resharper_align_multiline_binary_patterns = true -resharper_align_multiline_calls_chain = true -resharper_align_multiline_expression = true -resharper_align_multiline_extends_list = true -resharper_align_multiline_for_stmt = true -resharper_align_multiline_parameter = true -resharper_align_multiline_property_pattern = true -resharper_align_multiline_switch_expression = true -resharper_align_multiple_declaration = true -resharper_align_multline_type_parameter_constrains = true -resharper_align_multline_type_parameter_list = true -resharper_align_tuple_components = true -resharper_attribute_indent = align_by_first_attribute -resharper_attribute_style = on_single_line -resharper_autodetect_indent_settings = true -resharper_constructor_or_destructor_body = expression_body -resharper_cpp_brace_style = next_line -resharper_csharp_outdent_commas = true -resharper_default_value_when_type_not_evident = default_expression -resharper_empty_block_style = together_same_line -resharper_force_attribute_style = join -resharper_force_chop_compound_do_expression = true -resharper_force_chop_compound_if_expression = true -resharper_force_chop_compound_while_expression = true -resharper_for_built_in_types = use_var_when_evident -resharper_fsharp_type_declaration_braces = next_line -resharper_indent_nested_fixed_stmt = true -resharper_indent_nested_foreach_stmt = true -resharper_indent_nested_for_stmt = true -resharper_indent_nested_lock_stmt = true -resharper_indent_nested_usings_stmt = true -resharper_indent_nested_while_stmt = true -resharper_indent_preprocessor_if = outdent -resharper_indent_preprocessor_other = usual_indent -resharper_indent_switch_labels = true -resharper_int_align_assignments = true -resharper_int_align_binary_expressions = true -resharper_int_align_comments = true -resharper_int_align_fields = true -resharper_int_align_methods = true -resharper_int_align_nested_ternary = true -resharper_int_align_properties = true -resharper_int_align_property_patterns = true -resharper_int_align_switch_expressions = true -resharper_int_align_switch_sections = true -resharper_int_align_variables = true -resharper_keep_existing_arrangement = false -resharper_keep_user_linebreaks = false -resharper_linebreak_before_all_elements = true -resharper_local_function_body = expression_body -resharper_max_blank_lines_between_tags = 0 -resharper_max_enum_members_on_line = 1 -resharper_method_or_operator_body = expression_body -resharper_nested_ternary_style = expanded -resharper_new_line_before_while = false -resharper_normalize_tag_names = true -resharper_outdent_binary_ops = true -resharper_outdent_binary_pattern_ops = true -resharper_outdent_dots = true -resharper_outdent_statement_labels = true -resharper_place_attribute_on_same_line = false -resharper_place_expr_accessor_on_single_line = true -resharper_place_expr_method_on_single_line = true -resharper_place_expr_property_on_single_line = true -resharper_place_linq_into_on_new_line = false -resharper_place_simple_anonymousmethod_on_single_line = false -resharper_place_simple_case_statement_on_same_line = true -resharper_place_simple_embedded_statement_on_same_line = false -resharper_place_simple_initializer_on_single_line = false -resharper_place_simple_switch_expression_on_single_line = true -resharper_prefer_explicit_discard_declaration = true -resharper_qualified_using_at_nested_scope = true -resharper_show_autodetect_configure_formatting_tip = false -resharper_sort_attributes = true -resharper_sort_class_selectors = true -resharper_space_after_keywords_in_control_flow_statements = false -resharper_space_after_last_pi_attribute = true -resharper_space_after_unary_operator = false -resharper_space_around_binary_operator = true -resharper_space_before_self_closing = true -resharper_space_within_empty_braces = false -resharper_stick_comment = false -resharper_use_indent_from_vs = false -resharper_wrap_after_dot_in_method_calls = true -resharper_wrap_before_first_type_parameter_constraint = true -resharper_wrap_before_type_parameter_langle = true -resharper_wrap_enum_declaration = wrap_if_long -resharper_wrap_for_stmt_header_style = wrap_if_long -resharper_wrap_lines = true -resharper_wrap_multiple_declaration_style = wrap_if_long -resharper_wrap_multiple_type_parameter_constraints_style = wrap_if_long -resharper_wrap_object_and_collection_initializer_style = chop_always -resharper_wrap_ternary_expr_style = wrap_if_long -resharper_wrap_verbatim_interpolated_strings = wrap_if_long - -# ReSharper inspection severities -resharper_annotate_can_be_null_parameter_highlighting = warning -resharper_annotate_can_be_null_type_member_highlighting = warning -resharper_annotate_not_null_parameter_highlighting = warning -resharper_annotate_not_null_type_member_highlighting = warning -resharper_arrange_attributes_highlighting = hint -resharper_arrange_constructor_or_destructor_body_highlighting = warning -resharper_arrange_default_value_when_type_evident_highlighting = warning -resharper_arrange_default_value_when_type_not_evident_highlighting = warning -resharper_arrange_local_function_body_highlighting = warning -resharper_arrange_method_or_operator_body_highlighting = warning -resharper_arrange_object_creation_when_type_evident_highlighting = warning -resharper_arrange_object_creation_when_type_not_evident_highlighting = warning -resharper_arrange_redundant_parentheses_highlighting = hint -resharper_arrange_this_qualifier_highlighting = hint -resharper_arrange_type_member_modifiers_highlighting = hint -resharper_arrange_type_modifiers_highlighting = hint -resharper_async_void_method_highlighting = warning -resharper_built_in_type_reference_style_for_member_access_highlighting = hint -resharper_built_in_type_reference_style_highlighting = hint -resharper_compare_non_constrained_generic_with_null_highlighting = warning -resharper_heap_view_boxing_allocation_highlighting = none -resharper_heap_view_delegate_allocation_highlighting = none -resharper_heap_view_object_allocation_evident_highlighting = none -resharper_heap_view_object_allocation_highlighting = none -resharper_inheritdoc_consider_usage_highlighting = warning -resharper_local_function_can_be_made_static_highlighting = warning -resharper_loop_can_be_partly_converted_to_query_highlighting = warning -resharper_member_can_be_internal_highlighting = warning -resharper_nullable_warning_suppression_is_used_highlighting = warning -resharper_redundant_base_qualifier_highlighting = warning -resharper_remove_constructor_invocation_highlighting = warning -resharper_separate_control_transfer_statement_highlighting = warning -resharper_string_ends_with_is_culture_specific_highlighting = warning -resharper_string_starts_with_is_culture_specific_highlighting = warning -resharper_struct_member_can_be_made_read_only_highlighting = warning -resharper_suggest_var_or_type_built_in_types_highlighting = hint -resharper_suggest_var_or_type_elsewhere_highlighting = hint -resharper_suggest_var_or_type_simple_types_highlighting = hint -resharper_tabs_are_disallowed_highlighting = warning -resharper_unnecessary_whitespace_highlighting = warning -resharper_use_nameof_expression_for_part_of_the_string_highlighting = warning -resharper_use_positional_deconstruction_pattern_highlighting = warning -resharper_web_config_module_not_resolved_highlighting = warning -resharper_web_config_type_not_resolved_highlighting = warning -resharper_web_config_wrong_module_highlighting = warning - -[{*.har,*.inputactions,*.jsb2,*.jsb3,*.json,.babelrc,.eslintrc,.stylelintrc,bowerrc,jest.config}] -indent_style = space +# These are for markup languages (HTML, XML, etc) +spaces_around_eq_in_pi_attribute = false +space_after_last_pi_attribute = true +pi_attributes_indent = align_by_first_attribute +blank_line_after_pi = true +spaces_around_eq_in_attribute = false +space_after_last_attribute = false +space_before_self_closing = true +attribute_style = on_single_line +attribute_indent = align_by_first_attribute +sort_attributes = true +sort_class_selectors = true +max_blank_lines_between_tags = 0 +linebreak_before_all_elements = true +linebreak_before_multiline_elements = true +quote_style = doublequoted +delete_quotes_from_solid_values = false +normalize_tag_names = true + + +[{.babelrc,.stylelintrc,jest.config,.eslintrc,.prettierrc,*.json,*.jsb3,*.jsb2,*.bowerrc}] indent_size = 2 -[{*.yaml,*.yml,.analysis_options}] -indent_style = space +[*.js.map] indent_size = 2 -[*.csv] -indent_style = tab -tab_width = 1 +[*.{css,scss}] +indent_size = 2 +declarations_style = separate_lines_for_nonsingle +media_query_style = separate_lines +selector_style = same_line +properties_style = separate_lines_for_nonsingle +brace_style = next_line -[{*.bash,*.sh,*.tool,*.zsh}] -indent_style = space +[{.analysis_options,*.yml,*.yaml}] indent_size = 2 -[*.{appxmanifest,asax,ascx,aspx,axaml,build,cg,cginc,compute,cs,cshtml,dtd,fs,fsi,fsscript,fsx,hlsl,hlsli,hlslinc,master,ml,mli,nuspec,paml,razor,resw,resx,shader,skin,usf,ush,vb,xaml,xamlx,xoml,xsd}] -indent_style = space -indent_size = 4 -tab_width = 4 +# Xml project files +[*.{csproj,vcxproj,vcxproj.filters,proj,nativeproj,locproj}] +indent_size = 2 + +# Xml files +[*.{xml,stylecop,resx,ruleset}] +indent_size = 2 + +# Xml config files +[*.{props,targets,config,nuspec}] +indent_size = 2 + +# .net files +[*.{cs,vb}] +# These set the this. / Me. +dotnet_style_qualification_for_field = false:warning +dotnet_style_qualification_for_property = false:warning +dotnet_style_qualification_for_method = false:warning +dotnet_style_qualification_for_event = false:warning + +# These make it suggest Int32 instead of int, etc. +dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion +dotnet_style_predefined_type_for_member_access = true:suggestion + +# This controls implicit access modifiers +dotnet_style_require_accessibility_modifiers = never:suggestion + +# Prefer non modified fields to be marked readonly +dotnet_style_readonly_field = true:warning + +# Parenthesis settings +dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:warning +dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:warning +dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:warning +dotnet_style_parentheses_in_other_operators = always_for_clarity:warning + +dotnet_style_object_initializer = true:suggestion +dotnet_style_collection_initializer = true:suggestion +dotnet_style_explicit_tuple_names = true:error +dotnet_style_prefer_inferred_tuple_names = true:warning +dotnet_style_prefer_inferred_anonymous_type_member_names = true:warning +dotnet_style_prefer_is_null_check_over_reference_equality_method = true:warning +dotnet_style_prefer_conditional_expression_over_return = true:warning +dotnet_style_coalesce_expression = true:warning +dotnet_style_null_propagation = true:error + +dotnet_sort_system_directives_first = true + +# Constants in C style, all-caps +dotnet_naming_rule.constant_fields_caps.symbols = constant_fields +dotnet_naming_rule.constant_fields_caps.severity = warning +dotnet_naming_rule.constant_fields_caps.style = caps_style +dotnet_naming_symbols.constant_fields.applicable_kinds = field +dotnet_naming_symbols.constant_fields.required_modifiers = const +dotnet_naming_style.caps_style.capitalization = all_upper + +# interfaces should be prefixed with I +dotnet_naming_rule.pascal_case_for_interface.severity = error +dotnet_naming_rule.pascal_case_for_interface.symbols = interfaces_fields +dotnet_naming_rule.pascal_case_for_interface.style = pascal_case_interface_style +dotnet_naming_symbols.interfaces_fields.applicable_kinds = interface +dotnet_naming_style.pascal_case_interface_style.required_prefix = I +dotnet_naming_style.pascal_case_interface_style.capitalization = pascal_case + +## internal and private fields should be _camelCase +dotnet_naming_rule.camel_case_for_private_internal_fields.severity = warning +dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields +dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style +dotnet_naming_symbols.private_internal_fields.applicable_kinds = field +dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal +dotnet_naming_style.camel_case_underscore_style.required_prefix = _ +dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case + +# 2018-12-07 NP: This is not yet working in VS2017 +# local variables should be camelCase +#dotnet_naming_rule.camel_case_for_locals.severity = suggestion +#dotnet_naming_rule.camel_case_for_locals.symbols = local_fields +#dotnet_naming_rule.camel_case_for_locals.style = camel_case_style +#dotnet_naming_symbols.local_fields.applicable_kinds = local +#dotnet_naming_style.camel_case_style.capitalization = camel_case + +[*.cs] +# var var var +csharp_style_var_for_built_in_types = false:warning +csharp_style_var_when_type_is_apparent = true:suggestion +csharp_style_var_elsewhere = false:warning + +csharp_style_expression_bodied_methods = when_on_single_line:suggestion +csharp_style_expression_bodied_constructors = when_on_single_line:suggestion +csharp_style_expression_bodied_operators = when_on_single_line:suggestion +csharp_style_expression_bodied_properties = when_on_single_line:suggestion +csharp_style_expression_bodied_indexers = when_on_single_line:suggestion +csharp_style_expression_bodied_accessors = when_on_single_line:suggestion + +csharp_style_pattern_matching_over_is_with_cast_check = true:warning +csharp_style_pattern_matching_over_as_with_null_check = when_on_single_line:warning + +csharp_style_inlined_variable_declaration = true:warning + +csharp_prefer_simple_default_expression = true:warning +csharp_style_deconstructed_variable_declaration = false:warning + +csharp_style_throw_expression = true:warning +csharp_style_conditional_delegate_call = true:warning + +csharp_prefer_braces = false + +csharp_new_line_before_open_brace = all +csharp_new_line_before_else = true +csharp_new_line_before_catch = true +csharp_new_line_before_finally = true +csharp_new_line_before_members_in_object_initializers = true +csharp_new_line_before_members_in_anonymous_types = true +csharp_new_line_between_query_expression_clauses = true + +csharp_indent_case_contents = true +csharp_indent_switch_labels = true +csharp_indent_labels = flush_left + +csharp_space_after_cast = false +csharp_space_after_keywords_in_control_flow_statements = false +csharp_space_between_method_declaration_parameter_list_parentheses = false +csharp_space_between_parentheses = none +csharp_space_before_colon_in_inheritance_clause = true +csharp_space_after_colon_in_inheritance_clause = true +csharp_space_around_binary_operators = before_and_after +csharp_space_between_method_declaration_empty_parameter_list_parentheses = false +csharp_space_between_method_call_name_and_opening_parenthesis = false +csharp_space_between_method_call_empty_parameter_list_parentheses = false + +csharp_preserve_single_line_statements = false +csharp_preserve_single_line_blocks = true + +csharp_blank_lines_around_region = 0 +csharp_blank_lines_inside_region = 0 +csharp_blank_lines_before_single_line_comment = 1 +csharp_keep_blank_lines_in_declarations = 1 +csharp_remove_blank_lines_near_braces_in_declarations = true +csharp_blank_lines_after_start_comment = false +csharp_blank_lines_between_using_groups = 0 +csharp_blank_lines_after_using_list = 1 +csharp_blank_lines_around_namespace = 1 +csharp_blank_lines_inside_namespace = 0 +csharp_blank_lines_around_type = 1 +csharp_blank_lines_inside_type = 0 +csharp_blank_lines_around_field = 0 +csharp_blank_lines_around_single_line_field = 0 +csharp_blank_lines_around_property = 1 +csharp_blank_lines_around_single_line_property = 0 +csharp_blank_lines_around_auto_property = 0 +csharp_blank_lines_around_single_line_auto_property = 0 +csharp_blank_lines_around_invocable = 1 +csharp_blank_lines_around_single_line_invocable = 1 +csharp_keep_blank_lines_in_code = 1 +csharp_remove_blank_lines_near_braces_in_code = true +csharp_blank_lines_around_local_method = 1 +csharp_blank_lines_around_single_line_local_method = 1 +csharp_blank_lines_before_control_transfer_statements = 1 +csharp_blank_lines_after_control_transfer_statements = 1 +csharp_blank_lines_before_block_statements = 1 +csharp_blank_lines_after_block_statements = 1 +csharp_blank_lines_before_multiline_statements = 1 +csharp_blank_lines_after_multiline_statements = 1 + +csharp_type_declaration_braces = next_line +csharp_brace_style = next_line +csharp_indent_inside_namespace = true +csharp_invocable_declaration_braces = next_line +csharp_anonymous_method_declaration_braces = next_line +csharp_accessor_owner_declaration_braces = next_line +csharp_accessor_declaration_braces = next_line +csharp_case_block_braces = next_line +csharp_initializer_braces = next_line +csharp_other_braces = next_line +csharp_allow_comment_after_lbrace = false +csharp_empty_block_style = together_same_line + +csharp_for_built_in_types = use_explicit_type +csharp_for_simple_types = use_var_when_evident +csharp_for_other_types = use_explicit_type +csharp_prefer_separate_deconstructed_variables_declaration = true +csharp_prefer_explicit_discard_declaration = false + +csharp_instance_members_qualify_members = none +csharp_builtin_type_reference_style = use_keyword +csharp_prefer_qualified_reference = false +csharp_add_imports_to_deepest_scope = false +csharp_allow_alias = true +csharp_default_private_modifier = implicit +csharp_default_internal_modifier = implicit +csharp_arguments_literal = positional +csharp_arguments_string_literal = positional +csharp_arguments_named = positional +csharp_arguments_anonymous_function = positional +csharp_arguments_other = positional +csharp_braces_for_ifelse = not_required +csharp_braces_for_for = not_required +csharp_braces_for_foreach = not_required +csharp_braces_for_while = not_required +csharp_braces_for_dowhile = not_required +csharp_braces_for_using = not_required +csharp_braces_for_lock = not_required +csharp_braces_for_fixed = not_required +csharp_method_or_operator_body = expression_body +csharp_local_function_body = expression_body +csharp_constructor_or_destructor_body = expression_body +csharp_accessor_owner_body = expression_body +csharp_force_attribute_style = join +csharp_indent_nested_usings_stmt = true + +csharp_builtin_type_reference_for_member_access_style = use_keyword +csharp_indent_nested_fixed_stmt = true +csharp_indent_nested_lock_stmt = true +csharp_indent_nested_for_stmt = true +csharp_indent_nested_foreach_stmt = true +csharp_indent_nested_while_stmt = true +csharp_use_continuous_indent_inside_parens = true +csharp_indent_method_decl_pars = inside +csharp_indent_invocation_pars = inside +csharp_indent_statement_pars = inside +csharp_indent_typeparam_angles = inside +csharp_indent_typearg_angles = inside +csharp_indent_pars = inside +csharp_indent_preprocessor_if = outdent +csharp_indent_preprocessor_region = usual_indent +csharp_indent_preprocessor_other = usual_indent +csharp_indent_switch_labels = true +csharp_indent_type_constraints = true +csharp_stick_comment = false +csharp_alignment_tab_fill_style = use_spaces +csharp_align_multiline_parameter = true +csharp_align_multiline_extends_list = true +csharp_align_linq_query = true +csharp_align_multiline_binary_expressions_chain = true +csharp_outdent_binary_ops = true +csharp_align_multiline_calls_chain = true +csharp_outdent_dots = true +csharp_align_multiline_array_and_object_initializer = false +csharp_indent_anonymous_method_block = false +csharp_align_first_arg_by_paren = true +csharp_align_multiline_argument = true +csharp_align_tuple_components = true +csharp_align_multiline_expression = true +csharp_align_multiline_for_stmt = true +csharp_align_multiple_declaration = true +csharp_align_multline_type_parameter_list = true +csharp_align_multline_type_parameter_constrains = true +csharp_int_align_fields = true +csharp_int_align_properties = true +csharp_int_align_methods = true +csharp_int_align_parameters = false +csharp_int_align_variables = true +csharp_int_align_assignments = true +csharp_int_align_nested_ternary = true +csharp_int_align_invocations = false +csharp_int_align_binary_expressions = true +csharp_int_align_comments = true +csharp_int_align_switch_sections = true +csharp_int_align = true +csharp_keep_user_linebreaks = false +csharp_keep_existing_arrangement = false +csharp_keep_existing_linebreaks = false +csharp_max_line_length = 120 +csharp_wrap_before_comma = false +csharp_special_else_if_treatment = true +csharp_insert_final_newline = false +csharp_place_type_attribute_on_same_line = never +csharp_place_method_attribute_on_same_line = never +csharp_place_accessorholder_attribute_on_same_line = never +csharp_place_attribute_on_same_line = never +csharp_place_accessor_attribute_on_same_line = never +csharp_place_attribute_on_same_line = never +csharp_place_field_attribute_on_same_line = never +csharp_place_attribute_on_same_line = never +csharp_wrap_parameters_style = wrap_if_long +csharp_keep_existing_declaration_parens_arrangement = false +csharp_wrap_before_declaration_lpar = false +csharp_wrap_after_declaration_lpar = false +csharp_wrap_before_declaration_rpar = false +csharp_place_constructor_initializer_on_same_line = true +csharp_keep_existing_expr_member_arrangement = false +csharp_place_expr_method_on_single_line = true +csharp_place_expr_property_on_single_line = true +csharp_place_expr_accessor_on_single_line = true +csharp_wrap_before_arrow_with_expressions = false +csharp_place_type_constraints_on_same_line = true +csharp_wrap_before_first_type_parameter_constraint = true +csharp_wrap_multiple_type_parameter_constraints_style = wrap_if_long +csharp_wrap_before_type_parameter_langle = true +csharp_wrap_before_extends_colon = false +csharp_wrap_extends_list_style = wrap_if_long +csharp_keep_existing_declaration_block_arrangement = false +csharp_place_abstract_accessorholder_on_single_line = true +csharp_place_simple_accessorholder_on_single_line = false +csharp_place_accessor_with_attrs_holder_on_single_line = false +csharp_place_simple_accessor_on_single_line = true +csharp_place_simple_method_on_single_line = false +csharp_keep_existing_enum_arrangement = false +csharp_place_simple_enum_on_single_line = false +csharp_wrap_enum_declaration = wrap_if_long +csharp_new_line_before_else = true +csharp_new_line_before_while = false +csharp_wrap_for_stmt_header_style = wrap_if_long +csharp_wrap_multiple_declaration_style = wrap_if_long +csharp_keep_existing_embedded_arrangement = false +csharp_place_simple_embedded_statement_on_same_line = false +csharp_place_simple_case_statement_on_same_line = true +csharp_keep_existing_embedded_block_arrangement = false +csharp_place_simple_embedded_block_on_same_line = false +csharp_place_simple_anonymousmethod_on_single_line = false +csharp_keep_existing_initializer_arrangement = false +csharp_place_simple_initializer_on_single_line = false +csharp_wrap_object_and_collection_initializer_style = chop_always +csharp_wrap_array_initializer_style = wrap_if_long +csharp_wrap_arguments_style = wrap_if_long +csharp_keep_existing_invocation_parens_arrangement = false +csharp_wrap_after_invocation_lpar = false +csharp_wrap_before_invocation_rpar = false +csharp_wrap_after_dot_in_method_calls = true +csharp_wrap_chained_method_calls = wrap_if_long +csharp_wrap_before_binary_opsign = false +csharp_wrap_chained_binary_expressions = wrap_if_long +csharp_force_chop_compound_if_expression = true +csharp_force_chop_compound_while_expression = true +csharp_force_chop_compound_do_expression = true +csharp_wrap_before_ternary_opsigns = true +csharp_wrap_ternary_expr_style = wrap_if_long +csharp_nested_ternary_style = expanded +csharp_wrap_linq_expressions = wrap_if_long +csharp_wrap_before_linq_expression = false +csharp_place_linq_into_on_new_line = false +csharp_wrap_verbatim_interpolated_strings = wrap_if_long +csharp_extra_spaces = remove_all +csharp_space_after_keywords_in_control_flow_statements = false +csharp_space_between_method_call_name_and_opening_parenthesis = false +csharp_space_between_method_declaration_name_and_open_parenthesis = false +csharp_space_before_typeof_parentheses = false +csharp_space_before_checked_parentheses = false +csharp_space_before_sizeof_parentheses = false +csharp_space_before_nameof_parentheses = false +csharp_space_between_keyword_and_expression = true +csharp_space_between_keyword_and_type = true +csharp_space_around_assignment_op = true +csharp_space_around_logical_op = true +csharp_space_around_binary_operator = true +csharp_space_around_equality_op = true +csharp_space_around_relational_op = true +csharp_space_around_bitwise_op = true +csharp_space_around_additive_op = true +csharp_space_around_multiplicative_op = true +csharp_space_around_shift_op = true +csharp_space_around_nullcoalescing_op = true +csharp_space_around_arrow_op = false +csharp_space_after_logical_not_op = false +csharp_space_after_unary_operator = false +csharp_space_after_cast = false +csharp_space_around_dot = false +csharp_space_around_lambda_arrow = true +csharp_space_before_pointer_asterik_declaration = false +csharp_space_before_nullable_mark = false +csharp_style_namespace_declarations = file_scoped:warning + +[*.cshtml] +linebreaks_around_razor_statements = true +blank_lines_around_razor_functions = true +blank_lines_around_razor_helpers = true +blank_lines_around_razor_sections = true + +# C++ +[*.{cc,cpp,cxx,h,hpp,hxx}] +cpp_indent_access_specifiers_from_class = true +cpp_indent_wrapped_function_names = false +cpp_align_multiline_type_argument = true + +# C, C++ and ObjectiveC +[*.{c,h,cc,cpp,cxx,m,hpp,hxx}] +indent_preprocessor_directives = normal +indent_type_constraints = true + +# Javascript and Typescript +[*.{js,js.map,ts}] +quote_style = doublequoted +termination_style = ensure_semicolon From cfe81b8905f2407a8e2f1d67482a44612f95b0be Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 15 Nov 2022 15:58:41 +0000 Subject: [PATCH 198/217] General code cleanup and style refactor. --- Aaru.Helpers.csproj | 140 +++++++++++++++--------------- ArrayFill.cs | 4 +- ArrayIsEmpty.cs | 4 +- BigEndianBitConverter.cs | 4 +- CHS.cs | 4 +- DateHandlers.cs | 40 ++++----- Extensions.cs | 6 +- Marshal.cs | 92 ++++++++++---------- MarshallingPropertiesAttribute.cs | 4 +- PrintHex.cs | 26 +++--- StringHandlers.cs | 16 ++-- Swapping.cs | 4 +- 12 files changed, 171 insertions(+), 173 deletions(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index 604834a5c..914137bcc 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -1,73 +1,73 @@  - - 2.0 - {F8BDF57B-1571-4CD0-84B3-B422088D359A} - Library - Aaru.Helpers - Aaru.Helpers - $(Version) - false - true - 6.0.0-alpha8 - Claunia.com - Copyright © 2011-2022 Natalia Portillo - Aaru Data Preservation Suite - Aaru.Helpers - $(Version) - net7.0 - 11 - Contains helpers used by the Aaru Data Preservation Suite. - https://github.com/aaru-dps/ - LGPL-2.1-only - https://github.com/aaru-dps/Aaru.Helpers - true - en-US - true - true - snupkg - Natalia Portillo <claunia@claunia.com> - true - true - - - CS1591;CS1574 - - - - - - - $(Version)+{chash:8} - true - true - - - - - - - - - - - - - - - - - - - - - - - LICENSE.LGPL - - - - - - + + 2.0 + {F8BDF57B-1571-4CD0-84B3-B422088D359A} + Library + Aaru.Helpers + Aaru.Helpers + $(Version) + false + true + 6.0.0-alpha8 + Claunia.com + Copyright © 2011-2022 Natalia Portillo + Aaru Data Preservation Suite + Aaru.Helpers + $(Version) + net7.0 + 11 + Contains helpers used by the Aaru Data Preservation Suite. + https://github.com/aaru-dps/ + LGPL-2.1-only + https://github.com/aaru-dps/Aaru.Helpers + true + en-US + true + true + snupkg + Natalia Portillo <claunia@claunia.com> + true + true + + + CS1591;CS1574 + + + + + + + $(Version)+{chash:8} + true + true + + + + + + + + + + + + + + + + + + + + + + + LICENSE.LGPL + + + + + + \ No newline at end of file diff --git a/ArrayFill.cs b/ArrayFill.cs index f4e440cbc..c3e9e1b0f 100644 --- a/ArrayFill.cs +++ b/ArrayFill.cs @@ -24,11 +24,11 @@ // Copyright(C) 2014 mykohsu // ****************************************************************************/ -namespace Aaru.Helpers; - using System; using System.Text; +namespace Aaru.Helpers; + public static partial class ArrayHelpers { /// Fills an array with the specified value diff --git a/ArrayIsEmpty.cs b/ArrayIsEmpty.cs index 7df593cf6..a8c062ad5 100644 --- a/ArrayIsEmpty.cs +++ b/ArrayIsEmpty.cs @@ -30,10 +30,10 @@ // Copyright © 2011-2022 Natalia Portillo // ****************************************************************************/ -namespace Aaru.Helpers; - using System.Linq; +namespace Aaru.Helpers; + /// Helper operations to work with arrays public static partial class ArrayHelpers { diff --git a/BigEndianBitConverter.cs b/BigEndianBitConverter.cs index 4c180a5af..f378fed18 100644 --- a/BigEndianBitConverter.cs +++ b/BigEndianBitConverter.cs @@ -30,11 +30,11 @@ // Copyright © 2011-2022 Natalia Portillo // ****************************************************************************/ -namespace Aaru.Helpers; - using System; using System.Linq; +namespace Aaru.Helpers; + /// /// Converts base data types to an array of bytes, and an array of bytes to base data types. All info taken from /// the meta data of System.BitConverter. This implementation allows for Endianness consideration. diff --git a/CHS.cs b/CHS.cs index ad9945014..aa58ff396 100644 --- a/CHS.cs +++ b/CHS.cs @@ -43,6 +43,6 @@ public static class CHS /// Number of sectors per track /// public static uint ToLBA(uint cyl, uint head, uint sector, uint maxHead, uint maxSector) => - maxHead == 0 || maxSector == 0 ? (cyl * 16 + head) * 63 + sector - 1 - : (cyl * maxHead + head) * maxSector + sector - 1; + maxHead == 0 || maxSector == 0 ? (((cyl * 16) + head) * 63) + sector - 1 + : (((cyl * maxHead) + head) * maxSector) + sector - 1; } \ No newline at end of file diff --git a/DateHandlers.cs b/DateHandlers.cs index b01dd0ddd..9aecf7af6 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -30,12 +30,12 @@ // Copyright © 2011-2022 Natalia Portillo // ****************************************************************************/ -namespace Aaru.Helpers; - using System; using System.Text; using Aaru.Console; +namespace Aaru.Helpers; + /// Helper operations for timestamp management (date and time) public static class DateHandlers { @@ -88,7 +88,7 @@ public static DateTime UnixUnsignedToDateTime(uint seconds, uint nanoseconds) => /// .NET DateTime public static DateTime HighSierraToDateTime(byte[] vdDateTime) { - var isoTime = new byte[17]; + byte[] isoTime = new byte[17]; Array.Copy(vdDateTime, 0, isoTime, 0, 16); return Iso9660ToDateTime(isoTime); @@ -100,8 +100,8 @@ public static DateTime HighSierraToDateTime(byte[] vdDateTime) /// .NET DateTime public static DateTime Iso9660ToDateTime(byte[] vdDateTime) { - var twoCharValue = new byte[2]; - var fourCharValue = new byte[4]; + byte[] twoCharValue = new byte[2]; + byte[] fourCharValue = new byte[4]; fourCharValue[0] = vdDateTime[0]; fourCharValue[1] = vdDateTime[1]; @@ -172,7 +172,7 @@ public static DateTime Iso9660ToDateTime(byte[] vdDateTime) "decodedDT = new DateTime({0}, {1}, {2}, {3}, {4}, {5}, {6}, DateTimeKind.Unspecified);", year, month, day, hour, minute, second, hundredths * 10); - var difference = (sbyte)vdDateTime[16]; + sbyte difference = (sbyte)vdDateTime[16]; var decodedDt = new DateTime(year, month, day, hour, minute, second, hundredths * 10, DateTimeKind.Utc); @@ -257,9 +257,9 @@ public static DateTime DosToDateTime(ushort date, ushort time) /// .NET DateTime public static DateTime CpmToDateTime(byte[] timestamp) { - var 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); @@ -284,15 +284,15 @@ public static DateTime EcmaToDateTime(ushort typeAndTimeZone, short year, byte m byte minute, byte second, byte centiseconds, byte hundredsOfMicroseconds, byte microseconds) { - var specification = (byte)((typeAndTimeZone & 0xF000) >> 12); + 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); - var preOffset = (ushort)(typeAndTimeZone & 0xFFF); - short offset; + ushort preOffset = (ushort)(typeAndTimeZone & 0xFFF); + short offset; if((preOffset & 0x800) == 0x800) offset = (short)(preOffset | 0xF000); @@ -324,7 +324,7 @@ public static DateTime EcmaToDateTime(ushort typeAndTimeZone, short year, byte m public static DateTime Os9ToDateTime(byte[] date) { if(date == null || - date.Length != 3 && date.Length != 5) + (date.Length != 3 && date.Length != 5)) return DateTime.MinValue; DateTime os9Date; @@ -361,12 +361,12 @@ public static DateTime LifToDateTime(byte year, byte month, byte day, byte hour, { try { - 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 isecond = (second >> 4) * 10 + (second & 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 isecond = ((second >> 4) * 10) + (second & 0xF); if(iyear >= 70) iyear += 1900; diff --git a/Extensions.cs b/Extensions.cs index c1b8479c0..cc413ea3c 100644 --- a/Extensions.cs +++ b/Extensions.cs @@ -30,10 +30,10 @@ // Copyright © 2011-2022 Natalia Portillo // ****************************************************************************/ -namespace Aaru.Helpers; - using System.IO; +namespace Aaru.Helpers; + public static class Extensions { /// @@ -58,7 +58,7 @@ public static class Extensions /// public static int EnsureRead(this Stream s, byte[] buffer, int offset, int count) { - var pos = 0; + int pos = 0; int read; do diff --git a/Marshal.cs b/Marshal.cs index 90b09f7e1..6bf697f1a 100644 --- a/Marshal.cs +++ b/Marshal.cs @@ -30,14 +30,14 @@ // Copyright © 2011-2022 Natalia Portillo // ****************************************************************************/ -namespace Aaru.Helpers; - using System; using System.Diagnostics.CodeAnalysis; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +namespace Aaru.Helpers; + /// Provides methods to marshal binary data into C# structs public static class Marshal { @@ -250,15 +250,15 @@ public static T MarshalStructure(byte[] bytes) where T : struct return ByteArrayToStructureLittleEndian(bytes); return properties.Endian switch - { - BitEndian.Little => properties.HasReferences ? ByteArrayToStructureLittleEndian(bytes) - : SpanToStructureLittleEndian(bytes), - BitEndian.Big => properties.HasReferences ? ByteArrayToStructureBigEndian(bytes) - : SpanToStructureBigEndian(bytes), - BitEndian.Pdp => properties.HasReferences ? ByteArrayToStructurePdpEndian(bytes) - : SpanToStructurePdpEndian(bytes), - _ => throw new ArgumentOutOfRangeException() - }; + { + BitEndian.Little => properties.HasReferences ? ByteArrayToStructureLittleEndian(bytes) + : SpanToStructureLittleEndian(bytes), + BitEndian.Big => properties.HasReferences ? ByteArrayToStructureBigEndian(bytes) + : SpanToStructureBigEndian(bytes), + BitEndian.Pdp => properties.HasReferences ? ByteArrayToStructurePdpEndian(bytes) + : SpanToStructurePdpEndian(bytes), + _ => throw new ArgumentOutOfRangeException() + }; } /// Swaps all members of a structure @@ -272,22 +272,22 @@ public static object SwapStructureMembersEndian(object str) foreach(FieldInfo fi in fieldInfo) if(fi.FieldType == typeof(short) || - fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(short)) + (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(short))) { - var x = (short)(fi.GetValue(str) ?? default(short)); + short x = (short)(fi.GetValue(str) ?? default(short)); fi.SetValue(str, (short)((x << 8) | ((x >> 8) & 0xFF))); } else if(fi.FieldType == typeof(int) || - fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(int)) + (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(int))) { - var x = (int)(fi.GetValue(str) ?? default(int)); + int x = (int)(fi.GetValue(str) ?? default(int)); x = (int)(((x << 8) & 0xFF00FF00) | (((uint)x >> 8) & 0xFF00FF)); fi.SetValue(str, (int)(((uint)x << 16) | (((uint)x >> 16) & 0xFFFF))); } else if(fi.FieldType == typeof(long) || - fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(long)) + (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(long))) { - var x = (long)(fi.GetValue(str) ?? default(long)); + long x = (long)(fi.GetValue(str) ?? default(long)); x = ((x & 0x00000000FFFFFFFF) << 32) | (long)(((ulong)x & 0xFFFFFFFF00000000) >> 32); x = ((x & 0x0000FFFF0000FFFF) << 16) | (long)(((ulong)x & 0xFFFF0000FFFF0000) >> 16); x = ((x & 0x00FF00FF00FF00FF) << 8) | (long)(((ulong)x & 0xFF00FF00FF00FF00) >> 8); @@ -295,22 +295,22 @@ public static object SwapStructureMembersEndian(object str) fi.SetValue(str, x); } else if(fi.FieldType == typeof(ushort) || - fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(ushort)) + (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(ushort))) { - var x = (ushort)(fi.GetValue(str) ?? default(ushort)); + ushort x = (ushort)(fi.GetValue(str) ?? default(ushort)); fi.SetValue(str, (ushort)((x << 8) | (x >> 8))); } else if(fi.FieldType == typeof(uint) || - fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(uint)) + (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(uint))) { - var x = (uint)(fi.GetValue(str) ?? default(uint)); + uint x = (uint)(fi.GetValue(str) ?? default(uint)); x = ((x << 8) & 0xFF00FF00) | ((x >> 8) & 0xFF00FF); fi.SetValue(str, (x << 16) | (x >> 16)); } else if(fi.FieldType == typeof(ulong) || - fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(ulong)) + (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(ulong))) { - var x = (ulong)(fi.GetValue(str) ?? default(ulong)); + ulong x = (ulong)(fi.GetValue(str) ?? default(ulong)); x = ((x & 0x00000000FFFFFFFF) << 32) | ((x & 0xFFFFFFFF00000000) >> 32); x = ((x & 0x0000FFFF0000FFFF) << 16) | ((x & 0xFFFF0000FFFF0000) >> 16); x = ((x & 0x00FF00FF00FF00FF) << 8) | ((x & 0xFF00FF00FF00FF00) >> 8); @@ -318,7 +318,7 @@ public static object SwapStructureMembersEndian(object str) } else if(fi.FieldType == typeof(float)) { - var flt = (float)(fi.GetValue(str) ?? default(float)); + float flt = (float)(fi.GetValue(str) ?? default(float)); byte[] flt_b = BitConverter.GetBytes(flt); fi.SetValue(str, BitConverter.ToSingle(new[] @@ -328,7 +328,7 @@ public static object SwapStructureMembersEndian(object str) } else if(fi.FieldType == typeof(double)) { - var dbl = (double)(fi.GetValue(str) ?? default(double)); + double dbl = (double)(fi.GetValue(str) ?? default(double)); byte[] dbl_b = BitConverter.GetBytes(dbl); fi.SetValue(str, BitConverter.ToDouble(new[] @@ -348,8 +348,7 @@ public static object SwapStructureMembersEndian(object str) // TODO: Swap arrays else if(fi.FieldType.IsValueType && - !fi.FieldType.IsEnum && - !fi.FieldType.IsArray) + fi.FieldType is { IsEnum: false, IsArray: false }) { object obj = fi.GetValue(str); object strc = SwapStructureMembersEndian(obj); @@ -382,22 +381,21 @@ public static object SwapStructureMembersEndianPdp(object str) // Do nothing } else if(fi.FieldType == typeof(int) || - fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(int)) + (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(int))) { - var x = (int)(fi.GetValue(str) ?? default(int)); + int x = (int)(fi.GetValue(str) ?? default(int)); fi.SetValue(str, ((x & 0xffffu) << 16) | ((x & 0xffff0000u) >> 16)); } else if(fi.FieldType == typeof(uint) || - fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(uint)) + (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(uint))) { - var x = (uint)(fi.GetValue(str) ?? default(uint)); + uint x = (uint)(fi.GetValue(str) ?? default(uint)); fi.SetValue(str, ((x & 0xffffu) << 16) | ((x & 0xffff0000u) >> 16)); } // TODO: Swap arrays else if(fi.FieldType.IsValueType && - !fi.FieldType.IsEnum && - !fi.FieldType.IsArray) + fi.FieldType is { IsEnum: false, IsArray: false }) { object obj = fi.GetValue(str); object strc = SwapStructureMembersEndianPdp(obj); @@ -414,8 +412,8 @@ public static object SwapStructureMembersEndianPdp(object str) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static byte[] StructureToByteArrayLittleEndian(T str) where T : struct { - var buf = new byte[SizeOf()]; - var ptr = GCHandle.Alloc(buf, GCHandleType.Pinned); + byte[] buf = new byte[SizeOf()]; + var ptr = GCHandle.Alloc(buf, GCHandleType.Pinned); System.Runtime.InteropServices.Marshal.StructureToPtr(str, ptr.AddrOfPinnedObject(), false); ptr.Free(); @@ -441,14 +439,14 @@ public static int ConvertFromHexAscii(string hex, out byte[] outBuf) if(hex is null or "") return -1; - var off = 0; + int off = 0; if(hex[0] == '0' && (hex[1] == 'x' || hex[1] == 'X')) off = 2; outBuf = new byte[(hex.Length - off) / 2]; - var count = 0; + int count = 0; for(int i = off; i < hex.Length; i += 2) { @@ -458,11 +456,11 @@ public static int ConvertFromHexAscii(string hex, out byte[] outBuf) break; c -= c switch - { - >= 'a' and <= 'f' => '\u0057', - >= 'A' and <= 'F' => '\u0037', - _ => '\u0030' - }; + { + >= 'a' and <= 'f' => '\u0057', + >= 'A' and <= 'F' => '\u0037', + _ => '\u0030' + }; outBuf[(i - off) / 2] = (byte)(c << 4); @@ -472,11 +470,11 @@ public static int ConvertFromHexAscii(string hex, out byte[] outBuf) break; c -= c switch - { - >= 'a' and <= 'f' => '\u0057', - >= 'A' and <= 'F' => '\u0037', - _ => '\u0030' - }; + { + >= 'a' and <= 'f' => '\u0057', + >= 'A' and <= 'F' => '\u0037', + _ => '\u0030' + }; outBuf[(i - off) / 2] += (byte)c; diff --git a/MarshallingPropertiesAttribute.cs b/MarshallingPropertiesAttribute.cs index ac96c2592..bb9f7c35c 100644 --- a/MarshallingPropertiesAttribute.cs +++ b/MarshallingPropertiesAttribute.cs @@ -36,10 +36,10 @@ // Copyright © 2011-2022 Natalia Portillo // ****************************************************************************/ -namespace Aaru.Helpers; - using System; +namespace Aaru.Helpers; + /// /// Defines properties to help marshalling structs from binary data [AttributeUsage(AttributeTargets.Struct)] diff --git a/PrintHex.cs b/PrintHex.cs index 0d193e95a..448b3423c 100644 --- a/PrintHex.cs +++ b/PrintHex.cs @@ -30,11 +30,11 @@ // Copyright © 2011-2022 Natalia Portillo // ****************************************************************************/ -namespace Aaru.Helpers; - using System.Text; using Aaru.Console; +namespace Aaru.Helpers; + /// Helper operations to get hexadecimal representations of byte arrays public static class PrintHex { @@ -56,11 +56,11 @@ public static string ByteArrayToHexArrayString(byte[] array, int width = 16, boo // TODO: Color list // TODO: Allow to change width - var str = "Offset"; - int rows = array.Length / width; - int last = array.Length % width; - int offsetLength = $"{array.Length:X}".Length; - var sb = new StringBuilder(); + string str = "Offset"; + int rows = array.Length / width; + int last = array.Length % width; + int offsetLength = $"{array.Length:X}".Length; + var sb = new StringBuilder(); switch(last) { @@ -86,7 +86,7 @@ public static string ByteArrayToHexArrayString(byte[] array, int width = 16, boo sb.Append(str); sb.Append(" "); - for(var i = 0; i < width; i++) + for(int i = 0; i < width; i++) sb.AppendFormat(" {0:X2}", i); if(color) @@ -94,11 +94,11 @@ public static string ByteArrayToHexArrayString(byte[] array, int width = 16, boo sb.AppendLine(); - var b = 0; + int b = 0; string format = $"{{0:X{offsetLength}}}"; - for(var i = 0; i < rows; i++) + for(int i = 0; i < rows; i++) { if(color) sb.Append("\u001b[36m"); @@ -112,19 +112,19 @@ public static string ByteArrayToHexArrayString(byte[] array, int width = 16, boo int lastBytes = i == rows - 1 ? last : width; int lastSpaces = width - lastBytes; - for(var j = 0; j < lastBytes; j++) + for(int j = 0; j < lastBytes; j++) { sb.AppendFormat(" {0:X2}", array[b]); b++; } - for(var j = 0; j < lastSpaces; j++) + for(int j = 0; j < lastSpaces; j++) sb.Append(" "); b -= lastBytes; sb.Append(" "); - for(var j = 0; j < lastBytes; j++) + for(int j = 0; j < lastBytes; j++) { int v = array[b]; sb.Append(v is > 31 and < 127 or > 159 ? (char)v : '.'); diff --git a/StringHandlers.cs b/StringHandlers.cs index d00e1e089..2238a3e4b 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -30,11 +30,11 @@ // Copyright © 2011-2022 Natalia Portillo // ****************************************************************************/ -namespace Aaru.Helpers; - using System; using System.Text; +namespace Aaru.Helpers; + /// Helper operations to work with strings public static class StringHandlers { @@ -54,7 +54,7 @@ public static string CToString(byte[] cString, Encoding encoding, bool twoBytes if(cString == null) return null; - var len = 0; + int len = 0; for(int i = start; i < cString.Length; i++) { @@ -78,7 +78,7 @@ public static string CToString(byte[] cString, Encoding encoding, bool twoBytes if(twoBytes && len % 2 > 0) len--; - var dest = new byte[len]; + byte[] dest = new byte[len]; Array.Copy(cString, start, dest, 0, len); return len == 0 ? "" : encoding.GetString(dest); @@ -100,7 +100,7 @@ public static string PascalToString(byte[] pascalString, Encoding encoding, int return null; byte length = pascalString[start]; - var len = 0; + int len = 0; for(int i = start + 1; i < length + 1 && i < pascalString.Length; i++) { @@ -110,7 +110,7 @@ public static string PascalToString(byte[] pascalString, Encoding encoding, int len++; } - var dest = new byte[len]; + byte[] dest = new byte[len]; Array.Copy(pascalString, start + 1, dest, 0, len); return len == 0 ? "" : encoding.GetString(dest); @@ -156,13 +156,13 @@ public static string SpacePaddedToString(byte[] spacePaddedString, Encoding enco public static string DecompressUnicode(byte[] dstring) { byte compId = dstring[0]; - var temp = ""; + string temp = ""; if(compId != 8 && compId != 16) return null; - for(var byteIndex = 1; byteIndex < dstring.Length;) + for(int byteIndex = 1; byteIndex < dstring.Length;) { ushort unicode; diff --git a/Swapping.cs b/Swapping.cs index cf713265a..3bc76eefc 100644 --- a/Swapping.cs +++ b/Swapping.cs @@ -30,10 +30,10 @@ // Copyright © 2011-2022 Natalia Portillo // ****************************************************************************/ -namespace Aaru.Helpers; - using System.Runtime.CompilerServices; +namespace Aaru.Helpers; + /// Helper operations to work with swapping endians public static class Swapping { From 25b15c9c3368026554fe4ccfd00f9e629c81de90 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 28 Nov 2022 10:22:27 +0000 Subject: [PATCH 199/217] Move all localizable strings from Aaru.Helpers project to resources. --- Aaru.Helpers.csproj | 9 ++++ Aaru.Helpers.csproj.DotSettings | 2 + ArrayFill.cs | 2 +- Localization/Localization.Designer.cs | 60 +++++++++++++++++++++++++++ Localization/Localization.resx | 30 ++++++++++++++ PrintHex.cs | 2 +- 6 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 Aaru.Helpers.csproj.DotSettings create mode 100644 Localization/Localization.Designer.cs create mode 100644 Localization/Localization.resx diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index 914137bcc..46080df1e 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -48,6 +48,11 @@ + + True + True + Localization.resx + @@ -65,6 +70,10 @@ LICENSE.LGPL + + ResXFileCodeGenerator + Localization.Designer.cs + diff --git a/Aaru.Helpers.csproj.DotSettings b/Aaru.Helpers.csproj.DotSettings new file mode 100644 index 000000000..dc0dbdcef --- /dev/null +++ b/Aaru.Helpers.csproj.DotSettings @@ -0,0 +1,2 @@ + + True \ No newline at end of file diff --git a/ArrayFill.cs b/ArrayFill.cs index c3e9e1b0f..bda93c731 100644 --- a/ArrayFill.cs +++ b/ArrayFill.cs @@ -49,7 +49,7 @@ public static void ArrayFill(T[] destinationArray, T[] value) ArgumentNullException.ThrowIfNull(destinationArray); if(value.Length > destinationArray.Length) - throw new ArgumentException("Length of value array must not be more than length of destination"); + throw new ArgumentException(Localization.Length_of_value_array_must_not_be_more_than_length_of_destination); // set the initial array value Array.Copy(value, destinationArray, value.Length); diff --git a/Localization/Localization.Designer.cs b/Localization/Localization.Designer.cs new file mode 100644 index 000000000..4080069a6 --- /dev/null +++ b/Localization/Localization.Designer.cs @@ -0,0 +1,60 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Aaru.Helpers { + using System; + + + [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [System.Diagnostics.DebuggerNonUserCodeAttribute()] + [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Localization { + + private static System.Resources.ResourceManager resourceMan; + + private static System.Globalization.CultureInfo resourceCulture; + + [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Localization() { + } + + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Resources.ResourceManager ResourceManager { + get { + if (object.Equals(null, resourceMan)) { + System.Resources.ResourceManager temp = new System.Resources.ResourceManager("Aaru.Helpers.Localization.Localization", typeof(Localization).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + internal static string Length_of_value_array_must_not_be_more_than_length_of_destination { + get { + return ResourceManager.GetString("Length_of_value_array_must_not_be_more_than_length_of_destination", resourceCulture); + } + } + + internal static string Offset { + get { + return ResourceManager.GetString("Offset", resourceCulture); + } + } + } +} diff --git a/Localization/Localization.resx b/Localization/Localization.resx new file mode 100644 index 000000000..bc6fe314c --- /dev/null +++ b/Localization/Localization.resx @@ -0,0 +1,30 @@ + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089 + + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089 + + + + Length of value array must not be more than length of destination + + + Offset + + \ No newline at end of file diff --git a/PrintHex.cs b/PrintHex.cs index 448b3423c..cc56d2566 100644 --- a/PrintHex.cs +++ b/PrintHex.cs @@ -56,7 +56,7 @@ public static string ByteArrayToHexArrayString(byte[] array, int width = 16, boo // TODO: Color list // TODO: Allow to change width - string str = "Offset"; + string str = Localization.Offset; int rows = array.Length / width; int last = array.Length % width; int offsetLength = $"{array.Length:X}".Length; From c9e8b4dd0fddd6a1c222e583090efdfbf6c178dc Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sat, 3 Dec 2022 16:07:08 +0000 Subject: [PATCH 200/217] Update copyright year. --- Aaru.Helpers.csproj | 2 +- ArrayFill.cs | 2 +- ArrayIsEmpty.cs | 2 +- BigEndianBitConverter.cs | 2 +- BitEndian.cs | 2 +- CHS.cs | 2 +- CompareBytes.cs | 2 +- CountBits.cs | 2 +- DateHandlers.cs | 2 +- Extensions.cs | 2 +- Marshal.cs | 2 +- MarshallingPropertiesAttribute.cs | 2 +- PrintHex.cs | 2 +- StringHandlers.cs | 2 +- Swapping.cs | 2 +- 15 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index 46080df1e..eca1a3132 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -11,7 +11,7 @@ true 6.0.0-alpha8 Claunia.com - Copyright © 2011-2022 Natalia Portillo + Copyright © 2011-2023 Natalia Portillo Aaru Data Preservation Suite Aaru.Helpers $(Version) diff --git a/ArrayFill.cs b/ArrayFill.cs index bda93c731..d37300612 100644 --- a/ArrayFill.cs +++ b/ArrayFill.cs @@ -20,7 +20,7 @@ // Assuming open source. // // ---------------------------------------------------------------------------- -// Copyright © 2011-2022 Natalia Portillo +// Copyright © 2011-2023 Natalia Portillo // Copyright(C) 2014 mykohsu // ****************************************************************************/ diff --git a/ArrayIsEmpty.cs b/ArrayIsEmpty.cs index a8c062ad5..aa8302bfe 100644 --- a/ArrayIsEmpty.cs +++ b/ArrayIsEmpty.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2022 Natalia Portillo +// Copyright © 2011-2023 Natalia Portillo // ****************************************************************************/ using System.Linq; diff --git a/BigEndianBitConverter.cs b/BigEndianBitConverter.cs index f378fed18..dcadf371e 100644 --- a/BigEndianBitConverter.cs +++ b/BigEndianBitConverter.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2022 Natalia Portillo +// Copyright © 2011-2023 Natalia Portillo // ****************************************************************************/ using System; diff --git a/BitEndian.cs b/BitEndian.cs index f85dccc6b..72ae6fdf4 100644 --- a/BitEndian.cs +++ b/BitEndian.cs @@ -33,7 +33,7 @@ // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // ---------------------------------------------------------------------------- -// Copyright © 2011-2022 Natalia Portillo +// Copyright © 2011-2023 Natalia Portillo // ****************************************************************************/ namespace Aaru.Helpers; diff --git a/CHS.cs b/CHS.cs index aa58ff396..d6bd38dde 100644 --- a/CHS.cs +++ b/CHS.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2022 Natalia Portillo +// Copyright © 2011-2023 Natalia Portillo // ****************************************************************************/ namespace Aaru.Helpers; diff --git a/CompareBytes.cs b/CompareBytes.cs index b52a6f774..b60245c2b 100644 --- a/CompareBytes.cs +++ b/CompareBytes.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2022 Natalia Portillo +// Copyright © 2011-2023 Natalia Portillo // ****************************************************************************/ namespace Aaru.Helpers; diff --git a/CountBits.cs b/CountBits.cs index ba50fe767..50460ab98 100644 --- a/CountBits.cs +++ b/CountBits.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2022 Natalia Portillo +// Copyright © 2011-2023 Natalia Portillo // ****************************************************************************/ namespace Aaru.Helpers; diff --git a/DateHandlers.cs b/DateHandlers.cs index 9aecf7af6..8fd4d5ed6 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2022 Natalia Portillo +// Copyright © 2011-2023 Natalia Portillo // ****************************************************************************/ using System; diff --git a/Extensions.cs b/Extensions.cs index cc413ea3c..f43643d63 100644 --- a/Extensions.cs +++ b/Extensions.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2022 Natalia Portillo +// Copyright © 2011-2023 Natalia Portillo // ****************************************************************************/ using System.IO; diff --git a/Marshal.cs b/Marshal.cs index 6bf697f1a..17df2f039 100644 --- a/Marshal.cs +++ b/Marshal.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2022 Natalia Portillo +// Copyright © 2011-2023 Natalia Portillo // ****************************************************************************/ using System; diff --git a/MarshallingPropertiesAttribute.cs b/MarshallingPropertiesAttribute.cs index bb9f7c35c..4dfafe569 100644 --- a/MarshallingPropertiesAttribute.cs +++ b/MarshallingPropertiesAttribute.cs @@ -33,7 +33,7 @@ // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // ---------------------------------------------------------------------------- -// Copyright © 2011-2022 Natalia Portillo +// Copyright © 2011-2023 Natalia Portillo // ****************************************************************************/ using System; diff --git a/PrintHex.cs b/PrintHex.cs index cc56d2566..df4b5a99a 100644 --- a/PrintHex.cs +++ b/PrintHex.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2022 Natalia Portillo +// Copyright © 2011-2023 Natalia Portillo // ****************************************************************************/ using System.Text; diff --git a/StringHandlers.cs b/StringHandlers.cs index 2238a3e4b..8247656d0 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2022 Natalia Portillo +// Copyright © 2011-2023 Natalia Portillo // ****************************************************************************/ using System; diff --git a/Swapping.cs b/Swapping.cs index 3bc76eefc..b25403913 100644 --- a/Swapping.cs +++ b/Swapping.cs @@ -27,7 +27,7 @@ // License along with this library; if not, see . // // ---------------------------------------------------------------------------- -// Copyright © 2011-2022 Natalia Portillo +// Copyright © 2011-2023 Natalia Portillo // ****************************************************************************/ using System.Runtime.CompilerServices; From e4ca717ef56a83f2b862bba42e8bab121267a6b3 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 6 Dec 2022 22:14:03 +0000 Subject: [PATCH 201/217] Enable default compile items. --- Aaru.Helpers.csproj | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index eca1a3132..6f3c97d06 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -7,7 +7,6 @@ Aaru.Helpers Aaru.Helpers $(Version) - false true 6.0.0-alpha8 Claunia.com @@ -42,27 +41,6 @@ true true - - - - - - - - True - True - Localization.resx - - - - - - - - - - - From b03390c74bff28cd7c48c27abaf6f013d7e4545c Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Fri, 23 Dec 2022 17:38:02 +0000 Subject: [PATCH 202/217] Bump version to v6.0.0-alpha9. --- Aaru.Helpers.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index 6f3c97d06..628a1ecc4 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -8,7 +8,7 @@ Aaru.Helpers $(Version) true - 6.0.0-alpha8 + 6.0.0-alpha9 Claunia.com Copyright © 2011-2023 Natalia Portillo Aaru Data Preservation Suite From 88caaa77e71092966ba5a8f3254b90d1d24b61ca Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 24 Sep 2023 21:48:58 +0100 Subject: [PATCH 203/217] Update to .NET 8.0 RC1. --- Aaru.Helpers.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers.csproj index 628a1ecc4..02a2e0461 100644 --- a/Aaru.Helpers.csproj +++ b/Aaru.Helpers.csproj @@ -14,8 +14,8 @@ Aaru Data Preservation Suite Aaru.Helpers $(Version) - net7.0 - 11 + net8.0 + 12 Contains helpers used by the Aaru Data Preservation Suite. https://github.com/aaru-dps/ LGPL-2.1-only From 12ef48cf9889f8af30c14a7f2ed979ed100181a1 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 27 Sep 2023 00:46:24 +0100 Subject: [PATCH 204/217] Translate Aaru.Helpers to Spanish (Spain). --- Localization/Localization.es.resx | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Localization/Localization.es.resx diff --git a/Localization/Localization.es.resx b/Localization/Localization.es.resx new file mode 100644 index 000000000..abef6d011 --- /dev/null +++ b/Localization/Localization.es.resx @@ -0,0 +1,20 @@ + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Compensación + + + La longitud de una colección no puede ser mayor que la longitud del destino + + \ No newline at end of file From d2559f07c97e834f927c742dbf46f202bc3338ed Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 3 Oct 2023 17:52:21 +0100 Subject: [PATCH 205/217] [Aaru.Helpers] Introduced constants for module names Introduces constant fields for respective debug module names, replacing the hardcoded ones. This is done to standardize the naming convention, reduce redundancy and potentially avoid any typos or name mismatches across the project. This change makes the code more maintainable and easier to update in case module names need to be changed. --- DateHandlers.cs | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/DateHandlers.cs b/DateHandlers.cs index 8fd4d5ed6..1c83dfa8a 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -39,9 +39,12 @@ namespace Aaru.Helpers; /// Helper operations for timestamp management (date and time) public static class DateHandlers { - static readonly DateTime _lisaEpoch = new(1901, 1, 1, 0, 0, 0); - static readonly DateTime _macEpoch = new(1904, 1, 1, 0, 0, 0); - static readonly DateTime _unixEpoch = new(1970, 1, 1, 0, 0, 0); + const string ISO9660_MODULE_NAME = "ISO9600ToDateTime handler"; + const string PASCAL_MODULE_NAME = "UCSDPascalToDateTime handler"; + const string DOS_MODULE_NAME = "DOSToDateTime handler"; + static readonly DateTime _lisaEpoch = new(1901, 1, 1, 0, 0, 0); + static readonly DateTime _macEpoch = new(1904, 1, 1, 0, 0, 0); + static readonly DateTime _unixEpoch = new(1970, 1, 1, 0, 0, 0); /// Day 0 of Julian Date system static readonly DateTime _julianEpoch = new(1858, 11, 17, 0, 0, 0); static readonly DateTime _amigaEpoch = new(1978, 1, 1, 0, 0, 0); @@ -108,7 +111,7 @@ public static DateTime Iso9660ToDateTime(byte[] vdDateTime) fourCharValue[2] = vdDateTime[2]; fourCharValue[3] = vdDateTime[3]; - AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "year = \"{0}\"", + AaruConsole.DebugWriteLine(ISO9660_MODULE_NAME, "year = \"{0}\"", StringHandlers.CToString(fourCharValue, Encoding.ASCII)); if(!int.TryParse(StringHandlers.CToString(fourCharValue, Encoding.ASCII), out int year)) @@ -117,7 +120,7 @@ public static DateTime Iso9660ToDateTime(byte[] vdDateTime) twoCharValue[0] = vdDateTime[4]; twoCharValue[1] = vdDateTime[5]; - AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "month = \"{0}\"", + AaruConsole.DebugWriteLine(ISO9660_MODULE_NAME, "month = \"{0}\"", StringHandlers.CToString(twoCharValue, Encoding.ASCII)); if(!int.TryParse(StringHandlers.CToString(twoCharValue, Encoding.ASCII), out int month)) @@ -126,7 +129,7 @@ public static DateTime Iso9660ToDateTime(byte[] vdDateTime) twoCharValue[0] = vdDateTime[6]; twoCharValue[1] = vdDateTime[7]; - AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "day = \"{0}\"", + AaruConsole.DebugWriteLine(ISO9660_MODULE_NAME, "day = \"{0}\"", StringHandlers.CToString(twoCharValue, Encoding.ASCII)); if(!int.TryParse(StringHandlers.CToString(twoCharValue, Encoding.ASCII), out int day)) @@ -135,7 +138,7 @@ public static DateTime Iso9660ToDateTime(byte[] vdDateTime) twoCharValue[0] = vdDateTime[8]; twoCharValue[1] = vdDateTime[9]; - AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "hour = \"{0}\"", + AaruConsole.DebugWriteLine(ISO9660_MODULE_NAME, "hour = \"{0}\"", StringHandlers.CToString(twoCharValue, Encoding.ASCII)); if(!int.TryParse(StringHandlers.CToString(twoCharValue, Encoding.ASCII), out int hour)) @@ -144,7 +147,7 @@ public static DateTime Iso9660ToDateTime(byte[] vdDateTime) twoCharValue[0] = vdDateTime[10]; twoCharValue[1] = vdDateTime[11]; - AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "minute = \"{0}\"", + AaruConsole.DebugWriteLine(ISO9660_MODULE_NAME, "minute = \"{0}\"", StringHandlers.CToString(twoCharValue, Encoding.ASCII)); if(!int.TryParse(StringHandlers.CToString(twoCharValue, Encoding.ASCII), out int minute)) @@ -153,7 +156,7 @@ public static DateTime Iso9660ToDateTime(byte[] vdDateTime) twoCharValue[0] = vdDateTime[12]; twoCharValue[1] = vdDateTime[13]; - AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "second = \"{0}\"", + AaruConsole.DebugWriteLine(ISO9660_MODULE_NAME, "second = \"{0}\"", StringHandlers.CToString(twoCharValue, Encoding.ASCII)); if(!int.TryParse(StringHandlers.CToString(twoCharValue, Encoding.ASCII), out int second)) @@ -162,13 +165,13 @@ public static DateTime Iso9660ToDateTime(byte[] vdDateTime) twoCharValue[0] = vdDateTime[14]; twoCharValue[1] = vdDateTime[15]; - AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", "hundredths = \"{0}\"", + AaruConsole.DebugWriteLine(ISO9660_MODULE_NAME, "hundredths = \"{0}\"", StringHandlers.CToString(twoCharValue, Encoding.ASCII)); if(!int.TryParse(StringHandlers.CToString(twoCharValue, Encoding.ASCII), out int hundredths)) hundredths = 0; - AaruConsole.DebugWriteLine("ISO9600ToDateTime handler", + AaruConsole.DebugWriteLine(ISO9660_MODULE_NAME, "decodedDT = new DateTime({0}, {1}, {2}, {3}, {4}, {5}, {6}, DateTimeKind.Unspecified);", year, month, day, hour, minute, second, hundredths * 10); @@ -212,7 +215,7 @@ public static DateTime UcsdPascalToDateTime(short dateRecord) int day = (dateRecord & 0x01F0) >> 4; int month = dateRecord & 0x000F; - AaruConsole.DebugWriteLine("UCSDPascalToDateTime handler", + AaruConsole.DebugWriteLine(PASCAL_MODULE_NAME, "dateRecord = 0x{0:X4}, year = {1}, month = {2}, day = {3}", dateRecord, year, month, day); @@ -232,10 +235,10 @@ public static DateTime DosToDateTime(ushort date, ushort time) int minute = (time & 0x7E0) >> 5; int second = (time & 0x1F) * 2; - AaruConsole.DebugWriteLine("DOSToDateTime handler", "date = 0x{0:X4}, year = {1}, month = {2}, day = {3}", date, + AaruConsole.DebugWriteLine(DOS_MODULE_NAME, "date = 0x{0:X4}, year = {1}, month = {2}, day = {3}", date, year, month, day); - AaruConsole.DebugWriteLine("DOSToDateTime handler", "time = 0x{0:X4}, hour = {1}, minute = {2}, second = {3}", + AaruConsole.DebugWriteLine(DOS_MODULE_NAME, "time = 0x{0:X4}, hour = {1}, minute = {2}, second = {3}", time, hour, minute, second); DateTime dosDate; From 4806a311ea713d6df669f76bea7d96db5c3fc377 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 3 Oct 2023 21:05:01 +0100 Subject: [PATCH 206/217] Update style configuration. --- .editorconfig | 1886 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 1292 insertions(+), 594 deletions(-) diff --git a/.editorconfig b/.editorconfig index 7586c80d3..fd4cb0e6b 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,631 +1,1329 @@ [*] charset = utf-8 -next_line = crlf -insert_final_newline = false -indent_style = space +end_of_line = lf indent_size = 4 - -# Generic non-language specific ones for Resharper and friends -brace_style = next_line -int_align = true -keep_existing_arrangement = false -place_simple_blocks_on_single_line = true -place_simple_declaration_blocks_on_single_line = true -place_attribute_on_same_line = false -space_after_unary_operator = false -space_after_comma = true -space_around_ternary_operator = true -space_around_binary_operator = true -space_around_member_access_operator = false -space_before_open_square_brackets = false -space_after_keywords_in_control_flow_statements = true -space_before_comma = false -space_between_method_call_name_and_opening_parenthesis = false -space_between_method_declaration_name_and_open_parenthesis = false -space_between_square_brackets = false -space_between_parentheses_of_control_flow_statements = false -accessor_owner_declaration_braces = next_line -accessor_declaration_braces = next_line -case_block_braces = next_line -initializer_braces = next_line -other_braces = next_line -allow_comment_after_lbrace = false -empty_block_style = together_same_line -braces_for_ifelse = not_required -braces_for_for = not_required -braces_for_foreach = not_required -braces_for_while = not_required -braces_for_dowhile = not_required -braces_for_using = not_required -braces_for_lock = not_required -braces_for_fixed = not_required -method_or_operator_body = expression_body -local_function_body = expression_body -constructor_or_destructor_body = expression_body -accessor_owner_body = expression_body -force_attribute_style = join -function_braces = next_line -force_control_statements_braces = always_remove -space_in_singleline_accessorholder = true -type_declaration_braces = next_line -invocable_declaration_braces = next_line -anonymous_method_declaration_braces = next_line -space_between_accessors_in_singleline_property = true -indent_nested_usings_stmt = true -space_within_empty_braces = false -indent_nested_fixed_stmt = true -indent_nested_lock_stmt = true -indent_nested_for_stmt = true -indent_nested_foreach_stmt = true -indent_nested_while_stmt = true -use_continuous_indent_inside_parens = true -indent_method_decl_pars = inside -indent_invocation_pars = inside -indent_statement_pars = inside -indent_typeparam_angles = inside -indent_typearg_angles = inside -indent_pars = inside -indent_preprocessor_if = outdent -indent_preprocessor_region = usual_indent -indent_preprocessor_other = usual_indent -indent_switch_labels = true -indent_type_constraints = true -stick_comment = false -alignment_tab_fill_style = use_spaces -align_multiline_parameter = true -align_multiline_extends_list = true -align_linq_query = true -align_multiline_binary_expressions_chain = true -outdent_binary_ops = true -align_multiline_calls_chain = true -outdent_dots = true -align_multiline_array_and_object_initializer = false -indent_anonymous_method_block = false -align_first_arg_by_paren = true -align_multiline_argument = true -align_tuple_components = true -align_multiline_expression = true -align_multiline_for_stmt = true -align_multiple_declaration = true -align_multline_type_parameter_list = true -align_multline_type_parameter_constrains = true -int_align_fields = true -int_align_properties = true -int_align_methods = true -int_align_parameters = false -int_align_variables = true -int_align_assignments = true -int_align_nested_ternary = true -int_align_invocations = false -int_align_binary_expressions = true -int_align_comments = true -int_align_switch_sections = true -keep_user_linebreaks = false -keep_existing_arrangement = false -keep_existing_linebreaks = false +indent_style = space +insert_final_newline = false max_line_length = 120 -wrap_before_comma = false -special_else_if_treatment = true -place_type_attribute_on_same_line = never -place_method_attribute_on_same_line = never -place_accessorholder_attribute_on_same_line = never -place_attribute_on_same_line = never -place_accessor_attribute_on_same_line = never -place_attribute_on_same_line = never -place_field_attribute_on_same_line = never -place_attribute_on_same_line = never -wrap_parameters_style = wrap_if_long -keep_existing_declaration_parens_arrangement = false -wrap_before_declaration_lpar = false -wrap_after_declaration_lpar = false -wrap_before_declaration_rpar = false -place_constructor_initializer_on_same_line = true -keep_existing_expr_member_arrangement = false -place_expr_method_on_single_line = true -place_expr_property_on_single_line = true -place_expr_accessor_on_single_line = true -wrap_before_arrow_with_expressions = false -place_type_constraints_on_same_line = true -wrap_before_first_type_parameter_constraint = true -wrap_multiple_type_parameter_constraints_style = wrap_if_long -wrap_before_type_parameter_langle = true -wrap_before_extends_colon = false -wrap_extends_list_style = wrap_if_long -keep_existing_declaration_block_arrangement = false -place_abstract_accessorholder_on_single_line = true -place_simple_accessorholder_on_single_line = false -place_accessor_with_attrs_holder_on_single_line = false -place_simple_accessor_on_single_line = true -place_simple_method_on_single_line = false -keep_existing_enum_arrangement = false -place_simple_enum_on_single_line = false -wrap_enum_declaration = wrap_if_long -new_line_before_else = true -new_line_before_while = false -wrap_for_stmt_header_style = wrap_if_long -wrap_multiple_declaration_style = wrap_if_long -keep_existing_embedded_arrangement = false -place_simple_embedded_statement_on_same_line = false -place_simple_case_statement_on_same_line = true -keep_existing_embedded_block_arrangement = false -place_simple_embedded_block_on_same_line = false -place_simple_anonymousmethod_on_single_line = false -keep_existing_initializer_arrangement = false -place_simple_initializer_on_single_line = false -wrap_object_and_collection_initializer_style = chop_always -wrap_array_initializer_style = wrap_if_long -wrap_arguments_style = wrap_if_long -keep_existing_invocation_parens_arrangement = false -wrap_after_invocation_lpar = false -wrap_before_invocation_rpar = false -wrap_after_dot_in_method_calls = true -wrap_chained_method_calls = wrap_if_long -wrap_before_binary_opsign = false -wrap_chained_binary_expressions = wrap_if_long -force_chop_compound_if_expression = true -force_chop_compound_while_expression = true -force_chop_compound_do_expression = true -wrap_before_ternary_opsigns = true -wrap_ternary_expr_style = wrap_if_long -nested_ternary_style = expanded -wrap_linq_expressions = wrap_if_long -wrap_before_linq_expression = false -place_linq_into_on_new_line = false -wrap_verbatim_interpolated_strings = wrap_if_long -extra_spaces = remove_all -space_after_keywords_in_control_flow_statements = false -space_between_method_call_name_and_opening_parenthesis = false -space_between_method_declaration_name_and_open_parenthesis = false -space_before_typeof_parentheses = false -space_before_checked_parentheses = false -space_before_sizeof_parentheses = false -space_before_nameof_parentheses = false -space_between_keyword_and_expression = true -space_between_keyword_and_type = true -space_around_assignment_op = true -space_around_logical_op = true -space_around_binary_operator = true -space_around_equality_op = true -space_around_relational_op = true -space_around_bitwise_op = true -space_around_additive_op = true -space_around_multiplicative_op = true -space_around_shift_op = true -space_around_nullcoalescing_op = true -space_around_arrow_op = false -space_after_logical_not_op = false -space_after_unary_operator = false -space_after_cast = false -space_around_dot = false -space_around_lambda_arrow = true -space_before_pointer_asterik_declaration = false -space_before_nullable_mark = false -blank_lines_around_class_definition = 1 -namespace_indentation = all -space_within_template_argument = false -align_union_type_usage = true -space_in_singleline_method = true -space_in_singleline_anonymous_method = true -space_within_single_line_array_initializer_braces = true -space_around_arrow_op = false +tab_width = 4 +trim_trailing_whitespace = false +ij_continuation_indent_size = 8 +ij_formatter_off_tag = @formatter:off +ij_formatter_on_tag = @formatter:on +ij_formatter_tags_enabled = true +ij_smart_tabs = false +ij_visual_guides = +ij_wrap_on_typing = false -# These are for markup languages (HTML, XML, etc) -spaces_around_eq_in_pi_attribute = false -space_after_last_pi_attribute = true -pi_attributes_indent = align_by_first_attribute -blank_line_after_pi = true -spaces_around_eq_in_attribute = false -space_after_last_attribute = false -space_before_self_closing = true -attribute_style = on_single_line -attribute_indent = align_by_first_attribute -sort_attributes = true -sort_class_selectors = true -max_blank_lines_between_tags = 0 -linebreak_before_all_elements = true -linebreak_before_multiline_elements = true -quote_style = doublequoted -delete_quotes_from_solid_values = false -normalize_tag_names = true +# Microsoft .NET properties +csharp_preferred_modifier_order = public, private, protected, internal, file, new, static, abstract, virtual, sealed, readonly, override, extern, unsafe, volatile, async, required:suggestion +csharp_space_after_keywords_in_control_flow_statements = false +csharp_style_namespace_declarations = file_scoped:warning +csharp_style_prefer_utf8_string_literals = true:warning +csharp_style_var_elsewhere = false:none +csharp_style_var_for_built_in_types = false:suggestion +csharp_using_directive_placement = inside_namespace:silent +dotnet_naming_rule.private_constants_rule.import_to_resharper = as_predefined +dotnet_naming_rule.private_constants_rule.severity = warning +dotnet_naming_rule.private_constants_rule.style = all_upper_style +dotnet_naming_rule.private_constants_rule.symbols = private_constants_symbols +dotnet_naming_rule.unity_serialized_field_rule.import_to_resharper = True +dotnet_naming_rule.unity_serialized_field_rule.resharper_description = Unity serialized field +dotnet_naming_rule.unity_serialized_field_rule.resharper_guid = 5f0fdb63-c892-4d2c-9324-15c80b22a7ef +dotnet_naming_rule.unity_serialized_field_rule.severity = warning +dotnet_naming_rule.unity_serialized_field_rule.style = lower_camel_case_style +dotnet_naming_rule.unity_serialized_field_rule.symbols = unity_serialized_field_symbols +dotnet_naming_style.all_upper_style.capitalization = all_upper +dotnet_naming_style.all_upper_style.word_separator = _ +dotnet_naming_style.lower_camel_case_style.capitalization = camel_case +dotnet_naming_symbols.private_constants_symbols.applicable_accessibilities = private +dotnet_naming_symbols.private_constants_symbols.applicable_kinds = field +dotnet_naming_symbols.private_constants_symbols.required_modifiers = const +dotnet_naming_symbols.unity_serialized_field_symbols.applicable_accessibilities = * +dotnet_naming_symbols.unity_serialized_field_symbols.applicable_kinds = +dotnet_naming_symbols.unity_serialized_field_symbols.resharper_applicable_kinds = unity_serialised_field +dotnet_naming_symbols.unity_serialized_field_symbols.resharper_required_modifiers = instance +dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:warning +dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:warning +dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary:warning +dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion +dotnet_style_predefined_type_for_member_access = true:suggestion +dotnet_style_qualification_for_event = false:suggestion +dotnet_style_qualification_for_field = false:suggestion +dotnet_style_qualification_for_method = false:suggestion +dotnet_style_qualification_for_property = false:suggestion +dotnet_style_require_accessibility_modifiers = never:suggestion +# ReSharper properties +resharper_align_linq_query = true +resharper_align_multiline_argument = true +resharper_align_multiline_array_and_object_initializer = true +resharper_align_multiline_binary_expressions_chain = true +resharper_align_multiline_binary_patterns = true +resharper_align_multiline_calls_chain = true +resharper_align_multiline_expression = true +resharper_align_multiline_expression_braces = true +resharper_align_multiline_extends_list = true +resharper_align_multiline_for_stmt = true +resharper_align_multiline_list_pattern = true +resharper_align_multiline_parameter = true +resharper_align_multiline_property_pattern = true +resharper_align_multiline_switch_expression = true +resharper_align_multiple_declaration = true +resharper_align_multline_type_parameter_constrains = true +resharper_align_multline_type_parameter_list = true +resharper_align_ternary = align_all +resharper_align_tuple_components = true +resharper_autodetect_indent_settings = true +resharper_braces_for_for = required_for_multiline +resharper_braces_for_foreach = required_for_multiline +resharper_braces_for_ifelse = required_for_multiline +resharper_braces_for_while = required_for_multiline +resharper_builtin_type_apply_to_native_integer = true +resharper_constructor_or_destructor_body = expression_body +resharper_csharp_align_first_arg_by_paren = true +resharper_csharp_empty_block_style = together_same_line +resharper_csharp_place_comments_at_first_column = true +resharper_default_value_when_type_not_evident = default_expression +resharper_enforce_line_ending_style = true +resharper_formatter_off_tag = @formatter:off +resharper_formatter_on_tag = @formatter:on +resharper_formatter_tags_enabled = true +resharper_for_built_in_types = use_var_when_evident +resharper_function_declaration_return_type_style = on_single_line +resharper_function_definition_return_type_style = on_single_line +resharper_html_pi_attribute_style = first_attribute_on_single_line +resharper_indent_anonymous_method_block = true +resharper_indent_preprocessor_if = outdent +resharper_indent_preprocessor_other = outdent +resharper_indent_preprocessor_region = outdent +resharper_int_align = true +resharper_int_align_bitfield_sizes = true +resharper_int_align_comments = true +resharper_int_align_declaration_names = true +resharper_int_align_enum_initializers = true +resharper_int_align_eq = true +resharper_keep_existing_embedded_arrangement = false +resharper_keep_existing_initializer_arrangement = false +resharper_keep_existing_list_patterns_arrangement = false +resharper_keep_existing_property_patterns_arrangement = false +resharper_keep_existing_switch_expression_arrangement = false +resharper_line_break_after_colon_in_member_initializer_lists = on_single_line +resharper_line_break_before_requires_clause = on_single_line +resharper_linkage_specification_indentation = all +resharper_local_function_body = expression_body +resharper_member_initializer_list_style = on_single_line +resharper_method_or_operator_body = expression_body +resharper_outdent_binary_ops = true +resharper_outdent_binary_pattern_ops = true +resharper_outdent_commas = true +resharper_outdent_dots = true +resharper_outdent_statement_labels = true +resharper_parentheses_redundancy_style = remove +resharper_place_attribute_on_same_line = false +resharper_show_autodetect_configure_formatting_tip = false +resharper_simple_block_style = on_single_line +resharper_simple_case_statement_style = line_break +resharper_simple_embedded_statement_style = on_single_line +resharper_space_after_ptr_in_data_member = false +resharper_space_after_ptr_in_method = false +resharper_space_after_ref_in_data_member = false +resharper_space_after_ref_in_method = false +resharper_space_before_ptr_in_data_member = true +resharper_space_before_ptr_in_method = true +resharper_space_before_ref_in_data_member = true +resharper_space_before_ref_in_method = true +resharper_space_before_template_params = false +resharper_space_within_empty_braces = false +resharper_toplevel_function_declaration_return_type_style = on_single_line +resharper_toplevel_function_definition_return_type_style = on_single_line +resharper_use_indent_from_vs = false +resharper_wrap_base_clause_style = chop_if_long +resharper_wrap_braced_init_list_style = chop_if_long +resharper_wrap_ctor_initializer_style = chop_if_long +resharper_wrap_lines = true +resharper_xmldoc_attribute_indent = align_by_first_attribute +resharper_xmldoc_attribute_style = first_attribute_on_single_line +resharper_xmldoc_pi_attribute_style = first_attribute_on_single_line -[{.babelrc,.stylelintrc,jest.config,.eslintrc,.prettierrc,*.json,*.jsb3,*.jsb2,*.bowerrc}] -indent_size = 2 +# ReSharper inspection severities +resharper_annotate_can_be_null_parameter_highlighting = warning +resharper_annotate_can_be_null_type_member_highlighting = warning +resharper_annotate_not_null_parameter_highlighting = warning +resharper_annotate_not_null_type_member_highlighting = warning +resharper_arguments_style_anonymous_function_highlighting = warning +resharper_arguments_style_literal_highlighting = warning +resharper_arguments_style_named_expression_highlighting = warning +resharper_arguments_style_other_highlighting = warning +resharper_arguments_style_string_literal_highlighting = warning +resharper_arrange_accessor_owner_body_highlighting = warning +resharper_arrange_constructor_or_destructor_body_highlighting = warning +resharper_arrange_local_function_body_highlighting = warning +resharper_arrange_method_or_operator_body_highlighting = warning +resharper_arrange_redundant_parentheses_highlighting = hint +resharper_arrange_static_member_qualifier_highlighting = warning +resharper_arrange_this_qualifier_highlighting = hint +resharper_arrange_trailing_comma_in_multiline_lists_highlighting = warning +resharper_arrange_trailing_comma_in_singleline_lists_highlighting = warning +resharper_arrange_type_member_modifiers_highlighting = hint +resharper_arrange_type_modifiers_highlighting = hint +resharper_arrange_var_keywords_in_deconstructing_declaration_highlighting = warning +resharper_async_void_method_highlighting = warning +resharper_auto_property_can_be_made_get_only_global_highlighting = warning +resharper_auto_property_can_be_made_get_only_local_highlighting = warning +resharper_bad_attribute_brackets_spaces_highlighting = warning +resharper_bad_braces_spaces_highlighting = warning +resharper_bad_colon_spaces_highlighting = warning +resharper_bad_comma_spaces_highlighting = warning +resharper_bad_control_braces_indent_highlighting = warning +resharper_bad_control_braces_line_breaks_highlighting = warning +resharper_bad_declaration_braces_indent_highlighting = warning +resharper_bad_declaration_braces_line_breaks_highlighting = warning +resharper_bad_empty_braces_line_breaks_highlighting = warning +resharper_bad_expression_braces_indent_highlighting = warning +resharper_bad_expression_braces_line_breaks_highlighting = warning +resharper_bad_generic_brackets_spaces_highlighting = warning +resharper_bad_indent_highlighting = warning +resharper_bad_linq_line_breaks_highlighting = warning +resharper_bad_member_access_spaces_highlighting = warning +resharper_bad_namespace_braces_indent_highlighting = warning +resharper_bad_parens_line_breaks_highlighting = warning +resharper_bad_parens_spaces_highlighting = warning +resharper_bad_preprocessor_indent_highlighting = warning +resharper_bad_semicolon_spaces_highlighting = warning +resharper_bad_spaces_after_keyword_highlighting = warning +resharper_bad_square_brackets_spaces_highlighting = warning +resharper_bad_switch_braces_indent_highlighting = warning +resharper_bad_symbol_spaces_highlighting = warning +resharper_built_in_type_reference_style_for_member_access_highlighting = hint +resharper_built_in_type_reference_style_highlighting = hint +resharper_check_for_reference_equality_instead_1_highlighting = warning +resharper_check_for_reference_equality_instead_2_highlighting = warning +resharper_check_for_reference_equality_instead_3_highlighting = warning +resharper_check_for_reference_equality_instead_4_highlighting = warning +resharper_class_can_be_sealed_global_highlighting = warning +resharper_class_can_be_sealed_local_highlighting = warning +resharper_class_never_instantiated_global_highlighting = warning +resharper_class_never_instantiated_local_highlighting = warning +resharper_class_with_virtual_members_never_inherited_global_highlighting = warning +resharper_class_with_virtual_members_never_inherited_local_highlighting = warning +resharper_comment_typo_highlighting = none +resharper_compare_non_constrained_generic_with_null_highlighting = warning +resharper_convert_closure_to_method_group_highlighting = warning +resharper_convert_conditional_ternary_expression_to_switch_expression_highlighting = warning +resharper_convert_if_do_to_while_highlighting = warning +resharper_convert_if_statement_to_conditional_ternary_expression_highlighting = warning +resharper_convert_if_statement_to_null_coalescing_assignment_highlighting = warning +resharper_convert_if_statement_to_null_coalescing_expression_highlighting = warning +resharper_convert_if_statement_to_return_statement_highlighting = warning +resharper_convert_if_statement_to_switch_statement_highlighting = warning +resharper_convert_if_to_or_expression_highlighting = warning +resharper_convert_nullable_to_short_form_highlighting = warning +resharper_convert_switch_statement_to_switch_expression_highlighting = warning +resharper_convert_to_auto_property_highlighting = warning +resharper_convert_to_auto_property_when_possible_highlighting = warning +resharper_convert_to_auto_property_with_private_setter_highlighting = warning +resharper_convert_to_compound_assignment_highlighting = warning +resharper_convert_to_constant_global_highlighting = warning +resharper_convert_to_constant_local_highlighting = warning +resharper_convert_to_lambda_expression_highlighting = warning +resharper_convert_to_local_function_highlighting = warning +resharper_convert_to_null_coalescing_compound_assignment_highlighting = warning +resharper_convert_to_primary_constructor_highlighting = warning +resharper_convert_to_static_class_highlighting = warning +resharper_convert_to_using_declaration_highlighting = warning +resharper_cpp_enforce_cv_qualifiers_order_highlighting = hint +resharper_cpp_enforce_cv_qualifiers_placement_highlighting = hint +resharper_cpp_enforce_do_statement_braces_highlighting = hint +resharper_cpp_enforce_for_statement_braces_highlighting = hint +resharper_cpp_enforce_function_declaration_style_highlighting = hint +resharper_cpp_enforce_if_statement_braces_highlighting = hint +resharper_cpp_enforce_type_alias_code_style_highlighting = hint +resharper_cpp_enforce_while_statement_braces_highlighting = hint +resharper_cpp_remove_redundant_braces_highlighting = hint +resharper_double_negation_in_pattern_highlighting = warning +resharper_double_negation_operator_highlighting = warning +resharper_event_never_invoked_global_highlighting = warning +resharper_event_never_subscribed_to_global_highlighting = warning +resharper_event_never_subscribed_to_local_highlighting = warning +resharper_field_can_be_made_read_only_global_highlighting = warning +resharper_field_can_be_made_read_only_local_highlighting = warning +resharper_foreach_can_be_converted_to_query_using_another_get_enumerator_highlighting = warning +resharper_foreach_can_be_partly_converted_to_query_using_another_get_enumerator_highlighting = none +resharper_for_can_be_converted_to_foreach_highlighting = warning +resharper_heap_view_boxing_allocation_highlighting = none +resharper_heap_view_closure_allocation_highlighting = none +resharper_heap_view_delegate_allocation_highlighting = none +resharper_heap_view_object_allocation_evident_highlighting = none +resharper_heap_view_object_allocation_highlighting = none +resharper_identifier_typo_highlighting = none +resharper_incorrect_blank_lines_near_braces_highlighting = warning +resharper_inheritdoc_consider_usage_highlighting = warning +resharper_inline_out_variable_declaration_highlighting = warning +resharper_inline_temporary_variable_highlighting = warning +resharper_introduce_optional_parameters_global_highlighting = warning +resharper_introduce_optional_parameters_local_highlighting = warning +resharper_invert_condition_1_highlighting = warning +resharper_invert_if_highlighting = warning +resharper_invocation_is_skipped_highlighting = warning +resharper_invoke_as_extension_method_highlighting = warning +resharper_join_declaration_and_initializer_highlighting = warning +resharper_join_null_check_with_usage_highlighting = warning +resharper_lambda_expression_must_be_static_highlighting = warning +resharper_local_function_can_be_made_static_highlighting = warning +resharper_loop_can_be_converted_to_query_highlighting = warning +resharper_loop_can_be_partly_converted_to_query_highlighting = warning +resharper_member_can_be_file_local_highlighting = warning +resharper_member_can_be_internal_highlighting = warning +resharper_member_can_be_made_static_global_highlighting = warning +resharper_member_can_be_made_static_local_highlighting = warning +resharper_member_can_be_private_global_highlighting = warning +resharper_member_can_be_private_local_highlighting = warning +resharper_member_can_be_protected_global_highlighting = warning +resharper_member_can_be_protected_local_highlighting = warning +resharper_merge_and_pattern_highlighting = warning +resharper_merge_cast_with_type_check_highlighting = warning +resharper_merge_conditional_expression_highlighting = warning +resharper_merge_into_logical_pattern_highlighting = warning +resharper_merge_into_negated_pattern_highlighting = warning +resharper_merge_into_pattern_highlighting = warning +resharper_merge_nested_property_patterns_highlighting = warning +resharper_merge_sequential_checks_highlighting = warning +resharper_method_has_async_overload_highlighting = warning +resharper_method_has_async_overload_with_cancellation_highlighting = warning +resharper_method_supports_cancellation_highlighting = warning +resharper_missing_blank_lines_highlighting = warning +resharper_missing_linebreak_highlighting = warning +resharper_missing_space_highlighting = warning +resharper_more_specific_foreach_variable_type_available_highlighting = warning +resharper_move_to_existing_positional_deconstruction_pattern_highlighting = warning +resharper_move_variable_declaration_inside_loop_condition_highlighting = warning +resharper_multiple_spaces_highlighting = warning +resharper_multiple_statements_on_one_line_highlighting = warning +resharper_multiple_type_members_on_one_line_highlighting = warning +resharper_negation_of_relational_pattern_highlighting = warning +resharper_negative_equality_expression_highlighting = warning +resharper_nested_string_interpolation_highlighting = warning +resharper_not_accessed_field_global_highlighting = warning +resharper_nullable_warning_suppression_is_used_highlighting = warning +resharper_outdent_is_off_prev_level_highlighting = warning +resharper_out_parameter_value_is_always_discarded_global_highlighting = warning +resharper_parameter_only_used_for_precondition_check_global_highlighting = warning +resharper_parameter_type_can_be_enumerable_global_highlighting = warning +resharper_parameter_type_can_be_enumerable_local_highlighting = warning +resharper_pass_string_interpolation_highlighting = warning +resharper_possible_unintended_queryable_as_enumerable_highlighting = warning +resharper_property_can_be_made_init_only_global_highlighting = warning +resharper_property_can_be_made_init_only_local_highlighting = warning +resharper_public_constructor_in_abstract_class_highlighting = warning +resharper_raw_string_can_be_simplified_highlighting = warning +resharper_redundant_accessor_body_highlighting = warning +resharper_redundant_always_match_subpattern_highlighting = warning +resharper_redundant_array_creation_expression_highlighting = warning +resharper_redundant_attribute_parentheses_highlighting = warning +resharper_redundant_attribute_usage_property_highlighting = warning +resharper_redundant_base_qualifier_highlighting = warning +resharper_redundant_blank_lines_highlighting = warning +resharper_redundant_collection_initializer_element_braces_highlighting = warning +resharper_redundant_configure_await_highlighting = warning +resharper_redundant_declaration_semicolon_highlighting = warning +resharper_redundant_discard_designation_highlighting = warning +resharper_redundant_empty_object_creation_argument_list_highlighting = warning +resharper_redundant_enum_case_label_for_default_section_highlighting = warning +resharper_redundant_explicit_params_array_creation_highlighting = warning +resharper_redundant_fixed_pointer_declaration_highlighting = warning +resharper_redundant_if_else_block_highlighting = warning +resharper_redundant_immediate_delegate_invocation_highlighting = warning +resharper_redundant_is_before_relational_pattern_highlighting = warning +resharper_redundant_lambda_signature_parentheses_highlighting = warning +resharper_redundant_overload_global_highlighting = warning +resharper_redundant_overload_local_highlighting = warning +resharper_redundant_pattern_parentheses_highlighting = warning +resharper_redundant_property_pattern_clause_highlighting = warning +resharper_redundant_query_order_by_ascending_keyword_highlighting = warning +resharper_redundant_range_bound_highlighting = warning +resharper_redundant_readonly_modifier_highlighting = warning +resharper_redundant_space_highlighting = warning +resharper_redundant_string_interpolation_highlighting = warning +resharper_redundant_to_string_call_for_value_type_highlighting = warning +resharper_redundant_verbatim_prefix_highlighting = warning +resharper_redundant_verbatim_string_prefix_highlighting = warning +resharper_redundant_with_expression_highlighting = warning +resharper_remove_constructor_invocation_highlighting = warning +resharper_remove_redundant_braces_highlighting = warning +resharper_remove_redundant_or_statement_false_highlighting = warning +resharper_remove_redundant_or_statement_true_highlighting = warning +resharper_remove_to_list_1_highlighting = warning +resharper_remove_to_list_2_highlighting = warning +resharper_replace_auto_property_with_computed_property_highlighting = warning +resharper_replace_conditional_expression_with_null_coalescing_highlighting = warning +resharper_replace_object_pattern_with_var_pattern_highlighting = warning +resharper_replace_slice_with_range_indexer_highlighting = warning +resharper_replace_substring_with_range_indexer_highlighting = warning +resharper_replace_with_field_keyword_highlighting = warning +resharper_replace_with_first_or_default_1_highlighting = warning +resharper_replace_with_first_or_default_2_highlighting = warning +resharper_replace_with_first_or_default_3_highlighting = warning +resharper_replace_with_first_or_default_4_highlighting = warning +resharper_replace_with_last_or_default_1_highlighting = warning +resharper_replace_with_last_or_default_2_highlighting = warning +resharper_replace_with_last_or_default_3_highlighting = warning +resharper_replace_with_last_or_default_4_highlighting = warning +resharper_replace_with_of_type_1_highlighting = warning +resharper_replace_with_of_type_2_highlighting = warning +resharper_replace_with_of_type_3_highlighting = warning +resharper_replace_with_of_type_any_1_highlighting = warning +resharper_replace_with_of_type_any_2_highlighting = warning +resharper_replace_with_of_type_count_1_highlighting = warning +resharper_replace_with_of_type_count_2_highlighting = warning +resharper_replace_with_of_type_first_1_highlighting = warning +resharper_replace_with_of_type_first_2_highlighting = warning +resharper_replace_with_of_type_first_or_default_1_highlighting = warning +resharper_replace_with_of_type_first_or_default_2_highlighting = warning +resharper_replace_with_of_type_last_1_highlighting = warning +resharper_replace_with_of_type_last_2_highlighting = warning +resharper_replace_with_of_type_last_or_default_1_highlighting = warning +resharper_replace_with_of_type_last_or_default_2_highlighting = warning +resharper_replace_with_of_type_long_count_highlighting = warning +resharper_replace_with_of_type_single_1_highlighting = warning +resharper_replace_with_of_type_single_2_highlighting = warning +resharper_replace_with_of_type_single_or_default_1_highlighting = warning +resharper_replace_with_of_type_single_or_default_2_highlighting = warning +resharper_replace_with_of_type_where_highlighting = warning +resharper_replace_with_simple_assignment_false_highlighting = warning +resharper_replace_with_simple_assignment_true_highlighting = warning +resharper_replace_with_single_assignment_false_highlighting = warning +resharper_replace_with_single_assignment_true_highlighting = warning +resharper_replace_with_single_call_to_any_highlighting = warning +resharper_replace_with_single_call_to_count_highlighting = warning +resharper_replace_with_single_call_to_first_highlighting = warning +resharper_replace_with_single_call_to_first_or_default_highlighting = warning +resharper_replace_with_single_call_to_last_highlighting = warning +resharper_replace_with_single_call_to_last_or_default_highlighting = warning +resharper_replace_with_single_call_to_single_highlighting = warning +resharper_replace_with_single_call_to_single_or_default_highlighting = warning +resharper_replace_with_single_or_default_1_highlighting = warning +resharper_replace_with_single_or_default_2_highlighting = warning +resharper_replace_with_single_or_default_3_highlighting = warning +resharper_replace_with_single_or_default_4_highlighting = warning +resharper_replace_with_string_is_null_or_empty_highlighting = warning +resharper_return_type_can_be_enumerable_global_highlighting = warning +resharper_return_type_can_be_enumerable_local_highlighting = warning +resharper_safe_cast_is_used_as_type_check_highlighting = warning +resharper_separate_control_transfer_statement_highlighting = warning +resharper_similar_anonymous_type_nearby_highlighting = warning +resharper_simplify_conditional_ternary_expression_highlighting = warning +resharper_simplify_linq_expression_use_all_highlighting = warning +resharper_simplify_linq_expression_use_any_highlighting = warning +resharper_simplify_linq_expression_use_min_by_and_max_by_highlighting = warning +resharper_simplify_string_interpolation_highlighting = warning +resharper_specify_string_comparison_highlighting = warning +resharper_string_ends_with_is_culture_specific_highlighting = warning +resharper_string_literal_as_interpolation_argument_highlighting = warning +resharper_string_literal_typo_highlighting = warning +resharper_string_starts_with_is_culture_specific_highlighting = warning +resharper_struct_can_be_made_read_only_highlighting = warning +resharper_struct_member_can_be_made_read_only_highlighting = warning +resharper_suggest_base_type_for_parameter_highlighting = none +resharper_suggest_base_type_for_parameter_in_constructor_highlighting = warning +resharper_suggest_var_or_type_built_in_types_highlighting = hint +resharper_suggest_var_or_type_deconstruction_declarations_highlighting = warning +resharper_suggest_var_or_type_elsewhere_highlighting = hint +resharper_suggest_var_or_type_simple_types_highlighting = hint +resharper_swap_via_deconstruction_highlighting = warning +resharper_switch_expression_handles_some_known_enum_values_with_exception_in_default_highlighting = warning +resharper_switch_statement_handles_some_known_enum_values_with_default_highlighting = none +resharper_switch_statement_missing_some_enum_cases_no_default_highlighting = none +resharper_tabs_and_spaces_mismatch_highlighting = warning +resharper_tabs_are_disallowed_highlighting = warning +resharper_tabs_outside_indent_highlighting = warning +resharper_tail_recursive_call_highlighting = warning +resharper_too_wide_local_variable_scope_highlighting = warning +resharper_try_cast_always_succeeds_highlighting = warning +resharper_try_statements_can_be_merged_highlighting = warning +resharper_type_parameter_can_be_variant_highlighting = warning +resharper_unnecessary_whitespace_highlighting = warning +resharper_unused_member_global_highlighting = warning +resharper_unused_member_hierarchy_global_highlighting = warning +resharper_unused_member_in_super_global_highlighting = warning +resharper_unused_method_return_value_global_highlighting = warning +resharper_unused_parameter_global_highlighting = warning +resharper_unused_type_global_highlighting = warning +resharper_use_array_creation_expression_1_highlighting = warning +resharper_use_array_creation_expression_2_highlighting = warning +resharper_use_array_empty_method_highlighting = warning +resharper_use_await_using_highlighting = warning +resharper_use_cancellation_token_for_i_async_enumerable_highlighting = warning +resharper_use_collection_count_property_highlighting = warning +resharper_use_configure_await_false_highlighting = warning +resharper_use_deconstruction_highlighting = warning +resharper_use_empty_types_field_highlighting = warning +resharper_use_event_args_empty_field_highlighting = warning +resharper_use_format_specifier_in_format_string_highlighting = warning +resharper_use_indexed_property_highlighting = warning +resharper_use_index_from_end_expression_highlighting = warning +resharper_use_is_operator_1_highlighting = warning +resharper_use_is_operator_2_highlighting = warning +resharper_use_method_any_0_highlighting = warning +resharper_use_method_any_1_highlighting = warning +resharper_use_method_any_2_highlighting = warning +resharper_use_method_any_3_highlighting = warning +resharper_use_method_any_4_highlighting = warning +resharper_use_method_is_instance_of_type_highlighting = warning +resharper_use_nameof_expression_for_part_of_the_string_highlighting = warning +resharper_use_nameof_expression_highlighting = warning +resharper_use_nameof_for_dependency_property_highlighting = warning +resharper_use_name_of_instead_of_type_of_highlighting = warning +resharper_use_negated_pattern_in_is_expression_highlighting = warning +resharper_use_negated_pattern_matching_highlighting = warning +resharper_use_nullable_annotation_instead_of_attribute_highlighting = warning +resharper_use_nullable_attributes_supported_by_compiler_highlighting = warning +resharper_use_null_propagation_highlighting = warning +resharper_use_object_or_collection_initializer_highlighting = warning +resharper_use_pattern_matching_highlighting = warning +resharper_use_positional_deconstruction_pattern_highlighting = warning +resharper_use_raw_string_highlighting = warning +resharper_use_string_interpolation_highlighting = warning +resharper_use_switch_case_pattern_variable_highlighting = warning +resharper_use_throw_if_null_method_highlighting = warning +resharper_use_unsigned_right_shift_operator_highlighting = warning +resharper_use_verbatim_string_highlighting = warning +resharper_use_with_expression_to_copy_anonymous_object_highlighting = warning +resharper_use_with_expression_to_copy_record_highlighting = warning +resharper_use_with_expression_to_copy_struct_highlighting = warning +resharper_use_with_expression_to_copy_tuple_highlighting = warning +resharper_virtual_member_never_overridden_global_highlighting = warning +resharper_virtual_member_never_overridden_local_highlighting = warning +resharper_web_config_module_not_resolved_highlighting = warning +resharper_web_config_type_not_resolved_highlighting = warning +resharper_web_config_wrong_module_highlighting = warning +resharper_with_expression_instead_of_initializer_highlighting = warning +resharper_wrong_indent_size_highlighting = warning -[*.js.map] -indent_size = 2 - -[*.{css,scss}] -indent_size = 2 -declarations_style = separate_lines_for_nonsingle -media_query_style = separate_lines -selector_style = same_line -properties_style = separate_lines_for_nonsingle -brace_style = next_line +[*.css] +ij_css_align_closing_brace_with_properties = false +ij_css_blank_lines_around_nested_selector = 1 +ij_css_blank_lines_between_blocks = 1 +ij_css_block_comment_add_space = false +ij_css_brace_placement = end_of_line +ij_css_enforce_quotes_on_format = false +ij_css_hex_color_long_format = false +ij_css_hex_color_lower_case = false +ij_css_hex_color_short_format = false +ij_css_hex_color_upper_case = false +ij_css_keep_blank_lines_in_code = 2 +ij_css_keep_indents_on_empty_lines = false +ij_css_keep_single_line_blocks = false +ij_css_properties_order = font,font-family,font-size,font-weight,font-style,font-variant,font-size-adjust,font-stretch,line-height,position,z-index,top,right,bottom,left,display,visibility,float,clear,overflow,overflow-x,overflow-y,clip,zoom,align-content,align-items,align-self,flex,flex-flow,flex-basis,flex-direction,flex-grow,flex-shrink,flex-wrap,justify-content,order,box-sizing,width,min-width,max-width,height,min-height,max-height,margin,margin-top,margin-right,margin-bottom,margin-left,padding,padding-top,padding-right,padding-bottom,padding-left,table-layout,empty-cells,caption-side,border-spacing,border-collapse,list-style,list-style-position,list-style-type,list-style-image,content,quotes,counter-reset,counter-increment,resize,cursor,user-select,nav-index,nav-up,nav-right,nav-down,nav-left,transition,transition-delay,transition-timing-function,transition-duration,transition-property,transform,transform-origin,animation,animation-name,animation-duration,animation-play-state,animation-timing-function,animation-delay,animation-iteration-count,animation-direction,text-align,text-align-last,vertical-align,white-space,text-decoration,text-emphasis,text-emphasis-color,text-emphasis-style,text-emphasis-position,text-indent,text-justify,letter-spacing,word-spacing,text-outline,text-transform,text-wrap,text-overflow,text-overflow-ellipsis,text-overflow-mode,word-wrap,word-break,tab-size,hyphens,pointer-events,opacity,color,border,border-width,border-style,border-color,border-top,border-top-width,border-top-style,border-top-color,border-right,border-right-width,border-right-style,border-right-color,border-bottom,border-bottom-width,border-bottom-style,border-bottom-color,border-left,border-left-width,border-left-style,border-left-color,border-radius,border-top-left-radius,border-top-right-radius,border-bottom-right-radius,border-bottom-left-radius,border-image,border-image-source,border-image-slice,border-image-width,border-image-outset,border-image-repeat,outline,outline-width,outline-style,outline-color,outline-offset,background,background-color,background-image,background-repeat,background-attachment,background-position,background-position-x,background-position-y,background-clip,background-origin,background-size,box-decoration-break,box-shadow,text-shadow +ij_css_space_after_colon = true +ij_css_space_before_opening_brace = true +ij_css_use_double_quotes = true +ij_css_value_alignment = do_not_align -[{.analysis_options,*.yml,*.yaml}] -indent_size = 2 +[*.csv] +max_line_length = 2147483647 +ij_csv_wrap_long_lines = false +indent_style = tab +tab_width = 1 -# Xml project files -[*.{csproj,vcxproj,vcxproj.filters,proj,nativeproj,locproj}] -indent_size = 2 +[*.dart] +max_line_length = 80 -# Xml files -[*.{xml,stylecop,resx,ruleset}] +[*.less] indent_size = 2 +ij_less_align_closing_brace_with_properties = false +ij_less_blank_lines_around_nested_selector = 1 +ij_less_blank_lines_between_blocks = 1 +ij_less_block_comment_add_space = false +ij_less_brace_placement = 0 +ij_less_enforce_quotes_on_format = false +ij_less_hex_color_long_format = false +ij_less_hex_color_lower_case = false +ij_less_hex_color_short_format = false +ij_less_hex_color_upper_case = false +ij_less_keep_blank_lines_in_code = 2 +ij_less_keep_indents_on_empty_lines = false +ij_less_keep_single_line_blocks = false +ij_less_line_comment_add_space = false +ij_less_line_comment_at_first_column = false +ij_less_properties_order = font,font-family,font-size,font-weight,font-style,font-variant,font-size-adjust,font-stretch,line-height,position,z-index,top,right,bottom,left,display,visibility,float,clear,overflow,overflow-x,overflow-y,clip,zoom,align-content,align-items,align-self,flex,flex-flow,flex-basis,flex-direction,flex-grow,flex-shrink,flex-wrap,justify-content,order,box-sizing,width,min-width,max-width,height,min-height,max-height,margin,margin-top,margin-right,margin-bottom,margin-left,padding,padding-top,padding-right,padding-bottom,padding-left,table-layout,empty-cells,caption-side,border-spacing,border-collapse,list-style,list-style-position,list-style-type,list-style-image,content,quotes,counter-reset,counter-increment,resize,cursor,user-select,nav-index,nav-up,nav-right,nav-down,nav-left,transition,transition-delay,transition-timing-function,transition-duration,transition-property,transform,transform-origin,animation,animation-name,animation-duration,animation-play-state,animation-timing-function,animation-delay,animation-iteration-count,animation-direction,text-align,text-align-last,vertical-align,white-space,text-decoration,text-emphasis,text-emphasis-color,text-emphasis-style,text-emphasis-position,text-indent,text-justify,letter-spacing,word-spacing,text-outline,text-transform,text-wrap,text-overflow,text-overflow-ellipsis,text-overflow-mode,word-wrap,word-break,tab-size,hyphens,pointer-events,opacity,color,border,border-width,border-style,border-color,border-top,border-top-width,border-top-style,border-top-color,border-right,border-right-width,border-right-style,border-right-color,border-bottom,border-bottom-width,border-bottom-style,border-bottom-color,border-left,border-left-width,border-left-style,border-left-color,border-radius,border-top-left-radius,border-top-right-radius,border-bottom-right-radius,border-bottom-left-radius,border-image,border-image-source,border-image-slice,border-image-width,border-image-outset,border-image-repeat,outline,outline-width,outline-style,outline-color,outline-offset,background,background-color,background-image,background-repeat,background-attachment,background-position,background-position-x,background-position-y,background-clip,background-origin,background-size,box-decoration-break,box-shadow,text-shadow +ij_less_space_after_colon = true +ij_less_space_before_opening_brace = true +ij_less_use_double_quotes = true +ij_less_value_alignment = 0 -# Xml config files -[*.{props,targets,config,nuspec}] +[*.pp] indent_size = 2 +tab_width = 2 +ij_continuation_indent_size = 2 +ij_puppet_keep_indents_on_empty_lines = false -# .net files -[*.{cs,vb}] -# These set the this. / Me. -dotnet_style_qualification_for_field = false:warning -dotnet_style_qualification_for_property = false:warning -dotnet_style_qualification_for_method = false:warning -dotnet_style_qualification_for_event = false:warning - -# These make it suggest Int32 instead of int, etc. -dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion -dotnet_style_predefined_type_for_member_access = true:suggestion - -# This controls implicit access modifiers -dotnet_style_require_accessibility_modifiers = never:suggestion - -# Prefer non modified fields to be marked readonly -dotnet_style_readonly_field = true:warning +[*.properties] +ij_properties_align_group_field_declarations = true +ij_properties_keep_blank_lines = false +ij_properties_key_value_delimiter = equals +ij_properties_spaces_around_key_value_delimiter = true -# Parenthesis settings -dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:warning -dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:warning -dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:warning -dotnet_style_parentheses_in_other_operators = always_for_clarity:warning - -dotnet_style_object_initializer = true:suggestion -dotnet_style_collection_initializer = true:suggestion -dotnet_style_explicit_tuple_names = true:error -dotnet_style_prefer_inferred_tuple_names = true:warning -dotnet_style_prefer_inferred_anonymous_type_member_names = true:warning -dotnet_style_prefer_is_null_check_over_reference_equality_method = true:warning -dotnet_style_prefer_conditional_expression_over_return = true:warning -dotnet_style_coalesce_expression = true:warning -dotnet_style_null_propagation = true:error - -dotnet_sort_system_directives_first = true - -# Constants in C style, all-caps -dotnet_naming_rule.constant_fields_caps.symbols = constant_fields -dotnet_naming_rule.constant_fields_caps.severity = warning -dotnet_naming_rule.constant_fields_caps.style = caps_style -dotnet_naming_symbols.constant_fields.applicable_kinds = field -dotnet_naming_symbols.constant_fields.required_modifiers = const -dotnet_naming_style.caps_style.capitalization = all_upper - -# interfaces should be prefixed with I -dotnet_naming_rule.pascal_case_for_interface.severity = error -dotnet_naming_rule.pascal_case_for_interface.symbols = interfaces_fields -dotnet_naming_rule.pascal_case_for_interface.style = pascal_case_interface_style -dotnet_naming_symbols.interfaces_fields.applicable_kinds = interface -dotnet_naming_style.pascal_case_interface_style.required_prefix = I -dotnet_naming_style.pascal_case_interface_style.capitalization = pascal_case - -## internal and private fields should be _camelCase -dotnet_naming_rule.camel_case_for_private_internal_fields.severity = warning -dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields -dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style -dotnet_naming_symbols.private_internal_fields.applicable_kinds = field -dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal -dotnet_naming_style.camel_case_underscore_style.required_prefix = _ -dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case +[*.sass] +indent_size = 2 +ij_sass_align_closing_brace_with_properties = false +ij_sass_blank_lines_around_nested_selector = 1 +ij_sass_blank_lines_between_blocks = 1 +ij_sass_brace_placement = 0 +ij_sass_enforce_quotes_on_format = false +ij_sass_hex_color_long_format = false +ij_sass_hex_color_lower_case = false +ij_sass_hex_color_short_format = false +ij_sass_hex_color_upper_case = false +ij_sass_keep_blank_lines_in_code = 2 +ij_sass_keep_indents_on_empty_lines = false +ij_sass_keep_single_line_blocks = false +ij_sass_line_comment_add_space = false +ij_sass_line_comment_at_first_column = false +ij_sass_properties_order = font,font-family,font-size,font-weight,font-style,font-variant,font-size-adjust,font-stretch,line-height,position,z-index,top,right,bottom,left,display,visibility,float,clear,overflow,overflow-x,overflow-y,clip,zoom,align-content,align-items,align-self,flex,flex-flow,flex-basis,flex-direction,flex-grow,flex-shrink,flex-wrap,justify-content,order,box-sizing,width,min-width,max-width,height,min-height,max-height,margin,margin-top,margin-right,margin-bottom,margin-left,padding,padding-top,padding-right,padding-bottom,padding-left,table-layout,empty-cells,caption-side,border-spacing,border-collapse,list-style,list-style-position,list-style-type,list-style-image,content,quotes,counter-reset,counter-increment,resize,cursor,user-select,nav-index,nav-up,nav-right,nav-down,nav-left,transition,transition-delay,transition-timing-function,transition-duration,transition-property,transform,transform-origin,animation,animation-name,animation-duration,animation-play-state,animation-timing-function,animation-delay,animation-iteration-count,animation-direction,text-align,text-align-last,vertical-align,white-space,text-decoration,text-emphasis,text-emphasis-color,text-emphasis-style,text-emphasis-position,text-indent,text-justify,letter-spacing,word-spacing,text-outline,text-transform,text-wrap,text-overflow,text-overflow-ellipsis,text-overflow-mode,word-wrap,word-break,tab-size,hyphens,pointer-events,opacity,color,border,border-width,border-style,border-color,border-top,border-top-width,border-top-style,border-top-color,border-right,border-right-width,border-right-style,border-right-color,border-bottom,border-bottom-width,border-bottom-style,border-bottom-color,border-left,border-left-width,border-left-style,border-left-color,border-radius,border-top-left-radius,border-top-right-radius,border-bottom-right-radius,border-bottom-left-radius,border-image,border-image-source,border-image-slice,border-image-width,border-image-outset,border-image-repeat,outline,outline-width,outline-style,outline-color,outline-offset,background,background-color,background-image,background-repeat,background-attachment,background-position,background-position-x,background-position-y,background-clip,background-origin,background-size,box-decoration-break,box-shadow,text-shadow +ij_sass_space_after_colon = true +ij_sass_space_before_opening_brace = true +ij_sass_use_double_quotes = true +ij_sass_value_alignment = 0 -# 2018-12-07 NP: This is not yet working in VS2017 -# local variables should be camelCase -#dotnet_naming_rule.camel_case_for_locals.severity = suggestion -#dotnet_naming_rule.camel_case_for_locals.symbols = local_fields -#dotnet_naming_rule.camel_case_for_locals.style = camel_case_style -#dotnet_naming_symbols.local_fields.applicable_kinds = local -#dotnet_naming_style.camel_case_style.capitalization = camel_case +[*.scss] +indent_size = 2 +ij_scss_align_closing_brace_with_properties = false +ij_scss_blank_lines_around_nested_selector = 1 +ij_scss_blank_lines_between_blocks = 1 +ij_scss_block_comment_add_space = false +ij_scss_brace_placement = 0 +ij_scss_enforce_quotes_on_format = false +ij_scss_hex_color_long_format = false +ij_scss_hex_color_lower_case = false +ij_scss_hex_color_short_format = false +ij_scss_hex_color_upper_case = false +ij_scss_keep_blank_lines_in_code = 2 +ij_scss_keep_indents_on_empty_lines = false +ij_scss_keep_single_line_blocks = false +ij_scss_line_comment_add_space = false +ij_scss_line_comment_at_first_column = false +ij_scss_properties_order = font,font-family,font-size,font-weight,font-style,font-variant,font-size-adjust,font-stretch,line-height,position,z-index,top,right,bottom,left,display,visibility,float,clear,overflow,overflow-x,overflow-y,clip,zoom,align-content,align-items,align-self,flex,flex-flow,flex-basis,flex-direction,flex-grow,flex-shrink,flex-wrap,justify-content,order,box-sizing,width,min-width,max-width,height,min-height,max-height,margin,margin-top,margin-right,margin-bottom,margin-left,padding,padding-top,padding-right,padding-bottom,padding-left,table-layout,empty-cells,caption-side,border-spacing,border-collapse,list-style,list-style-position,list-style-type,list-style-image,content,quotes,counter-reset,counter-increment,resize,cursor,user-select,nav-index,nav-up,nav-right,nav-down,nav-left,transition,transition-delay,transition-timing-function,transition-duration,transition-property,transform,transform-origin,animation,animation-name,animation-duration,animation-play-state,animation-timing-function,animation-delay,animation-iteration-count,animation-direction,text-align,text-align-last,vertical-align,white-space,text-decoration,text-emphasis,text-emphasis-color,text-emphasis-style,text-emphasis-position,text-indent,text-justify,letter-spacing,word-spacing,text-outline,text-transform,text-wrap,text-overflow,text-overflow-ellipsis,text-overflow-mode,word-wrap,word-break,tab-size,hyphens,pointer-events,opacity,color,border,border-width,border-style,border-color,border-top,border-top-width,border-top-style,border-top-color,border-right,border-right-width,border-right-style,border-right-color,border-bottom,border-bottom-width,border-bottom-style,border-bottom-color,border-left,border-left-width,border-left-style,border-left-color,border-radius,border-top-left-radius,border-top-right-radius,border-bottom-right-radius,border-bottom-left-radius,border-image,border-image-source,border-image-slice,border-image-width,border-image-outset,border-image-repeat,outline,outline-width,outline-style,outline-color,outline-offset,background,background-color,background-image,background-repeat,background-attachment,background-position,background-position-x,background-position-y,background-clip,background-origin,background-size,box-decoration-break,box-shadow,text-shadow +ij_scss_space_after_colon = true +ij_scss_space_before_opening_brace = true +ij_scss_use_double_quotes = true +ij_scss_value_alignment = 0 -[*.cs] -# var var var -csharp_style_var_for_built_in_types = false:warning -csharp_style_var_when_type_is_apparent = true:suggestion -csharp_style_var_elsewhere = false:warning +[*.slim] +indent_size = 2 +ij_slim_keep_indents_on_empty_lines = false -csharp_style_expression_bodied_methods = when_on_single_line:suggestion -csharp_style_expression_bodied_constructors = when_on_single_line:suggestion -csharp_style_expression_bodied_operators = when_on_single_line:suggestion -csharp_style_expression_bodied_properties = when_on_single_line:suggestion -csharp_style_expression_bodied_indexers = when_on_single_line:suggestion -csharp_style_expression_bodied_accessors = when_on_single_line:suggestion +[*.twig] +ij_twig_keep_indents_on_empty_lines = false +ij_twig_spaces_inside_comments_delimiters = true +ij_twig_spaces_inside_delimiters = true +ij_twig_spaces_inside_variable_delimiters = true -csharp_style_pattern_matching_over_is_with_cast_check = true:warning -csharp_style_pattern_matching_over_as_with_null_check = when_on_single_line:warning +[*.vue] +indent_size = 2 +tab_width = 2 +ij_continuation_indent_size = 4 +ij_vue_indent_children_of_top_level = template +ij_vue_interpolation_new_line_after_start_delimiter = true +ij_vue_interpolation_new_line_before_end_delimiter = true +ij_vue_interpolation_wrap = off +ij_vue_keep_indents_on_empty_lines = false +ij_vue_spaces_within_interpolation_expressions = true -csharp_style_inlined_variable_declaration = true:warning +[.editorconfig] +ij_editorconfig_align_group_field_declarations = true +ij_editorconfig_space_after_colon = false +ij_editorconfig_space_after_comma = true +ij_editorconfig_space_before_colon = false +ij_editorconfig_space_before_comma = false +ij_editorconfig_spaces_around_assignment_operators = true -csharp_prefer_simple_default_expression = true:warning -csharp_style_deconstructed_variable_declaration = false:warning +[{*.ad,*.adoc,*.asciidoc,.asciidoctorconfig}] +ij_asciidoc_blank_lines_after_header = 1 +ij_asciidoc_blank_lines_keep_after_header = 1 +ij_asciidoc_formatting_enabled = true +ij_asciidoc_one_sentence_per_line = true -csharp_style_throw_expression = true:warning -csharp_style_conditional_delegate_call = true:warning +[{*.ant,*.appxmanifest,*.axml,*.cscfg,*.csdef,*.disco,*.dotsettings,*.filelayout,*.fxml,*.jhm,*.jnlp,*.jrxml,*.manifest,*.myapp,*.nuspec,*.rng,*.sdef,*.stylecop,*.svcmap,*.tld,*.wadcfgx,*.webref,*.wsdl,*.xml,*.xsd,*.xsl,*.xslt,*.xul,StyleCop.Cache}] +ij_xml_align_attributes = true +ij_xml_align_text = false +ij_xml_attribute_wrap = on_every_item +ij_xml_block_comment_add_space = false +ij_xml_block_comment_at_first_column = true +ij_xml_keep_blank_lines = 2 +ij_xml_keep_indents_on_empty_lines = false +ij_xml_keep_line_breaks = true +ij_xml_keep_line_breaks_in_text = true +ij_xml_keep_whitespaces = false +ij_xml_keep_whitespaces_around_cdata = preserve +ij_xml_keep_whitespaces_inside_cdata = false +ij_xml_line_comment_at_first_column = true +ij_xml_space_after_tag_name = false +ij_xml_space_around_equals_in_attribute = false +ij_xml_space_inside_empty_tag = false +ij_xml_text_wrap = normal +ij_xml_use_custom_settings = false -csharp_prefer_braces = false +[{*.applescript,*.scpt}] +indent_size = 2 +tab_width = 2 +ij_continuation_indent_size = 4 +ij_applescript_align_multiline_binary_operation = true +ij_applescript_align_multiline_parameters = true +ij_applescript_align_multiline_parameters_in_calls = true +ij_applescript_binary_operation_sign_on_next_line = false +ij_applescript_binary_operation_wrap = off +ij_applescript_block_brace_style = next_line +ij_applescript_call_parameters_new_line_after_left_paren = false +ij_applescript_call_parameters_right_paren_on_new_line = false +ij_applescript_call_parameters_wrap = off +ij_applescript_else_on_new_line = true +ij_applescript_keep_blank_lines_in_code = 2 +ij_applescript_keep_first_column_comment = true +ij_applescript_keep_indents_on_empty_lines = false +ij_applescript_keep_line_breaks = true +ij_applescript_method_brace_style = next_line +ij_applescript_method_parameters_new_line_after_left_paren = false +ij_applescript_method_parameters_right_paren_on_new_line = false +ij_applescript_method_parameters_wrap = off +ij_applescript_parentheses_expression_new_line_after_left_paren = false +ij_applescript_parentheses_expression_right_paren_on_new_line = false +ij_applescript_space_after_colon = true +ij_applescript_space_after_comma = true +ij_applescript_space_after_comma_in_type_arguments = true +ij_applescript_space_before_colon = true +ij_applescript_space_before_comma = false +ij_applescript_space_before_else_keyword = true +ij_applescript_space_before_else_left_brace = true +ij_applescript_space_before_if_parentheses = false +ij_applescript_space_before_method_call_parentheses = false +ij_applescript_space_before_method_left_brace = true +ij_applescript_space_before_method_parentheses = false +ij_applescript_space_before_while_keyword = true +ij_applescript_spaces_around_additive_operators = true +ij_applescript_spaces_around_assignment_operators = true +ij_applescript_spaces_around_equality_operators = true +ij_applescript_spaces_around_logical_operators = true +ij_applescript_spaces_around_multiplicative_operators = true +ij_applescript_spaces_around_relational_operators = true +ij_applescript_spaces_around_shift_operators = true +ij_applescript_spaces_around_unary_operator = false +ij_applescript_spaces_within_if_parentheses = false +ij_applescript_spaces_within_method_call_parentheses = false +ij_applescript_spaces_within_method_parentheses = false +ij_applescript_special_else_if_treatment = true -csharp_new_line_before_open_brace = all -csharp_new_line_before_else = true -csharp_new_line_before_catch = true -csharp_new_line_before_finally = true -csharp_new_line_before_members_in_object_initializers = true -csharp_new_line_before_members_in_anonymous_types = true -csharp_new_line_between_query_expression_clauses = true +[{*.ats,*.cts,*.mts,*.ts}] +ij_continuation_indent_size = 4 +ij_typescript_align_imports = true +ij_typescript_align_multiline_array_initializer_expression = true +ij_typescript_align_multiline_binary_operation = true +ij_typescript_align_multiline_chained_methods = true +ij_typescript_align_multiline_extends_list = false +ij_typescript_align_multiline_for = true +ij_typescript_align_multiline_parameters = true +ij_typescript_align_multiline_parameters_in_calls = true +ij_typescript_align_multiline_ternary_operation = true +ij_typescript_align_object_properties = 1 +ij_typescript_align_union_types = true +ij_typescript_align_var_statements = 2 +ij_typescript_array_initializer_new_line_after_left_brace = false +ij_typescript_array_initializer_right_brace_on_new_line = false +ij_typescript_array_initializer_wrap = on_every_item +ij_typescript_assignment_wrap = on_every_item +ij_typescript_binary_operation_sign_on_next_line = false +ij_typescript_binary_operation_wrap = on_every_item +ij_typescript_blacklist_imports = rxjs/Rx,node_modules/**,**/node_modules/**,@angular/material,@angular/material/typings/** +ij_typescript_blank_lines_after_imports = 1 +ij_typescript_blank_lines_around_class = 1 +ij_typescript_blank_lines_around_field = 0 +ij_typescript_blank_lines_around_field_in_interface = 0 +ij_typescript_blank_lines_around_function = 1 +ij_typescript_blank_lines_around_method = 1 +ij_typescript_blank_lines_around_method_in_interface = 1 +ij_typescript_block_brace_style = next_line +ij_typescript_block_comment_add_space = false +ij_typescript_block_comment_at_first_column = true +ij_typescript_call_parameters_new_line_after_left_paren = false +ij_typescript_call_parameters_right_paren_on_new_line = false +ij_typescript_call_parameters_wrap = on_every_item +ij_typescript_catch_on_new_line = true +ij_typescript_chained_call_dot_on_new_line = true +ij_typescript_class_brace_style = next_line +ij_typescript_comma_on_new_line = false +ij_typescript_do_while_brace_force = always +ij_typescript_else_on_new_line = false +ij_typescript_enforce_trailing_comma = keep +ij_typescript_enum_constants_wrap = on_every_item +ij_typescript_extends_keyword_wrap = normal +ij_typescript_extends_list_wrap = on_every_item +ij_typescript_field_prefix = _ +ij_typescript_file_name_style = relaxed +ij_typescript_finally_on_new_line = true +ij_typescript_for_brace_force = if_multiline +ij_typescript_for_statement_new_line_after_left_paren = false +ij_typescript_for_statement_right_paren_on_new_line = false +ij_typescript_for_statement_wrap = on_every_item +ij_typescript_force_quote_style = true +ij_typescript_force_semicolon_style = true +ij_typescript_function_expression_brace_style = next_line +ij_typescript_if_brace_force = never +ij_typescript_import_merge_members = global +ij_typescript_import_prefer_absolute_path = true +ij_typescript_import_sort_members = true +ij_typescript_import_sort_module_name = true +ij_typescript_import_use_node_resolution = true +ij_typescript_imports_wrap = on_every_item +ij_typescript_indent_case_from_switch = true +ij_typescript_indent_chained_calls = true +ij_typescript_indent_package_children = 0 +ij_typescript_jsdoc_include_types = false +ij_typescript_jsx_attribute_value = braces +ij_typescript_keep_blank_lines_in_code = 2 +ij_typescript_keep_first_column_comment = true +ij_typescript_keep_indents_on_empty_lines = false +ij_typescript_keep_line_breaks = true +ij_typescript_keep_simple_blocks_in_one_line = false +ij_typescript_keep_simple_methods_in_one_line = false +ij_typescript_line_comment_add_space = true +ij_typescript_line_comment_at_first_column = false +ij_typescript_method_brace_style = next_line +ij_typescript_method_call_chain_wrap = on_every_item +ij_typescript_method_parameters_new_line_after_left_paren = false +ij_typescript_method_parameters_right_paren_on_new_line = false +ij_typescript_method_parameters_wrap = on_every_item +ij_typescript_object_literal_wrap = on_every_item +ij_typescript_object_types_wrap = on_every_item +ij_typescript_parentheses_expression_new_line_after_left_paren = false +ij_typescript_parentheses_expression_right_paren_on_new_line = false +ij_typescript_place_assignment_sign_on_next_line = false +ij_typescript_prefer_as_type_cast = false +ij_typescript_prefer_explicit_types_function_expression_returns = false +ij_typescript_prefer_explicit_types_function_returns = false +ij_typescript_prefer_explicit_types_vars_fields = false +ij_typescript_prefer_parameters_wrap = false +ij_typescript_property_prefix = +ij_typescript_reformat_c_style_comments = false +ij_typescript_space_after_colon = true +ij_typescript_space_after_comma = true +ij_typescript_space_after_dots_in_rest_parameter = false +ij_typescript_space_after_generator_mult = true +ij_typescript_space_after_property_colon = true +ij_typescript_space_after_quest = true +ij_typescript_space_after_type_colon = true +ij_typescript_space_after_unary_not = false +ij_typescript_space_before_async_arrow_lparen = false +ij_typescript_space_before_catch_keyword = true +ij_typescript_space_before_catch_left_brace = false +ij_typescript_space_before_catch_parentheses = false +ij_typescript_space_before_class_lbrace = false +ij_typescript_space_before_class_left_brace = true +ij_typescript_space_before_colon = true +ij_typescript_space_before_comma = false +ij_typescript_space_before_do_left_brace = false +ij_typescript_space_before_else_keyword = true +ij_typescript_space_before_else_left_brace = false +ij_typescript_space_before_finally_keyword = true +ij_typescript_space_before_finally_left_brace = false +ij_typescript_space_before_for_left_brace = false +ij_typescript_space_before_for_parentheses = false +ij_typescript_space_before_for_semicolon = false +ij_typescript_space_before_function_left_parenth = false +ij_typescript_space_before_generator_mult = false +ij_typescript_space_before_if_left_brace = false +ij_typescript_space_before_if_parentheses = false +ij_typescript_space_before_method_call_parentheses = false +ij_typescript_space_before_method_left_brace = false +ij_typescript_space_before_method_parentheses = false +ij_typescript_space_before_property_colon = false +ij_typescript_space_before_quest = true +ij_typescript_space_before_switch_left_brace = false +ij_typescript_space_before_switch_parentheses = false +ij_typescript_space_before_try_left_brace = false +ij_typescript_space_before_type_colon = false +ij_typescript_space_before_unary_not = false +ij_typescript_space_before_while_keyword = true +ij_typescript_space_before_while_left_brace = false +ij_typescript_space_before_while_parentheses = false +ij_typescript_spaces_around_additive_operators = true +ij_typescript_spaces_around_arrow_function_operator = true +ij_typescript_spaces_around_assignment_operators = true +ij_typescript_spaces_around_bitwise_operators = true +ij_typescript_spaces_around_equality_operators = true +ij_typescript_spaces_around_logical_operators = true +ij_typescript_spaces_around_multiplicative_operators = true +ij_typescript_spaces_around_relational_operators = true +ij_typescript_spaces_around_shift_operators = true +ij_typescript_spaces_around_unary_operator = false +ij_typescript_spaces_within_array_initializer_brackets = false +ij_typescript_spaces_within_brackets = false +ij_typescript_spaces_within_catch_parentheses = false +ij_typescript_spaces_within_for_parentheses = false +ij_typescript_spaces_within_if_parentheses = false +ij_typescript_spaces_within_imports = false +ij_typescript_spaces_within_interpolation_expressions = false +ij_typescript_spaces_within_method_call_parentheses = false +ij_typescript_spaces_within_method_parentheses = false +ij_typescript_spaces_within_object_literal_braces = false +ij_typescript_spaces_within_object_type_braces = true +ij_typescript_spaces_within_parentheses = false +ij_typescript_spaces_within_switch_parentheses = false +ij_typescript_spaces_within_type_assertion = false +ij_typescript_spaces_within_union_types = true +ij_typescript_spaces_within_while_parentheses = false +ij_typescript_special_else_if_treatment = true +ij_typescript_ternary_operation_signs_on_next_line = false +ij_typescript_ternary_operation_wrap = on_every_item +ij_typescript_union_types_wrap = on_every_item +ij_typescript_use_chained_calls_group_indents = false +ij_typescript_use_double_quotes = true +ij_typescript_use_explicit_js_extension = auto +ij_typescript_use_path_mapping = always +ij_typescript_use_public_modifier = false +ij_typescript_use_semicolon_after_statement = true +ij_typescript_var_declaration_wrap = normal +ij_typescript_while_brace_force = always +ij_typescript_while_on_new_line = false +ij_typescript_wrap_comments = false -csharp_indent_case_contents = true -csharp_indent_switch_labels = true -csharp_indent_labels = flush_left +[{*.bash,*.sh,*.zsh}] +indent_size = 2 +tab_width = 2 +ij_shell_binary_ops_start_line = false +ij_shell_keep_column_alignment_padding = false +ij_shell_minify_program = false +ij_shell_redirect_followed_by_space = false +ij_shell_switch_cases_indented = true +ij_shell_use_unix_line_separator = true +indent_style = space -csharp_space_after_cast = false -csharp_space_after_keywords_in_control_flow_statements = false -csharp_space_between_method_declaration_parameter_list_parentheses = false -csharp_space_between_parentheses = none -csharp_space_before_colon_in_inheritance_clause = true -csharp_space_after_colon_in_inheritance_clause = true -csharp_space_around_binary_operators = before_and_after -csharp_space_between_method_declaration_empty_parameter_list_parentheses = false -csharp_space_between_method_call_name_and_opening_parenthesis = false -csharp_space_between_method_call_empty_parameter_list_parentheses = false +[{*.cjs,*.js}] +ij_continuation_indent_size = 4 +ij_javascript_align_imports = true +ij_javascript_align_multiline_array_initializer_expression = true +ij_javascript_align_multiline_binary_operation = true +ij_javascript_align_multiline_chained_methods = false +ij_javascript_align_multiline_extends_list = true +ij_javascript_align_multiline_for = true +ij_javascript_align_multiline_parameters = true +ij_javascript_align_multiline_parameters_in_calls = true +ij_javascript_align_multiline_ternary_operation = true +ij_javascript_align_object_properties = 1 +ij_javascript_align_union_types = false +ij_javascript_align_var_statements = 2 +ij_javascript_array_initializer_new_line_after_left_brace = false +ij_javascript_array_initializer_right_brace_on_new_line = false +ij_javascript_array_initializer_wrap = on_every_item +ij_javascript_assignment_wrap = on_every_item +ij_javascript_binary_operation_sign_on_next_line = false +ij_javascript_binary_operation_wrap = on_every_item +ij_javascript_blacklist_imports = rxjs/Rx,node_modules/**,**/node_modules/**,@angular/material,@angular/material/typings/** +ij_javascript_blank_lines_after_imports = 1 +ij_javascript_blank_lines_around_class = 1 +ij_javascript_blank_lines_around_field = 0 +ij_javascript_blank_lines_around_function = 1 +ij_javascript_blank_lines_around_method = 1 +ij_javascript_block_brace_style = next_line +ij_javascript_block_comment_add_space = false +ij_javascript_block_comment_at_first_column = true +ij_javascript_call_parameters_new_line_after_left_paren = false +ij_javascript_call_parameters_right_paren_on_new_line = false +ij_javascript_call_parameters_wrap = on_every_item +ij_javascript_catch_on_new_line = true +ij_javascript_chained_call_dot_on_new_line = true +ij_javascript_class_brace_style = next_line +ij_javascript_comma_on_new_line = false +ij_javascript_do_while_brace_force = always +ij_javascript_else_on_new_line = true +ij_javascript_enforce_trailing_comma = remove +ij_javascript_extends_keyword_wrap = normal +ij_javascript_extends_list_wrap = on_every_item +ij_javascript_field_prefix = _ +ij_javascript_file_name_style = relaxed +ij_javascript_finally_on_new_line = true +ij_javascript_for_brace_force = if_multiline +ij_javascript_for_statement_new_line_after_left_paren = false +ij_javascript_for_statement_right_paren_on_new_line = false +ij_javascript_for_statement_wrap = on_every_item +ij_javascript_force_quote_style = true +ij_javascript_force_semicolon_style = true +ij_javascript_function_expression_brace_style = next_line +ij_javascript_if_brace_force = if_multiline +ij_javascript_import_merge_members = global +ij_javascript_import_prefer_absolute_path = true +ij_javascript_import_sort_members = true +ij_javascript_import_sort_module_name = true +ij_javascript_import_use_node_resolution = true +ij_javascript_imports_wrap = on_every_item +ij_javascript_indent_case_from_switch = true +ij_javascript_indent_chained_calls = true +ij_javascript_indent_package_children = 0 +ij_javascript_jsx_attribute_value = braces +ij_javascript_keep_blank_lines_in_code = 2 +ij_javascript_keep_first_column_comment = true +ij_javascript_keep_indents_on_empty_lines = false +ij_javascript_keep_line_breaks = true +ij_javascript_keep_simple_blocks_in_one_line = false +ij_javascript_keep_simple_methods_in_one_line = false +ij_javascript_line_comment_add_space = true +ij_javascript_line_comment_at_first_column = false +ij_javascript_method_brace_style = next_line +ij_javascript_method_call_chain_wrap = on_every_item +ij_javascript_method_parameters_new_line_after_left_paren = false +ij_javascript_method_parameters_right_paren_on_new_line = false +ij_javascript_method_parameters_wrap = on_every_item +ij_javascript_object_literal_wrap = on_every_item +ij_javascript_object_types_wrap = on_every_item +ij_javascript_parentheses_expression_new_line_after_left_paren = false +ij_javascript_parentheses_expression_right_paren_on_new_line = false +ij_javascript_place_assignment_sign_on_next_line = true +ij_javascript_prefer_as_type_cast = false +ij_javascript_prefer_explicit_types_function_expression_returns = false +ij_javascript_prefer_explicit_types_function_returns = false +ij_javascript_prefer_explicit_types_vars_fields = false +ij_javascript_prefer_parameters_wrap = false +ij_javascript_property_prefix = +ij_javascript_reformat_c_style_comments = true +ij_javascript_space_after_colon = true +ij_javascript_space_after_comma = true +ij_javascript_space_after_dots_in_rest_parameter = false +ij_javascript_space_after_generator_mult = true +ij_javascript_space_after_property_colon = true +ij_javascript_space_after_quest = true +ij_javascript_space_after_type_colon = true +ij_javascript_space_after_unary_not = false +ij_javascript_space_before_async_arrow_lparen = false +ij_javascript_space_before_catch_keyword = true +ij_javascript_space_before_catch_left_brace = false +ij_javascript_space_before_catch_parentheses = false +ij_javascript_space_before_class_lbrace = false +ij_javascript_space_before_class_left_brace = true +ij_javascript_space_before_colon = true +ij_javascript_space_before_comma = false +ij_javascript_space_before_do_left_brace = false +ij_javascript_space_before_else_keyword = true +ij_javascript_space_before_else_left_brace = false +ij_javascript_space_before_finally_keyword = true +ij_javascript_space_before_finally_left_brace = false +ij_javascript_space_before_for_left_brace = false +ij_javascript_space_before_for_parentheses = false +ij_javascript_space_before_for_semicolon = false +ij_javascript_space_before_function_left_parenth = false +ij_javascript_space_before_generator_mult = false +ij_javascript_space_before_if_left_brace = false +ij_javascript_space_before_if_parentheses = false +ij_javascript_space_before_method_call_parentheses = false +ij_javascript_space_before_method_left_brace = false +ij_javascript_space_before_method_parentheses = false +ij_javascript_space_before_property_colon = false +ij_javascript_space_before_quest = true +ij_javascript_space_before_switch_left_brace = false +ij_javascript_space_before_switch_parentheses = false +ij_javascript_space_before_try_left_brace = false +ij_javascript_space_before_type_colon = false +ij_javascript_space_before_unary_not = false +ij_javascript_space_before_while_keyword = true +ij_javascript_space_before_while_left_brace = false +ij_javascript_space_before_while_parentheses = false +ij_javascript_spaces_around_additive_operators = true +ij_javascript_spaces_around_arrow_function_operator = true +ij_javascript_spaces_around_assignment_operators = true +ij_javascript_spaces_around_bitwise_operators = true +ij_javascript_spaces_around_equality_operators = true +ij_javascript_spaces_around_logical_operators = true +ij_javascript_spaces_around_multiplicative_operators = true +ij_javascript_spaces_around_relational_operators = true +ij_javascript_spaces_around_shift_operators = true +ij_javascript_spaces_around_unary_operator = false +ij_javascript_spaces_within_array_initializer_brackets = false +ij_javascript_spaces_within_brackets = false +ij_javascript_spaces_within_catch_parentheses = false +ij_javascript_spaces_within_for_parentheses = false +ij_javascript_spaces_within_if_parentheses = false +ij_javascript_spaces_within_imports = false +ij_javascript_spaces_within_interpolation_expressions = false +ij_javascript_spaces_within_method_call_parentheses = false +ij_javascript_spaces_within_method_parentheses = false +ij_javascript_spaces_within_object_literal_braces = false +ij_javascript_spaces_within_object_type_braces = true +ij_javascript_spaces_within_parentheses = false +ij_javascript_spaces_within_switch_parentheses = false +ij_javascript_spaces_within_type_assertion = false +ij_javascript_spaces_within_union_types = true +ij_javascript_spaces_within_while_parentheses = false +ij_javascript_special_else_if_treatment = true +ij_javascript_ternary_operation_signs_on_next_line = false +ij_javascript_ternary_operation_wrap = on_every_item +ij_javascript_union_types_wrap = on_every_item +ij_javascript_use_chained_calls_group_indents = true +ij_javascript_use_double_quotes = true +ij_javascript_use_explicit_js_extension = auto +ij_javascript_use_path_mapping = always +ij_javascript_use_public_modifier = false +ij_javascript_use_semicolon_after_statement = true +ij_javascript_var_declaration_wrap = normal +ij_javascript_while_brace_force = always +ij_javascript_while_on_new_line = false +ij_javascript_wrap_comments = false -csharp_preserve_single_line_statements = false -csharp_preserve_single_line_blocks = true +[{*.comp,*.frag,*.fsh,*.geom,*.glsl,*.tesc,*.tese,*.vert,*.vsh}] +ij_glsl_keep_indents_on_empty_lines = false -csharp_blank_lines_around_region = 0 -csharp_blank_lines_inside_region = 0 -csharp_blank_lines_before_single_line_comment = 1 -csharp_keep_blank_lines_in_declarations = 1 -csharp_remove_blank_lines_near_braces_in_declarations = true -csharp_blank_lines_after_start_comment = false -csharp_blank_lines_between_using_groups = 0 -csharp_blank_lines_after_using_list = 1 -csharp_blank_lines_around_namespace = 1 -csharp_blank_lines_inside_namespace = 0 -csharp_blank_lines_around_type = 1 -csharp_blank_lines_inside_type = 0 -csharp_blank_lines_around_field = 0 -csharp_blank_lines_around_single_line_field = 0 -csharp_blank_lines_around_property = 1 -csharp_blank_lines_around_single_line_property = 0 -csharp_blank_lines_around_auto_property = 0 -csharp_blank_lines_around_single_line_auto_property = 0 -csharp_blank_lines_around_invocable = 1 -csharp_blank_lines_around_single_line_invocable = 1 -csharp_keep_blank_lines_in_code = 1 -csharp_remove_blank_lines_near_braces_in_code = true -csharp_blank_lines_around_local_method = 1 -csharp_blank_lines_around_single_line_local_method = 1 -csharp_blank_lines_before_control_transfer_statements = 1 -csharp_blank_lines_after_control_transfer_statements = 1 -csharp_blank_lines_before_block_statements = 1 -csharp_blank_lines_after_block_statements = 1 -csharp_blank_lines_before_multiline_statements = 1 -csharp_blank_lines_after_multiline_statements = 1 +[{*.har,*.jsb2,*.jsb3,*.json,*.jsonc,.babelrc,.eslintrc,.prettierrc,.stylelintrc,bowerrc,jest.config}] +indent_size = 2 +ij_json_array_wrapping = normal +ij_json_keep_blank_lines_in_code = 0 +ij_json_keep_indents_on_empty_lines = false +ij_json_keep_line_breaks = true +ij_json_keep_trailing_comma = false +ij_json_object_wrapping = normal +ij_json_property_alignment = align_on_value +ij_json_space_after_colon = true +ij_json_space_after_comma = true +ij_json_space_before_colon = false +ij_json_space_before_comma = false +ij_json_spaces_within_braces = false +ij_json_spaces_within_brackets = false +ij_json_wrap_long_lines = false +indent_style = space -csharp_type_declaration_braces = next_line -csharp_brace_style = next_line -csharp_indent_inside_namespace = true -csharp_invocable_declaration_braces = next_line -csharp_anonymous_method_declaration_braces = next_line -csharp_accessor_owner_declaration_braces = next_line -csharp_accessor_declaration_braces = next_line -csharp_case_block_braces = next_line -csharp_initializer_braces = next_line -csharp_other_braces = next_line -csharp_allow_comment_after_lbrace = false -csharp_empty_block_style = together_same_line +[{*.htm,*.html,*.ng,*.sht,*.shtm,*.shtml}] +ij_html_add_new_line_before_tags = body,div,p,form,h1,h2,h3 +ij_html_align_attributes = true +ij_html_align_text = false +ij_html_attribute_wrap = normal +ij_html_block_comment_add_space = false +ij_html_block_comment_at_first_column = true +ij_html_do_not_align_children_of_min_lines = 0 +ij_html_do_not_break_if_inline_tags = title,h1,h2,h3,h4,h5,h6,p +ij_html_do_not_indent_children_of_tags = html,body,thead,tbody,tfoot +ij_html_enforce_quotes = false +ij_html_inline_tags = a,abbr,acronym,b,basefont,bdo,big,br,cite,cite,code,dfn,em,font,i,img,input,kbd,label,q,s,samp,select,small,span,strike,strong,sub,sup,textarea,tt,u,var +ij_html_keep_blank_lines = 2 +ij_html_keep_indents_on_empty_lines = false +ij_html_keep_line_breaks = true +ij_html_keep_line_breaks_in_text = true +ij_html_keep_whitespaces = false +ij_html_keep_whitespaces_inside = span,pre,textarea +ij_html_line_comment_at_first_column = true +ij_html_new_line_after_last_attribute = never +ij_html_new_line_before_first_attribute = never +ij_html_quote_style = double +ij_html_remove_new_line_before_tags = br +ij_html_space_after_tag_name = false +ij_html_space_around_equality_in_attribute = false +ij_html_space_inside_empty_tag = false +ij_html_text_wrap = normal -csharp_for_built_in_types = use_explicit_type -csharp_for_simple_types = use_var_when_evident -csharp_for_other_types = use_explicit_type -csharp_prefer_separate_deconstructed_variables_declaration = true -csharp_prefer_explicit_discard_declaration = false +[{*.http,*.rest}] +indent_size = 0 +ij_continuation_indent_size = 4 +ij_http-request_call_parameters_wrap = normal +ij_http-request_method_parameters_wrap = split_into_lines +ij_http-request_space_before_comma = true +ij_http-request_spaces_around_assignment_operators = true -csharp_instance_members_qualify_members = none -csharp_builtin_type_reference_style = use_keyword -csharp_prefer_qualified_reference = false -csharp_add_imports_to_deepest_scope = false -csharp_allow_alias = true -csharp_default_private_modifier = implicit -csharp_default_internal_modifier = implicit -csharp_arguments_literal = positional -csharp_arguments_string_literal = positional -csharp_arguments_named = positional -csharp_arguments_anonymous_function = positional -csharp_arguments_other = positional -csharp_braces_for_ifelse = not_required -csharp_braces_for_for = not_required -csharp_braces_for_foreach = not_required -csharp_braces_for_while = not_required -csharp_braces_for_dowhile = not_required -csharp_braces_for_using = not_required -csharp_braces_for_lock = not_required -csharp_braces_for_fixed = not_required -csharp_method_or_operator_body = expression_body -csharp_local_function_body = expression_body -csharp_constructor_or_destructor_body = expression_body -csharp_accessor_owner_body = expression_body -csharp_force_attribute_style = join -csharp_indent_nested_usings_stmt = true +[{*.markdown,*.md}] +ij_markdown_force_one_space_after_blockquote_symbol = true +ij_markdown_force_one_space_after_header_symbol = true +ij_markdown_force_one_space_after_list_bullet = true +ij_markdown_force_one_space_between_words = true +ij_markdown_format_tables = true +ij_markdown_insert_quote_arrows_on_wrap = true +ij_markdown_keep_indents_on_empty_lines = false +ij_markdown_keep_line_breaks_inside_text_blocks = true +ij_markdown_max_lines_around_block_elements = 1 +ij_markdown_max_lines_around_header = 1 +ij_markdown_max_lines_between_paragraphs = 1 +ij_markdown_min_lines_around_block_elements = 1 +ij_markdown_min_lines_around_header = 1 +ij_markdown_min_lines_between_paragraphs = 1 +ij_markdown_wrap_text_if_long = true +ij_markdown_wrap_text_inside_blockquotes = true -csharp_builtin_type_reference_for_member_access_style = use_keyword -csharp_indent_nested_fixed_stmt = true -csharp_indent_nested_lock_stmt = true -csharp_indent_nested_for_stmt = true -csharp_indent_nested_foreach_stmt = true -csharp_indent_nested_while_stmt = true -csharp_use_continuous_indent_inside_parens = true -csharp_indent_method_decl_pars = inside -csharp_indent_invocation_pars = inside -csharp_indent_statement_pars = inside -csharp_indent_typeparam_angles = inside -csharp_indent_typearg_angles = inside -csharp_indent_pars = inside -csharp_indent_preprocessor_if = outdent -csharp_indent_preprocessor_region = usual_indent -csharp_indent_preprocessor_other = usual_indent -csharp_indent_switch_labels = true -csharp_indent_type_constraints = true -csharp_stick_comment = false -csharp_alignment_tab_fill_style = use_spaces -csharp_align_multiline_parameter = true -csharp_align_multiline_extends_list = true -csharp_align_linq_query = true -csharp_align_multiline_binary_expressions_chain = true -csharp_outdent_binary_ops = true -csharp_align_multiline_calls_chain = true -csharp_outdent_dots = true -csharp_align_multiline_array_and_object_initializer = false -csharp_indent_anonymous_method_block = false -csharp_align_first_arg_by_paren = true -csharp_align_multiline_argument = true -csharp_align_tuple_components = true -csharp_align_multiline_expression = true -csharp_align_multiline_for_stmt = true -csharp_align_multiple_declaration = true -csharp_align_multline_type_parameter_list = true -csharp_align_multline_type_parameter_constrains = true -csharp_int_align_fields = true -csharp_int_align_properties = true -csharp_int_align_methods = true -csharp_int_align_parameters = false -csharp_int_align_variables = true -csharp_int_align_assignments = true -csharp_int_align_nested_ternary = true -csharp_int_align_invocations = false -csharp_int_align_binary_expressions = true -csharp_int_align_comments = true -csharp_int_align_switch_sections = true -csharp_int_align = true -csharp_keep_user_linebreaks = false -csharp_keep_existing_arrangement = false -csharp_keep_existing_linebreaks = false -csharp_max_line_length = 120 -csharp_wrap_before_comma = false -csharp_special_else_if_treatment = true -csharp_insert_final_newline = false -csharp_place_type_attribute_on_same_line = never -csharp_place_method_attribute_on_same_line = never -csharp_place_accessorholder_attribute_on_same_line = never -csharp_place_attribute_on_same_line = never -csharp_place_accessor_attribute_on_same_line = never -csharp_place_attribute_on_same_line = never -csharp_place_field_attribute_on_same_line = never -csharp_place_attribute_on_same_line = never -csharp_wrap_parameters_style = wrap_if_long -csharp_keep_existing_declaration_parens_arrangement = false -csharp_wrap_before_declaration_lpar = false -csharp_wrap_after_declaration_lpar = false -csharp_wrap_before_declaration_rpar = false -csharp_place_constructor_initializer_on_same_line = true -csharp_keep_existing_expr_member_arrangement = false -csharp_place_expr_method_on_single_line = true -csharp_place_expr_property_on_single_line = true -csharp_place_expr_accessor_on_single_line = true -csharp_wrap_before_arrow_with_expressions = false -csharp_place_type_constraints_on_same_line = true -csharp_wrap_before_first_type_parameter_constraint = true -csharp_wrap_multiple_type_parameter_constraints_style = wrap_if_long -csharp_wrap_before_type_parameter_langle = true -csharp_wrap_before_extends_colon = false -csharp_wrap_extends_list_style = wrap_if_long -csharp_keep_existing_declaration_block_arrangement = false -csharp_place_abstract_accessorholder_on_single_line = true -csharp_place_simple_accessorholder_on_single_line = false -csharp_place_accessor_with_attrs_holder_on_single_line = false -csharp_place_simple_accessor_on_single_line = true -csharp_place_simple_method_on_single_line = false -csharp_keep_existing_enum_arrangement = false -csharp_place_simple_enum_on_single_line = false -csharp_wrap_enum_declaration = wrap_if_long -csharp_new_line_before_else = true -csharp_new_line_before_while = false -csharp_wrap_for_stmt_header_style = wrap_if_long -csharp_wrap_multiple_declaration_style = wrap_if_long -csharp_keep_existing_embedded_arrangement = false -csharp_place_simple_embedded_statement_on_same_line = false -csharp_place_simple_case_statement_on_same_line = true -csharp_keep_existing_embedded_block_arrangement = false -csharp_place_simple_embedded_block_on_same_line = false -csharp_place_simple_anonymousmethod_on_single_line = false -csharp_keep_existing_initializer_arrangement = false -csharp_place_simple_initializer_on_single_line = false -csharp_wrap_object_and_collection_initializer_style = chop_always -csharp_wrap_array_initializer_style = wrap_if_long -csharp_wrap_arguments_style = wrap_if_long -csharp_keep_existing_invocation_parens_arrangement = false -csharp_wrap_after_invocation_lpar = false -csharp_wrap_before_invocation_rpar = false -csharp_wrap_after_dot_in_method_calls = true -csharp_wrap_chained_method_calls = wrap_if_long -csharp_wrap_before_binary_opsign = false -csharp_wrap_chained_binary_expressions = wrap_if_long -csharp_force_chop_compound_if_expression = true -csharp_force_chop_compound_while_expression = true -csharp_force_chop_compound_do_expression = true -csharp_wrap_before_ternary_opsigns = true -csharp_wrap_ternary_expr_style = wrap_if_long -csharp_nested_ternary_style = expanded -csharp_wrap_linq_expressions = wrap_if_long -csharp_wrap_before_linq_expression = false -csharp_place_linq_into_on_new_line = false -csharp_wrap_verbatim_interpolated_strings = wrap_if_long -csharp_extra_spaces = remove_all -csharp_space_after_keywords_in_control_flow_statements = false -csharp_space_between_method_call_name_and_opening_parenthesis = false -csharp_space_between_method_declaration_name_and_open_parenthesis = false -csharp_space_before_typeof_parentheses = false -csharp_space_before_checked_parentheses = false -csharp_space_before_sizeof_parentheses = false -csharp_space_before_nameof_parentheses = false -csharp_space_between_keyword_and_expression = true -csharp_space_between_keyword_and_type = true -csharp_space_around_assignment_op = true -csharp_space_around_logical_op = true -csharp_space_around_binary_operator = true -csharp_space_around_equality_op = true -csharp_space_around_relational_op = true -csharp_space_around_bitwise_op = true -csharp_space_around_additive_op = true -csharp_space_around_multiplicative_op = true -csharp_space_around_shift_op = true -csharp_space_around_nullcoalescing_op = true -csharp_space_around_arrow_op = false -csharp_space_after_logical_not_op = false -csharp_space_after_unary_operator = false -csharp_space_after_cast = false -csharp_space_around_dot = false -csharp_space_around_lambda_arrow = true -csharp_space_before_pointer_asterik_declaration = false -csharp_space_before_nullable_mark = false -csharp_style_namespace_declarations = file_scoped:warning +[{*.ps1,*.psd1,*.psm1}] +max_line_length = 115 +ij_powershell_align_multiline_binary_operation = true +ij_powershell_align_multiline_chained_methods = false +ij_powershell_align_multiline_for = true +ij_powershell_align_multiline_parameters = true +ij_powershell_align_multiline_parameters_in_calls = false +ij_powershell_binary_operation_wrap = on_every_item +ij_powershell_block_brace_style = next_line +ij_powershell_call_parameters_new_line_after_left_paren = false +ij_powershell_call_parameters_right_paren_on_new_line = false +ij_powershell_call_parameters_wrap = on_every_item +ij_powershell_catch_on_new_line = true +ij_powershell_class_annotation_wrap = split_into_lines +ij_powershell_class_brace_style = next_line +ij_powershell_else_on_new_line = true +ij_powershell_field_annotation_wrap = off +ij_powershell_finally_on_new_line = true +ij_powershell_for_statement_new_line_after_left_paren = false +ij_powershell_for_statement_right_paren_on_new_line = false +ij_powershell_for_statement_wrap = on_every_item +ij_powershell_keep_blank_lines_in_code = 2 +ij_powershell_keep_first_column_comment = true +ij_powershell_keep_line_breaks = true +ij_powershell_keep_simple_blocks_in_one_line = true +ij_powershell_keep_simple_classes_in_one_line = false +ij_powershell_keep_simple_lambdas_in_one_line = true +ij_powershell_keep_simple_methods_in_one_line = true +ij_powershell_method_annotation_wrap = split_into_lines +ij_powershell_method_brace_style = next_line +ij_powershell_method_call_chain_wrap = on_every_item +ij_powershell_method_parameters_new_line_after_left_paren = false +ij_powershell_method_parameters_right_paren_on_new_line = false +ij_powershell_method_parameters_wrap = on_every_item +ij_powershell_parameter_annotation_wrap = off +ij_powershell_parentheses_expression_new_line_after_left_paren = false +ij_powershell_parentheses_expression_right_paren_on_new_line = false +ij_powershell_space_after_colon = true +ij_powershell_space_after_comma = true +ij_powershell_space_after_for_semicolon = true +ij_powershell_space_after_type_cast = false +ij_powershell_space_before_annotation_parameter_list = false +ij_powershell_space_before_array_initializer_left_brace = false +ij_powershell_space_before_catch_keyword = true +ij_powershell_space_before_catch_left_brace = false +ij_powershell_space_before_class_left_brace = false +ij_powershell_space_before_colon = true +ij_powershell_space_before_comma = false +ij_powershell_space_before_do_left_brace = false +ij_powershell_space_before_else_keyword = true +ij_powershell_space_before_else_left_brace = false +ij_powershell_space_before_finally_keyword = true +ij_powershell_space_before_finally_left_brace = false +ij_powershell_space_before_for_left_brace = false +ij_powershell_space_before_for_parentheses = false +ij_powershell_space_before_for_semicolon = false +ij_powershell_space_before_if_left_brace = false +ij_powershell_space_before_if_parentheses = false +ij_powershell_space_before_method_call_parentheses = false +ij_powershell_space_before_method_left_brace = false +ij_powershell_space_before_method_parentheses = false +ij_powershell_space_before_switch_left_brace = false +ij_powershell_space_before_switch_parentheses = false +ij_powershell_space_before_try_left_brace = false +ij_powershell_space_before_while_keyword = true +ij_powershell_space_before_while_left_brace = false +ij_powershell_space_before_while_parentheses = false +ij_powershell_space_within_empty_method_call_parentheses = false +ij_powershell_space_within_empty_method_parentheses = false +ij_powershell_spaces_around_additive_operators = true +ij_powershell_spaces_around_assignment_operators = true +ij_powershell_spaces_around_bitwise_operators = true +ij_powershell_spaces_around_logical_operators = true +ij_powershell_spaces_around_method_ref_dbl_colon = false +ij_powershell_spaces_around_multiplicative_operators = true +ij_powershell_spaces_around_relational_operators = true +ij_powershell_spaces_around_unary_operator = false +ij_powershell_spaces_within_annotation_parentheses = false +ij_powershell_spaces_within_braces = true +ij_powershell_spaces_within_brackets = false +ij_powershell_spaces_within_cast_parentheses = false +ij_powershell_spaces_within_for_parentheses = false +ij_powershell_spaces_within_if_parentheses = false +ij_powershell_spaces_within_method_call_parentheses = false +ij_powershell_spaces_within_method_parentheses = false +ij_powershell_spaces_within_parentheses = false +ij_powershell_spaces_within_switch_parentheses = false +ij_powershell_spaces_within_while_parentheses = false +ij_powershell_special_else_if_treatment = true +ij_powershell_while_on_new_line = false +ij_powershell_wrap_first_method_in_call_chain = false +ij_powershell_wrap_long_lines = false -[*.cshtml] -linebreaks_around_razor_statements = true -blank_lines_around_razor_functions = true -blank_lines_around_razor_helpers = true -blank_lines_around_razor_sections = true +[{*.py,*.pyw}] +ij_python_align_collections_and_comprehensions = true +ij_python_align_multiline_imports = true +ij_python_align_multiline_parameters = true +ij_python_align_multiline_parameters_in_calls = true +ij_python_blank_line_at_file_end = false +ij_python_blank_lines_after_imports = 1 +ij_python_blank_lines_after_local_imports = 0 +ij_python_blank_lines_around_class = 1 +ij_python_blank_lines_around_method = 1 +ij_python_blank_lines_around_top_level_classes_functions = 2 +ij_python_blank_lines_before_first_method = 0 +ij_python_call_parameters_new_line_after_left_paren = false +ij_python_call_parameters_right_paren_on_new_line = false +ij_python_call_parameters_wrap = on_every_item +ij_python_dict_alignment = 0 +ij_python_dict_new_line_after_left_brace = false +ij_python_dict_new_line_before_right_brace = false +ij_python_dict_wrapping = 5 +ij_python_from_import_new_line_after_left_parenthesis = false +ij_python_from_import_new_line_before_right_parenthesis = false +ij_python_from_import_parentheses_force_if_multiline = false +ij_python_from_import_trailing_comma_if_multiline = false +ij_python_from_import_wrapping = 5 +ij_python_hang_closing_brackets = true +ij_python_keep_blank_lines_in_code = 1 +ij_python_keep_blank_lines_in_declarations = 1 +ij_python_keep_indents_on_empty_lines = false +ij_python_keep_line_breaks = true +ij_python_method_parameters_new_line_after_left_paren = false +ij_python_method_parameters_right_paren_on_new_line = false +ij_python_method_parameters_wrap = on_every_item +ij_python_new_line_after_colon = false +ij_python_new_line_after_colon_multi_clause = true +ij_python_optimize_imports_always_split_from_imports = false +ij_python_optimize_imports_case_insensitive_order = true +ij_python_optimize_imports_join_from_imports_with_same_source = false +ij_python_optimize_imports_sort_by_type_first = true +ij_python_optimize_imports_sort_imports = true +ij_python_optimize_imports_sort_names_in_from_imports = true +ij_python_space_after_comma = true +ij_python_space_after_number_sign = true +ij_python_space_after_py_colon = true +ij_python_space_before_backslash = true +ij_python_space_before_comma = false +ij_python_space_before_for_semicolon = false +ij_python_space_before_lbracket = false +ij_python_space_before_method_call_parentheses = false +ij_python_space_before_method_parentheses = false +ij_python_space_before_number_sign = true +ij_python_space_before_py_colon = false +ij_python_space_within_empty_method_call_parentheses = false +ij_python_space_within_empty_method_parentheses = false +ij_python_spaces_around_additive_operators = true +ij_python_spaces_around_assignment_operators = true +ij_python_spaces_around_bitwise_operators = true +ij_python_spaces_around_eq_in_keyword_argument = false +ij_python_spaces_around_eq_in_named_parameter = false +ij_python_spaces_around_equality_operators = true +ij_python_spaces_around_multiplicative_operators = true +ij_python_spaces_around_power_operator = true +ij_python_spaces_around_relational_operators = true +ij_python_spaces_around_shift_operators = true +ij_python_spaces_within_braces = false +ij_python_spaces_within_brackets = false +ij_python_spaces_within_method_call_parentheses = false +ij_python_spaces_within_method_parentheses = false +ij_python_use_continuation_indent_for_arguments = false +ij_python_use_continuation_indent_for_collection_and_comprehensions = false +ij_python_use_continuation_indent_for_parameters = true +ij_python_wrap_long_lines = false -# C++ -[*.{cc,cpp,cxx,h,hpp,hxx}] -cpp_indent_access_specifiers_from_class = true -cpp_indent_wrapped_function_names = false -cpp_align_multiline_type_argument = true +[{*.toml,Cargo.lock,Cargo.toml.orig,Gopkg.lock,Pipfile,poetry.lock}] +ij_toml_keep_indents_on_empty_lines = false -# C, C++ and ObjectiveC -[*.{c,h,cc,cpp,cxx,m,hpp,hxx}] -indent_preprocessor_directives = normal -indent_type_constraints = true +[{*.yaml,*.yml,pubspec.lock}] +indent_size = 2 +ij_yaml_align_values_properties = on_value +ij_yaml_autoinsert_sequence_marker = true +ij_yaml_block_mapping_on_new_line = false +ij_yaml_indent_sequence_value = true +ij_yaml_keep_indents_on_empty_lines = false +ij_yaml_keep_line_breaks = true +ij_yaml_sequence_on_new_line = false +ij_yaml_space_before_colon = false +ij_yaml_spaces_within_braces = true +ij_yaml_spaces_within_brackets = true +indent_style = space -# Javascript and Typescript -[*.{js,js.map,ts}] -quote_style = doublequoted -termination_style = ensure_semicolon +[*.{appxmanifest,asax,ascx,aspx,axaml,build,c,c++,cc,cginc,compute,cp,cpp,cppm,cs,cshtml,cu,cuh,cxx,dtd,fs,fsi,fsscript,fsx,fx,fxh,h,hh,hlsl,hlsli,hlslinc,hpp,hxx,inc,inl,ino,ipp,ixx,master,ml,mli,mpp,mq4,mq5,mqh,nuspec,paml,razor,resw,resx,shader,skin,tpp,usf,ush,uxml,vb,xaml,xamlx,xoml,xsd}] +indent_style = space +indent_size = 4 +tab_width = 4 From b6bd18e8b2106c88c390d6e57fab0367b44f615f Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 3 Oct 2023 21:13:56 +0100 Subject: [PATCH 207/217] Disable JetBrains spell checking in Spanish (Spain) resource files. --- Localization/Localization.es.resx | 1 + 1 file changed, 1 insertion(+) diff --git a/Localization/Localization.es.resx b/Localization/Localization.es.resx index abef6d011..2be0f2713 100644 --- a/Localization/Localization.es.resx +++ b/Localization/Localization.es.resx @@ -1,4 +1,5 @@ + text/microsoft-resx From 6bd5e90a922b25bb167aefb7b7db04d7fa39fac9 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 3 Oct 2023 21:26:15 +0100 Subject: [PATCH 208/217] Update code style. --- .editorconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.editorconfig b/.editorconfig index fd4cb0e6b..99b0609a8 100644 --- a/.editorconfig +++ b/.editorconfig @@ -57,7 +57,7 @@ dotnet_style_require_accessibility_modifiers = never:suggestion # ReSharper properties resharper_align_linq_query = true resharper_align_multiline_argument = true -resharper_align_multiline_array_and_object_initializer = true +resharper_align_multiline_array_and_object_initializer = false resharper_align_multiline_binary_expressions_chain = true resharper_align_multiline_binary_patterns = true resharper_align_multiline_calls_chain = true From ca2f08311f0abcf9ddd2b302f6177073a9e17865 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 3 Oct 2023 21:41:44 +0100 Subject: [PATCH 209/217] Update code style (final). --- .editorconfig | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.editorconfig b/.editorconfig index 99b0609a8..9a88a7205 100644 --- a/.editorconfig +++ b/.editorconfig @@ -20,9 +20,10 @@ csharp_preferred_modifier_order = public, private, protected, internal, file, ne csharp_space_after_keywords_in_control_flow_statements = false csharp_style_namespace_declarations = file_scoped:warning csharp_style_prefer_utf8_string_literals = true:warning -csharp_style_var_elsewhere = false:none +csharp_style_var_elsewhere = false:suggestion csharp_style_var_for_built_in_types = false:suggestion -csharp_using_directive_placement = inside_namespace:silent +csharp_style_var_when_type_is_apparent = true:suggestion +csharp_using_directive_placement = outside_namespace:silent dotnet_naming_rule.private_constants_rule.import_to_resharper = as_predefined dotnet_naming_rule.private_constants_rule.severity = warning dotnet_naming_rule.private_constants_rule.style = all_upper_style @@ -84,6 +85,7 @@ resharper_constructor_or_destructor_body = expression_body resharper_csharp_align_first_arg_by_paren = true resharper_csharp_empty_block_style = together_same_line resharper_csharp_place_comments_at_first_column = true +resharper_csharp_prefer_qualified_reference = false resharper_default_value_when_type_not_evident = default_expression resharper_enforce_line_ending_style = true resharper_formatter_off_tag = @formatter:off @@ -121,6 +123,8 @@ resharper_outdent_dots = true resharper_outdent_statement_labels = true resharper_parentheses_redundancy_style = remove resharper_place_attribute_on_same_line = false +resharper_place_simple_embedded_statement_on_same_line = false +resharper_qualified_using_at_nested_scope = true resharper_show_autodetect_configure_formatting_tip = false resharper_simple_block_style = on_single_line resharper_simple_case_statement_style = line_break @@ -138,6 +142,7 @@ resharper_space_within_empty_braces = false resharper_toplevel_function_declaration_return_type_style = on_single_line resharper_toplevel_function_definition_return_type_style = on_single_line resharper_use_indent_from_vs = false +resharper_wrap_after_dot_in_method_calls = true resharper_wrap_base_clause_style = chop_if_long resharper_wrap_braced_init_list_style = chop_if_long resharper_wrap_ctor_initializer_style = chop_if_long From 57ad637c20b8b520c78fa099d7fbdad6ab2ce263 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 3 Oct 2023 23:25:24 +0100 Subject: [PATCH 210/217] [Aaru.Helpers] Reformat and cleanup. --- .editorconfig | 2480 +++++++++++++------------ Aaru.Helpers.csproj.DotSettings | 5 +- ArrayFill.cs | 5 +- CHS.cs | 5 +- CompareBytes.cs | 2 + CountBits.cs | 6 +- DateHandlers.cs | 48 +- Extensions.cs | 2 +- Localization/Localization.Designer.cs | 44 +- Localization/Localization.es.resx | 34 +- Localization/Localization.resx | 46 +- Marshal.cs | 133 +- MarshallingPropertiesAttribute.cs | 1 + PrintHex.cs | 14 +- StringHandlers.cs | 16 +- Swapping.cs | 28 +- 16 files changed, 1456 insertions(+), 1413 deletions(-) diff --git a/.editorconfig b/.editorconfig index 9a88a7205..71a05170a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,1334 +1,1338 @@ [*] -charset = utf-8 -end_of_line = lf -indent_size = 4 -indent_style = space -insert_final_newline = false -max_line_length = 120 -tab_width = 4 -trim_trailing_whitespace = false -ij_continuation_indent_size = 8 +charset = utf-8 +end_of_line = lf +indent_size = 2 +indent_style = space +insert_final_newline = false +max_line_length = 120 +tab_width = 2 +trim_trailing_whitespace = false +ij_continuation_indent_size = 4 ij_formatter_off_tag = @formatter:off -ij_formatter_on_tag = @formatter:on -ij_formatter_tags_enabled = true -ij_smart_tabs = false -ij_visual_guides = -ij_wrap_on_typing = false +ij_formatter_on_tag = @formatter:on +ij_formatter_tags_enabled = true +ij_smart_tabs = false +ij_visual_guides = +ij_wrap_on_typing = false # Microsoft .NET properties -csharp_preferred_modifier_order = public, private, protected, internal, file, new, static, abstract, virtual, sealed, readonly, override, extern, unsafe, volatile, async, required:suggestion -csharp_space_after_keywords_in_control_flow_statements = false -csharp_style_namespace_declarations = file_scoped:warning -csharp_style_prefer_utf8_string_literals = true:warning -csharp_style_var_elsewhere = false:suggestion -csharp_style_var_for_built_in_types = false:suggestion -csharp_style_var_when_type_is_apparent = true:suggestion -csharp_using_directive_placement = outside_namespace:silent -dotnet_naming_rule.private_constants_rule.import_to_resharper = as_predefined -dotnet_naming_rule.private_constants_rule.severity = warning -dotnet_naming_rule.private_constants_rule.style = all_upper_style -dotnet_naming_rule.private_constants_rule.symbols = private_constants_symbols -dotnet_naming_rule.unity_serialized_field_rule.import_to_resharper = True -dotnet_naming_rule.unity_serialized_field_rule.resharper_description = Unity serialized field -dotnet_naming_rule.unity_serialized_field_rule.resharper_guid = 5f0fdb63-c892-4d2c-9324-15c80b22a7ef -dotnet_naming_rule.unity_serialized_field_rule.severity = warning -dotnet_naming_rule.unity_serialized_field_rule.style = lower_camel_case_style -dotnet_naming_rule.unity_serialized_field_rule.symbols = unity_serialized_field_symbols -dotnet_naming_style.all_upper_style.capitalization = all_upper -dotnet_naming_style.all_upper_style.word_separator = _ -dotnet_naming_style.lower_camel_case_style.capitalization = camel_case -dotnet_naming_symbols.private_constants_symbols.applicable_accessibilities = private -dotnet_naming_symbols.private_constants_symbols.applicable_kinds = field -dotnet_naming_symbols.private_constants_symbols.required_modifiers = const -dotnet_naming_symbols.unity_serialized_field_symbols.applicable_accessibilities = * -dotnet_naming_symbols.unity_serialized_field_symbols.applicable_kinds = -dotnet_naming_symbols.unity_serialized_field_symbols.resharper_applicable_kinds = unity_serialised_field -dotnet_naming_symbols.unity_serialized_field_symbols.resharper_required_modifiers = instance -dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:warning -dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:warning -dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary:warning -dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion -dotnet_style_predefined_type_for_member_access = true:suggestion -dotnet_style_qualification_for_event = false:suggestion -dotnet_style_qualification_for_field = false:suggestion -dotnet_style_qualification_for_method = false:suggestion -dotnet_style_qualification_for_property = false:suggestion -dotnet_style_require_accessibility_modifiers = never:suggestion +csharp_preferred_modifier_order = public, private, protected, internal, file, new, static, abstract, virtual, sealed, readonly, override, extern, unsafe, volatile, async, required:suggestion +csharp_space_after_keywords_in_control_flow_statements = false +csharp_style_namespace_declarations = file_scoped:warning +csharp_style_prefer_utf8_string_literals = true:warning +csharp_style_var_elsewhere = false:suggestion +csharp_style_var_for_built_in_types = false:suggestion +csharp_style_var_when_type_is_apparent = true:suggestion +csharp_using_directive_placement = outside_namespace:silent +dotnet_naming_rule.private_constants_rule.import_to_resharper = as_predefined +dotnet_naming_rule.private_constants_rule.severity = warning +dotnet_naming_rule.private_constants_rule.style = all_upper_style +dotnet_naming_rule.private_constants_rule.symbols = private_constants_symbols +dotnet_naming_rule.unity_serialized_field_rule.import_to_resharper = True +dotnet_naming_rule.unity_serialized_field_rule.resharper_description = Unity serialized field +dotnet_naming_rule.unity_serialized_field_rule.resharper_guid = 5f0fdb63-c892-4d2c-9324-15c80b22a7ef +dotnet_naming_rule.unity_serialized_field_rule.severity = warning +dotnet_naming_rule.unity_serialized_field_rule.style = lower_camel_case_style +dotnet_naming_rule.unity_serialized_field_rule.symbols = unity_serialized_field_symbols +dotnet_naming_style.all_upper_style.capitalization = all_upper +dotnet_naming_style.all_upper_style.word_separator = _ +dotnet_naming_style.lower_camel_case_style.capitalization = camel_case +dotnet_naming_symbols.private_constants_symbols.applicable_accessibilities = private +dotnet_naming_symbols.private_constants_symbols.applicable_kinds = field +dotnet_naming_symbols.private_constants_symbols.required_modifiers = const +dotnet_naming_symbols.unity_serialized_field_symbols.applicable_accessibilities = * +dotnet_naming_symbols.unity_serialized_field_symbols.applicable_kinds = +dotnet_naming_symbols.unity_serialized_field_symbols.resharper_applicable_kinds = unity_serialised_field +dotnet_naming_symbols.unity_serialized_field_symbols.resharper_required_modifiers = instance +dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:warning +dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:warning +dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary:warning +dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion +dotnet_style_predefined_type_for_member_access = true:suggestion +dotnet_style_qualification_for_event = false:suggestion +dotnet_style_qualification_for_field = false:suggestion +dotnet_style_qualification_for_method = false:suggestion +dotnet_style_qualification_for_property = false:suggestion +dotnet_style_require_accessibility_modifiers = never:suggestion # ReSharper properties -resharper_align_linq_query = true -resharper_align_multiline_argument = true -resharper_align_multiline_array_and_object_initializer = false -resharper_align_multiline_binary_expressions_chain = true -resharper_align_multiline_binary_patterns = true -resharper_align_multiline_calls_chain = true -resharper_align_multiline_expression = true -resharper_align_multiline_expression_braces = true -resharper_align_multiline_extends_list = true -resharper_align_multiline_for_stmt = true -resharper_align_multiline_list_pattern = true -resharper_align_multiline_parameter = true -resharper_align_multiline_property_pattern = true -resharper_align_multiline_switch_expression = true -resharper_align_multiple_declaration = true -resharper_align_multline_type_parameter_constrains = true -resharper_align_multline_type_parameter_list = true -resharper_align_ternary = align_all -resharper_align_tuple_components = true -resharper_autodetect_indent_settings = true -resharper_braces_for_for = required_for_multiline -resharper_braces_for_foreach = required_for_multiline -resharper_braces_for_ifelse = required_for_multiline -resharper_braces_for_while = required_for_multiline -resharper_builtin_type_apply_to_native_integer = true -resharper_constructor_or_destructor_body = expression_body -resharper_csharp_align_first_arg_by_paren = true -resharper_csharp_empty_block_style = together_same_line -resharper_csharp_place_comments_at_first_column = true -resharper_csharp_prefer_qualified_reference = false -resharper_default_value_when_type_not_evident = default_expression -resharper_enforce_line_ending_style = true +resharper_align_first_arg_by_paren = false +resharper_align_linq_query = true +resharper_align_multiline_argument = true +resharper_align_multiline_array_and_object_initializer = false +resharper_align_multiline_binary_expressions_chain = true +resharper_align_multiline_binary_patterns = true +resharper_align_multiline_calls_chain = true +resharper_align_multiline_expression = true +resharper_align_multiline_expression_braces = true +resharper_align_multiline_extends_list = true +resharper_align_multiline_for_stmt = true +resharper_align_multiline_list_pattern = true +resharper_align_multiline_parameter = true +resharper_align_multiline_property_pattern = true +resharper_align_multiline_switch_expression = true +resharper_align_multiple_declaration = true +resharper_align_multline_type_parameter_constrains = true +resharper_align_multline_type_parameter_list = true +resharper_align_ternary = align_all +resharper_align_tuple_components = true +resharper_autodetect_indent_settings = true +resharper_braces_for_for = required_for_multiline +resharper_braces_for_foreach = required_for_multiline +resharper_braces_for_ifelse = required_for_multiline +resharper_braces_for_while = required_for_multiline +resharper_builtin_type_apply_to_native_integer = false +resharper_constructor_or_destructor_body = expression_body +resharper_csharp_align_first_arg_by_paren = false +resharper_csharp_empty_block_style = together_same_line +resharper_csharp_place_comments_at_first_column = true +resharper_csharp_prefer_qualified_reference = false +resharper_default_value_when_type_not_evident = default_expression +resharper_enforce_line_ending_style = true resharper_formatter_off_tag = @formatter:off -resharper_formatter_on_tag = @formatter:on -resharper_formatter_tags_enabled = true -resharper_for_built_in_types = use_var_when_evident -resharper_function_declaration_return_type_style = on_single_line -resharper_function_definition_return_type_style = on_single_line -resharper_html_pi_attribute_style = first_attribute_on_single_line -resharper_indent_anonymous_method_block = true -resharper_indent_preprocessor_if = outdent -resharper_indent_preprocessor_other = outdent -resharper_indent_preprocessor_region = outdent -resharper_int_align = true -resharper_int_align_bitfield_sizes = true -resharper_int_align_comments = true -resharper_int_align_declaration_names = true -resharper_int_align_enum_initializers = true -resharper_int_align_eq = true -resharper_keep_existing_embedded_arrangement = false -resharper_keep_existing_initializer_arrangement = false -resharper_keep_existing_list_patterns_arrangement = false -resharper_keep_existing_property_patterns_arrangement = false -resharper_keep_existing_switch_expression_arrangement = false -resharper_line_break_after_colon_in_member_initializer_lists = on_single_line -resharper_line_break_before_requires_clause = on_single_line -resharper_linkage_specification_indentation = all -resharper_local_function_body = expression_body -resharper_member_initializer_list_style = on_single_line -resharper_method_or_operator_body = expression_body -resharper_outdent_binary_ops = true -resharper_outdent_binary_pattern_ops = true -resharper_outdent_commas = true -resharper_outdent_dots = true -resharper_outdent_statement_labels = true -resharper_parentheses_redundancy_style = remove -resharper_place_attribute_on_same_line = false -resharper_place_simple_embedded_statement_on_same_line = false -resharper_qualified_using_at_nested_scope = true -resharper_show_autodetect_configure_formatting_tip = false -resharper_simple_block_style = on_single_line -resharper_simple_case_statement_style = line_break -resharper_simple_embedded_statement_style = on_single_line -resharper_space_after_ptr_in_data_member = false -resharper_space_after_ptr_in_method = false -resharper_space_after_ref_in_data_member = false -resharper_space_after_ref_in_method = false -resharper_space_before_ptr_in_data_member = true -resharper_space_before_ptr_in_method = true -resharper_space_before_ref_in_data_member = true -resharper_space_before_ref_in_method = true -resharper_space_before_template_params = false -resharper_space_within_empty_braces = false -resharper_toplevel_function_declaration_return_type_style = on_single_line -resharper_toplevel_function_definition_return_type_style = on_single_line -resharper_use_indent_from_vs = false -resharper_wrap_after_dot_in_method_calls = true -resharper_wrap_base_clause_style = chop_if_long -resharper_wrap_braced_init_list_style = chop_if_long -resharper_wrap_ctor_initializer_style = chop_if_long -resharper_wrap_lines = true -resharper_xmldoc_attribute_indent = align_by_first_attribute -resharper_xmldoc_attribute_style = first_attribute_on_single_line -resharper_xmldoc_pi_attribute_style = first_attribute_on_single_line +resharper_formatter_on_tag = @formatter:on +resharper_formatter_tags_enabled = true +resharper_for_built_in_types = use_var_when_evident +resharper_function_declaration_return_type_style = on_single_line +resharper_function_definition_return_type_style = on_single_line +resharper_html_pi_attribute_style = first_attribute_on_single_line +resharper_indent_anonymous_method_block = false +resharper_indent_preprocessor_if = outdent +resharper_indent_preprocessor_other = outdent +resharper_indent_preprocessor_region = outdent +resharper_int_align = true +resharper_int_align_bitfield_sizes = true +resharper_int_align_comments = true +resharper_int_align_declaration_names = true +resharper_int_align_enum_initializers = true +resharper_int_align_eq = true +resharper_keep_existing_embedded_arrangement = false +resharper_keep_existing_initializer_arrangement = false +resharper_keep_existing_list_patterns_arrangement = false +resharper_keep_existing_property_patterns_arrangement = false +resharper_keep_existing_switch_expression_arrangement = false +resharper_line_break_after_colon_in_member_initializer_lists = on_single_line +resharper_line_break_before_requires_clause = on_single_line +resharper_linkage_specification_indentation = all +resharper_local_function_body = expression_body +resharper_member_initializer_list_style = on_single_line +resharper_method_or_operator_body = expression_body +resharper_outdent_binary_ops = true +resharper_outdent_binary_pattern_ops = true +resharper_outdent_commas = true +resharper_outdent_dots = true +resharper_outdent_statement_labels = true +resharper_parentheses_redundancy_style = remove +resharper_place_attribute_on_same_line = false +resharper_place_simple_embedded_statement_on_same_line = false +resharper_qualified_using_at_nested_scope = true +resharper_show_autodetect_configure_formatting_tip = false +resharper_simple_block_style = on_single_line +resharper_simple_case_statement_style = line_break +resharper_simple_embedded_statement_style = on_single_line +resharper_space_after_ptr_in_data_member = false +resharper_space_after_ptr_in_method = false +resharper_space_after_ref_in_data_member = false +resharper_space_after_ref_in_method = false +resharper_space_before_ptr_in_data_member = true +resharper_space_before_ptr_in_method = true +resharper_space_before_ref_in_data_member = true +resharper_space_before_ref_in_method = true +resharper_space_before_template_params = false +resharper_space_within_empty_braces = false +resharper_toplevel_function_declaration_return_type_style = on_single_line +resharper_toplevel_function_definition_return_type_style = on_single_line +resharper_use_indent_from_vs = false +resharper_wrap_after_dot_in_method_calls = true +resharper_wrap_base_clause_style = chop_if_long +resharper_wrap_braced_init_list_style = chop_if_long +resharper_wrap_ctor_initializer_style = chop_if_long +resharper_wrap_lines = true +resharper_xmldoc_attribute_indent = align_by_first_attribute +resharper_xmldoc_attribute_style = first_attribute_on_single_line +resharper_xmldoc_pi_attribute_style = first_attribute_on_single_line # ReSharper inspection severities -resharper_annotate_can_be_null_parameter_highlighting = warning -resharper_annotate_can_be_null_type_member_highlighting = warning -resharper_annotate_not_null_parameter_highlighting = warning -resharper_annotate_not_null_type_member_highlighting = warning -resharper_arguments_style_anonymous_function_highlighting = warning -resharper_arguments_style_literal_highlighting = warning -resharper_arguments_style_named_expression_highlighting = warning -resharper_arguments_style_other_highlighting = warning -resharper_arguments_style_string_literal_highlighting = warning -resharper_arrange_accessor_owner_body_highlighting = warning -resharper_arrange_constructor_or_destructor_body_highlighting = warning -resharper_arrange_local_function_body_highlighting = warning -resharper_arrange_method_or_operator_body_highlighting = warning -resharper_arrange_redundant_parentheses_highlighting = hint -resharper_arrange_static_member_qualifier_highlighting = warning -resharper_arrange_this_qualifier_highlighting = hint -resharper_arrange_trailing_comma_in_multiline_lists_highlighting = warning -resharper_arrange_trailing_comma_in_singleline_lists_highlighting = warning -resharper_arrange_type_member_modifiers_highlighting = hint -resharper_arrange_type_modifiers_highlighting = hint -resharper_arrange_var_keywords_in_deconstructing_declaration_highlighting = warning -resharper_async_void_method_highlighting = warning -resharper_auto_property_can_be_made_get_only_global_highlighting = warning -resharper_auto_property_can_be_made_get_only_local_highlighting = warning -resharper_bad_attribute_brackets_spaces_highlighting = warning -resharper_bad_braces_spaces_highlighting = warning -resharper_bad_colon_spaces_highlighting = warning -resharper_bad_comma_spaces_highlighting = warning -resharper_bad_control_braces_indent_highlighting = warning -resharper_bad_control_braces_line_breaks_highlighting = warning -resharper_bad_declaration_braces_indent_highlighting = warning -resharper_bad_declaration_braces_line_breaks_highlighting = warning -resharper_bad_empty_braces_line_breaks_highlighting = warning -resharper_bad_expression_braces_indent_highlighting = warning -resharper_bad_expression_braces_line_breaks_highlighting = warning -resharper_bad_generic_brackets_spaces_highlighting = warning -resharper_bad_indent_highlighting = warning -resharper_bad_linq_line_breaks_highlighting = warning -resharper_bad_member_access_spaces_highlighting = warning -resharper_bad_namespace_braces_indent_highlighting = warning -resharper_bad_parens_line_breaks_highlighting = warning -resharper_bad_parens_spaces_highlighting = warning -resharper_bad_preprocessor_indent_highlighting = warning -resharper_bad_semicolon_spaces_highlighting = warning -resharper_bad_spaces_after_keyword_highlighting = warning -resharper_bad_square_brackets_spaces_highlighting = warning -resharper_bad_switch_braces_indent_highlighting = warning -resharper_bad_symbol_spaces_highlighting = warning -resharper_built_in_type_reference_style_for_member_access_highlighting = hint -resharper_built_in_type_reference_style_highlighting = hint -resharper_check_for_reference_equality_instead_1_highlighting = warning -resharper_check_for_reference_equality_instead_2_highlighting = warning -resharper_check_for_reference_equality_instead_3_highlighting = warning -resharper_check_for_reference_equality_instead_4_highlighting = warning -resharper_class_can_be_sealed_global_highlighting = warning -resharper_class_can_be_sealed_local_highlighting = warning -resharper_class_never_instantiated_global_highlighting = warning -resharper_class_never_instantiated_local_highlighting = warning -resharper_class_with_virtual_members_never_inherited_global_highlighting = warning -resharper_class_with_virtual_members_never_inherited_local_highlighting = warning -resharper_comment_typo_highlighting = none -resharper_compare_non_constrained_generic_with_null_highlighting = warning -resharper_convert_closure_to_method_group_highlighting = warning -resharper_convert_conditional_ternary_expression_to_switch_expression_highlighting = warning -resharper_convert_if_do_to_while_highlighting = warning -resharper_convert_if_statement_to_conditional_ternary_expression_highlighting = warning -resharper_convert_if_statement_to_null_coalescing_assignment_highlighting = warning -resharper_convert_if_statement_to_null_coalescing_expression_highlighting = warning -resharper_convert_if_statement_to_return_statement_highlighting = warning -resharper_convert_if_statement_to_switch_statement_highlighting = warning -resharper_convert_if_to_or_expression_highlighting = warning -resharper_convert_nullable_to_short_form_highlighting = warning -resharper_convert_switch_statement_to_switch_expression_highlighting = warning -resharper_convert_to_auto_property_highlighting = warning -resharper_convert_to_auto_property_when_possible_highlighting = warning -resharper_convert_to_auto_property_with_private_setter_highlighting = warning -resharper_convert_to_compound_assignment_highlighting = warning -resharper_convert_to_constant_global_highlighting = warning -resharper_convert_to_constant_local_highlighting = warning -resharper_convert_to_lambda_expression_highlighting = warning -resharper_convert_to_local_function_highlighting = warning -resharper_convert_to_null_coalescing_compound_assignment_highlighting = warning -resharper_convert_to_primary_constructor_highlighting = warning -resharper_convert_to_static_class_highlighting = warning -resharper_convert_to_using_declaration_highlighting = warning -resharper_cpp_enforce_cv_qualifiers_order_highlighting = hint -resharper_cpp_enforce_cv_qualifiers_placement_highlighting = hint -resharper_cpp_enforce_do_statement_braces_highlighting = hint -resharper_cpp_enforce_for_statement_braces_highlighting = hint -resharper_cpp_enforce_function_declaration_style_highlighting = hint -resharper_cpp_enforce_if_statement_braces_highlighting = hint -resharper_cpp_enforce_type_alias_code_style_highlighting = hint -resharper_cpp_enforce_while_statement_braces_highlighting = hint -resharper_cpp_remove_redundant_braces_highlighting = hint -resharper_double_negation_in_pattern_highlighting = warning -resharper_double_negation_operator_highlighting = warning -resharper_event_never_invoked_global_highlighting = warning -resharper_event_never_subscribed_to_global_highlighting = warning -resharper_event_never_subscribed_to_local_highlighting = warning -resharper_field_can_be_made_read_only_global_highlighting = warning -resharper_field_can_be_made_read_only_local_highlighting = warning -resharper_foreach_can_be_converted_to_query_using_another_get_enumerator_highlighting = warning -resharper_foreach_can_be_partly_converted_to_query_using_another_get_enumerator_highlighting = none -resharper_for_can_be_converted_to_foreach_highlighting = warning -resharper_heap_view_boxing_allocation_highlighting = none -resharper_heap_view_closure_allocation_highlighting = none -resharper_heap_view_delegate_allocation_highlighting = none -resharper_heap_view_object_allocation_evident_highlighting = none -resharper_heap_view_object_allocation_highlighting = none -resharper_identifier_typo_highlighting = none -resharper_incorrect_blank_lines_near_braces_highlighting = warning -resharper_inheritdoc_consider_usage_highlighting = warning -resharper_inline_out_variable_declaration_highlighting = warning -resharper_inline_temporary_variable_highlighting = warning -resharper_introduce_optional_parameters_global_highlighting = warning -resharper_introduce_optional_parameters_local_highlighting = warning -resharper_invert_condition_1_highlighting = warning -resharper_invert_if_highlighting = warning -resharper_invocation_is_skipped_highlighting = warning -resharper_invoke_as_extension_method_highlighting = warning -resharper_join_declaration_and_initializer_highlighting = warning -resharper_join_null_check_with_usage_highlighting = warning -resharper_lambda_expression_must_be_static_highlighting = warning -resharper_local_function_can_be_made_static_highlighting = warning -resharper_loop_can_be_converted_to_query_highlighting = warning -resharper_loop_can_be_partly_converted_to_query_highlighting = warning -resharper_member_can_be_file_local_highlighting = warning -resharper_member_can_be_internal_highlighting = warning -resharper_member_can_be_made_static_global_highlighting = warning -resharper_member_can_be_made_static_local_highlighting = warning -resharper_member_can_be_private_global_highlighting = warning -resharper_member_can_be_private_local_highlighting = warning -resharper_member_can_be_protected_global_highlighting = warning -resharper_member_can_be_protected_local_highlighting = warning -resharper_merge_and_pattern_highlighting = warning -resharper_merge_cast_with_type_check_highlighting = warning -resharper_merge_conditional_expression_highlighting = warning -resharper_merge_into_logical_pattern_highlighting = warning -resharper_merge_into_negated_pattern_highlighting = warning -resharper_merge_into_pattern_highlighting = warning -resharper_merge_nested_property_patterns_highlighting = warning -resharper_merge_sequential_checks_highlighting = warning -resharper_method_has_async_overload_highlighting = warning -resharper_method_has_async_overload_with_cancellation_highlighting = warning -resharper_method_supports_cancellation_highlighting = warning -resharper_missing_blank_lines_highlighting = warning -resharper_missing_linebreak_highlighting = warning -resharper_missing_space_highlighting = warning -resharper_more_specific_foreach_variable_type_available_highlighting = warning -resharper_move_to_existing_positional_deconstruction_pattern_highlighting = warning -resharper_move_variable_declaration_inside_loop_condition_highlighting = warning -resharper_multiple_spaces_highlighting = warning -resharper_multiple_statements_on_one_line_highlighting = warning -resharper_multiple_type_members_on_one_line_highlighting = warning -resharper_negation_of_relational_pattern_highlighting = warning -resharper_negative_equality_expression_highlighting = warning -resharper_nested_string_interpolation_highlighting = warning -resharper_not_accessed_field_global_highlighting = warning -resharper_nullable_warning_suppression_is_used_highlighting = warning -resharper_outdent_is_off_prev_level_highlighting = warning -resharper_out_parameter_value_is_always_discarded_global_highlighting = warning -resharper_parameter_only_used_for_precondition_check_global_highlighting = warning -resharper_parameter_type_can_be_enumerable_global_highlighting = warning -resharper_parameter_type_can_be_enumerable_local_highlighting = warning -resharper_pass_string_interpolation_highlighting = warning -resharper_possible_unintended_queryable_as_enumerable_highlighting = warning -resharper_property_can_be_made_init_only_global_highlighting = warning -resharper_property_can_be_made_init_only_local_highlighting = warning -resharper_public_constructor_in_abstract_class_highlighting = warning -resharper_raw_string_can_be_simplified_highlighting = warning -resharper_redundant_accessor_body_highlighting = warning -resharper_redundant_always_match_subpattern_highlighting = warning -resharper_redundant_array_creation_expression_highlighting = warning -resharper_redundant_attribute_parentheses_highlighting = warning -resharper_redundant_attribute_usage_property_highlighting = warning -resharper_redundant_base_qualifier_highlighting = warning -resharper_redundant_blank_lines_highlighting = warning -resharper_redundant_collection_initializer_element_braces_highlighting = warning -resharper_redundant_configure_await_highlighting = warning -resharper_redundant_declaration_semicolon_highlighting = warning -resharper_redundant_discard_designation_highlighting = warning -resharper_redundant_empty_object_creation_argument_list_highlighting = warning -resharper_redundant_enum_case_label_for_default_section_highlighting = warning -resharper_redundant_explicit_params_array_creation_highlighting = warning -resharper_redundant_fixed_pointer_declaration_highlighting = warning -resharper_redundant_if_else_block_highlighting = warning -resharper_redundant_immediate_delegate_invocation_highlighting = warning -resharper_redundant_is_before_relational_pattern_highlighting = warning -resharper_redundant_lambda_signature_parentheses_highlighting = warning -resharper_redundant_overload_global_highlighting = warning -resharper_redundant_overload_local_highlighting = warning -resharper_redundant_pattern_parentheses_highlighting = warning -resharper_redundant_property_pattern_clause_highlighting = warning -resharper_redundant_query_order_by_ascending_keyword_highlighting = warning -resharper_redundant_range_bound_highlighting = warning -resharper_redundant_readonly_modifier_highlighting = warning -resharper_redundant_space_highlighting = warning -resharper_redundant_string_interpolation_highlighting = warning -resharper_redundant_to_string_call_for_value_type_highlighting = warning -resharper_redundant_verbatim_prefix_highlighting = warning -resharper_redundant_verbatim_string_prefix_highlighting = warning -resharper_redundant_with_expression_highlighting = warning -resharper_remove_constructor_invocation_highlighting = warning -resharper_remove_redundant_braces_highlighting = warning -resharper_remove_redundant_or_statement_false_highlighting = warning -resharper_remove_redundant_or_statement_true_highlighting = warning -resharper_remove_to_list_1_highlighting = warning -resharper_remove_to_list_2_highlighting = warning -resharper_replace_auto_property_with_computed_property_highlighting = warning -resharper_replace_conditional_expression_with_null_coalescing_highlighting = warning -resharper_replace_object_pattern_with_var_pattern_highlighting = warning -resharper_replace_slice_with_range_indexer_highlighting = warning -resharper_replace_substring_with_range_indexer_highlighting = warning -resharper_replace_with_field_keyword_highlighting = warning -resharper_replace_with_first_or_default_1_highlighting = warning -resharper_replace_with_first_or_default_2_highlighting = warning -resharper_replace_with_first_or_default_3_highlighting = warning -resharper_replace_with_first_or_default_4_highlighting = warning -resharper_replace_with_last_or_default_1_highlighting = warning -resharper_replace_with_last_or_default_2_highlighting = warning -resharper_replace_with_last_or_default_3_highlighting = warning -resharper_replace_with_last_or_default_4_highlighting = warning -resharper_replace_with_of_type_1_highlighting = warning -resharper_replace_with_of_type_2_highlighting = warning -resharper_replace_with_of_type_3_highlighting = warning -resharper_replace_with_of_type_any_1_highlighting = warning -resharper_replace_with_of_type_any_2_highlighting = warning -resharper_replace_with_of_type_count_1_highlighting = warning -resharper_replace_with_of_type_count_2_highlighting = warning -resharper_replace_with_of_type_first_1_highlighting = warning -resharper_replace_with_of_type_first_2_highlighting = warning -resharper_replace_with_of_type_first_or_default_1_highlighting = warning -resharper_replace_with_of_type_first_or_default_2_highlighting = warning -resharper_replace_with_of_type_last_1_highlighting = warning -resharper_replace_with_of_type_last_2_highlighting = warning -resharper_replace_with_of_type_last_or_default_1_highlighting = warning -resharper_replace_with_of_type_last_or_default_2_highlighting = warning -resharper_replace_with_of_type_long_count_highlighting = warning -resharper_replace_with_of_type_single_1_highlighting = warning -resharper_replace_with_of_type_single_2_highlighting = warning -resharper_replace_with_of_type_single_or_default_1_highlighting = warning -resharper_replace_with_of_type_single_or_default_2_highlighting = warning -resharper_replace_with_of_type_where_highlighting = warning -resharper_replace_with_simple_assignment_false_highlighting = warning -resharper_replace_with_simple_assignment_true_highlighting = warning -resharper_replace_with_single_assignment_false_highlighting = warning -resharper_replace_with_single_assignment_true_highlighting = warning -resharper_replace_with_single_call_to_any_highlighting = warning -resharper_replace_with_single_call_to_count_highlighting = warning -resharper_replace_with_single_call_to_first_highlighting = warning -resharper_replace_with_single_call_to_first_or_default_highlighting = warning -resharper_replace_with_single_call_to_last_highlighting = warning -resharper_replace_with_single_call_to_last_or_default_highlighting = warning -resharper_replace_with_single_call_to_single_highlighting = warning -resharper_replace_with_single_call_to_single_or_default_highlighting = warning -resharper_replace_with_single_or_default_1_highlighting = warning -resharper_replace_with_single_or_default_2_highlighting = warning -resharper_replace_with_single_or_default_3_highlighting = warning -resharper_replace_with_single_or_default_4_highlighting = warning -resharper_replace_with_string_is_null_or_empty_highlighting = warning -resharper_return_type_can_be_enumerable_global_highlighting = warning -resharper_return_type_can_be_enumerable_local_highlighting = warning -resharper_safe_cast_is_used_as_type_check_highlighting = warning -resharper_separate_control_transfer_statement_highlighting = warning -resharper_similar_anonymous_type_nearby_highlighting = warning -resharper_simplify_conditional_ternary_expression_highlighting = warning -resharper_simplify_linq_expression_use_all_highlighting = warning -resharper_simplify_linq_expression_use_any_highlighting = warning -resharper_simplify_linq_expression_use_min_by_and_max_by_highlighting = warning -resharper_simplify_string_interpolation_highlighting = warning -resharper_specify_string_comparison_highlighting = warning -resharper_string_ends_with_is_culture_specific_highlighting = warning -resharper_string_literal_as_interpolation_argument_highlighting = warning -resharper_string_literal_typo_highlighting = warning -resharper_string_starts_with_is_culture_specific_highlighting = warning -resharper_struct_can_be_made_read_only_highlighting = warning -resharper_struct_member_can_be_made_read_only_highlighting = warning -resharper_suggest_base_type_for_parameter_highlighting = none -resharper_suggest_base_type_for_parameter_in_constructor_highlighting = warning -resharper_suggest_var_or_type_built_in_types_highlighting = hint -resharper_suggest_var_or_type_deconstruction_declarations_highlighting = warning -resharper_suggest_var_or_type_elsewhere_highlighting = hint -resharper_suggest_var_or_type_simple_types_highlighting = hint -resharper_swap_via_deconstruction_highlighting = warning +resharper_annotate_can_be_null_parameter_highlighting = warning +resharper_annotate_can_be_null_type_member_highlighting = warning +resharper_annotate_not_null_parameter_highlighting = warning +resharper_annotate_not_null_type_member_highlighting = warning +resharper_arguments_style_anonymous_function_highlighting = warning +resharper_arguments_style_literal_highlighting = warning +resharper_arguments_style_named_expression_highlighting = warning +resharper_arguments_style_other_highlighting = warning +resharper_arguments_style_string_literal_highlighting = warning +resharper_arrange_accessor_owner_body_highlighting = warning +resharper_arrange_constructor_or_destructor_body_highlighting = warning +resharper_arrange_local_function_body_highlighting = warning +resharper_arrange_method_or_operator_body_highlighting = warning +resharper_arrange_redundant_parentheses_highlighting = hint +resharper_arrange_static_member_qualifier_highlighting = warning +resharper_arrange_this_qualifier_highlighting = hint +resharper_arrange_trailing_comma_in_multiline_lists_highlighting = warning +resharper_arrange_trailing_comma_in_singleline_lists_highlighting = warning +resharper_arrange_type_member_modifiers_highlighting = hint +resharper_arrange_type_modifiers_highlighting = hint +resharper_arrange_var_keywords_in_deconstructing_declaration_highlighting = warning +resharper_async_void_method_highlighting = warning +resharper_auto_property_can_be_made_get_only_global_highlighting = warning +resharper_auto_property_can_be_made_get_only_local_highlighting = warning +resharper_bad_attribute_brackets_spaces_highlighting = warning +resharper_bad_braces_spaces_highlighting = warning +resharper_bad_colon_spaces_highlighting = warning +resharper_bad_comma_spaces_highlighting = warning +resharper_bad_control_braces_indent_highlighting = warning +resharper_bad_control_braces_line_breaks_highlighting = warning +resharper_bad_declaration_braces_indent_highlighting = warning +resharper_bad_declaration_braces_line_breaks_highlighting = warning +resharper_bad_empty_braces_line_breaks_highlighting = warning +resharper_bad_expression_braces_indent_highlighting = warning +resharper_bad_expression_braces_line_breaks_highlighting = warning +resharper_bad_generic_brackets_spaces_highlighting = warning +resharper_bad_indent_highlighting = warning +resharper_bad_linq_line_breaks_highlighting = warning +resharper_bad_member_access_spaces_highlighting = warning +resharper_bad_namespace_braces_indent_highlighting = warning +resharper_bad_parens_line_breaks_highlighting = warning +resharper_bad_parens_spaces_highlighting = warning +resharper_bad_preprocessor_indent_highlighting = warning +resharper_bad_semicolon_spaces_highlighting = warning +resharper_bad_spaces_after_keyword_highlighting = warning +resharper_bad_square_brackets_spaces_highlighting = warning +resharper_bad_switch_braces_indent_highlighting = warning +resharper_bad_symbol_spaces_highlighting = warning +resharper_built_in_type_reference_style_for_member_access_highlighting = hint +resharper_built_in_type_reference_style_highlighting = hint +resharper_check_for_reference_equality_instead_1_highlighting = warning +resharper_check_for_reference_equality_instead_2_highlighting = warning +resharper_check_for_reference_equality_instead_3_highlighting = warning +resharper_check_for_reference_equality_instead_4_highlighting = warning +resharper_class_can_be_sealed_global_highlighting = warning +resharper_class_can_be_sealed_local_highlighting = warning +resharper_class_never_instantiated_global_highlighting = warning +resharper_class_never_instantiated_local_highlighting = warning +resharper_class_with_virtual_members_never_inherited_global_highlighting = warning +resharper_class_with_virtual_members_never_inherited_local_highlighting = warning +resharper_comment_typo_highlighting = none +resharper_compare_non_constrained_generic_with_null_highlighting = warning +resharper_convert_closure_to_method_group_highlighting = warning +resharper_convert_conditional_ternary_expression_to_switch_expression_highlighting = warning +resharper_convert_if_do_to_while_highlighting = warning +resharper_convert_if_statement_to_conditional_ternary_expression_highlighting = warning +resharper_convert_if_statement_to_null_coalescing_assignment_highlighting = warning +resharper_convert_if_statement_to_null_coalescing_expression_highlighting = warning +resharper_convert_if_statement_to_return_statement_highlighting = warning +resharper_convert_if_statement_to_switch_statement_highlighting = warning +resharper_convert_if_to_or_expression_highlighting = warning +resharper_convert_nullable_to_short_form_highlighting = warning +resharper_convert_switch_statement_to_switch_expression_highlighting = warning +resharper_convert_to_auto_property_highlighting = warning +resharper_convert_to_auto_property_when_possible_highlighting = warning +resharper_convert_to_auto_property_with_private_setter_highlighting = warning +resharper_convert_to_compound_assignment_highlighting = warning +resharper_convert_to_constant_global_highlighting = warning +resharper_convert_to_constant_local_highlighting = warning +resharper_convert_to_lambda_expression_highlighting = warning +resharper_convert_to_local_function_highlighting = warning +resharper_convert_to_null_coalescing_compound_assignment_highlighting = warning +resharper_convert_to_primary_constructor_highlighting = warning +resharper_convert_to_static_class_highlighting = warning +resharper_convert_to_using_declaration_highlighting = warning +resharper_cpp_enforce_cv_qualifiers_order_highlighting = hint +resharper_cpp_enforce_cv_qualifiers_placement_highlighting = hint +resharper_cpp_enforce_do_statement_braces_highlighting = hint +resharper_cpp_enforce_for_statement_braces_highlighting = hint +resharper_cpp_enforce_function_declaration_style_highlighting = hint +resharper_cpp_enforce_if_statement_braces_highlighting = hint +resharper_cpp_enforce_type_alias_code_style_highlighting = hint +resharper_cpp_enforce_while_statement_braces_highlighting = hint +resharper_cpp_remove_redundant_braces_highlighting = hint +resharper_double_negation_in_pattern_highlighting = warning +resharper_double_negation_operator_highlighting = warning +resharper_event_never_invoked_global_highlighting = warning +resharper_event_never_subscribed_to_global_highlighting = warning +resharper_event_never_subscribed_to_local_highlighting = warning +resharper_field_can_be_made_read_only_global_highlighting = warning +resharper_field_can_be_made_read_only_local_highlighting = warning +resharper_foreach_can_be_converted_to_query_using_another_get_enumerator_highlighting = warning +resharper_foreach_can_be_partly_converted_to_query_using_another_get_enumerator_highlighting = none +resharper_for_can_be_converted_to_foreach_highlighting = warning +resharper_heap_view_boxing_allocation_highlighting = none +resharper_heap_view_closure_allocation_highlighting = none +resharper_heap_view_delegate_allocation_highlighting = none +resharper_heap_view_object_allocation_evident_highlighting = none +resharper_heap_view_object_allocation_highlighting = none +resharper_identifier_typo_highlighting = none +resharper_incorrect_blank_lines_near_braces_highlighting = warning +resharper_inheritdoc_consider_usage_highlighting = warning +resharper_inline_out_variable_declaration_highlighting = warning +resharper_inline_temporary_variable_highlighting = warning +resharper_introduce_optional_parameters_global_highlighting = warning +resharper_introduce_optional_parameters_local_highlighting = warning +resharper_invert_condition_1_highlighting = warning +resharper_invert_if_highlighting = warning +resharper_invocation_is_skipped_highlighting = warning +resharper_invoke_as_extension_method_highlighting = warning +resharper_join_declaration_and_initializer_highlighting = warning +resharper_join_null_check_with_usage_highlighting = warning +resharper_lambda_expression_must_be_static_highlighting = warning +resharper_local_function_can_be_made_static_highlighting = warning +resharper_loop_can_be_converted_to_query_highlighting = warning +resharper_loop_can_be_partly_converted_to_query_highlighting = warning +resharper_member_can_be_file_local_highlighting = warning +resharper_member_can_be_internal_highlighting = warning +resharper_member_can_be_made_static_global_highlighting = warning +resharper_member_can_be_made_static_local_highlighting = warning +resharper_member_can_be_private_global_highlighting = warning +resharper_member_can_be_private_local_highlighting = warning +resharper_member_can_be_protected_global_highlighting = warning +resharper_member_can_be_protected_local_highlighting = warning +resharper_merge_and_pattern_highlighting = warning +resharper_merge_cast_with_type_check_highlighting = warning +resharper_merge_conditional_expression_highlighting = warning +resharper_merge_into_logical_pattern_highlighting = warning +resharper_merge_into_negated_pattern_highlighting = warning +resharper_merge_into_pattern_highlighting = warning +resharper_merge_nested_property_patterns_highlighting = warning +resharper_merge_sequential_checks_highlighting = warning +resharper_method_has_async_overload_highlighting = warning +resharper_method_has_async_overload_with_cancellation_highlighting = warning +resharper_method_supports_cancellation_highlighting = warning +resharper_missing_blank_lines_highlighting = warning +resharper_missing_linebreak_highlighting = warning +resharper_missing_space_highlighting = warning +resharper_more_specific_foreach_variable_type_available_highlighting = warning +resharper_move_to_existing_positional_deconstruction_pattern_highlighting = warning +resharper_move_variable_declaration_inside_loop_condition_highlighting = warning +resharper_multiple_spaces_highlighting = warning +resharper_multiple_statements_on_one_line_highlighting = warning +resharper_multiple_type_members_on_one_line_highlighting = warning +resharper_negation_of_relational_pattern_highlighting = warning +resharper_negative_equality_expression_highlighting = warning +resharper_nested_string_interpolation_highlighting = warning +resharper_not_accessed_field_global_highlighting = warning +resharper_nullable_warning_suppression_is_used_highlighting = warning +resharper_outdent_is_off_prev_level_highlighting = warning +resharper_out_parameter_value_is_always_discarded_global_highlighting = warning +resharper_parameter_only_used_for_precondition_check_global_highlighting = warning +resharper_parameter_type_can_be_enumerable_global_highlighting = warning +resharper_parameter_type_can_be_enumerable_local_highlighting = warning +resharper_pass_string_interpolation_highlighting = warning +resharper_possible_unintended_queryable_as_enumerable_highlighting = warning +resharper_property_can_be_made_init_only_global_highlighting = warning +resharper_property_can_be_made_init_only_local_highlighting = warning +resharper_public_constructor_in_abstract_class_highlighting = warning +resharper_raw_string_can_be_simplified_highlighting = warning +resharper_redundant_accessor_body_highlighting = warning +resharper_redundant_always_match_subpattern_highlighting = warning +resharper_redundant_array_creation_expression_highlighting = warning +resharper_redundant_attribute_parentheses_highlighting = warning +resharper_redundant_attribute_usage_property_highlighting = warning +resharper_redundant_base_qualifier_highlighting = warning +resharper_redundant_blank_lines_highlighting = warning +resharper_redundant_collection_initializer_element_braces_highlighting = warning +resharper_redundant_configure_await_highlighting = warning +resharper_redundant_declaration_semicolon_highlighting = warning +resharper_redundant_discard_designation_highlighting = warning +resharper_redundant_empty_object_creation_argument_list_highlighting = warning +resharper_redundant_enum_case_label_for_default_section_highlighting = warning +resharper_redundant_explicit_params_array_creation_highlighting = warning +resharper_redundant_fixed_pointer_declaration_highlighting = warning +resharper_redundant_if_else_block_highlighting = warning +resharper_redundant_immediate_delegate_invocation_highlighting = warning +resharper_redundant_is_before_relational_pattern_highlighting = warning +resharper_redundant_lambda_signature_parentheses_highlighting = warning +resharper_redundant_overload_global_highlighting = warning +resharper_redundant_overload_local_highlighting = warning +resharper_redundant_pattern_parentheses_highlighting = warning +resharper_redundant_property_pattern_clause_highlighting = warning +resharper_redundant_query_order_by_ascending_keyword_highlighting = warning +resharper_redundant_range_bound_highlighting = warning +resharper_redundant_readonly_modifier_highlighting = warning +resharper_redundant_space_highlighting = warning +resharper_redundant_string_interpolation_highlighting = warning +resharper_redundant_to_string_call_for_value_type_highlighting = warning +resharper_redundant_verbatim_prefix_highlighting = warning +resharper_redundant_verbatim_string_prefix_highlighting = warning +resharper_redundant_with_expression_highlighting = warning +resharper_remove_constructor_invocation_highlighting = warning +resharper_remove_redundant_braces_highlighting = warning +resharper_remove_redundant_or_statement_false_highlighting = warning +resharper_remove_redundant_or_statement_true_highlighting = warning +resharper_remove_to_list_1_highlighting = warning +resharper_remove_to_list_2_highlighting = warning +resharper_replace_auto_property_with_computed_property_highlighting = warning +resharper_replace_conditional_expression_with_null_coalescing_highlighting = warning +resharper_replace_object_pattern_with_var_pattern_highlighting = warning +resharper_replace_slice_with_range_indexer_highlighting = warning +resharper_replace_substring_with_range_indexer_highlighting = warning +resharper_replace_with_field_keyword_highlighting = warning +resharper_replace_with_first_or_default_1_highlighting = warning +resharper_replace_with_first_or_default_2_highlighting = warning +resharper_replace_with_first_or_default_3_highlighting = warning +resharper_replace_with_first_or_default_4_highlighting = warning +resharper_replace_with_last_or_default_1_highlighting = warning +resharper_replace_with_last_or_default_2_highlighting = warning +resharper_replace_with_last_or_default_3_highlighting = warning +resharper_replace_with_last_or_default_4_highlighting = warning +resharper_replace_with_of_type_1_highlighting = warning +resharper_replace_with_of_type_2_highlighting = warning +resharper_replace_with_of_type_3_highlighting = warning +resharper_replace_with_of_type_any_1_highlighting = warning +resharper_replace_with_of_type_any_2_highlighting = warning +resharper_replace_with_of_type_count_1_highlighting = warning +resharper_replace_with_of_type_count_2_highlighting = warning +resharper_replace_with_of_type_first_1_highlighting = warning +resharper_replace_with_of_type_first_2_highlighting = warning +resharper_replace_with_of_type_first_or_default_1_highlighting = warning +resharper_replace_with_of_type_first_or_default_2_highlighting = warning +resharper_replace_with_of_type_last_1_highlighting = warning +resharper_replace_with_of_type_last_2_highlighting = warning +resharper_replace_with_of_type_last_or_default_1_highlighting = warning +resharper_replace_with_of_type_last_or_default_2_highlighting = warning +resharper_replace_with_of_type_long_count_highlighting = warning +resharper_replace_with_of_type_single_1_highlighting = warning +resharper_replace_with_of_type_single_2_highlighting = warning +resharper_replace_with_of_type_single_or_default_1_highlighting = warning +resharper_replace_with_of_type_single_or_default_2_highlighting = warning +resharper_replace_with_of_type_where_highlighting = warning +resharper_replace_with_simple_assignment_false_highlighting = warning +resharper_replace_with_simple_assignment_true_highlighting = warning +resharper_replace_with_single_assignment_false_highlighting = warning +resharper_replace_with_single_assignment_true_highlighting = warning +resharper_replace_with_single_call_to_any_highlighting = warning +resharper_replace_with_single_call_to_count_highlighting = warning +resharper_replace_with_single_call_to_first_highlighting = warning +resharper_replace_with_single_call_to_first_or_default_highlighting = warning +resharper_replace_with_single_call_to_last_highlighting = warning +resharper_replace_with_single_call_to_last_or_default_highlighting = warning +resharper_replace_with_single_call_to_single_highlighting = warning +resharper_replace_with_single_call_to_single_or_default_highlighting = warning +resharper_replace_with_single_or_default_1_highlighting = warning +resharper_replace_with_single_or_default_2_highlighting = warning +resharper_replace_with_single_or_default_3_highlighting = warning +resharper_replace_with_single_or_default_4_highlighting = warning +resharper_replace_with_string_is_null_or_empty_highlighting = warning +resharper_return_type_can_be_enumerable_global_highlighting = warning +resharper_return_type_can_be_enumerable_local_highlighting = warning +resharper_safe_cast_is_used_as_type_check_highlighting = warning +resharper_separate_control_transfer_statement_highlighting = warning +resharper_similar_anonymous_type_nearby_highlighting = warning +resharper_simplify_conditional_ternary_expression_highlighting = warning +resharper_simplify_linq_expression_use_all_highlighting = warning +resharper_simplify_linq_expression_use_any_highlighting = warning +resharper_simplify_linq_expression_use_min_by_and_max_by_highlighting = warning +resharper_simplify_string_interpolation_highlighting = warning +resharper_specify_string_comparison_highlighting = warning +resharper_string_ends_with_is_culture_specific_highlighting = warning +resharper_string_literal_as_interpolation_argument_highlighting = warning +resharper_string_literal_typo_highlighting = warning +resharper_string_starts_with_is_culture_specific_highlighting = warning +resharper_struct_can_be_made_read_only_highlighting = warning +resharper_struct_member_can_be_made_read_only_highlighting = warning +resharper_suggest_base_type_for_parameter_highlighting = none +resharper_suggest_base_type_for_parameter_in_constructor_highlighting = warning +resharper_suggest_var_or_type_built_in_types_highlighting = hint +resharper_suggest_var_or_type_deconstruction_declarations_highlighting = warning +resharper_suggest_var_or_type_elsewhere_highlighting = hint +resharper_suggest_var_or_type_simple_types_highlighting = hint +resharper_swap_via_deconstruction_highlighting = warning resharper_switch_expression_handles_some_known_enum_values_with_exception_in_default_highlighting = warning -resharper_switch_statement_handles_some_known_enum_values_with_default_highlighting = none -resharper_switch_statement_missing_some_enum_cases_no_default_highlighting = none -resharper_tabs_and_spaces_mismatch_highlighting = warning -resharper_tabs_are_disallowed_highlighting = warning -resharper_tabs_outside_indent_highlighting = warning -resharper_tail_recursive_call_highlighting = warning -resharper_too_wide_local_variable_scope_highlighting = warning -resharper_try_cast_always_succeeds_highlighting = warning -resharper_try_statements_can_be_merged_highlighting = warning -resharper_type_parameter_can_be_variant_highlighting = warning -resharper_unnecessary_whitespace_highlighting = warning -resharper_unused_member_global_highlighting = warning -resharper_unused_member_hierarchy_global_highlighting = warning -resharper_unused_member_in_super_global_highlighting = warning -resharper_unused_method_return_value_global_highlighting = warning -resharper_unused_parameter_global_highlighting = warning -resharper_unused_type_global_highlighting = warning -resharper_use_array_creation_expression_1_highlighting = warning -resharper_use_array_creation_expression_2_highlighting = warning -resharper_use_array_empty_method_highlighting = warning -resharper_use_await_using_highlighting = warning -resharper_use_cancellation_token_for_i_async_enumerable_highlighting = warning -resharper_use_collection_count_property_highlighting = warning -resharper_use_configure_await_false_highlighting = warning -resharper_use_deconstruction_highlighting = warning -resharper_use_empty_types_field_highlighting = warning -resharper_use_event_args_empty_field_highlighting = warning -resharper_use_format_specifier_in_format_string_highlighting = warning -resharper_use_indexed_property_highlighting = warning -resharper_use_index_from_end_expression_highlighting = warning -resharper_use_is_operator_1_highlighting = warning -resharper_use_is_operator_2_highlighting = warning -resharper_use_method_any_0_highlighting = warning -resharper_use_method_any_1_highlighting = warning -resharper_use_method_any_2_highlighting = warning -resharper_use_method_any_3_highlighting = warning -resharper_use_method_any_4_highlighting = warning -resharper_use_method_is_instance_of_type_highlighting = warning -resharper_use_nameof_expression_for_part_of_the_string_highlighting = warning -resharper_use_nameof_expression_highlighting = warning -resharper_use_nameof_for_dependency_property_highlighting = warning -resharper_use_name_of_instead_of_type_of_highlighting = warning -resharper_use_negated_pattern_in_is_expression_highlighting = warning -resharper_use_negated_pattern_matching_highlighting = warning -resharper_use_nullable_annotation_instead_of_attribute_highlighting = warning -resharper_use_nullable_attributes_supported_by_compiler_highlighting = warning -resharper_use_null_propagation_highlighting = warning -resharper_use_object_or_collection_initializer_highlighting = warning -resharper_use_pattern_matching_highlighting = warning -resharper_use_positional_deconstruction_pattern_highlighting = warning -resharper_use_raw_string_highlighting = warning -resharper_use_string_interpolation_highlighting = warning -resharper_use_switch_case_pattern_variable_highlighting = warning -resharper_use_throw_if_null_method_highlighting = warning -resharper_use_unsigned_right_shift_operator_highlighting = warning -resharper_use_verbatim_string_highlighting = warning -resharper_use_with_expression_to_copy_anonymous_object_highlighting = warning -resharper_use_with_expression_to_copy_record_highlighting = warning -resharper_use_with_expression_to_copy_struct_highlighting = warning -resharper_use_with_expression_to_copy_tuple_highlighting = warning -resharper_virtual_member_never_overridden_global_highlighting = warning -resharper_virtual_member_never_overridden_local_highlighting = warning -resharper_web_config_module_not_resolved_highlighting = warning -resharper_web_config_type_not_resolved_highlighting = warning -resharper_web_config_wrong_module_highlighting = warning -resharper_with_expression_instead_of_initializer_highlighting = warning -resharper_wrong_indent_size_highlighting = warning +resharper_switch_statement_handles_some_known_enum_values_with_default_highlighting = none +resharper_switch_statement_missing_some_enum_cases_no_default_highlighting = none +resharper_tabs_and_spaces_mismatch_highlighting = warning +resharper_tabs_are_disallowed_highlighting = warning +resharper_tabs_outside_indent_highlighting = warning +resharper_tail_recursive_call_highlighting = warning +resharper_too_wide_local_variable_scope_highlighting = warning +resharper_try_cast_always_succeeds_highlighting = warning +resharper_try_statements_can_be_merged_highlighting = warning +resharper_type_parameter_can_be_variant_highlighting = warning +resharper_unnecessary_whitespace_highlighting = warning +resharper_unused_member_global_highlighting = warning +resharper_unused_member_hierarchy_global_highlighting = warning +resharper_unused_member_in_super_global_highlighting = warning +resharper_unused_method_return_value_global_highlighting = warning +resharper_unused_parameter_global_highlighting = warning +resharper_unused_type_global_highlighting = warning +resharper_use_array_creation_expression_1_highlighting = warning +resharper_use_array_creation_expression_2_highlighting = warning +resharper_use_array_empty_method_highlighting = warning +resharper_use_await_using_highlighting = warning +resharper_use_cancellation_token_for_i_async_enumerable_highlighting = warning +resharper_use_collection_count_property_highlighting = warning +resharper_use_configure_await_false_highlighting = warning +resharper_use_deconstruction_highlighting = warning +resharper_use_empty_types_field_highlighting = warning +resharper_use_event_args_empty_field_highlighting = warning +resharper_use_format_specifier_in_format_string_highlighting = warning +resharper_use_indexed_property_highlighting = warning +resharper_use_index_from_end_expression_highlighting = warning +resharper_use_is_operator_1_highlighting = warning +resharper_use_is_operator_2_highlighting = warning +resharper_use_method_any_0_highlighting = warning +resharper_use_method_any_1_highlighting = warning +resharper_use_method_any_2_highlighting = warning +resharper_use_method_any_3_highlighting = warning +resharper_use_method_any_4_highlighting = warning +resharper_use_method_is_instance_of_type_highlighting = warning +resharper_use_nameof_expression_for_part_of_the_string_highlighting = warning +resharper_use_nameof_expression_highlighting = warning +resharper_use_nameof_for_dependency_property_highlighting = warning +resharper_use_name_of_instead_of_type_of_highlighting = warning +resharper_use_negated_pattern_in_is_expression_highlighting = warning +resharper_use_negated_pattern_matching_highlighting = warning +resharper_use_nullable_annotation_instead_of_attribute_highlighting = warning +resharper_use_nullable_attributes_supported_by_compiler_highlighting = warning +resharper_use_null_propagation_highlighting = warning +resharper_use_object_or_collection_initializer_highlighting = warning +resharper_use_pattern_matching_highlighting = warning +resharper_use_positional_deconstruction_pattern_highlighting = warning +resharper_use_raw_string_highlighting = warning +resharper_use_string_interpolation_highlighting = warning +resharper_use_switch_case_pattern_variable_highlighting = warning +resharper_use_throw_if_null_method_highlighting = warning +resharper_use_unsigned_right_shift_operator_highlighting = warning +resharper_use_verbatim_string_highlighting = warning +resharper_use_with_expression_to_copy_anonymous_object_highlighting = warning +resharper_use_with_expression_to_copy_record_highlighting = warning +resharper_use_with_expression_to_copy_struct_highlighting = warning +resharper_use_with_expression_to_copy_tuple_highlighting = warning +resharper_virtual_member_never_overridden_global_highlighting = warning +resharper_virtual_member_never_overridden_local_highlighting = warning +resharper_web_config_module_not_resolved_highlighting = warning +resharper_web_config_type_not_resolved_highlighting = warning +resharper_web_config_wrong_module_highlighting = warning +resharper_with_expression_instead_of_initializer_highlighting = warning +resharper_wrong_indent_size_highlighting = warning [*.css] ij_css_align_closing_brace_with_properties = false -ij_css_blank_lines_around_nested_selector = 1 -ij_css_blank_lines_between_blocks = 1 -ij_css_block_comment_add_space = false -ij_css_brace_placement = end_of_line -ij_css_enforce_quotes_on_format = false -ij_css_hex_color_long_format = false -ij_css_hex_color_lower_case = false -ij_css_hex_color_short_format = false -ij_css_hex_color_upper_case = false -ij_css_keep_blank_lines_in_code = 2 -ij_css_keep_indents_on_empty_lines = false -ij_css_keep_single_line_blocks = false -ij_css_properties_order = font,font-family,font-size,font-weight,font-style,font-variant,font-size-adjust,font-stretch,line-height,position,z-index,top,right,bottom,left,display,visibility,float,clear,overflow,overflow-x,overflow-y,clip,zoom,align-content,align-items,align-self,flex,flex-flow,flex-basis,flex-direction,flex-grow,flex-shrink,flex-wrap,justify-content,order,box-sizing,width,min-width,max-width,height,min-height,max-height,margin,margin-top,margin-right,margin-bottom,margin-left,padding,padding-top,padding-right,padding-bottom,padding-left,table-layout,empty-cells,caption-side,border-spacing,border-collapse,list-style,list-style-position,list-style-type,list-style-image,content,quotes,counter-reset,counter-increment,resize,cursor,user-select,nav-index,nav-up,nav-right,nav-down,nav-left,transition,transition-delay,transition-timing-function,transition-duration,transition-property,transform,transform-origin,animation,animation-name,animation-duration,animation-play-state,animation-timing-function,animation-delay,animation-iteration-count,animation-direction,text-align,text-align-last,vertical-align,white-space,text-decoration,text-emphasis,text-emphasis-color,text-emphasis-style,text-emphasis-position,text-indent,text-justify,letter-spacing,word-spacing,text-outline,text-transform,text-wrap,text-overflow,text-overflow-ellipsis,text-overflow-mode,word-wrap,word-break,tab-size,hyphens,pointer-events,opacity,color,border,border-width,border-style,border-color,border-top,border-top-width,border-top-style,border-top-color,border-right,border-right-width,border-right-style,border-right-color,border-bottom,border-bottom-width,border-bottom-style,border-bottom-color,border-left,border-left-width,border-left-style,border-left-color,border-radius,border-top-left-radius,border-top-right-radius,border-bottom-right-radius,border-bottom-left-radius,border-image,border-image-source,border-image-slice,border-image-width,border-image-outset,border-image-repeat,outline,outline-width,outline-style,outline-color,outline-offset,background,background-color,background-image,background-repeat,background-attachment,background-position,background-position-x,background-position-y,background-clip,background-origin,background-size,box-decoration-break,box-shadow,text-shadow -ij_css_space_after_colon = true -ij_css_space_before_opening_brace = true -ij_css_use_double_quotes = true -ij_css_value_alignment = do_not_align +ij_css_blank_lines_around_nested_selector = 1 +ij_css_blank_lines_between_blocks = 1 +ij_css_block_comment_add_space = false +ij_css_brace_placement = end_of_line +ij_css_enforce_quotes_on_format = false +ij_css_hex_color_long_format = false +ij_css_hex_color_lower_case = false +ij_css_hex_color_short_format = false +ij_css_hex_color_upper_case = false +ij_css_keep_blank_lines_in_code = 2 +ij_css_keep_indents_on_empty_lines = false +ij_css_keep_single_line_blocks = false +ij_css_properties_order = font, font-family, font-size, font-weight, font-style, font-variant, font-size-adjust, font-stretch, line-height, position, z-index, top, right, bottom, left, display, visibility, float, clear, overflow, overflow-x, overflow-y, clip, zoom, align-content, align-items, align-self, flex, flex-flow, flex-basis, flex-direction, flex-grow, flex-shrink, flex-wrap, justify-content, order, box-sizing, width, min-width, max-width, height, min-height, max-height, margin, margin-top, margin-right, margin-bottom, margin-left, padding, padding-top, padding-right, padding-bottom, padding-left, table-layout, empty-cells, caption-side, border-spacing, border-collapse, list-style, list-style-position, list-style-type, list-style-image, content, quotes, counter-reset, counter-increment, resize, cursor, user-select, nav-index, nav-up, nav-right, nav-down, nav-left, transition, transition-delay, transition-timing-function, transition-duration, transition-property, transform, transform-origin, animation, animation-name, animation-duration, animation-play-state, animation-timing-function, animation-delay, animation-iteration-count, animation-direction, text-align, text-align-last, vertical-align, white-space, text-decoration, text-emphasis, text-emphasis-color, text-emphasis-style, text-emphasis-position, text-indent, text-justify, letter-spacing, word-spacing, text-outline, text-transform, text-wrap, text-overflow, text-overflow-ellipsis, text-overflow-mode, word-wrap, word-break, tab-size, hyphens, pointer-events, opacity, color, border, border-width, border-style, border-color, border-top, border-top-width, border-top-style, border-top-color, border-right, border-right-width, border-right-style, border-right-color, border-bottom, border-bottom-width, border-bottom-style, border-bottom-color, border-left, border-left-width, border-left-style, border-left-color, border-radius, border-top-left-radius, border-top-right-radius, border-bottom-right-radius, border-bottom-left-radius, border-image, border-image-source, border-image-slice, border-image-width, border-image-outset, border-image-repeat, outline, outline-width, outline-style, outline-color, outline-offset, background, background-color, background-image, background-repeat, background-attachment, background-position, background-position-x, background-position-y, background-clip, background-origin, background-size, box-decoration-break, box-shadow, text-shadow +ij_css_space_after_colon = true +ij_css_space_before_opening_brace = true +ij_css_use_double_quotes = true +ij_css_value_alignment = do_not_align [*.csv] -max_line_length = 2147483647 +max_line_length = 2147483647 ij_csv_wrap_long_lines = false -indent_style = tab -tab_width = 1 +indent_style = tab +tab_width = 1 [*.dart] max_line_length = 80 [*.less] -indent_size = 2 +indent_size = 2 ij_less_align_closing_brace_with_properties = false -ij_less_blank_lines_around_nested_selector = 1 -ij_less_blank_lines_between_blocks = 1 -ij_less_block_comment_add_space = false -ij_less_brace_placement = 0 -ij_less_enforce_quotes_on_format = false -ij_less_hex_color_long_format = false -ij_less_hex_color_lower_case = false -ij_less_hex_color_short_format = false -ij_less_hex_color_upper_case = false -ij_less_keep_blank_lines_in_code = 2 -ij_less_keep_indents_on_empty_lines = false -ij_less_keep_single_line_blocks = false -ij_less_line_comment_add_space = false -ij_less_line_comment_at_first_column = false -ij_less_properties_order = font,font-family,font-size,font-weight,font-style,font-variant,font-size-adjust,font-stretch,line-height,position,z-index,top,right,bottom,left,display,visibility,float,clear,overflow,overflow-x,overflow-y,clip,zoom,align-content,align-items,align-self,flex,flex-flow,flex-basis,flex-direction,flex-grow,flex-shrink,flex-wrap,justify-content,order,box-sizing,width,min-width,max-width,height,min-height,max-height,margin,margin-top,margin-right,margin-bottom,margin-left,padding,padding-top,padding-right,padding-bottom,padding-left,table-layout,empty-cells,caption-side,border-spacing,border-collapse,list-style,list-style-position,list-style-type,list-style-image,content,quotes,counter-reset,counter-increment,resize,cursor,user-select,nav-index,nav-up,nav-right,nav-down,nav-left,transition,transition-delay,transition-timing-function,transition-duration,transition-property,transform,transform-origin,animation,animation-name,animation-duration,animation-play-state,animation-timing-function,animation-delay,animation-iteration-count,animation-direction,text-align,text-align-last,vertical-align,white-space,text-decoration,text-emphasis,text-emphasis-color,text-emphasis-style,text-emphasis-position,text-indent,text-justify,letter-spacing,word-spacing,text-outline,text-transform,text-wrap,text-overflow,text-overflow-ellipsis,text-overflow-mode,word-wrap,word-break,tab-size,hyphens,pointer-events,opacity,color,border,border-width,border-style,border-color,border-top,border-top-width,border-top-style,border-top-color,border-right,border-right-width,border-right-style,border-right-color,border-bottom,border-bottom-width,border-bottom-style,border-bottom-color,border-left,border-left-width,border-left-style,border-left-color,border-radius,border-top-left-radius,border-top-right-radius,border-bottom-right-radius,border-bottom-left-radius,border-image,border-image-source,border-image-slice,border-image-width,border-image-outset,border-image-repeat,outline,outline-width,outline-style,outline-color,outline-offset,background,background-color,background-image,background-repeat,background-attachment,background-position,background-position-x,background-position-y,background-clip,background-origin,background-size,box-decoration-break,box-shadow,text-shadow -ij_less_space_after_colon = true -ij_less_space_before_opening_brace = true -ij_less_use_double_quotes = true -ij_less_value_alignment = 0 +ij_less_blank_lines_around_nested_selector = 1 +ij_less_blank_lines_between_blocks = 1 +ij_less_block_comment_add_space = false +ij_less_brace_placement = 0 +ij_less_enforce_quotes_on_format = false +ij_less_hex_color_long_format = false +ij_less_hex_color_lower_case = false +ij_less_hex_color_short_format = false +ij_less_hex_color_upper_case = false +ij_less_keep_blank_lines_in_code = 2 +ij_less_keep_indents_on_empty_lines = false +ij_less_keep_single_line_blocks = false +ij_less_line_comment_add_space = false +ij_less_line_comment_at_first_column = false +ij_less_properties_order = font, font-family, font-size, font-weight, font-style, font-variant, font-size-adjust, font-stretch, line-height, position, z-index, top, right, bottom, left, display, visibility, float, clear, overflow, overflow-x, overflow-y, clip, zoom, align-content, align-items, align-self, flex, flex-flow, flex-basis, flex-direction, flex-grow, flex-shrink, flex-wrap, justify-content, order, box-sizing, width, min-width, max-width, height, min-height, max-height, margin, margin-top, margin-right, margin-bottom, margin-left, padding, padding-top, padding-right, padding-bottom, padding-left, table-layout, empty-cells, caption-side, border-spacing, border-collapse, list-style, list-style-position, list-style-type, list-style-image, content, quotes, counter-reset, counter-increment, resize, cursor, user-select, nav-index, nav-up, nav-right, nav-down, nav-left, transition, transition-delay, transition-timing-function, transition-duration, transition-property, transform, transform-origin, animation, animation-name, animation-duration, animation-play-state, animation-timing-function, animation-delay, animation-iteration-count, animation-direction, text-align, text-align-last, vertical-align, white-space, text-decoration, text-emphasis, text-emphasis-color, text-emphasis-style, text-emphasis-position, text-indent, text-justify, letter-spacing, word-spacing, text-outline, text-transform, text-wrap, text-overflow, text-overflow-ellipsis, text-overflow-mode, word-wrap, word-break, tab-size, hyphens, pointer-events, opacity, color, border, border-width, border-style, border-color, border-top, border-top-width, border-top-style, border-top-color, border-right, border-right-width, border-right-style, border-right-color, border-bottom, border-bottom-width, border-bottom-style, border-bottom-color, border-left, border-left-width, border-left-style, border-left-color, border-radius, border-top-left-radius, border-top-right-radius, border-bottom-right-radius, border-bottom-left-radius, border-image, border-image-source, border-image-slice, border-image-width, border-image-outset, border-image-repeat, outline, outline-width, outline-style, outline-color, outline-offset, background, background-color, background-image, background-repeat, background-attachment, background-position, background-position-x, background-position-y, background-clip, background-origin, background-size, box-decoration-break, box-shadow, text-shadow +ij_less_space_after_colon = true +ij_less_space_before_opening_brace = true +ij_less_use_double_quotes = true +ij_less_value_alignment = 0 [*.pp] -indent_size = 2 -tab_width = 2 -ij_continuation_indent_size = 2 +indent_size = 2 +tab_width = 2 +ij_continuation_indent_size = 2 ij_puppet_keep_indents_on_empty_lines = false [*.properties] -ij_properties_align_group_field_declarations = true -ij_properties_keep_blank_lines = false -ij_properties_key_value_delimiter = equals +ij_properties_align_group_field_declarations = true +ij_properties_keep_blank_lines = false +ij_properties_key_value_delimiter = equals ij_properties_spaces_around_key_value_delimiter = true [*.sass] -indent_size = 2 +indent_size = 2 ij_sass_align_closing_brace_with_properties = false -ij_sass_blank_lines_around_nested_selector = 1 -ij_sass_blank_lines_between_blocks = 1 -ij_sass_brace_placement = 0 -ij_sass_enforce_quotes_on_format = false -ij_sass_hex_color_long_format = false -ij_sass_hex_color_lower_case = false -ij_sass_hex_color_short_format = false -ij_sass_hex_color_upper_case = false -ij_sass_keep_blank_lines_in_code = 2 -ij_sass_keep_indents_on_empty_lines = false -ij_sass_keep_single_line_blocks = false -ij_sass_line_comment_add_space = false -ij_sass_line_comment_at_first_column = false -ij_sass_properties_order = font,font-family,font-size,font-weight,font-style,font-variant,font-size-adjust,font-stretch,line-height,position,z-index,top,right,bottom,left,display,visibility,float,clear,overflow,overflow-x,overflow-y,clip,zoom,align-content,align-items,align-self,flex,flex-flow,flex-basis,flex-direction,flex-grow,flex-shrink,flex-wrap,justify-content,order,box-sizing,width,min-width,max-width,height,min-height,max-height,margin,margin-top,margin-right,margin-bottom,margin-left,padding,padding-top,padding-right,padding-bottom,padding-left,table-layout,empty-cells,caption-side,border-spacing,border-collapse,list-style,list-style-position,list-style-type,list-style-image,content,quotes,counter-reset,counter-increment,resize,cursor,user-select,nav-index,nav-up,nav-right,nav-down,nav-left,transition,transition-delay,transition-timing-function,transition-duration,transition-property,transform,transform-origin,animation,animation-name,animation-duration,animation-play-state,animation-timing-function,animation-delay,animation-iteration-count,animation-direction,text-align,text-align-last,vertical-align,white-space,text-decoration,text-emphasis,text-emphasis-color,text-emphasis-style,text-emphasis-position,text-indent,text-justify,letter-spacing,word-spacing,text-outline,text-transform,text-wrap,text-overflow,text-overflow-ellipsis,text-overflow-mode,word-wrap,word-break,tab-size,hyphens,pointer-events,opacity,color,border,border-width,border-style,border-color,border-top,border-top-width,border-top-style,border-top-color,border-right,border-right-width,border-right-style,border-right-color,border-bottom,border-bottom-width,border-bottom-style,border-bottom-color,border-left,border-left-width,border-left-style,border-left-color,border-radius,border-top-left-radius,border-top-right-radius,border-bottom-right-radius,border-bottom-left-radius,border-image,border-image-source,border-image-slice,border-image-width,border-image-outset,border-image-repeat,outline,outline-width,outline-style,outline-color,outline-offset,background,background-color,background-image,background-repeat,background-attachment,background-position,background-position-x,background-position-y,background-clip,background-origin,background-size,box-decoration-break,box-shadow,text-shadow -ij_sass_space_after_colon = true -ij_sass_space_before_opening_brace = true -ij_sass_use_double_quotes = true -ij_sass_value_alignment = 0 +ij_sass_blank_lines_around_nested_selector = 1 +ij_sass_blank_lines_between_blocks = 1 +ij_sass_brace_placement = 0 +ij_sass_enforce_quotes_on_format = false +ij_sass_hex_color_long_format = false +ij_sass_hex_color_lower_case = false +ij_sass_hex_color_short_format = false +ij_sass_hex_color_upper_case = false +ij_sass_keep_blank_lines_in_code = 2 +ij_sass_keep_indents_on_empty_lines = false +ij_sass_keep_single_line_blocks = false +ij_sass_line_comment_add_space = false +ij_sass_line_comment_at_first_column = false +ij_sass_properties_order = font, font-family, font-size, font-weight, font-style, font-variant, font-size-adjust, font-stretch, line-height, position, z-index, top, right, bottom, left, display, visibility, float, clear, overflow, overflow-x, overflow-y, clip, zoom, align-content, align-items, align-self, flex, flex-flow, flex-basis, flex-direction, flex-grow, flex-shrink, flex-wrap, justify-content, order, box-sizing, width, min-width, max-width, height, min-height, max-height, margin, margin-top, margin-right, margin-bottom, margin-left, padding, padding-top, padding-right, padding-bottom, padding-left, table-layout, empty-cells, caption-side, border-spacing, border-collapse, list-style, list-style-position, list-style-type, list-style-image, content, quotes, counter-reset, counter-increment, resize, cursor, user-select, nav-index, nav-up, nav-right, nav-down, nav-left, transition, transition-delay, transition-timing-function, transition-duration, transition-property, transform, transform-origin, animation, animation-name, animation-duration, animation-play-state, animation-timing-function, animation-delay, animation-iteration-count, animation-direction, text-align, text-align-last, vertical-align, white-space, text-decoration, text-emphasis, text-emphasis-color, text-emphasis-style, text-emphasis-position, text-indent, text-justify, letter-spacing, word-spacing, text-outline, text-transform, text-wrap, text-overflow, text-overflow-ellipsis, text-overflow-mode, word-wrap, word-break, tab-size, hyphens, pointer-events, opacity, color, border, border-width, border-style, border-color, border-top, border-top-width, border-top-style, border-top-color, border-right, border-right-width, border-right-style, border-right-color, border-bottom, border-bottom-width, border-bottom-style, border-bottom-color, border-left, border-left-width, border-left-style, border-left-color, border-radius, border-top-left-radius, border-top-right-radius, border-bottom-right-radius, border-bottom-left-radius, border-image, border-image-source, border-image-slice, border-image-width, border-image-outset, border-image-repeat, outline, outline-width, outline-style, outline-color, outline-offset, background, background-color, background-image, background-repeat, background-attachment, background-position, background-position-x, background-position-y, background-clip, background-origin, background-size, box-decoration-break, box-shadow, text-shadow +ij_sass_space_after_colon = true +ij_sass_space_before_opening_brace = true +ij_sass_use_double_quotes = true +ij_sass_value_alignment = 0 [*.scss] -indent_size = 2 +indent_size = 2 ij_scss_align_closing_brace_with_properties = false -ij_scss_blank_lines_around_nested_selector = 1 -ij_scss_blank_lines_between_blocks = 1 -ij_scss_block_comment_add_space = false -ij_scss_brace_placement = 0 -ij_scss_enforce_quotes_on_format = false -ij_scss_hex_color_long_format = false -ij_scss_hex_color_lower_case = false -ij_scss_hex_color_short_format = false -ij_scss_hex_color_upper_case = false -ij_scss_keep_blank_lines_in_code = 2 -ij_scss_keep_indents_on_empty_lines = false -ij_scss_keep_single_line_blocks = false -ij_scss_line_comment_add_space = false -ij_scss_line_comment_at_first_column = false -ij_scss_properties_order = font,font-family,font-size,font-weight,font-style,font-variant,font-size-adjust,font-stretch,line-height,position,z-index,top,right,bottom,left,display,visibility,float,clear,overflow,overflow-x,overflow-y,clip,zoom,align-content,align-items,align-self,flex,flex-flow,flex-basis,flex-direction,flex-grow,flex-shrink,flex-wrap,justify-content,order,box-sizing,width,min-width,max-width,height,min-height,max-height,margin,margin-top,margin-right,margin-bottom,margin-left,padding,padding-top,padding-right,padding-bottom,padding-left,table-layout,empty-cells,caption-side,border-spacing,border-collapse,list-style,list-style-position,list-style-type,list-style-image,content,quotes,counter-reset,counter-increment,resize,cursor,user-select,nav-index,nav-up,nav-right,nav-down,nav-left,transition,transition-delay,transition-timing-function,transition-duration,transition-property,transform,transform-origin,animation,animation-name,animation-duration,animation-play-state,animation-timing-function,animation-delay,animation-iteration-count,animation-direction,text-align,text-align-last,vertical-align,white-space,text-decoration,text-emphasis,text-emphasis-color,text-emphasis-style,text-emphasis-position,text-indent,text-justify,letter-spacing,word-spacing,text-outline,text-transform,text-wrap,text-overflow,text-overflow-ellipsis,text-overflow-mode,word-wrap,word-break,tab-size,hyphens,pointer-events,opacity,color,border,border-width,border-style,border-color,border-top,border-top-width,border-top-style,border-top-color,border-right,border-right-width,border-right-style,border-right-color,border-bottom,border-bottom-width,border-bottom-style,border-bottom-color,border-left,border-left-width,border-left-style,border-left-color,border-radius,border-top-left-radius,border-top-right-radius,border-bottom-right-radius,border-bottom-left-radius,border-image,border-image-source,border-image-slice,border-image-width,border-image-outset,border-image-repeat,outline,outline-width,outline-style,outline-color,outline-offset,background,background-color,background-image,background-repeat,background-attachment,background-position,background-position-x,background-position-y,background-clip,background-origin,background-size,box-decoration-break,box-shadow,text-shadow -ij_scss_space_after_colon = true -ij_scss_space_before_opening_brace = true -ij_scss_use_double_quotes = true -ij_scss_value_alignment = 0 +ij_scss_blank_lines_around_nested_selector = 1 +ij_scss_blank_lines_between_blocks = 1 +ij_scss_block_comment_add_space = false +ij_scss_brace_placement = 0 +ij_scss_enforce_quotes_on_format = false +ij_scss_hex_color_long_format = false +ij_scss_hex_color_lower_case = false +ij_scss_hex_color_short_format = false +ij_scss_hex_color_upper_case = false +ij_scss_keep_blank_lines_in_code = 2 +ij_scss_keep_indents_on_empty_lines = false +ij_scss_keep_single_line_blocks = false +ij_scss_line_comment_add_space = false +ij_scss_line_comment_at_first_column = false +ij_scss_properties_order = font, font-family, font-size, font-weight, font-style, font-variant, font-size-adjust, font-stretch, line-height, position, z-index, top, right, bottom, left, display, visibility, float, clear, overflow, overflow-x, overflow-y, clip, zoom, align-content, align-items, align-self, flex, flex-flow, flex-basis, flex-direction, flex-grow, flex-shrink, flex-wrap, justify-content, order, box-sizing, width, min-width, max-width, height, min-height, max-height, margin, margin-top, margin-right, margin-bottom, margin-left, padding, padding-top, padding-right, padding-bottom, padding-left, table-layout, empty-cells, caption-side, border-spacing, border-collapse, list-style, list-style-position, list-style-type, list-style-image, content, quotes, counter-reset, counter-increment, resize, cursor, user-select, nav-index, nav-up, nav-right, nav-down, nav-left, transition, transition-delay, transition-timing-function, transition-duration, transition-property, transform, transform-origin, animation, animation-name, animation-duration, animation-play-state, animation-timing-function, animation-delay, animation-iteration-count, animation-direction, text-align, text-align-last, vertical-align, white-space, text-decoration, text-emphasis, text-emphasis-color, text-emphasis-style, text-emphasis-position, text-indent, text-justify, letter-spacing, word-spacing, text-outline, text-transform, text-wrap, text-overflow, text-overflow-ellipsis, text-overflow-mode, word-wrap, word-break, tab-size, hyphens, pointer-events, opacity, color, border, border-width, border-style, border-color, border-top, border-top-width, border-top-style, border-top-color, border-right, border-right-width, border-right-style, border-right-color, border-bottom, border-bottom-width, border-bottom-style, border-bottom-color, border-left, border-left-width, border-left-style, border-left-color, border-radius, border-top-left-radius, border-top-right-radius, border-bottom-right-radius, border-bottom-left-radius, border-image, border-image-source, border-image-slice, border-image-width, border-image-outset, border-image-repeat, outline, outline-width, outline-style, outline-color, outline-offset, background, background-color, background-image, background-repeat, background-attachment, background-position, background-position-x, background-position-y, background-clip, background-origin, background-size, box-decoration-break, box-shadow, text-shadow +ij_scss_space_after_colon = true +ij_scss_space_before_opening_brace = true +ij_scss_use_double_quotes = true +ij_scss_value_alignment = 0 [*.slim] -indent_size = 2 +indent_size = 2 ij_slim_keep_indents_on_empty_lines = false [*.twig] -ij_twig_keep_indents_on_empty_lines = false +ij_twig_keep_indents_on_empty_lines = false ij_twig_spaces_inside_comments_delimiters = true -ij_twig_spaces_inside_delimiters = true +ij_twig_spaces_inside_delimiters = true ij_twig_spaces_inside_variable_delimiters = true [*.vue] -indent_size = 2 -tab_width = 2 -ij_continuation_indent_size = 4 -ij_vue_indent_children_of_top_level = template +indent_size = 2 +tab_width = 2 +ij_continuation_indent_size = 4 +ij_vue_indent_children_of_top_level = template ij_vue_interpolation_new_line_after_start_delimiter = true -ij_vue_interpolation_new_line_before_end_delimiter = true -ij_vue_interpolation_wrap = off -ij_vue_keep_indents_on_empty_lines = false -ij_vue_spaces_within_interpolation_expressions = true +ij_vue_interpolation_new_line_before_end_delimiter = true +ij_vue_interpolation_wrap = off +ij_vue_keep_indents_on_empty_lines = false +ij_vue_spaces_within_interpolation_expressions = true [.editorconfig] -ij_editorconfig_align_group_field_declarations = true -ij_editorconfig_space_after_colon = false -ij_editorconfig_space_after_comma = true -ij_editorconfig_space_before_colon = false -ij_editorconfig_space_before_comma = false +ij_editorconfig_align_group_field_declarations = true +ij_editorconfig_space_after_colon = false +ij_editorconfig_space_after_comma = true +ij_editorconfig_space_before_colon = false +ij_editorconfig_space_before_comma = false ij_editorconfig_spaces_around_assignment_operators = true [{*.ad,*.adoc,*.asciidoc,.asciidoctorconfig}] -ij_asciidoc_blank_lines_after_header = 1 +ij_asciidoc_blank_lines_after_header = 1 ij_asciidoc_blank_lines_keep_after_header = 1 -ij_asciidoc_formatting_enabled = true -ij_asciidoc_one_sentence_per_line = true +ij_asciidoc_formatting_enabled = true +ij_asciidoc_one_sentence_per_line = true [{*.ant,*.appxmanifest,*.axml,*.cscfg,*.csdef,*.disco,*.dotsettings,*.filelayout,*.fxml,*.jhm,*.jnlp,*.jrxml,*.manifest,*.myapp,*.nuspec,*.rng,*.sdef,*.stylecop,*.svcmap,*.tld,*.wadcfgx,*.webref,*.wsdl,*.xml,*.xsd,*.xsl,*.xslt,*.xul,StyleCop.Cache}] -ij_xml_align_attributes = true -ij_xml_align_text = false -ij_xml_attribute_wrap = on_every_item -ij_xml_block_comment_add_space = false -ij_xml_block_comment_at_first_column = true -ij_xml_keep_blank_lines = 2 -ij_xml_keep_indents_on_empty_lines = false -ij_xml_keep_line_breaks = true -ij_xml_keep_line_breaks_in_text = true -ij_xml_keep_whitespaces = false -ij_xml_keep_whitespaces_around_cdata = preserve -ij_xml_keep_whitespaces_inside_cdata = false -ij_xml_line_comment_at_first_column = true -ij_xml_space_after_tag_name = false +ij_xml_align_attributes = true +ij_xml_align_text = false +ij_xml_attribute_wrap = on_every_item +ij_xml_block_comment_add_space = false +ij_xml_block_comment_at_first_column = true +ij_xml_keep_blank_lines = 2 +ij_xml_keep_indents_on_empty_lines = false +ij_xml_keep_line_breaks = true +ij_xml_keep_line_breaks_in_text = true +ij_xml_keep_whitespaces = false +ij_xml_keep_whitespaces_around_cdata = preserve +ij_xml_keep_whitespaces_inside_cdata = false +ij_xml_line_comment_at_first_column = true +ij_xml_space_after_tag_name = false ij_xml_space_around_equals_in_attribute = false -ij_xml_space_inside_empty_tag = false -ij_xml_text_wrap = normal -ij_xml_use_custom_settings = false +ij_xml_space_inside_empty_tag = false +ij_xml_text_wrap = normal +ij_xml_use_custom_settings = false +indent_size = 2 +tab_width = 2 +ij_continuation_indent_size = 4 [{*.applescript,*.scpt}] -indent_size = 2 -tab_width = 2 -ij_continuation_indent_size = 4 -ij_applescript_align_multiline_binary_operation = true -ij_applescript_align_multiline_parameters = true -ij_applescript_align_multiline_parameters_in_calls = true -ij_applescript_binary_operation_sign_on_next_line = false -ij_applescript_binary_operation_wrap = off -ij_applescript_block_brace_style = next_line -ij_applescript_call_parameters_new_line_after_left_paren = false -ij_applescript_call_parameters_right_paren_on_new_line = false -ij_applescript_call_parameters_wrap = off -ij_applescript_else_on_new_line = true -ij_applescript_keep_blank_lines_in_code = 2 -ij_applescript_keep_first_column_comment = true -ij_applescript_keep_indents_on_empty_lines = false -ij_applescript_keep_line_breaks = true -ij_applescript_method_brace_style = next_line -ij_applescript_method_parameters_new_line_after_left_paren = false -ij_applescript_method_parameters_right_paren_on_new_line = false -ij_applescript_method_parameters_wrap = off +indent_size = 2 +tab_width = 2 +ij_continuation_indent_size = 4 +ij_applescript_align_multiline_binary_operation = true +ij_applescript_align_multiline_parameters = true +ij_applescript_align_multiline_parameters_in_calls = true +ij_applescript_binary_operation_sign_on_next_line = false +ij_applescript_binary_operation_wrap = off +ij_applescript_block_brace_style = next_line +ij_applescript_call_parameters_new_line_after_left_paren = false +ij_applescript_call_parameters_right_paren_on_new_line = false +ij_applescript_call_parameters_wrap = off +ij_applescript_else_on_new_line = true +ij_applescript_keep_blank_lines_in_code = 2 +ij_applescript_keep_first_column_comment = true +ij_applescript_keep_indents_on_empty_lines = false +ij_applescript_keep_line_breaks = true +ij_applescript_method_brace_style = next_line +ij_applescript_method_parameters_new_line_after_left_paren = false +ij_applescript_method_parameters_right_paren_on_new_line = false +ij_applescript_method_parameters_wrap = off ij_applescript_parentheses_expression_new_line_after_left_paren = false -ij_applescript_parentheses_expression_right_paren_on_new_line = false -ij_applescript_space_after_colon = true -ij_applescript_space_after_comma = true -ij_applescript_space_after_comma_in_type_arguments = true -ij_applescript_space_before_colon = true -ij_applescript_space_before_comma = false -ij_applescript_space_before_else_keyword = true -ij_applescript_space_before_else_left_brace = true -ij_applescript_space_before_if_parentheses = false -ij_applescript_space_before_method_call_parentheses = false -ij_applescript_space_before_method_left_brace = true -ij_applescript_space_before_method_parentheses = false -ij_applescript_space_before_while_keyword = true -ij_applescript_spaces_around_additive_operators = true -ij_applescript_spaces_around_assignment_operators = true -ij_applescript_spaces_around_equality_operators = true -ij_applescript_spaces_around_logical_operators = true -ij_applescript_spaces_around_multiplicative_operators = true -ij_applescript_spaces_around_relational_operators = true -ij_applescript_spaces_around_shift_operators = true -ij_applescript_spaces_around_unary_operator = false -ij_applescript_spaces_within_if_parentheses = false -ij_applescript_spaces_within_method_call_parentheses = false -ij_applescript_spaces_within_method_parentheses = false -ij_applescript_special_else_if_treatment = true +ij_applescript_parentheses_expression_right_paren_on_new_line = false +ij_applescript_space_after_colon = true +ij_applescript_space_after_comma = true +ij_applescript_space_after_comma_in_type_arguments = true +ij_applescript_space_before_colon = true +ij_applescript_space_before_comma = false +ij_applescript_space_before_else_keyword = true +ij_applescript_space_before_else_left_brace = true +ij_applescript_space_before_if_parentheses = false +ij_applescript_space_before_method_call_parentheses = false +ij_applescript_space_before_method_left_brace = true +ij_applescript_space_before_method_parentheses = false +ij_applescript_space_before_while_keyword = true +ij_applescript_spaces_around_additive_operators = true +ij_applescript_spaces_around_assignment_operators = true +ij_applescript_spaces_around_equality_operators = true +ij_applescript_spaces_around_logical_operators = true +ij_applescript_spaces_around_multiplicative_operators = true +ij_applescript_spaces_around_relational_operators = true +ij_applescript_spaces_around_shift_operators = true +ij_applescript_spaces_around_unary_operator = false +ij_applescript_spaces_within_if_parentheses = false +ij_applescript_spaces_within_method_call_parentheses = false +ij_applescript_spaces_within_method_parentheses = false +ij_applescript_special_else_if_treatment = true [{*.ats,*.cts,*.mts,*.ts}] -ij_continuation_indent_size = 4 -ij_typescript_align_imports = true -ij_typescript_align_multiline_array_initializer_expression = true -ij_typescript_align_multiline_binary_operation = true -ij_typescript_align_multiline_chained_methods = true -ij_typescript_align_multiline_extends_list = false -ij_typescript_align_multiline_for = true -ij_typescript_align_multiline_parameters = true -ij_typescript_align_multiline_parameters_in_calls = true -ij_typescript_align_multiline_ternary_operation = true -ij_typescript_align_object_properties = 1 -ij_typescript_align_union_types = true -ij_typescript_align_var_statements = 2 -ij_typescript_array_initializer_new_line_after_left_brace = false -ij_typescript_array_initializer_right_brace_on_new_line = false -ij_typescript_array_initializer_wrap = on_every_item -ij_typescript_assignment_wrap = on_every_item -ij_typescript_binary_operation_sign_on_next_line = false -ij_typescript_binary_operation_wrap = on_every_item -ij_typescript_blacklist_imports = rxjs/Rx,node_modules/**,**/node_modules/**,@angular/material,@angular/material/typings/** -ij_typescript_blank_lines_after_imports = 1 -ij_typescript_blank_lines_around_class = 1 -ij_typescript_blank_lines_around_field = 0 -ij_typescript_blank_lines_around_field_in_interface = 0 -ij_typescript_blank_lines_around_function = 1 -ij_typescript_blank_lines_around_method = 1 -ij_typescript_blank_lines_around_method_in_interface = 1 -ij_typescript_block_brace_style = next_line -ij_typescript_block_comment_add_space = false -ij_typescript_block_comment_at_first_column = true -ij_typescript_call_parameters_new_line_after_left_paren = false -ij_typescript_call_parameters_right_paren_on_new_line = false -ij_typescript_call_parameters_wrap = on_every_item -ij_typescript_catch_on_new_line = true -ij_typescript_chained_call_dot_on_new_line = true -ij_typescript_class_brace_style = next_line -ij_typescript_comma_on_new_line = false -ij_typescript_do_while_brace_force = always -ij_typescript_else_on_new_line = false -ij_typescript_enforce_trailing_comma = keep -ij_typescript_enum_constants_wrap = on_every_item -ij_typescript_extends_keyword_wrap = normal -ij_typescript_extends_list_wrap = on_every_item -ij_typescript_field_prefix = _ -ij_typescript_file_name_style = relaxed -ij_typescript_finally_on_new_line = true -ij_typescript_for_brace_force = if_multiline -ij_typescript_for_statement_new_line_after_left_paren = false -ij_typescript_for_statement_right_paren_on_new_line = false -ij_typescript_for_statement_wrap = on_every_item -ij_typescript_force_quote_style = true -ij_typescript_force_semicolon_style = true -ij_typescript_function_expression_brace_style = next_line -ij_typescript_if_brace_force = never -ij_typescript_import_merge_members = global -ij_typescript_import_prefer_absolute_path = true -ij_typescript_import_sort_members = true -ij_typescript_import_sort_module_name = true -ij_typescript_import_use_node_resolution = true -ij_typescript_imports_wrap = on_every_item -ij_typescript_indent_case_from_switch = true -ij_typescript_indent_chained_calls = true -ij_typescript_indent_package_children = 0 -ij_typescript_jsdoc_include_types = false -ij_typescript_jsx_attribute_value = braces -ij_typescript_keep_blank_lines_in_code = 2 -ij_typescript_keep_first_column_comment = true -ij_typescript_keep_indents_on_empty_lines = false -ij_typescript_keep_line_breaks = true -ij_typescript_keep_simple_blocks_in_one_line = false -ij_typescript_keep_simple_methods_in_one_line = false -ij_typescript_line_comment_add_space = true -ij_typescript_line_comment_at_first_column = false -ij_typescript_method_brace_style = next_line -ij_typescript_method_call_chain_wrap = on_every_item -ij_typescript_method_parameters_new_line_after_left_paren = false -ij_typescript_method_parameters_right_paren_on_new_line = false -ij_typescript_method_parameters_wrap = on_every_item -ij_typescript_object_literal_wrap = on_every_item -ij_typescript_object_types_wrap = on_every_item -ij_typescript_parentheses_expression_new_line_after_left_paren = false -ij_typescript_parentheses_expression_right_paren_on_new_line = false -ij_typescript_place_assignment_sign_on_next_line = false -ij_typescript_prefer_as_type_cast = false +ij_continuation_indent_size = 4 +ij_typescript_align_imports = true +ij_typescript_align_multiline_array_initializer_expression = true +ij_typescript_align_multiline_binary_operation = true +ij_typescript_align_multiline_chained_methods = true +ij_typescript_align_multiline_extends_list = false +ij_typescript_align_multiline_for = true +ij_typescript_align_multiline_parameters = true +ij_typescript_align_multiline_parameters_in_calls = true +ij_typescript_align_multiline_ternary_operation = true +ij_typescript_align_object_properties = 1 +ij_typescript_align_union_types = true +ij_typescript_align_var_statements = 2 +ij_typescript_array_initializer_new_line_after_left_brace = false +ij_typescript_array_initializer_right_brace_on_new_line = false +ij_typescript_array_initializer_wrap = on_every_item +ij_typescript_assignment_wrap = on_every_item +ij_typescript_binary_operation_sign_on_next_line = false +ij_typescript_binary_operation_wrap = on_every_item +ij_typescript_blacklist_imports = rxjs/Rx, node_modules/**, **/node_modules/**, @angular/material, @angular/material/typings/** +ij_typescript_blank_lines_after_imports = 1 +ij_typescript_blank_lines_around_class = 1 +ij_typescript_blank_lines_around_field = 0 +ij_typescript_blank_lines_around_field_in_interface = 0 +ij_typescript_blank_lines_around_function = 1 +ij_typescript_blank_lines_around_method = 1 +ij_typescript_blank_lines_around_method_in_interface = 1 +ij_typescript_block_brace_style = next_line +ij_typescript_block_comment_add_space = false +ij_typescript_block_comment_at_first_column = true +ij_typescript_call_parameters_new_line_after_left_paren = false +ij_typescript_call_parameters_right_paren_on_new_line = false +ij_typescript_call_parameters_wrap = on_every_item +ij_typescript_catch_on_new_line = true +ij_typescript_chained_call_dot_on_new_line = true +ij_typescript_class_brace_style = next_line +ij_typescript_comma_on_new_line = false +ij_typescript_do_while_brace_force = always +ij_typescript_else_on_new_line = false +ij_typescript_enforce_trailing_comma = keep +ij_typescript_enum_constants_wrap = on_every_item +ij_typescript_extends_keyword_wrap = normal +ij_typescript_extends_list_wrap = on_every_item +ij_typescript_field_prefix = _ +ij_typescript_file_name_style = relaxed +ij_typescript_finally_on_new_line = true +ij_typescript_for_brace_force = if_multiline +ij_typescript_for_statement_new_line_after_left_paren = false +ij_typescript_for_statement_right_paren_on_new_line = false +ij_typescript_for_statement_wrap = on_every_item +ij_typescript_force_quote_style = true +ij_typescript_force_semicolon_style = true +ij_typescript_function_expression_brace_style = next_line +ij_typescript_if_brace_force = never +ij_typescript_import_merge_members = global +ij_typescript_import_prefer_absolute_path = true +ij_typescript_import_sort_members = true +ij_typescript_import_sort_module_name = true +ij_typescript_import_use_node_resolution = true +ij_typescript_imports_wrap = on_every_item +ij_typescript_indent_case_from_switch = true +ij_typescript_indent_chained_calls = true +ij_typescript_indent_package_children = 0 +ij_typescript_jsdoc_include_types = false +ij_typescript_jsx_attribute_value = braces +ij_typescript_keep_blank_lines_in_code = 2 +ij_typescript_keep_first_column_comment = true +ij_typescript_keep_indents_on_empty_lines = false +ij_typescript_keep_line_breaks = true +ij_typescript_keep_simple_blocks_in_one_line = false +ij_typescript_keep_simple_methods_in_one_line = false +ij_typescript_line_comment_add_space = true +ij_typescript_line_comment_at_first_column = false +ij_typescript_method_brace_style = next_line +ij_typescript_method_call_chain_wrap = on_every_item +ij_typescript_method_parameters_new_line_after_left_paren = false +ij_typescript_method_parameters_right_paren_on_new_line = false +ij_typescript_method_parameters_wrap = on_every_item +ij_typescript_object_literal_wrap = on_every_item +ij_typescript_object_types_wrap = on_every_item +ij_typescript_parentheses_expression_new_line_after_left_paren = false +ij_typescript_parentheses_expression_right_paren_on_new_line = false +ij_typescript_place_assignment_sign_on_next_line = false +ij_typescript_prefer_as_type_cast = false ij_typescript_prefer_explicit_types_function_expression_returns = false -ij_typescript_prefer_explicit_types_function_returns = false -ij_typescript_prefer_explicit_types_vars_fields = false -ij_typescript_prefer_parameters_wrap = false -ij_typescript_property_prefix = -ij_typescript_reformat_c_style_comments = false -ij_typescript_space_after_colon = true -ij_typescript_space_after_comma = true -ij_typescript_space_after_dots_in_rest_parameter = false -ij_typescript_space_after_generator_mult = true -ij_typescript_space_after_property_colon = true -ij_typescript_space_after_quest = true -ij_typescript_space_after_type_colon = true -ij_typescript_space_after_unary_not = false -ij_typescript_space_before_async_arrow_lparen = false -ij_typescript_space_before_catch_keyword = true -ij_typescript_space_before_catch_left_brace = false -ij_typescript_space_before_catch_parentheses = false -ij_typescript_space_before_class_lbrace = false -ij_typescript_space_before_class_left_brace = true -ij_typescript_space_before_colon = true -ij_typescript_space_before_comma = false -ij_typescript_space_before_do_left_brace = false -ij_typescript_space_before_else_keyword = true -ij_typescript_space_before_else_left_brace = false -ij_typescript_space_before_finally_keyword = true -ij_typescript_space_before_finally_left_brace = false -ij_typescript_space_before_for_left_brace = false -ij_typescript_space_before_for_parentheses = false -ij_typescript_space_before_for_semicolon = false -ij_typescript_space_before_function_left_parenth = false -ij_typescript_space_before_generator_mult = false -ij_typescript_space_before_if_left_brace = false -ij_typescript_space_before_if_parentheses = false -ij_typescript_space_before_method_call_parentheses = false -ij_typescript_space_before_method_left_brace = false -ij_typescript_space_before_method_parentheses = false -ij_typescript_space_before_property_colon = false -ij_typescript_space_before_quest = true -ij_typescript_space_before_switch_left_brace = false -ij_typescript_space_before_switch_parentheses = false -ij_typescript_space_before_try_left_brace = false -ij_typescript_space_before_type_colon = false -ij_typescript_space_before_unary_not = false -ij_typescript_space_before_while_keyword = true -ij_typescript_space_before_while_left_brace = false -ij_typescript_space_before_while_parentheses = false -ij_typescript_spaces_around_additive_operators = true -ij_typescript_spaces_around_arrow_function_operator = true -ij_typescript_spaces_around_assignment_operators = true -ij_typescript_spaces_around_bitwise_operators = true -ij_typescript_spaces_around_equality_operators = true -ij_typescript_spaces_around_logical_operators = true -ij_typescript_spaces_around_multiplicative_operators = true -ij_typescript_spaces_around_relational_operators = true -ij_typescript_spaces_around_shift_operators = true -ij_typescript_spaces_around_unary_operator = false -ij_typescript_spaces_within_array_initializer_brackets = false -ij_typescript_spaces_within_brackets = false -ij_typescript_spaces_within_catch_parentheses = false -ij_typescript_spaces_within_for_parentheses = false -ij_typescript_spaces_within_if_parentheses = false -ij_typescript_spaces_within_imports = false -ij_typescript_spaces_within_interpolation_expressions = false -ij_typescript_spaces_within_method_call_parentheses = false -ij_typescript_spaces_within_method_parentheses = false -ij_typescript_spaces_within_object_literal_braces = false -ij_typescript_spaces_within_object_type_braces = true -ij_typescript_spaces_within_parentheses = false -ij_typescript_spaces_within_switch_parentheses = false -ij_typescript_spaces_within_type_assertion = false -ij_typescript_spaces_within_union_types = true -ij_typescript_spaces_within_while_parentheses = false -ij_typescript_special_else_if_treatment = true -ij_typescript_ternary_operation_signs_on_next_line = false -ij_typescript_ternary_operation_wrap = on_every_item -ij_typescript_union_types_wrap = on_every_item -ij_typescript_use_chained_calls_group_indents = false -ij_typescript_use_double_quotes = true -ij_typescript_use_explicit_js_extension = auto -ij_typescript_use_path_mapping = always -ij_typescript_use_public_modifier = false -ij_typescript_use_semicolon_after_statement = true -ij_typescript_var_declaration_wrap = normal -ij_typescript_while_brace_force = always -ij_typescript_while_on_new_line = false -ij_typescript_wrap_comments = false +ij_typescript_prefer_explicit_types_function_returns = false +ij_typescript_prefer_explicit_types_vars_fields = false +ij_typescript_prefer_parameters_wrap = false +ij_typescript_property_prefix = +ij_typescript_reformat_c_style_comments = false +ij_typescript_space_after_colon = true +ij_typescript_space_after_comma = true +ij_typescript_space_after_dots_in_rest_parameter = false +ij_typescript_space_after_generator_mult = true +ij_typescript_space_after_property_colon = true +ij_typescript_space_after_quest = true +ij_typescript_space_after_type_colon = true +ij_typescript_space_after_unary_not = false +ij_typescript_space_before_async_arrow_lparen = false +ij_typescript_space_before_catch_keyword = true +ij_typescript_space_before_catch_left_brace = false +ij_typescript_space_before_catch_parentheses = false +ij_typescript_space_before_class_lbrace = false +ij_typescript_space_before_class_left_brace = true +ij_typescript_space_before_colon = true +ij_typescript_space_before_comma = false +ij_typescript_space_before_do_left_brace = false +ij_typescript_space_before_else_keyword = true +ij_typescript_space_before_else_left_brace = false +ij_typescript_space_before_finally_keyword = true +ij_typescript_space_before_finally_left_brace = false +ij_typescript_space_before_for_left_brace = false +ij_typescript_space_before_for_parentheses = false +ij_typescript_space_before_for_semicolon = false +ij_typescript_space_before_function_left_parenth = false +ij_typescript_space_before_generator_mult = false +ij_typescript_space_before_if_left_brace = false +ij_typescript_space_before_if_parentheses = false +ij_typescript_space_before_method_call_parentheses = false +ij_typescript_space_before_method_left_brace = false +ij_typescript_space_before_method_parentheses = false +ij_typescript_space_before_property_colon = false +ij_typescript_space_before_quest = true +ij_typescript_space_before_switch_left_brace = false +ij_typescript_space_before_switch_parentheses = false +ij_typescript_space_before_try_left_brace = false +ij_typescript_space_before_type_colon = false +ij_typescript_space_before_unary_not = false +ij_typescript_space_before_while_keyword = true +ij_typescript_space_before_while_left_brace = false +ij_typescript_space_before_while_parentheses = false +ij_typescript_spaces_around_additive_operators = true +ij_typescript_spaces_around_arrow_function_operator = true +ij_typescript_spaces_around_assignment_operators = true +ij_typescript_spaces_around_bitwise_operators = true +ij_typescript_spaces_around_equality_operators = true +ij_typescript_spaces_around_logical_operators = true +ij_typescript_spaces_around_multiplicative_operators = true +ij_typescript_spaces_around_relational_operators = true +ij_typescript_spaces_around_shift_operators = true +ij_typescript_spaces_around_unary_operator = false +ij_typescript_spaces_within_array_initializer_brackets = false +ij_typescript_spaces_within_brackets = false +ij_typescript_spaces_within_catch_parentheses = false +ij_typescript_spaces_within_for_parentheses = false +ij_typescript_spaces_within_if_parentheses = false +ij_typescript_spaces_within_imports = false +ij_typescript_spaces_within_interpolation_expressions = false +ij_typescript_spaces_within_method_call_parentheses = false +ij_typescript_spaces_within_method_parentheses = false +ij_typescript_spaces_within_object_literal_braces = false +ij_typescript_spaces_within_object_type_braces = true +ij_typescript_spaces_within_parentheses = false +ij_typescript_spaces_within_switch_parentheses = false +ij_typescript_spaces_within_type_assertion = false +ij_typescript_spaces_within_union_types = true +ij_typescript_spaces_within_while_parentheses = false +ij_typescript_special_else_if_treatment = true +ij_typescript_ternary_operation_signs_on_next_line = false +ij_typescript_ternary_operation_wrap = on_every_item +ij_typescript_union_types_wrap = on_every_item +ij_typescript_use_chained_calls_group_indents = false +ij_typescript_use_double_quotes = true +ij_typescript_use_explicit_js_extension = auto +ij_typescript_use_path_mapping = always +ij_typescript_use_public_modifier = false +ij_typescript_use_semicolon_after_statement = true +ij_typescript_var_declaration_wrap = normal +ij_typescript_while_brace_force = always +ij_typescript_while_on_new_line = false +ij_typescript_wrap_comments = false [{*.bash,*.sh,*.zsh}] -indent_size = 2 -tab_width = 2 -ij_shell_binary_ops_start_line = false +indent_size = 2 +tab_width = 2 +ij_shell_binary_ops_start_line = false ij_shell_keep_column_alignment_padding = false -ij_shell_minify_program = false -ij_shell_redirect_followed_by_space = false -ij_shell_switch_cases_indented = true -ij_shell_use_unix_line_separator = true -indent_style = space +ij_shell_minify_program = false +ij_shell_redirect_followed_by_space = false +ij_shell_switch_cases_indented = true +ij_shell_use_unix_line_separator = true +indent_style = space [{*.cjs,*.js}] -ij_continuation_indent_size = 4 -ij_javascript_align_imports = true -ij_javascript_align_multiline_array_initializer_expression = true -ij_javascript_align_multiline_binary_operation = true -ij_javascript_align_multiline_chained_methods = false -ij_javascript_align_multiline_extends_list = true -ij_javascript_align_multiline_for = true -ij_javascript_align_multiline_parameters = true -ij_javascript_align_multiline_parameters_in_calls = true -ij_javascript_align_multiline_ternary_operation = true -ij_javascript_align_object_properties = 1 -ij_javascript_align_union_types = false -ij_javascript_align_var_statements = 2 -ij_javascript_array_initializer_new_line_after_left_brace = false -ij_javascript_array_initializer_right_brace_on_new_line = false -ij_javascript_array_initializer_wrap = on_every_item -ij_javascript_assignment_wrap = on_every_item -ij_javascript_binary_operation_sign_on_next_line = false -ij_javascript_binary_operation_wrap = on_every_item -ij_javascript_blacklist_imports = rxjs/Rx,node_modules/**,**/node_modules/**,@angular/material,@angular/material/typings/** -ij_javascript_blank_lines_after_imports = 1 -ij_javascript_blank_lines_around_class = 1 -ij_javascript_blank_lines_around_field = 0 -ij_javascript_blank_lines_around_function = 1 -ij_javascript_blank_lines_around_method = 1 -ij_javascript_block_brace_style = next_line -ij_javascript_block_comment_add_space = false -ij_javascript_block_comment_at_first_column = true -ij_javascript_call_parameters_new_line_after_left_paren = false -ij_javascript_call_parameters_right_paren_on_new_line = false -ij_javascript_call_parameters_wrap = on_every_item -ij_javascript_catch_on_new_line = true -ij_javascript_chained_call_dot_on_new_line = true -ij_javascript_class_brace_style = next_line -ij_javascript_comma_on_new_line = false -ij_javascript_do_while_brace_force = always -ij_javascript_else_on_new_line = true -ij_javascript_enforce_trailing_comma = remove -ij_javascript_extends_keyword_wrap = normal -ij_javascript_extends_list_wrap = on_every_item -ij_javascript_field_prefix = _ -ij_javascript_file_name_style = relaxed -ij_javascript_finally_on_new_line = true -ij_javascript_for_brace_force = if_multiline -ij_javascript_for_statement_new_line_after_left_paren = false -ij_javascript_for_statement_right_paren_on_new_line = false -ij_javascript_for_statement_wrap = on_every_item -ij_javascript_force_quote_style = true -ij_javascript_force_semicolon_style = true -ij_javascript_function_expression_brace_style = next_line -ij_javascript_if_brace_force = if_multiline -ij_javascript_import_merge_members = global -ij_javascript_import_prefer_absolute_path = true -ij_javascript_import_sort_members = true -ij_javascript_import_sort_module_name = true -ij_javascript_import_use_node_resolution = true -ij_javascript_imports_wrap = on_every_item -ij_javascript_indent_case_from_switch = true -ij_javascript_indent_chained_calls = true -ij_javascript_indent_package_children = 0 -ij_javascript_jsx_attribute_value = braces -ij_javascript_keep_blank_lines_in_code = 2 -ij_javascript_keep_first_column_comment = true -ij_javascript_keep_indents_on_empty_lines = false -ij_javascript_keep_line_breaks = true -ij_javascript_keep_simple_blocks_in_one_line = false -ij_javascript_keep_simple_methods_in_one_line = false -ij_javascript_line_comment_add_space = true -ij_javascript_line_comment_at_first_column = false -ij_javascript_method_brace_style = next_line -ij_javascript_method_call_chain_wrap = on_every_item -ij_javascript_method_parameters_new_line_after_left_paren = false -ij_javascript_method_parameters_right_paren_on_new_line = false -ij_javascript_method_parameters_wrap = on_every_item -ij_javascript_object_literal_wrap = on_every_item -ij_javascript_object_types_wrap = on_every_item -ij_javascript_parentheses_expression_new_line_after_left_paren = false -ij_javascript_parentheses_expression_right_paren_on_new_line = false -ij_javascript_place_assignment_sign_on_next_line = true -ij_javascript_prefer_as_type_cast = false +ij_continuation_indent_size = 4 +ij_javascript_align_imports = true +ij_javascript_align_multiline_array_initializer_expression = true +ij_javascript_align_multiline_binary_operation = true +ij_javascript_align_multiline_chained_methods = false +ij_javascript_align_multiline_extends_list = true +ij_javascript_align_multiline_for = true +ij_javascript_align_multiline_parameters = true +ij_javascript_align_multiline_parameters_in_calls = true +ij_javascript_align_multiline_ternary_operation = true +ij_javascript_align_object_properties = 1 +ij_javascript_align_union_types = false +ij_javascript_align_var_statements = 2 +ij_javascript_array_initializer_new_line_after_left_brace = false +ij_javascript_array_initializer_right_brace_on_new_line = false +ij_javascript_array_initializer_wrap = on_every_item +ij_javascript_assignment_wrap = on_every_item +ij_javascript_binary_operation_sign_on_next_line = false +ij_javascript_binary_operation_wrap = on_every_item +ij_javascript_blacklist_imports = rxjs/Rx, node_modules/**, **/node_modules/**, @angular/material, @angular/material/typings/** +ij_javascript_blank_lines_after_imports = 1 +ij_javascript_blank_lines_around_class = 1 +ij_javascript_blank_lines_around_field = 0 +ij_javascript_blank_lines_around_function = 1 +ij_javascript_blank_lines_around_method = 1 +ij_javascript_block_brace_style = next_line +ij_javascript_block_comment_add_space = false +ij_javascript_block_comment_at_first_column = true +ij_javascript_call_parameters_new_line_after_left_paren = false +ij_javascript_call_parameters_right_paren_on_new_line = false +ij_javascript_call_parameters_wrap = on_every_item +ij_javascript_catch_on_new_line = true +ij_javascript_chained_call_dot_on_new_line = true +ij_javascript_class_brace_style = next_line +ij_javascript_comma_on_new_line = false +ij_javascript_do_while_brace_force = always +ij_javascript_else_on_new_line = true +ij_javascript_enforce_trailing_comma = remove +ij_javascript_extends_keyword_wrap = normal +ij_javascript_extends_list_wrap = on_every_item +ij_javascript_field_prefix = _ +ij_javascript_file_name_style = relaxed +ij_javascript_finally_on_new_line = true +ij_javascript_for_brace_force = if_multiline +ij_javascript_for_statement_new_line_after_left_paren = false +ij_javascript_for_statement_right_paren_on_new_line = false +ij_javascript_for_statement_wrap = on_every_item +ij_javascript_force_quote_style = true +ij_javascript_force_semicolon_style = true +ij_javascript_function_expression_brace_style = next_line +ij_javascript_if_brace_force = if_multiline +ij_javascript_import_merge_members = global +ij_javascript_import_prefer_absolute_path = true +ij_javascript_import_sort_members = true +ij_javascript_import_sort_module_name = true +ij_javascript_import_use_node_resolution = true +ij_javascript_imports_wrap = on_every_item +ij_javascript_indent_case_from_switch = true +ij_javascript_indent_chained_calls = true +ij_javascript_indent_package_children = 0 +ij_javascript_jsx_attribute_value = braces +ij_javascript_keep_blank_lines_in_code = 2 +ij_javascript_keep_first_column_comment = true +ij_javascript_keep_indents_on_empty_lines = false +ij_javascript_keep_line_breaks = true +ij_javascript_keep_simple_blocks_in_one_line = false +ij_javascript_keep_simple_methods_in_one_line = false +ij_javascript_line_comment_add_space = true +ij_javascript_line_comment_at_first_column = false +ij_javascript_method_brace_style = next_line +ij_javascript_method_call_chain_wrap = on_every_item +ij_javascript_method_parameters_new_line_after_left_paren = false +ij_javascript_method_parameters_right_paren_on_new_line = false +ij_javascript_method_parameters_wrap = on_every_item +ij_javascript_object_literal_wrap = on_every_item +ij_javascript_object_types_wrap = on_every_item +ij_javascript_parentheses_expression_new_line_after_left_paren = false +ij_javascript_parentheses_expression_right_paren_on_new_line = false +ij_javascript_place_assignment_sign_on_next_line = true +ij_javascript_prefer_as_type_cast = false ij_javascript_prefer_explicit_types_function_expression_returns = false -ij_javascript_prefer_explicit_types_function_returns = false -ij_javascript_prefer_explicit_types_vars_fields = false -ij_javascript_prefer_parameters_wrap = false -ij_javascript_property_prefix = -ij_javascript_reformat_c_style_comments = true -ij_javascript_space_after_colon = true -ij_javascript_space_after_comma = true -ij_javascript_space_after_dots_in_rest_parameter = false -ij_javascript_space_after_generator_mult = true -ij_javascript_space_after_property_colon = true -ij_javascript_space_after_quest = true -ij_javascript_space_after_type_colon = true -ij_javascript_space_after_unary_not = false -ij_javascript_space_before_async_arrow_lparen = false -ij_javascript_space_before_catch_keyword = true -ij_javascript_space_before_catch_left_brace = false -ij_javascript_space_before_catch_parentheses = false -ij_javascript_space_before_class_lbrace = false -ij_javascript_space_before_class_left_brace = true -ij_javascript_space_before_colon = true -ij_javascript_space_before_comma = false -ij_javascript_space_before_do_left_brace = false -ij_javascript_space_before_else_keyword = true -ij_javascript_space_before_else_left_brace = false -ij_javascript_space_before_finally_keyword = true -ij_javascript_space_before_finally_left_brace = false -ij_javascript_space_before_for_left_brace = false -ij_javascript_space_before_for_parentheses = false -ij_javascript_space_before_for_semicolon = false -ij_javascript_space_before_function_left_parenth = false -ij_javascript_space_before_generator_mult = false -ij_javascript_space_before_if_left_brace = false -ij_javascript_space_before_if_parentheses = false -ij_javascript_space_before_method_call_parentheses = false -ij_javascript_space_before_method_left_brace = false -ij_javascript_space_before_method_parentheses = false -ij_javascript_space_before_property_colon = false -ij_javascript_space_before_quest = true -ij_javascript_space_before_switch_left_brace = false -ij_javascript_space_before_switch_parentheses = false -ij_javascript_space_before_try_left_brace = false -ij_javascript_space_before_type_colon = false -ij_javascript_space_before_unary_not = false -ij_javascript_space_before_while_keyword = true -ij_javascript_space_before_while_left_brace = false -ij_javascript_space_before_while_parentheses = false -ij_javascript_spaces_around_additive_operators = true -ij_javascript_spaces_around_arrow_function_operator = true -ij_javascript_spaces_around_assignment_operators = true -ij_javascript_spaces_around_bitwise_operators = true -ij_javascript_spaces_around_equality_operators = true -ij_javascript_spaces_around_logical_operators = true -ij_javascript_spaces_around_multiplicative_operators = true -ij_javascript_spaces_around_relational_operators = true -ij_javascript_spaces_around_shift_operators = true -ij_javascript_spaces_around_unary_operator = false -ij_javascript_spaces_within_array_initializer_brackets = false -ij_javascript_spaces_within_brackets = false -ij_javascript_spaces_within_catch_parentheses = false -ij_javascript_spaces_within_for_parentheses = false -ij_javascript_spaces_within_if_parentheses = false -ij_javascript_spaces_within_imports = false -ij_javascript_spaces_within_interpolation_expressions = false -ij_javascript_spaces_within_method_call_parentheses = false -ij_javascript_spaces_within_method_parentheses = false -ij_javascript_spaces_within_object_literal_braces = false -ij_javascript_spaces_within_object_type_braces = true -ij_javascript_spaces_within_parentheses = false -ij_javascript_spaces_within_switch_parentheses = false -ij_javascript_spaces_within_type_assertion = false -ij_javascript_spaces_within_union_types = true -ij_javascript_spaces_within_while_parentheses = false -ij_javascript_special_else_if_treatment = true -ij_javascript_ternary_operation_signs_on_next_line = false -ij_javascript_ternary_operation_wrap = on_every_item -ij_javascript_union_types_wrap = on_every_item -ij_javascript_use_chained_calls_group_indents = true -ij_javascript_use_double_quotes = true -ij_javascript_use_explicit_js_extension = auto -ij_javascript_use_path_mapping = always -ij_javascript_use_public_modifier = false -ij_javascript_use_semicolon_after_statement = true -ij_javascript_var_declaration_wrap = normal -ij_javascript_while_brace_force = always -ij_javascript_while_on_new_line = false -ij_javascript_wrap_comments = false +ij_javascript_prefer_explicit_types_function_returns = false +ij_javascript_prefer_explicit_types_vars_fields = false +ij_javascript_prefer_parameters_wrap = false +ij_javascript_property_prefix = +ij_javascript_reformat_c_style_comments = true +ij_javascript_space_after_colon = true +ij_javascript_space_after_comma = true +ij_javascript_space_after_dots_in_rest_parameter = false +ij_javascript_space_after_generator_mult = true +ij_javascript_space_after_property_colon = true +ij_javascript_space_after_quest = true +ij_javascript_space_after_type_colon = true +ij_javascript_space_after_unary_not = false +ij_javascript_space_before_async_arrow_lparen = false +ij_javascript_space_before_catch_keyword = true +ij_javascript_space_before_catch_left_brace = false +ij_javascript_space_before_catch_parentheses = false +ij_javascript_space_before_class_lbrace = false +ij_javascript_space_before_class_left_brace = true +ij_javascript_space_before_colon = true +ij_javascript_space_before_comma = false +ij_javascript_space_before_do_left_brace = false +ij_javascript_space_before_else_keyword = true +ij_javascript_space_before_else_left_brace = false +ij_javascript_space_before_finally_keyword = true +ij_javascript_space_before_finally_left_brace = false +ij_javascript_space_before_for_left_brace = false +ij_javascript_space_before_for_parentheses = false +ij_javascript_space_before_for_semicolon = false +ij_javascript_space_before_function_left_parenth = false +ij_javascript_space_before_generator_mult = false +ij_javascript_space_before_if_left_brace = false +ij_javascript_space_before_if_parentheses = false +ij_javascript_space_before_method_call_parentheses = false +ij_javascript_space_before_method_left_brace = false +ij_javascript_space_before_method_parentheses = false +ij_javascript_space_before_property_colon = false +ij_javascript_space_before_quest = true +ij_javascript_space_before_switch_left_brace = false +ij_javascript_space_before_switch_parentheses = false +ij_javascript_space_before_try_left_brace = false +ij_javascript_space_before_type_colon = false +ij_javascript_space_before_unary_not = false +ij_javascript_space_before_while_keyword = true +ij_javascript_space_before_while_left_brace = false +ij_javascript_space_before_while_parentheses = false +ij_javascript_spaces_around_additive_operators = true +ij_javascript_spaces_around_arrow_function_operator = true +ij_javascript_spaces_around_assignment_operators = true +ij_javascript_spaces_around_bitwise_operators = true +ij_javascript_spaces_around_equality_operators = true +ij_javascript_spaces_around_logical_operators = true +ij_javascript_spaces_around_multiplicative_operators = true +ij_javascript_spaces_around_relational_operators = true +ij_javascript_spaces_around_shift_operators = true +ij_javascript_spaces_around_unary_operator = false +ij_javascript_spaces_within_array_initializer_brackets = false +ij_javascript_spaces_within_brackets = false +ij_javascript_spaces_within_catch_parentheses = false +ij_javascript_spaces_within_for_parentheses = false +ij_javascript_spaces_within_if_parentheses = false +ij_javascript_spaces_within_imports = false +ij_javascript_spaces_within_interpolation_expressions = false +ij_javascript_spaces_within_method_call_parentheses = false +ij_javascript_spaces_within_method_parentheses = false +ij_javascript_spaces_within_object_literal_braces = false +ij_javascript_spaces_within_object_type_braces = true +ij_javascript_spaces_within_parentheses = false +ij_javascript_spaces_within_switch_parentheses = false +ij_javascript_spaces_within_type_assertion = false +ij_javascript_spaces_within_union_types = true +ij_javascript_spaces_within_while_parentheses = false +ij_javascript_special_else_if_treatment = true +ij_javascript_ternary_operation_signs_on_next_line = false +ij_javascript_ternary_operation_wrap = on_every_item +ij_javascript_union_types_wrap = on_every_item +ij_javascript_use_chained_calls_group_indents = true +ij_javascript_use_double_quotes = true +ij_javascript_use_explicit_js_extension = auto +ij_javascript_use_path_mapping = always +ij_javascript_use_public_modifier = false +ij_javascript_use_semicolon_after_statement = true +ij_javascript_var_declaration_wrap = normal +ij_javascript_while_brace_force = always +ij_javascript_while_on_new_line = false +ij_javascript_wrap_comments = false [{*.comp,*.frag,*.fsh,*.geom,*.glsl,*.tesc,*.tese,*.vert,*.vsh}] ij_glsl_keep_indents_on_empty_lines = false [{*.har,*.jsb2,*.jsb3,*.json,*.jsonc,.babelrc,.eslintrc,.prettierrc,.stylelintrc,bowerrc,jest.config}] -indent_size = 2 -ij_json_array_wrapping = normal -ij_json_keep_blank_lines_in_code = 0 +indent_size = 2 +ij_json_array_wrapping = normal +ij_json_keep_blank_lines_in_code = 0 ij_json_keep_indents_on_empty_lines = false -ij_json_keep_line_breaks = true -ij_json_keep_trailing_comma = false -ij_json_object_wrapping = normal -ij_json_property_alignment = align_on_value -ij_json_space_after_colon = true -ij_json_space_after_comma = true -ij_json_space_before_colon = false -ij_json_space_before_comma = false -ij_json_spaces_within_braces = false -ij_json_spaces_within_brackets = false -ij_json_wrap_long_lines = false -indent_style = space +ij_json_keep_line_breaks = true +ij_json_keep_trailing_comma = false +ij_json_object_wrapping = normal +ij_json_property_alignment = align_on_value +ij_json_space_after_colon = true +ij_json_space_after_comma = true +ij_json_space_before_colon = false +ij_json_space_before_comma = false +ij_json_spaces_within_braces = false +ij_json_spaces_within_brackets = false +ij_json_wrap_long_lines = false +indent_style = space [{*.htm,*.html,*.ng,*.sht,*.shtm,*.shtml}] -ij_html_add_new_line_before_tags = body,div,p,form,h1,h2,h3 -ij_html_align_attributes = true -ij_html_align_text = false -ij_html_attribute_wrap = normal -ij_html_block_comment_add_space = false -ij_html_block_comment_at_first_column = true +ij_html_add_new_line_before_tags = body, div, p, form, h1, h2, h3 +ij_html_align_attributes = true +ij_html_align_text = false +ij_html_attribute_wrap = normal +ij_html_block_comment_add_space = false +ij_html_block_comment_at_first_column = true ij_html_do_not_align_children_of_min_lines = 0 -ij_html_do_not_break_if_inline_tags = title,h1,h2,h3,h4,h5,h6,p -ij_html_do_not_indent_children_of_tags = html,body,thead,tbody,tfoot -ij_html_enforce_quotes = false -ij_html_inline_tags = a,abbr,acronym,b,basefont,bdo,big,br,cite,cite,code,dfn,em,font,i,img,input,kbd,label,q,s,samp,select,small,span,strike,strong,sub,sup,textarea,tt,u,var -ij_html_keep_blank_lines = 2 -ij_html_keep_indents_on_empty_lines = false -ij_html_keep_line_breaks = true -ij_html_keep_line_breaks_in_text = true -ij_html_keep_whitespaces = false -ij_html_keep_whitespaces_inside = span,pre,textarea -ij_html_line_comment_at_first_column = true -ij_html_new_line_after_last_attribute = never -ij_html_new_line_before_first_attribute = never -ij_html_quote_style = double -ij_html_remove_new_line_before_tags = br -ij_html_space_after_tag_name = false +ij_html_do_not_break_if_inline_tags = title, h1, h2, h3, h4, h5, h6, p +ij_html_do_not_indent_children_of_tags = html, body, thead, tbody, tfoot +ij_html_enforce_quotes = false +ij_html_inline_tags = a, abbr, acronym, b, basefont, bdo, big, br, cite, cite, code, dfn, em, font, i, img, input, kbd, label, q, s, samp, select, small, span, strike, strong, sub, sup, textarea, tt, u, var +ij_html_keep_blank_lines = 2 +ij_html_keep_indents_on_empty_lines = false +ij_html_keep_line_breaks = true +ij_html_keep_line_breaks_in_text = true +ij_html_keep_whitespaces = false +ij_html_keep_whitespaces_inside = span, pre, textarea +ij_html_line_comment_at_first_column = true +ij_html_new_line_after_last_attribute = never +ij_html_new_line_before_first_attribute = never +ij_html_quote_style = double +ij_html_remove_new_line_before_tags = br +ij_html_space_after_tag_name = false ij_html_space_around_equality_in_attribute = false -ij_html_space_inside_empty_tag = false -ij_html_text_wrap = normal +ij_html_space_inside_empty_tag = false +ij_html_text_wrap = normal [{*.http,*.rest}] -indent_size = 0 -ij_continuation_indent_size = 4 -ij_http-request_call_parameters_wrap = normal -ij_http-request_method_parameters_wrap = split_into_lines -ij_http-request_space_before_comma = true +indent_size = 0 +ij_continuation_indent_size = 4 +ij_http-request_call_parameters_wrap = normal +ij_http-request_method_parameters_wrap = split_into_lines +ij_http-request_space_before_comma = true ij_http-request_spaces_around_assignment_operators = true [{*.markdown,*.md}] ij_markdown_force_one_space_after_blockquote_symbol = true -ij_markdown_force_one_space_after_header_symbol = true -ij_markdown_force_one_space_after_list_bullet = true -ij_markdown_force_one_space_between_words = true -ij_markdown_format_tables = true -ij_markdown_insert_quote_arrows_on_wrap = true -ij_markdown_keep_indents_on_empty_lines = false -ij_markdown_keep_line_breaks_inside_text_blocks = true -ij_markdown_max_lines_around_block_elements = 1 -ij_markdown_max_lines_around_header = 1 -ij_markdown_max_lines_between_paragraphs = 1 -ij_markdown_min_lines_around_block_elements = 1 -ij_markdown_min_lines_around_header = 1 -ij_markdown_min_lines_between_paragraphs = 1 -ij_markdown_wrap_text_if_long = true -ij_markdown_wrap_text_inside_blockquotes = true +ij_markdown_force_one_space_after_header_symbol = true +ij_markdown_force_one_space_after_list_bullet = true +ij_markdown_force_one_space_between_words = true +ij_markdown_format_tables = true +ij_markdown_insert_quote_arrows_on_wrap = true +ij_markdown_keep_indents_on_empty_lines = false +ij_markdown_keep_line_breaks_inside_text_blocks = true +ij_markdown_max_lines_around_block_elements = 1 +ij_markdown_max_lines_around_header = 1 +ij_markdown_max_lines_between_paragraphs = 1 +ij_markdown_min_lines_around_block_elements = 1 +ij_markdown_min_lines_around_header = 1 +ij_markdown_min_lines_between_paragraphs = 1 +ij_markdown_wrap_text_if_long = true +ij_markdown_wrap_text_inside_blockquotes = true [{*.ps1,*.psd1,*.psm1}] -max_line_length = 115 -ij_powershell_align_multiline_binary_operation = true -ij_powershell_align_multiline_chained_methods = false -ij_powershell_align_multiline_for = true -ij_powershell_align_multiline_parameters = true -ij_powershell_align_multiline_parameters_in_calls = false -ij_powershell_binary_operation_wrap = on_every_item -ij_powershell_block_brace_style = next_line -ij_powershell_call_parameters_new_line_after_left_paren = false -ij_powershell_call_parameters_right_paren_on_new_line = false -ij_powershell_call_parameters_wrap = on_every_item -ij_powershell_catch_on_new_line = true -ij_powershell_class_annotation_wrap = split_into_lines -ij_powershell_class_brace_style = next_line -ij_powershell_else_on_new_line = true -ij_powershell_field_annotation_wrap = off -ij_powershell_finally_on_new_line = true -ij_powershell_for_statement_new_line_after_left_paren = false -ij_powershell_for_statement_right_paren_on_new_line = false -ij_powershell_for_statement_wrap = on_every_item -ij_powershell_keep_blank_lines_in_code = 2 -ij_powershell_keep_first_column_comment = true -ij_powershell_keep_line_breaks = true -ij_powershell_keep_simple_blocks_in_one_line = true -ij_powershell_keep_simple_classes_in_one_line = false -ij_powershell_keep_simple_lambdas_in_one_line = true -ij_powershell_keep_simple_methods_in_one_line = true -ij_powershell_method_annotation_wrap = split_into_lines -ij_powershell_method_brace_style = next_line -ij_powershell_method_call_chain_wrap = on_every_item -ij_powershell_method_parameters_new_line_after_left_paren = false -ij_powershell_method_parameters_right_paren_on_new_line = false -ij_powershell_method_parameters_wrap = on_every_item -ij_powershell_parameter_annotation_wrap = off +max_line_length = 115 +ij_powershell_align_multiline_binary_operation = true +ij_powershell_align_multiline_chained_methods = false +ij_powershell_align_multiline_for = true +ij_powershell_align_multiline_parameters = true +ij_powershell_align_multiline_parameters_in_calls = false +ij_powershell_binary_operation_wrap = on_every_item +ij_powershell_block_brace_style = next_line +ij_powershell_call_parameters_new_line_after_left_paren = false +ij_powershell_call_parameters_right_paren_on_new_line = false +ij_powershell_call_parameters_wrap = on_every_item +ij_powershell_catch_on_new_line = true +ij_powershell_class_annotation_wrap = split_into_lines +ij_powershell_class_brace_style = next_line +ij_powershell_else_on_new_line = true +ij_powershell_field_annotation_wrap = off +ij_powershell_finally_on_new_line = true +ij_powershell_for_statement_new_line_after_left_paren = false +ij_powershell_for_statement_right_paren_on_new_line = false +ij_powershell_for_statement_wrap = on_every_item +ij_powershell_keep_blank_lines_in_code = 2 +ij_powershell_keep_first_column_comment = true +ij_powershell_keep_line_breaks = true +ij_powershell_keep_simple_blocks_in_one_line = true +ij_powershell_keep_simple_classes_in_one_line = false +ij_powershell_keep_simple_lambdas_in_one_line = true +ij_powershell_keep_simple_methods_in_one_line = true +ij_powershell_method_annotation_wrap = split_into_lines +ij_powershell_method_brace_style = next_line +ij_powershell_method_call_chain_wrap = on_every_item +ij_powershell_method_parameters_new_line_after_left_paren = false +ij_powershell_method_parameters_right_paren_on_new_line = false +ij_powershell_method_parameters_wrap = on_every_item +ij_powershell_parameter_annotation_wrap = off ij_powershell_parentheses_expression_new_line_after_left_paren = false -ij_powershell_parentheses_expression_right_paren_on_new_line = false -ij_powershell_space_after_colon = true -ij_powershell_space_after_comma = true -ij_powershell_space_after_for_semicolon = true -ij_powershell_space_after_type_cast = false -ij_powershell_space_before_annotation_parameter_list = false -ij_powershell_space_before_array_initializer_left_brace = false -ij_powershell_space_before_catch_keyword = true -ij_powershell_space_before_catch_left_brace = false -ij_powershell_space_before_class_left_brace = false -ij_powershell_space_before_colon = true -ij_powershell_space_before_comma = false -ij_powershell_space_before_do_left_brace = false -ij_powershell_space_before_else_keyword = true -ij_powershell_space_before_else_left_brace = false -ij_powershell_space_before_finally_keyword = true -ij_powershell_space_before_finally_left_brace = false -ij_powershell_space_before_for_left_brace = false -ij_powershell_space_before_for_parentheses = false -ij_powershell_space_before_for_semicolon = false -ij_powershell_space_before_if_left_brace = false -ij_powershell_space_before_if_parentheses = false -ij_powershell_space_before_method_call_parentheses = false -ij_powershell_space_before_method_left_brace = false -ij_powershell_space_before_method_parentheses = false -ij_powershell_space_before_switch_left_brace = false -ij_powershell_space_before_switch_parentheses = false -ij_powershell_space_before_try_left_brace = false -ij_powershell_space_before_while_keyword = true -ij_powershell_space_before_while_left_brace = false -ij_powershell_space_before_while_parentheses = false -ij_powershell_space_within_empty_method_call_parentheses = false -ij_powershell_space_within_empty_method_parentheses = false -ij_powershell_spaces_around_additive_operators = true -ij_powershell_spaces_around_assignment_operators = true -ij_powershell_spaces_around_bitwise_operators = true -ij_powershell_spaces_around_logical_operators = true -ij_powershell_spaces_around_method_ref_dbl_colon = false -ij_powershell_spaces_around_multiplicative_operators = true -ij_powershell_spaces_around_relational_operators = true -ij_powershell_spaces_around_unary_operator = false -ij_powershell_spaces_within_annotation_parentheses = false -ij_powershell_spaces_within_braces = true -ij_powershell_spaces_within_brackets = false -ij_powershell_spaces_within_cast_parentheses = false -ij_powershell_spaces_within_for_parentheses = false -ij_powershell_spaces_within_if_parentheses = false -ij_powershell_spaces_within_method_call_parentheses = false -ij_powershell_spaces_within_method_parentheses = false -ij_powershell_spaces_within_parentheses = false -ij_powershell_spaces_within_switch_parentheses = false -ij_powershell_spaces_within_while_parentheses = false -ij_powershell_special_else_if_treatment = true -ij_powershell_while_on_new_line = false -ij_powershell_wrap_first_method_in_call_chain = false -ij_powershell_wrap_long_lines = false +ij_powershell_parentheses_expression_right_paren_on_new_line = false +ij_powershell_space_after_colon = true +ij_powershell_space_after_comma = true +ij_powershell_space_after_for_semicolon = true +ij_powershell_space_after_type_cast = false +ij_powershell_space_before_annotation_parameter_list = false +ij_powershell_space_before_array_initializer_left_brace = false +ij_powershell_space_before_catch_keyword = true +ij_powershell_space_before_catch_left_brace = false +ij_powershell_space_before_class_left_brace = false +ij_powershell_space_before_colon = true +ij_powershell_space_before_comma = false +ij_powershell_space_before_do_left_brace = false +ij_powershell_space_before_else_keyword = true +ij_powershell_space_before_else_left_brace = false +ij_powershell_space_before_finally_keyword = true +ij_powershell_space_before_finally_left_brace = false +ij_powershell_space_before_for_left_brace = false +ij_powershell_space_before_for_parentheses = false +ij_powershell_space_before_for_semicolon = false +ij_powershell_space_before_if_left_brace = false +ij_powershell_space_before_if_parentheses = false +ij_powershell_space_before_method_call_parentheses = false +ij_powershell_space_before_method_left_brace = false +ij_powershell_space_before_method_parentheses = false +ij_powershell_space_before_switch_left_brace = false +ij_powershell_space_before_switch_parentheses = false +ij_powershell_space_before_try_left_brace = false +ij_powershell_space_before_while_keyword = true +ij_powershell_space_before_while_left_brace = false +ij_powershell_space_before_while_parentheses = false +ij_powershell_space_within_empty_method_call_parentheses = false +ij_powershell_space_within_empty_method_parentheses = false +ij_powershell_spaces_around_additive_operators = true +ij_powershell_spaces_around_assignment_operators = true +ij_powershell_spaces_around_bitwise_operators = true +ij_powershell_spaces_around_logical_operators = true +ij_powershell_spaces_around_method_ref_dbl_colon = false +ij_powershell_spaces_around_multiplicative_operators = true +ij_powershell_spaces_around_relational_operators = true +ij_powershell_spaces_around_unary_operator = false +ij_powershell_spaces_within_annotation_parentheses = false +ij_powershell_spaces_within_braces = true +ij_powershell_spaces_within_brackets = false +ij_powershell_spaces_within_cast_parentheses = false +ij_powershell_spaces_within_for_parentheses = false +ij_powershell_spaces_within_if_parentheses = false +ij_powershell_spaces_within_method_call_parentheses = false +ij_powershell_spaces_within_method_parentheses = false +ij_powershell_spaces_within_parentheses = false +ij_powershell_spaces_within_switch_parentheses = false +ij_powershell_spaces_within_while_parentheses = false +ij_powershell_special_else_if_treatment = true +ij_powershell_while_on_new_line = false +ij_powershell_wrap_first_method_in_call_chain = false +ij_powershell_wrap_long_lines = false [{*.py,*.pyw}] -ij_python_align_collections_and_comprehensions = true -ij_python_align_multiline_imports = true -ij_python_align_multiline_parameters = true -ij_python_align_multiline_parameters_in_calls = true -ij_python_blank_line_at_file_end = false -ij_python_blank_lines_after_imports = 1 -ij_python_blank_lines_after_local_imports = 0 -ij_python_blank_lines_around_class = 1 -ij_python_blank_lines_around_method = 1 -ij_python_blank_lines_around_top_level_classes_functions = 2 -ij_python_blank_lines_before_first_method = 0 -ij_python_call_parameters_new_line_after_left_paren = false -ij_python_call_parameters_right_paren_on_new_line = false -ij_python_call_parameters_wrap = on_every_item -ij_python_dict_alignment = 0 -ij_python_dict_new_line_after_left_brace = false -ij_python_dict_new_line_before_right_brace = false -ij_python_dict_wrapping = 5 -ij_python_from_import_new_line_after_left_parenthesis = false -ij_python_from_import_new_line_before_right_parenthesis = false -ij_python_from_import_parentheses_force_if_multiline = false -ij_python_from_import_trailing_comma_if_multiline = false -ij_python_from_import_wrapping = 5 -ij_python_hang_closing_brackets = true -ij_python_keep_blank_lines_in_code = 1 -ij_python_keep_blank_lines_in_declarations = 1 -ij_python_keep_indents_on_empty_lines = false -ij_python_keep_line_breaks = true -ij_python_method_parameters_new_line_after_left_paren = false -ij_python_method_parameters_right_paren_on_new_line = false -ij_python_method_parameters_wrap = on_every_item -ij_python_new_line_after_colon = false -ij_python_new_line_after_colon_multi_clause = true -ij_python_optimize_imports_always_split_from_imports = false -ij_python_optimize_imports_case_insensitive_order = true -ij_python_optimize_imports_join_from_imports_with_same_source = false -ij_python_optimize_imports_sort_by_type_first = true -ij_python_optimize_imports_sort_imports = true -ij_python_optimize_imports_sort_names_in_from_imports = true -ij_python_space_after_comma = true -ij_python_space_after_number_sign = true -ij_python_space_after_py_colon = true -ij_python_space_before_backslash = true -ij_python_space_before_comma = false -ij_python_space_before_for_semicolon = false -ij_python_space_before_lbracket = false -ij_python_space_before_method_call_parentheses = false -ij_python_space_before_method_parentheses = false -ij_python_space_before_number_sign = true -ij_python_space_before_py_colon = false -ij_python_space_within_empty_method_call_parentheses = false -ij_python_space_within_empty_method_parentheses = false -ij_python_spaces_around_additive_operators = true -ij_python_spaces_around_assignment_operators = true -ij_python_spaces_around_bitwise_operators = true -ij_python_spaces_around_eq_in_keyword_argument = false -ij_python_spaces_around_eq_in_named_parameter = false -ij_python_spaces_around_equality_operators = true -ij_python_spaces_around_multiplicative_operators = true -ij_python_spaces_around_power_operator = true -ij_python_spaces_around_relational_operators = true -ij_python_spaces_around_shift_operators = true -ij_python_spaces_within_braces = false -ij_python_spaces_within_brackets = false -ij_python_spaces_within_method_call_parentheses = false -ij_python_spaces_within_method_parentheses = false -ij_python_use_continuation_indent_for_arguments = false +ij_python_align_collections_and_comprehensions = true +ij_python_align_multiline_imports = true +ij_python_align_multiline_parameters = true +ij_python_align_multiline_parameters_in_calls = true +ij_python_blank_line_at_file_end = false +ij_python_blank_lines_after_imports = 1 +ij_python_blank_lines_after_local_imports = 0 +ij_python_blank_lines_around_class = 1 +ij_python_blank_lines_around_method = 1 +ij_python_blank_lines_around_top_level_classes_functions = 2 +ij_python_blank_lines_before_first_method = 0 +ij_python_call_parameters_new_line_after_left_paren = false +ij_python_call_parameters_right_paren_on_new_line = false +ij_python_call_parameters_wrap = on_every_item +ij_python_dict_alignment = 0 +ij_python_dict_new_line_after_left_brace = false +ij_python_dict_new_line_before_right_brace = false +ij_python_dict_wrapping = 5 +ij_python_from_import_new_line_after_left_parenthesis = false +ij_python_from_import_new_line_before_right_parenthesis = false +ij_python_from_import_parentheses_force_if_multiline = false +ij_python_from_import_trailing_comma_if_multiline = false +ij_python_from_import_wrapping = 5 +ij_python_hang_closing_brackets = true +ij_python_keep_blank_lines_in_code = 1 +ij_python_keep_blank_lines_in_declarations = 1 +ij_python_keep_indents_on_empty_lines = false +ij_python_keep_line_breaks = true +ij_python_method_parameters_new_line_after_left_paren = false +ij_python_method_parameters_right_paren_on_new_line = false +ij_python_method_parameters_wrap = on_every_item +ij_python_new_line_after_colon = false +ij_python_new_line_after_colon_multi_clause = true +ij_python_optimize_imports_always_split_from_imports = false +ij_python_optimize_imports_case_insensitive_order = true +ij_python_optimize_imports_join_from_imports_with_same_source = false +ij_python_optimize_imports_sort_by_type_first = true +ij_python_optimize_imports_sort_imports = true +ij_python_optimize_imports_sort_names_in_from_imports = true +ij_python_space_after_comma = true +ij_python_space_after_number_sign = true +ij_python_space_after_py_colon = true +ij_python_space_before_backslash = true +ij_python_space_before_comma = false +ij_python_space_before_for_semicolon = false +ij_python_space_before_lbracket = false +ij_python_space_before_method_call_parentheses = false +ij_python_space_before_method_parentheses = false +ij_python_space_before_number_sign = true +ij_python_space_before_py_colon = false +ij_python_space_within_empty_method_call_parentheses = false +ij_python_space_within_empty_method_parentheses = false +ij_python_spaces_around_additive_operators = true +ij_python_spaces_around_assignment_operators = true +ij_python_spaces_around_bitwise_operators = true +ij_python_spaces_around_eq_in_keyword_argument = false +ij_python_spaces_around_eq_in_named_parameter = false +ij_python_spaces_around_equality_operators = true +ij_python_spaces_around_multiplicative_operators = true +ij_python_spaces_around_power_operator = true +ij_python_spaces_around_relational_operators = true +ij_python_spaces_around_shift_operators = true +ij_python_spaces_within_braces = false +ij_python_spaces_within_brackets = false +ij_python_spaces_within_method_call_parentheses = false +ij_python_spaces_within_method_parentheses = false +ij_python_use_continuation_indent_for_arguments = false ij_python_use_continuation_indent_for_collection_and_comprehensions = false -ij_python_use_continuation_indent_for_parameters = true -ij_python_wrap_long_lines = false +ij_python_use_continuation_indent_for_parameters = true +ij_python_wrap_long_lines = false [{*.toml,Cargo.lock,Cargo.toml.orig,Gopkg.lock,Pipfile,poetry.lock}] ij_toml_keep_indents_on_empty_lines = false [{*.yaml,*.yml,pubspec.lock}] -indent_size = 2 -ij_yaml_align_values_properties = on_value -ij_yaml_autoinsert_sequence_marker = true -ij_yaml_block_mapping_on_new_line = false -ij_yaml_indent_sequence_value = true +indent_size = 2 +ij_yaml_align_values_properties = on_value +ij_yaml_autoinsert_sequence_marker = true +ij_yaml_block_mapping_on_new_line = false +ij_yaml_indent_sequence_value = true ij_yaml_keep_indents_on_empty_lines = false -ij_yaml_keep_line_breaks = true -ij_yaml_sequence_on_new_line = false -ij_yaml_space_before_colon = false -ij_yaml_spaces_within_braces = true -ij_yaml_spaces_within_brackets = true -indent_style = space +ij_yaml_keep_line_breaks = true +ij_yaml_sequence_on_new_line = false +ij_yaml_space_before_colon = false +ij_yaml_spaces_within_braces = true +ij_yaml_spaces_within_brackets = true +indent_style = space [*.{appxmanifest,asax,ascx,aspx,axaml,build,c,c++,cc,cginc,compute,cp,cpp,cppm,cs,cshtml,cu,cuh,cxx,dtd,fs,fsi,fsscript,fsx,fx,fxh,h,hh,hlsl,hlsli,hlslinc,hpp,hxx,inc,inl,ino,ipp,ixx,master,ml,mli,mpp,mq4,mq5,mqh,nuspec,paml,razor,resw,resx,shader,skin,tpp,usf,ush,uxml,vb,xaml,xamlx,xoml,xsd}] indent_style = space -indent_size = 4 -tab_width = 4 +indent_size = 4 +tab_width = 4 diff --git a/Aaru.Helpers.csproj.DotSettings b/Aaru.Helpers.csproj.DotSettings index dc0dbdcef..67ed7f8db 100644 --- a/Aaru.Helpers.csproj.DotSettings +++ b/Aaru.Helpers.csproj.DotSettings @@ -1,2 +1,5 @@ - + True \ No newline at end of file diff --git a/ArrayFill.cs b/ArrayFill.cs index d37300612..ac54f41db 100644 --- a/ArrayFill.cs +++ b/ArrayFill.cs @@ -35,10 +35,7 @@ public static partial class ArrayHelpers /// Array /// Value /// Array type - public static void ArrayFill(T[] destinationArray, T value) => ArrayFill(destinationArray, new[] - { - value - }); + public static void ArrayFill(T[] destinationArray, T value) => ArrayFill(destinationArray, new[] { value }); /// Fills an array with the contents of the specified array /// Array diff --git a/CHS.cs b/CHS.cs index d6bd38dde..d13c80b22 100644 --- a/CHS.cs +++ b/CHS.cs @@ -43,6 +43,7 @@ public static class CHS /// Number of sectors per track /// public static uint ToLBA(uint cyl, uint head, uint sector, uint maxHead, uint maxSector) => - maxHead == 0 || maxSector == 0 ? (((cyl * 16) + head) * 63) + sector - 1 - : (((cyl * maxHead) + head) * maxSector) + sector - 1; + maxHead == 0 || maxSector == 0 + ? (cyl * 16 + head) * 63 + sector - 1 + : (cyl * maxHead + head) * maxSector + sector - 1; } \ No newline at end of file diff --git a/CompareBytes.cs b/CompareBytes.cs index b60245c2b..c7d741113 100644 --- a/CompareBytes.cs +++ b/CompareBytes.cs @@ -60,11 +60,13 @@ public static void CompareBytes(out bool different, out bool sameSize, byte[] co leastBytes = compareArray1.LongLength; for(long i = 0; i < leastBytes; i++) + { if(compareArray1[i] != compareArray2[i]) { different = true; return; } + } } } \ No newline at end of file diff --git a/CountBits.cs b/CountBits.cs index 50460ab98..44b81526c 100644 --- a/CountBits.cs +++ b/CountBits.cs @@ -40,9 +40,9 @@ public static class CountBits /// Bits set to true public static int Count(uint number) { - number -= (number >> 1) & 0x55555555; - number = (number & 0x33333333) + ((number >> 2) & 0x33333333); + number -= number >> 1 & 0x55555555; + number = (number & 0x33333333) + (number >> 2 & 0x33333333); - return (int)((((number + (number >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24); + return (int)((number + (number >> 4) & 0x0F0F0F0F) * 0x01010101 >> 24); } } \ No newline at end of file diff --git a/DateHandlers.cs b/DateHandlers.cs index 1c83dfa8a..fc9073346 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -91,7 +91,7 @@ public static DateTime UnixUnsignedToDateTime(uint seconds, uint nanoseconds) => /// .NET DateTime public static DateTime HighSierraToDateTime(byte[] vdDateTime) { - byte[] isoTime = new byte[17]; + var isoTime = new byte[17]; Array.Copy(vdDateTime, 0, isoTime, 0, 16); return Iso9660ToDateTime(isoTime); @@ -103,8 +103,8 @@ public static DateTime HighSierraToDateTime(byte[] vdDateTime) /// .NET DateTime public static DateTime Iso9660ToDateTime(byte[] vdDateTime) { - byte[] twoCharValue = new byte[2]; - byte[] fourCharValue = new byte[4]; + var twoCharValue = new byte[2]; + var fourCharValue = new byte[4]; fourCharValue[0] = vdDateTime[0]; fourCharValue[1] = vdDateTime[1]; @@ -175,7 +175,7 @@ public static DateTime Iso9660ToDateTime(byte[] vdDateTime) "decodedDT = new DateTime({0}, {1}, {2}, {3}, {4}, {5}, {6}, DateTimeKind.Unspecified);", year, month, day, hour, minute, second, hundredths * 10); - sbyte difference = (sbyte)vdDateTime[16]; + var difference = (sbyte)vdDateTime[16]; var decodedDt = new DateTime(year, month, day, hour, minute, second, hundredths * 10, DateTimeKind.Utc); @@ -260,9 +260,9 @@ public static DateTime DosToDateTime(ushort date, ushort time) /// .NET DateTime public static DateTime CpmToDateTime(byte[] timestamp) { - ushort days = BitConverter.ToUInt16(timestamp, 0); - int hours = timestamp[2]; - int minutes = timestamp[3]; + var days = BitConverter.ToUInt16(timestamp, 0); + int hours = timestamp[2]; + int minutes = timestamp[3]; DateTime temp = _amigaEpoch.AddDays(days); temp = temp.AddHours(hours); @@ -284,18 +284,18 @@ public static DateTime CpmToDateTime(byte[] timestamp) /// 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 minute, byte second, byte centiseconds, byte hundredsOfMicroseconds, + byte microseconds) { - byte specification = (byte)((typeAndTimeZone & 0xF000) >> 12); + var 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; + var preOffset = (ushort)(typeAndTimeZone & 0xFFF); + short offset; if((preOffset & 0x800) == 0x800) offset = (short)(preOffset | 0xF000); @@ -327,15 +327,16 @@ public static DateTime EcmaToDateTime(ushort typeAndTimeZone, short year, byte m public static DateTime Os9ToDateTime(byte[] date) { if(date == null || - (date.Length != 3 && date.Length != 5)) + date.Length != 3 && date.Length != 5) return DateTime.MinValue; DateTime os9Date; try { - 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); + 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); } catch(ArgumentOutOfRangeException) { @@ -348,7 +349,8 @@ public static DateTime Os9ToDateTime(byte[] date) /// Converts a LIF timestamp to .NET DateTime /// LIF timestamp /// .NET DateTime - public static DateTime LifToDateTime(byte[] date) => date is not { Length: 6 } ? new DateTime(1970, 1, 1, 0, 0, 0) + public static DateTime LifToDateTime(byte[] date) => date is not { Length: 6 } + ? new DateTime(1970, 1, 1, 0, 0, 0) : LifToDateTime(date[0], date[1], date[2], date[3], date[4], date[5]); @@ -364,12 +366,12 @@ public static DateTime LifToDateTime(byte year, byte month, byte day, byte hour, { try { - 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 isecond = ((second >> 4) * 10) + (second & 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 isecond = (second >> 4) * 10 + (second & 0xF); if(iyear >= 70) iyear += 1900; diff --git a/Extensions.cs b/Extensions.cs index f43643d63..c48b97066 100644 --- a/Extensions.cs +++ b/Extensions.cs @@ -58,7 +58,7 @@ public static class Extensions /// public static int EnsureRead(this Stream s, byte[] buffer, int offset, int count) { - int pos = 0; + var pos = 0; int read; do diff --git a/Localization/Localization.Designer.cs b/Localization/Localization.Designer.cs index 4080069a6..a07e3a819 100644 --- a/Localization/Localization.Designer.cs +++ b/Localization/Localization.Designer.cs @@ -11,32 +11,46 @@ namespace Aaru.Helpers { using System; - [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] - [System.Diagnostics.DebuggerNonUserCodeAttribute()] - [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Localization { - private static System.Resources.ResourceManager resourceMan; + private static global::System.Resources.ResourceManager resourceMan; - private static System.Globalization.CultureInfo resourceCulture; + private static global::System.Globalization.CultureInfo resourceCulture; - [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] internal Localization() { } - [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] - internal static System.Resources.ResourceManager ResourceManager { + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { get { - if (object.Equals(null, resourceMan)) { - System.Resources.ResourceManager temp = new System.Resources.ResourceManager("Aaru.Helpers.Localization.Localization", typeof(Localization).Assembly); + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Aaru.Helpers.Localization.Localization", typeof(Localization).Assembly); resourceMan = temp; } return resourceMan; } } - [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] - internal static System.Globalization.CultureInfo Culture { + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { get { return resourceCulture; } @@ -45,12 +59,18 @@ internal static System.Globalization.CultureInfo Culture { } } + /// + /// Looks up a localized string similar to Length of value array must not be more than length of destination. + /// internal static string Length_of_value_array_must_not_be_more_than_length_of_destination { get { return ResourceManager.GetString("Length_of_value_array_must_not_be_more_than_length_of_destination", resourceCulture); } } + /// + /// Looks up a localized string similar to Offset. + /// internal static string Offset { get { return ResourceManager.GetString("Offset", resourceCulture); diff --git a/Localization/Localization.es.resx b/Localization/Localization.es.resx index 2be0f2713..15b6f7ebd 100644 --- a/Localization/Localization.es.resx +++ b/Localization/Localization.es.resx @@ -1,21 +1,25 @@ - - - text/microsoft-resx - - - 1.3 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089 + + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089 + + + Compensación - + La longitud de una colección no puede ser mayor que la longitud del destino \ No newline at end of file diff --git a/Localization/Localization.resx b/Localization/Localization.resx index bc6fe314c..7ec00abdd 100644 --- a/Localization/Localization.resx +++ b/Localization/Localization.resx @@ -1,30 +1,32 @@ - - - - - text/microsoft-resx - - - 1.3 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, - PublicKeyToken=b77a5c561934e089 - - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, - PublicKeyToken=b77a5c561934e089 - - - + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089 + + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, + PublicKeyToken=b77a5c561934e089 + + + Length of value array must not be more than length of destination - + Offset \ No newline at end of file diff --git a/Marshal.cs b/Marshal.cs index 17df2f039..682451675 100644 --- a/Marshal.cs +++ b/Marshal.cs @@ -250,91 +250,93 @@ public static T MarshalStructure(byte[] bytes) where T : struct return ByteArrayToStructureLittleEndian(bytes); return properties.Endian switch - { - BitEndian.Little => properties.HasReferences ? ByteArrayToStructureLittleEndian(bytes) - : SpanToStructureLittleEndian(bytes), - BitEndian.Big => properties.HasReferences ? ByteArrayToStructureBigEndian(bytes) - : SpanToStructureBigEndian(bytes), - BitEndian.Pdp => properties.HasReferences ? ByteArrayToStructurePdpEndian(bytes) - : SpanToStructurePdpEndian(bytes), - _ => throw new ArgumentOutOfRangeException() - }; + { + BitEndian.Little => properties.HasReferences + ? ByteArrayToStructureLittleEndian(bytes) + : SpanToStructureLittleEndian(bytes), + BitEndian.Big => properties.HasReferences + ? ByteArrayToStructureBigEndian(bytes) + : SpanToStructureBigEndian(bytes), + BitEndian.Pdp => properties.HasReferences + ? ByteArrayToStructurePdpEndian(bytes) + : SpanToStructurePdpEndian(bytes), + _ => throw new ArgumentOutOfRangeException() + }; } /// Swaps all members of a structure /// /// - [MethodImpl(MethodImplOptions.AggressiveInlining), SuppressMessage("ReSharper", "InconsistentNaming")] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [SuppressMessage("ReSharper", "InconsistentNaming")] public static object SwapStructureMembersEndian(object str) { Type t = str.GetType(); FieldInfo[] fieldInfo = t.GetFields(); foreach(FieldInfo fi in fieldInfo) + { if(fi.FieldType == typeof(short) || - (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(short))) + fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(short)) { - short x = (short)(fi.GetValue(str) ?? default(short)); - fi.SetValue(str, (short)((x << 8) | ((x >> 8) & 0xFF))); + var x = (short)(fi.GetValue(str) ?? default(short)); + fi.SetValue(str, (short)(x << 8 | x >> 8 & 0xFF)); } else if(fi.FieldType == typeof(int) || - (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(int))) + fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(int)) { - int x = (int)(fi.GetValue(str) ?? default(int)); - x = (int)(((x << 8) & 0xFF00FF00) | (((uint)x >> 8) & 0xFF00FF)); - fi.SetValue(str, (int)(((uint)x << 16) | (((uint)x >> 16) & 0xFFFF))); + var x = (int)(fi.GetValue(str) ?? default(int)); + x = (int)(x << 8 & 0xFF00FF00 | (uint)x >> 8 & 0xFF00FF); + fi.SetValue(str, (int)((uint)x << 16 | (uint)x >> 16 & 0xFFFF)); } else if(fi.FieldType == typeof(long) || - (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(long))) + fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(long)) { - long x = (long)(fi.GetValue(str) ?? default(long)); - x = ((x & 0x00000000FFFFFFFF) << 32) | (long)(((ulong)x & 0xFFFFFFFF00000000) >> 32); - x = ((x & 0x0000FFFF0000FFFF) << 16) | (long)(((ulong)x & 0xFFFF0000FFFF0000) >> 16); - x = ((x & 0x00FF00FF00FF00FF) << 8) | (long)(((ulong)x & 0xFF00FF00FF00FF00) >> 8); + var x = (long)(fi.GetValue(str) ?? default(long)); + x = (x & 0x00000000FFFFFFFF) << 32 | (long)(((ulong)x & 0xFFFFFFFF00000000) >> 32); + x = (x & 0x0000FFFF0000FFFF) << 16 | (long)(((ulong)x & 0xFFFF0000FFFF0000) >> 16); + x = (x & 0x00FF00FF00FF00FF) << 8 | (long)(((ulong)x & 0xFF00FF00FF00FF00) >> 8); fi.SetValue(str, x); } else if(fi.FieldType == typeof(ushort) || - (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(ushort))) + fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(ushort)) { - ushort x = (ushort)(fi.GetValue(str) ?? default(ushort)); - fi.SetValue(str, (ushort)((x << 8) | (x >> 8))); + var x = (ushort)(fi.GetValue(str) ?? default(ushort)); + fi.SetValue(str, (ushort)(x << 8 | x >> 8)); } else if(fi.FieldType == typeof(uint) || - (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(uint))) + fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(uint)) { - uint x = (uint)(fi.GetValue(str) ?? default(uint)); - x = ((x << 8) & 0xFF00FF00) | ((x >> 8) & 0xFF00FF); - fi.SetValue(str, (x << 16) | (x >> 16)); + var x = (uint)(fi.GetValue(str) ?? default(uint)); + x = x << 8 & 0xFF00FF00 | x >> 8 & 0xFF00FF; + fi.SetValue(str, x << 16 | x >> 16); } else if(fi.FieldType == typeof(ulong) || - (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(ulong))) + fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(ulong)) { - ulong x = (ulong)(fi.GetValue(str) ?? default(ulong)); - x = ((x & 0x00000000FFFFFFFF) << 32) | ((x & 0xFFFFFFFF00000000) >> 32); - x = ((x & 0x0000FFFF0000FFFF) << 16) | ((x & 0xFFFF0000FFFF0000) >> 16); - x = ((x & 0x00FF00FF00FF00FF) << 8) | ((x & 0xFF00FF00FF00FF00) >> 8); + var x = (ulong)(fi.GetValue(str) ?? default(ulong)); + x = (x & 0x00000000FFFFFFFF) << 32 | (x & 0xFFFFFFFF00000000) >> 32; + x = (x & 0x0000FFFF0000FFFF) << 16 | (x & 0xFFFF0000FFFF0000) >> 16; + x = (x & 0x00FF00FF00FF00FF) << 8 | (x & 0xFF00FF00FF00FF00) >> 8; fi.SetValue(str, x); } else if(fi.FieldType == typeof(float)) { - float flt = (float)(fi.GetValue(str) ?? default(float)); + var flt = (float)(fi.GetValue(str) ?? default(float)); byte[] flt_b = BitConverter.GetBytes(flt); - fi.SetValue(str, BitConverter.ToSingle(new[] - { - flt_b[3], flt_b[2], flt_b[1], flt_b[0] - }, 0)); + fi.SetValue(str, BitConverter.ToSingle(new[] { flt_b[3], flt_b[2], flt_b[1], flt_b[0] }, 0)); } else if(fi.FieldType == typeof(double)) { - double dbl = (double)(fi.GetValue(str) ?? default(double)); + var dbl = (double)(fi.GetValue(str) ?? default(double)); byte[] dbl_b = BitConverter.GetBytes(dbl); - fi.SetValue(str, BitConverter.ToDouble(new[] - { - dbl_b[7], dbl_b[6], dbl_b[5], dbl_b[4], dbl_b[3], dbl_b[2], dbl_b[1], dbl_b[0] - }, 0)); + fi.SetValue( + str, + BitConverter.ToDouble( + new[] { dbl_b[7], dbl_b[6], dbl_b[5], dbl_b[4], dbl_b[3], dbl_b[2], dbl_b[1], dbl_b[0] }, 0)); } else if(fi.FieldType == typeof(byte) || fi.FieldType == typeof(sbyte)) @@ -354,6 +356,7 @@ public static object SwapStructureMembersEndian(object str) object strc = SwapStructureMembersEndian(obj); fi.SetValue(str, strc); } + } return str; } @@ -368,6 +371,7 @@ public static object SwapStructureMembersEndianPdp(object str) FieldInfo[] fieldInfo = t.GetFields(); foreach(FieldInfo fi in fieldInfo) + { if(fi.FieldType == typeof(short) || fi.FieldType == typeof(long) || fi.FieldType == typeof(ushort) || @@ -381,16 +385,16 @@ public static object SwapStructureMembersEndianPdp(object str) // Do nothing } else if(fi.FieldType == typeof(int) || - (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(int))) + fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(int)) { - int x = (int)(fi.GetValue(str) ?? default(int)); - fi.SetValue(str, ((x & 0xffffu) << 16) | ((x & 0xffff0000u) >> 16)); + var x = (int)(fi.GetValue(str) ?? default(int)); + fi.SetValue(str, (x & 0xffffu) << 16 | (x & 0xffff0000u) >> 16); } else if(fi.FieldType == typeof(uint) || - (fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(uint))) + fi.FieldType.IsEnum && fi.FieldType.GetEnumUnderlyingType() == typeof(uint)) { - uint x = (uint)(fi.GetValue(str) ?? default(uint)); - fi.SetValue(str, ((x & 0xffffu) << 16) | ((x & 0xffff0000u) >> 16)); + var x = (uint)(fi.GetValue(str) ?? default(uint)); + fi.SetValue(str, (x & 0xffffu) << 16 | (x & 0xffff0000u) >> 16); } // TODO: Swap arrays @@ -401,6 +405,7 @@ public static object SwapStructureMembersEndianPdp(object str) object strc = SwapStructureMembersEndianPdp(obj); fi.SetValue(str, strc); } + } return str; } @@ -412,8 +417,8 @@ public static object SwapStructureMembersEndianPdp(object str) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static byte[] StructureToByteArrayLittleEndian(T str) where T : struct { - byte[] buf = new byte[SizeOf()]; - var ptr = GCHandle.Alloc(buf, GCHandleType.Pinned); + var buf = new byte[SizeOf()]; + var ptr = GCHandle.Alloc(buf, GCHandleType.Pinned); System.Runtime.InteropServices.Marshal.StructureToPtr(str, ptr.AddrOfPinnedObject(), false); ptr.Free(); @@ -439,14 +444,14 @@ public static int ConvertFromHexAscii(string hex, out byte[] outBuf) if(hex is null or "") return -1; - int off = 0; + var off = 0; if(hex[0] == '0' && (hex[1] == 'x' || hex[1] == 'X')) off = 2; outBuf = new byte[(hex.Length - off) / 2]; - int count = 0; + var count = 0; for(int i = off; i < hex.Length; i += 2) { @@ -456,11 +461,11 @@ public static int ConvertFromHexAscii(string hex, out byte[] outBuf) break; c -= c switch - { - >= 'a' and <= 'f' => '\u0057', - >= 'A' and <= 'F' => '\u0037', - _ => '\u0030' - }; + { + >= 'a' and <= 'f' => '\u0057', + >= 'A' and <= 'F' => '\u0037', + _ => '\u0030' + }; outBuf[(i - off) / 2] = (byte)(c << 4); @@ -470,11 +475,11 @@ public static int ConvertFromHexAscii(string hex, out byte[] outBuf) break; c -= c switch - { - >= 'a' and <= 'f' => '\u0057', - >= 'A' and <= 'F' => '\u0037', - _ => '\u0030' - }; + { + >= 'a' and <= 'f' => '\u0057', + >= 'A' and <= 'F' => '\u0037', + _ => '\u0030' + }; outBuf[(i - off) / 2] += (byte)c; diff --git a/MarshallingPropertiesAttribute.cs b/MarshallingPropertiesAttribute.cs index 4dfafe569..40dc5d63f 100644 --- a/MarshallingPropertiesAttribute.cs +++ b/MarshallingPropertiesAttribute.cs @@ -56,6 +56,7 @@ public MarshallingPropertiesAttribute(BitEndian endian) /// c public BitEndian Endian { get; } + /// Tells if the structure, or any nested structure, has any non-value type (e.g. arrays, strings, etc). public bool HasReferences { get; set; } } \ No newline at end of file diff --git a/PrintHex.cs b/PrintHex.cs index df4b5a99a..30934d018 100644 --- a/PrintHex.cs +++ b/PrintHex.cs @@ -86,7 +86,7 @@ public static string ByteArrayToHexArrayString(byte[] array, int width = 16, boo sb.Append(str); sb.Append(" "); - for(int i = 0; i < width; i++) + for(var i = 0; i < width; i++) sb.AppendFormat(" {0:X2}", i); if(color) @@ -94,11 +94,11 @@ public static string ByteArrayToHexArrayString(byte[] array, int width = 16, boo sb.AppendLine(); - int b = 0; + var b = 0; - string format = $"{{0:X{offsetLength}}}"; + var format = $"{{0:X{offsetLength}}}"; - for(int i = 0; i < rows; i++) + for(var i = 0; i < rows; i++) { if(color) sb.Append("\u001b[36m"); @@ -112,19 +112,19 @@ public static string ByteArrayToHexArrayString(byte[] array, int width = 16, boo int lastBytes = i == rows - 1 ? last : width; int lastSpaces = width - lastBytes; - for(int j = 0; j < lastBytes; j++) + for(var j = 0; j < lastBytes; j++) { sb.AppendFormat(" {0:X2}", array[b]); b++; } - for(int j = 0; j < lastSpaces; j++) + for(var j = 0; j < lastSpaces; j++) sb.Append(" "); b -= lastBytes; sb.Append(" "); - for(int j = 0; j < lastBytes; j++) + for(var j = 0; j < lastBytes; j++) { int v = array[b]; sb.Append(v is > 31 and < 127 or > 159 ? (char)v : '.'); diff --git a/StringHandlers.cs b/StringHandlers.cs index 8247656d0..b7077a833 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -54,11 +54,12 @@ public static string CToString(byte[] cString, Encoding encoding, bool twoBytes if(cString == null) return null; - int len = 0; + var len = 0; for(int i = start; i < cString.Length; i++) { if(cString[i] == 0) + { if(twoBytes) { if(i + 1 < cString.Length && @@ -71,6 +72,7 @@ public static string CToString(byte[] cString, Encoding encoding, bool twoBytes } else break; + } len++; } @@ -78,7 +80,7 @@ public static string CToString(byte[] cString, Encoding encoding, bool twoBytes if(twoBytes && len % 2 > 0) len--; - byte[] dest = new byte[len]; + var dest = new byte[len]; Array.Copy(cString, start, dest, 0, len); return len == 0 ? "" : encoding.GetString(dest); @@ -100,7 +102,7 @@ public static string PascalToString(byte[] pascalString, Encoding encoding, int return null; byte length = pascalString[start]; - int len = 0; + var len = 0; for(int i = start + 1; i < length + 1 && i < pascalString.Length; i++) { @@ -110,7 +112,7 @@ public static string PascalToString(byte[] pascalString, Encoding encoding, int len++; } - byte[] dest = new byte[len]; + var dest = new byte[len]; Array.Copy(pascalString, start + 1, dest, 0, len); return len == 0 ? "" : encoding.GetString(dest); @@ -155,14 +157,14 @@ public static string SpacePaddedToString(byte[] spacePaddedString, Encoding enco /// OSTA compressed unicode byte array. public static string DecompressUnicode(byte[] dstring) { - byte compId = dstring[0]; - string temp = ""; + byte compId = dstring[0]; + var temp = ""; if(compId != 8 && compId != 16) return null; - for(int byteIndex = 1; byteIndex < dstring.Length;) + for(var byteIndex = 1; byteIndex < dstring.Length;) { ushort unicode; diff --git a/Swapping.cs b/Swapping.cs index b25403913..cc80e97a2 100644 --- a/Swapping.cs +++ b/Swapping.cs @@ -41,25 +41,25 @@ public static class Swapping /// Little endian unsigned integer /// PDP unsigned integer [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static uint PDPFromLittleEndian(uint x) => ((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16); + public static uint PDPFromLittleEndian(uint x) => (x & 0xffff) << 16 | (x & 0xffff0000) >> 16; /// Gets the PDP endian equivalent of the given big endian unsigned integer /// Big endian unsigned integer /// PDP unsigned integer [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static uint PDPFromBigEndian(uint x) => ((x & 0xff00ff) << 8) | ((x & 0xff00ff00) >> 8); + public static uint PDPFromBigEndian(uint x) => (x & 0xff00ff) << 8 | (x & 0xff00ff00) >> 8; /// Swaps the endian of the specified unsigned short integer /// Unsigned short integer /// Swapped unsigned short integer [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ushort Swap(ushort x) => (ushort)((x << 8) | (x >> 8)); + public static ushort Swap(ushort x) => (ushort)(x << 8 | x >> 8); /// Swaps the endian of the specified signed short integer /// Signed short integer /// Swapped signed short integer [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static short Swap(short x) => (short)((x << 8) | ((x >> 8) & 0xFF)); + public static short Swap(short x) => (short)(x << 8 | x >> 8 & 0xFF); /// Swaps the endian of the specified unsigned integer /// Unsigned integer @@ -67,9 +67,9 @@ public static class Swapping [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint Swap(uint x) { - x = ((x << 8) & 0xFF00FF00) | ((x >> 8) & 0xFF00FF); + x = x << 8 & 0xFF00FF00 | x >> 8 & 0xFF00FF; - return (x << 16) | (x >> 16); + return x << 16 | x >> 16; } /// Swaps the endian of the specified signed integer @@ -78,9 +78,9 @@ public static uint Swap(uint x) [MethodImpl(MethodImplOptions.AggressiveInlining)] 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); } /// Swaps the endian of the specified unsigned long integer @@ -89,9 +89,9 @@ public static int Swap(int x) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ulong Swap(ulong x) { - x = ((x & 0x00000000FFFFFFFF) << 32) | ((x & 0xFFFFFFFF00000000) >> 32); - x = ((x & 0x0000FFFF0000FFFF) << 16) | ((x & 0xFFFF0000FFFF0000) >> 16); - x = ((x & 0x00FF00FF00FF00FF) << 8) | ((x & 0xFF00FF00FF00FF00) >> 8); + x = (x & 0x00000000FFFFFFFF) << 32 | (x & 0xFFFFFFFF00000000) >> 32; + x = (x & 0x0000FFFF0000FFFF) << 16 | (x & 0xFFFF0000FFFF0000) >> 16; + x = (x & 0x00FF00FF00FF00FF) << 8 | (x & 0xFF00FF00FF00FF00) >> 8; return x; } @@ -102,9 +102,9 @@ public static ulong Swap(ulong x) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Swap(long x) { - x = ((x & 0x00000000FFFFFFFF) << 32) | (long)(((ulong)x & 0xFFFFFFFF00000000) >> 32); - x = ((x & 0x0000FFFF0000FFFF) << 16) | (long)(((ulong)x & 0xFFFF0000FFFF0000) >> 16); - x = ((x & 0x00FF00FF00FF00FF) << 8) | (long)(((ulong)x & 0xFF00FF00FF00FF00) >> 8); + x = (x & 0x00000000FFFFFFFF) << 32 | (long)(((ulong)x & 0xFFFFFFFF00000000) >> 32); + x = (x & 0x0000FFFF0000FFFF) << 16 | (long)(((ulong)x & 0xFFFF0000FFFF0000) >> 16); + x = (x & 0x00FF00FF00FF00FF) << 8 | (long)(((ulong)x & 0xFF00FF00FF00FF00) >> 8); return x; } From 6f76a5d4601dc3ba2895eba4981ff8602a52aae4 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 4 Oct 2023 07:39:21 +0100 Subject: [PATCH 211/217] Invert 'if' statement to reduce nesting. --- CompareBytes.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CompareBytes.cs b/CompareBytes.cs index c7d741113..a06aaed9f 100644 --- a/CompareBytes.cs +++ b/CompareBytes.cs @@ -61,12 +61,12 @@ public static void CompareBytes(out bool different, out bool sameSize, byte[] co for(long i = 0; i < leastBytes; i++) { - if(compareArray1[i] != compareArray2[i]) - { - different = true; + if(compareArray1[i] == compareArray2[i]) + continue; - return; - } + different = true; + + return; } } } \ No newline at end of file From bfe4402f0a2d448149fd5d36daf0da5d003e7853 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 4 Oct 2023 08:16:20 +0100 Subject: [PATCH 212/217] Pass string interpolation. --- ArrayFill.cs | 2 +- PrintHex.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ArrayFill.cs b/ArrayFill.cs index ac54f41db..ee3e9e1f0 100644 --- a/ArrayFill.cs +++ b/ArrayFill.cs @@ -69,7 +69,7 @@ public static string ByteArrayToHex(byte[] array, bool upper = false) var sb = new StringBuilder(); for(long i = 0; i < array.LongLength; i++) - sb.AppendFormat("{0:x2}", array[i]); + sb.Append($"{array[i]:x2}"); return upper ? sb.ToString().ToUpper() : sb.ToString(); } diff --git a/PrintHex.cs b/PrintHex.cs index 30934d018..0f3c92b87 100644 --- a/PrintHex.cs +++ b/PrintHex.cs @@ -87,7 +87,7 @@ public static string ByteArrayToHexArrayString(byte[] array, int width = 16, boo sb.Append(" "); for(var i = 0; i < width; i++) - sb.AppendFormat(" {0:X2}", i); + sb.Append($" {i:X2}"); if(color) sb.Append("\u001b[0m"); @@ -114,7 +114,7 @@ public static string ByteArrayToHexArrayString(byte[] array, int width = 16, boo for(var j = 0; j < lastBytes; j++) { - sb.AppendFormat(" {0:X2}", array[b]); + sb.Append($" {array[b]:X2}"); b++; } From e59bc38221d3ee973fc4b991234d959182f6e502 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 4 Oct 2023 17:34:37 +0100 Subject: [PATCH 213/217] Redo Reformat and cleanup. Rider EAP was having a bug interpreting .editorconfig that didn't generate the code style as we wanted. This is now done with Rider-stable. --- .editorconfig | 6 +++++- ArrayFill.cs | 5 ++++- DateHandlers.cs | 16 +++++++--------- Marshal.cs | 25 ++++++++++++------------- StringHandlers.cs | 6 ++---- 5 files changed, 30 insertions(+), 28 deletions(-) diff --git a/.editorconfig b/.editorconfig index 71a05170a..103a5d927 100644 --- a/.editorconfig +++ b/.editorconfig @@ -83,7 +83,7 @@ resharper_braces_for_ifelse resharper_braces_for_while = required_for_multiline resharper_builtin_type_apply_to_native_integer = false resharper_constructor_or_destructor_body = expression_body -resharper_csharp_align_first_arg_by_paren = false +resharper_csharp_align_first_arg_by_paren = true resharper_csharp_empty_block_style = together_same_line resharper_csharp_place_comments_at_first_column = true resharper_csharp_prefer_qualified_reference = false @@ -108,6 +108,7 @@ resharper_int_align_enum_initializers resharper_int_align_eq = true resharper_keep_existing_embedded_arrangement = false resharper_keep_existing_initializer_arrangement = false +resharper_keep_existing_linebreaks = false resharper_keep_existing_list_patterns_arrangement = false resharper_keep_existing_property_patterns_arrangement = false resharper_keep_existing_switch_expression_arrangement = false @@ -125,6 +126,7 @@ resharper_outdent_statement_labels resharper_parentheses_redundancy_style = remove resharper_place_attribute_on_same_line = false resharper_place_simple_embedded_statement_on_same_line = false +resharper_place_simple_initializer_on_single_line = false resharper_qualified_using_at_nested_scope = true resharper_show_autodetect_configure_formatting_tip = false resharper_simple_block_style = on_single_line @@ -146,6 +148,8 @@ resharper_use_indent_from_vs resharper_wrap_after_dot_in_method_calls = true resharper_wrap_base_clause_style = chop_if_long resharper_wrap_braced_init_list_style = chop_if_long +resharper_wrap_chained_binary_expressions = chop_if_long +resharper_wrap_chained_method_calls = chop_if_long resharper_wrap_ctor_initializer_style = chop_if_long resharper_wrap_lines = true resharper_xmldoc_attribute_indent = align_by_first_attribute diff --git a/ArrayFill.cs b/ArrayFill.cs index ee3e9e1f0..cbac721e8 100644 --- a/ArrayFill.cs +++ b/ArrayFill.cs @@ -35,7 +35,10 @@ public static partial class ArrayHelpers /// Array /// Value /// Array type - public static void ArrayFill(T[] destinationArray, T value) => ArrayFill(destinationArray, new[] { value }); + public static void ArrayFill(T[] destinationArray, T value) => ArrayFill(destinationArray, new[] + { + value + }); /// Fills an array with the contents of the specified array /// Array diff --git a/DateHandlers.cs b/DateHandlers.cs index fc9073346..ba80926df 100644 --- a/DateHandlers.cs +++ b/DateHandlers.cs @@ -215,9 +215,8 @@ public static DateTime UcsdPascalToDateTime(short dateRecord) int day = (dateRecord & 0x01F0) >> 4; int month = dateRecord & 0x000F; - AaruConsole.DebugWriteLine(PASCAL_MODULE_NAME, - "dateRecord = 0x{0:X4}, year = {1}, month = {2}, day = {3}", dateRecord, year, month, - day); + AaruConsole.DebugWriteLine(PASCAL_MODULE_NAME, "dateRecord = 0x{0:X4}, year = {1}, month = {2}, day = {3}", + dateRecord, year, month, day); return new DateTime(year, month, day); } @@ -235,11 +234,11 @@ public static DateTime DosToDateTime(ushort date, ushort time) int minute = (time & 0x7E0) >> 5; int second = (time & 0x1F) * 2; - AaruConsole.DebugWriteLine(DOS_MODULE_NAME, "date = 0x{0:X4}, year = {1}, month = {2}, day = {3}", date, - year, month, day); + AaruConsole.DebugWriteLine(DOS_MODULE_NAME, "date = 0x{0:X4}, year = {1}, month = {2}, day = {3}", date, year, + month, day); - AaruConsole.DebugWriteLine(DOS_MODULE_NAME, "time = 0x{0:X4}, hour = {1}, minute = {2}, second = {3}", - time, hour, minute, second); + AaruConsole.DebugWriteLine(DOS_MODULE_NAME, "time = 0x{0:X4}, hour = {1}, minute = {2}, second = {3}", time, + hour, minute, second); DateTime dosDate; @@ -326,8 +325,7 @@ public static DateTime EcmaToDateTime(ushort typeAndTimeZone, short year, byte m /// .NET DateTime public static DateTime Os9ToDateTime(byte[] date) { - if(date == null || - date.Length != 3 && date.Length != 5) + if(date == null || date.Length != 3 && date.Length != 5) return DateTime.MinValue; DateTime os9Date; diff --git a/Marshal.cs b/Marshal.cs index 682451675..7791e2332 100644 --- a/Marshal.cs +++ b/Marshal.cs @@ -326,20 +326,22 @@ public static object SwapStructureMembersEndian(object str) var flt = (float)(fi.GetValue(str) ?? default(float)); byte[] flt_b = BitConverter.GetBytes(flt); - fi.SetValue(str, BitConverter.ToSingle(new[] { flt_b[3], flt_b[2], flt_b[1], flt_b[0] }, 0)); + fi.SetValue(str, BitConverter.ToSingle(new[] + { + flt_b[3], flt_b[2], flt_b[1], flt_b[0] + }, 0)); } else if(fi.FieldType == typeof(double)) { var dbl = (double)(fi.GetValue(str) ?? default(double)); byte[] dbl_b = BitConverter.GetBytes(dbl); - fi.SetValue( - str, - BitConverter.ToDouble( - new[] { dbl_b[7], dbl_b[6], dbl_b[5], dbl_b[4], dbl_b[3], dbl_b[2], dbl_b[1], dbl_b[0] }, 0)); + fi.SetValue(str, BitConverter.ToDouble(new[] + { + dbl_b[7], dbl_b[6], dbl_b[5], dbl_b[4], dbl_b[3], dbl_b[2], dbl_b[1], dbl_b[0] + }, 0)); } - else if(fi.FieldType == typeof(byte) || - fi.FieldType == typeof(sbyte)) + else if(fi.FieldType == typeof(byte) || fi.FieldType == typeof(sbyte)) { // Do nothing, can't byteswap them! } @@ -349,8 +351,7 @@ public static object SwapStructureMembersEndian(object str) } // TODO: Swap arrays - else if(fi.FieldType.IsValueType && - fi.FieldType is { IsEnum: false, IsArray: false }) + else if(fi.FieldType.IsValueType && fi.FieldType is { IsEnum: false, IsArray: false }) { object obj = fi.GetValue(str); object strc = SwapStructureMembersEndian(obj); @@ -398,8 +399,7 @@ public static object SwapStructureMembersEndianPdp(object str) } // TODO: Swap arrays - else if(fi.FieldType.IsValueType && - fi.FieldType is { IsEnum: false, IsArray: false }) + else if(fi.FieldType.IsValueType && fi.FieldType is { IsEnum: false, IsArray: false }) { object obj = fi.GetValue(str); object strc = SwapStructureMembersEndianPdp(obj); @@ -446,8 +446,7 @@ public static int ConvertFromHexAscii(string hex, out byte[] outBuf) var off = 0; - if(hex[0] == '0' && - (hex[1] == 'x' || hex[1] == 'X')) + if(hex[0] == '0' && (hex[1] == 'x' || hex[1] == 'X')) off = 2; outBuf = new byte[(hex.Length - off) / 2]; diff --git a/StringHandlers.cs b/StringHandlers.cs index b7077a833..aa9bc4c24 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -62,8 +62,7 @@ public static string CToString(byte[] cString, Encoding encoding, bool twoBytes { if(twoBytes) { - if(i + 1 < cString.Length && - cString[i + 1] == 0) + if(i + 1 < cString.Length && cString[i + 1] == 0) { len++; @@ -160,8 +159,7 @@ public static string DecompressUnicode(byte[] dstring) byte compId = dstring[0]; var temp = ""; - if(compId != 8 && - compId != 16) + if(compId != 8 && compId != 16) return null; for(var byteIndex = 1; byteIndex < dstring.Length;) From a03ee5efee746bfd60689fa28da759aabe14ba06 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Thu, 5 Oct 2023 01:05:21 +0100 Subject: [PATCH 214/217] Annotate or remove unused elements. --- BigEndianBitConverter.cs | 3 +++ Marshal.cs | 2 ++ StringHandlers.cs | 2 ++ Swapping.cs | 2 ++ 4 files changed, 9 insertions(+) diff --git a/BigEndianBitConverter.cs b/BigEndianBitConverter.cs index dcadf371e..cb1225bea 100644 --- a/BigEndianBitConverter.cs +++ b/BigEndianBitConverter.cs @@ -31,6 +31,7 @@ // ****************************************************************************/ using System; +using System.Diagnostics.CodeAnalysis; using System.Linq; namespace Aaru.Helpers; @@ -39,6 +40,8 @@ namespace Aaru.Helpers; /// Converts base data types to an array of bytes, and an array of bytes to base data types. All info taken from /// the meta data of System.BitConverter. This implementation allows for Endianness consideration. /// +[SuppressMessage("ReSharper", "UnusedParameter.Global")] +[SuppressMessage("ReSharper", "UnusedMember.Global")] public static class BigEndianBitConverter { /// Converts the specified double-precision floating point number to a 64-bit signed integer. diff --git a/Marshal.cs b/Marshal.cs index 7791e2332..738c75f7c 100644 --- a/Marshal.cs +++ b/Marshal.cs @@ -39,6 +39,8 @@ namespace Aaru.Helpers; /// Provides methods to marshal binary data into C# structs +[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] +[SuppressMessage("ReSharper", "UnusedMember.Global")] public static class Marshal { /// Returns the size of an unmanaged type in bytes. diff --git a/StringHandlers.cs b/StringHandlers.cs index aa9bc4c24..07348633b 100644 --- a/StringHandlers.cs +++ b/StringHandlers.cs @@ -31,11 +31,13 @@ // ****************************************************************************/ using System; +using System.Diagnostics.CodeAnalysis; using System.Text; namespace Aaru.Helpers; /// Helper operations to work with strings +[SuppressMessage("ReSharper", "UnusedMember.Global")] public static class StringHandlers { /// Converts a null-terminated (aka C string) ASCII byte array to a C# string diff --git a/Swapping.cs b/Swapping.cs index cc80e97a2..e5f3b64f2 100644 --- a/Swapping.cs +++ b/Swapping.cs @@ -30,11 +30,13 @@ // Copyright © 2011-2023 Natalia Portillo // ****************************************************************************/ +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; namespace Aaru.Helpers; /// Helper operations to work with swapping endians +[SuppressMessage("ReSharper", "UnusedMember.Global")] public static class Swapping { /// Gets the PDP endian equivalent of the given little endian unsigned integer From 0a5ccd5a9a3a4963589e2cc9e444a0a0ac01cba2 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sat, 7 Oct 2023 21:29:42 +0100 Subject: [PATCH 215/217] [Aaru.Helpers] Move all stream extensions from around the application to this project. --- IO/ForcedSeekStream.cs | 257 ++++++++++ IO/NonClosableStream.cs | 78 +++ IO/OffsetStream.cs | 680 ++++++++++++++++++++++++++ IO/SplitJoinStream.cs | 372 ++++++++++++++ Localization/Localization.Designer.cs | 117 +++++ Localization/Localization.es.resx | 39 ++ Localization/Localization.resx | 39 ++ 7 files changed, 1582 insertions(+) create mode 100644 IO/ForcedSeekStream.cs create mode 100644 IO/NonClosableStream.cs create mode 100644 IO/OffsetStream.cs create mode 100644 IO/SplitJoinStream.cs diff --git a/IO/ForcedSeekStream.cs b/IO/ForcedSeekStream.cs new file mode 100644 index 000000000..fd48c2f49 --- /dev/null +++ b/IO/ForcedSeekStream.cs @@ -0,0 +1,257 @@ +// /*************************************************************************** +// Aaru Data Preservation Suite +// ---------------------------------------------------------------------------- +// +// Filename : ForcedSeekStream.cs +// Author(s) : Natalia Portillo +// +// Component : Filters. +// +// --[ Description ] ---------------------------------------------------------- +// +// Provides a seekable stream from a forward-readable stream. +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2023 Natalia Portillo +// ****************************************************************************/ + +using System; +using System.IO; + +namespace Aaru.Helpers.IO; + +/// +/// ForcedSeekStream allows to seek a forward-readable stream (like System.IO.Compression streams) by doing the +/// slow and known trick of rewinding and forward reading until arriving the desired position. +/// +/// +public sealed class ForcedSeekStream : Stream where T : Stream +{ + const int BUFFER_LEN = 1048576; + readonly string _backFile; + readonly FileStream _backStream; + readonly T _baseStream; + long _streamLength; + + /// Initializes a new instance of the class. + /// The real (uncompressed) length of the stream. + /// Parameters that are used to create the base stream. + /// + public ForcedSeekStream(long length, params object[] args) + { + _streamLength = length; + _baseStream = (T)Activator.CreateInstance(typeof(T), args); + _backFile = Path.GetTempFileName(); + _backStream = new FileStream(_backFile, FileMode.Open, FileAccess.ReadWrite, FileShare.None); + + if(length == 0) + CalculateLength(); + } + + /// Initializes a new instance of the class. + /// Parameters that are used to create the base stream. + /// + public ForcedSeekStream(params object[] args) + { + _baseStream = (T)Activator.CreateInstance(typeof(T), args); + _backFile = Path.GetTempFileName(); + _backStream = new FileStream(_backFile, FileMode.Open, FileAccess.ReadWrite, FileShare.None); + CalculateLength(); + } + + /// + public override bool CanRead => _baseStream.CanRead; + + /// + public override bool CanSeek => true; + + /// + public override bool CanWrite => false; + + /// + public override long Length => _streamLength; + + /// + public override long Position + { + get => _backStream.Position; + + set => SetPosition(value); + } + + /// + /// Calculates the real (uncompressed) length of the stream. It basically reads (uncompresses) the whole stream to + /// memory discarding its contents, so it should be used as a last resort. + /// + /// The length. + public void CalculateLength() + { + int read; + + do + { + var buffer = new byte[BUFFER_LEN]; + read = _baseStream.EnsureRead(buffer, 0, BUFFER_LEN); + _backStream.Write(buffer, 0, read); + } while(read == BUFFER_LEN); + + _streamLength = _backStream.Length; + _backStream.Position = 0; + } + + void SetPosition(long position) + { + if(position == _backStream.Position) + return; + + if(position < _backStream.Length) + { + _backStream.Position = position; + + return; + } + + if(position > _streamLength) + position = _streamLength; + + _backStream.Position = _backStream.Length; + long toPosition = position - _backStream.Position; + var fullBufferReads = (int)(toPosition / BUFFER_LEN); + var restToRead = (int)(toPosition % BUFFER_LEN); + byte[] buffer; + int bufPos; + int left; + + for(var i = 0; i < fullBufferReads; i++) + { + buffer = new byte[BUFFER_LEN]; + bufPos = 0; + left = BUFFER_LEN; + + while(left > 0) + { + int done = _baseStream.EnsureRead(buffer, bufPos, left); + left -= done; + bufPos += done; + } + + _backStream.Write(buffer, 0, BUFFER_LEN); + } + + buffer = new byte[restToRead]; + bufPos = 0; + left = restToRead; + + while(left > 0) + { + int done = _baseStream.EnsureRead(buffer, bufPos, left); + left -= done; + bufPos += done; + } + + _backStream.Write(buffer, 0, restToRead); + } + + /// + public override void Flush() + { + _baseStream.Flush(); + _backStream.Flush(); + } + + /// + public override int Read(byte[] buffer, int offset, int count) + { + if(_backStream.Position + count > _streamLength) + count = (int)(_streamLength - _backStream.Position); + + if(_backStream.Position + count <= _backStream.Length) + return _backStream.EnsureRead(buffer, offset, count); + + long oldPosition = _backStream.Position; + SetPosition(_backStream.Position + count); + SetPosition(oldPosition); + + return _backStream.EnsureRead(buffer, offset, count); + } + + /// + public override int ReadByte() + { + if(_backStream.Position + 1 > _streamLength) + return -1; + + if(_backStream.Position + 1 <= _backStream.Length) + return _backStream.ReadByte(); + + SetPosition(_backStream.Position + 1); + SetPosition(_backStream.Position - 1); + + return _backStream.ReadByte(); + } + + /// + public override long Seek(long offset, SeekOrigin origin) + { + switch(origin) + { + case SeekOrigin.Begin: + if(offset < 0) + throw new IOException(Localization.Cannot_seek_before_stream_start); + + SetPosition(offset); + + break; + case SeekOrigin.End: + if(offset > 0) + throw new IOException(Localization.Cannot_seek_after_stream_end); + + if(_streamLength == 0) + CalculateLength(); + + SetPosition(_streamLength + offset); + + break; + default: + SetPosition(_backStream.Position + offset); + + break; + } + + return _backStream.Position; + } + + /// + public override void SetLength(long value) => throw new NotSupportedException(); + + /// + public override void Write(byte[] buffer, int offset, int count) => throw new NotSupportedException(); + + /// + public override void Close() + { + _backStream?.Close(); + File.Delete(_backFile); + } + + ~ForcedSeekStream() + { + _backStream?.Close(); + File.Delete(_backFile); + } +} \ No newline at end of file diff --git a/IO/NonClosableStream.cs b/IO/NonClosableStream.cs new file mode 100644 index 000000000..72c100df8 --- /dev/null +++ b/IO/NonClosableStream.cs @@ -0,0 +1,78 @@ +// /*************************************************************************** +// Aaru Data Preservation Suite +// ---------------------------------------------------------------------------- +// +// Filename : NonClosableStream.cs +// Author(s) : Natalia Portillo +// +// Component : Compression. +// +// --[ Description ] ---------------------------------------------------------- +// +// Overrides MemoryStream to ignore standard close requests. +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2023 Natalia Portillo +// ****************************************************************************/ + +using System.Diagnostics.CodeAnalysis; +using System.IO; + +namespace Aaru.Helpers.IO; + +/// +/// Creates a MemoryStream that ignores close commands +[SuppressMessage("ReSharper", "UnusedMember.Global")] +public sealed class NonClosableStream : Stream +{ + readonly Stream _baseStream; + + public NonClosableStream(byte[] buffer) => _baseStream = new MemoryStream(buffer); + + public NonClosableStream() => _baseStream = new MemoryStream(); + + public NonClosableStream(Stream stream) => _baseStream = stream; + + public override bool CanRead => _baseStream.CanRead; + public override bool CanSeek => _baseStream.CanSeek; + public override bool CanWrite => _baseStream.CanWrite; + public override long Length => _baseStream.Length; + + public override long Position + { + get => _baseStream.Position; + set => _baseStream.Position = value; + } + + public override void Flush() => _baseStream.Flush(); + + public override int Read(byte[] buffer, int offset, int count) => _baseStream.EnsureRead(buffer, offset, count); + + public override long Seek(long offset, SeekOrigin origin) => _baseStream.Seek(offset, origin); + + public override void SetLength(long value) => _baseStream.SetLength(value); + + public override void Write(byte[] buffer, int offset, int count) => _baseStream.Write(buffer, offset, count); + + public override void Close() + { + // Do nothing + } + + public void ReallyClose() => _baseStream.Close(); +} \ No newline at end of file diff --git a/IO/OffsetStream.cs b/IO/OffsetStream.cs new file mode 100644 index 000000000..809b8948e --- /dev/null +++ b/IO/OffsetStream.cs @@ -0,0 +1,680 @@ +// /*************************************************************************** +// Aaru Data Preservation Suite +// ---------------------------------------------------------------------------- +// +// Filename : OffsetStream.cs +// Author(s) : Natalia Portillo +// +// Component : Filters. +// +// --[ Description ] ---------------------------------------------------------- +// +// Provides a stream that's a subset of another stream. +// +// --[ License ] -------------------------------------------------------------- +// +// This library is free software; you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 2.1 of the +// License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2011-2023 Natalia Portillo +// ****************************************************************************/ + +using System; +using System.Diagnostics.CodeAnalysis; +using System.IO; +using Microsoft.Win32.SafeHandles; +#if !NETSTANDARD2_0 + +#endif + +namespace Aaru.Helpers.IO; + +/// Creates a stream that is a subset of another stream. +/// +[SuppressMessage("ReSharper", "UnusedMember.Global")] +public sealed class OffsetStream : Stream +{ + readonly Stream _baseStream; + readonly long _streamEnd; + readonly long _streamStart; + + /// + /// + /// Initializes a stream that only allows reading from to of the + /// specified stream, both inclusive. + /// + /// Base stream + /// Start position + /// Last readable position + /// Invalid range + public OffsetStream(Stream stream, long start, long end) + { + if(start < 0) + throw new ArgumentOutOfRangeException(nameof(start), Localization.Start_cant_be_a_negative_number); + + if(end < 0) + throw new ArgumentOutOfRangeException(nameof(end), Localization.End_cant_be_a_negative_number); + + _streamStart = start; + _streamEnd = end; + + _baseStream = stream; + + if(end > _baseStream.Length) + throw new ArgumentOutOfRangeException(nameof(end), Localization.End_is_after_stream_end); + + _baseStream.Position = start; + } + + /// + /// + /// Initializes a stream that only allows reading from to of the + /// specified file, both inclusive. + /// + /// A relative or absolute path for the file that the stream will encapsulate. + /// One of the enumeration values that determines how to open or create the file. + /// + /// A bitwise combination of the enumeration values that determines how the file can be accessed by a + /// object. + /// + /// + /// A bitwise combination of the enumeration values that determines how the file will be shared by + /// processes. + /// + /// + /// A positive Int32 value greater than 0 indicating the buffer size. The default buffer size is + /// 4096. + /// + /// A bitwise combination of the enumeration values that specifies additional file options. + /// Start position + /// Last readable position + /// Invalid range + public OffsetStream(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, + FileOptions options, long start, long end) + { + if(start < 0) + throw new ArgumentOutOfRangeException(nameof(start), Localization.Start_cant_be_a_negative_number); + + if(end < 0) + throw new ArgumentOutOfRangeException(nameof(end), Localization.End_cant_be_a_negative_number); + + _streamStart = start; + _streamEnd = end; + + _baseStream = new FileStream(path, mode, access, share, bufferSize, options); + + if(end > _baseStream.Length) + throw new ArgumentOutOfRangeException(nameof(end), Localization.End_is_after_stream_end); + + _baseStream.Position = start; + } + + /// + /// + /// Initializes a stream that only allows reading from to of the + /// specified file, both inclusive. + /// + /// A file handle for the file that the stream will encapsulate. + /// + /// A bitwise combination of the enumeration values that determines how the file can be accessed by a + /// object. + /// + /// Start position + /// Last readable position + /// Invalid range + public OffsetStream(SafeFileHandle handle, FileAccess access, long start, long end) + { + if(start < 0) + throw new ArgumentOutOfRangeException(nameof(start), Localization.Start_cant_be_a_negative_number); + + if(end < 0) + throw new ArgumentOutOfRangeException(nameof(end), Localization.End_cant_be_a_negative_number); + + _streamStart = start; + _streamEnd = end; + + _baseStream = new FileStream(handle, access); + + if(end > _baseStream.Length) + throw new ArgumentOutOfRangeException(nameof(end), Localization.End_is_after_stream_end); + + _baseStream.Position = start; + } + + /// + /// + /// Initializes a stream that only allows reading from to of the + /// specified file, both inclusive. + /// + /// A file handle for the file that the stream will encapsulate. + /// + /// A bitwise combination of the enumeration values that determines how the file can be accessed by a + /// object. + /// + /// + /// A positive Int32 value greater than 0 indicating the buffer size. The default buffer size is + /// 4096. + /// + /// Start position + /// Last readable position + /// Invalid range + public OffsetStream(SafeFileHandle handle, FileAccess access, int bufferSize, long start, long end) + { + if(start < 0) + throw new ArgumentOutOfRangeException(nameof(start), Localization.Start_cant_be_a_negative_number); + + if(end < 0) + throw new ArgumentOutOfRangeException(nameof(end), Localization.End_cant_be_a_negative_number); + + _streamStart = start; + _streamEnd = end; + + _baseStream = new FileStream(handle, access, bufferSize); + + if(end > _baseStream.Length) + throw new ArgumentOutOfRangeException(nameof(end), Localization.End_is_after_stream_end); + + _baseStream.Position = start; + } + + /// + /// + /// Initializes a stream that only allows reading from to of the + /// specified file, both inclusive. + /// + /// A file handle for the file that the stream will encapsulate. + /// + /// A bitwise combination of the enumeration values that determines how the file can be accessed by a + /// object. + /// + /// + /// A positive Int32 value greater than 0 indicating the buffer size. The default buffer size is + /// 4096. + /// + /// Specifies whether to use asynchronous I/O or synchronous I/O. + /// Start position + /// Last readable position + /// Invalid range + public OffsetStream(SafeFileHandle handle, FileAccess access, int bufferSize, bool isAsync, long start, long end) + { + if(start < 0) + throw new ArgumentOutOfRangeException(nameof(start), Localization.Start_cant_be_a_negative_number); + + if(end < 0) + throw new ArgumentOutOfRangeException(nameof(end), Localization.End_cant_be_a_negative_number); + + _streamStart = start; + _streamEnd = end; + + _baseStream = new FileStream(handle, access, bufferSize, isAsync); + + if(end > _baseStream.Length) + throw new ArgumentOutOfRangeException(nameof(end), Localization.End_is_after_stream_end); + + _baseStream.Position = start; + } + + /// + /// + /// Initializes a stream that only allows reading from to of the + /// specified file, both inclusive. + /// + /// A relative or absolute path for the file that the stream will encapsulate. + /// One of the enumeration values that determines how to open or create the file. + /// + /// A bitwise combination of the enumeration values that determines how the file can be accessed by a + /// object. + /// + /// + /// A bitwise combination of the enumeration values that determines how the file will be shared by + /// processes. + /// + /// + /// A positive Int32 value greater than 0 indicating the buffer size. The default buffer size is + /// 4096. + /// + /// Specifies whether to use asynchronous I/O or synchronous I/O. + /// Start position + /// Last readable position + /// Invalid range + public OffsetStream(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, bool useAsync, + long start, long end) + { + if(start < 0) + throw new ArgumentOutOfRangeException(nameof(start), Localization.Start_cant_be_a_negative_number); + + if(end < 0) + throw new ArgumentOutOfRangeException(nameof(end), Localization.End_cant_be_a_negative_number); + + _streamStart = start; + _streamEnd = end; + + _baseStream = new FileStream(path, mode, access, share, bufferSize, useAsync); + + if(end > _baseStream.Length) + throw new ArgumentOutOfRangeException(nameof(end), Localization.End_is_after_stream_end); + + _baseStream.Position = start; + } + + /// + /// + /// Initializes a stream that only allows reading from to of the + /// specified file, both inclusive. + /// + /// A relative or absolute path for the file that the stream will encapsulate. + /// One of the enumeration values that determines how to open or create the file. + /// + /// A bitwise combination of the enumeration values that determines how the file can be accessed by a + /// object. + /// + /// + /// A bitwise combination of the enumeration values that determines how the file will be shared by + /// processes. + /// + /// + /// A positive Int32 value greater than 0 indicating the buffer size. The default buffer size is + /// 4096. + /// + /// Start position + /// Last readable position + /// Invalid range + public OffsetStream(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, long start, + long end) + { + if(start < 0) + throw new ArgumentOutOfRangeException(nameof(start), Localization.Start_cant_be_a_negative_number); + + if(end < 0) + throw new ArgumentOutOfRangeException(nameof(end), Localization.End_cant_be_a_negative_number); + + _streamStart = start; + _streamEnd = end; + + _baseStream = new FileStream(path, mode, access, share, bufferSize); + + if(end > _baseStream.Length) + throw new ArgumentOutOfRangeException(nameof(end), Localization.End_is_after_stream_end); + + _baseStream.Position = start; + } + + /// + /// + /// Initializes a stream that only allows reading from to of the + /// specified file, both inclusive. + /// + /// A relative or absolute path for the file that the stream will encapsulate. + /// One of the enumeration values that determines how to open or create the file. + /// + /// A bitwise combination of the enumeration values that determines how the file can be accessed by a + /// object. + /// + /// + /// A bitwise combination of the enumeration values that determines how the file will be shared by + /// processes. + /// + /// Start position + /// Last readable position + /// Invalid range + public OffsetStream(string path, FileMode mode, FileAccess access, FileShare share, long start, long end) + { + if(start < 0) + throw new ArgumentOutOfRangeException(nameof(start), Localization.Start_cant_be_a_negative_number); + + if(end < 0) + throw new ArgumentOutOfRangeException(nameof(end), Localization.End_cant_be_a_negative_number); + + _streamStart = start; + _streamEnd = end; + + _baseStream = new FileStream(path, mode, access, share); + + if(end > _baseStream.Length) + throw new ArgumentOutOfRangeException(nameof(end), Localization.End_is_after_stream_end); + + _baseStream.Position = start; + } + + /// + /// + /// Initializes a stream that only allows reading from to of the + /// specified file, both inclusive. + /// + /// A relative or absolute path for the file that the stream will encapsulate. + /// One of the enumeration values that determines how to open or create the file. + /// + /// A bitwise combination of the enumeration values that determines how the file can be accessed by a + /// object. + /// + /// Start position + /// Last readable position + /// Invalid range + public OffsetStream(string path, FileMode mode, FileAccess access, long start, long end) + { + if(start < 0) + throw new ArgumentOutOfRangeException(nameof(start), Localization.Start_cant_be_a_negative_number); + + if(end < 0) + throw new ArgumentOutOfRangeException(nameof(end), Localization.End_cant_be_a_negative_number); + + _streamStart = start; + _streamEnd = end; + + _baseStream = new FileStream(path, mode, access); + + if(end > _baseStream.Length) + throw new ArgumentOutOfRangeException(nameof(end), Localization.End_is_after_stream_end); + + _baseStream.Position = start; + } + + /// + /// + /// Initializes a stream that only allows reading from to of the + /// specified file, both inclusive. + /// + /// A relative or absolute path for the file that the stream will encapsulate. + /// One of the enumeration values that determines how to open or create the file. + /// Start position + /// Last readable position + /// Invalid range + public OffsetStream(string path, FileMode mode, long start, long end) + { + if(start < 0) + throw new ArgumentOutOfRangeException(nameof(start), Localization.Start_cant_be_a_negative_number); + + if(end < 0) + throw new ArgumentOutOfRangeException(nameof(end), Localization.End_cant_be_a_negative_number); + + _streamStart = start; + _streamEnd = end; + + _baseStream = new FileStream(path, mode); + + if(end > _baseStream.Length) + throw new ArgumentOutOfRangeException(nameof(end), Localization.End_is_after_stream_end); + + _baseStream.Position = start; + } + + /// + /// + /// Initializes a stream that only allows reading from to of the + /// specified byte array, both inclusive. + /// + /// The array of unsigned bytes to add at the end of this stream. + /// The index into at which the stream begins. + /// The length in bytes to add to the end of the current stream. + /// The setting of the CanWrite property, currently ignored. + /// Currently ignored. + /// Start position + /// Last readable position + /// Invalid range + public OffsetStream(byte[] buffer, int index, int count, bool writable, bool publiclyVisible, long start, long end) + { + if(start < 0) + throw new ArgumentOutOfRangeException(nameof(start), Localization.Start_cant_be_a_negative_number); + + if(end < 0) + throw new ArgumentOutOfRangeException(nameof(end), Localization.End_cant_be_a_negative_number); + + _streamStart = start; + _streamEnd = end; + + _baseStream = new MemoryStream(buffer, index, count, writable, publiclyVisible); + + if(end > _baseStream.Length) + throw new ArgumentOutOfRangeException(nameof(end), Localization.End_is_after_stream_end); + + _baseStream.Position = start; + } + + /// + /// + /// Initializes a stream that only allows reading from to of the + /// specified byte array, both inclusive. + /// + /// The array of unsigned bytes to add at the end of this stream. + /// The index into at which the stream begins. + /// The length in bytes to add to the end of the current stream. + /// The setting of the CanWrite property, currently ignored. + /// Start position + /// Last readable position + /// Invalid range + public OffsetStream(byte[] buffer, int index, int count, bool writable, long start, long end) + { + if(start < 0) + throw new ArgumentOutOfRangeException(nameof(start), Localization.Start_cant_be_a_negative_number); + + if(end < 0) + throw new ArgumentOutOfRangeException(nameof(end), Localization.End_cant_be_a_negative_number); + + _streamStart = start; + _streamEnd = end; + + _baseStream = new MemoryStream(buffer, index, count, writable); + + if(end > _baseStream.Length) + throw new ArgumentOutOfRangeException(nameof(end), Localization.End_is_after_stream_end); + + _baseStream.Position = start; + } + + /// + /// + /// Initializes a stream that only allows reading from to of the + /// specified byte array, both inclusive. + /// + /// The array of unsigned bytes to add at the end of this stream. + /// The index into at which the stream begins. + /// The length in bytes to add to the end of the current stream. + /// Start position + /// Last readable position + /// Invalid range + public OffsetStream(byte[] buffer, int index, int count, long start, long end) + { + if(start < 0) + throw new ArgumentOutOfRangeException(nameof(start), Localization.Start_cant_be_a_negative_number); + + if(end < 0) + throw new ArgumentOutOfRangeException(nameof(end), Localization.End_cant_be_a_negative_number); + + _streamStart = start; + _streamEnd = end; + + _baseStream = new MemoryStream(buffer, index, count); + + if(end > _baseStream.Length) + throw new ArgumentOutOfRangeException(nameof(end), Localization.End_is_after_stream_end); + + _baseStream.Position = start; + } + + /// + /// + /// Initializes a stream that only allows reading from to of the + /// specified byte array, both inclusive. + /// + /// The array of unsigned bytes to add at the end of this stream. + /// The setting of the CanWrite property, currently ignored. + /// Start position + /// Last readable position + /// Invalid range + public OffsetStream(byte[] buffer, bool writable, long start, long end) + { + if(start < 0) + throw new ArgumentOutOfRangeException(nameof(start), Localization.Start_cant_be_a_negative_number); + + if(end < 0) + throw new ArgumentOutOfRangeException(nameof(end), Localization.End_cant_be_a_negative_number); + + _streamStart = start; + _streamEnd = end; + + _baseStream = new MemoryStream(buffer, writable); + + if(end > _baseStream.Length) + throw new ArgumentOutOfRangeException(nameof(end), Localization.End_is_after_stream_end); + + _baseStream.Position = start; + } + + /// + /// + /// Initializes a stream that only allows reading from to of the + /// specified byte array, both inclusive. + /// + /// The array of unsigned bytes to add at the end of this stream. + /// Start position + /// Last readable position + /// Invalid range + public OffsetStream(byte[] buffer, long start, long end) + { + if(start < 0) + throw new ArgumentOutOfRangeException(nameof(start), Localization.Start_cant_be_a_negative_number); + + if(end < 0) + throw new ArgumentOutOfRangeException(nameof(end), Localization.End_cant_be_a_negative_number); + + _streamStart = start; + _streamEnd = end; + + _baseStream = new MemoryStream(buffer); + + if(end > _baseStream.Length) + throw new ArgumentOutOfRangeException(nameof(end), Localization.End_is_after_stream_end); + + _baseStream.Position = start; + } + + /// + public override bool CanRead => _baseStream.CanRead; + + /// + public override bool CanSeek => _baseStream.CanSeek; + + /// + public override bool CanWrite => _baseStream.CanWrite; + + /// + public override long Length => _streamEnd - _streamStart + 1; + + /// + public override long Position + { + get => _baseStream.Position - _streamStart; + + set + { + if(value + _streamStart > _streamEnd) + throw new IOException(Localization.Cannot_set_position_past_stream_end); + + _baseStream.Position = value + _streamStart; + } + } + + ~OffsetStream() + { + _baseStream.Close(); + _baseStream.Dispose(); + } + + /// + public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) + { + if(_baseStream.Position + count > _streamEnd) + throw new IOException(Localization.Cannot_read_past_stream_end); + + return _baseStream.BeginRead(buffer, offset, count, callback, state); + } + + /// + public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) + { + if(_baseStream.Position + count > _streamEnd) + throw new IOException(Localization.Cannot_write_past_stream_end); + + return _baseStream.BeginWrite(buffer, offset, count, callback, state); + } + + /// + public override void Close() => _baseStream.Close(); + + /// + public override int EndRead(IAsyncResult asyncResult) => _baseStream.EndRead(asyncResult); + + /// + public override void EndWrite(IAsyncResult asyncResult) => _baseStream.EndWrite(asyncResult); + + /// + public override int ReadByte() => _baseStream.Position == _streamEnd + 1 ? -1 : _baseStream.ReadByte(); + + /// + public override void WriteByte(byte value) + { + if(_baseStream.Position + 1 > _streamEnd) + throw new IOException(Localization.Cannot_write_past_stream_end); + + _baseStream.WriteByte(value); + } + + /// + public override void Flush() => _baseStream.Flush(); + + /// + public override int Read(byte[] buffer, int offset, int count) + { + if(_baseStream.Position + count > _streamEnd + 1) + throw new IOException(Localization.Cannot_read_past_stream_end); + + return _baseStream.EnsureRead(buffer, offset, count); + } + + /// + public override long Seek(long offset, SeekOrigin origin) + { + switch(origin) + { + case SeekOrigin.Begin: + if(offset + _streamStart > _streamEnd) + throw new IOException(Localization.Cannot_seek_after_stream_end); + + return _baseStream.Seek(offset + _streamStart, SeekOrigin.Begin) - _streamStart; + case SeekOrigin.End: + if(offset - (_baseStream.Length - _streamEnd) < _streamStart) + throw new IOException(Localization.Cannot_seek_before_stream_start); + + return _baseStream.Seek(offset - (_baseStream.Length - _streamEnd), SeekOrigin.End) - _streamStart; + default: + if(offset + _baseStream.Position > _streamEnd) + throw new IOException(Localization.Cannot_seek_after_stream_end); + + return _baseStream.Seek(offset, SeekOrigin.Current) - _streamStart; + } + } + + /// + public override void SetLength(long value) => + throw new NotSupportedException(Localization.Growing_OffsetStream_is_not_supported); + + /// + public override void Write(byte[] buffer, int offset, int count) + { + if(_baseStream.Position + count > _streamEnd) + throw new IOException(Localization.Cannot_write_past_stream_end); + + _baseStream.Write(buffer, offset, count); + } +} \ No newline at end of file diff --git a/IO/SplitJoinStream.cs b/IO/SplitJoinStream.cs new file mode 100644 index 000000000..34981ec06 --- /dev/null +++ b/IO/SplitJoinStream.cs @@ -0,0 +1,372 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Diagnostics.CodeAnalysis; +using System.IO; +using System.Linq; +using Microsoft.Win32.SafeHandles; + +namespace Aaru.Helpers.IO; + +/// +/// Implements a stream that joins two or more files (sequentially) as a single stream +[SuppressMessage("ReSharper", "UnusedMember.Global")] +public class SplitJoinStream : Stream +{ + readonly Dictionary _baseStreams; + long _position; + long _streamLength; + + /// + public SplitJoinStream() + { + _baseStreams = new Dictionary(); + _streamLength = 0; + _position = 0; + } + + /// + public override bool CanRead => true; + + /// + public override bool CanSeek => true; + + /// + public override bool CanWrite => false; + + /// + public override long Length => _streamLength; + + /// + public override long Position + { + get => _position; + + set + { + if(value >= _streamLength) + throw new IOException(Localization.Cannot_set_position_past_stream_end); + + _position = value; + } + } + + /// Adds a stream at the end of the current stream + /// Stream to add + /// The specified stream is non-readable or non-seekable + public void Add(Stream stream) + { + if(!stream.CanSeek) + throw new ArgumentException(Localization.Non_seekable_streams_are_not_supported); + + if(!stream.CanRead) + throw new ArgumentException(Localization.Non_readable_streams_are_not_supported); + + _baseStreams[_streamLength] = stream; + _streamLength += stream.Length; + } + + /// Adds the specified file to the end of the current stream + /// A relative or absolute path for the file that the stream will encapsulate. + /// One of the enumeration values that determines how to open or create the file. + /// + /// A bitwise combination of the enumeration values that determines how the file can be accessed by a + /// object. + /// + /// + /// A bitwise combination of the enumeration values that determines how the file will be shared by + /// processes. + /// + /// + /// A positive Int32 value greater than 0 indicating the buffer size. The default buffer size is + /// 4096. + /// + /// A bitwise combination of the enumeration values that specifies additional file options. + public void Add(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, + FileOptions options) => Add(new FileStream(path, mode, access, share, bufferSize, options)); + + /// Adds the specified file to the end of the current stream + /// A file handle for the file that the stream will encapsulate. + /// + /// A bitwise combination of the enumeration values that determines how the file can be accessed by a + /// object. + /// + public void Add(SafeFileHandle handle, FileAccess access) => Add(new FileStream(handle, access)); + + /// Adds the specified file to the end of the current stream + /// A file handle for the file that the stream will encapsulate. + /// + /// A bitwise combination of the enumeration values that determines how the file can be accessed by a + /// object. + /// + /// + /// A positive Int32 value greater than 0 indicating the buffer size. The default buffer size is + /// 4096. + /// + public void Add(SafeFileHandle handle, FileAccess access, int bufferSize) => + Add(new FileStream(handle, access, bufferSize)); + + /// Adds the specified file to the end of the current stream + /// A file handle for the file that the stream will encapsulate. + /// + /// A bitwise combination of the enumeration values that determines how the file can be accessed by a + /// object. + /// + /// + /// A positive Int32 value greater than 0 indicating the buffer size. The default buffer size is + /// 4096. + /// + /// Specifies whether to use asynchronous I/O or synchronous I/O. + public void Add(SafeFileHandle handle, FileAccess access, int bufferSize, bool isAsync) => + Add(new FileStream(handle, access, bufferSize, isAsync)); + + /// Adds the specified file to the end of the current stream + /// A relative or absolute path for the file that the stream will encapsulate. + /// One of the enumeration values that determines how to open or create the file. + /// + /// A bitwise combination of the enumeration values that determines how the file can be accessed by a + /// object. + /// + /// + /// A bitwise combination of the enumeration values that determines how the file will be shared by + /// processes. + /// + /// + /// A positive Int32 value greater than 0 indicating the buffer size. The default buffer size is + /// 4096. + /// + /// Specifies whether to use asynchronous I/O or synchronous I/O. + public void Add(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, bool useAsync) => + Add(new FileStream(path, mode, access, share, bufferSize, useAsync)); + + /// Adds the specified file to the end of the current stream + /// A relative or absolute path for the file that the stream will encapsulate. + /// One of the enumeration values that determines how to open or create the file. + /// + /// A bitwise combination of the enumeration values that determines how the file can be accessed by a + /// object. + /// + /// + /// A bitwise combination of the enumeration values that determines how the file will be shared by + /// processes. + /// + /// + /// A positive Int32 value greater than 0 indicating the buffer size. The default buffer size is + /// 4096. + /// + public void Add(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize) => + Add(new FileStream(path, mode, access, share, bufferSize)); + + /// Adds the specified file to the end of the current stream + /// A relative or absolute path for the file that the stream will encapsulate. + /// One of the enumeration values that determines how to open or create the file. + /// + /// A bitwise combination of the enumeration values that determines how the file can be accessed by a + /// object. + /// + /// + /// A bitwise combination of the enumeration values that determines how the file will be shared by + /// processes. + /// + public void Add(string path, FileMode mode, FileAccess access, FileShare share) => + Add(new FileStream(path, mode, access, share)); + + /// Adds the specified file to the end of the current stream + /// A relative or absolute path for the file that the stream will encapsulate. + /// One of the enumeration values that determines how to open or create the file. + /// + /// A bitwise combination of the enumeration values that determines how the file can be accessed by a + /// object. + /// + public void Add(string path, FileMode mode, FileAccess access) => Add(new FileStream(path, mode, access)); + + /// Adds the specified file to the end of the current stream + /// A relative or absolute path for the file that the stream will encapsulate. + /// One of the enumeration values that determines how to open or create the file. + public void Add(string path, FileMode mode) => Add(new FileStream(path, mode)); + + /// Adds the specified byte array to the end of the current stream + /// The array of unsigned bytes to add at the end of this stream. + /// The index into at which the stream begins. + /// The length in bytes to add to the end of the current stream. + /// The setting of the CanWrite property, currently ignored. + /// Currently ignored. + public void Add(byte[] buffer, int index, int count, bool writable, bool publiclyVisible) => + Add(new MemoryStream(buffer, index, count, writable, publiclyVisible)); + + /// Adds the specified byte array to the end of the current stream + /// The array of unsigned bytes to add at the end of this stream. + /// The index into at which the stream begins. + /// The length in bytes to add to the end of the current stream. + /// The setting of the CanWrite property, currently ignored. + public void Add(byte[] buffer, int index, int count, bool writable) => + Add(new MemoryStream(buffer, index, count, writable)); + + /// Adds the specified byte array to the end of the current stream + /// The array of unsigned bytes to add at the end of this stream. + /// The index into at which the stream begins. + /// The length in bytes to add to the end of the current stream. + public void Add(byte[] buffer, int index, int count) => Add(new MemoryStream(buffer, index, count)); + + /// Adds the specified byte array to the end of the current stream + /// The array of unsigned bytes to add at the end of this stream. + /// The setting of the CanWrite property, currently ignored. + public void Add(byte[] buffer, bool writable) => Add(new MemoryStream(buffer, writable)); + + /// Adds the specified byte array to the end of the current stream + /// The array of unsigned bytes to add at the end of this stream. + public void Add(byte[] buffer) => Add(new MemoryStream(buffer)); + + /// Adds a range of files to the end of the current stream, alphabetically sorted + /// Base file path, directory path only + /// Counter format, includes filename and a formatting string + /// Counter start, defaults to 0 + /// + /// A bitwise combination of the enumeration values that determines how the file can be accessed by a + /// object. + /// + public void AddRange(string basePath, string counterFormat = "{0:D3}", int counterStart = 0, + FileAccess access = FileAccess.Read) + { + while(true) + { + string filePath = Path.Combine(basePath, string.Format(counterFormat, counterStart)); + + if(!File.Exists(filePath)) + break; + + Add(filePath, FileMode.Open, access); + + counterStart++; + } + } + + ~SplitJoinStream() + { + foreach(Stream stream in _baseStreams.Values) + { + stream.Close(); + stream.Dispose(); + } + + _baseStreams.Clear(); + _position = 0; + } + + /// + public override IAsyncResult + BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) => + throw new NotSupportedException(Localization.Asynchronous_IO_is_not_supported); + + /// + public override IAsyncResult + BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) => + throw new NotSupportedException(Localization.Asynchronous_IO_is_not_supported); + + /// + public override void Close() + { + foreach(Stream stream in _baseStreams.Values) + stream.Close(); + + _baseStreams.Clear(); + _position = 0; + } + + /// + public override int EndRead(IAsyncResult asyncResult) => + throw new NotSupportedException(Localization.Asynchronous_IO_is_not_supported); + + /// + public override void EndWrite(IAsyncResult asyncResult) => + throw new NotSupportedException(Localization.Asynchronous_IO_is_not_supported); + + /// + public override int ReadByte() + { + if(_position >= _streamLength) + return -1; + + KeyValuePair baseStream = _baseStreams.FirstOrDefault(s => s.Key >= _position); + + if(baseStream.Value == null) + return -1; + + baseStream.Value.Position = _position - baseStream.Key; + _position++; + + return baseStream.Value.ReadByte(); + } + + /// + public override void WriteByte(byte value) => throw new ReadOnlyException(Localization.This_stream_is_read_only); + + /// + public override void Flush() {} + + /// + public override int Read(byte[] buffer, int offset, int count) + { + var read = 0; + + while(count > 0) + { + KeyValuePair baseStream = _baseStreams.LastOrDefault(s => s.Key <= _position); + + if(baseStream.Value == null) + break; + + baseStream.Value.Position = _position - baseStream.Key; + + int currentCount = count; + + if(baseStream.Value.Position + currentCount > baseStream.Value.Length) + currentCount = (int)(baseStream.Value.Length - baseStream.Value.Position); + + read += baseStream.Value.Read(buffer, offset, currentCount); + + count -= currentCount; + offset += currentCount; + } + + return read; + } + + /// + public override long Seek(long offset, SeekOrigin origin) + { + switch(origin) + { + case SeekOrigin.Begin: + if(offset >= _streamLength) + throw new IOException(Localization.Cannot_seek_after_stream_end); + + _position = offset; + + break; + case SeekOrigin.End: + if(_position - offset < 0) + throw new IOException(Localization.Cannot_seek_before_stream_start); + + _position -= offset; + + break; + default: + if(_position + offset >= _streamLength) + throw new IOException(Localization.Cannot_seek_after_stream_end); + + _position += offset; + + break; + } + + return _position; + } + + /// + public override void SetLength(long value) => throw new ReadOnlyException(Localization.This_stream_is_read_only); + + /// + public override void Write(byte[] buffer, int offset, int count) => + throw new ReadOnlyException(Localization.This_stream_is_read_only); +} \ No newline at end of file diff --git a/Localization/Localization.Designer.cs b/Localization/Localization.Designer.cs index a07e3a819..36a0e6131 100644 --- a/Localization/Localization.Designer.cs +++ b/Localization/Localization.Designer.cs @@ -59,6 +59,87 @@ internal Localization() { } } + /// + /// Looks up a localized string similar to Asynchronous I/O is not supported.. + /// + internal static string Asynchronous_IO_is_not_supported { + get { + return ResourceManager.GetString("Asynchronous_IO_is_not_supported", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Cannot read past stream end.. + /// + internal static string Cannot_read_past_stream_end { + get { + return ResourceManager.GetString("Cannot_read_past_stream_end", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Cannot seek after stream end.. + /// + internal static string Cannot_seek_after_stream_end { + get { + return ResourceManager.GetString("Cannot_seek_after_stream_end", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Cannot seek before stream start.. + /// + internal static string Cannot_seek_before_stream_start { + get { + return ResourceManager.GetString("Cannot_seek_before_stream_start", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Cannot set position past stream end.. + /// + internal static string Cannot_set_position_past_stream_end { + get { + return ResourceManager.GetString("Cannot_set_position_past_stream_end", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Cannot write past stream end.. + /// + internal static string Cannot_write_past_stream_end { + get { + return ResourceManager.GetString("Cannot_write_past_stream_end", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to End can't be a negative number.. + /// + internal static string End_cant_be_a_negative_number { + get { + return ResourceManager.GetString("End_cant_be_a_negative_number", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to End is after stream end.. + /// + internal static string End_is_after_stream_end { + get { + return ResourceManager.GetString("End_is_after_stream_end", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Growing OffsetStream is not supported.. + /// + internal static string Growing_OffsetStream_is_not_supported { + get { + return ResourceManager.GetString("Growing_OffsetStream_is_not_supported", resourceCulture); + } + } + /// /// Looks up a localized string similar to Length of value array must not be more than length of destination. /// @@ -68,6 +149,24 @@ internal static string Length_of_value_array_must_not_be_more_than_length_of_des } } + /// + /// Looks up a localized string similar to Non-readable streams are not supported. + /// + internal static string Non_readable_streams_are_not_supported { + get { + return ResourceManager.GetString("Non_readable_streams_are_not_supported", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Non-seekable streams are not supported. + /// + internal static string Non_seekable_streams_are_not_supported { + get { + return ResourceManager.GetString("Non_seekable_streams_are_not_supported", resourceCulture); + } + } + /// /// Looks up a localized string similar to Offset. /// @@ -76,5 +175,23 @@ internal static string Offset { return ResourceManager.GetString("Offset", resourceCulture); } } + + /// + /// Looks up a localized string similar to Start can't be a negative number.. + /// + internal static string Start_cant_be_a_negative_number { + get { + return ResourceManager.GetString("Start_cant_be_a_negative_number", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to This stream is read-only. + /// + internal static string This_stream_is_read_only { + get { + return ResourceManager.GetString("This_stream_is_read_only", resourceCulture); + } + } } } diff --git a/Localization/Localization.es.resx b/Localization/Localization.es.resx index 15b6f7ebd..9ed14ff70 100644 --- a/Localization/Localization.es.resx +++ b/Localization/Localization.es.resx @@ -22,4 +22,43 @@ La longitud de una colección no puede ser mayor que la longitud del destino + + Las secuencias no legíbles no están soportadas. + + + Las secuencias no posicionables no están soportadas. + + + No se puede leer más allá del final de la secuencia. + + + No se puede posicionar después del final de la secuencia. + + + No se puede posicionar antes del comienzo de la secuencia. + + + No se puede establecer la posición más allá del final de la secuencia. + + + No se puede escribir después del final de la secuencia. + + + El final no puede ser un número negativo. + + + El final está después del final de la secuencia. + + + No se puede agrandar un OffsetStream. + + + E/S asíncrona no soportada. + + + El comienzo no puede ser un número negativo. + + + Esta secuencia es de sólo lectura. + \ No newline at end of file diff --git a/Localization/Localization.resx b/Localization/Localization.resx index 7ec00abdd..6f9a16a67 100644 --- a/Localization/Localization.resx +++ b/Localization/Localization.resx @@ -29,4 +29,43 @@ Offset + + Start can't be a negative number. + + + End can't be a negative number. + + + End is after stream end. + + + Cannot set position past stream end. + + + Cannot read past stream end. + + + Cannot write past stream end. + + + Growing OffsetStream is not supported. + + + Cannot seek before stream start. + + + Cannot seek after stream end. + + + Non-seekable streams are not supported + + + Non-readable streams are not supported + + + Asynchronous I/O is not supported. + + + This stream is read-only + \ No newline at end of file From 934b86c79f3e21bee1d7c853997bad820e4e6fc3 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 8 Oct 2023 16:48:56 +0100 Subject: [PATCH 216/217] [OffsetStream] Do not raise an exception if trying to read past stream end, just return partial data. --- IO/OffsetStream.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/IO/OffsetStream.cs b/IO/OffsetStream.cs index 809b8948e..07fa54a2e 100644 --- a/IO/OffsetStream.cs +++ b/IO/OffsetStream.cs @@ -595,7 +595,7 @@ public override long Position public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { if(_baseStream.Position + count > _streamEnd) - throw new IOException(Localization.Cannot_read_past_stream_end); + count = (int)(_streamEnd - _baseStream.Position); return _baseStream.BeginRead(buffer, offset, count, callback, state); } @@ -637,7 +637,7 @@ public override void WriteByte(byte value) public override int Read(byte[] buffer, int offset, int count) { if(_baseStream.Position + count > _streamEnd + 1) - throw new IOException(Localization.Cannot_read_past_stream_end); + count = (int)(_streamEnd - _baseStream.Position); return _baseStream.EnsureRead(buffer, offset, count); } From 22fc5539710b8c0c1c65b636a3c413fe6f8fbcc6 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 19 Dec 2023 13:18:14 +0000 Subject: [PATCH 217/217] Move all files into project subdirectory --- .editorconfig => Aaru.Helpers/.editorconfig | 0 .gitignore => Aaru.Helpers/.gitignore | 0 Aaru.Helpers.csproj => Aaru.Helpers/Aaru.Helpers.csproj | 0 .../Aaru.Helpers.csproj.DotSettings | 0 ArrayFill.cs => Aaru.Helpers/ArrayFill.cs | 0 ArrayIsEmpty.cs => Aaru.Helpers/ArrayIsEmpty.cs | 0 BigEndianBitConverter.cs => Aaru.Helpers/BigEndianBitConverter.cs | 0 BitEndian.cs => Aaru.Helpers/BitEndian.cs | 0 CHS.cs => Aaru.Helpers/CHS.cs | 0 CompareBytes.cs => Aaru.Helpers/CompareBytes.cs | 0 CountBits.cs => Aaru.Helpers/CountBits.cs | 0 DateHandlers.cs => Aaru.Helpers/DateHandlers.cs | 0 Extensions.cs => Aaru.Helpers/Extensions.cs | 0 {IO => Aaru.Helpers/IO}/ForcedSeekStream.cs | 0 {IO => Aaru.Helpers/IO}/NonClosableStream.cs | 0 {IO => Aaru.Helpers/IO}/OffsetStream.cs | 0 {IO => Aaru.Helpers/IO}/SplitJoinStream.cs | 0 .../Localization}/Localization.Designer.cs | 0 {Localization => Aaru.Helpers/Localization}/Localization.es.resx | 0 {Localization => Aaru.Helpers/Localization}/Localization.resx | 0 Marshal.cs => Aaru.Helpers/Marshal.cs | 0 .../MarshallingPropertiesAttribute.cs | 0 PrintHex.cs => Aaru.Helpers/PrintHex.cs | 0 StringHandlers.cs => Aaru.Helpers/StringHandlers.cs | 0 Swapping.cs => Aaru.Helpers/Swapping.cs | 0 25 files changed, 0 insertions(+), 0 deletions(-) rename .editorconfig => Aaru.Helpers/.editorconfig (100%) rename .gitignore => Aaru.Helpers/.gitignore (100%) rename Aaru.Helpers.csproj => Aaru.Helpers/Aaru.Helpers.csproj (100%) rename Aaru.Helpers.csproj.DotSettings => Aaru.Helpers/Aaru.Helpers.csproj.DotSettings (100%) rename ArrayFill.cs => Aaru.Helpers/ArrayFill.cs (100%) rename ArrayIsEmpty.cs => Aaru.Helpers/ArrayIsEmpty.cs (100%) rename BigEndianBitConverter.cs => Aaru.Helpers/BigEndianBitConverter.cs (100%) rename BitEndian.cs => Aaru.Helpers/BitEndian.cs (100%) rename CHS.cs => Aaru.Helpers/CHS.cs (100%) rename CompareBytes.cs => Aaru.Helpers/CompareBytes.cs (100%) rename CountBits.cs => Aaru.Helpers/CountBits.cs (100%) rename DateHandlers.cs => Aaru.Helpers/DateHandlers.cs (100%) rename Extensions.cs => Aaru.Helpers/Extensions.cs (100%) rename {IO => Aaru.Helpers/IO}/ForcedSeekStream.cs (100%) rename {IO => Aaru.Helpers/IO}/NonClosableStream.cs (100%) rename {IO => Aaru.Helpers/IO}/OffsetStream.cs (100%) rename {IO => Aaru.Helpers/IO}/SplitJoinStream.cs (100%) rename {Localization => Aaru.Helpers/Localization}/Localization.Designer.cs (100%) rename {Localization => Aaru.Helpers/Localization}/Localization.es.resx (100%) rename {Localization => Aaru.Helpers/Localization}/Localization.resx (100%) rename Marshal.cs => Aaru.Helpers/Marshal.cs (100%) rename MarshallingPropertiesAttribute.cs => Aaru.Helpers/MarshallingPropertiesAttribute.cs (100%) rename PrintHex.cs => Aaru.Helpers/PrintHex.cs (100%) rename StringHandlers.cs => Aaru.Helpers/StringHandlers.cs (100%) rename Swapping.cs => Aaru.Helpers/Swapping.cs (100%) diff --git a/.editorconfig b/Aaru.Helpers/.editorconfig similarity index 100% rename from .editorconfig rename to Aaru.Helpers/.editorconfig diff --git a/.gitignore b/Aaru.Helpers/.gitignore similarity index 100% rename from .gitignore rename to Aaru.Helpers/.gitignore diff --git a/Aaru.Helpers.csproj b/Aaru.Helpers/Aaru.Helpers.csproj similarity index 100% rename from Aaru.Helpers.csproj rename to Aaru.Helpers/Aaru.Helpers.csproj diff --git a/Aaru.Helpers.csproj.DotSettings b/Aaru.Helpers/Aaru.Helpers.csproj.DotSettings similarity index 100% rename from Aaru.Helpers.csproj.DotSettings rename to Aaru.Helpers/Aaru.Helpers.csproj.DotSettings diff --git a/ArrayFill.cs b/Aaru.Helpers/ArrayFill.cs similarity index 100% rename from ArrayFill.cs rename to Aaru.Helpers/ArrayFill.cs diff --git a/ArrayIsEmpty.cs b/Aaru.Helpers/ArrayIsEmpty.cs similarity index 100% rename from ArrayIsEmpty.cs rename to Aaru.Helpers/ArrayIsEmpty.cs diff --git a/BigEndianBitConverter.cs b/Aaru.Helpers/BigEndianBitConverter.cs similarity index 100% rename from BigEndianBitConverter.cs rename to Aaru.Helpers/BigEndianBitConverter.cs diff --git a/BitEndian.cs b/Aaru.Helpers/BitEndian.cs similarity index 100% rename from BitEndian.cs rename to Aaru.Helpers/BitEndian.cs diff --git a/CHS.cs b/Aaru.Helpers/CHS.cs similarity index 100% rename from CHS.cs rename to Aaru.Helpers/CHS.cs diff --git a/CompareBytes.cs b/Aaru.Helpers/CompareBytes.cs similarity index 100% rename from CompareBytes.cs rename to Aaru.Helpers/CompareBytes.cs diff --git a/CountBits.cs b/Aaru.Helpers/CountBits.cs similarity index 100% rename from CountBits.cs rename to Aaru.Helpers/CountBits.cs diff --git a/DateHandlers.cs b/Aaru.Helpers/DateHandlers.cs similarity index 100% rename from DateHandlers.cs rename to Aaru.Helpers/DateHandlers.cs diff --git a/Extensions.cs b/Aaru.Helpers/Extensions.cs similarity index 100% rename from Extensions.cs rename to Aaru.Helpers/Extensions.cs diff --git a/IO/ForcedSeekStream.cs b/Aaru.Helpers/IO/ForcedSeekStream.cs similarity index 100% rename from IO/ForcedSeekStream.cs rename to Aaru.Helpers/IO/ForcedSeekStream.cs diff --git a/IO/NonClosableStream.cs b/Aaru.Helpers/IO/NonClosableStream.cs similarity index 100% rename from IO/NonClosableStream.cs rename to Aaru.Helpers/IO/NonClosableStream.cs diff --git a/IO/OffsetStream.cs b/Aaru.Helpers/IO/OffsetStream.cs similarity index 100% rename from IO/OffsetStream.cs rename to Aaru.Helpers/IO/OffsetStream.cs diff --git a/IO/SplitJoinStream.cs b/Aaru.Helpers/IO/SplitJoinStream.cs similarity index 100% rename from IO/SplitJoinStream.cs rename to Aaru.Helpers/IO/SplitJoinStream.cs diff --git a/Localization/Localization.Designer.cs b/Aaru.Helpers/Localization/Localization.Designer.cs similarity index 100% rename from Localization/Localization.Designer.cs rename to Aaru.Helpers/Localization/Localization.Designer.cs diff --git a/Localization/Localization.es.resx b/Aaru.Helpers/Localization/Localization.es.resx similarity index 100% rename from Localization/Localization.es.resx rename to Aaru.Helpers/Localization/Localization.es.resx diff --git a/Localization/Localization.resx b/Aaru.Helpers/Localization/Localization.resx similarity index 100% rename from Localization/Localization.resx rename to Aaru.Helpers/Localization/Localization.resx diff --git a/Marshal.cs b/Aaru.Helpers/Marshal.cs similarity index 100% rename from Marshal.cs rename to Aaru.Helpers/Marshal.cs diff --git a/MarshallingPropertiesAttribute.cs b/Aaru.Helpers/MarshallingPropertiesAttribute.cs similarity index 100% rename from MarshallingPropertiesAttribute.cs rename to Aaru.Helpers/MarshallingPropertiesAttribute.cs diff --git a/PrintHex.cs b/Aaru.Helpers/PrintHex.cs similarity index 100% rename from PrintHex.cs rename to Aaru.Helpers/PrintHex.cs diff --git a/StringHandlers.cs b/Aaru.Helpers/StringHandlers.cs similarity index 100% rename from StringHandlers.cs rename to Aaru.Helpers/StringHandlers.cs diff --git a/Swapping.cs b/Aaru.Helpers/Swapping.cs similarity index 100% rename from Swapping.cs rename to Aaru.Helpers/Swapping.cs