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