mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
[TUI] Identify partitions.
This commit is contained in:
@@ -11,5 +11,5 @@ public class FileModel
|
|||||||
public bool IsDirectory { get; set; }
|
public bool IsDirectory { get; set; }
|
||||||
public FileInfo? FileInfo { get; set; }
|
public FileInfo? FileInfo { get; set; }
|
||||||
public string? Information { get; set; }
|
public string? Information { get; set; }
|
||||||
public IBaseImage? ImageFormat { get; set; }
|
public IMediaImage? ImageFormat { get; set; }
|
||||||
}
|
}
|
||||||
19
Aaru.Tui/Models/FileSystemModelNode.cs
Normal file
19
Aaru.Tui/Models/FileSystemModelNode.cs
Normal 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; }
|
||||||
|
}
|
||||||
@@ -1,8 +1,12 @@
|
|||||||
|
using System.Collections.ObjectModel;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
using Aaru.CommonTypes;
|
||||||
using Aaru.CommonTypes.Interfaces;
|
using Aaru.CommonTypes.Interfaces;
|
||||||
|
using Aaru.Tui.Models;
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Controls.ApplicationLifetimes;
|
using Avalonia.Controls.ApplicationLifetimes;
|
||||||
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using CommunityToolkit.Mvvm.Input;
|
using CommunityToolkit.Mvvm.Input;
|
||||||
|
|
||||||
namespace Aaru.Tui.ViewModels.Windows;
|
namespace Aaru.Tui.ViewModels.Windows;
|
||||||
@@ -10,10 +14,16 @@ namespace Aaru.Tui.ViewModels.Windows;
|
|||||||
public sealed partial class ImageWindowViewModel : ViewModelBase
|
public sealed partial class ImageWindowViewModel : ViewModelBase
|
||||||
{
|
{
|
||||||
readonly string _filename;
|
readonly string _filename;
|
||||||
readonly IBaseImage _imageFormat;
|
readonly IMediaImage _imageFormat;
|
||||||
readonly Window _view;
|
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;
|
_imageFormat = imageFormat;
|
||||||
_filename = filename;
|
_filename = filename;
|
||||||
@@ -36,4 +46,45 @@ public sealed partial class ImageWindowViewModel : ViewModelBase
|
|||||||
var lifetime = Application.Current!.ApplicationLifetime as IControlledApplicationLifetime;
|
var lifetime = Application.Current!.ApplicationLifetime as IControlledApplicationLifetime;
|
||||||
lifetime!.Shutdown();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -277,7 +277,7 @@ public sealed partial class MainWindowViewModel : ViewModelBase
|
|||||||
|
|
||||||
file.Information = sb.ToString();
|
file.Information = sb.ToString();
|
||||||
|
|
||||||
file.ImageFormat = imageFormat;
|
file.ImageFormat = imageFormat as IMediaImage;
|
||||||
}
|
}
|
||||||
catch(Exception ex)
|
catch(Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -29,7 +29,21 @@
|
|||||||
</Border.BorderBrush>
|
</Border.BorderBrush>
|
||||||
<Grid RowDefinitions="*,Auto">
|
<Grid RowDefinitions="*,Auto">
|
||||||
<Grid ColumnDefinitions="*,*"
|
<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"
|
<TextBlock Grid.Row="1"
|
||||||
Text="{Binding Status, Mode=OneWay}"
|
Text="{Binding Status, Mode=OneWay}"
|
||||||
IsVisible="{Binding IsStatusVisible, Mode=OneWay}" />
|
IsVisible="{Binding IsStatusVisible, Mode=OneWay}" />
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
|
using Aaru.Tui.ViewModels.Windows;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Interactivity;
|
||||||
|
|
||||||
namespace Aaru.Tui.Views.Windows;
|
namespace Aaru.Tui.Views.Windows;
|
||||||
|
|
||||||
@@ -8,4 +10,12 @@ public partial class ImageWindow : Window
|
|||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void OnLoaded(RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnLoaded(e);
|
||||||
|
|
||||||
|
(DataContext as ImageWindowViewModel)?.LoadComplete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user