jellyfin/MediaBrowser.MediaEncoding/Configuration/EncodingConfigurationFactory.cs

58 lines
1.7 KiB
C#
Raw Normal View History

2014-12-21 12:40:37 -07:00
using MediaBrowser.Common.Configuration;
using MediaBrowser.Model.Configuration;
using System.Collections.Generic;
using System.IO;
2015-10-03 21:23:11 -07:00
using CommonIO;
2015-09-13 16:07:54 -07:00
using MediaBrowser.Common.IO;
2014-12-21 12:40:37 -07:00
namespace MediaBrowser.MediaEncoding.Configuration
{
public class EncodingConfigurationFactory : IConfigurationFactory
{
2015-09-13 16:07:54 -07:00
private readonly IFileSystem _fileSystem;
public EncodingConfigurationFactory(IFileSystem fileSystem)
{
_fileSystem = fileSystem;
}
2014-12-21 12:40:37 -07:00
public IEnumerable<ConfigurationStore> GetConfigurations()
{
return new[]
{
2015-09-13 16:07:54 -07:00
new EncodingConfigurationStore(_fileSystem)
2014-12-21 12:40:37 -07:00
};
}
}
public class EncodingConfigurationStore : ConfigurationStore, IValidatingConfiguration
{
2015-09-13 16:07:54 -07:00
private readonly IFileSystem _fileSystem;
public EncodingConfigurationStore(IFileSystem fileSystem)
2014-12-21 12:40:37 -07:00
{
ConfigurationType = typeof(EncodingOptions);
Key = "encoding";
2015-09-13 16:07:54 -07:00
_fileSystem = fileSystem;
2014-12-21 12:40:37 -07:00
}
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
2015-09-13 16:07:54 -07:00
if (!_fileSystem.DirectoryExists(newPath))
2014-12-21 12:40:37 -07:00
{
throw new DirectoryNotFoundException(string.Format("{0} does not exist.", newPath));
}
}
}
}
}