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:
@@ -56,7 +56,6 @@
|
|||||||
<ConsolePause>false</ConsolePause>
|
<ConsolePause>false</ConsolePause>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Device\DeviceException.cs" />
|
|
||||||
<Compile Include="Device\ScsiCommands\MediaTek.cs" />
|
<Compile Include="Device\ScsiCommands\MediaTek.cs" />
|
||||||
<Compile Include="Device\ScsiCommands\MiniDisc.cs" />
|
<Compile Include="Device\ScsiCommands\MiniDisc.cs" />
|
||||||
<Compile Include="Device\ScsiCommands\Optical.cs" />
|
<Compile Include="Device\ScsiCommands\Optical.cs" />
|
||||||
|
|||||||
@@ -50,10 +50,11 @@ public partial class Device
|
|||||||
{
|
{
|
||||||
/// <summary>Opens the device for sending direct commands</summary>
|
/// <summary>Opens the device for sending direct commands</summary>
|
||||||
/// <param name="devicePath">Device path</param>
|
/// <param name="devicePath">Device path</param>
|
||||||
public static Device Create(string devicePath)
|
public static Device Create(string devicePath, out ErrorNumber errno)
|
||||||
{
|
{
|
||||||
Device dev = null;
|
Device dev = null;
|
||||||
Uri aaruUri;
|
Uri aaruUri;
|
||||||
|
errno = ErrorNumber.NoError;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -61,18 +62,20 @@ public partial class Device
|
|||||||
}
|
}
|
||||||
catch(Exception)
|
catch(Exception)
|
||||||
{
|
{
|
||||||
return null;
|
aaruUri = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(aaruUri.Scheme is "dic" or "aaru")
|
if(aaruUri?.Scheme is "dic" or "aaru")
|
||||||
dev = Remote.Device.Create(aaruUri);
|
dev = Remote.Device.Create(aaruUri, out errno);
|
||||||
else if(OperatingSystem.IsLinux())
|
else if(OperatingSystem.IsLinux())
|
||||||
dev = Linux.Device.Create(devicePath);
|
dev = Linux.Device.Create(devicePath, out errno);
|
||||||
else if(OperatingSystem.IsWindows())
|
else if(OperatingSystem.IsWindows())
|
||||||
dev = Windows.Device.Create(devicePath);
|
dev = Windows.Device.Create(devicePath, out errno);
|
||||||
|
else
|
||||||
|
errno = ErrorNumber.NotSupported;
|
||||||
|
|
||||||
if(dev is null)
|
if(dev is null)
|
||||||
throw new DeviceException("Platform not supported.");
|
return null;
|
||||||
|
|
||||||
if(dev.Type == DeviceType.SCSI ||
|
if(dev.Type == DeviceType.SCSI ||
|
||||||
dev.Type == DeviceType.ATAPI)
|
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; }
|
|
||||||
}
|
|
||||||
@@ -54,8 +54,10 @@ partial class Device : Devices.Device
|
|||||||
|
|
||||||
Device() {}
|
Device() {}
|
||||||
|
|
||||||
internal new static Device Create(string devicePath)
|
internal new static Device Create(string devicePath, out ErrorNumber errno)
|
||||||
{
|
{
|
||||||
|
errno = ErrorNumber.NoError;
|
||||||
|
|
||||||
var dev = new Device
|
var dev = new Device
|
||||||
{
|
{
|
||||||
PlatformId = DetectOS.GetRealPlatformID(),
|
PlatformId = DetectOS.GetRealPlatformID(),
|
||||||
@@ -86,7 +88,11 @@ partial class Device : Devices.Device
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(dev.Error)
|
if(dev.Error)
|
||||||
throw new DeviceException(dev.LastError);
|
{
|
||||||
|
errno = (ErrorNumber)dev.LastError;
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// Seems ioctl(2) does not allow the atomicity needed
|
// Seems ioctl(2) does not allow the atomicity needed
|
||||||
if(dev.PlatformId == PlatformID.Linux)
|
if(dev.PlatformId == PlatformID.Linux)
|
||||||
@@ -96,7 +102,11 @@ partial class Device : Devices.Device
|
|||||||
dev.ScsiType = PeripheralDeviceTypes.UnknownDevice;
|
dev.ScsiType = PeripheralDeviceTypes.UnknownDevice;
|
||||||
|
|
||||||
if(dev.Error)
|
if(dev.Error)
|
||||||
throw new DeviceException(dev.LastError);
|
{
|
||||||
|
errno = (ErrorNumber)dev.LastError;
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
string devPath;
|
string devPath;
|
||||||
|
|
||||||
|
|||||||
@@ -75,8 +75,10 @@ public sealed partial class Device : Devices.Device
|
|||||||
/// <summary>Opens the device for sending direct commands</summary>
|
/// <summary>Opens the device for sending direct commands</summary>
|
||||||
/// <param name="aaruUri">AaruRemote URI</param>
|
/// <param name="aaruUri">AaruRemote URI</param>
|
||||||
/// <returns>Device</returns>
|
/// <returns>Device</returns>
|
||||||
internal static Device Create(Uri aaruUri)
|
internal static Device Create(Uri aaruUri, out ErrorNumber errno)
|
||||||
{
|
{
|
||||||
|
errno = ErrorNumber.NoError;
|
||||||
|
|
||||||
var dev = new Device
|
var dev = new Device
|
||||||
{
|
{
|
||||||
PlatformId = DetectOS.GetRealPlatformID(),
|
PlatformId = DetectOS.GetRealPlatformID(),
|
||||||
@@ -100,11 +102,16 @@ public sealed partial class Device : Devices.Device
|
|||||||
|
|
||||||
dev._remote = new Remote(aaruUri);
|
dev._remote = new Remote(aaruUri);
|
||||||
|
|
||||||
dev.Error = !dev._remote.Open(devicePath, out int errno);
|
dev.Error = !dev._remote.Open(devicePath, out int remoteErrno);
|
||||||
dev.LastError = errno;
|
dev.LastError = remoteErrno;
|
||||||
|
|
||||||
|
// TODO: Convert error codes
|
||||||
if(dev.Error)
|
if(dev.Error)
|
||||||
throw new DeviceException(dev.LastError);
|
{
|
||||||
|
errno = (ErrorNumber)remoteErrno;
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if(dev._remote.ServerOperatingSystem == "Linux")
|
if(dev._remote.ServerOperatingSystem == "Linux")
|
||||||
_readMultipleBlockCannotSetBlockCount = true;
|
_readMultipleBlockCannotSetBlockCount = true;
|
||||||
@@ -113,7 +120,12 @@ public sealed partial class Device : Devices.Device
|
|||||||
dev.ScsiType = PeripheralDeviceTypes.UnknownDevice;
|
dev.ScsiType = PeripheralDeviceTypes.UnknownDevice;
|
||||||
|
|
||||||
if(dev.Error)
|
if(dev.Error)
|
||||||
throw new DeviceException(dev.LastError);
|
if(dev.Error)
|
||||||
|
{
|
||||||
|
errno = (ErrorNumber)dev.LastError;
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
dev.Type = dev._remote.GetDeviceType();
|
dev.Type = dev._remote.GetDeviceType();
|
||||||
|
|
||||||
|
|||||||
@@ -51,8 +51,10 @@ partial class Device : Devices.Device
|
|||||||
|
|
||||||
Device() {}
|
Device() {}
|
||||||
|
|
||||||
internal new static Device Create(string devicePath)
|
internal new static Device Create(string devicePath, out ErrorNumber errno)
|
||||||
{
|
{
|
||||||
|
errno = ErrorNumber.NoError;
|
||||||
|
|
||||||
var dev = new Device
|
var dev = new Device
|
||||||
{
|
{
|
||||||
PlatformId = DetectOS.GetRealPlatformID(),
|
PlatformId = DetectOS.GetRealPlatformID(),
|
||||||
@@ -71,13 +73,21 @@ partial class Device : Devices.Device
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(dev.Error)
|
if(dev.Error)
|
||||||
throw new DeviceException(dev.LastError);
|
{
|
||||||
|
errno = (ErrorNumber)dev.LastError;
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
dev.Type = DeviceType.Unknown;
|
dev.Type = DeviceType.Unknown;
|
||||||
dev.ScsiType = PeripheralDeviceTypes.UnknownDevice;
|
dev.ScsiType = PeripheralDeviceTypes.UnknownDevice;
|
||||||
|
|
||||||
if(dev.Error)
|
if(dev.Error)
|
||||||
throw new DeviceException(dev.LastError);
|
{
|
||||||
|
errno = (ErrorNumber)dev.LastError;
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// Windows is answering SCSI INQUIRY for all device types so it needs to be detected first
|
// Windows is answering SCSI INQUIRY for all device types so it needs to be detected first
|
||||||
var query = new StoragePropertyQuery();
|
var query = new StoragePropertyQuery();
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ namespace Aaru.Gui.ViewModels.Windows;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reactive;
|
using System.Reactive;
|
||||||
@@ -246,74 +245,72 @@ public sealed class MainWindowViewModel : ViewModelBase
|
|||||||
case DeviceModel deviceModel:
|
case DeviceModel deviceModel:
|
||||||
{
|
{
|
||||||
if(deviceModel.ViewModel is null)
|
if(deviceModel.ViewModel is null)
|
||||||
try
|
{
|
||||||
{
|
var dev = Device.Create(deviceModel.Path, out ErrorNumber devErrno);
|
||||||
var dev = Device.Create(deviceModel.Path);
|
|
||||||
|
|
||||||
if(dev is Devices.Remote.Device remoteDev)
|
switch(dev)
|
||||||
|
{
|
||||||
|
case null:
|
||||||
|
ContentPanel = $"Error {devErrno} opening device";
|
||||||
|
|
||||||
|
return;
|
||||||
|
case Devices.Remote.Device remoteDev:
|
||||||
Statistics.AddRemote(remoteDev.RemoteApplication, remoteDev.RemoteVersion,
|
Statistics.AddRemote(remoteDev.RemoteApplication, remoteDev.RemoteVersion,
|
||||||
remoteDev.RemoteOperatingSystem,
|
remoteDev.RemoteOperatingSystem,
|
||||||
remoteDev.RemoteOperatingSystemVersion,
|
remoteDev.RemoteOperatingSystemVersion,
|
||||||
remoteDev.RemoteArchitecture);
|
remoteDev.RemoteArchitecture);
|
||||||
|
|
||||||
if(dev.Error)
|
break;
|
||||||
{
|
|
||||||
ContentPanel = $"Error {dev.LastError} opening device";
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var devInfo = new DeviceInfo(dev);
|
|
||||||
|
|
||||||
deviceModel.ViewModel = new DeviceInfoViewModel(devInfo, _view);
|
|
||||||
|
|
||||||
if(!dev.IsRemovable)
|
|
||||||
deviceModel.Media.Add(new MediaModel
|
|
||||||
{
|
|
||||||
NonRemovable = true,
|
|
||||||
Name = "Non-removable device commands not yet implemented"
|
|
||||||
});
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// TODO: Removable non-SCSI?
|
|
||||||
var scsiInfo = new ScsiInfo(dev);
|
|
||||||
|
|
||||||
if(!scsiInfo.MediaInserted)
|
|
||||||
deviceModel.Media.Add(new MediaModel
|
|
||||||
{
|
|
||||||
NoMediaInserted = true,
|
|
||||||
Icon = _ejectIcon,
|
|
||||||
Name = "No media inserted"
|
|
||||||
});
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var mediaResource =
|
|
||||||
new Uri($"avares://Aaru.Gui/Assets/Logos/Media/{scsiInfo.MediaType}.png");
|
|
||||||
|
|
||||||
deviceModel.Media.Add(new MediaModel
|
|
||||||
{
|
|
||||||
DevicePath = deviceModel.Path,
|
|
||||||
Icon = _assets.Exists(mediaResource) ? new Bitmap(_assets.Open(mediaResource))
|
|
||||||
: null,
|
|
||||||
Name = $"{scsiInfo.MediaType}",
|
|
||||||
ViewModel = new MediaInfoViewModel(scsiInfo, deviceModel.Path, _view)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dev.Close();
|
|
||||||
}
|
}
|
||||||
catch(SystemException ex)
|
|
||||||
{
|
|
||||||
if(Debugger.IsAttached)
|
|
||||||
throw;
|
|
||||||
|
|
||||||
ContentPanel = ex.Message;
|
if(dev.Error)
|
||||||
AaruConsole.ErrorWriteLine(ex.Message);
|
{
|
||||||
|
ContentPanel = $"Error {dev.LastError} opening device";
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var devInfo = new DeviceInfo(dev);
|
||||||
|
|
||||||
|
deviceModel.ViewModel = new DeviceInfoViewModel(devInfo, _view);
|
||||||
|
|
||||||
|
if(!dev.IsRemovable)
|
||||||
|
deviceModel.Media.Add(new MediaModel
|
||||||
|
{
|
||||||
|
NonRemovable = true,
|
||||||
|
Name = "Non-removable device commands not yet implemented"
|
||||||
|
});
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// TODO: Removable non-SCSI?
|
||||||
|
var scsiInfo = new ScsiInfo(dev);
|
||||||
|
|
||||||
|
if(!scsiInfo.MediaInserted)
|
||||||
|
deviceModel.Media.Add(new MediaModel
|
||||||
|
{
|
||||||
|
NoMediaInserted = true,
|
||||||
|
Icon = _ejectIcon,
|
||||||
|
Name = "No media inserted"
|
||||||
|
});
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var mediaResource =
|
||||||
|
new Uri($"avares://Aaru.Gui/Assets/Logos/Media/{scsiInfo.MediaType}.png");
|
||||||
|
|
||||||
|
deviceModel.Media.Add(new MediaModel
|
||||||
|
{
|
||||||
|
DevicePath = deviceModel.Path,
|
||||||
|
Icon = _assets.Exists(mediaResource) ? new Bitmap(_assets.Open(mediaResource))
|
||||||
|
: null,
|
||||||
|
Name = $"{scsiInfo.MediaType}",
|
||||||
|
ViewModel = new MediaInfoViewModel(scsiInfo, deviceModel.Path, _view)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dev.Close();
|
||||||
|
}
|
||||||
|
|
||||||
ContentPanel = new Views.Panels.DeviceInfo
|
ContentPanel = new Views.Panels.DeviceInfo
|
||||||
{
|
{
|
||||||
DataContext = deviceModel.ViewModel
|
DataContext = deviceModel.ViewModel
|
||||||
@@ -786,10 +783,10 @@ public sealed class MainWindowViewModel : ViewModelBase
|
|||||||
Path = device.Path
|
Path = device.Path
|
||||||
};
|
};
|
||||||
|
|
||||||
try
|
var dev = Device.Create(device.Path, out _);
|
||||||
{
|
|
||||||
var dev = Device.Create(device.Path);
|
|
||||||
|
|
||||||
|
if(dev != null)
|
||||||
|
{
|
||||||
if(dev is Devices.Remote.Device remoteDev)
|
if(dev is Devices.Remote.Device remoteDev)
|
||||||
Statistics.AddRemote(remoteDev.RemoteApplication, remoteDev.RemoteVersion,
|
Statistics.AddRemote(remoteDev.RemoteApplication, remoteDev.RemoteVersion,
|
||||||
remoteDev.RemoteOperatingSystem, remoteDev.RemoteOperatingSystemVersion,
|
remoteDev.RemoteOperatingSystem, remoteDev.RemoteOperatingSystemVersion,
|
||||||
@@ -839,10 +836,6 @@ public sealed class MainWindowViewModel : ViewModelBase
|
|||||||
|
|
||||||
dev.Close();
|
dev.Close();
|
||||||
}
|
}
|
||||||
catch
|
|
||||||
{
|
|
||||||
// ignored
|
|
||||||
}
|
|
||||||
|
|
||||||
_devicesRoot.Devices.Add(deviceModel);
|
_devicesRoot.Devices.Add(deviceModel);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -724,25 +724,25 @@ public sealed class MediaDumpViewModel : ViewModelBase
|
|||||||
|
|
||||||
UpdateStatus("Opening device...");
|
UpdateStatus("Opening device...");
|
||||||
|
|
||||||
try
|
_dev = Device.Create(_devicePath, out ErrorNumber devErrno);
|
||||||
{
|
|
||||||
_dev = Device.Create(_devicePath);
|
|
||||||
|
|
||||||
if(_dev is Devices.Remote.Device remoteDev)
|
switch(_dev)
|
||||||
|
{
|
||||||
|
case null:
|
||||||
|
StoppingErrorMessage($"Error {devErrno} opening device.");
|
||||||
|
|
||||||
|
return;
|
||||||
|
case Devices.Remote.Device remoteDev:
|
||||||
Statistics.AddRemote(remoteDev.RemoteApplication, remoteDev.RemoteVersion,
|
Statistics.AddRemote(remoteDev.RemoteApplication, remoteDev.RemoteVersion,
|
||||||
remoteDev.RemoteOperatingSystem, remoteDev.RemoteOperatingSystemVersion,
|
remoteDev.RemoteOperatingSystem, remoteDev.RemoteOperatingSystemVersion,
|
||||||
remoteDev.RemoteArchitecture);
|
remoteDev.RemoteArchitecture);
|
||||||
|
|
||||||
if(_dev.Error)
|
break;
|
||||||
{
|
|
||||||
StoppingErrorMessage($"Error {_dev.LastError} opening device.");
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch(Exception exception)
|
|
||||||
|
if(_dev.Error)
|
||||||
{
|
{
|
||||||
StoppingErrorMessage($"Exception {exception.Message} opening device.");
|
StoppingErrorMessage($"Error {_dev.LastError} opening device.");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ using System.Collections.ObjectModel;
|
|||||||
using System.Reactive;
|
using System.Reactive;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Aaru.CommonTypes.Enums;
|
||||||
using Aaru.Core;
|
using Aaru.Core;
|
||||||
using Aaru.Core.Devices.Scanning;
|
using Aaru.Core.Devices.Scanning;
|
||||||
using Aaru.Devices;
|
using Aaru.Devices;
|
||||||
@@ -328,11 +329,28 @@ public sealed class MediaScanViewModel : ViewModelBase
|
|||||||
char.IsLetter(_devicePath[0]))
|
char.IsLetter(_devicePath[0]))
|
||||||
_devicePath = "\\\\.\\" + char.ToUpper(_devicePath[0]) + ':';
|
_devicePath = "\\\\.\\" + char.ToUpper(_devicePath[0]) + ':';
|
||||||
|
|
||||||
var dev = Device.Create(_devicePath);
|
var dev = Device.Create(_devicePath, out ErrorNumber devErrno);
|
||||||
|
|
||||||
if(dev is Devices.Remote.Device remoteDev)
|
switch(dev)
|
||||||
Statistics.AddRemote(remoteDev.RemoteApplication, remoteDev.RemoteVersion, remoteDev.RemoteOperatingSystem,
|
{
|
||||||
remoteDev.RemoteOperatingSystemVersion, remoteDev.RemoteArchitecture);
|
case null:
|
||||||
|
await MessageBoxManager.
|
||||||
|
GetMessageBoxStandardWindow("Error", $"Error {devErrno} opening device.", ButtonEnum.Ok,
|
||||||
|
Icon.Error).ShowDialog(_view);
|
||||||
|
|
||||||
|
StopVisible = false;
|
||||||
|
StartVisible = true;
|
||||||
|
CloseVisible = true;
|
||||||
|
ProgressVisible = false;
|
||||||
|
|
||||||
|
return;
|
||||||
|
case Devices.Remote.Device remoteDev:
|
||||||
|
Statistics.AddRemote(remoteDev.RemoteApplication, remoteDev.RemoteVersion,
|
||||||
|
remoteDev.RemoteOperatingSystem, remoteDev.RemoteOperatingSystemVersion,
|
||||||
|
remoteDev.RemoteArchitecture);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if(dev.Error)
|
if(dev.Error)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ static partial class MainClass
|
|||||||
AaruConsole.WriteLine("Going to open {0}. Press any key to continue...", devPath);
|
AaruConsole.WriteLine("Going to open {0}. Press any key to continue...", devPath);
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
|
|
||||||
var dev = Aaru.Devices.Device.Create(devPath);
|
var dev = Aaru.Devices.Device.Create(devPath, out _);
|
||||||
|
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ using Aaru.Database;
|
|||||||
using Aaru.Database.Models;
|
using Aaru.Database.Models;
|
||||||
using Aaru.Decoders.SCSI;
|
using Aaru.Decoders.SCSI;
|
||||||
using Aaru.Decoders.SCSI.MMC;
|
using Aaru.Decoders.SCSI.MMC;
|
||||||
using Aaru.Devices;
|
|
||||||
using Aaru.Helpers;
|
using Aaru.Helpers;
|
||||||
using Aaru.Settings;
|
using Aaru.Settings;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
@@ -124,27 +123,25 @@ sealed class DeviceReportCommand : Command
|
|||||||
char.IsLetter(devicePath[0]))
|
char.IsLetter(devicePath[0]))
|
||||||
devicePath = "\\\\.\\" + char.ToUpper(devicePath[0]) + ':';
|
devicePath = "\\\\.\\" + char.ToUpper(devicePath[0]) + ':';
|
||||||
|
|
||||||
Device dev;
|
var dev = Device.Create(devicePath, out ErrorNumber devErrno);
|
||||||
|
|
||||||
try
|
switch(dev)
|
||||||
{
|
{
|
||||||
dev = Device.Create(devicePath);
|
case null:
|
||||||
|
AaruConsole.ErrorWriteLine($"Could not open device, error {devErrno}.");
|
||||||
|
|
||||||
if(dev is Devices.Remote.Device remoteDev)
|
return (int)devErrno;
|
||||||
|
case Devices.Remote.Device remoteDev:
|
||||||
Statistics.AddRemote(remoteDev.RemoteApplication, remoteDev.RemoteVersion,
|
Statistics.AddRemote(remoteDev.RemoteApplication, remoteDev.RemoteVersion,
|
||||||
remoteDev.RemoteOperatingSystem, remoteDev.RemoteOperatingSystemVersion,
|
remoteDev.RemoteOperatingSystem, remoteDev.RemoteOperatingSystemVersion,
|
||||||
remoteDev.RemoteArchitecture);
|
remoteDev.RemoteArchitecture);
|
||||||
|
|
||||||
if(dev.Error)
|
break;
|
||||||
{
|
|
||||||
AaruConsole.ErrorWriteLine(Error.Print(dev.LastError));
|
|
||||||
|
|
||||||
return (int)ErrorNumber.CannotOpenDevice;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch(DeviceException e)
|
|
||||||
|
if(dev.Error)
|
||||||
{
|
{
|
||||||
AaruConsole.ErrorWriteLine(e.Message);
|
AaruConsole.ErrorWriteLine(Error.Print(dev.LastError));
|
||||||
|
|
||||||
return (int)ErrorNumber.CannotOpenDevice;
|
return (int)ErrorNumber.CannotOpenDevice;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -128,27 +128,25 @@ sealed class DeviceInfoCommand : Command
|
|||||||
char.IsLetter(devicePath[0]))
|
char.IsLetter(devicePath[0]))
|
||||||
devicePath = "\\\\.\\" + char.ToUpper(devicePath[0]) + ':';
|
devicePath = "\\\\.\\" + char.ToUpper(devicePath[0]) + ':';
|
||||||
|
|
||||||
Device dev;
|
var dev = Device.Create(devicePath, out ErrorNumber devErrno);
|
||||||
|
|
||||||
try
|
switch(dev)
|
||||||
{
|
{
|
||||||
dev = Device.Create(devicePath);
|
case null:
|
||||||
|
AaruConsole.ErrorWriteLine($"Could not open device, error {devErrno}.");
|
||||||
|
|
||||||
if(dev is Devices.Remote.Device remoteDev)
|
return (int)devErrno;
|
||||||
|
case Devices.Remote.Device remoteDev:
|
||||||
Statistics.AddRemote(remoteDev.RemoteApplication, remoteDev.RemoteVersion,
|
Statistics.AddRemote(remoteDev.RemoteApplication, remoteDev.RemoteVersion,
|
||||||
remoteDev.RemoteOperatingSystem, remoteDev.RemoteOperatingSystemVersion,
|
remoteDev.RemoteOperatingSystem, remoteDev.RemoteOperatingSystemVersion,
|
||||||
remoteDev.RemoteArchitecture);
|
remoteDev.RemoteArchitecture);
|
||||||
|
|
||||||
if(dev.Error)
|
break;
|
||||||
{
|
|
||||||
AaruConsole.ErrorWriteLine(Error.Print(dev.LastError));
|
|
||||||
|
|
||||||
return (int)ErrorNumber.CannotOpenDevice;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch(DeviceException e)
|
|
||||||
|
if(dev.Error)
|
||||||
{
|
{
|
||||||
AaruConsole.ErrorWriteLine(e.Message);
|
AaruConsole.ErrorWriteLine(Error.Print(dev.LastError));
|
||||||
|
|
||||||
return (int)ErrorNumber.CannotOpenDevice;
|
return (int)ErrorNumber.CannotOpenDevice;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -536,34 +536,37 @@ sealed class DumpMediaCommand : Command
|
|||||||
char.IsLetter(devicePath[0]))
|
char.IsLetter(devicePath[0]))
|
||||||
devicePath = "\\\\.\\" + char.ToUpper(devicePath[0]) + ':';
|
devicePath = "\\\\.\\" + char.ToUpper(devicePath[0]) + ':';
|
||||||
|
|
||||||
Device dev = null;
|
Device dev = null;
|
||||||
|
ErrorNumber devErrno = ErrorNumber.NoError;
|
||||||
|
|
||||||
try
|
Spectre.ProgressSingleSpinner(ctx =>
|
||||||
{
|
{
|
||||||
Spectre.ProgressSingleSpinner(ctx =>
|
ctx.AddTask("Opening device...").IsIndeterminate();
|
||||||
{
|
dev = Device.Create(devicePath, out devErrno);
|
||||||
ctx.AddTask("Opening device...").IsIndeterminate();
|
});
|
||||||
dev = Device.Create(devicePath);
|
|
||||||
});
|
|
||||||
|
|
||||||
if(dev is Devices.Remote.Device remoteDev)
|
switch(dev)
|
||||||
Statistics.AddRemote(remoteDev.RemoteApplication, remoteDev.RemoteVersion,
|
{
|
||||||
remoteDev.RemoteOperatingSystem, remoteDev.RemoteOperatingSystemVersion,
|
case null:
|
||||||
remoteDev.RemoteArchitecture);
|
|
||||||
|
|
||||||
if(dev.Error)
|
|
||||||
{
|
{
|
||||||
AaruConsole.ErrorWriteLine(Error.Print(dev.LastError));
|
AaruConsole.ErrorWriteLine($"Could not open device, error {devErrno}.");
|
||||||
|
|
||||||
if(isResponse)
|
if(isResponse)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
return (int)ErrorNumber.CannotOpenDevice;
|
return (int)devErrno;
|
||||||
}
|
}
|
||||||
|
case Devices.Remote.Device remoteDev:
|
||||||
|
Statistics.AddRemote(remoteDev.RemoteApplication, remoteDev.RemoteVersion,
|
||||||
|
remoteDev.RemoteOperatingSystem, remoteDev.RemoteOperatingSystemVersion,
|
||||||
|
remoteDev.RemoteArchitecture);
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
catch(DeviceException e)
|
|
||||||
|
if(dev.Error)
|
||||||
{
|
{
|
||||||
AaruConsole.ErrorWriteLine(e.Message ?? Error.Print(e.LastError));
|
AaruConsole.ErrorWriteLine(Error.Print(dev.LastError));
|
||||||
|
|
||||||
if(isResponse)
|
if(isResponse)
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ using Aaru.Decoders.DVD;
|
|||||||
using Aaru.Decoders.SCSI.MMC;
|
using Aaru.Decoders.SCSI.MMC;
|
||||||
using Aaru.Decoders.SCSI.SSC;
|
using Aaru.Decoders.SCSI.SSC;
|
||||||
using Aaru.Decoders.Xbox;
|
using Aaru.Decoders.Xbox;
|
||||||
using Aaru.Devices;
|
|
||||||
using Aaru.Settings;
|
using Aaru.Settings;
|
||||||
using Spectre.Console;
|
using Spectre.Console;
|
||||||
using BCA = Aaru.Decoders.Bluray.BCA;
|
using BCA = Aaru.Decoders.Bluray.BCA;
|
||||||
@@ -129,31 +128,32 @@ sealed class MediaInfoCommand : Command
|
|||||||
char.IsLetter(devicePath[0]))
|
char.IsLetter(devicePath[0]))
|
||||||
devicePath = "\\\\.\\" + char.ToUpper(devicePath[0]) + ':';
|
devicePath = "\\\\.\\" + char.ToUpper(devicePath[0]) + ':';
|
||||||
|
|
||||||
Device dev = null;
|
Device dev = null;
|
||||||
|
ErrorNumber devErrno = ErrorNumber.NoError;
|
||||||
|
|
||||||
try
|
Spectre.ProgressSingleSpinner(ctx =>
|
||||||
{
|
{
|
||||||
Spectre.ProgressSingleSpinner(ctx =>
|
ctx.AddTask("Opening device...").IsIndeterminate();
|
||||||
{
|
dev = Device.Create(devicePath, out devErrno);
|
||||||
ctx.AddTask("Opening device...").IsIndeterminate();
|
});
|
||||||
dev = Device.Create(devicePath);
|
|
||||||
});
|
|
||||||
|
|
||||||
if(dev is Devices.Remote.Device remoteDev)
|
switch(dev)
|
||||||
|
{
|
||||||
|
case null:
|
||||||
|
AaruConsole.ErrorWriteLine($"Could not open device, error {devErrno}.");
|
||||||
|
|
||||||
|
return (int)devErrno;
|
||||||
|
case Devices.Remote.Device remoteDev:
|
||||||
Statistics.AddRemote(remoteDev.RemoteApplication, remoteDev.RemoteVersion,
|
Statistics.AddRemote(remoteDev.RemoteApplication, remoteDev.RemoteVersion,
|
||||||
remoteDev.RemoteOperatingSystem, remoteDev.RemoteOperatingSystemVersion,
|
remoteDev.RemoteOperatingSystem, remoteDev.RemoteOperatingSystemVersion,
|
||||||
remoteDev.RemoteArchitecture);
|
remoteDev.RemoteArchitecture);
|
||||||
|
|
||||||
if(dev.Error)
|
break;
|
||||||
{
|
|
||||||
AaruConsole.ErrorWriteLine(Error.Print(dev.LastError));
|
|
||||||
|
|
||||||
return (int)ErrorNumber.CannotOpenDevice;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch(DeviceException e)
|
|
||||||
|
if(dev.Error)
|
||||||
{
|
{
|
||||||
AaruConsole.ErrorWriteLine(e.Message);
|
AaruConsole.ErrorWriteLine(Error.Print(dev.LastError));
|
||||||
|
|
||||||
return (int)ErrorNumber.CannotOpenDevice;
|
return (int)ErrorNumber.CannotOpenDevice;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -130,31 +130,32 @@ sealed class MediaScanCommand : Command
|
|||||||
char.IsLetter(devicePath[0]))
|
char.IsLetter(devicePath[0]))
|
||||||
devicePath = "\\\\.\\" + char.ToUpper(devicePath[0]) + ':';
|
devicePath = "\\\\.\\" + char.ToUpper(devicePath[0]) + ':';
|
||||||
|
|
||||||
Device dev = null;
|
Device dev = null;
|
||||||
|
ErrorNumber devErrno = ErrorNumber.NoError;
|
||||||
|
|
||||||
try
|
Spectre.ProgressSingleSpinner(ctx =>
|
||||||
{
|
{
|
||||||
Spectre.ProgressSingleSpinner(ctx =>
|
ctx.AddTask("Opening device...").IsIndeterminate();
|
||||||
{
|
dev = Device.Create(devicePath, out devErrno);
|
||||||
ctx.AddTask("Opening device...").IsIndeterminate();
|
});
|
||||||
dev = Device.Create(devicePath);
|
|
||||||
});
|
|
||||||
|
|
||||||
if(dev is Devices.Remote.Device remoteDev)
|
switch(dev)
|
||||||
|
{
|
||||||
|
case null:
|
||||||
|
AaruConsole.ErrorWriteLine($"Could not open device, error {devErrno}.");
|
||||||
|
|
||||||
|
return (int)devErrno;
|
||||||
|
case Devices.Remote.Device remoteDev:
|
||||||
Statistics.AddRemote(remoteDev.RemoteApplication, remoteDev.RemoteVersion,
|
Statistics.AddRemote(remoteDev.RemoteApplication, remoteDev.RemoteVersion,
|
||||||
remoteDev.RemoteOperatingSystem, remoteDev.RemoteOperatingSystemVersion,
|
remoteDev.RemoteOperatingSystem, remoteDev.RemoteOperatingSystemVersion,
|
||||||
remoteDev.RemoteArchitecture);
|
remoteDev.RemoteArchitecture);
|
||||||
|
|
||||||
if(dev.Error)
|
break;
|
||||||
{
|
|
||||||
AaruConsole.ErrorWriteLine(Error.Print(dev.LastError));
|
|
||||||
|
|
||||||
return (int)ErrorNumber.CannotOpenDevice;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch(DeviceException e)
|
|
||||||
|
if(dev.Error)
|
||||||
{
|
{
|
||||||
AaruConsole.ErrorWriteLine(e.Message);
|
AaruConsole.ErrorWriteLine(Error.Print(dev.LastError));
|
||||||
|
|
||||||
return (int)ErrorNumber.CannotOpenDevice;
|
return (int)ErrorNumber.CannotOpenDevice;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user