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.
48 lines
1.1 KiB
48 lines
1.1 KiB
using System.IO.Abstractions;
|
|
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)
|
|
{
|
|
configs.AddRange(_paths.ConfigsDirectory.EnumerateFiles("*.yml"));
|
|
}
|
|
|
|
if (_paths.ConfigPath.Exists)
|
|
{
|
|
configs.Add(_paths.ConfigPath);
|
|
}
|
|
|
|
return configs;
|
|
}
|
|
|
|
public IReadOnlyCollection<IFileInfo> GetConfigFiles(IReadOnlyCollection<IFileInfo>? configs)
|
|
{
|
|
if (configs is not null && configs.Any())
|
|
{
|
|
return configs;
|
|
}
|
|
|
|
configs = FindDefaultConfigFiles();
|
|
if (configs.Count == 0)
|
|
{
|
|
throw new NoConfigurationFilesException();
|
|
}
|
|
|
|
return configs;
|
|
}
|
|
}
|