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;
|
2020-04-10 04:16:48 +01:00
|
|
|
|
using System.Reactive;
|
|
|
|
|
|
using System.Reflection;
|
2023-10-05 13:47:59 +01:00
|
|
|
|
using Aaru.CommonTypes;
|
2020-04-10 04:16:48 +01:00
|
|
|
|
using Aaru.CommonTypes.Interfaces;
|
|
|
|
|
|
using Aaru.Core;
|
|
|
|
|
|
using Aaru.Gui.Models;
|
2020-04-16 20:40:25 +01:00
|
|
|
|
using Aaru.Gui.Views.Dialogs;
|
2022-11-19 21:10:41 +00:00
|
|
|
|
using Aaru.Localization;
|
2020-07-22 13:20:25 +01:00
|
|
|
|
using JetBrains.Annotations;
|
2020-04-10 04:16:48 +01:00
|
|
|
|
using ReactiveUI;
|
|
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
|
namespace Aaru.Gui.ViewModels.Dialogs;
|
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
public sealed class PluginsViewModel : ViewModelBase
|
2020-04-10 04:16:48 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
readonly PluginsDialog _view;
|
2020-04-10 04:16:48 +01:00
|
|
|
|
|
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);
|
2023-10-05 13:47:59 +01:00
|
|
|
|
PluginBase.Init();
|
2020-04-10 04:16:48 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
// TODO: Takes too much time
|
2023-10-05 13:47:59 +01:00
|
|
|
|
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
|
|
|
|
}
|
2020-04-10 04:16:48 +01:00
|
|
|
|
|
2023-10-05 13:47:59 +01: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,
|
2022-12-17 19:59:48 +00:00
|
|
|
|
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
|
|
|
|
}
|
2020-04-10 04:16:48 +01:00
|
|
|
|
|
2023-10-05 13:47:59 +01: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
|
|
|
|
}
|
2020-04-10 04:16:48 +01:00
|
|
|
|
|
2023-10-05 13:47:59 +01: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
|
|
|
|
}
|
|
|
|
|
|
|
2023-10-05 13:47:59 +01:00
|
|
|
|
foreach(Type filesystem in PluginRegister.Singleton.Filesystems.Values)
|
2022-12-17 19:16:42 +00:00
|
|
|
|
{
|
|
|
|
|
|
if(Activator.CreateInstance(filesystem) is not IFilesystem fs)
|
|
|
|
|
|
continue;
|
2020-04-10 04:16:48 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
Filesystems.Add(new PluginModel
|
|
|
|
|
|
{
|
2022-12-17 19:16:42 +00:00
|
|
|
|
Name = fs.Name,
|
|
|
|
|
|
Uuid = fs.Id,
|
|
|
|
|
|
Version = Assembly.GetAssembly(filesystem)?.GetName().Version?.ToString(),
|
|
|
|
|
|
Author = fs.Author
|
2022-03-06 13:29:38 +00:00
|
|
|
|
});
|
2022-12-17 19:16:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-10-05 13:47:59 +01:00
|
|
|
|
foreach(Type readOnlyFilesystem in PluginRegister.Singleton.ReadOnlyFilesystems.Values)
|
2022-12-17 19:16:42 +00:00
|
|
|
|
{
|
|
|
|
|
|
if(Activator.CreateInstance(readOnlyFilesystem) is not IReadOnlyFilesystem fs)
|
|
|
|
|
|
continue;
|
2020-04-10 04:16:48 +01:00
|
|
|
|
|
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(readOnlyFilesystem)?.GetName().Version?.ToString(),
|
|
|
|
|
|
Author = fs.Author
|
2022-03-06 13:29:38 +00:00
|
|
|
|
});
|
2022-12-17 19:16:42 +00:00
|
|
|
|
}
|
2020-04-10 04:16:48 +01:00
|
|
|
|
|
2023-10-05 13:47:59 +01:00
|
|
|
|
foreach(Type imageType in PluginRegister.Singleton.WritableFloppyImages.Values)
|
2022-12-17 19:59:48 +00:00
|
|
|
|
{
|
|
|
|
|
|
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,
|
2022-12-17 19:59:48 +00:00
|
|
|
|
Version = Assembly.GetAssembly(imageType)?.GetName().Version?.ToString(),
|
2022-03-06 13:29:38 +00:00
|
|
|
|
Author = writableFloppyImage.Author
|
|
|
|
|
|
});
|
2022-12-17 19:59:48 +00:00
|
|
|
|
}
|
2020-04-10 04:16:48 +01:00
|
|
|
|
|
2023-10-05 13:47:59 +01:00
|
|
|
|
foreach(Type baseWritableImageType in PluginRegister.Singleton.WritableImages.Values)
|
2022-11-15 01:35:06 +00:00
|
|
|
|
{
|
2022-12-17 19:50:32 +00:00
|
|
|
|
if(Activator.CreateInstance(baseWritableImageType) is not IWritableImage writableImage)
|
2022-11-15 01:35:06 +00:00
|
|
|
|
continue;
|
2022-11-15 15:58:43 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
WritableImages.Add(new PluginModel
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = writableImage.Name,
|
|
|
|
|
|
Uuid = writableImage.Id,
|
2022-12-17 19:59:48 +00:00
|
|
|
|
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
|
|
|
|
}
|
2020-04-10 04:16:48 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
[NotNull]
|
2022-11-19 21:10:41 +00:00
|
|
|
|
public string Title => UI.Title_Plugins;
|
2023-10-03 23:27:57 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
[NotNull]
|
2022-11-19 21:10:41 +00:00
|
|
|
|
public string FiltersLabel => UI.Title_Filters;
|
2023-10-03 23:27:57 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
[NotNull]
|
2022-11-19 21:10:41 +00:00
|
|
|
|
public string PartitionsLabel => UI.Title_Partitions;
|
2023-10-03 23:27:57 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
[NotNull]
|
2022-11-19 21:10:41 +00:00
|
|
|
|
public string FilesystemsLabel => UI.Title_Filesystems;
|
2023-10-03 23:27:57 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
[NotNull]
|
2022-11-19 21:10:41 +00:00
|
|
|
|
public string IdentifyLabel => UI.Title_Identify_only;
|
2023-10-03 23:27:57 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
[NotNull]
|
2022-11-19 21:10:41 +00:00
|
|
|
|
public string ImagesLabel => UI.Title_Media_images;
|
2023-10-03 23:27:57 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
[NotNull]
|
2022-11-19 21:10:41 +00:00
|
|
|
|
public string FloppyImagesLabel => UI.Title_Floppy_images;
|
2023-10-03 23:27:57 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
[NotNull]
|
2022-11-19 21:10:41 +00:00
|
|
|
|
public string ReadableLabel => UI.Title_Readable;
|
2023-10-03 23:27:57 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
[NotNull]
|
2022-11-19 21:10:41 +00:00
|
|
|
|
public string WritableLabel => UI.Title_Writable;
|
2023-10-03 23:27:57 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
[NotNull]
|
2022-11-19 21:10:41 +00:00
|
|
|
|
public string CloseLabel => UI.ButtonLabel_Close;
|
2023-10-03 23:27:57 +01:00
|
|
|
|
|
2022-11-19 21:10:41 +00:00
|
|
|
|
public string NameLabel => UI.Title_Name;
|
2023-10-05 01:52:48 +01:00
|
|
|
|
public string UuidLabel => UI.Title_UUID;
|
2022-11-19 21:10:41 +00:00
|
|
|
|
public string VersionLabel => UI.Title_Version;
|
|
|
|
|
|
public string AuthorLabel => UI.Title_Author;
|
2022-11-16 21:40:54 +00:00
|
|
|
|
|
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; }
|
2020-04-10 04:16:48 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
void ExecuteCloseCommand() => _view.Close();
|
2020-04-10 04:16:48 +01:00
|
|
|
|
}
|