[TUI] Detect filesystems.

This commit is contained in:
2025-10-16 11:57:23 +01:00
parent 2f885affe7
commit 7ace157e05
5 changed files with 51 additions and 12 deletions

View File

@@ -16,10 +16,12 @@ public class App : Application
public override void OnFrameworkInitializationCompleted()
{
if(ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopLifetime)
desktopLifetime.MainWindow = new MainWindow
{
DataContext = new MainWindowViewModel()
};
{
var mainWindow = new MainWindow();
var vm = new MainWindowViewModel(mainWindow);
mainWindow.DataContext = vm;
desktopLifetime.MainWindow = mainWindow;
}
base.OnFrameworkInitializationCompleted();
}

View File

@@ -1,5 +1,6 @@
using System.Collections.ObjectModel;
using Aaru.CommonTypes;
using Aaru.CommonTypes.Interfaces;
namespace Aaru.Tui.Models;
@@ -13,7 +14,8 @@ public class FileSystemModelNode
SubNodes = subNodes;
}
public ObservableCollection<FileSystemModelNode>? SubNodes { get; }
public string Title { get; }
public Partition? Partition { get; set; }
public ObservableCollection<FileSystemModelNode>? SubNodes { get; set; }
public string Title { get; }
public Partition? Partition { get; set; }
public IFilesystem? Filesystem { get; set; }
}

View File

@@ -15,6 +15,7 @@ public sealed partial class ImageWindowViewModel : ViewModelBase
{
readonly string _filename;
readonly IMediaImage _imageFormat;
readonly Window _parent;
readonly Window _view;
[ObservableProperty]
bool _isStatusVisible;
@@ -23,11 +24,12 @@ public sealed partial class ImageWindowViewModel : ViewModelBase
[ObservableProperty]
string? _status;
public ImageWindowViewModel(Window view, IMediaImage imageFormat, string filename)
public ImageWindowViewModel(Window parent, Window view, IMediaImage imageFormat, string filename)
{
_imageFormat = imageFormat;
_filename = filename;
_view = view;
_parent = parent;
ExitCommand = new RelayCommand(Exit);
BackCommand = new RelayCommand(Back);
@@ -38,6 +40,7 @@ public sealed partial class ImageWindowViewModel : ViewModelBase
void Back()
{
_parent.Show();
_view.Close();
}
@@ -73,6 +76,10 @@ public sealed partial class ImageWindowViewModel : ViewModelBase
var sequence = 0;
Status = "Loading filesystems...";
PluginRegister plugins = PluginRegister.Singleton;
foreach(Partition partition in partitionsList)
{
var node = new FileSystemModelNode(partition.Name ?? $"Partition {sequence}")
@@ -80,6 +87,25 @@ public sealed partial class ImageWindowViewModel : ViewModelBase
Partition = partition
};
Core.Filesystems.Identify(_imageFormat, out List<string>? idPlugins, partition);
if(idPlugins.Count > 0)
{
var subNodes = new ObservableCollection<FileSystemModelNode>();
foreach(string pluginName in idPlugins)
{
if(!plugins.Filesystems.TryGetValue(pluginName, out IFilesystem? fs)) continue;
if(fs is null) continue;
var fsNode = new FileSystemModelNode(fs.Name);
fsNode.Filesystem = fs;
subNodes.Add(fsNode);
}
node.SubNodes = subNodes;
}
Nodes.Add(node);
sequence++;
}

View File

@@ -10,6 +10,7 @@ using Aaru.Helpers;
using Aaru.Tui.Models;
using Aaru.Tui.Views.Windows;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Media;
using CommunityToolkit.Mvvm.ComponentModel;
@@ -22,6 +23,7 @@ namespace Aaru.Tui.ViewModels.Windows;
public sealed partial class MainWindowViewModel : ViewModelBase
{
readonly Window _view;
[ObservableProperty]
string _copyright;
[ObservableProperty]
@@ -36,8 +38,9 @@ public sealed partial class MainWindowViewModel : ViewModelBase
[ObservableProperty]
string _status;
public MainWindowViewModel()
public MainWindowViewModel(Window view)
{
_view = view;
ExitCommand = new RelayCommand(Exit);
OpenSelectedFileCommand = new RelayCommand(OpenSelectedFile, CanOpenSelectedFile);
@@ -300,10 +303,14 @@ public sealed partial class MainWindowViewModel : ViewModelBase
if(SelectedFile.ImageFormat is null) return;
var imageWindow = new ImageWindow();
var imageViewModel = new ImageWindowViewModel(imageWindow, SelectedFile.ImageFormat, SelectedFile.Filename);
var imageWindow = new ImageWindow();
var imageViewModel =
new ImageWindowViewModel(_view, imageWindow, SelectedFile.ImageFormat, SelectedFile.Filename);
imageWindow.DataContext = imageViewModel;
imageWindow.Show();
_view.Hide();
}
bool CanOpenSelectedFile() => SelectedFile != null;

View File

@@ -5,13 +5,15 @@ using Avalonia.Interactivity;
namespace Aaru.Tui.Views.Windows;
public partial class MainWindow : Window
public class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
public MainWindow(object? dataContext) : this() => DataContext = dataContext;
private void ListBox_OnKeyDown(object sender, KeyEventArgs e)
{
if(e.Key == Key.Enter)