jellyfin-server/MediaBrowser.MediaEncoding/Configuration/EncodingConfigurationFactory.cs

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