GUI RootDriveInfo per type

This commit is contained in:
2023-09-06 09:47:37 +02:00
parent 67484ba56b
commit ef88885d40
5 changed files with 139 additions and 89 deletions

View File

@@ -34,13 +34,14 @@ public class RootDriveInfoService : IRootDriveInfoService
var rootDriveInfos = _rootDrives.Selecting(r => GetContainer(r))
.Filtering(t => t.Item != null)
.Selecting(t => new RootDriveInfo(t.Drive, t.Item!))
.Ordering(d => d.Name)
.Ordering(d => GetDriveOrder(d.DriveType))
.ThenOrdering(d => d.Name)
.For(_rootDriveInfosConsumer);
RootDriveInfos = new ReadOnlyObservableCollection<RootDriveInfo>(rootDriveInfos);
AllDrives = new ReadOnlyObservableCollection<DriveInfo>(_allDrives);
(DriveInfo[] RootDrives, DriveInfo[] AllDrives) GetRootDrives()
static (DriveInfo[] RootDrives, DriveInfo[] AllDrives) GetRootDrives()
{
var allDrives = DriveInfo.GetDrives();
var drives = DriveInfo.GetDrives().Where(d => d.DriveType is not DriveType.Unknown and not DriveType.Ram);
@@ -70,6 +71,16 @@ public class RootDriveInfoService : IRootDriveInfoService
return (rootDriveInfo, task.Result as IContainer);
}
private static int GetDriveOrder(DriveType type)
=> type switch
{
DriveType.Fixed => 0,
DriveType.Removable => 1,
DriveType.CDRom => 2,
DriveType.Network => 3,
_ => 5
};
public Task ExitAsync(CancellationToken token = default)
{
_rootDriveInfosConsumer.Dispose();