You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.3 KiB
53 lines
1.3 KiB
using System.IO.Abstractions;
|
|
using Recyclarr.Common.Extensions;
|
|
using Recyclarr.TrashLib.Config.Parsing.ErrorHandling;
|
|
using Recyclarr.TrashLib.Startup;
|
|
|
|
namespace Recyclarr.TrashLib.Config.Parsing;
|
|
|
|
public class ConfigurationFinder : IConfigurationFinder
|
|
{
|
|
private readonly IAppPaths _paths;
|
|
|
|
public ConfigurationFinder(IAppPaths paths)
|
|
{
|
|
_paths = paths;
|
|
}
|
|
|
|
private IReadOnlyCollection<IFileInfo> FindDefaultConfigFiles()
|
|
{
|
|
var configs = new List<IFileInfo>();
|
|
|
|
if (_paths.ConfigsDirectory.Exists)
|
|
{
|
|
var extensions = new[] {"*.yml", "*.yaml"};
|
|
var files = extensions.SelectMany(x => _paths.ConfigsDirectory.EnumerateFiles(x));
|
|
configs.AddRange(files);
|
|
}
|
|
|
|
var configPath = _paths.AppDataDirectory.YamlFile("recyclarr");
|
|
if (configPath is not null)
|
|
{
|
|
configs.Add(configPath);
|
|
}
|
|
|
|
return configs;
|
|
}
|
|
|
|
public IReadOnlyCollection<IFileInfo> GetConfigFiles(IReadOnlyCollection<IFileInfo>? configs = null)
|
|
{
|
|
if (configs is not null && configs.Any())
|
|
{
|
|
return configs;
|
|
}
|
|
|
|
configs = FindDefaultConfigFiles();
|
|
if (configs.Count == 0)
|
|
{
|
|
throw new NoConfigurationFilesException();
|
|
}
|
|
|
|
return configs;
|
|
}
|
|
}
|