@@ -273,9 +273,28 @@ private void WizardFinish(object sender, RoutedEventArgs e)
273273 inputSuffixPath = Regex . Replace ( inputSuffixPath , @"[/\\]" + Regex . Escape ( comp ) + @"[/\\]" , "\\ " ) ;
274274 }
275275 string [ ] inputSuffixComponents = inputSuffixPath . Split ( new char [ ] { '/' , '\\ ' } , StringSplitOptions . RemoveEmptyEntries ) ;
276- if ( inputSuffixComponents . Length > 3 )
276+ if ( inputSuffixComponents . Length > 3 && Initializer . Config . reducePath )
277277 {
278- string [ ] newInputSuffixComponents = new string [ ] { inputSuffixComponents [ 0 ] , inputSuffixComponents [ inputSuffixComponents . Length - 2 ] , inputSuffixComponents [ inputSuffixComponents . Length - 1 ] } ;
278+ // inputSuffixComponents[0] is drive number, inputSuffixComponents[-1] is filename, inputSuffixComponents[1:-2] is the effective path to be reduced.
279+ string effectivePathPrefix = string . Join ( "\\ " , inputSuffixComponents , 1 , inputSuffixComponents . Length - 3 ) ;
280+ string effectivePathLast = inputSuffixComponents [ inputSuffixComponents . Length - 2 ] ;
281+ Regex rVolNumber = new Regex ( @".*Vol[.\- ]?(?<vol>\d+).*" , RegexOptions . Compiled | RegexOptions . IgnoreCase ) ;
282+ Match mLast = rVolNumber . Match ( effectivePathLast ) ;
283+
284+ string newEffectivePath ;
285+ if ( mLast . Success )
286+ {
287+ // If the last level path contains a volume number, keep the last level path unchanged.
288+ newEffectivePath = effectivePathLast ;
289+ }
290+ else
291+ {
292+ // By default, the last level path is preserved and the crc of the prefix path is added to prevent naming conflicts.
293+ byte [ ] buffer = System . Text . Encoding . UTF8 . GetBytes ( effectivePathPrefix ) ;
294+ var crc = CRC32 . Compute ( buffer ) ;
295+ newEffectivePath = crc . ToString ( "X8" ) + "-" + effectivePathLast ;
296+ }
297+ string [ ] newInputSuffixComponents = new string [ ] { inputSuffixComponents [ 0 ] , newEffectivePath , inputSuffixComponents [ inputSuffixComponents . Length - 1 ] } ;
279298 inputSuffixPath = string . Join ( "\\ " , newInputSuffixComponents ) ;
280299 }
281300 Logger . Debug ( "inputSuffixPathComponents: " + string . Join ( ", " , inputSuffixComponents ) ) ;
0 commit comments