diff --git a/ArrayFill.cs b/ArrayFill.cs index 436825b88..7c6be86cb 100644 --- a/ArrayFill.cs +++ b/ArrayFill.cs @@ -33,14 +33,14 @@ namespace DiscImageChef 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 @@ namespace DiscImageChef /// 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 @@ namespace DiscImageChef /// 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 @@ namespace DiscImageChef /// 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 @@ namespace DiscImageChef /// 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 @@ namespace DiscImageChef /// 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 @@ namespace DiscImageChef /// 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 @@ namespace DiscImageChef /// 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 @@ namespace DiscImageChef 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 @@ namespace DiscImageChef 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 @@ namespace DiscImageChef } // 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 +// /*************************************************************************** +// 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 +// ****************************************************************************/ -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; 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 @@ namespace DiscImageChef 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); }