2019-11-08 11:49:00 +00:00
|
|
|
using System;
|
2019-01-13 20:02:23 +00:00
|
|
|
using System.Collections.Generic;
|
2019-11-08 11:49:00 +00:00
|
|
|
using System.Globalization;
|
2018-12-14 09:40:55 +00:00
|
|
|
using System.IO;
|
2019-01-13 19:26:04 +00:00
|
|
|
using MediaBrowser.Common.Configuration;
|
|
|
|
using MediaBrowser.Model.Configuration;
|
2018-12-14 09:40:55 +00:00
|
|
|
|
|
|
|
namespace MediaBrowser.MediaEncoding.Configuration
|
|
|
|
{
|
|
|
|
public class EncodingConfigurationFactory : IConfigurationFactory
|
|
|
|
{
|
|
|
|
public IEnumerable<ConfigurationStore> GetConfigurations()
|
|
|
|
{
|
|
|
|
return new[]
|
|
|
|
{
|
2019-11-08 11:49:00 +00:00
|
|
|
new EncodingConfigurationStore()
|
2018-12-14 09:40:55 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class EncodingConfigurationStore : ConfigurationStore, IValidatingConfiguration
|
|
|
|
{
|
2019-11-08 11:49:00 +00:00
|
|
|
public EncodingConfigurationStore()
|
2018-12-14 09:40:55 +00:00
|
|
|
{
|
|
|
|
ConfigurationType = typeof(EncodingOptions);
|
|
|
|
Key = "encoding";
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Validate(object oldConfig, object newConfig)
|
|
|
|
{
|
2019-11-08 11:49:00 +00:00
|
|
|
var newPath = ((EncodingOptions)newConfig).TranscodingTempPath;
|
2018-12-14 09:40:55 +00:00
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(newPath)
|
2019-11-08 11:49:00 +00:00
|
|
|
&& !string.Equals(((EncodingOptions)oldConfig).TranscodingTempPath, newPath, StringComparison.Ordinal))
|
2018-12-14 09:40:55 +00:00
|
|
|
{
|
|
|
|
// Validate
|
2019-01-29 13:45:07 +00:00
|
|
|
if (!Directory.Exists(newPath))
|
2018-12-14 09:40:55 +00:00
|
|
|
{
|
2019-11-08 11:49:00 +00:00
|
|
|
throw new DirectoryNotFoundException(
|
|
|
|
string.Format(
|
|
|
|
CultureInfo.InvariantCulture,
|
|
|
|
"{0} does not exist.",
|
|
|
|
newPath));
|
2018-12-14 09:40:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|