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;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using DiscImageChef.CommonTypes.Interop;
|
using DiscImageChef.CommonTypes.Interop;
|
||||||
|
using DiscImageChef.Console;
|
||||||
using PlatformID = DiscImageChef.CommonTypes.Interop.PlatformID;
|
using PlatformID = DiscImageChef.CommonTypes.Interop.PlatformID;
|
||||||
|
|
||||||
namespace DiscImageChef.Devices
|
namespace DiscImageChef.Devices
|
||||||
@@ -60,15 +61,30 @@ namespace DiscImageChef.Devices
|
|||||||
|
|
||||||
public partial class Device
|
public partial class Device
|
||||||
{
|
{
|
||||||
public static DeviceInfo[] ListDevices()
|
public static DeviceInfo[] ListDevices(string dicRemote = null)
|
||||||
{
|
{
|
||||||
switch (DetectOS.GetRealPlatformID())
|
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.");
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
case PlatformID.Win32NT: return Windows.ListDevices.GetList();
|
using (var remote = new Remote.Remote(dicRemote))
|
||||||
case PlatformID.Linux: return Linux.ListDevices.GetList();
|
{
|
||||||
case PlatformID.FreeBSD: return FreeBSD.ListDevices.GetList();
|
return remote.ListDevices();
|
||||||
default:
|
}
|
||||||
throw new InvalidOperationException($"Platform {DetectOS.GetRealPlatformID()} not yet supported.");
|
}
|
||||||
|
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
|
namespace DiscImageChef.Devices.Remote
|
||||||
{
|
{
|
||||||
public class Remote
|
public class Remote : IDisposable
|
||||||
{
|
{
|
||||||
private readonly Socket _socket;
|
private readonly Socket _socket;
|
||||||
|
|
||||||
@@ -115,10 +115,20 @@ namespace DiscImageChef.Devices.Remote
|
|||||||
public string ServerArchitecture { get; }
|
public string ServerArchitecture { get; }
|
||||||
public int ServerProtocolVersion { get; }
|
public int ServerProtocolVersion { get; }
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
public void Disconnect()
|
public void Disconnect()
|
||||||
{
|
{
|
||||||
_socket.Shutdown(SocketShutdown.Both);
|
_socket.Shutdown(SocketShutdown.Both);
|
||||||
_socket.Close();
|
_socket.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DeviceInfo[] ListDevices()
|
||||||
|
{
|
||||||
|
return new DeviceInfo[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -40,9 +40,9 @@ using Mono.Options;
|
|||||||
|
|
||||||
namespace DiscImageChef.Commands
|
namespace DiscImageChef.Commands
|
||||||
{
|
{
|
||||||
class ListDevicesCommand : Command
|
internal class ListDevicesCommand : Command
|
||||||
{
|
{
|
||||||
bool showHelp;
|
private bool showHelp;
|
||||||
|
|
||||||
public ListDevicesCommand() : base("list-devices", "Lists all connected devices.")
|
public ListDevicesCommand() : base("list-devices", "Lists all connected devices.")
|
||||||
{
|
{
|
||||||
@@ -51,7 +51,7 @@ namespace DiscImageChef.Commands
|
|||||||
$"{MainClass.AssemblyTitle} {MainClass.AssemblyVersion?.InformationalVersion}",
|
$"{MainClass.AssemblyTitle} {MainClass.AssemblyVersion?.InformationalVersion}",
|
||||||
$"{MainClass.AssemblyCopyright}",
|
$"{MainClass.AssemblyCopyright}",
|
||||||
"",
|
"",
|
||||||
$"usage: DiscImageChef {Name}",
|
$"usage: DiscImageChef {Name} [dic-remote-host]",
|
||||||
"",
|
"",
|
||||||
Help,
|
Help,
|
||||||
{"help|h|?", "Show this message and exit.", v => showHelp = v != null}
|
{"help|h|?", "Show this message and exit.", v => showHelp = v != null}
|
||||||
@@ -60,46 +60,53 @@ namespace DiscImageChef.Commands
|
|||||||
|
|
||||||
public override int Invoke(IEnumerable<string> arguments)
|
public override int Invoke(IEnumerable<string> arguments)
|
||||||
{
|
{
|
||||||
List<string> extra = Options.Parse(arguments);
|
var extra = Options.Parse(arguments);
|
||||||
|
|
||||||
if(showHelp)
|
if (showHelp)
|
||||||
{
|
{
|
||||||
Options.WriteOptionDescriptions(CommandSet.Out);
|
Options.WriteOptionDescriptions(CommandSet.Out);
|
||||||
return (int)ErrorNumber.HelpRequested;
|
return (int) ErrorNumber.HelpRequested;
|
||||||
}
|
}
|
||||||
|
|
||||||
MainClass.PrintCopyright();
|
MainClass.PrintCopyright();
|
||||||
if(MainClass.Debug) DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine;
|
if (MainClass.Debug) DicConsole.DebugWriteLineEvent += System.Console.Error.WriteLine;
|
||||||
if(MainClass.Verbose) DicConsole.VerboseWriteLineEvent += System.Console.WriteLine;
|
if (MainClass.Verbose) DicConsole.VerboseWriteLineEvent += System.Console.WriteLine;
|
||||||
Statistics.AddCommand("list-devices");
|
Statistics.AddCommand("list-devices");
|
||||||
|
|
||||||
if(extra.Count > 0)
|
string dicRemote = null;
|
||||||
|
|
||||||
|
if (extra.Count > 1)
|
||||||
{
|
{
|
||||||
DicConsole.ErrorWriteLine("Too many arguments.");
|
DicConsole.ErrorWriteLine("Too many arguments.");
|
||||||
return (int)ErrorNumber.UnexpectedArgumentCount;
|
return (int) ErrorNumber.UnexpectedArgumentCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
DicConsole.DebugWriteLine("List-Devices command", "--debug={0}", MainClass.Debug);
|
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);
|
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
|
else
|
||||||
{
|
{
|
||||||
devices = devices.OrderBy(d => d.Path).ToArray();
|
devices = devices.OrderBy(d => d.Path).ToArray();
|
||||||
|
|
||||||
DicConsole.WriteLine("{0,-22}|{1,-16}|{2,-24}|{3,-24}|{4,-10}|{5,-10}", "Path", "Vendor", "Model",
|
DicConsole.WriteLine("{0,-22}|{1,-16}|{2,-24}|{3,-24}|{4,-10}|{5,-10}", "Path", "Vendor", "Model",
|
||||||
"Serial", "Bus", "Supported?");
|
"Serial", "Bus", "Supported?");
|
||||||
DicConsole.WriteLine("{0,-22}+{1,-16}+{2,-24}+{3,-24}+{4,-10}+{5,-10}", "----------------------",
|
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,
|
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);
|
dev.Model, dev.Serial, dev.Bus, dev.Supported);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int)ErrorNumber.NoError;
|
return (int) ErrorNumber.NoError;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user