mirror of
				https://github.com/jellyfin/jellyfin.git
				synced 2025-11-04 03:27:21 -05:00 
			
		
		
		
	
		
			
				
	
	
		
			57 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			57 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
using MediaBrowser.Common.Configuration;
 | 
						|
using MediaBrowser.Model.Configuration;
 | 
						|
using System.Collections.Generic;
 | 
						|
using System.IO;
 | 
						|
using MediaBrowser.Common.IO;
 | 
						|
 | 
						|
namespace MediaBrowser.MediaEncoding.Configuration
 | 
						|
{
 | 
						|
    public class EncodingConfigurationFactory : IConfigurationFactory
 | 
						|
    {
 | 
						|
        private readonly IFileSystem _fileSystem;
 | 
						|
 | 
						|
        public EncodingConfigurationFactory(IFileSystem fileSystem)
 | 
						|
        {
 | 
						|
            _fileSystem = fileSystem;
 | 
						|
        }
 | 
						|
 | 
						|
        public IEnumerable<ConfigurationStore> GetConfigurations()
 | 
						|
        {
 | 
						|
            return new[]
 | 
						|
            {
 | 
						|
                new EncodingConfigurationStore(_fileSystem)
 | 
						|
            };
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    public class EncodingConfigurationStore : ConfigurationStore, IValidatingConfiguration
 | 
						|
    {
 | 
						|
        private readonly IFileSystem _fileSystem;
 | 
						|
 | 
						|
        public EncodingConfigurationStore(IFileSystem fileSystem)
 | 
						|
        {
 | 
						|
            ConfigurationType = typeof(EncodingOptions);
 | 
						|
            Key = "encoding";
 | 
						|
            _fileSystem = fileSystem;
 | 
						|
        }
 | 
						|
 | 
						|
        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
 | 
						|
                if (!_fileSystem.DirectoryExists(newPath))
 | 
						|
                {
 | 
						|
                    throw new DirectoryNotFoundException(string.Format("{0} does not exist.", newPath));
 | 
						|
                }
 | 
						|
            }
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 |