mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Allow listing devices from remote.
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using DiscImageChef.CommonTypes.Interop;
|
||||
using DiscImageChef.Console;
|
||||
using PlatformID = DiscImageChef.CommonTypes.Interop.PlatformID;
|
||||
|
||||
namespace DiscImageChef.Devices
|
||||
@@ -60,15 +61,30 @@ namespace DiscImageChef.Devices
|
||||
|
||||
public partial class Device
|
||||
{
|
||||
public static DeviceInfo[] ListDevices()
|
||||
public static DeviceInfo[] ListDevices(string dicRemote = null)
|
||||
{
|
||||
if (dicRemote is null)
|
||||
switch (DetectOS.GetRealPlatformID())
|
||||
{
|
||||
case PlatformID.Win32NT: return Windows.ListDevices.GetList();
|
||||
case PlatformID.Linux: return Linux.ListDevices.GetList();
|
||||
case PlatformID.FreeBSD: return FreeBSD.ListDevices.GetList();
|
||||
default:
|
||||
throw new InvalidOperationException($"Platform {DetectOS.GetRealPlatformID()} not yet supported.");
|
||||
throw new InvalidOperationException(
|
||||
$"Platform {DetectOS.GetRealPlatformID()} not yet supported.");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
using (var remote = new Remote.Remote(dicRemote))
|
||||
{
|
||||
return remote.ListDevices();
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
DicConsole.ErrorWriteLine("Error connecting to host.");
|
||||
return new DeviceInfo[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ using Version = DiscImageChef.CommonTypes.Interop.Version;
|
||||
|
||||
namespace DiscImageChef.Devices.Remote
|
||||
{
|
||||
public class Remote
|
||||
public class Remote : IDisposable
|
||||
{
|
||||
private readonly Socket _socket;
|
||||
|
||||
@@ -115,10 +115,20 @@ namespace DiscImageChef.Devices.Remote
|
||||
public string ServerArchitecture { get; }
|
||||
public int ServerProtocolVersion { get; }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Disconnect();
|
||||
}
|
||||
|
||||
public void Disconnect()
|
||||
{
|
||||
_socket.Shutdown(SocketShutdown.Both);
|
||||
_socket.Close();
|
||||
}
|
||||
|
||||
public DeviceInfo[] ListDevices()
|
||||
{
|
||||
return new DeviceInfo[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,9 +40,9 @@ using Mono.Options;
|
||||
|
||||
namespace DiscImageChef.Commands
|
||||
{
|
||||
class ListDevicesCommand : Command
|
||||
internal class ListDevicesCommand : Command
|
||||
{
|
||||
bool showHelp;
|
||||
private bool showHelp;
|
||||
|
||||
public ListDevicesCommand() : base("list-devices", "Lists all connected devices.")
|
||||
{
|
||||
@@ -51,7 +51,7 @@ namespace DiscImageChef.Commands
|
||||
$"{MainClass.AssemblyTitle} {MainClass.AssemblyVersion?.InformationalVersion}",
|
||||
$"{MainClass.AssemblyCopyright}",
|
||||
"",
|
||||
$"usage: DiscImageChef {Name}",
|
||||
$"usage: DiscImageChef {Name} [dic-remote-host]",
|
||||
"",
|
||||
Help,
|
||||
{"help|h|?", "Show this message and exit.", v => showHelp = v != null}
|
||||
@@ -60,7 +60,7 @@ namespace DiscImageChef.Commands
|
||||
|
||||
public override int Invoke(IEnumerable<string> arguments)
|
||||
{
|
||||
List<string> extra = Options.Parse(arguments);
|
||||
var extra = Options.Parse(arguments);
|
||||
|
||||
if (showHelp)
|
||||
{
|
||||
@@ -73,18 +73,25 @@ namespace DiscImageChef.Commands
|
||||
if (MainClass.Verbose) DicConsole.VerboseWriteLineEvent += System.Console.WriteLine;
|
||||
Statistics.AddCommand("list-devices");
|
||||
|
||||
if(extra.Count > 0)
|
||||
string dicRemote = null;
|
||||
|
||||
if (extra.Count > 1)
|
||||
{
|
||||
DicConsole.ErrorWriteLine("Too many arguments.");
|
||||
return (int) ErrorNumber.UnexpectedArgumentCount;
|
||||
}
|
||||
|
||||
if (extra.Count == 1) dicRemote = extra[0];
|
||||
|
||||
DicConsole.DebugWriteLine("List-Devices command", "--debug={0}", MainClass.Debug);
|
||||
DicConsole.DebugWriteLine("List-Devices command", "--verbose={0}", MainClass.Verbose);
|
||||
|
||||
DeviceInfo[] devices = Device.ListDevices();
|
||||
var devices = Device.ListDevices(dicRemote);
|
||||
|
||||
if(devices == null || devices.Length == 0) DicConsole.WriteLine("No known devices attached.");
|
||||
if (devices == null || devices.Length == 0)
|
||||
{
|
||||
DicConsole.WriteLine("No known devices attached.");
|
||||
}
|
||||
else
|
||||
{
|
||||
devices = devices.OrderBy(d => d.Path).ToArray();
|
||||
@@ -94,7 +101,7 @@ namespace DiscImageChef.Commands
|
||||
DicConsole.WriteLine("{0,-22}+{1,-16}+{2,-24}+{3,-24}+{4,-10}+{5,-10}", "----------------------",
|
||||
"----------------", "------------------------", "------------------------",
|
||||
"----------", "----------");
|
||||
foreach(DeviceInfo dev in devices)
|
||||
foreach (var dev in devices)
|
||||
DicConsole.WriteLine("{0,-22}|{1,-16}|{2,-24}|{3,-24}|{4,-10}|{5,-10}", dev.Path, dev.Vendor,
|
||||
dev.Model, dev.Serial, dev.Bus, dev.Supported);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user