RootDrives WIP

This commit is contained in:
2022-05-14 22:14:37 +02:00
parent 1682d5afd1
commit 9a99aad030
16 changed files with 409 additions and 15 deletions

View File

@@ -1,3 +1,5 @@
using System.Collections.ObjectModel;
using FileTime.App.Core.Models;
using FileTime.App.Core.ViewModels;
using FileTime.GuiApp.Configuration;
@@ -10,4 +12,5 @@ public interface IGuiAppState : IAppState
bool NoCommandFound { get; set; }
string? MessageBoxText { get; set; }
List<CommandBindingConfiguration> PossibleCommands { get; set; }
BindedCollection<RootDriveInfo> RootDriveInfos { get; set; }
}

View File

@@ -0,0 +1,57 @@
using System.ComponentModel;
using System.Runtime.InteropServices;
using FileTime.Core.Models;
using FileTime.GuiApp.Models;
using PropertyChanged.SourceGenerator;
using IContainer = FileTime.Core.Models.IContainer;
namespace FileTime.GuiApp.ViewModels;
public partial class RootDriveInfo : IHaveAbsolutePath, INotifyPropertyChanged
{
private readonly DriveInfo _driveInfo;
[Notify] private string _name;
[Notify] private string _fullName;
[Notify] private string? _label;
[Notify] private long _size = 0;
[Notify] private long _free = 0;
[Notify] private long _used = 0;
[Notify] public long UsedPercentage => Size == 0 ? 0 : Used * 100 / Size;
public IAbsolutePath Path { get; }
public RootDriveInfo(DriveInfo driveInfo, IContainer container)
{
_driveInfo = driveInfo;
_name = container.Name;
_fullName = _name;
try
{
_fullName = container.FullName?.Path[(container.Provider.FullName!.Path.Length + 1)..] ?? _fullName;
}
catch
{
}
Path = new AbsolutePath(container);
Refresh();
}
private void Refresh()
{
Label = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? _driveInfo.VolumeLabel : null;
Size = _driveInfo.TotalSize;
Free = _driveInfo.AvailableFreeSpace;
Used = _driveInfo.TotalSize - _driveInfo.AvailableFreeSpace;
}
}