Use error number for device instead of exception.

This commit is contained in:
2022-03-26 20:18:01 +00:00
parent 89a2c52911
commit 755da6cd2c
15 changed files with 219 additions and 222 deletions

View File

@@ -50,10 +50,11 @@ public partial class Device
{
/// <summary>Opens the device for sending direct commands</summary>
/// <param name="devicePath">Device path</param>
public static Device Create(string devicePath)
public static Device Create(string devicePath, out ErrorNumber errno)
{
Device dev = null;
Uri aaruUri;
errno = ErrorNumber.NoError;
try
{
@@ -61,18 +62,20 @@ public partial class Device
}
catch(Exception)
{
return null;
aaruUri = null;
}
if(aaruUri.Scheme is "dic" or "aaru")
dev = Remote.Device.Create(aaruUri);
if(aaruUri?.Scheme is "dic" or "aaru")
dev = Remote.Device.Create(aaruUri, out errno);
else if(OperatingSystem.IsLinux())
dev = Linux.Device.Create(devicePath);
dev = Linux.Device.Create(devicePath, out errno);
else if(OperatingSystem.IsWindows())
dev = Windows.Device.Create(devicePath);
dev = Windows.Device.Create(devicePath, out errno);
else
errno = ErrorNumber.NotSupported;
if(dev is null)
throw new DeviceException("Platform not supported.");
return null;
if(dev.Type == DeviceType.SCSI ||
dev.Type == DeviceType.ATAPI)

View File

@@ -1,47 +0,0 @@
// /***************************************************************************
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// Filename : DeviceException.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Devices.
//
// --[ Description ] ----------------------------------------------------------
//
// Exception to be returned by the device constructor.
//
// --[ 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 <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2011-2022 Natalia Portillo
// ****************************************************************************/
namespace Aaru.Devices;
using System;
/// <inheritdoc />
/// <summary>Exception to be returned by the device constructor</summary>
public sealed class DeviceException : Exception
{
internal DeviceException(string message) : base(message) {}
internal DeviceException(int lastError) => LastError = lastError;
/// <summary>Last error sent by the operating systen</summary>
public int LastError { get; }
}