Refactor and code cleanup.

This commit is contained in:
2016-07-28 22:25:26 +01:00
parent c93d469da9
commit a63ba13b6b
199 changed files with 3614 additions and 3744 deletions

View File

@@ -30,44 +30,6 @@
// Copyright © 2011-2016 Natalia Portillo
// ****************************************************************************/
// /***************************************************************************
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// Filename : Ata28.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 <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright (C) 2011-2015 Claunia.com
// ****************************************************************************/
// //$Id$
using System;
using DiscImageChef.Console;
using DiscImageChef.Decoders.ATA;

View File

@@ -30,44 +30,6 @@
// Copyright © 2011-2016 Natalia Portillo
// ****************************************************************************/
// /***************************************************************************
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// Filename : Ata48.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 <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright (C) 2011-2015 Claunia.com
// ****************************************************************************/
// //$Id$
using System;
using DiscImageChef.Console;
using DiscImageChef.Decoders.ATA;

View File

@@ -30,44 +30,6 @@
// Copyright © 2011-2016 Natalia Portillo
// ****************************************************************************/
// /***************************************************************************
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// Filename : AtaCommands.cs
// Version : 1.0
// Author(s) : Natalia Portillo
//
// Component : Direct device access
//
// Revision : $Revision$
// Last change by : $Author$
// Date : $Date$
//
// --[ Description ] ----------------------------------------------------------
//
// Contains ATA commands
//
// --[ 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 <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright (C) 2011-2015 Claunia.com
// ****************************************************************************/
// //$Id$
using System;
using DiscImageChef.Console;
using DiscImageChef.Decoders.ATA;

View File

@@ -30,44 +30,6 @@
// Copyright © 2011-2016 Natalia Portillo
// ****************************************************************************/
// /***************************************************************************
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// Filename : AtapiCommands.cs
// Version : 1.0
// Author(s) : Natalia Portillo
//
// Component : Direct device access
//
// Revision : $Revision$
// Last change by : $Author$
// Date : $Date$
//
// --[ Description ] ----------------------------------------------------------
//
// Contains ATAPI commands
//
// --[ 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 <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright (C) 2011-2015 Claunia.com
// ****************************************************************************/
// //$Id$
using System;
using DiscImageChef.Console;
using DiscImageChef.Decoders.ATA;

View File

@@ -30,44 +30,6 @@
// Copyright © 2011-2016 Natalia Portillo
// ****************************************************************************/
// /***************************************************************************
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// Filename : Cfa.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 <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright (C) 2011-2015 Claunia.com
// ****************************************************************************/
// //$Id$
using System;
using DiscImageChef.Console;
using DiscImageChef.Decoders.ATA;

View File

@@ -30,44 +30,6 @@
// Copyright © 2011-2016 Natalia Portillo
// ****************************************************************************/
// /***************************************************************************
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// Filename : MCPT.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 <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright (C) 2011-2015 Claunia.com
// ****************************************************************************/
// //$Id$
using System;
using DiscImageChef.Console;
using DiscImageChef.Decoders.ATA;

View File

@@ -30,44 +30,6 @@
// Copyright © 2011-2016 Natalia Portillo
// ****************************************************************************/
// /***************************************************************************
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// Filename : Smart.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 <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright (C) 2011-2015 Claunia.com
// ****************************************************************************/
// //$Id$
using System;
using DiscImageChef.Console;
using DiscImageChef.Decoders.ATA;

View File

@@ -30,7 +30,6 @@
// Copyright © 2011-2016 Natalia Portillo
// ****************************************************************************/
using System;
using DiscImageChef.Decoders.ATA;
namespace DiscImageChef.Devices

View File

