mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 11:26:27 +00:00
Workshop - Implemented workshop installation, layout selection and removal
This commit is contained in:
1 parent
dad6a56238
commit
28edabae89
23 files changed
+226
-168
No files matched your search
@@ -1,31 +0,0 @@
|
||||
using System.IO;
|
||||
|
||||
namespace Artemis.Core;
|
||||
|
||||
internal static class DirectoryInfoExtensions
|
||||
{
|
||||
public static void CopyFilesRecursively(this DirectoryInfo source, DirectoryInfo target)
|
||||
{
|
||||
foreach (DirectoryInfo dir in source.GetDirectories())
|
||||
CopyFilesRecursively(dir, target.CreateSubdirectory(dir.Name));
|
||||
foreach (FileInfo file in source.GetFiles())
|
||||
file.CopyTo(Path.Combine(target.FullName, file.Name));
|
||||
}
|
||||
|
||||
public static void DeleteRecursively(this DirectoryInfo baseDir)
|
||||
{
|
||||
if (!baseDir.Exists)
|
||||
return;
|
||||
|
||||
foreach (DirectoryInfo dir in baseDir.EnumerateDirectories())
|
||||
DeleteRecursively(dir);
|
||||
FileInfo[] files = baseDir.GetFiles();
|
||||
foreach (FileInfo file in files)
|
||||
{
|
||||
file.IsReadOnly = false;
|
||||
file.Delete();
|
||||
}
|
||||
|
||||
baseDir.Delete();
|
||||
}
|
||||
}
|
||||
@@ -398,14 +398,6 @@ public class ArtemisDevice : CorePropertyChanged
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invokes the <see cref="DeviceUpdated" /> event
|
||||
/// </summary>
|
||||
protected virtual void OnDeviceUpdated()
|
||||
{
|
||||
DeviceUpdated?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies the provided layout to the device
|
||||
/// </summary>
|
||||
@@ -418,7 +410,7 @@ public class ArtemisDevice : CorePropertyChanged
|
||||
/// A boolean indicating whether to remove excess LEDs present in the device but missing
|
||||
/// in the layout
|
||||
/// </param>
|
||||
internal void ApplyLayout(ArtemisLayout? layout, bool createMissingLeds, bool removeExcessiveLeds)
|
||||
public void ApplyLayout(ArtemisLayout? layout, bool createMissingLeds, bool removeExcessiveLeds)
|
||||
{
|
||||
if (layout != null && layout.IsValid && createMissingLeds && !DeviceProvider.CreateMissingLedsSupported)
|
||||
throw new ArtemisCoreException($"Cannot apply layout with {nameof(createMissingLeds)} set to true because the device provider does not support it");
|
||||
@@ -445,6 +437,14 @@ public class ArtemisDevice : CorePropertyChanged
|
||||
CalculateRenderProperties();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invokes the <see cref="DeviceUpdated" /> event
|
||||
/// </summary>
|
||||
protected virtual void OnDeviceUpdated()
|
||||
{
|
||||
DeviceUpdated?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
private void ClearLayout()
|
||||
{
|
||||
if (Layout == null)
|
||||
|
||||
@@ -1,17 +1,8 @@
|
||||
using Artemis.Core.Services;
|
||||
using RGB.NET.Layout;
|
||||
|
||||
namespace Artemis.Core.Providers;
|
||||
namespace Artemis.Core.Providers;
|
||||
|
||||
public class CustomPathLayoutProvider : ILayoutProvider
|
||||
{
|
||||
public static string LayoutType = "CustomPath";
|
||||
private readonly IDeviceService _deviceService;
|
||||
|
||||
public CustomPathLayoutProvider(IDeviceService deviceService)
|
||||
{
|
||||
_deviceService = deviceService;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ArtemisLayout? GetDeviceLayout(ArtemisDevice device)
|
||||
@@ -34,7 +25,7 @@ public class CustomPathLayoutProvider : ILayoutProvider
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the provided device to use this layout provider.
|
||||
/// Configures the provided device to use this layout provider.
|
||||
/// </summary>
|
||||
/// <param name="device">The device to apply the provider to.</param>
|
||||
/// <param name="path">The path to the custom layout.</param>
|
||||
@@ -42,7 +33,5 @@ public class CustomPathLayoutProvider : ILayoutProvider
|
||||
{
|
||||
device.LayoutSelection.Type = LayoutType;
|
||||
device.LayoutSelection.Parameter = path;
|
||||
_deviceService.SaveDevice(device);
|
||||
_deviceService.LoadDeviceLayout(device);
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,9 @@
|
||||
using Artemis.Core.Services;
|
||||
|
||||
namespace Artemis.Core.Providers;
|
||||
namespace Artemis.Core.Providers;
|
||||
|
||||
public class DefaultLayoutProvider : ILayoutProvider
|
||||
{
|
||||
public static string LayoutType = "Default";
|
||||
private readonly IDeviceService _deviceService;
|
||||
|
||||
public DefaultLayoutProvider(IDeviceService deviceService)
|
||||
{
|
||||
_deviceService = deviceService;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ArtemisLayout? GetDeviceLayout(ArtemisDevice device)
|
||||
{
|
||||
@@ -30,22 +22,20 @@ public class DefaultLayoutProvider : ILayoutProvider
|
||||
else
|
||||
device.ApplyLayout(layout, device.DeviceProvider.CreateMissingLedsSupported, device.DeviceProvider.RemoveExcessiveLedsSupported);
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsMatch(ArtemisDevice device)
|
||||
{
|
||||
return device.LayoutSelection.Type == LayoutType;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Configures the provided device to use this layout provider.
|
||||
/// Configures the provided device to use this layout provider.
|
||||
/// </summary>
|
||||
/// <param name="device">The device to apply the provider to.</param>
|
||||
public void ConfigureDevice(ArtemisDevice device)
|
||||
{
|
||||
device.LayoutSelection.Type = LayoutType;
|
||||
device.LayoutSelection.Parameter = null;
|
||||
_deviceService.SaveDevice(device);
|
||||
_deviceService.LoadDeviceLayout(device);
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
namespace Artemis.Core.Providers;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a class that can provide Artemis layouts for devices.
|
||||
/// Represents a class that can provide Artemis layouts for devices.
|
||||
/// </summary>
|
||||
public interface ILayoutProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// If available, loads an Artemis layout for the provided device.
|
||||
/// If available, loads an Artemis layout for the provided device.
|
||||
/// </summary>
|
||||
/// <param name="device">The device to load the layout for.</param>
|
||||
/// <returns>The resulting layout if one was available; otherwise <see langword="null"/>.</returns>
|
||||
/// <returns>The resulting layout if one was available; otherwise <see langword="null" />.</returns>
|
||||
ArtemisLayout? GetDeviceLayout(ArtemisDevice device);
|
||||
|
||||
void ApplyLayout(ArtemisDevice device, ArtemisLayout layout);
|
||||
|
||||
@@ -1,17 +1,9 @@
|
||||
using Artemis.Core.Services;
|
||||
|
||||
namespace Artemis.Core.Providers;
|
||||
namespace Artemis.Core.Providers;
|
||||
|
||||
public class NoneLayoutProvider : ILayoutProvider
|
||||
{
|
||||
private readonly IDeviceService _deviceService;
|
||||
public static string LayoutType = "None";
|
||||
|
||||
public NoneLayoutProvider(IDeviceService deviceService)
|
||||
{
|
||||
_deviceService = deviceService;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ArtemisLayout? GetDeviceLayout(ArtemisDevice device)
|
||||
{
|
||||
@@ -23,22 +15,20 @@ public class NoneLayoutProvider : ILayoutProvider
|
||||
{
|
||||
device.ApplyLayout(null, false, false);
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool IsMatch(ArtemisDevice device)
|
||||
{
|
||||
return device.LayoutSelection.Type == LayoutType;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Configures the provided device to use this layout provider.
|
||||
/// Configures the provided device to use this layout provider.
|
||||
/// </summary>
|
||||
/// <param name="device">The device to apply the provider to.</param>
|
||||
public void ConfigureDevice(ArtemisDevice device)
|
||||
{
|
||||
device.LayoutSelection.Type = LayoutType;
|
||||
device.LayoutSelection.Parameter = null;
|
||||
_deviceService.SaveDevice(device);
|
||||
_deviceService.LoadDeviceLayout(device);
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ internal class DeviceService : IDeviceService
|
||||
private readonly IPluginManagementService _pluginManagementService;
|
||||
private readonly IDeviceRepository _deviceRepository;
|
||||
private readonly Lazy<IRenderService> _renderService;
|
||||
private readonly LazyEnumerable<ILayoutProvider> _layoutProviders;
|
||||
private readonly Func<List<ILayoutProvider>> _getLayoutProviders;
|
||||
private readonly List<ArtemisDevice> _enabledDevices = new();
|
||||
private readonly List<ArtemisDevice> _devices = new();
|
||||
|
||||
@@ -28,13 +28,13 @@ internal class DeviceService : IDeviceService
|
||||
IPluginManagementService pluginManagementService,
|
||||
IDeviceRepository deviceRepository,
|
||||
Lazy<IRenderService> renderService,
|
||||
LazyEnumerable<ILayoutProvider> layoutProviders)
|
||||
Func<List<ILayoutProvider>> getLayoutProviders)
|
||||
{
|
||||
_logger = logger;
|
||||
_pluginManagementService = pluginManagementService;
|
||||
_deviceRepository = deviceRepository;
|
||||
_renderService = renderService;
|
||||
_layoutProviders = layoutProviders;
|
||||
_getLayoutProviders = getLayoutProviders;
|
||||
|
||||
EnabledDevices = new ReadOnlyCollection<ArtemisDevice>(_enabledDevices);
|
||||
Devices = new ReadOnlyCollection<ArtemisDevice>(_devices);
|
||||
@@ -167,7 +167,7 @@ internal class DeviceService : IDeviceService
|
||||
/// <inheritdoc />
|
||||
public void LoadDeviceLayout(ArtemisDevice device)
|
||||
{
|
||||
ILayoutProvider? provider = _layoutProviders.FirstOrDefault(p => p.IsMatch(device));
|
||||
ILayoutProvider? provider = _getLayoutProviders().FirstOrDefault(p => p.IsMatch(device));
|
||||
if (provider == null)
|
||||
_logger.Warning("Could not find a layout provider for type {LayoutType} of device {Device}", device.LayoutSelection.Type, device);
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ internal class PluginManagementService : IPluginManagementService
|
||||
|
||||
// Remove the old directory if it exists
|
||||
if (Directory.Exists(pluginDirectory.FullName))
|
||||
pluginDirectory.DeleteRecursively();
|
||||
pluginDirectory.Delete(true);
|
||||
|
||||
// Extract everything in the same archive directory to the unique plugin directory
|
||||
Utilities.CreateAccessibleDirectory(pluginDirectory.FullName);
|
||||
|
||||
Reference in new issue
Block a user