EncodingConfigurationFactory.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #pragma warning disable CS1591
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Globalization;
  5. using System.IO;
  6. using MediaBrowser.Common.Configuration;
  7. using MediaBrowser.Model.Configuration;
  8. namespace MediaBrowser.MediaEncoding.Configuration
  9. {
  10. public class EncodingConfigurationFactory : IConfigurationFactory
  11. {
  12. public IEnumerable<ConfigurationStore> GetConfigurations()
  13. {
  14. return new[]
  15. {
  16. new EncodingConfigurationStore()
  17. };
  18. }
  19. }
  20. public class EncodingConfigurationStore : ConfigurationStore, IValidatingConfiguration
  21. {
  22. public EncodingConfigurationStore()
  23. {
  24. ConfigurationType = typeof(EncodingOptions);
  25. Key = "encoding";
  26. }
  27. public void Validate(object oldConfig, object newConfig)
  28. {
  29. var newPath = ((EncodingOptions)newConfig).TranscodingTempPath;
  30. if (!string.IsNullOrWhiteSpace(newPath)
  31. && !string.Equals(((EncodingOptions)oldConfig).TranscodingTempPath, newPath, StringComparison.Ordinal))
  32. {
  33. // Validate
  34. if (!Directory.Exists(newPath))
  35. {
  36. throw new DirectoryNotFoundException(
  37. string.Format(
  38. CultureInfo.InvariantCulture,
  39. "{0} does not exist.",
  40. newPath));
  41. }
  42. }
  43. }
  44. }
  45. }