mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 20:06:33 +00:00
Added most of the settings code, doesn't work because SQLite is weird
This commit is contained in:
1 parent
231e5e7517
commit
ac577e87cc
42 files changed
+409
-582
No files matched your search
@@ -0,0 +1,35 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Artemis.Storage.Entities;
|
||||
using Artemis.Storage.Repositories;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Artemis.Core.Plugins.Models
|
||||
{
|
||||
public class PluginSettings
|
||||
{
|
||||
private readonly PluginInfo _pluginInfo;
|
||||
private readonly ISettingRepository _settingRepository;
|
||||
private readonly Dictionary<string, SettingEntity> _settingEntities;
|
||||
|
||||
public PluginSettings(PluginInfo pluginInfo, ISettingRepository settingRepository)
|
||||
{
|
||||
_pluginInfo = pluginInfo;
|
||||
_settingRepository = settingRepository;
|
||||
_settingEntities = settingRepository.GetByPluginGuid(_pluginInfo.Guid).ToDictionary(se => se.Name);
|
||||
}
|
||||
|
||||
public PluginSetting<T> GetSetting<T>(string name, T defaultValue = default)
|
||||
{
|
||||
if (_settingEntities.ContainsKey(name))
|
||||
return new PluginSetting<T>(_pluginInfo, _settingRepository, _settingEntities[name]);
|
||||
|
||||
var settingEntity = new SettingEntity {Name = name, PluginGuid = _pluginInfo.Guid, Value = JsonConvert.SerializeObject(defaultValue)};
|
||||
_settingRepository.Add(settingEntity);
|
||||
_settingRepository.Save();
|
||||
|
||||
_settingEntities.Add(name, settingEntity);
|
||||
return GetSetting(name, defaultValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user