mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Use error number for device instead of exception.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
Reference in New Issue
Block a user