2018-08-27 18:29:55 +01:00
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
// Aaru Data Preservation Suite
|
2018-08-27 18:29:55 +01:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : frmMain.xeto.cs
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
|
|
|
|
// Component : Main window.
|
|
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Implements main GUI window.
|
|
|
|
|
//
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General public License as
|
|
|
|
|
// published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This program 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 General public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU General public License
|
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2020-01-03 17:51:30 +00:00
|
|
|
// Copyright © 2011-2020 Natalia Portillo
|
2018-08-27 18:29:55 +01:00
|
|
|
// ****************************************************************************/
|
2018-08-28 23:29:06 +01:00
|
|
|
|
2018-08-27 15:07:51 +01:00
|
|
|
using System;
|
2018-10-08 00:49:30 +01:00
|
|
|
using System.Collections.Generic;
|
2018-08-27 18:25:11 +01:00
|
|
|
using System.ComponentModel;
|
2018-10-03 00:05:25 +01:00
|
|
|
using System.IO;
|
2018-08-27 15:07:51 +01:00
|
|
|
using System.Linq;
|
2020-02-27 00:33:26 +00:00
|
|
|
using Aaru.CommonTypes.Enums;
|
|
|
|
|
using Aaru.CommonTypes.Interfaces;
|
|
|
|
|
using Aaru.CommonTypes.Structs;
|
|
|
|
|
using Aaru.CommonTypes.Structs.Devices.SCSI;
|
|
|
|
|
using Aaru.Console;
|
|
|
|
|
using Aaru.Core;
|
|
|
|
|
using Aaru.Core.Media.Info;
|
|
|
|
|
using Aaru.Devices;
|
2020-02-29 18:03:35 +00:00
|
|
|
using Aaru.Gui.Panels;
|
2018-10-07 23:29:28 +01:00
|
|
|
using Eto.Drawing;
|
2018-08-27 15:07:51 +01:00
|
|
|
using Eto.Forms;
|
|
|
|
|
using Eto.Serialization.Xaml;
|
2020-02-27 00:33:26 +00:00
|
|
|
using FileAttributes = Aaru.CommonTypes.Structs.FileAttributes;
|
2018-08-27 15:07:51 +01:00
|
|
|
|
2020-02-27 00:33:26 +00:00
|
|
|
namespace Aaru.Gui.Forms
|
2018-08-27 15:07:51 +01:00
|
|
|
{
|
|
|
|
|
public class frmMain : Form
|
|
|
|
|
{
|
2019-12-07 19:54:27 +00:00
|
|
|
readonly Bitmap devicesIcon;
|
|
|
|
|
readonly Bitmap ejectIcon;
|
|
|
|
|
readonly Bitmap hardDiskIcon;
|
|
|
|
|
readonly Bitmap imagesIcon;
|
|
|
|
|
readonly Label lblError;
|
|
|
|
|
/// <summary>This is to remember that column is an image to be set in future</summary>
|
|
|
|
|
readonly Image nullImage;
|
|
|
|
|
readonly Bitmap opticalIcon;
|
|
|
|
|
readonly TreeGridItem placeholderItem;
|
|
|
|
|
readonly Bitmap removableIcon;
|
|
|
|
|
readonly Bitmap sdIcon;
|
|
|
|
|
readonly Bitmap tapeIcon;
|
|
|
|
|
readonly TreeGridItemCollection treeImagesItems;
|
|
|
|
|
readonly ContextMenu treeImagesMenu;
|
|
|
|
|
readonly Bitmap usbIcon;
|
2020-01-03 18:13:57 +00:00
|
|
|
bool closing;
|
|
|
|
|
GridView grdFiles;
|
|
|
|
|
TreeGridView treeImages;
|
2018-08-27 15:07:51 +01:00
|
|
|
|
2018-08-27 18:25:11 +01:00
|
|
|
public frmMain(bool debug, bool verbose)
|
2018-08-27 15:07:51 +01:00
|
|
|
{
|
|
|
|
|
XamlReader.Load(this);
|
|
|
|
|
|
2018-10-07 23:29:28 +01:00
|
|
|
lblError = new Label();
|
|
|
|
|
grdFiles = new GridView();
|
|
|
|
|
nullImage = null;
|
2018-09-02 01:41:03 +01:00
|
|
|
|
2018-08-27 18:25:11 +01:00
|
|
|
ConsoleHandler.Init();
|
|
|
|
|
ConsoleHandler.Debug = debug;
|
|
|
|
|
ConsoleHandler.Verbose = verbose;
|
|
|
|
|
|
2018-08-27 15:07:51 +01:00
|
|
|
treeImagesItems = new TreeGridItemCollection();
|
|
|
|
|
|
2019-12-07 19:54:27 +00:00
|
|
|
treeImages.Columns.Add(new GridColumn
|
|
|
|
|
{
|
|
|
|
|
HeaderText = "Name", DataCell = new ImageTextCell(0, 1)
|
|
|
|
|
});
|
2018-08-27 15:07:51 +01:00
|
|
|
|
|
|
|
|
treeImages.AllowMultipleSelection = false;
|
|
|
|
|
treeImages.ShowHeader = false;
|
|
|
|
|
treeImages.DataStore = treeImagesItems;
|
|
|
|
|
|
2018-10-08 00:14:03 +01:00
|
|
|
// TODO: SVG
|
|
|
|
|
imagesIcon =
|
2019-12-07 19:54:27 +00:00
|
|
|
new Bitmap(ResourceHandler.
|
2020-02-27 13:57:32 +00:00
|
|
|
GetResourceStream("Aaru.Gui.Assets.Icons.oxygen._32x32.inode-directory.png"));
|
2019-12-07 19:54:27 +00:00
|
|
|
|
2018-10-08 00:14:03 +01:00
|
|
|
devicesIcon =
|
2020-02-29 18:03:35 +00:00
|
|
|
new Bitmap(ResourceHandler.GetResourceStream("Aaru.Gui.Assets.Icons.oxygen._32x32.computer.png"));
|
2019-12-07 19:54:27 +00:00
|
|
|
|
2018-10-08 00:14:03 +01:00
|
|
|
hardDiskIcon =
|
2020-02-29 18:03:35 +00:00
|
|
|
new Bitmap(ResourceHandler.GetResourceStream("Aaru.Gui.Assets.Icons.oxygen._32x32.drive-harddisk.png"));
|
2019-12-07 19:54:27 +00:00
|
|
|
|
2018-10-08 00:14:03 +01:00
|
|
|
opticalIcon =
|
2020-02-29 18:03:35 +00:00
|
|
|
new Bitmap(ResourceHandler.GetResourceStream("Aaru.Gui.Assets.Icons.oxygen._32x32.drive-optical.png"));
|
2019-12-07 19:54:27 +00:00
|
|
|
|
2018-10-08 00:14:03 +01:00
|
|
|
usbIcon =
|
2019-12-07 19:54:27 +00:00
|
|
|
new Bitmap(ResourceHandler.
|
2020-02-27 13:57:32 +00:00
|
|
|
GetResourceStream("Aaru.Gui.Assets.Icons.oxygen._32x32.drive-removable-media-usb.png"));
|
2019-12-07 19:54:27 +00:00
|
|
|
|
2018-10-08 00:14:03 +01:00
|
|
|
removableIcon =
|
2019-12-07 19:54:27 +00:00
|
|
|
new Bitmap(ResourceHandler.
|
2020-02-27 13:57:32 +00:00
|
|
|
GetResourceStream("Aaru.Gui.Assets.Icons.oxygen._32x32.drive-removable-media.png"));
|
2019-12-07 19:54:27 +00:00
|
|
|
|
2018-10-08 00:14:03 +01:00
|
|
|
sdIcon =
|
2019-12-07 19:54:27 +00:00
|
|
|
new Bitmap(ResourceHandler.
|
2020-02-27 13:57:32 +00:00
|
|
|
GetResourceStream("Aaru.Gui.Assets.Icons.oxygen._32x32.media-flash-sd-mmc.png"));
|
2019-12-07 19:54:27 +00:00
|
|
|
|
2018-10-08 00:14:03 +01:00
|
|
|
tapeIcon =
|
2020-02-29 18:03:35 +00:00
|
|
|
new Bitmap(ResourceHandler.GetResourceStream("Aaru.Gui.Assets.Icons.oxygen._32x32.media-tape.png"));
|
2019-12-07 19:54:27 +00:00
|
|
|
|
2018-10-08 00:14:03 +01:00
|
|
|
ejectIcon =
|
2020-02-29 18:03:35 +00:00
|
|
|
new Bitmap(ResourceHandler.GetResourceStream("Aaru.Gui.Assets.Icons.oxygen._32x32.media-eject.png"));
|
2019-12-07 19:54:27 +00:00
|
|
|
|
|
|
|
|
imagesRoot = new TreeGridItem
|
|
|
|
|
{
|
|
|
|
|
Values = new object[]
|
|
|
|
|
{
|
|
|
|
|
imagesIcon, "Images"
|
|
|
|
|
}
|
|
|
|
|
};
|
2018-10-08 00:14:03 +01:00
|
|
|
|
2019-12-07 19:54:27 +00:00
|
|
|
devicesRoot = new TreeGridItem
|
|
|
|
|
{
|
|
|
|
|
Values = new object[]
|
|
|
|
|
{
|
|
|
|
|
devicesIcon, "Devices"
|
|
|
|
|
}
|
|
|
|
|
};
|
2018-08-27 15:07:51 +01:00
|
|
|
|
|
|
|
|
treeImagesItems.Add(imagesRoot);
|
|
|
|
|
treeImagesItems.Add(devicesRoot);
|
2018-08-27 18:25:11 +01:00
|
|
|
|
2019-12-07 19:54:27 +00:00
|
|
|
placeholderItem = new TreeGridItem
|
|
|
|
|
{
|
|
|
|
|
Values = new object[]
|
|
|
|
|
{
|
|
|
|
|
nullImage, "You should not be seeing this"
|
|
|
|
|
}
|
|
|
|
|
};
|
2018-09-06 22:27:58 +01:00
|
|
|
|
2018-08-27 18:25:11 +01:00
|
|
|
Closing += OnClosing;
|
2018-11-17 00:06:50 +00:00
|
|
|
|
|
|
|
|
treeImagesMenu = new ContextMenu();
|
|
|
|
|
treeImagesMenu.Opening += OnTreeImagesMenuOpening;
|
|
|
|
|
treeImages.ContextMenu = treeImagesMenu;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OnTreeImagesMenuOpening(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
OnTreeImagesSelectedItemChanged(treeImages, e);
|
|
|
|
|
|
|
|
|
|
treeImagesMenu.Items.Clear();
|
2019-12-07 19:54:27 +00:00
|
|
|
|
|
|
|
|
var menuItem = new ButtonMenuItem
|
|
|
|
|
{
|
|
|
|
|
Text = "Close all images"
|
|
|
|
|
};
|
|
|
|
|
|
2018-11-17 00:06:50 +00:00
|
|
|
menuItem.Click += CloseAllImages;
|
|
|
|
|
treeImagesMenu.Items.Add(menuItem);
|
2019-12-07 19:54:27 +00:00
|
|
|
|
|
|
|
|
menuItem = new ButtonMenuItem
|
|
|
|
|
{
|
|
|
|
|
Text = "Refresh devices"
|
|
|
|
|
};
|
|
|
|
|
|
2018-11-17 00:06:50 +00:00
|
|
|
menuItem.Click += OnDeviceRefresh;
|
|
|
|
|
treeImagesMenu.Items.Add(menuItem);
|
|
|
|
|
|
2019-12-07 19:54:27 +00:00
|
|
|
if(!(treeImages.SelectedItem is TreeGridItem selectedItem))
|
|
|
|
|
return;
|
2018-11-17 00:06:50 +00:00
|
|
|
|
2019-12-07 19:54:27 +00:00
|
|
|
if(selectedItem.Values.Length < 4)
|
|
|
|
|
return;
|
2018-11-17 00:06:50 +00:00
|
|
|
}
|
|
|
|
|
|
2019-12-07 19:54:27 +00:00
|
|
|
// TODO
|
2020-04-10 18:52:50 +01:00
|
|
|
void CloseAllImages(object sender, EventArgs eventArgs) => Eto.Forms.MessageBox.Show("Not yet implemented");
|
2018-08-27 18:25:11 +01:00
|
|
|
|
|
|
|
|
void OnClosing(object sender, CancelEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// This prevents an infinite loop of crashes :p
|
2019-12-07 19:54:27 +00:00
|
|
|
if(closing)
|
|
|
|
|
return;
|
2018-08-27 18:25:11 +01:00
|
|
|
|
|
|
|
|
closing = true;
|
|
|
|
|
Application.Instance.Quit();
|
2018-08-27 15:07:51 +01:00
|
|
|
}
|
|
|
|
|
|
2019-12-07 19:54:27 +00:00
|
|
|
protected void OnDeviceRefresh(object sender, EventArgs e) => RefreshDevices();
|
2018-08-27 15:07:51 +01:00
|
|
|
|
|
|
|
|
protected override void OnLoadComplete(EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnLoadComplete(e);
|
|
|
|
|
|
|
|
|
|
RefreshDevices();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RefreshDevices()
|
|
|
|
|
{
|
2018-08-27 22:03:20 +01:00
|
|
|
try
|
2018-08-27 15:07:51 +01:00
|
|
|
{
|
2020-02-27 23:48:41 +00:00
|
|
|
AaruConsole.WriteLine("Refreshing devices");
|
2018-08-27 22:03:20 +01:00
|
|
|
devicesRoot.Children.Clear();
|
|
|
|
|
|
2019-12-07 19:54:27 +00:00
|
|
|
foreach(DeviceInfo device in Device.ListDevices().Where(d => d.Supported).OrderBy(d => d.Vendor).
|
|
|
|
|
ThenBy(d => d.Model))
|
2018-08-27 15:07:51 +01:00
|
|
|
{
|
2020-02-27 23:48:41 +00:00
|
|
|
AaruConsole.DebugWriteLine("Main window",
|
2020-02-29 18:03:35 +00:00
|
|
|
"Found supported device model {0} by manufacturer {1} on bus {2} and path {3}",
|
|
|
|
|
device.Model, device.Vendor, device.Bus, device.Path);
|
2018-09-06 22:27:58 +01:00
|
|
|
|
2019-12-07 19:54:27 +00:00
|
|
|
var devItem = new TreeGridItem
|
2018-08-27 22:03:20 +01:00
|
|
|
{
|
2018-10-07 23:29:28 +01:00
|
|
|
Values = new object[]
|
|
|
|
|
{
|
2018-10-08 00:14:03 +01:00
|
|
|
hardDiskIcon, $"{device.Vendor} {device.Model} ({device.Bus})", device.Path, null
|
2018-10-07 23:29:28 +01:00
|
|
|
}
|
2018-09-06 22:27:58 +01:00
|
|
|
};
|
2018-10-08 00:14:03 +01:00
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2019-12-07 19:54:27 +00:00
|
|
|
var dev = new Device(device.Path);
|
|
|
|
|
|
|
|
|
|
if(dev.IsRemote)
|
|
|
|
|
Statistics.AddRemote(dev.RemoteApplication, dev.RemoteVersion, dev.RemoteOperatingSystem,
|
|
|
|
|
dev.RemoteOperatingSystemVersion, dev.RemoteArchitecture);
|
2018-10-08 00:14:03 +01:00
|
|
|
|
|
|
|
|
switch(dev.Type)
|
|
|
|
|
{
|
|
|
|
|
case DeviceType.ATAPI:
|
|
|
|
|
case DeviceType.SCSI:
|
|
|
|
|
switch(dev.ScsiType)
|
|
|
|
|
{
|
|
|
|
|
case PeripheralDeviceTypes.DirectAccess:
|
|
|
|
|
case PeripheralDeviceTypes.SCSIZonedBlockDevice:
|
|
|
|
|
case PeripheralDeviceTypes.SimplifiedDevice:
|
2019-12-07 19:54:27 +00:00
|
|
|
devItem.Values[0] = dev.IsRemovable ? dev.IsUsb
|
|
|
|
|
? usbIcon
|
|
|
|
|
: removableIcon : hardDiskIcon;
|
|
|
|
|
|
2018-10-08 00:14:03 +01:00
|
|
|
break;
|
|
|
|
|
case PeripheralDeviceTypes.SequentialAccess:
|
|
|
|
|
devItem.Values[0] = tapeIcon;
|
2019-12-07 19:54:27 +00:00
|
|
|
|
2018-10-08 00:14:03 +01:00
|
|
|
break;
|
|
|
|
|
case PeripheralDeviceTypes.OpticalDevice:
|
|
|
|
|
case PeripheralDeviceTypes.WriteOnceDevice:
|
|
|
|
|
case PeripheralDeviceTypes.OCRWDevice:
|
|
|
|
|
devItem.Values[0] = removableIcon;
|
2019-12-07 19:54:27 +00:00
|
|
|
|
2018-10-08 00:14:03 +01:00
|
|
|
break;
|
|
|
|
|
case PeripheralDeviceTypes.MultiMediaDevice:
|
|
|
|
|
devItem.Values[0] = opticalIcon;
|
2019-12-07 19:54:27 +00:00
|
|
|
|
2018-10-08 00:14:03 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case DeviceType.SecureDigital:
|
|
|
|
|
case DeviceType.MMC:
|
|
|
|
|
devItem.Values[0] = sdIcon;
|
2019-12-07 19:54:27 +00:00
|
|
|
|
2018-10-08 00:14:03 +01:00
|
|
|
break;
|
|
|
|
|
case DeviceType.NVMe:
|
|
|
|
|
devItem.Values[0] = nullImage;
|
2019-12-07 19:54:27 +00:00
|
|
|
|
2018-10-08 00:14:03 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dev.Close();
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// ignored
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-06 22:27:58 +01:00
|
|
|
devItem.Children.Add(placeholderItem);
|
|
|
|
|
devicesRoot.Children.Add(devItem);
|
2018-08-27 22:03:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
treeImages.ReloadData();
|
|
|
|
|
}
|
2019-12-07 19:54:27 +00:00
|
|
|
catch(InvalidOperationException ex)
|
|
|
|
|
{
|
2020-02-27 23:48:41 +00:00
|
|
|
AaruConsole.ErrorWriteLine(ex.Message);
|
2019-12-07 19:54:27 +00:00
|
|
|
}
|
2018-08-27 15:07:51 +01:00
|
|
|
}
|
|
|
|
|
|
2018-09-02 01:41:03 +01:00
|
|
|
protected void OnTreeImagesSelectedItemChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2019-12-07 19:54:27 +00:00
|
|
|
if(!(sender is TreeGridView tree))
|
|
|
|
|
return;
|
2018-09-02 01:41:03 +01:00
|
|
|
|
2019-12-07 19:54:27 +00:00
|
|
|
if(!(tree.SelectedItem is TreeGridItem selectedItem))
|
|
|
|
|
return;
|
2018-09-02 01:41:03 +01:00
|
|
|
|
|
|
|
|
splMain.Panel2 = null;
|
|
|
|
|
|
2019-12-07 19:54:27 +00:00
|
|
|
if(selectedItem.Values.Length >= 4 &&
|
|
|
|
|
selectedItem.Values[3] is Panel infoPanel)
|
2018-09-09 01:00:54 +01:00
|
|
|
{
|
|
|
|
|
splMain.Panel2 = infoPanel;
|
2019-12-07 19:54:27 +00:00
|
|
|
|
2018-09-09 01:00:54 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-07 19:54:27 +00:00
|
|
|
if(selectedItem.Values.Length < 4)
|
|
|
|
|
return;
|
2018-09-02 01:41:03 +01:00
|
|
|
|
2018-10-07 23:29:28 +01:00
|
|
|
switch(selectedItem.Values[3])
|
2018-09-02 01:41:03 +01:00
|
|
|
{
|
2018-10-24 23:16:45 +01:00
|
|
|
case null when selectedItem.Parent == devicesRoot:
|
2018-09-02 01:41:03 +01:00
|
|
|
try
|
|
|
|
|
{
|
2019-12-07 19:54:27 +00:00
|
|
|
var dev = new Device((string)selectedItem.Values[2]);
|
|
|
|
|
|
|
|
|
|
if(dev.IsRemote)
|
|
|
|
|
Statistics.AddRemote(dev.RemoteApplication, dev.RemoteVersion, dev.RemoteOperatingSystem,
|
|
|
|
|
dev.RemoteOperatingSystemVersion, dev.RemoteArchitecture);
|
|
|
|
|
|
2018-09-02 01:41:03 +01:00
|
|
|
if(dev.Error)
|
|
|
|
|
{
|
2018-10-07 23:29:28 +01:00
|
|
|
selectedItem.Values[3] = $"Error {dev.LastError} opening device";
|
2019-12-07 19:54:27 +00:00
|
|
|
|
2018-09-02 01:41:03 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-07 19:54:27 +00:00
|
|
|
var devInfo = new Core.Devices.Info.DeviceInfo(dev);
|
2018-09-02 01:41:03 +01:00
|
|
|
|
2018-10-07 23:29:28 +01:00
|
|
|
selectedItem.Values[3] = new pnlDeviceInfo(devInfo);
|
|
|
|
|
splMain.Panel2 = (Panel)selectedItem.Values[3];
|
2018-09-02 01:41:03 +01:00
|
|
|
|
|
|
|
|
dev.Close();
|
|
|
|
|
}
|
|
|
|
|
catch(SystemException ex)
|
|
|
|
|
{
|
2018-10-07 23:29:28 +01:00
|
|
|
selectedItem.Values[3] = ex.Message;
|
2018-09-02 01:41:03 +01:00
|
|
|
lblError.Text = ex.Message;
|
|
|
|
|
splMain.Panel2 = lblError;
|
2020-02-27 23:48:41 +00:00
|
|
|
AaruConsole.ErrorWriteLine(ex.Message);
|
2018-09-02 01:41:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
2018-10-24 23:16:45 +01:00
|
|
|
case string devErrorMessage when selectedItem.Parent == devicesRoot:
|
2018-09-02 01:41:03 +01:00
|
|
|
lblError.Text = devErrorMessage;
|
|
|
|
|
splMain.Panel2 = lblError;
|
2019-12-07 19:54:27 +00:00
|
|
|
|
2019-04-19 14:55:31 +01:00
|
|
|
break;
|
2018-09-02 01:41:03 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-06 22:27:58 +01:00
|
|
|
protected void OnTreeImagesItemExpanding(object sender, TreeGridViewItemCancelEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// First expansion of a device
|
2018-10-24 23:16:45 +01:00
|
|
|
if((e.Item as TreeGridItem)?.Children?.Count != 1 ||
|
2019-12-07 19:54:27 +00:00
|
|
|
((TreeGridItem)e.Item).Children[0] != placeholderItem)
|
|
|
|
|
return;
|
2018-10-24 23:16:45 +01:00
|
|
|
|
|
|
|
|
if(((TreeGridItem)e.Item).Parent == devicesRoot)
|
2018-09-06 22:27:58 +01:00
|
|
|
{
|
2019-12-07 19:54:27 +00:00
|
|
|
var deviceItem = (TreeGridItem)e.Item;
|
2018-09-06 22:27:58 +01:00
|
|
|
|
|
|
|
|
deviceItem.Children.Clear();
|
|
|
|
|
Device dev;
|
2019-12-07 19:54:27 +00:00
|
|
|
|
2018-09-06 22:27:58 +01:00
|
|
|
try
|
|
|
|
|
{
|
2018-10-07 23:29:28 +01:00
|
|
|
dev = new Device((string)deviceItem.Values[2]);
|
2019-12-07 19:54:27 +00:00
|
|
|
|
|
|
|
|
if(dev.IsRemote)
|
|
|
|
|
Statistics.AddRemote(dev.RemoteApplication, dev.RemoteVersion, dev.RemoteOperatingSystem,
|
|
|
|
|
dev.RemoteOperatingSystemVersion, dev.RemoteArchitecture);
|
|
|
|
|
|
2018-09-06 22:27:58 +01:00
|
|
|
if(dev.Error)
|
|
|
|
|
{
|
2018-10-07 23:29:28 +01:00
|
|
|
deviceItem.Values[3] = $"Error {dev.LastError} opening device";
|
2018-09-06 22:27:58 +01:00
|
|
|
e.Cancel = true;
|
|
|
|
|
treeImages.ReloadData();
|
|
|
|
|
treeImages.SelectedItem = deviceItem;
|
2019-12-07 19:54:27 +00:00
|
|
|
|
2018-09-06 22:27:58 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch(SystemException ex)
|
|
|
|
|
{
|
2018-10-07 23:29:28 +01:00
|
|
|
deviceItem.Values[3] = ex.Message;
|
2018-09-06 22:27:58 +01:00
|
|
|
e.Cancel = true;
|
|
|
|
|
treeImages.ReloadData();
|
2020-02-27 23:48:41 +00:00
|
|
|
AaruConsole.ErrorWriteLine(ex.Message);
|
2018-09-06 22:27:58 +01:00
|
|
|
treeImages.SelectedItem = deviceItem;
|
2019-12-07 19:54:27 +00:00
|
|
|
|
2018-09-06 22:27:58 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!dev.IsRemovable)
|
|
|
|
|
deviceItem.Children.Add(new TreeGridItem
|
|
|
|
|
{
|
|
|
|
|
Values = new object[]
|
|
|
|
|
{
|
2019-12-07 19:54:27 +00:00
|
|
|
nullImage, "Non-removable device commands not yet implemented"
|
2018-09-06 22:27:58 +01:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
else
|
2018-09-09 01:00:54 +01:00
|
|
|
{
|
|
|
|
|
// TODO: Removable non-SCSI?
|
2019-12-07 19:54:27 +00:00
|
|
|
var scsiInfo = new ScsiInfo(dev);
|
2018-09-09 01:00:54 +01:00
|
|
|
|
|
|
|
|
if(!scsiInfo.MediaInserted)
|
2018-10-07 23:29:28 +01:00
|
|
|
deviceItem.Children.Add(new TreeGridItem
|
|
|
|
|
{
|
2019-12-07 19:54:27 +00:00
|
|
|
Values = new object[]
|
|
|
|
|
{
|
|
|
|
|
ejectIcon, "No media inserted"
|
|
|
|
|
}
|
2018-10-07 23:29:28 +01:00
|
|
|
});
|
2018-09-09 01:00:54 +01:00
|
|
|
else
|
2018-10-07 23:29:28 +01:00
|
|
|
{
|
|
|
|
|
// TODO: SVG
|
|
|
|
|
Stream logo =
|
2020-02-29 18:03:35 +00:00
|
|
|
ResourceHandler.GetResourceStream($"Aaru.Gui.Assets.Logos.Media.{scsiInfo.MediaType}.png");
|
2018-10-07 23:29:28 +01:00
|
|
|
|
2018-09-09 01:00:54 +01:00
|
|
|
deviceItem.Children.Add(new TreeGridItem
|
2018-09-06 22:27:58 +01:00
|
|
|
{
|
2018-09-09 01:00:54 +01:00
|
|
|
Values = new[]
|
|
|
|
|
{
|
2019-12-07 19:54:27 +00:00
|
|
|
logo == null ? null : new Bitmap(logo), scsiInfo.MediaType, deviceItem.Values[2],
|
2018-10-07 23:29:28 +01:00
|
|
|
new pnlScsiInfo(scsiInfo, (string)deviceItem.Values[2])
|
2018-09-09 01:00:54 +01:00
|
|
|
}
|
|
|
|
|
});
|
2018-10-07 23:29:28 +01:00
|
|
|
}
|
2018-09-09 01:00:54 +01:00
|
|
|
}
|
2018-09-06 22:27:58 +01:00
|
|
|
|
|
|
|
|
dev.Close();
|
|
|
|
|
}
|
2018-10-24 23:16:45 +01:00
|
|
|
else if(((TreeGridItem)e.Item).Values[2] is IReadOnlyFilesystem fsPlugin)
|
|
|
|
|
{
|
2019-12-07 19:54:27 +00:00
|
|
|
var fsItem = (TreeGridItem)e.Item;
|
2018-10-24 23:16:45 +01:00
|
|
|
|
|
|
|
|
fsItem.Children.Clear();
|
|
|
|
|
|
2019-12-07 19:54:27 +00:00
|
|
|
if(fsItem.Values.Length == 5 &&
|
|
|
|
|
fsItem.Values[4] is string dirPath)
|
2018-10-24 23:16:45 +01:00
|
|
|
{
|
|
|
|
|
Errno errno = fsPlugin.ReadDir(dirPath, out List<string> dirents);
|
|
|
|
|
|
|
|
|
|
if(errno != Errno.NoError)
|
|
|
|
|
{
|
2020-04-10 18:52:50 +01:00
|
|
|
Eto.Forms.MessageBox.Show($"Error {errno} trying to read \"{dirPath}\" of chosen filesystem",
|
|
|
|
|
MessageBoxType.Error);
|
2019-12-07 19:54:27 +00:00
|
|
|
|
2018-10-24 23:16:45 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-19 14:55:31 +01:00
|
|
|
List<string> directories = new List<string>();
|
2018-10-24 23:16:45 +01:00
|
|
|
|
|
|
|
|
foreach(string dirent in dirents)
|
|
|
|
|
{
|
|
|
|
|
errno = fsPlugin.Stat(dirPath + "/" + dirent, out FileEntryInfo stat);
|
|
|
|
|
|
|
|
|
|
if(errno != Errno.NoError)
|
|
|
|
|
{
|
2020-02-27 23:48:41 +00:00
|
|
|
AaruConsole.
|
2019-12-07 19:54:27 +00:00
|
|
|
ErrorWriteLine($"Error {errno} trying to get information about filesystem entry named {dirent}");
|
|
|
|
|
|
2018-10-24 23:16:45 +01:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-07 19:54:27 +00:00
|
|
|
if(stat.Attributes.HasFlag(FileAttributes.Directory))
|
|
|
|
|
directories.Add(dirent);
|
2018-10-24 23:16:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach(string directory in directories)
|
|
|
|
|
{
|
2019-12-07 19:54:27 +00:00
|
|
|
var dirItem = new TreeGridItem
|
2018-10-24 23:16:45 +01:00
|
|
|
{
|
2019-12-07 19:54:27 +00:00
|
|
|
Values = new object[]
|
|
|
|
|
{
|
|
|
|
|
imagesIcon, directory, fsPlugin, null, dirPath + "/" + directory
|
|
|
|
|
}
|
2018-10-24 23:16:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
dirItem.Children.Add(placeholderItem);
|
|
|
|
|
fsItem.Children.Add(dirItem);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Errno errno = fsPlugin.ReadDir("/", out List<string> dirents);
|
|
|
|
|
|
|
|
|
|
if(errno != Errno.NoError)
|
|
|
|
|
{
|
2020-04-10 18:52:50 +01:00
|
|
|
Eto.Forms.MessageBox.Show($"Error {errno} trying to read root directory of chosen filesystem",
|
|
|
|
|
MessageBoxType.Error);
|
2019-12-07 19:54:27 +00:00
|
|
|
|
2018-10-24 23:16:45 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Dictionary<string, FileEntryInfo> files = new Dictionary<string, FileEntryInfo>();
|
|
|
|
|
List<string> directories = new List<string>();
|
|
|
|
|
|
|
|
|
|
foreach(string dirent in dirents)
|
|
|
|
|
{
|
|
|
|
|
errno = fsPlugin.Stat("/" + dirent, out FileEntryInfo stat);
|
|
|
|
|
|
|
|
|
|
if(errno != Errno.NoError)
|
|
|
|
|
{
|
2020-02-27 23:48:41 +00:00
|
|
|
AaruConsole.
|
2019-12-07 19:54:27 +00:00
|
|
|
ErrorWriteLine($"Error {errno} trying to get information about filesystem entry named {dirent}");
|
|
|
|
|
|
2018-10-24 23:16:45 +01:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-07 19:54:27 +00:00
|
|
|
if(stat.Attributes.HasFlag(FileAttributes.Directory))
|
|
|
|
|
directories.Add(dirent);
|
|
|
|
|
else
|
|
|
|
|
files.Add(dirent, stat);
|
2018-10-24 23:16:45 +01:00
|
|
|
}
|
|
|
|
|
|
2019-12-07 19:54:27 +00:00
|
|
|
var rootDirectoryItem = new TreeGridItem
|
2018-10-24 23:16:45 +01:00
|
|
|
{
|
|
|
|
|
Values = new object[]
|
|
|
|
|
{
|
|
|
|
|
nullImage, // TODO: Get icon from volume
|
|
|
|
|
"/", fsPlugin, files
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
foreach(string directory in directories)
|
|
|
|
|
{
|
2019-12-07 19:54:27 +00:00
|
|
|
var dirItem = new TreeGridItem
|
2018-10-24 23:16:45 +01:00
|
|
|
{
|
2019-12-07 19:54:27 +00:00
|
|
|
Values = new object[]
|
|
|
|
|
{
|
|
|
|
|
imagesIcon, directory, fsPlugin, null, "/" + directory
|
|
|
|
|
}
|
2018-10-24 23:16:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
dirItem.Children.Add(placeholderItem);
|
|
|
|
|
rootDirectoryItem.Children.Add(dirItem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fsItem.Children.Add(rootDirectoryItem);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-06 22:27:58 +01:00
|
|
|
}
|
|
|
|
|
|
2018-08-27 15:07:51 +01:00
|
|
|
#region XAML IDs
|
2019-12-07 19:54:27 +00:00
|
|
|
readonly TreeGridItem devicesRoot;
|
|
|
|
|
readonly TreeGridItem imagesRoot;
|
|
|
|
|
Splitter splMain;
|
2018-08-27 15:07:51 +01:00
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|