| | | 1 | | #pragma warning disable CS1591 |
| | | 2 | | |
| | | 3 | | using System; |
| | | 4 | | using System.Globalization; |
| | | 5 | | using System.IO; |
| | | 6 | | using MediaBrowser.Common.Configuration; |
| | | 7 | | using MediaBrowser.Model.Configuration; |
| | | 8 | | |
| | | 9 | | namespace MediaBrowser.MediaEncoding.Configuration |
| | | 10 | | { |
| | | 11 | | public class EncodingConfigurationStore : ConfigurationStore, IValidatingConfiguration |
| | | 12 | | { |
| | 21 | 13 | | public EncodingConfigurationStore() |
| | | 14 | | { |
| | 21 | 15 | | ConfigurationType = typeof(EncodingOptions); |
| | 21 | 16 | | Key = "encoding"; |
| | 21 | 17 | | } |
| | | 18 | | |
| | | 19 | | public void Validate(object oldConfig, object newConfig) |
| | | 20 | | { |
| | 0 | 21 | | var oldEncodingOptions = (EncodingOptions)oldConfig; |
| | 0 | 22 | | var newEncodingOptions = (EncodingOptions)newConfig; |
| | | 23 | | |
| | 0 | 24 | | ArgumentNullException.ThrowIfNull(oldEncodingOptions, nameof(oldConfig)); |
| | 0 | 25 | | ArgumentNullException.ThrowIfNull(newEncodingOptions, nameof(newConfig)); |
| | | 26 | | |
| | 0 | 27 | | var newPath = newEncodingOptions.TranscodingTempPath; |
| | | 28 | | |
| | 0 | 29 | | if (!string.IsNullOrWhiteSpace(newPath) |
| | 0 | 30 | | && !string.Equals(oldEncodingOptions.TranscodingTempPath, newPath, StringComparison.Ordinal)) |
| | | 31 | | { |
| | | 32 | | // Validate |
| | 0 | 33 | | if (!Directory.Exists(newPath)) |
| | | 34 | | { |
| | 0 | 35 | | throw new DirectoryNotFoundException( |
| | 0 | 36 | | string.Format( |
| | 0 | 37 | | CultureInfo.InvariantCulture, |
| | 0 | 38 | | "{0} does not exist.", |
| | 0 | 39 | | newPath)); |
| | | 40 | | } |
| | | 41 | | } |
| | | 42 | | |
| | 0 | 43 | | if (!string.IsNullOrWhiteSpace(newEncodingOptions.EncoderAppPath) |
| | 0 | 44 | | && !string.Equals(oldEncodingOptions.EncoderAppPath, newEncodingOptions.EncoderAppPath, StringComparison |
| | | 45 | | { |
| | 0 | 46 | | throw new InvalidOperationException("Unable to update encoder app path."); |
| | | 47 | | } |
| | 0 | 48 | | } |
| | | 49 | | } |
| | | 50 | | } |