mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 11:26:27 +00:00
Code style - Use file scoped namespaces
Code style - Ran code cleanup
This commit is contained in:
1 parent
e68e16df4d
commit
f6090dc296
691 files changed
+37301
-38119
No files matched your search
@@ -1,65 +1,63 @@
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
|
||||
namespace Artemis.Core
|
||||
namespace Artemis.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a key or combination of keys that changes the suspension status of a <see cref="ProfileConfiguration" />
|
||||
/// </summary>
|
||||
public class Hotkey : CorePropertyChanged, IStorageModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a key or combination of keys that changes the suspension status of a <see cref="ProfileConfiguration"/>
|
||||
/// Creates a new instance of <see cref="Hotkey" />
|
||||
/// </summary>
|
||||
public class Hotkey : CorePropertyChanged, IStorageModel
|
||||
public Hotkey()
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="Hotkey" />
|
||||
/// </summary>
|
||||
public Hotkey()
|
||||
{
|
||||
Entity = new ProfileConfigurationHotkeyEntity();
|
||||
}
|
||||
|
||||
internal Hotkey(ProfileConfigurationHotkeyEntity entity)
|
||||
{
|
||||
Entity = entity;
|
||||
Load();
|
||||
}
|
||||
|
||||
internal ProfileConfigurationHotkeyEntity Entity { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="KeyboardKey" /> of the hotkey
|
||||
/// </summary>
|
||||
public KeyboardKey? Key { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="KeyboardModifierKey" />s of the hotkey
|
||||
/// </summary>
|
||||
public KeyboardModifierKey? Modifiers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the provided <see cref="ArtemisKeyboardKeyEventArgs" /> match the hotkey
|
||||
/// </summary>
|
||||
/// <returns><see langword="true" /> if the event args match the hotkey; otherwise <see langword="false" /></returns>
|
||||
public bool MatchesEventArgs(ArtemisKeyboardKeyEventArgs eventArgs)
|
||||
{
|
||||
return eventArgs.Key == Key && eventArgs.Modifiers == Modifiers;
|
||||
}
|
||||
|
||||
#region Implementation of IStorageModel
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Load()
|
||||
{
|
||||
Key = (KeyboardKey?) Entity.Key;
|
||||
Modifiers = (KeyboardModifierKey?) Entity.Modifiers;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Save()
|
||||
{
|
||||
Entity.Key = (int?) Key;
|
||||
Entity.Modifiers = (int?) Modifiers;
|
||||
}
|
||||
|
||||
#endregion
|
||||
Entity = new ProfileConfigurationHotkeyEntity();
|
||||
}
|
||||
|
||||
internal Hotkey(ProfileConfigurationHotkeyEntity entity)
|
||||
{
|
||||
Entity = entity;
|
||||
Load();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="KeyboardKey" /> of the hotkey
|
||||
/// </summary>
|
||||
public KeyboardKey? Key { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="KeyboardModifierKey" />s of the hotkey
|
||||
/// </summary>
|
||||
public KeyboardModifierKey? Modifiers { get; set; }
|
||||
|
||||
internal ProfileConfigurationHotkeyEntity Entity { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the provided <see cref="ArtemisKeyboardKeyEventArgs" /> match the hotkey
|
||||
/// </summary>
|
||||
/// <returns><see langword="true" /> if the event args match the hotkey; otherwise <see langword="false" /></returns>
|
||||
public bool MatchesEventArgs(ArtemisKeyboardKeyEventArgs eventArgs)
|
||||
{
|
||||
return eventArgs.Key == Key && eventArgs.Modifiers == Modifiers;
|
||||
}
|
||||
|
||||
#region Implementation of IStorageModel
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Load()
|
||||
{
|
||||
Key = (KeyboardKey?) Entity.Key;
|
||||
Modifiers = (KeyboardModifierKey?) Entity.Modifiers;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Save()
|
||||
{
|
||||
Entity.Key = (int?) Key;
|
||||
Entity.Modifiers = (int?) Modifiers;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -4,376 +4,373 @@ using System.Linq;
|
||||
using Artemis.Core.Modules;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
|
||||
namespace Artemis.Core
|
||||
namespace Artemis.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the configuration of a profile, contained in a <see cref="ProfileCategory" />
|
||||
/// </summary>
|
||||
public class ProfileConfiguration : BreakableModel, IStorageModel, IDisposable
|
||||
{
|
||||
private ActivationBehaviour _activationBehaviour;
|
||||
private bool _activationConditionMet;
|
||||
private ProfileCategory _category;
|
||||
private Hotkey? _disableHotkey;
|
||||
private bool _disposed;
|
||||
private Hotkey? _enableHotkey;
|
||||
private ProfileConfigurationHotkeyMode _hotkeyMode;
|
||||
private bool _isBeingEdited;
|
||||
private bool _isMissingModule;
|
||||
private bool _isSuspended;
|
||||
private Module? _module;
|
||||
|
||||
private string _name;
|
||||
private int _order;
|
||||
private Profile? _profile;
|
||||
|
||||
internal ProfileConfiguration(ProfileCategory category, string name, string icon)
|
||||
{
|
||||
_name = name;
|
||||
_category = category;
|
||||
|
||||
Entity = new ProfileConfigurationEntity();
|
||||
Icon = new ProfileConfigurationIcon(Entity);
|
||||
Icon.SetIconByName(icon);
|
||||
ActivationCondition = new NodeScript<bool>("Activate profile", "Whether or not the profile should be active", this);
|
||||
}
|
||||
|
||||
internal ProfileConfiguration(ProfileCategory category, ProfileConfigurationEntity entity)
|
||||
{
|
||||
// Will be loaded from the entity
|
||||
_name = null!;
|
||||
_category = category;
|
||||
|
||||
Entity = entity;
|
||||
Icon = new ProfileConfigurationIcon(Entity);
|
||||
ActivationCondition = new NodeScript<bool>("Activate profile", "Whether or not the profile should be active", this);
|
||||
|
||||
Load();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of this profile configuration
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get => _name;
|
||||
set => SetAndNotify(ref _name, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The order in which this profile appears in the update loop and sidebar
|
||||
/// </summary>
|
||||
public int Order
|
||||
{
|
||||
get => _order;
|
||||
set => SetAndNotify(ref _order, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a boolean indicating whether this profile is suspended, disabling it regardless of the
|
||||
/// <see cref="ActivationCondition" />
|
||||
/// </summary>
|
||||
public bool IsSuspended
|
||||
{
|
||||
get => _isSuspended;
|
||||
set => SetAndNotify(ref _isSuspended, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a boolean indicating whether this profile configuration is missing any modules
|
||||
/// </summary>
|
||||
public bool IsMissingModule
|
||||
{
|
||||
get => _isMissingModule;
|
||||
private set => SetAndNotify(ref _isMissingModule, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the category of this profile configuration
|
||||
/// </summary>
|
||||
public ProfileCategory Category
|
||||
{
|
||||
get => _category;
|
||||
internal set => SetAndNotify(ref _category, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="ProfileConfigurationHotkeyMode" /> used to determine hotkey behaviour
|
||||
/// </summary>
|
||||
public ProfileConfigurationHotkeyMode HotkeyMode
|
||||
{
|
||||
get => _hotkeyMode;
|
||||
set => SetAndNotify(ref _hotkeyMode, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the hotkey used to enable or toggle the profile
|
||||
/// </summary>
|
||||
public Hotkey? EnableHotkey
|
||||
{
|
||||
get => _enableHotkey;
|
||||
set => SetAndNotify(ref _enableHotkey, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the hotkey used to disable the profile
|
||||
/// </summary>
|
||||
public Hotkey? DisableHotkey
|
||||
{
|
||||
get => _disableHotkey;
|
||||
set => SetAndNotify(ref _disableHotkey, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the behaviour of when this profile is activated
|
||||
/// </summary>
|
||||
public ActivationBehaviour ActivationBehaviour
|
||||
{
|
||||
get => _activationBehaviour;
|
||||
set => SetAndNotify(ref _activationBehaviour, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a boolean indicating whether the activation conditions where met during the last <see cref="Update" /> call
|
||||
/// </summary>
|
||||
public bool ActivationConditionMet
|
||||
{
|
||||
get => _activationConditionMet;
|
||||
private set => SetAndNotify(ref _activationConditionMet, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a boolean indicating whether this profile configuration is being edited
|
||||
/// </summary>
|
||||
public bool IsBeingEdited
|
||||
{
|
||||
get => _isBeingEdited;
|
||||
set => SetAndNotify(ref _isBeingEdited, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the profile of this profile configuration
|
||||
/// </summary>
|
||||
public Profile? Profile
|
||||
{
|
||||
get => _profile;
|
||||
internal set => SetAndNotify(ref _profile, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the module this profile uses
|
||||
/// </summary>
|
||||
public Module? Module
|
||||
{
|
||||
get => _module;
|
||||
set
|
||||
{
|
||||
SetAndNotify(ref _module, value);
|
||||
IsMissingModule = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the icon configuration
|
||||
/// </summary>
|
||||
public ProfileConfigurationIcon Icon { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the data model condition that must evaluate to <see langword="true" /> for this profile to be activated
|
||||
/// alongside any activation requirements of the <see cref="Module" />, if set
|
||||
/// </summary>
|
||||
public NodeScript<bool> ActivationCondition { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the entity used by this profile config
|
||||
/// </summary>
|
||||
public ProfileConfigurationEntity Entity { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ID of the profile of this profile configuration
|
||||
/// </summary>
|
||||
public Guid ProfileId => Entity.ProfileId;
|
||||
|
||||
#region Overrides of BreakableModel
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string BrokenDisplayName => "Profile Configuration";
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Updates this configurations activation condition status
|
||||
/// </summary>
|
||||
public void Update()
|
||||
{
|
||||
if (_disposed)
|
||||
throw new ObjectDisposedException("ProfileConfiguration");
|
||||
|
||||
if (!ActivationCondition.ExitNodeConnected)
|
||||
{
|
||||
ActivationConditionMet = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ActivationCondition.Run();
|
||||
ActivationConditionMet = ActivationCondition.Result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the profile of this configuration should be active
|
||||
/// </summary>
|
||||
/// <param name="includeActivationCondition">Whether or not to take activation conditions into consideration</param>
|
||||
public bool ShouldBeActive(bool includeActivationCondition)
|
||||
{
|
||||
if (_disposed)
|
||||
throw new ObjectDisposedException("ProfileConfiguration");
|
||||
if (IsBeingEdited)
|
||||
return true;
|
||||
if (Category.IsSuspended || IsSuspended || IsMissingModule)
|
||||
return false;
|
||||
|
||||
if (includeActivationCondition)
|
||||
return ActivationConditionMet && (Module == null || Module.IsActivated);
|
||||
return Module == null || Module.IsActivated;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
return $"[ProfileConfiguration] {nameof(Name)}: {Name}";
|
||||
}
|
||||
|
||||
internal void LoadModules(List<Module> enabledModules)
|
||||
{
|
||||
if (_disposed)
|
||||
throw new ObjectDisposedException("ProfileConfiguration");
|
||||
|
||||
Module = enabledModules.FirstOrDefault(m => m.Id == Entity.ModuleId);
|
||||
IsMissingModule = Module == null && Entity.ModuleId != null;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
_disposed = true;
|
||||
ActivationCondition.Dispose();
|
||||
}
|
||||
|
||||
#region Implementation of IStorageModel
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Load()
|
||||
{
|
||||
if (_disposed)
|
||||
throw new ObjectDisposedException("ProfileConfiguration");
|
||||
|
||||
Name = Entity.Name;
|
||||
IsSuspended = Entity.IsSuspended;
|
||||
ActivationBehaviour = (ActivationBehaviour) Entity.ActivationBehaviour;
|
||||
HotkeyMode = (ProfileConfigurationHotkeyMode) Entity.HotkeyMode;
|
||||
Order = Entity.Order;
|
||||
|
||||
Icon.Load();
|
||||
|
||||
if (Entity.ActivationCondition != null)
|
||||
ActivationCondition.LoadFromEntity(Entity.ActivationCondition);
|
||||
|
||||
EnableHotkey = Entity.EnableHotkey != null ? new Hotkey(Entity.EnableHotkey) : null;
|
||||
DisableHotkey = Entity.DisableHotkey != null ? new Hotkey(Entity.DisableHotkey) : null;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Save()
|
||||
{
|
||||
if (_disposed)
|
||||
throw new ObjectDisposedException("ProfileConfiguration");
|
||||
|
||||
Entity.Name = Name;
|
||||
Entity.IsSuspended = IsSuspended;
|
||||
Entity.ActivationBehaviour = (int) ActivationBehaviour;
|
||||
Entity.HotkeyMode = (int) HotkeyMode;
|
||||
Entity.ProfileCategoryId = Category.Entity.Id;
|
||||
Entity.Order = Order;
|
||||
|
||||
Icon.Save();
|
||||
|
||||
ActivationCondition.Save();
|
||||
Entity.ActivationCondition = ActivationCondition.Entity;
|
||||
|
||||
EnableHotkey?.Save();
|
||||
Entity.EnableHotkey = EnableHotkey?.Entity;
|
||||
DisableHotkey?.Save();
|
||||
Entity.DisableHotkey = DisableHotkey?.Entity;
|
||||
|
||||
if (!IsMissingModule)
|
||||
Entity.ModuleId = Module?.Id;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a type of behaviour when this profile is activated
|
||||
/// </summary>
|
||||
public enum ActivationBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the configuration of a profile, contained in a <see cref="ProfileCategory" />
|
||||
/// Do nothing to other profiles
|
||||
/// </summary>
|
||||
public class ProfileConfiguration : BreakableModel, IStorageModel, IDisposable
|
||||
{
|
||||
private bool _disposed;
|
||||
|
||||
private string _name;
|
||||
private int _order;
|
||||
private bool _isSuspended;
|
||||
private bool _isMissingModule;
|
||||
private ProfileCategory _category;
|
||||
private ProfileConfigurationHotkeyMode _hotkeyMode;
|
||||
private Hotkey? _enableHotkey;
|
||||
private Hotkey? _disableHotkey;
|
||||
private ActivationBehaviour _activationBehaviour;
|
||||
private bool _activationConditionMet;
|
||||
private bool _isBeingEdited;
|
||||
private Profile? _profile;
|
||||
private Module? _module;
|
||||
|
||||
internal ProfileConfiguration(ProfileCategory category, string name, string icon)
|
||||
{
|
||||
_name = name;
|
||||
_category = category;
|
||||
|
||||
Entity = new ProfileConfigurationEntity();
|
||||
Icon = new ProfileConfigurationIcon(Entity);
|
||||
Icon.SetIconByName(icon);
|
||||
ActivationCondition = new NodeScript<bool>("Activate profile", "Whether or not the profile should be active", this);
|
||||
}
|
||||
|
||||
internal ProfileConfiguration(ProfileCategory category, ProfileConfigurationEntity entity)
|
||||
{
|
||||
// Will be loaded from the entity
|
||||
_name = null!;
|
||||
_category = category;
|
||||
|
||||
Entity = entity;
|
||||
Icon = new ProfileConfigurationIcon(Entity);
|
||||
ActivationCondition = new NodeScript<bool>("Activate profile", "Whether or not the profile should be active", this);
|
||||
|
||||
Load();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of this profile configuration
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get => _name;
|
||||
set => SetAndNotify(ref _name, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The order in which this profile appears in the update loop and sidebar
|
||||
/// </summary>
|
||||
public int Order
|
||||
{
|
||||
get => _order;
|
||||
set => SetAndNotify(ref _order, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a boolean indicating whether this profile is suspended, disabling it regardless of the
|
||||
/// <see cref="ActivationCondition" />
|
||||
/// </summary>
|
||||
public bool IsSuspended
|
||||
{
|
||||
get => _isSuspended;
|
||||
set => SetAndNotify(ref _isSuspended, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a boolean indicating whether this profile configuration is missing any modules
|
||||
/// </summary>
|
||||
public bool IsMissingModule
|
||||
{
|
||||
get => _isMissingModule;
|
||||
private set => SetAndNotify(ref _isMissingModule, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the category of this profile configuration
|
||||
/// </summary>
|
||||
public ProfileCategory Category
|
||||
{
|
||||
get => _category;
|
||||
internal set => SetAndNotify(ref _category, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="ProfileConfigurationHotkeyMode" /> used to determine hotkey behaviour
|
||||
/// </summary>
|
||||
public ProfileConfigurationHotkeyMode HotkeyMode
|
||||
{
|
||||
get => _hotkeyMode;
|
||||
set => SetAndNotify(ref _hotkeyMode, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the hotkey used to enable or toggle the profile
|
||||
/// </summary>
|
||||
public Hotkey? EnableHotkey
|
||||
{
|
||||
get => _enableHotkey;
|
||||
set => SetAndNotify(ref _enableHotkey, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the hotkey used to disable the profile
|
||||
/// </summary>
|
||||
public Hotkey? DisableHotkey
|
||||
{
|
||||
get => _disableHotkey;
|
||||
set => SetAndNotify(ref _disableHotkey, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the behaviour of when this profile is activated
|
||||
/// </summary>
|
||||
public ActivationBehaviour ActivationBehaviour
|
||||
{
|
||||
get => _activationBehaviour;
|
||||
set => SetAndNotify(ref _activationBehaviour, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a boolean indicating whether the activation conditions where met during the last <see cref="Update" /> call
|
||||
/// </summary>
|
||||
public bool ActivationConditionMet
|
||||
{
|
||||
get => _activationConditionMet;
|
||||
private set => SetAndNotify(ref _activationConditionMet, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a boolean indicating whether this profile configuration is being edited
|
||||
/// </summary>
|
||||
public bool IsBeingEdited
|
||||
{
|
||||
get => _isBeingEdited;
|
||||
set => SetAndNotify(ref _isBeingEdited, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the profile of this profile configuration
|
||||
/// </summary>
|
||||
public Profile? Profile
|
||||
{
|
||||
get => _profile;
|
||||
internal set => SetAndNotify(ref _profile, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the module this profile uses
|
||||
/// </summary>
|
||||
public Module? Module
|
||||
{
|
||||
get => _module;
|
||||
set
|
||||
{
|
||||
SetAndNotify(ref _module, value);
|
||||
IsMissingModule = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the icon configuration
|
||||
/// </summary>
|
||||
public ProfileConfigurationIcon Icon { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the data model condition that must evaluate to <see langword="true" /> for this profile to be activated
|
||||
/// alongside any activation requirements of the <see cref="Module" />, if set
|
||||
/// </summary>
|
||||
public NodeScript<bool> ActivationCondition { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the entity used by this profile config
|
||||
/// </summary>
|
||||
public ProfileConfigurationEntity Entity { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ID of the profile of this profile configuration
|
||||
/// </summary>
|
||||
public Guid ProfileId => Entity.ProfileId;
|
||||
|
||||
/// <summary>
|
||||
/// Updates this configurations activation condition status
|
||||
/// </summary>
|
||||
public void Update()
|
||||
{
|
||||
if (_disposed)
|
||||
throw new ObjectDisposedException("ProfileConfiguration");
|
||||
|
||||
if (!ActivationCondition.ExitNodeConnected)
|
||||
ActivationConditionMet = true;
|
||||
else
|
||||
{
|
||||
ActivationCondition.Run();
|
||||
ActivationConditionMet = ActivationCondition.Result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the profile of this configuration should be active
|
||||
/// </summary>
|
||||
/// <param name="includeActivationCondition">Whether or not to take activation conditions into consideration</param>
|
||||
public bool ShouldBeActive(bool includeActivationCondition)
|
||||
{
|
||||
if (_disposed)
|
||||
throw new ObjectDisposedException("ProfileConfiguration");
|
||||
if (IsBeingEdited)
|
||||
return true;
|
||||
if (Category.IsSuspended || IsSuspended || IsMissingModule)
|
||||
return false;
|
||||
|
||||
if (includeActivationCondition)
|
||||
return ActivationConditionMet && (Module == null || Module.IsActivated);
|
||||
return Module == null || Module.IsActivated;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
return $"[ProfileConfiguration] {nameof(Name)}: {Name}";
|
||||
}
|
||||
|
||||
internal void LoadModules(List<Module> enabledModules)
|
||||
{
|
||||
if (_disposed)
|
||||
throw new ObjectDisposedException("ProfileConfiguration");
|
||||
|
||||
Module = enabledModules.FirstOrDefault(m => m.Id == Entity.ModuleId);
|
||||
IsMissingModule = Module == null && Entity.ModuleId != null;
|
||||
}
|
||||
|
||||
#region IDisposable
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
_disposed = true;
|
||||
ActivationCondition.Dispose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Implementation of IStorageModel
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Load()
|
||||
{
|
||||
if (_disposed)
|
||||
throw new ObjectDisposedException("ProfileConfiguration");
|
||||
|
||||
Name = Entity.Name;
|
||||
IsSuspended = Entity.IsSuspended;
|
||||
ActivationBehaviour = (ActivationBehaviour) Entity.ActivationBehaviour;
|
||||
HotkeyMode = (ProfileConfigurationHotkeyMode) Entity.HotkeyMode;
|
||||
Order = Entity.Order;
|
||||
|
||||
Icon.Load();
|
||||
|
||||
if (Entity.ActivationCondition != null)
|
||||
ActivationCondition.LoadFromEntity(Entity.ActivationCondition);
|
||||
|
||||
EnableHotkey = Entity.EnableHotkey != null ? new Hotkey(Entity.EnableHotkey) : null;
|
||||
DisableHotkey = Entity.DisableHotkey != null ? new Hotkey(Entity.DisableHotkey) : null;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Save()
|
||||
{
|
||||
if (_disposed)
|
||||
throw new ObjectDisposedException("ProfileConfiguration");
|
||||
|
||||
Entity.Name = Name;
|
||||
Entity.IsSuspended = IsSuspended;
|
||||
Entity.ActivationBehaviour = (int) ActivationBehaviour;
|
||||
Entity.HotkeyMode = (int) HotkeyMode;
|
||||
Entity.ProfileCategoryId = Category.Entity.Id;
|
||||
Entity.Order = Order;
|
||||
|
||||
Icon.Save();
|
||||
|
||||
ActivationCondition.Save();
|
||||
Entity.ActivationCondition = ActivationCondition.Entity;
|
||||
|
||||
EnableHotkey?.Save();
|
||||
Entity.EnableHotkey = EnableHotkey?.Entity;
|
||||
DisableHotkey?.Save();
|
||||
Entity.DisableHotkey = DisableHotkey?.Entity;
|
||||
|
||||
if (!IsMissingModule)
|
||||
Entity.ModuleId = Module?.Id;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Overrides of BreakableModel
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string BrokenDisplayName => "Profile Configuration";
|
||||
|
||||
#endregion
|
||||
}
|
||||
None,
|
||||
|
||||
/// <summary>
|
||||
/// Represents a type of behaviour when this profile is activated
|
||||
/// Disable all other profiles
|
||||
/// </summary>
|
||||
public enum ActivationBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// Do nothing to other profiles
|
||||
/// </summary>
|
||||
None,
|
||||
|
||||
/// <summary>
|
||||
/// Disable all other profiles
|
||||
/// </summary>
|
||||
DisableOthers,
|
||||
|
||||
/// <summary>
|
||||
/// Disable all other profiles below this one
|
||||
/// </summary>
|
||||
DisableOthersBelow,
|
||||
|
||||
/// <summary>
|
||||
/// Disable all other profiles above this one
|
||||
/// </summary>
|
||||
DisableOthersAbove,
|
||||
|
||||
/// <summary>
|
||||
/// Disable all other profiles in the same category
|
||||
/// </summary>
|
||||
DisableOthersInCategory,
|
||||
|
||||
/// <summary>
|
||||
/// Disable all other profiles below this one in the same category
|
||||
/// </summary>
|
||||
DisableOthersBelowInCategory,
|
||||
|
||||
/// <summary>
|
||||
/// Disable all other profiles above this one in the same category
|
||||
/// </summary>
|
||||
DisableOthersAboveInCategory
|
||||
}
|
||||
DisableOthers,
|
||||
|
||||
/// <summary>
|
||||
/// Represents a hotkey mode for a profile configuration
|
||||
/// Disable all other profiles below this one
|
||||
/// </summary>
|
||||
public enum ProfileConfigurationHotkeyMode
|
||||
{
|
||||
/// <summary>
|
||||
/// Use no hotkeys
|
||||
/// </summary>
|
||||
None,
|
||||
DisableOthersBelow,
|
||||
|
||||
/// <summary>
|
||||
/// Toggle the profile with one hotkey
|
||||
/// </summary>
|
||||
Toggle,
|
||||
/// <summary>
|
||||
/// Disable all other profiles above this one
|
||||
/// </summary>
|
||||
DisableOthersAbove,
|
||||
|
||||
/// <summary>
|
||||
/// Enable and disable the profile with two separate hotkeys
|
||||
/// </summary>
|
||||
EnableDisable
|
||||
}
|
||||
/// <summary>
|
||||
/// Disable all other profiles in the same category
|
||||
/// </summary>
|
||||
DisableOthersInCategory,
|
||||
|
||||
/// <summary>
|
||||
/// Disable all other profiles below this one in the same category
|
||||
/// </summary>
|
||||
DisableOthersBelowInCategory,
|
||||
|
||||
/// <summary>
|
||||
/// Disable all other profiles above this one in the same category
|
||||
/// </summary>
|
||||
DisableOthersAboveInCategory
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a hotkey mode for a profile configuration
|
||||
/// </summary>
|
||||
public enum ProfileConfigurationHotkeyMode
|
||||
{
|
||||
/// <summary>
|
||||
/// Use no hotkeys
|
||||
/// </summary>
|
||||
None,
|
||||
|
||||
/// <summary>
|
||||
/// Toggle the profile with one hotkey
|
||||
/// </summary>
|
||||
Toggle,
|
||||
|
||||
/// <summary>
|
||||
/// Enable and disable the profile with two separate hotkeys
|
||||
/// </summary>
|
||||
EnableDisable
|
||||
}
|
||||
@@ -4,34 +4,33 @@ using Artemis.Core.JsonConverters;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Artemis.Core
|
||||
namespace Artemis.Core;
|
||||
|
||||
/// <summary>
|
||||
/// A model that can be used to serialize a profile configuration, it's profile and it's icon
|
||||
/// </summary>
|
||||
public class ProfileConfigurationExportModel : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// A model that can be used to serialize a profile configuration, it's profile and it's icon
|
||||
/// Gets or sets the storage entity of the profile configuration
|
||||
/// </summary>
|
||||
public class ProfileConfigurationExportModel : IDisposable
|
||||
public ProfileConfigurationEntity? ProfileConfigurationEntity { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the storage entity of the profile
|
||||
/// </summary>
|
||||
[JsonProperty(Required = Required.Always)]
|
||||
public ProfileEntity ProfileEntity { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a stream containing the profile image
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(StreamConverter))]
|
||||
public Stream? ProfileImage { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the storage entity of the profile configuration
|
||||
/// </summary>
|
||||
public ProfileConfigurationEntity? ProfileConfigurationEntity { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the storage entity of the profile
|
||||
/// </summary>
|
||||
[JsonProperty(Required = Required.Always)]
|
||||
public ProfileEntity ProfileEntity { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a stream containing the profile image
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(StreamConverter))]
|
||||
public Stream? ProfileImage { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
ProfileImage?.Dispose();
|
||||
}
|
||||
ProfileImage?.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -3,168 +3,167 @@ using System.ComponentModel;
|
||||
using System.IO;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
|
||||
namespace Artemis.Core
|
||||
namespace Artemis.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Represents the icon of a <see cref="ProfileConfiguration" />
|
||||
/// </summary>
|
||||
public class ProfileConfigurationIcon : CorePropertyChanged, IStorageModel
|
||||
{
|
||||
private readonly ProfileConfigurationEntity _entity;
|
||||
private bool _fill;
|
||||
private string? _iconName;
|
||||
private Stream? _iconStream;
|
||||
private ProfileConfigurationIconType _iconType;
|
||||
private string? _originalFileName;
|
||||
|
||||
internal ProfileConfigurationIcon(ProfileConfigurationEntity entity)
|
||||
{
|
||||
_entity = entity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of icon this profile configuration uses
|
||||
/// </summary>
|
||||
public ProfileConfigurationIconType IconType
|
||||
{
|
||||
get => _iconType;
|
||||
private set => SetAndNotify(ref _iconType, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the icon if <see cref="IconType" /> is <see cref="ProfileConfigurationIconType.MaterialIcon" />
|
||||
/// </summary>
|
||||
public string? IconName
|
||||
{
|
||||
get => _iconName;
|
||||
private set => SetAndNotify(ref _iconName, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the original file name of the icon (if applicable)
|
||||
/// </summary>
|
||||
public string? OriginalFileName
|
||||
{
|
||||
get => _originalFileName;
|
||||
private set => SetAndNotify(ref _originalFileName, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a boolean indicating whether or not this icon should be filled.
|
||||
/// </summary>
|
||||
public bool Fill
|
||||
{
|
||||
get => _fill;
|
||||
set => SetAndNotify(ref _fill, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the <see cref="IconName" /> to the provided value and changes the <see cref="IconType" /> is
|
||||
/// <see cref="ProfileConfigurationIconType.MaterialIcon" />
|
||||
/// </summary>
|
||||
/// <param name="iconName">The name of the icon</param>
|
||||
public void SetIconByName(string iconName)
|
||||
{
|
||||
if (iconName == null) throw new ArgumentNullException(nameof(iconName));
|
||||
|
||||
_iconStream?.Dispose();
|
||||
IconName = iconName;
|
||||
OriginalFileName = null;
|
||||
IconType = ProfileConfigurationIconType.MaterialIcon;
|
||||
|
||||
OnIconUpdated();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the stream returned by <see cref="GetIconStream" /> to the provided stream
|
||||
/// </summary>
|
||||
/// <param name="originalFileName">The original file name backing the stream, should include the extension</param>
|
||||
/// <param name="stream">The stream to copy</param>
|
||||
public void SetIconByStream(string originalFileName, Stream stream)
|
||||
{
|
||||
if (originalFileName == null) throw new ArgumentNullException(nameof(originalFileName));
|
||||
if (stream == null) throw new ArgumentNullException(nameof(stream));
|
||||
|
||||
_iconStream?.Dispose();
|
||||
_iconStream = new MemoryStream();
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
stream.CopyTo(_iconStream);
|
||||
_iconStream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
IconName = null;
|
||||
OriginalFileName = originalFileName;
|
||||
IconType = ProfileConfigurationIconType.BitmapImage;
|
||||
OnIconUpdated();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a copy of the stream containing the icon
|
||||
/// </summary>
|
||||
/// <returns>A stream containing the icon</returns>
|
||||
public Stream? GetIconStream()
|
||||
{
|
||||
if (_iconStream == null)
|
||||
return null;
|
||||
|
||||
MemoryStream stream = new();
|
||||
_iconStream.CopyTo(stream);
|
||||
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
_iconStream.Seek(0, SeekOrigin.Begin);
|
||||
return stream;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the icon was updated
|
||||
/// </summary>
|
||||
public event EventHandler? IconUpdated;
|
||||
|
||||
/// <summary>
|
||||
/// Invokes the <see cref="IconUpdated" /> event
|
||||
/// </summary>
|
||||
protected virtual void OnIconUpdated()
|
||||
{
|
||||
IconUpdated?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
#region Implementation of IStorageModel
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Load()
|
||||
{
|
||||
IconType = (ProfileConfigurationIconType) _entity.IconType;
|
||||
Fill = _entity.IconFill;
|
||||
if (IconType != ProfileConfigurationIconType.MaterialIcon)
|
||||
return;
|
||||
|
||||
IconName = _entity.MaterialIcon;
|
||||
OnIconUpdated();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Save()
|
||||
{
|
||||
_entity.IconType = (int) IconType;
|
||||
_entity.MaterialIcon = IconType == ProfileConfigurationIconType.MaterialIcon ? IconName : null;
|
||||
_entity.IconFill = Fill;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a type of profile icon
|
||||
/// </summary>
|
||||
public enum ProfileConfigurationIconType
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the icon of a <see cref="ProfileConfiguration" />
|
||||
/// An icon picked from the Material Design Icons collection
|
||||
/// </summary>
|
||||
public class ProfileConfigurationIcon : CorePropertyChanged, IStorageModel
|
||||
{
|
||||
private readonly ProfileConfigurationEntity _entity;
|
||||
private Stream? _iconStream;
|
||||
private ProfileConfigurationIconType _iconType;
|
||||
private string? _iconName;
|
||||
private string? _originalFileName;
|
||||
private bool _fill;
|
||||
|
||||
internal ProfileConfigurationIcon(ProfileConfigurationEntity entity)
|
||||
{
|
||||
_entity = entity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of icon this profile configuration uses
|
||||
/// </summary>
|
||||
public ProfileConfigurationIconType IconType
|
||||
{
|
||||
get => _iconType;
|
||||
private set => SetAndNotify(ref _iconType, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the icon if <see cref="IconType" /> is <see cref="ProfileConfigurationIconType.MaterialIcon" />
|
||||
/// </summary>
|
||||
public string? IconName
|
||||
{
|
||||
get => _iconName;
|
||||
private set => SetAndNotify(ref _iconName, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the original file name of the icon (if applicable)
|
||||
/// </summary>
|
||||
public string? OriginalFileName
|
||||
{
|
||||
get => _originalFileName;
|
||||
private set => SetAndNotify(ref _originalFileName, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a boolean indicating whether or not this icon should be filled.
|
||||
/// </summary>
|
||||
public bool Fill
|
||||
{
|
||||
get => _fill;
|
||||
set => SetAndNotify(ref _fill, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the <see cref="IconName" /> to the provided value and changes the <see cref="IconType" /> is
|
||||
/// <see cref="ProfileConfigurationIconType.MaterialIcon" />
|
||||
/// </summary>
|
||||
/// <param name="iconName">The name of the icon</param>
|
||||
public void SetIconByName(string iconName)
|
||||
{
|
||||
if (iconName == null) throw new ArgumentNullException(nameof(iconName));
|
||||
|
||||
_iconStream?.Dispose();
|
||||
IconName = iconName;
|
||||
OriginalFileName = null;
|
||||
IconType = ProfileConfigurationIconType.MaterialIcon;
|
||||
|
||||
OnIconUpdated();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the stream returned by <see cref="GetIconStream" /> to the provided stream
|
||||
/// </summary>
|
||||
/// <param name="originalFileName">The original file name backing the stream, should include the extension</param>
|
||||
/// <param name="stream">The stream to copy</param>
|
||||
public void SetIconByStream(string originalFileName, Stream stream)
|
||||
{
|
||||
if (originalFileName == null) throw new ArgumentNullException(nameof(originalFileName));
|
||||
if (stream == null) throw new ArgumentNullException(nameof(stream));
|
||||
|
||||
_iconStream?.Dispose();
|
||||
_iconStream = new MemoryStream();
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
stream.CopyTo(_iconStream);
|
||||
_iconStream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
IconName = null;
|
||||
OriginalFileName = originalFileName;
|
||||
IconType = ProfileConfigurationIconType.BitmapImage;
|
||||
OnIconUpdated();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a copy of the stream containing the icon
|
||||
/// </summary>
|
||||
/// <returns>A stream containing the icon</returns>
|
||||
public Stream? GetIconStream()
|
||||
{
|
||||
if (_iconStream == null)
|
||||
return null;
|
||||
|
||||
MemoryStream stream = new();
|
||||
_iconStream.CopyTo(stream);
|
||||
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
_iconStream.Seek(0, SeekOrigin.Begin);
|
||||
return stream;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the icon was updated
|
||||
/// </summary>
|
||||
public event EventHandler? IconUpdated;
|
||||
|
||||
/// <summary>
|
||||
/// Invokes the <see cref="IconUpdated" /> event
|
||||
/// </summary>
|
||||
protected virtual void OnIconUpdated()
|
||||
{
|
||||
IconUpdated?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
#region Implementation of IStorageModel
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Load()
|
||||
{
|
||||
IconType = (ProfileConfigurationIconType) _entity.IconType;
|
||||
Fill = _entity.IconFill;
|
||||
if (IconType != ProfileConfigurationIconType.MaterialIcon)
|
||||
return;
|
||||
|
||||
IconName = _entity.MaterialIcon;
|
||||
OnIconUpdated();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Save()
|
||||
{
|
||||
_entity.IconType = (int) IconType;
|
||||
_entity.MaterialIcon = IconType == ProfileConfigurationIconType.MaterialIcon ? IconName : null;
|
||||
_entity.IconFill = Fill;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
[Description("Material Design Icon")] MaterialIcon,
|
||||
|
||||
/// <summary>
|
||||
/// Represents a type of profile icon
|
||||
/// A bitmap image icon
|
||||
/// </summary>
|
||||
public enum ProfileConfigurationIconType
|
||||
{
|
||||
/// <summary>
|
||||
/// An icon picked from the Material Design Icons collection
|
||||
/// </summary>
|
||||
[Description("Material Design Icon")] MaterialIcon,
|
||||
|
||||
/// <summary>
|
||||
/// A bitmap image icon
|
||||
/// </summary>
|
||||
[Description("Bitmap Image")] BitmapImage,
|
||||
}
|
||||
[Description("Bitmap Image")] BitmapImage
|
||||
}
|
||||
Reference in new issue
Block a user