|
|
@ -2,22 +2,19 @@ using System.IO.Abstractions;
|
|
|
|
using Recyclarr.Common.Extensions;
|
|
|
|
using Recyclarr.Common.Extensions;
|
|
|
|
using Recyclarr.Platform;
|
|
|
|
using Recyclarr.Platform;
|
|
|
|
using Recyclarr.Yaml;
|
|
|
|
using Recyclarr.Yaml;
|
|
|
|
using Serilog;
|
|
|
|
|
|
|
|
using YamlDotNet.Core;
|
|
|
|
using YamlDotNet.Core;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Recyclarr.Settings;
|
|
|
|
namespace Recyclarr.Settings;
|
|
|
|
|
|
|
|
|
|
|
|
public class SettingsProvider : ISettingsProvider
|
|
|
|
public class SettingsProvider : ISettingsProvider
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private readonly ILogger _log;
|
|
|
|
|
|
|
|
private readonly IAppPaths _paths;
|
|
|
|
private readonly IAppPaths _paths;
|
|
|
|
private readonly Lazy<SettingsValues> _settings;
|
|
|
|
private readonly Lazy<SettingsValues> _settings;
|
|
|
|
|
|
|
|
|
|
|
|
public SettingsValues Settings => _settings.Value;
|
|
|
|
public SettingsValues Settings => _settings.Value;
|
|
|
|
|
|
|
|
|
|
|
|
public SettingsProvider(ILogger log, IAppPaths paths, IYamlSerializerFactory serializerFactory)
|
|
|
|
public SettingsProvider(IAppPaths paths, IYamlSerializerFactory serializerFactory)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_log = log;
|
|
|
|
|
|
|
|
_paths = paths;
|
|
|
|
_paths = paths;
|
|
|
|
_settings = new Lazy<SettingsValues>(() => LoadOrCreateSettingsFile(serializerFactory));
|
|
|
|
_settings = new Lazy<SettingsValues>(() => LoadOrCreateSettingsFile(serializerFactory));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -34,14 +31,7 @@ public class SettingsProvider : ISettingsProvider
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (YamlException e)
|
|
|
|
catch (YamlException e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_log.Error(e, "Exception while parsing settings.yml at line {Line}", e.Start.Line);
|
|
|
|
e.Data["ContextualMessage"] = SettingsContextualMessages.GetContextualErrorFromException(e);
|
|
|
|
|
|
|
|
|
|
|
|
var context = SettingsContextualMessages.GetContextualErrorFromException(e);
|
|
|
|
|
|
|
|
if (context is not null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_log.Error(context);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
throw;
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|