@@ -66,7 +66,6 @@ namespace DiscImageChef.Devices
lastError = Marshal.GetLastWin32Error();
}
//throw new NotImplementedException();
break;
}
case Interop.PlatformID.Linux:
@@ -79,15 +78,14 @@ namespace DiscImageChef.Devices
lastError = Marshal.GetLastWin32Error();
}
//throw new NotImplementedException();
break;
}
default:
throw new InvalidOperationException(String.Format("Platform {0} not yet supported.", platformID));
throw new InvalidOperationException(string.Format("Platform {0} not yet supported.", platformID));
}
if(error)
throw new SystemException(String.Format("Error {0} opening device.", lastError));
throw new SystemException(string.Format("Error {0} opening device.", lastError));
type = DeviceType.Unknown;
scsiType = Decoders.SCSI.PeripheralDeviceTypes.UnknownDevice;
@@ -101,12 +99,12 @@ namespace DiscImageChef.Devices
bool scsiSense = ScsiInquiry(out inqBuf, out senseBuf);
if(error)
throw new SystemException(String.Format("Error {0} trying device.", lastError));
throw new SystemException(string.Format("Error {0} trying device.", lastError));
#region USB
if(platformID == DiscImageChef.Interop.PlatformID.Linux)
if(platformID == Interop.PlatformID.Linux)
{
if(devicePath.StartsWith("/dev/sd") || devicePath.StartsWith("/dev/sr") || devicePath.StartsWith("/dev/st"))
if(devicePath.StartsWith("/dev/sd", StringComparison.Ordinal) || devicePath.StartsWith("/dev/sr", StringComparison.Ordinal) || devicePath.StartsWith("/dev/st", StringComparison.Ordinal))
{
string devPath = devicePath.Substring(5);
if(System.IO.Directory.Exists("/sys/block/" + devPath))
@@ -178,9 +176,9 @@ namespace DiscImageChef.Devices
#endregion USB
#region FireWire
if(platformID == DiscImageChef.Interop.PlatformID.Linux)
if(platformID == Interop.PlatformID.Linux)
{
if(devicePath.StartsWith("/dev/sd") || devicePath.StartsWith("/dev/sr") || devicePath.StartsWith("/dev/st"))
if(devicePath.StartsWith("/dev/sd", StringComparison.Ordinal) || devicePath.StartsWith("/dev/sr", StringComparison.Ordinal) || devicePath.StartsWith("/dev/st", StringComparison.Ordinal))
{
string devPath = devicePath.Substring(5);
if(System.IO.Directory.Exists("/sys/block/" + devPath))
@@ -331,7 +329,7 @@ namespace DiscImageChef.Devices
{
foreach(char c in serial)
{
if(Char.IsControl(c))
if(char.IsControl(c))
serial = usbSerialString;
}
}
@@ -344,13 +342,13 @@ namespace DiscImageChef.Devices
if(string.IsNullOrEmpty(model))
model = firewireModelName;
if(string.IsNullOrEmpty(serial))
serial = String.Format("{0:X16}", firewireGuid);
serial = string.Format("{0:X16}", firewireGuid);
else
{
foreach(char c in serial)
{
if(Char.IsControl(c))
serial = String.Format("{0:X16}", firewireGuid);
if(char.IsControl(c))
serial = string.Format("{0:X16}", firewireGuid);
}
}
}

View File

@@ -30,7 +30,6 @@
// Copyright © 2011-2016 Natalia Portillo
// ****************************************************************************/
using System;
using Microsoft.Win32.SafeHandles;
namespace DiscImageChef.Devices
@@ -39,7 +38,7 @@ namespace DiscImageChef.Devices
{
/// <summary>
/// Releases unmanaged resources and performs other cleanup operations before the
/// <see cref="DiscImageChef.Devices.Device"/> is reclaimed by garbage collection.
/// <see cref="Device"/> is reclaimed by garbage collection.
/// </summary>
~Device()
{

View File

@@ -30,7 +30,6 @@
// Copyright © 2011-2016 Natalia Portillo
// ****************************************************************************/
using System;
using DiscImageChef.Console;
namespace DiscImageChef.Devices

View File

@@ -30,7 +30,6 @@
// Copyright © 2011-2016 Natalia Portillo
// ****************************************************************************/
using System;
using DiscImageChef.Console;
namespace DiscImageChef.Devices

View File

@@ -30,7 +30,6 @@
// Copyright © 2011-2016 Natalia Portillo
// ****************************************************************************/
using System;
using DiscImageChef.Console;
namespace DiscImageChef.Devices

View File

@@ -95,7 +95,9 @@ namespace DiscImageChef.Devices
if(sense)
return true;
#pragma warning disable IDE0004 // Cast is necessary or an invalid bitshift happens
ushort confLength = (ushort)(((int)buffer[2] << 8) + buffer[3] + 4);
#pragma warning restore IDE0004 // Cast is necessary or an invalid bitshift happens
buffer = new byte[confLength];
cdb[7] = (byte)((buffer.Length & 0xFF00) >> 8);
cdb[8] = (byte)(buffer.Length & 0xFF);
@@ -147,7 +149,9 @@ namespace DiscImageChef.Devices
if(sense)
return true;
#pragma warning disable IDE0004 // Cast is necessary or an invalid bitshift happens
ushort strctLength = (ushort)(((int)buffer[0] << 8) + buffer[1] + 2);
#pragma warning restore IDE0004 // Cast is necessary or an invalid bitshift happens
buffer = new byte[strctLength];
cdb[8] = (byte)((buffer.Length & 0xFF00) >> 8);
cdb[9] = (byte)(buffer.Length & 0xFF);
@@ -304,7 +308,9 @@ namespace DiscImageChef.Devices
lastError = SendScsiCommand(cdb, ref tmpBuffer, out senseBuffer, timeout, ScsiDirection.In, out duration, out sense);
error = lastError != 0;
#pragma warning disable IDE0004 // Cast is necessary or an invalid bitshift happens
uint strctLength = (uint)(((int)tmpBuffer[0] << 8) + tmpBuffer[1] + 2);
#pragma warning restore IDE0004 // Cast is necessary or an invalid bitshift happens
buffer = new byte[strctLength];
if(buffer.Length <= tmpBuffer.Length)
@@ -361,7 +367,9 @@ namespace DiscImageChef.Devices
lastError = SendScsiCommand(cdb, ref tmpBuffer, out senseBuffer, timeout, ScsiDirection.In, out duration, out sense);
error = lastError != 0;
#pragma warning disable IDE0004 // Cast is necessary or an invalid bitshift happens
uint strctLength = (uint)(((int)tmpBuffer[0] << 8) + tmpBuffer[1] + 2);
#pragma warning restore IDE0004 // Cast is necessary or an invalid bitshift happens
buffer = new byte[strctLength];
Array.Copy(tmpBuffer, 0, buffer, 0, buffer.Length);

View File

@@ -30,7 +30,6 @@
// Copyright © 2011-2016 Natalia Portillo
// ****************************************************************************/
using System;
using DiscImageChef.Console;
namespace DiscImageChef.Devices

View File

@@ -30,7 +30,6 @@
// Copyright © 2011-2016 Natalia Portillo
// ****************************************************************************/
using System;
using DiscImageChef.Console;
namespace DiscImageChef.Devices

View File

@@ -30,7 +30,6 @@
// Copyright © 2011-2016 Natalia Portillo
// ****************************************************************************/
using System;
using DiscImageChef.Console;
namespace DiscImageChef.Devices
@@ -80,7 +79,9 @@ namespace DiscImageChef.Devices
if(sense)
return true;
#pragma warning disable IDE0004 // Cast is necessary or an invalid bitshift happens
uint attrLen = (uint)(((int)buffer[0] << 24) + ((int)buffer[1] << 16) + ((int)buffer[2] << 8) + buffer[3] + 4);
#pragma warning restore IDE0004 // Cast is necessary or an invalid bitshift happens
buffer = new byte[attrLen];
cdb[10] = (byte)((buffer.Length & 0xFF000000) >> 24);
cdb[11] = (byte)((buffer.Length & 0xFF0000) >> 16);

View File

@@ -356,7 +356,9 @@ namespace DiscImageChef.Devices
if(sense)
return true;
#pragma warning disable IDE0004 // Cast is necessary or an invalid bitshift happens
ushort modeLength = (ushort)(((int)buffer[0] << 8) + buffer[1] + 2);
#pragma warning restore IDE0004 // Cast is necessary or an invalid bitshift happens
buffer = new byte[modeLength];
cdb[7] = (byte)((buffer.Length & 0xFF00) >> 8);
cdb[8] = (byte)(buffer.Length & 0xFF);
@@ -577,7 +579,9 @@ namespace DiscImageChef.Devices
if(sense)
return true;
#pragma warning disable IDE0004 // Cast is necessary or an invalid bitshift happens
uint strctLength = (uint)(((int)buffer[0] << 24) + ((int)buffer[1] << 16) + ((int)buffer[2] << 8) + buffer[3] + 4);
#pragma warning restore IDE0004 // Cast is necessary or an invalid bitshift happens
buffer = new byte[strctLength];
cdb[6] = (byte)((buffer.Length & 0xFF000000) >> 24);
cdb[7] = (byte)((buffer.Length & 0xFF0000) >> 16);

View File

@@ -900,7 +900,9 @@ namespace DiscImageChef.Devices
if(sense)
return true;
#pragma warning disable IDE0004 // Cast is necessary or an invalid bitshift happens
ushort availableLength = (ushort)(((int)buffer[0] << 8) + buffer[1] + 2);
#pragma warning restore IDE0004 // Cast is necessary or an invalid bitshift happens
buffer = new byte[availableLength];
cdb[7] = (byte)((buffer.Length & 0xFF00) >> 8);
cdb[8] = (byte)(buffer.Length & 0xFF);

View File

@@ -30,9 +30,6 @@
// Copyright © 2011-2016 Natalia Portillo
// ****************************************************************************/
using System;
using Microsoft.Win32.SafeHandles;
namespace DiscImageChef.Devices
{
public partial class Device
@@ -97,7 +94,7 @@ namespace DiscImageChef.Devices
}
/// <summary>
/// Gets a value indicating whether this <see cref="DiscImageChef.Devices.Device"/> is in error.
/// Gets a value indicating whether this <see cref="Device"/> is in error.
/// </summary>
/// <value><c>true</c> if error; otherwise, <c>false</c>.</value>
public bool Error