mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
[TUI] Detect filesystems.
This commit is contained in:
@@ -16,10 +16,12 @@ public class App : Application
|
|||||||
public override void OnFrameworkInitializationCompleted()
|
public override void OnFrameworkInitializationCompleted()
|
||||||
{
|
{
|
||||||
if(ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopLifetime)
|
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();
|
base.OnFrameworkInitializationCompleted();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using Aaru.CommonTypes;
|
using Aaru.CommonTypes;
|
||||||
|
using Aaru.CommonTypes.Interfaces;
|
||||||
|
|
||||||
namespace Aaru.Tui.Models;
|
namespace Aaru.Tui.Models;
|
||||||
|
|
||||||
@@ -13,7 +14,8 @@ public class FileSystemModelNode
|
|||||||
SubNodes = subNodes;
|
SubNodes = subNodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObservableCollection<FileSystemModelNode>? SubNodes { get; }
|
public ObservableCollection<FileSystemModelNode>? SubNodes { get; set; }
|
||||||
public string Title { get; }
|
public string Title { get; }
|
||||||
public Partition? Partition { get; set; }
|
public Partition? Partition { get; set; }
|
||||||
|
public IFilesystem? Filesystem { get; set; }
|
||||||
}
|
}
|
||||||
@@ -15,6 +15,7 @@ public sealed partial class ImageWindowViewModel : ViewModelBase
|
|||||||
{
|
{
|
||||||
readonly string _filename;
|
readonly string _filename;
|
||||||
readonly IMediaImage _imageFormat;
|
readonly IMediaImage _imageFormat;
|
||||||
|
readonly Window _parent;
|
||||||
readonly Window _view;
|
readonly Window _view;
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
bool _isStatusVisible;
|
bool _isStatusVisible;
|
||||||
@@ -23,11 +24,12 @@ public sealed partial class ImageWindowViewModel : ViewModelBase
|
|||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
string? _status;
|
string? _status;
|
||||||
|
|
||||||
public ImageWindowViewModel(Window view, IMediaImage imageFormat, string filename)
|
public ImageWindowViewModel(Window parent, Window view, IMediaImage imageFormat, string filename)
|
||||||
{
|
{
|
||||||
_imageFormat = imageFormat;
|
_imageFormat = imageFormat;
|
||||||
_filename = filename;
|
_filename = filename;
|
||||||
_view = view;
|
_view = view;
|
||||||
|
_parent = parent;
|
||||||
|
|
||||||
ExitCommand = new RelayCommand(Exit);
|
ExitCommand = new RelayCommand(Exit);
|
||||||
BackCommand = new RelayCommand(Back);
|
BackCommand = new RelayCommand(Back);
|
||||||
@@ -38,6 +40,7 @@ public sealed partial class ImageWindowViewModel : ViewModelBase
|
|||||||
|
|
||||||
void Back()
|
void Back()
|
||||||
{
|
{
|
||||||
|
_parent.Show();
|
||||||
_view.Close();
|
_view.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,6 +76,10 @@ public sealed partial class ImageWindowViewModel : ViewModelBase
|
|||||||
|
|
||||||
var sequence = 0;
|
var sequence = 0;
|
||||||
|
|
||||||
|
Status = "Loading filesystems...";
|
||||||
|
|
||||||
|
PluginRegister plugins = PluginRegister.Singleton;
|
||||||
|
|
||||||
foreach(Partition partition in partitionsList)
|
foreach(Partition partition in partitionsList)
|
||||||
{
|
{
|
||||||
var node = new FileSystemModelNode(partition.Name ?? $"Partition {sequence}")
|
var node = new FileSystemModelNode(partition.Name ?? $"Partition {sequence}")
|
||||||
@@ -80,6 +87,25 @@ public sealed partial class ImageWindowViewModel : ViewModelBase
|
|||||||
Partition = partition
|
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);
|
Nodes.Add(node);
|
||||||
sequence++;
|
sequence++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ using Aaru.Helpers;
|
|||||||
using Aaru.Tui.Models;
|
using Aaru.Tui.Models;
|
||||||
using Aaru.Tui.Views.Windows;
|
using Aaru.Tui.Views.Windows;
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
|
using Avalonia.Controls;
|
||||||
using Avalonia.Controls.ApplicationLifetimes;
|
using Avalonia.Controls.ApplicationLifetimes;
|
||||||
using Avalonia.Media;
|
using Avalonia.Media;
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
@@ -22,6 +23,7 @@ namespace Aaru.Tui.ViewModels.Windows;
|
|||||||
|
|
||||||
public sealed partial class MainWindowViewModel : ViewModelBase
|
public sealed partial class MainWindowViewModel : ViewModelBase
|
||||||
{
|
{
|
||||||
|
readonly Window _view;
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
string _copyright;
|
string _copyright;
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
@@ -36,8 +38,9 @@ public sealed partial class MainWindowViewModel : ViewModelBase
|
|||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
string _status;
|
string _status;
|
||||||
|
|
||||||
public MainWindowViewModel()
|
public MainWindowViewModel(Window view)
|
||||||
{
|
{
|
||||||
|
_view = view;
|
||||||
ExitCommand = new RelayCommand(Exit);
|
ExitCommand = new RelayCommand(Exit);
|
||||||
OpenSelectedFileCommand = new RelayCommand(OpenSelectedFile, CanOpenSelectedFile);
|
OpenSelectedFileCommand = new RelayCommand(OpenSelectedFile, CanOpenSelectedFile);
|
||||||
|
|
||||||
@@ -301,9 +304,13 @@ public sealed partial class MainWindowViewModel : ViewModelBase
|
|||||||
if(SelectedFile.ImageFormat is null) return;
|
if(SelectedFile.ImageFormat is null) return;
|
||||||
|
|
||||||
var imageWindow = new ImageWindow();
|
var imageWindow = new ImageWindow();
|
||||||
var imageViewModel = new ImageWindowViewModel(imageWindow, SelectedFile.ImageFormat, SelectedFile.Filename);
|
|
||||||
|
var imageViewModel =
|
||||||
|
new ImageWindowViewModel(_view, imageWindow, SelectedFile.ImageFormat, SelectedFile.Filename);
|
||||||
|
|
||||||
imageWindow.DataContext = imageViewModel;
|
imageWindow.DataContext = imageViewModel;
|
||||||
imageWindow.Show();
|
imageWindow.Show();
|
||||||
|
_view.Hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CanOpenSelectedFile() => SelectedFile != null;
|
bool CanOpenSelectedFile() => SelectedFile != null;
|
||||||
|
|||||||
@@ -5,13 +5,15 @@ using Avalonia.Interactivity;
|
|||||||
|
|
||||||
namespace Aaru.Tui.Views.Windows;
|
namespace Aaru.Tui.Views.Windows;
|
||||||
|
|
||||||
public partial class MainWindow : Window
|
public class MainWindow : Window
|
||||||
{
|
{
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MainWindow(object? dataContext) : this() => DataContext = dataContext;
|
||||||
|
|
||||||
private void ListBox_OnKeyDown(object sender, KeyEventArgs e)
|
private void ListBox_OnKeyDown(object sender, KeyEventArgs e)
|
||||||
{
|
{
|
||||||
if(e.Key == Key.Enter)
|
if(e.Key == Key.Enter)
|
||||||
|
|||||||
Reference in New Issue
Block a user