mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Modules - Added IsActivatedOverride which indicates exactly that
Core - During creation ensure all local users can access the data folder Core - Wrap exceptions during module enable/disable in PluginExceptions
This commit is contained in:
parent
0beae810ea
commit
cf8e6e1b2b
@ -1,4 +1,6 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Security.AccessControl;
|
||||||
|
using System.Security.Principal;
|
||||||
using Artemis.Core.Exceptions;
|
using Artemis.Core.Exceptions;
|
||||||
using Artemis.Core.Plugins.Settings;
|
using Artemis.Core.Plugins.Settings;
|
||||||
using Artemis.Core.Services.Interfaces;
|
using Artemis.Core.Services.Interfaces;
|
||||||
@ -44,10 +46,6 @@ namespace Artemis.Core.Ninject
|
|||||||
|
|
||||||
Kernel.Bind<LiteRepository>().ToMethod(t =>
|
Kernel.Bind<LiteRepository>().ToMethod(t =>
|
||||||
{
|
{
|
||||||
// Ensure the data folder exists
|
|
||||||
if (!Directory.Exists(Constants.DataFolder))
|
|
||||||
Directory.CreateDirectory(Constants.DataFolder);
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return new LiteRepository(Constants.ConnectionString);
|
return new LiteRepository(Constants.ConnectionString);
|
||||||
|
|||||||
@ -91,6 +91,12 @@ namespace Artemis.Core.Plugins.Modules
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsActivated { get; internal set; }
|
public bool IsActivated { get; internal set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets whether this module's activation was due to an override, can only be true if <see cref="IsActivated" /> is
|
||||||
|
/// true
|
||||||
|
/// </summary>
|
||||||
|
public bool IsActivatedOverride { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A list of activation requirements
|
/// A list of activation requirements
|
||||||
/// <para>Note: if empty the module is always activated</para>
|
/// <para>Note: if empty the module is always activated</para>
|
||||||
@ -182,6 +188,7 @@ namespace Artemis.Core.Plugins.Modules
|
|||||||
if (IsActivated)
|
if (IsActivated)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
IsActivatedOverride = isOverride;
|
||||||
ModuleActivated(isOverride);
|
ModuleActivated(isOverride);
|
||||||
IsActivated = true;
|
IsActivated = true;
|
||||||
}
|
}
|
||||||
@ -191,6 +198,7 @@ namespace Artemis.Core.Plugins.Modules
|
|||||||
if (!IsActivated)
|
if (!IsActivated)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
IsActivatedOverride = false;
|
||||||
IsActivated = false;
|
IsActivated = false;
|
||||||
ModuleDeactivated(isOverride);
|
ModuleDeactivated(isOverride);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,6 +7,7 @@ using System.Threading.Tasks;
|
|||||||
using System.Timers;
|
using System.Timers;
|
||||||
using Artemis.Core.Events;
|
using Artemis.Core.Events;
|
||||||
using Artemis.Core.Exceptions;
|
using Artemis.Core.Exceptions;
|
||||||
|
using Artemis.Core.Plugins.Exceptions;
|
||||||
using Artemis.Core.Plugins.Modules;
|
using Artemis.Core.Plugins.Modules;
|
||||||
using Artemis.Core.Services.Interfaces;
|
using Artemis.Core.Services.Interfaces;
|
||||||
using Artemis.Core.Services.Storage.Interfaces;
|
using Artemis.Core.Services.Storage.Interfaces;
|
||||||
@ -156,20 +157,36 @@ namespace Artemis.Core.Services
|
|||||||
|
|
||||||
private async Task ActivateModule(Module module, bool isOverride)
|
private async Task ActivateModule(Module module, bool isOverride)
|
||||||
{
|
{
|
||||||
module.Activate(isOverride);
|
try
|
||||||
|
{
|
||||||
|
module.Activate(isOverride);
|
||||||
|
|
||||||
// If this is a profile module, activate the last active profile after module activation
|
// If this is a profile module, activate the last active profile after module activation
|
||||||
if (module is ProfileModule profileModule)
|
if (module is ProfileModule profileModule)
|
||||||
await _profileService.ActivateLastProfileAnimated(profileModule);
|
await _profileService.ActivateLastProfileAnimated(profileModule);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.Error(new ArtemisPluginException(module.PluginInfo, "Failed to activate module and last profile.", e), "Failed to activate module and last profile");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task DeactivateModule(Module module, bool isOverride)
|
private async Task DeactivateModule(Module module, bool isOverride)
|
||||||
{
|
{
|
||||||
// If this is a profile module, activate the last active profile after module activation
|
try
|
||||||
if (module.IsActivated && module is ProfileModule profileModule)
|
{
|
||||||
await profileModule.ChangeActiveProfileAnimated(null, null);
|
// If this is a profile module, activate the last active profile after module activation
|
||||||
|
if (module.IsActivated && module is ProfileModule profileModule)
|
||||||
|
await profileModule.ChangeActiveProfileAnimated(null, null);
|
||||||
|
|
||||||
module.Deactivate(isOverride);
|
module.Deactivate(isOverride);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.Error(new ArtemisPluginException(module.PluginInfo, "Failed to deactivate module and last profile.", e), "Failed to deactivate module and last profile");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PopulatePriorities()
|
private void PopulatePriorities()
|
||||||
|
|||||||
@ -1,13 +1,15 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Security.AccessControl;
|
||||||
|
using System.Security.Principal;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Documents;
|
|
||||||
using System.Windows.Markup;
|
using System.Windows.Markup;
|
||||||
using System.Windows.Threading;
|
using System.Windows.Threading;
|
||||||
using Artemis.Core.Models.Profile.Conditions;
|
using Artemis.Core;
|
||||||
using Artemis.Core.Ninject;
|
using Artemis.Core.Ninject;
|
||||||
using Artemis.Core.Services.Interfaces;
|
using Artemis.Core.Services.Interfaces;
|
||||||
using Artemis.UI.Ninject;
|
using Artemis.UI.Ninject;
|
||||||
@ -37,11 +39,12 @@ namespace Artemis.UI
|
|||||||
|
|
||||||
protected override void Launch()
|
protected override void Launch()
|
||||||
{
|
{
|
||||||
StartupArguments = Args.ToList();
|
|
||||||
|
|
||||||
var logger = Kernel.Get<ILogger>();
|
var logger = Kernel.Get<ILogger>();
|
||||||
var viewManager = Kernel.Get<IViewManager>();
|
var viewManager = Kernel.Get<IViewManager>();
|
||||||
|
|
||||||
|
StartupArguments = Args.ToList();
|
||||||
|
CreateDataDirectory(logger);
|
||||||
|
|
||||||
// Create the Artemis core
|
// Create the Artemis core
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -113,6 +116,29 @@ namespace Artemis.UI
|
|||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void CreateDataDirectory(ILogger logger)
|
||||||
|
{
|
||||||
|
// Ensure the data folder exists
|
||||||
|
if (Directory.Exists(Constants.DataFolder))
|
||||||
|
return;
|
||||||
|
|
||||||
|
logger.Information("Creating data directory at {dataDirectoryFolder}", Constants.DataFolder);
|
||||||
|
Directory.CreateDirectory(Constants.DataFolder);
|
||||||
|
|
||||||
|
// During creation ensure all local users can access the data folder
|
||||||
|
// This is needed when later running Artemis as a different user or when Artemis is first run as admin
|
||||||
|
var directoryInfo = new DirectoryInfo(Constants.DataFolder);
|
||||||
|
var accessControl = directoryInfo.GetAccessControl();
|
||||||
|
accessControl.AddAccessRule(new FileSystemAccessRule(
|
||||||
|
new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null),
|
||||||
|
FileSystemRights.FullControl,
|
||||||
|
InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit,
|
||||||
|
PropagationFlags.InheritOnly,
|
||||||
|
AccessControlType.Allow)
|
||||||
|
);
|
||||||
|
directoryInfo.SetAccessControl(accessControl);
|
||||||
|
}
|
||||||
|
|
||||||
private void HandleFatalException(Exception e, ILogger logger)
|
private void HandleFatalException(Exception e, ILogger logger)
|
||||||
{
|
{
|
||||||
logger.Fatal(e, "Fatal exception during initialization, shutting down.");
|
logger.Fatal(e, "Fatal exception during initialization, shutting down.");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user