jellyfin-server/MediaBrowser.MediaEncoding/Configuration/EncodingConfigurationFactory.cs
Vasily 91e99effc9
Apply suggestions from code review for flipped conditions.
Co-Authored-By: EraYaN <EraYaN@users.noreply.github.com>
2019-01-29 14:45:07 +01:00

57 lines
1.7 KiB
C#

using System.Collections.Generic;
using System.IO;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.IO;
namespace MediaBrowser.MediaEncoding.Configuration
{
public class EncodingConfigurationFactory : IConfigurationFactory
{
private readonly IFileSystem _fileSystem;
public EncodingConfigurationFactory(IFileSystem fileSystem)
{
_fileSystem = fileSystem;
}
public IEnumerable<ConfigurationStore> GetConfigurations()
{
return new[]
{
new EncodingConfigurationStore(_fileSystem)
};
}
}
public class EncodingConfigurationStore : ConfigurationStore, IValidatingConfiguration
{
private readonly IFileSystem _fileSystem;
public EncodingConfigurationStore(IFileSystem fileSystem)
{
ConfigurationType = typeof(EncodingOptions);
Key = "encoding";
_fileSystem = fileSystem;
}
public void Validate(object oldConfig, object newConfig)
{
var oldEncodingConfig = (EncodingOptions)oldConfig;
var newEncodingConfig = (EncodingOptions)newConfig;
var newPath = newEncodingConfig.TranscodingTempPath;
if (!string.IsNullOrWhiteSpace(newPath)
&& !string.Equals(oldEncodingConfig.TranscodingTempPath ?? string.Empty, newPath))
{
// Validate
if (!Directory.Exists(newPath))
{
throw new FileNotFoundException(string.Format("{0} does not exist.", newPath));
}
}
}
}
}