@@ -35,24 +35,28 @@ public class Preferences
3535 /// </summary>
3636 public bool UpdateStatusBar { get ; set ; } = true ;
3737
38- /// <summary>
39- /// Gets or sets the list of enabled compression algorithms.
40- /// </summary>
41- public List < string > EnabledCompressionAlgorithms { get ; set ; } = new List < string > ( ) ;
42-
4338 /// <summary>
4439 /// Gets the compression algorithms available.
4540 /// </summary>
4641 public IEnumerable < CompressionSettings > CompressionAlgorithms => GetType ( ) . GetProperties ( )
4742 . Where ( m => m . PropertyType . IsSubclassOf ( typeof ( CompressionSettings ) ) )
48- . Select ( m => ( CompressionSettings ) m . GetValue ( this ) ! ) ;
43+ . Select ( m => ( CompressionSettings ) m . GetValue ( this ) ! )
44+ . OrderBy ( ( settings ) => settings . SortOrder ) ;
45+
46+ /// <summary>
47+ /// Gets the active compression algorithms that the plugin should switch through
48+ /// </summary>
49+ public IEnumerable < CompressionSettings > ActiveCompressionAlgorithms => SupportedCompressionAlgorithms . Where ( comp => comp . IsActive ) ;
50+
51+ /// <summary>
52+ /// Gets the enabled compression algorithms.
53+ /// </summary>
54+ public IEnumerable < CompressionSettings > EnabledCompressionAlgorithms => CompressionAlgorithms . Where ( comp => comp . IsEnabled ) ;
4955
5056 /// <summary>
5157 /// Gets the compression algorithms that are supported.
5258 /// </summary>
53- public IEnumerable < CompressionSettings > SupportedCompressionAlgorithms => GetType ( ) . GetProperties ( )
54- . Where ( m => m . PropertyType . IsSubclassOf ( typeof ( CompressionSettings ) ) )
55- . Select ( m => ( CompressionSettings ) m . GetValue ( this ) ! ) . Where ( alg => alg . IsSupported ) ;
59+ public IEnumerable < CompressionSettings > SupportedCompressionAlgorithms => EnabledCompressionAlgorithms . Where ( alg => alg . IsSupported ) ;
5660 #endregion
5761
5862 #region Constructor
@@ -155,7 +159,7 @@ public static Preferences Deserialize(Stream from)
155159 /// <returns>The compression settings for the file.</returns>
156160 public CompressionSettings ? GetCompressionBySuffix ( string ? path )
157161 {
158- return SupportedCompressionAlgorithms . FirstOrDefault ( comp => comp . Extensions . Any ( ext => path ? . EndsWith ( ext , StringComparison . OrdinalIgnoreCase ) ?? false ) ) ;
162+ return EnabledCompressionAlgorithms . FirstOrDefault ( comp => comp . Extensions . Any ( ext => path ? . EndsWith ( ext , StringComparison . OrdinalIgnoreCase ) ?? false ) ) ;
159163 }
160164
161165 /// <summary>
@@ -172,10 +176,13 @@ public static Preferences Deserialize(Stream from)
172176 public GZipSettings GZipSettings { get ; set ; } = new ( ) ;
173177 public ZstdSettings ZstdSettings { get ; set ; } = new ( ) ;
174178 public XZSettings XZSettings { get ; set ; } = new ( ) ;
175-
176179 public BrotliSettings BrotliSettings { get ; set ; } = new ( ) ;
177180 #endregion
178181
182+ public CompressionSettings ? GetCompressionByName ( string name ) => GetType ( ) . GetProperties ( )
183+ . Where ( m => m . PropertyType . IsSubclassOf ( typeof ( CompressionSettings ) ) )
184+ . Select ( m => ( CompressionSettings ) m . GetValue ( this ) ! ) . FirstOrDefault ( s => s . AlgorithmName == name ) ;
185+
179186 /// <summary>
180187 /// Gets the next enabled compression algoritm.
181188 /// </summary>
@@ -184,23 +191,18 @@ public static Preferences Deserialize(Stream from)
184191 /// <returns>The next compression algorithm</returns>
185192 public CompressionSettings ? GetNextCompressor ( string ? compressionAlgorithm , CompressionSettings ? compressionBySuffix )
186193 {
187- string cAlg ;
188194 if ( string . IsNullOrWhiteSpace ( compressionAlgorithm ) )
189- cAlg = compressionBySuffix ? . AlgorithmName ?? EnabledCompressionAlgorithms . FirstOrDefault ( String . Empty ) ;
195+ return compressionBySuffix ?? ActiveCompressionAlgorithms . FirstOrDefault ( ) ;
190196 else
191- cAlg = ( compressionAlgorithm != compressionBySuffix ? . AlgorithmName ?
197+ return ( compressionAlgorithm != compressionBySuffix ? . AlgorithmName ?
192198
193- EnabledCompressionAlgorithms
194- . SkipWhile ( alg => alg != compressionAlgorithm )
199+ ActiveCompressionAlgorithms
200+ . SkipWhile ( alg => alg . AlgorithmName != compressionAlgorithm )
195201 . Skip ( 1 )
196202 :
197- EnabledCompressionAlgorithms
203+ ActiveCompressionAlgorithms
198204 )
199- . FirstOrDefault ( algName => algName != compressionBySuffix ? . AlgorithmName , String . Empty ) ;
200-
201-
202- return SupportedCompressionAlgorithms . FirstOrDefault ( comp => comp . AlgorithmName == cAlg ) ;
203-
205+ . FirstOrDefault ( alg => alg != compressionBySuffix ) ;
204206 }
205207
206208 /// <summary>
@@ -211,7 +213,6 @@ public static Preferences Default
211213 get
212214 {
213215 Preferences preferences = new ( false ) ;
214- preferences . EnabledCompressionAlgorithms = preferences . SupportedCompressionAlgorithms . Select ( c => c . AlgorithmName ) . ToList ( ) ;
215216 preferences . GZipSettings . Extensions . AddRange ( [ ".gz" , ".gzip" ] ) ;
216217 preferences . BZip2Settings . Extensions . AddRange ( [ ".bz2" , ".bzip2" ] ) ;
217218 preferences . ZstdSettings . Extensions . Add ( ".zst" ) ;
0 commit comments