ConsoleUI container size text
This commit is contained in:
@@ -1,8 +0,0 @@
|
||||
using FileTime.Core.Models;
|
||||
|
||||
namespace FileTime.GuiApp.App.Models;
|
||||
|
||||
public interface IHaveFullPath
|
||||
{
|
||||
FullName Path { get; }
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using FileTime.App.Core.ViewModels;
|
||||
using FileTime.GuiApp.App.Models;
|
||||
using FileTime.Providers.Local;
|
||||
|
||||
namespace FileTime.GuiApp.App.ViewModels;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ using FileTime.GuiApp.App.Models;
|
||||
|
||||
namespace FileTime.GuiApp.App.ViewModels;
|
||||
|
||||
public class PlaceInfo : IHaveFullPath
|
||||
public class PlaceInfo
|
||||
{
|
||||
public IContainer Container { get; }
|
||||
public string DisplayName { get; }
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.InteropServices;
|
||||
using FileTime.Core.Models;
|
||||
using FileTime.GuiApp.App.Models;
|
||||
using PropertyChanged.SourceGenerator;
|
||||
using IContainer = FileTime.Core.Models.IContainer;
|
||||
|
||||
namespace FileTime.GuiApp.App.ViewModels;
|
||||
|
||||
public partial class RootDriveInfo : IHaveFullPath, 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 FullName 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 = container.FullName ?? throw new NullReferenceException($"Container does not have a {nameof(FullName)}");
|
||||
|
||||
Refresh();
|
||||
}
|
||||
|
||||
private void Refresh()
|
||||
{
|
||||
Label = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? _driveInfo.VolumeLabel : null;
|
||||
Size = _driveInfo.TotalSize;
|
||||
Free = _driveInfo.AvailableFreeSpace;
|
||||
Used = _driveInfo.TotalSize - _driveInfo.AvailableFreeSpace;
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using FileTime.App.Core.Services;
|
||||
using FileTime.Core.Models;
|
||||
using FileTime.GuiApp.App.ViewModels;
|
||||
using FileTime.Providers.Local;
|
||||
using ObservableComputations;
|
||||
|
||||
namespace FileTime.GuiApp.App.Services;
|
||||
|
||||
public class RootDriveInfoService : IExitHandler
|
||||
{
|
||||
private readonly ILocalContentProvider _localContentProvider;
|
||||
private readonly List<DriveInfo> _rootDrives = new();
|
||||
private readonly OcConsumer _rootDriveInfosConsumer = new();
|
||||
|
||||
public RootDriveInfoService(
|
||||
IGuiAppState guiAppState,
|
||||
ILocalContentProvider localContentProvider)
|
||||
{
|
||||
_localContentProvider = localContentProvider;
|
||||
InitRootDrives();
|
||||
|
||||
var rootDriveInfos = localContentProvider.Items.Selecting<AbsolutePath, (AbsolutePath Path, DriveInfo? Drive)>(
|
||||
i => MatchRootDrive(i)
|
||||
)
|
||||
.Filtering(t => IsNotNull(t.Drive))
|
||||
.Selecting(t => Resolve(t))
|
||||
.Filtering(t => t.Item is IContainer)
|
||||
.Selecting(t => new RootDriveInfo(t.Drive, (IContainer) t.Item!))
|
||||
.Ordering(d => d.Name);
|
||||
|
||||
rootDriveInfos.For(_rootDriveInfosConsumer);
|
||||
|
||||
guiAppState.RootDriveInfos = rootDriveInfos;
|
||||
|
||||
void InitRootDrives()
|
||||
{
|
||||
var driveInfos = new List<RootDriveInfo>();
|
||||
var drives = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
|
||||
? DriveInfo.GetDrives().Where(d => d.DriveType == DriveType.Fixed)
|
||||
: DriveInfo.GetDrives().Where(d =>
|
||||
d.DriveType == DriveType.Fixed
|
||||
&& d.DriveFormat != "pstorefs"
|
||||
&& d.DriveFormat != "bpf_fs"
|
||||
&& d.DriveFormat != "tracefs"
|
||||
&& !d.RootDirectory.FullName.StartsWith("/snap/"));
|
||||
|
||||
_rootDrives.Clear();
|
||||
_rootDrives.AddRange(drives);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsNotNull(object? obj) => obj is not null;
|
||||
|
||||
private static (IItem? Item, DriveInfo Drive) Resolve((AbsolutePath Path, DriveInfo? Drive) tuple)
|
||||
{
|
||||
var t = Task.Run(async () => await tuple.Path.ResolveAsyncSafe());
|
||||
t.Wait();
|
||||
return (Item: t.Result, Drive: tuple.Drive!);
|
||||
}
|
||||
|
||||
private (AbsolutePath Path, DriveInfo? Drive) MatchRootDrive(AbsolutePath sourceItem)
|
||||
{
|
||||
var rootDrive = _rootDrives.FirstOrDefault(d =>
|
||||
{
|
||||
var containerPath = _localContentProvider.GetNativePath(sourceItem.Path).Path;
|
||||
var drivePath = d.Name.TrimEnd(Path.DirectorySeparatorChar);
|
||||
return containerPath == drivePath
|
||||
|| (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && containerPath == "/" &&
|
||||
d.Name == "/");
|
||||
});
|
||||
|
||||
return (Path: sourceItem, Drive: rootDrive);
|
||||
}
|
||||
|
||||
public Task ExitAsync(CancellationToken token = default)
|
||||
{
|
||||
_rootDriveInfosConsumer.Dispose();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,7 @@
|
||||
xmlns:interactions="using:FileTime.Core.Interactions"
|
||||
xmlns:itemPreview="clr-namespace:FileTime.App.Core.ViewModels.ItemPreview;assembly=FileTime.App.Core"
|
||||
xmlns:local="using:FileTime.GuiApp.App.Views"
|
||||
xmlns:local1="clr-namespace:FileTime.Providers.Local;assembly=FileTime.Providers.Local.Abstractions"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:sizePreview="clr-namespace:FileTime.App.ContainerSizeScanner;assembly=FileTime.App.ContainerSizeScanner"
|
||||
xmlns:vm="using:FileTime.GuiApp.App.ViewModels"
|
||||
@@ -108,7 +109,7 @@
|
||||
|
||||
<ItemsRepeater Grid.Row="1" ItemsSource="{Binding AppState.RootDriveInfos}">
|
||||
<ItemsRepeater.ItemTemplate>
|
||||
<DataTemplate x:DataType="vm:RootDriveInfo">
|
||||
<DataTemplate x:DataType="local1:RootDriveInfo">
|
||||
<Grid
|
||||
Classes="SidebarContainerPresenter"
|
||||
Cursor="Hand"
|
||||
|
||||
@@ -10,6 +10,7 @@ using FileTime.Core.Models;
|
||||
using FileTime.GuiApp.App.Models;
|
||||
using FileTime.GuiApp.App.Services;
|
||||
using FileTime.GuiApp.App.ViewModels;
|
||||
using FileTime.Providers.Local;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
@@ -117,14 +118,18 @@ public partial class MainWindow : Window, IUiAccessor
|
||||
&& sender is StyledElement control)
|
||||
{
|
||||
FullName? path = null;
|
||||
if (control.DataContext is IHaveFullPath {Path: { }} hasFullPath)
|
||||
{
|
||||
path = hasFullPath.Path;
|
||||
}
|
||||
else if (control.DataContext is FullName p)
|
||||
if (control.DataContext is FullName p)
|
||||
{
|
||||
path = p;
|
||||
}
|
||||
else if (control.DataContext is RootDriveInfo {Path: { } rootDriveInfoPath})
|
||||
{
|
||||
path = rootDriveInfoPath;
|
||||
}
|
||||
else if (control.DataContext is PlaceInfo {Path: { } placeInfoPath})
|
||||
{
|
||||
path = placeInfoPath;
|
||||
}
|
||||
/*else if (control.DataContext is IElement element && element.GetParent() is IContainer parentContainer)
|
||||
{
|
||||
Task.Run(async () =>
|
||||
|
||||
@@ -7,6 +7,7 @@ using FileTime.App.Core.ViewModels;
|
||||
using FileTime.App.Core.ViewModels.Timeline;
|
||||
using FileTime.GuiApp.App.Models;
|
||||
using FileTime.GuiApp.App.ViewModels;
|
||||
using FileTime.Providers.Local;
|
||||
using MvvmGen;
|
||||
using PropertyChanged.SourceGenerator;
|
||||
|
||||
@@ -16,18 +17,19 @@ public partial class GuiAppState : AppStateBase, IGuiAppState, IDisposable
|
||||
{
|
||||
private readonly BehaviorSubject<GuiPanel> _activePanel = new(GuiPanel.FileBrowser);
|
||||
|
||||
public GuiAppState()
|
||||
{
|
||||
ActivePanel = _activePanel.AsObservable();
|
||||
}
|
||||
|
||||
[Notify] private ObservableCollection<RootDriveInfo> _rootDriveInfos = new();
|
||||
[Notify] private ObservableCollection<RootDriveInfo> _rootDriveInfos;
|
||||
|
||||
[Notify] private IReadOnlyList<PlaceInfo> _places = new List<PlaceInfo>();
|
||||
public ObservableCollection<string> PopupTexts { get; } = new();
|
||||
|
||||
public IObservable<GuiPanel> ActivePanel { get; }
|
||||
|
||||
public GuiAppState(IRootDriveInfoService rootDriveInfoService)
|
||||
{
|
||||
ActivePanel = _activePanel.AsObservable();
|
||||
_rootDriveInfos = rootDriveInfoService.RootDriveInfos;
|
||||
}
|
||||
|
||||
public void SetActivePanel(GuiPanel newPanel)
|
||||
=> _activePanel.OnNext(newPanel);
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ using FileTime.GuiApp.App.IconProviders;
|
||||
using FileTime.GuiApp.App.Logging;
|
||||
using FileTime.GuiApp.App.Services;
|
||||
using FileTime.GuiApp.App.ViewModels;
|
||||
using FileTime.Providers.Local;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
|
||||
Reference in New Issue
Block a user