Storage - Replace LiteDB with SQLite + EF Core (#843)

Storage - Added LiteDB to SQLite migration
UI - Try to die a bit more gracefully
Core - Delay start watching plugins for hot reload after initializing
UI - Simplify category management logic
UI - Avoid crash during profile icon load
Storage - Fix entry metadata retrieval
This commit is contained in:
RobertBeekman authored and GitHub committed 2024-03-13 20:19:21 +01:00
1 parent 9132301dbf
commit 551921db9f
130 files changed
+2965 -1135

No files matched your search

+9 -13
View File
@@ -23,14 +23,14 @@ public class Plugin : CorePropertyChanged, IDisposable
private bool _isEnabled;
internal Plugin(PluginInfo info, DirectoryInfo directory, PluginEntity? pluginEntity)
internal Plugin(PluginInfo info, DirectoryInfo directory, PluginEntity pluginEntity, bool loadedFromStorage)
{
Info = info;
Directory = directory;
Entity = pluginEntity ?? new PluginEntity {Id = Guid};
Entity = pluginEntity;
Info.Plugin = this;
_loadedFromStorage = pluginEntity != null;
_loadedFromStorage = loadedFromStorage;
_features = new List<PluginFeatureInfo>();
_profilers = new List<Profiler>();
@@ -309,13 +309,7 @@ public class Plugin : CorePropertyChanged, IDisposable
{
FeatureRemoved?.Invoke(this, e);
}
internal void ApplyToEntity()
{
Entity.Id = Guid;
Entity.IsEnabled = IsEnabled;
}
internal void AddFeature(PluginFeatureInfo featureInfo)
{
if (featureInfo.Plugin != this)
@@ -363,10 +357,10 @@ public class Plugin : CorePropertyChanged, IDisposable
return Entity.Features.Any(f => f.IsEnabled) || Features.Any(f => f.AlwaysEnabled);
}
internal void AutoEnableIfNew()
internal bool AutoEnableIfNew()
{
if (_loadedFromStorage)
return;
return false;
// Enabled is preset to true if the plugin meets the following criteria
// - Requires no admin rights
@@ -377,11 +371,13 @@ public class Plugin : CorePropertyChanged, IDisposable
Info.ArePrerequisitesMet();
if (!Entity.IsEnabled)
return;
return false;
// Also auto-enable any non-device provider feature
foreach (PluginFeatureInfo pluginFeatureInfo in Features)
pluginFeatureInfo.Entity.IsEnabled = !pluginFeatureInfo.FeatureType.IsAssignableTo(typeof(DeviceProvider));
return true;
}
/// <inheritdoc />
@@ -1,4 +1,5 @@
using System;
using System.Text.Json;
namespace Artemis.Core;
@@ -7,19 +8,18 @@ namespace Artemis.Core;
/// </summary>
public interface IPluginSetting
{
/// <summary>
/// The JSON serializer options used when serializing settings
/// </summary>
protected static readonly JsonSerializerOptions SerializerOptions = CoreJson.GetJsonSerializerOptions();
/// <summary>
/// The name of the setting, unique to this plugin
/// </summary>
string Name { get; }
/// <summary>
/// Determines whether the setting has been changed
/// </summary>
bool HasChanged { get; }
/// <summary>
/// Gets or sets whether changes must automatically be saved
/// <para>Note: When set to <c>true</c> <see cref="HasChanged" /> is always <c>false</c></para>
/// Gets or sets whether changes must automatically be saved
/// </summary>
bool AutoSave { get; set; }
@@ -31,10 +31,13 @@ public class PluginSettings
/// Gets the setting with the provided name. If the setting does not exist yet, it is created.
/// </summary>
/// <typeparam name="T">The type of the setting, can be any serializable type</typeparam>
/// <param name="name">The name of the setting</param>
/// <param name="name">The name of the setting, may not be longer than 128 characters</param>
/// <param name="defaultValue">The default value to use if the setting does not exist yet</param>
public PluginSetting<T> GetSetting<T>(string name, T? defaultValue = default)
{
if (name.Length > 128)
throw new ArtemisCoreException("Setting name cannot be longer than 128 characters");
lock (_settingEntities)
{
// Return cached value if available
@@ -51,7 +54,7 @@ public class PluginSettings
PluginGuid = Plugin.Guid,
Value = CoreJson.Serialize(defaultValue)
};
_pluginRepository.AddSetting(settingEntity);
_pluginRepository.SaveSetting(settingEntity);
}
PluginSetting<T> pluginSetting = new(_pluginRepository, settingEntity);