mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Core - Refactored (unused) queued actions system
This commit is contained in:
1 parent
0ed367530f
commit
a6f52ce4a0
9 files changed
+134
-68
No files matched your search
@@ -135,11 +135,16 @@ namespace Artemis.Core.Services
|
||||
DeviceProvider GetDeviceProviderByDevice(IRGBDevice device);
|
||||
|
||||
/// <summary>
|
||||
/// Queues an action for the provided plugin for the next time Artemis starts, before plugins are loaded
|
||||
/// Queues the provided plugin to be deleted the next time Artemis starts, before plugins are loaded
|
||||
/// </summary>
|
||||
/// <param name="plugin">The plugin to queue the action for</param>
|
||||
/// <param name="pluginAction">The action to take</param>
|
||||
void QueuePluginAction(Plugin plugin, PluginManagementAction pluginAction);
|
||||
/// <param name="plugin">The plugin to delete</param>
|
||||
void QueuePluginDeletion(Plugin plugin);
|
||||
|
||||
/// <summary>
|
||||
/// Removes the provided plugin for the deletion queue it was added to via <see cref="QueuePluginDeletion" />
|
||||
/// </summary>
|
||||
/// <param name="plugin">The plugin to dequeue</param>
|
||||
void DequeuePluginDeletion(Plugin plugin);
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when built-in plugins are being loaded
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.Linq;
|
||||
using System.Reflection;
|
||||
using Artemis.Core.DeviceProviders;
|
||||
using Artemis.Core.Ninject;
|
||||
using Artemis.Storage.Entities.General;
|
||||
using Artemis.Storage.Entities.Plugins;
|
||||
using Artemis.Storage.Repositories.Interfaces;
|
||||
using McMaster.NETCore.Plugins;
|
||||
@@ -26,17 +27,19 @@ namespace Artemis.Core.Services
|
||||
private readonly IKernel _kernel;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IPluginRepository _pluginRepository;
|
||||
private readonly IQueuedActionRepository _queuedActionRepository;
|
||||
private readonly List<Plugin> _plugins;
|
||||
private bool _isElevated;
|
||||
|
||||
public PluginManagementService(IKernel kernel, ILogger logger, IPluginRepository pluginRepository)
|
||||
public PluginManagementService(IKernel kernel, ILogger logger, IPluginRepository pluginRepository, IQueuedActionRepository queuedActionRepository)
|
||||
{
|
||||
_kernel = kernel;
|
||||
_logger = logger;
|
||||
_pluginRepository = pluginRepository;
|
||||
_queuedActionRepository = queuedActionRepository;
|
||||
_plugins = new List<Plugin>();
|
||||
|
||||
ProcessQueuedActions();
|
||||
ProcessPluginDeletionQueue();
|
||||
}
|
||||
|
||||
private void CopyBuiltInPlugin(ZipArchive zipArchive, string targetDirectory)
|
||||
@@ -664,27 +667,51 @@ namespace Artemis.Core.Services
|
||||
|
||||
#region Queued actions
|
||||
|
||||
public void QueuePluginAction(Plugin plugin, PluginManagementAction pluginAction)
|
||||
public void QueuePluginDeletion(Plugin plugin)
|
||||
{
|
||||
List<PluginQueuedActionEntity> existing = _pluginRepository.GetQueuedActions(plugin.Guid);
|
||||
if (existing.Any(e => pluginAction == PluginManagementAction.Delete && e is PluginQueuedDeleteEntity))
|
||||
return;
|
||||
|
||||
if (pluginAction == PluginManagementAction.Delete)
|
||||
_pluginRepository.AddQueuedAction(new PluginQueuedDeleteEntity {PluginGuid = plugin.Guid, Directory = plugin.Directory.FullName});
|
||||
_queuedActionRepository.Add(new QueuedActionEntity
|
||||
{
|
||||
Type = "DeletePlugin",
|
||||
CreatedAt = DateTimeOffset.Now,
|
||||
Parameters = new Dictionary<string, object>()
|
||||
{
|
||||
{"pluginGuid", plugin.Guid.ToString()},
|
||||
{"plugin", plugin.ToString()},
|
||||
{"directory", plugin.Directory.FullName}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void ProcessQueuedActions()
|
||||
public void DequeuePluginDeletion(Plugin plugin)
|
||||
{
|
||||
foreach (PluginQueuedActionEntity pluginQueuedActionEntity in _pluginRepository.GetQueuedActions())
|
||||
{
|
||||
if (pluginQueuedActionEntity is PluginQueuedDeleteEntity deleteAction)
|
||||
{
|
||||
if (Directory.Exists(deleteAction.Directory))
|
||||
Directory.Delete(deleteAction.Directory, true);
|
||||
}
|
||||
QueuedActionEntity? queuedActionEntity = _queuedActionRepository.GetByType("DeletePlugin").FirstOrDefault(q => q.Parameters["pluginGuid"].Equals(plugin.Guid.ToString()));
|
||||
if (queuedActionEntity != null)
|
||||
_queuedActionRepository.Remove(queuedActionEntity);
|
||||
}
|
||||
|
||||
_pluginRepository.RemoveQueuedAction(pluginQueuedActionEntity);
|
||||
private void ProcessPluginDeletionQueue()
|
||||
{
|
||||
foreach (QueuedActionEntity queuedActionEntity in _queuedActionRepository.GetByType("DeletePlugin"))
|
||||
{
|
||||
string? directory = queuedActionEntity.Parameters["directory"].ToString();
|
||||
try
|
||||
{
|
||||
if (Directory.Exists(directory))
|
||||
{
|
||||
_logger.Information("Queued plugin deletion - deleting folder - {plugin}", queuedActionEntity.Parameters["plugin"]);
|
||||
Directory.Delete(directory!, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Information("Queued plugin deletion - folder already deleted - {plugin}", queuedActionEntity.Parameters["plugin"]);
|
||||
}
|
||||
|
||||
_queuedActionRepository.Remove(queuedActionEntity);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.Warning(e, "Queued plugin deletion failed - {plugin}", queuedActionEntity.Parameters["plugin"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user