@@ -564,79 +564,32 @@ public List<CoveragePath> GetPathsOfInterest()
564564 } ) ;
565565 }
566566
567- if ( ! string . IsNullOrWhiteSpace ( ParityFile1 ) )
568- {
569- pathsOfInterest . Add ( new CoveragePath
570- {
571- FullPath = Path . GetFullPath ( ParityFile1 ) ,
572- PathType = PathTypeEnum . Parity ,
573- Name = @"Parity1"
574- } ) ;
575- }
567+ AddParityCoverage ( pathsOfInterest , ParityFile1 , @"Parity1" ) ;
576568
577- if ( ! string . IsNullOrWhiteSpace ( ParityFile2 ) )
578- {
579- pathsOfInterest . Add ( new CoveragePath
580- {
581- FullPath = Path . GetFullPath ( ParityFile2 ) ,
582- PathType = PathTypeEnum . Parity ,
583- Name = @"Parity2"
584- } ) ;
585- }
569+ AddParityCoverage ( pathsOfInterest , ParityFile2 , @"Parity2" ) ;
586570
587- if ( ! string . IsNullOrWhiteSpace ( ZParityFile ) )
588- {
589- pathsOfInterest . Add ( new CoveragePath
590- {
591- FullPath = Path . GetFullPath ( ZParityFile ) ,
592- PathType = PathTypeEnum . Parity ,
593- Name = @"ZParity"
594- } ) ;
595- }
571+ AddParityCoverage ( pathsOfInterest , ZParityFile , @"ZParity" ) ;
596572
597- if ( ! string . IsNullOrWhiteSpace ( ParityFile3 ) )
598- {
599- pathsOfInterest . Add ( new CoveragePath
600- {
601- FullPath = Path . GetFullPath ( ParityFile3 ) ,
602- PathType = PathTypeEnum . Parity ,
603- Name = @"Parity3"
604- } ) ;
605- }
573+ AddParityCoverage ( pathsOfInterest , ParityFile3 , @"Parity3" ) ;
606574
607- if ( ! string . IsNullOrWhiteSpace ( ParityFile4 ) )
608- {
609- pathsOfInterest . Add ( new CoveragePath
610- {
611- FullPath = Path . GetFullPath ( ParityFile4 ) ,
612- PathType = PathTypeEnum . Parity ,
613- Name = @"Parity4"
614- } ) ;
615- }
616-
617- if ( ! string . IsNullOrWhiteSpace ( ParityFile5 ) )
618- {
619- pathsOfInterest . Add ( new CoveragePath
620- {
621- FullPath = Path . GetFullPath ( ParityFile5 ) ,
622- PathType = PathTypeEnum . Parity ,
623- Name = @"Parity5"
624- } ) ;
625- }
626-
627- if ( ! string . IsNullOrWhiteSpace ( ParityFile6 ) )
628- {
629- pathsOfInterest . Add ( new CoveragePath
630- {
631- FullPath = Path . GetFullPath ( ParityFile6 ) ,
632- PathType = PathTypeEnum . Parity ,
633- Name = @"Parity6"
634- } ) ;
635- }
575+ AddParityCoverage ( pathsOfInterest , ParityFile4 , @"Parity4" ) ;
576+
577+ AddParityCoverage ( pathsOfInterest , ParityFile5 , @"Parity5" ) ;
578+
579+ AddParityCoverage ( pathsOfInterest , ParityFile6 , @"Parity6" ) ;
636580
637581 return pathsOfInterest ;
638582 }
639583
584+ private static void AddParityCoverage ( List < CoveragePath > pathsOfInterest , string parityPaths , string parityName )
585+ {
586+ if ( ! string . IsNullOrWhiteSpace ( parityPaths ) )
587+ {
588+ string [ ] parities = parityPaths . Trim ( ) . Split ( "," . ToCharArray ( ) ) ;
589+ pathsOfInterest . AddRange ( parities . Select ( parity => new CoveragePath { FullPath = Path . GetFullPath ( parity ) , PathType = PathTypeEnum . Parity , Name = parityName } ) ) ;
590+ }
591+ }
592+
640593 /// <summary>
641594 /// Writes the config file
642595 /// </summary>
@@ -651,40 +604,17 @@ public string Write(string trgtFileName)
651604
652605 // parity
653606 fileContents . Append ( Section2 ) ;
654- fileContents . AppendLine ( $ "parity { ( Directory . Exists ( ParityFile1 ) ? Path . Combine ( ParityFile1 , @"snapraid.1.parity" ) : ParityFile1 ) } " ) ;
607+ AddParityToConfig ( fileContents , ParityFile1 , char . MinValue ) ;
655608
656- // X -parity
609+ // # -parity
657610 fileContents . Append ( Section3 ) ;
658611
659- if ( ! string . IsNullOrEmpty ( ParityFile2 ) )
660- {
661- fileContents . AppendLine ( $ "2-parity { ( Directory . Exists ( ParityFile2 ) ? Path . Combine ( ParityFile2 , @"snapraid.2.parity" ) : ParityFile2 ) } ") ;
662- }
663-
664- if ( ! string . IsNullOrEmpty ( ZParityFile ) )
665- {
666- fileContents . AppendLine ( $ "z-parity { ( Directory . Exists ( ZParityFile ) ? Path . Combine ( ZParityFile , @"snapraid.Z.parity" ) : ZParityFile ) } ") ;
667- }
668-
669- if ( ! string . IsNullOrEmpty ( ParityFile3 ) )
670- {
671- fileContents . AppendLine ( $ "3-parity { ( Directory . Exists ( ParityFile3 ) ? Path . Combine ( ParityFile3 , @"snapraid.3.parity" ) : ParityFile3 ) } ") ;
672- }
673-
674- if ( ! string . IsNullOrEmpty ( ParityFile4 ) )
675- {
676- fileContents . AppendLine ( $ "4-parity { ( Directory . Exists ( ParityFile4 ) ? Path . Combine ( ParityFile4 , @"snapraid.4.parity" ) : ParityFile4 ) } ") ;
677- }
678-
679- if ( ! string . IsNullOrEmpty ( ParityFile5 ) )
680- {
681- fileContents . AppendLine ( $ "5-parity { ( Directory . Exists ( ParityFile5 ) ? Path . Combine ( ParityFile5 , @"snapraid.5.parity" ) : ParityFile5 ) } ") ;
682- }
683-
684- if ( ! string . IsNullOrEmpty ( ParityFile6 ) )
685- {
686- fileContents . AppendLine ( $ "6-parity { ( Directory . Exists ( ParityFile6 ) ? Path . Combine ( ParityFile6 , @"snapraid.6.parity" ) : ParityFile6 ) } ") ;
687- }
612+ AddParityToConfig ( fileContents , ParityFile2 , '2' ) ;
613+ AddParityToConfig ( fileContents , ZParityFile , 'z' ) ;
614+ AddParityToConfig ( fileContents , ParityFile3 , '3' ) ;
615+ AddParityToConfig ( fileContents , ParityFile4 , '4' ) ;
616+ AddParityToConfig ( fileContents , ParityFile5 , '5' ) ;
617+ AddParityToConfig ( fileContents , ParityFile6 , '6' ) ;
688618
689619 // content
690620 fileContents . Append ( Section4 ) ;
@@ -745,6 +675,42 @@ public string Write(string trgtFileName)
745675 return string . Empty ;
746676 }
747677
678+ private static void AddParityToConfig ( StringBuilder fileContents , string parityPaths , char offset )
679+ {
680+ if ( ! string . IsNullOrEmpty ( parityPaths ) )
681+ {
682+ if ( offset != char . MinValue )
683+ {
684+ fileContents . Append ( offset ) . Append ( '-' ) ;
685+ }
686+
687+ fileContents . Append ( "parity " ) ;
688+ string [ ] parities = parityPaths . Trim ( ) . Split ( "," . ToCharArray ( ) ) ;
689+ bool doneFirst = false ;
690+ foreach ( string parity in parities )
691+ {
692+ if ( doneFirst )
693+ {
694+ fileContents . Append ( ',' ) ;
695+ }
696+
697+ fileContents . Append ( parity ) ;
698+ doneFirst = true ;
699+ if ( Directory . Exists ( parity ) )
700+ {
701+ fileContents . Append ( @"\snapraid" ) ;
702+ if ( offset != char . MinValue )
703+ {
704+ fileContents . Append ( '-' ) . Append ( offset ) ;
705+ }
706+ fileContents . Append ( @".parity" ) ;
707+ }
708+ }
709+
710+ fileContents . AppendLine ( ) ;
711+ }
712+ }
713+
748714 private static StringBuilder Section1
749715 {
750716 get
0 commit comments