mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
[GUI] Add Save USB Descriptors functionality to DeviceViewModel
This commit is contained in:
@@ -31,6 +31,7 @@
|
|||||||
// ****************************************************************************/
|
// ****************************************************************************/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using Aaru.CommonTypes.Enums;
|
using Aaru.CommonTypes.Enums;
|
||||||
@@ -42,134 +43,137 @@ using Aaru.Gui.Views.Tabs;
|
|||||||
using Aaru.Gui.Views.Windows;
|
using Aaru.Gui.Views.Windows;
|
||||||
using Aaru.Localization;
|
using Aaru.Localization;
|
||||||
using Aaru.Logging;
|
using Aaru.Logging;
|
||||||
|
using Avalonia.Platform.Storage;
|
||||||
using Avalonia.Threading;
|
using Avalonia.Threading;
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
using CommunityToolkit.Mvvm.Input;
|
||||||
using Humanizer;
|
using Humanizer;
|
||||||
using Humanizer.Localisation;
|
using Humanizer.Localisation;
|
||||||
using MsBox.Avalonia;
|
using MsBox.Avalonia;
|
||||||
using MsBox.Avalonia.Base;
|
using MsBox.Avalonia.Base;
|
||||||
using MsBox.Avalonia.Enums;
|
using MsBox.Avalonia.Enums;
|
||||||
|
using DeviceInfo = Aaru.Core.Devices.Info.DeviceInfo;
|
||||||
|
|
||||||
namespace Aaru.Gui.ViewModels.Windows;
|
namespace Aaru.Gui.ViewModels.Windows;
|
||||||
|
|
||||||
public partial class DeviceViewModel : ViewModelBase
|
public partial class DeviceViewModel : ViewModelBase
|
||||||
{
|
{
|
||||||
readonly DeviceView _window;
|
readonly DeviceView _window;
|
||||||
Device _dev;
|
[ObservableProperty]
|
||||||
|
AtaInfo _ataInfo;
|
||||||
|
[ObservableProperty]
|
||||||
|
bool _blockLimits;
|
||||||
|
[ObservableProperty]
|
||||||
|
string _blockSizeGranularity;
|
||||||
|
[ObservableProperty]
|
||||||
|
string _densities;
|
||||||
|
Device _dev;
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
string _devicePath;
|
string _devicePath;
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
string _deviceType;
|
string _deviceType;
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
|
string _firewireGuid;
|
||||||
|
[ObservableProperty]
|
||||||
|
string _firewireManufacturer;
|
||||||
|
[ObservableProperty]
|
||||||
|
string _firewireModel;
|
||||||
|
[ObservableProperty]
|
||||||
|
string _firewireModelId;
|
||||||
|
[ObservableProperty]
|
||||||
|
string _firewireVendorId;
|
||||||
|
[ObservableProperty]
|
||||||
|
bool _firewireVisible;
|
||||||
|
[ObservableProperty]
|
||||||
|
bool _kreon;
|
||||||
|
[ObservableProperty]
|
||||||
|
bool _kreonChallengeResponse;
|
||||||
|
[ObservableProperty]
|
||||||
|
bool _kreonChallengeResponse360;
|
||||||
|
[ObservableProperty]
|
||||||
|
bool _kreonDecryptSs;
|
||||||
|
[ObservableProperty]
|
||||||
|
bool _kreonDecryptSs360;
|
||||||
|
[ObservableProperty]
|
||||||
|
bool _kreonErrorSkipping;
|
||||||
|
[ObservableProperty]
|
||||||
|
bool _kreonLock;
|
||||||
|
[ObservableProperty]
|
||||||
|
bool _kreonWxripperUnlock;
|
||||||
|
[ObservableProperty]
|
||||||
|
bool _kreonWxripperUnlock360;
|
||||||
|
[ObservableProperty]
|
||||||
|
bool _kreonXtremeUnlock;
|
||||||
|
[ObservableProperty]
|
||||||
|
bool _kreonXtremeUnlock360;
|
||||||
|
[ObservableProperty]
|
||||||
string _manufacturer;
|
string _manufacturer;
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
|
string _maxBlockSize;
|
||||||
|
[ObservableProperty]
|
||||||
|
string _mediumDensity;
|
||||||
|
[ObservableProperty]
|
||||||
|
string _mediumTypes;
|
||||||
|
[ObservableProperty]
|
||||||
|
string _minBlockSize;
|
||||||
|
[ObservableProperty]
|
||||||
string _model;
|
string _model;
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
bool _removableChecked;
|
PcmciaInfo _pcmciaInfo;
|
||||||
[ObservableProperty]
|
|
||||||
string _revision;
|
|
||||||
[ObservableProperty]
|
|
||||||
string _scsiType;
|
|
||||||
[ObservableProperty]
|
|
||||||
string _serial;
|
|
||||||
[ObservableProperty]
|
|
||||||
string _statusMessage;
|
|
||||||
[ObservableProperty]
|
|
||||||
bool _usbConnected;
|
|
||||||
[ObservableProperty]
|
|
||||||
bool _usbVisible;
|
|
||||||
[ObservableProperty]
|
|
||||||
string _usbVendorId;
|
|
||||||
[ObservableProperty]
|
|
||||||
string _usbProductId;
|
|
||||||
[ObservableProperty]
|
|
||||||
string _usbManufacturer;
|
|
||||||
[ObservableProperty]
|
|
||||||
string _usbProduct;
|
|
||||||
[ObservableProperty]
|
|
||||||
string _usbSerial;
|
|
||||||
[ObservableProperty]
|
|
||||||
bool _saveUsbDescriptorsEnabled;
|
|
||||||
[ObservableProperty]
|
|
||||||
bool _firewireVisible;
|
|
||||||
[ObservableProperty]
|
|
||||||
string _firewireVendorId;
|
|
||||||
[ObservableProperty]
|
|
||||||
string _firewireModelId;
|
|
||||||
[ObservableProperty]
|
|
||||||
string _firewireManufacturer;
|
|
||||||
[ObservableProperty]
|
|
||||||
string _firewireModel;
|
|
||||||
[ObservableProperty]
|
|
||||||
string _firewireGuid;
|
|
||||||
[ObservableProperty]
|
|
||||||
bool _plextorVisible;
|
|
||||||
[ObservableProperty]
|
|
||||||
bool _plextorEepromVisible;
|
|
||||||
[ObservableProperty]
|
|
||||||
bool _plextorDvdTimesVisible;
|
|
||||||
[ObservableProperty]
|
|
||||||
bool _plextorPoweRec;
|
|
||||||
[ObservableProperty]
|
|
||||||
bool _plextorPoweRecEnabled;
|
|
||||||
[ObservableProperty]
|
|
||||||
bool _plextorPoweRecRecommendedVisible;
|
|
||||||
[ObservableProperty]
|
|
||||||
bool _plextorPoweRecSelectedVisible;
|
|
||||||
[ObservableProperty]
|
|
||||||
bool _plextorPoweRecMaxVisible;
|
|
||||||
[ObservableProperty]
|
|
||||||
bool _plextorPoweRecLastVisible;
|
|
||||||
[ObservableProperty]
|
|
||||||
bool _plextorSilentMode;
|
|
||||||
[ObservableProperty]
|
|
||||||
bool _plextorSilentModeEnabled;
|
|
||||||
[ObservableProperty]
|
|
||||||
bool _plextorSilentModeDvdReadSpeedLimitVisible;
|
|
||||||
[ObservableProperty]
|
|
||||||
bool _plextorGigaRec;
|
|
||||||
[ObservableProperty]
|
|
||||||
bool _plextorSecuRec;
|
|
||||||
[ObservableProperty]
|
|
||||||
bool _plextorSpeedRead;
|
|
||||||
[ObservableProperty]
|
|
||||||
bool _plextorSpeedEnabled;
|
|
||||||
[ObservableProperty]
|
|
||||||
bool _plextorHiding;
|
|
||||||
[ObservableProperty]
|
|
||||||
bool _plextorHidesRecordables;
|
|
||||||
[ObservableProperty]
|
|
||||||
bool _plextorHidesSessions;
|
|
||||||
[ObservableProperty]
|
|
||||||
bool _plextorVariRec;
|
|
||||||
[ObservableProperty]
|
|
||||||
bool _plextorDvd;
|
|
||||||
[ObservableProperty]
|
|
||||||
bool _plextorVariRecDvd;
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
bool _plextorBitSetting;
|
bool _plextorBitSetting;
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
bool _plextorBitSettingDl;
|
bool _plextorBitSettingDl;
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
bool _plextorDvdPlusWriteTest;
|
|
||||||
[ObservableProperty]
|
|
||||||
string _plextorDiscs;
|
|
||||||
[ObservableProperty]
|
|
||||||
string _plextorCdReadTime;
|
string _plextorCdReadTime;
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
string _plextorCdWriteTime;
|
string _plextorCdWriteTime;
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
|
string _plextorDiscs;
|
||||||
|
[ObservableProperty]
|
||||||
|
bool _plextorDvd;
|
||||||
|
[ObservableProperty]
|
||||||
|
bool _plextorDvdPlusWriteTest;
|
||||||
|
[ObservableProperty]
|
||||||
string _plextorDvdReadTime;
|
string _plextorDvdReadTime;
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
|
bool _plextorDvdTimesVisible;
|
||||||
|
[ObservableProperty]
|
||||||
string _plextorDvdWriteTime;
|
string _plextorDvdWriteTime;
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
string _plextorPoweRecRecommended;
|
bool _plextorEepromVisible;
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
string _plextorPoweRecSelected;
|
bool _plextorGigaRec;
|
||||||
|
[ObservableProperty]
|
||||||
|
bool _plextorHidesRecordables;
|
||||||
|
[ObservableProperty]
|
||||||
|
bool _plextorHidesSessions;
|
||||||
|
[ObservableProperty]
|
||||||
|
bool _plextorHiding;
|
||||||
|
[ObservableProperty]
|
||||||
|
bool _plextorPoweRec;
|
||||||
|
[ObservableProperty]
|
||||||
|
bool _plextorPoweRecEnabled;
|
||||||
|
[ObservableProperty]
|
||||||
|
string _plextorPoweRecLast;
|
||||||
|
[ObservableProperty]
|
||||||
|
bool _plextorPoweRecLastVisible;
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
string _plextorPoweRecMax;
|
string _plextorPoweRecMax;
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
string _plextorPoweRecLast;
|
bool _plextorPoweRecMaxVisible;
|
||||||
|
[ObservableProperty]
|
||||||
|
string _plextorPoweRecRecommended;
|
||||||
|
[ObservableProperty]
|
||||||
|
bool _plextorPoweRecRecommendedVisible;
|
||||||
|
[ObservableProperty]
|
||||||
|
string _plextorPoweRecSelected;
|
||||||
|
[ObservableProperty]
|
||||||
|
bool _plextorPoweRecSelectedVisible;
|
||||||
|
[ObservableProperty]
|
||||||
|
bool _plextorSecuRec;
|
||||||
|
[ObservableProperty]
|
||||||
|
bool _plextorSilentMode;
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
string _plextorSilentModeAccessTime;
|
string _plextorSilentModeAccessTime;
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
@@ -179,64 +183,82 @@ public partial class DeviceViewModel : ViewModelBase
|
|||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
string _plextorSilentModeDvdReadSpeedLimit;
|
string _plextorSilentModeDvdReadSpeedLimit;
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
bool _kreon;
|
bool _plextorSilentModeDvdReadSpeedLimitVisible;
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
bool _kreonChallengeResponse;
|
bool _plextorSilentModeEnabled;
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
bool _kreonDecryptSs;
|
bool _plextorSpeedEnabled;
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
bool _kreonXtremeUnlock;
|
bool _plextorSpeedRead;
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
bool _kreonWxripperUnlock;
|
bool _plextorVariRec;
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
bool _kreonChallengeResponse360;
|
bool _plextorVariRecDvd;
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
bool _kreonDecryptSs360;
|
bool _plextorVisible;
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
bool _kreonXtremeUnlock360;
|
bool _removableChecked;
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
bool _kreonWxripperUnlock360;
|
string _revision;
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
bool _kreonLock;
|
bool _saveUsbDescriptorsEnabled;
|
||||||
[ObservableProperty]
|
|
||||||
bool _kreonErrorSkipping;
|
|
||||||
[ObservableProperty]
|
|
||||||
bool _ssc;
|
|
||||||
[ObservableProperty]
|
|
||||||
bool _blockLimits;
|
|
||||||
[ObservableProperty]
|
|
||||||
string _minBlockSize;
|
|
||||||
[ObservableProperty]
|
|
||||||
string _maxBlockSize;
|
|
||||||
[ObservableProperty]
|
|
||||||
string _blockSizeGranularity;
|
|
||||||
[ObservableProperty]
|
|
||||||
string _densities;
|
|
||||||
[ObservableProperty]
|
|
||||||
string _mediumTypes;
|
|
||||||
[ObservableProperty]
|
|
||||||
string _mediumDensity;
|
|
||||||
[ObservableProperty]
|
|
||||||
SdMmcInfo _sdMmcInfo;
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
ScsiInfo _scsiInfo;
|
ScsiInfo _scsiInfo;
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
PcmciaInfo _pcmciaInfo;
|
string _scsiType;
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
AtaInfo _ataInfo;
|
SdMmcInfo _sdMmcInfo;
|
||||||
|
[ObservableProperty]
|
||||||
|
string _serial;
|
||||||
|
[ObservableProperty]
|
||||||
|
bool _ssc;
|
||||||
|
[ObservableProperty]
|
||||||
|
string _statusMessage;
|
||||||
|
[ObservableProperty]
|
||||||
|
bool _usbConnected;
|
||||||
|
byte[] _usbDescriptors;
|
||||||
|
[ObservableProperty]
|
||||||
|
string _usbManufacturer;
|
||||||
|
[ObservableProperty]
|
||||||
|
string _usbProduct;
|
||||||
|
[ObservableProperty]
|
||||||
|
string _usbProductId;
|
||||||
|
[ObservableProperty]
|
||||||
|
string _usbSerial;
|
||||||
|
[ObservableProperty]
|
||||||
|
string _usbVendorId;
|
||||||
|
[ObservableProperty]
|
||||||
|
bool _usbVisible;
|
||||||
|
|
||||||
public DeviceViewModel(DeviceView window, string devicePath)
|
public DeviceViewModel(DeviceView window, string devicePath)
|
||||||
{
|
{
|
||||||
_window = window;
|
_window = window;
|
||||||
DevicePath = devicePath;
|
DevicePath = devicePath;
|
||||||
|
|
||||||
|
SaveUsbDescriptorsCommand = new AsyncRelayCommand(SaveUsbDescriptorsAsync);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ICommand SaveUsbDescriptorsCommand { get; }
|
||||||
|
|
||||||
public void LoadData()
|
public void LoadData()
|
||||||
{
|
{
|
||||||
_ = Task.Run(Worker);
|
_ = Task.Run(Worker);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICommand SaveUsbDescriptorsCommand { get; }
|
async Task SaveUsbDescriptorsAsync()
|
||||||
|
{
|
||||||
|
IStorageFile result = await _window.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions
|
||||||
|
{
|
||||||
|
FileTypeChoices = [FilePickerFileTypes.Binary]
|
||||||
|
});
|
||||||
|
|
||||||
|
if(result is null) return;
|
||||||
|
|
||||||
|
var saveFs = new FileStream(result.Path.AbsolutePath, FileMode.Create);
|
||||||
|
await saveFs.WriteAsync(_usbDescriptors, 0, _usbDescriptors.Length);
|
||||||
|
|
||||||
|
saveFs.Close();
|
||||||
|
}
|
||||||
|
|
||||||
void Worker()
|
void Worker()
|
||||||
{
|
{
|
||||||
@@ -299,20 +321,16 @@ public partial class DeviceViewModel : ViewModelBase
|
|||||||
|
|
||||||
Statistics.AddDevice(dev);
|
Statistics.AddDevice(dev);
|
||||||
|
|
||||||
Dispatcher.UIThread.Invoke(() =>
|
Dispatcher.UIThread.Invoke(() => { StatusMessage = "Querying device information..."; });
|
||||||
{
|
|
||||||
StatusMessage = "Querying device information...";
|
|
||||||
});
|
|
||||||
|
|
||||||
var devInfo = new Aaru.Core.Devices.Info.DeviceInfo(dev);
|
var devInfo = new DeviceInfo(dev);
|
||||||
|
|
||||||
Dispatcher.UIThread.Invoke(() =>
|
Dispatcher.UIThread.Invoke(() => { StatusMessage = "Device information queryied successfully..."; });
|
||||||
{
|
|
||||||
StatusMessage = "Device information queryied successfully...";
|
|
||||||
});
|
|
||||||
|
|
||||||
if(devInfo.IsUsb)
|
if(devInfo.IsUsb)
|
||||||
{
|
{
|
||||||
|
_usbDescriptors = devInfo.UsbDescriptors;
|
||||||
|
|
||||||
Dispatcher.UIThread.Invoke(() =>
|
Dispatcher.UIThread.Invoke(() =>
|
||||||
{
|
{
|
||||||
UsbVisible = true;
|
UsbVisible = true;
|
||||||
@@ -572,23 +590,31 @@ public partial class DeviceViewModel : ViewModelBase
|
|||||||
if(devInfo.DensitySupport != null)
|
if(devInfo.DensitySupport != null)
|
||||||
{
|
{
|
||||||
if(devInfo.DensitySupportHeader.HasValue)
|
if(devInfo.DensitySupportHeader.HasValue)
|
||||||
|
{
|
||||||
Dispatcher.UIThread.Invoke(() =>
|
Dispatcher.UIThread.Invoke(() =>
|
||||||
{
|
{
|
||||||
Densities = DensitySupport.PrettifyDensity(devInfo.DensitySupportHeader);
|
Densities =
|
||||||
|
DensitySupport.PrettifyDensity(devInfo.DensitySupportHeader);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(devInfo.MediumDensitySupport != null)
|
if(devInfo.MediumDensitySupport != null)
|
||||||
{
|
{
|
||||||
if(devInfo.MediaTypeSupportHeader.HasValue)
|
if(devInfo.MediaTypeSupportHeader.HasValue)
|
||||||
|
{
|
||||||
Dispatcher.UIThread.Invoke(() =>
|
Dispatcher.UIThread.Invoke(() =>
|
||||||
{
|
{
|
||||||
MediumTypes = DensitySupport.PrettifyMediumType(devInfo.MediaTypeSupportHeader);
|
MediumTypes =
|
||||||
|
DensitySupport
|
||||||
|
.PrettifyMediumType(devInfo.MediaTypeSupportHeader);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Dispatcher.UIThread.Invoke(() =>
|
Dispatcher.UIThread.Invoke(() =>
|
||||||
{
|
{
|
||||||
MediumDensity = DensitySupport.PrettifyMediumType(devInfo.MediumDensitySupport);
|
MediumDensity =
|
||||||
|
DensitySupport.PrettifyMediumType(devInfo.MediumDensitySupport);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -598,6 +624,7 @@ public partial class DeviceViewModel : ViewModelBase
|
|||||||
devInfo.OCR != null ||
|
devInfo.OCR != null ||
|
||||||
devInfo.ExtendedCSD != null ||
|
devInfo.ExtendedCSD != null ||
|
||||||
devInfo.SCR != null)
|
devInfo.SCR != null)
|
||||||
|
{
|
||||||
Dispatcher.UIThread.Invoke(() =>
|
Dispatcher.UIThread.Invoke(() =>
|
||||||
{
|
{
|
||||||
SdMmcInfo = new SdMmcInfo
|
SdMmcInfo = new SdMmcInfo
|
||||||
@@ -610,6 +637,7 @@ public partial class DeviceViewModel : ViewModelBase
|
|||||||
devInfo.SCR)
|
devInfo.SCR)
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Closed()
|
public void Closed()
|
||||||
|
|||||||
Reference in New Issue
Block a user