jellyfin/MediaBrowser.MediaEncoding/Configuration/EncodingConfigurationFactory.cs

58 lines
1.7 KiB
C#
Raw Normal View History

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