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

@@ -13,10 +13,15 @@
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.10.14" />
<PackageReference Include="PropertyChanged.SourceGenerator" Version="1.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\AppCommon\FileTime.App.Core.Abstraction\FileTime.App.Core.Abstraction.csproj" />
<ProjectReference Include="..\..\..\Core\FileTime.Core.Models\FileTime.Core.Models.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,8 @@
using FileTime.Core.Models;
namespace FileTime.GuiApp.Models;
public interface IHaveAbsolutePath
{
IAbsolutePath Path { get; }
}

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;
}
}