Files
Aaru/Aaru.Gui/ViewModels/Dialogs/PluginsViewModel.cs

224 lines
8.1 KiB
C#
Raw Normal View History

2020-04-17 21:45:50 +01:00
// /***************************************************************************
// Aaru Data Preservation Suite
// ----------------------------------------------------------------------------
//
// Filename : PluginsViewModel.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : GUI view models.
//
// --[ Description ] ----------------------------------------------------------
//
// View model and code for the plugins list dialog.
//
// --[ License ] --------------------------------------------------------------
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General public License for more details.
//
// You should have received a copy of the GNU General public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
2022-12-03 16:07:10 +00:00
// Copyright © 2011-2023 Natalia Portillo
2020-04-17 21:45:50 +01:00
// ****************************************************************************/
2022-12-17 19:16:42 +00:00
using System;
2020-04-17 21:45:50 +01:00
using System.Collections.ObjectModel;
using System.Reactive;
using System.Reflection;
using Aaru.CommonTypes;
using Aaru.CommonTypes.Interfaces;
using Aaru.Gui.Models;
2020-04-16 20:40:25 +01:00
using Aaru.Gui.Views.Dialogs;
using Aaru.Localization;
2020-07-22 13:20:25 +01:00
using JetBrains.Annotations;
using ReactiveUI;
namespace Aaru.Gui.ViewModels.Dialogs;
2022-03-06 13:29:38 +00:00
public sealed class PluginsViewModel : ViewModelBase
{
2022-03-06 13:29:38 +00:00
readonly PluginsDialog _view;
2022-03-06 13:29:38 +00:00
public PluginsViewModel(PluginsDialog view)
{
_view = view;
Filters = new ObservableCollection<PluginModel>();
PartitionSchemes = new ObservableCollection<PluginModel>();
Filesystems = new ObservableCollection<PluginModel>();
ReadOnlyFilesystems = new ObservableCollection<PluginModel>();
Images = new ObservableCollection<PluginModel>();
WritableImages = new ObservableCollection<PluginModel>();
FloppyImages = new ObservableCollection<PluginModel>();
WritableFloppyImages = new ObservableCollection<PluginModel>();
CloseCommand = ReactiveCommand.Create(ExecuteCloseCommand);
2022-03-06 13:29:38 +00:00
// TODO: Takes too much time
foreach(Type filterType in PluginRegister.Singleton.Filters.Values)
2022-12-17 19:56:04 +00:00
{
if(Activator.CreateInstance(filterType) is not IFilter filter)
continue;
2022-03-06 13:29:38 +00:00
Filters.Add(new PluginModel
{
Name = filter.Name,
Uuid = filter.Id,
2022-12-17 19:56:04 +00:00
Version = Assembly.GetAssembly(filterType)?.GetName().Version?.ToString(),
2022-03-06 13:29:38 +00:00
Author = filter.Author
});
2022-12-17 19:56:04 +00:00
}
foreach(Type imageType in PluginRegister.Singleton.FloppyImages.Values)
2022-12-17 19:58:03 +00:00
{
if(Activator.CreateInstance(imageType) is not IFloppyImage floppyImage)
continue;
2022-03-06 13:29:38 +00:00
FloppyImages.Add(new PluginModel
{
Name = floppyImage.Name,
Uuid = floppyImage.Id,
Version = Assembly.GetAssembly(imageType)?.GetName().Version?.ToString(),
2022-03-06 13:29:38 +00:00
Author = floppyImage.Author
});
2022-12-17 19:58:03 +00:00
}
foreach(Type imageType in PluginRegister.Singleton.MediaImages.Values)
2022-12-17 19:27:27 +00:00
{
if(Activator.CreateInstance(imageType) is not IMediaImage mediaImage)
continue;
2022-03-06 13:29:38 +00:00
Images.Add(new PluginModel
{
Name = mediaImage.Name,
Uuid = mediaImage.Id,
2022-12-17 19:27:27 +00:00
Version = Assembly.GetAssembly(imageType)?.GetName().Version?.ToString(),
2022-03-06 13:29:38 +00:00
Author = mediaImage.Author
});
2022-12-17 19:27:27 +00:00
}
foreach(Type partitionType in PluginRegister.Singleton.Partitions.Values)
2022-12-17 19:16:42 +00:00
{
if(Activator.CreateInstance(partitionType) is not IPartition partition)
continue;
2022-03-06 13:29:38 +00:00
PartitionSchemes.Add(new PluginModel
{
Name = partition.Name,
Uuid = partition.Id,
2022-12-17 19:16:42 +00:00
Version = Assembly.GetAssembly(partitionType)?.GetName().Version?.ToString(),
2022-03-06 13:29:38 +00:00
Author = partition.Author
});
2022-12-17 19:16:42 +00:00
}
foreach(IFilesystem filesystem in PluginRegister.Singleton.Filesystems.Values)
2022-12-17 19:16:42 +00:00
{
if(filesystem is null)
2022-12-17 19:16:42 +00:00
continue;
2022-03-06 13:29:38 +00:00
Filesystems.Add(new PluginModel
{
Name = filesystem.Name,
Uuid = filesystem.Id,
Version = Assembly.GetAssembly(filesystem.GetType())?.GetName().Version?.ToString(),
Author = filesystem.Author
2022-03-06 13:29:38 +00:00
});
2022-12-17 19:16:42 +00:00
}
foreach(IReadOnlyFilesystem fs in PluginRegister.Singleton.ReadOnlyFilesystems.Values)
2022-12-17 19:16:42 +00:00
{
if(fs is null)
2022-12-17 19:16:42 +00:00
continue;
2022-03-06 13:29:38 +00:00
ReadOnlyFilesystems.Add(new PluginModel
{
2022-12-17 19:16:42 +00:00
Name = fs.Name,
Uuid = fs.Id,
Version = Assembly.GetAssembly(fs.GetType())?.GetName().Version?.ToString(),
2022-12-17 19:16:42 +00:00
Author = fs.Author
2022-03-06 13:29:38 +00:00
});
2022-12-17 19:16:42 +00:00
}
foreach(Type imageType in PluginRegister.Singleton.WritableFloppyImages.Values)
{
if(Activator.CreateInstance(imageType) is not IWritableFloppyImage writableFloppyImage)
continue;
2022-03-06 13:29:38 +00:00
WritableFloppyImages.Add(new PluginModel
{
Name = writableFloppyImage.Name,
Uuid = writableFloppyImage.Id,
Version = Assembly.GetAssembly(imageType)?.GetName().Version?.ToString(),
2022-03-06 13:29:38 +00:00
Author = writableFloppyImage.Author
});
}
foreach(Type baseWritableImageType in PluginRegister.Singleton.WritableImages.Values)
2022-11-15 01:35:06 +00:00
{
if(Activator.CreateInstance(baseWritableImageType) is not IWritableImage writableImage)
2022-11-15 01:35:06 +00:00
continue;
2022-03-06 13:29:38 +00:00
WritableImages.Add(new PluginModel
{
Name = writableImage.Name,
Uuid = writableImage.Id,
Version = Assembly.GetAssembly(baseWritableImageType)?.GetName().Version?.ToString(),
2022-03-06 13:29:38 +00:00
Author = writableImage.Author
});
2022-11-15 01:35:06 +00:00
}
2022-03-06 13:29:38 +00:00
}
2022-03-06 13:29:38 +00:00
[NotNull]
public string Title => UI.Title_Plugins;
2023-10-03 23:27:57 +01:00
2022-03-06 13:29:38 +00:00
[NotNull]
public string FiltersLabel => UI.Title_Filters;
2023-10-03 23:27:57 +01:00
2022-03-06 13:29:38 +00:00
[NotNull]
public string PartitionsLabel => UI.Title_Partitions;
2023-10-03 23:27:57 +01:00
2022-03-06 13:29:38 +00:00
[NotNull]
public string FilesystemsLabel => UI.Title_Filesystems;
2023-10-03 23:27:57 +01:00
2022-03-06 13:29:38 +00:00
[NotNull]
public string IdentifyLabel => UI.Title_Identify_only;
2023-10-03 23:27:57 +01:00
2022-03-06 13:29:38 +00:00
[NotNull]
public string ImagesLabel => UI.Title_Media_images;
2023-10-03 23:27:57 +01:00
2022-03-06 13:29:38 +00:00
[NotNull]
public string FloppyImagesLabel => UI.Title_Floppy_images;
2023-10-03 23:27:57 +01:00
2022-03-06 13:29:38 +00:00
[NotNull]
public string ReadableLabel => UI.Title_Readable;
2023-10-03 23:27:57 +01:00
2022-03-06 13:29:38 +00:00
[NotNull]
public string WritableLabel => UI.Title_Writable;
2023-10-03 23:27:57 +01:00
2022-03-06 13:29:38 +00:00
[NotNull]
public string CloseLabel => UI.ButtonLabel_Close;
2023-10-03 23:27:57 +01:00
public string NameLabel => UI.Title_Name;
2023-10-05 01:52:48 +01:00
public string UuidLabel => UI.Title_UUID;
public string VersionLabel => UI.Title_Version;
public string AuthorLabel => UI.Title_Author;
2022-03-06 13:29:38 +00:00
public ReactiveCommand<Unit, Unit> CloseCommand { get; }
public ObservableCollection<PluginModel> Filters { get; }
public ObservableCollection<PluginModel> PartitionSchemes { get; }
public ObservableCollection<PluginModel> Filesystems { get; }
public ObservableCollection<PluginModel> ReadOnlyFilesystems { get; }
public ObservableCollection<PluginModel> Images { get; }
public ObservableCollection<PluginModel> WritableImages { get; }
public ObservableCollection<PluginModel> FloppyImages { get; }
public ObservableCollection<PluginModel> WritableFloppyImages { get; }
2022-03-06 13:29:38 +00:00
void ExecuteCloseCommand() => _view.Close();
}