jellyfin/MediaBrowser.MediaEncoding/Configuration/EncodingConfigurationFactory.cs

59 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;
2017-05-25 23:48:54 -07:00
2016-10-25 12:02:04 -07:00
using MediaBrowser.Controller.IO;
using MediaBrowser.Model.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
{
2016-10-30 00:11:37 -07:00
throw new FileNotFoundException(string.Format("{0} does not exist.", newPath));
2014-12-21 12:40:37 -07:00
}
}
}
}
}