[TUI] Identify partitions.

This commit is contained in:
2025-10-16 11:43:03 +01:00
parent 28b59e8535
commit 2f885affe7
6 changed files with 107 additions and 13 deletions

View File

@@ -5,11 +5,11 @@ namespace Aaru.Tui.Models;
public class FileModel
{
public string Path { get; set; }
public string Filename { get; set; }
public IBrush ForegroundBrush { get; set; }
public bool IsDirectory { get; set; }
public FileInfo? FileInfo { get; set; }
public string? Information { get; set; }
public IBaseImage? ImageFormat { get; set; }
public string Path { get; set; }
public string Filename { get; set; }
public IBrush ForegroundBrush { get; set; }
public bool IsDirectory { get; set; }
public FileInfo? FileInfo { get; set; }
public string? Information { get; set; }
public IMediaImage? ImageFormat { get; set; }
}

View File

@@ -0,0 +1,19 @@
using System.Collections.ObjectModel;
using Aaru.CommonTypes;
namespace Aaru.Tui.Models;
public class FileSystemModelNode
{
public FileSystemModelNode(string title) => Title = title;
public FileSystemModelNode(string title, ObservableCollection<FileSystemModelNode> subNodes)
{
Title = title;
SubNodes = subNodes;
}
public ObservableCollection<FileSystemModelNode>? SubNodes { get; }
public string Title { get; }
public Partition? Partition { get; set; }
}

View File

@@ -1,19 +1,29 @@
using System.Collections.ObjectModel;
using System.Windows.Input;
using Aaru.CommonTypes;
using Aaru.CommonTypes.Interfaces;
using Aaru.Tui.Models;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
namespace Aaru.Tui.ViewModels.Windows;
public sealed partial class ImageWindowViewModel : ViewModelBase
{
readonly string _filename;
readonly IBaseImage _imageFormat;
readonly Window _view;
readonly string _filename;
readonly IMediaImage _imageFormat;
readonly Window _view;
[ObservableProperty]
bool _isStatusVisible;
[ObservableProperty]
ObservableCollection<FileSystemModelNode> _nodes;
[ObservableProperty]
string? _status;
public ImageWindowViewModel(Window view, IBaseImage imageFormat, string filename)
public ImageWindowViewModel(Window view, IMediaImage imageFormat, string filename)
{
_imageFormat = imageFormat;
_filename = filename;
@@ -36,4 +46,45 @@ public sealed partial class ImageWindowViewModel : ViewModelBase
var lifetime = Application.Current!.ApplicationLifetime as IControlledApplicationLifetime;
lifetime!.Shutdown();
}
public void LoadComplete()
{
_ = Task.Run(Worker);
}
void Worker()
{
IsStatusVisible = true;
Status = "Loading partitions...";
Nodes = new ObservableCollection<FileSystemModelNode>();
List<Partition>? partitionsList = Core.Partitions.GetAll(_imageFormat);
if(partitionsList.Count == 0)
{
partitionsList.Add(new Partition
{
Name = Localization.Core.Whole_device,
Length = _imageFormat.Info.Sectors,
Size = _imageFormat.Info.Sectors * _imageFormat.Info.SectorSize
});
}
var sequence = 0;
foreach(Partition partition in partitionsList)
{
var node = new FileSystemModelNode(partition.Name ?? $"Partition {sequence}")
{
Partition = partition
};
Nodes.Add(node);
sequence++;
}
Status = "Done.";
IsStatusVisible = false;
}
}

View File

@@ -277,7 +277,7 @@ public sealed partial class MainWindowViewModel : ViewModelBase
file.Information = sb.ToString();
file.ImageFormat = imageFormat;
file.ImageFormat = imageFormat as IMediaImage;
}
catch(Exception ex)
{

View File

@@ -29,7 +29,21 @@
</Border.BorderBrush>
<Grid RowDefinitions="*,Auto">
<Grid ColumnDefinitions="*,*"
Grid.Row="0" />
Grid.Row="0">
<TreeView Grid.Column="0"
ItemsSource="{Binding Nodes, Mode=OneWay}"
BorderThickness="1">
<TreeView.BorderBrush>
<brushes:LineBrush LineStyle="DoubleLine"
Brush="Blue" />
</TreeView.BorderBrush>
<TreeView.ItemTemplate>
<TreeDataTemplate ItemsSource="{Binding SubNodes, Mode=OneWay}">
<TextBlock Text="{Binding Title, Mode=OneWay}" />
</TreeDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
</Grid>
<TextBlock Grid.Row="1"
Text="{Binding Status, Mode=OneWay}"
IsVisible="{Binding IsStatusVisible, Mode=OneWay}" />

View File

@@ -1,4 +1,6 @@
using Aaru.Tui.ViewModels.Windows;
using Avalonia.Controls;
using Avalonia.Interactivity;
namespace Aaru.Tui.Views.Windows;
@@ -8,4 +10,12 @@ public partial class ImageWindow : Window
{
InitializeComponent();
}
/// <inheritdoc />
protected override void OnLoaded(RoutedEventArgs e)
{
base.OnLoaded(e);
(DataContext as ImageWindowViewModel)?.LoadComplete();
}
}