@@ -62,7 +62,8 @@ public WindowsInstallerData Execute()
6262
6363 private void AddSectionToData ( )
6464 {
65- var cellsByTableAndRowId = new Dictionary < string , List < WixCustomTableCellSymbol > > ( ) ;
65+ var directoryRowsById = new Dictionary < string , Row > ( StringComparer . Ordinal ) ;
66+ var cellsByTableAndRowId = new Dictionary < string , List < WixCustomTableCellSymbol > > ( StringComparer . Ordinal ) ;
6667
6768 foreach ( var symbol in this . Section . Symbols )
6869 {
@@ -107,7 +108,7 @@ private void AddSectionToData()
107108 break ;
108109
109110 case SymbolDefinitionType . Directory :
110- this . AddDirectorySymbol ( ( DirectorySymbol ) symbol ) ;
111+ this . AddDirectorySymbol ( ( DirectorySymbol ) symbol , directoryRowsById ) ;
111112 break ;
112113
113114 case SymbolDefinitionType . DuplicateFile :
@@ -497,9 +498,9 @@ private void AddDialogSymbol(DialogSymbol symbol)
497498 this . Data . EnsureTable ( this . TableDefinitions [ "ListBox" ] ) ;
498499 }
499500
500- private void AddDirectorySymbol ( DirectorySymbol symbol )
501+ private void AddDirectorySymbol ( DirectorySymbol symbol , Dictionary < string , Row > directoryRowsById )
501502 {
502- ( var name , var parentDir ) = this . AddDirectorySubdirectories ( symbol ) ;
503+ ( var name , var parentDir ) = this . AddDirectorySubdirectories ( symbol , directoryRowsById ) ;
503504
504505 var shortName = symbol . ShortName ;
505506 var sourceShortname = symbol . SourceShortName ;
@@ -524,10 +525,7 @@ private void AddDirectorySymbol(DirectorySymbol symbol)
524525
525526 var defaultDir = String . IsNullOrEmpty ( sourceName ) || sourceName == targetName ? targetName : targetName + ":" + sourceName ;
526527
527- var row = this . CreateRow ( symbol , "Directory" ) ;
528- row [ 0 ] = symbol . Id . Id ;
529- row [ 1 ] = parentDir ;
530- row [ 2 ] = defaultDir ;
528+ this . CreateOrAddDirectoryRow ( directoryRowsById , symbol , symbol . Id . Id , parentDir , defaultDir ) ;
531529
532530 if ( OutputType . Module == this . Data . Type )
533531 {
@@ -1146,7 +1144,7 @@ private void AddWixActionSymbol(WixActionSymbol symbol)
11461144 }
11471145 else
11481146 {
1149- var after = ( null == symbol . Before ) ;
1147+ var after = null == symbol . Before ;
11501148 row [ 2 ] = after ? symbol . After : symbol . Before ;
11511149 row [ 3 ] = after ? 1 : 0 ;
11521150 }
@@ -1271,7 +1269,7 @@ private void AddWixModuleSymbol(WixModuleSymbol symbol)
12711269 }
12721270 }
12731271
1274- private void AddWixPackageSymbol ( WixPackageSymbol symbol )
1272+ private void AddWixPackageSymbol ( WixPackageSymbol _ )
12751273 {
12761274 // TODO: Remove the following from the compiler and do it here instead.
12771275 //this.AddProperty(sourceLineNumbers, new Identifier(AccessModifier.Global, "Manufacturer"), manufacturer, false, false, false, true);
@@ -1319,11 +1317,10 @@ private void EnsureModuleIgnoredTable(IntermediateSymbol symbol, string ignoredT
13191317 }
13201318 }
13211319
1322- private ( string , string ) AddDirectorySubdirectories ( DirectorySymbol symbol )
1320+ private ( string , string ) AddDirectorySubdirectories ( DirectorySymbol symbol , Dictionary < string , Row > directoryRowsById )
13231321 {
13241322 var directory = symbol . Name . Trim ( PathSeparatorChars ) ;
13251323 var parentDir = symbol . ParentDirectoryRef ?? ( symbol . Id . Id == "TARGETDIR" ? null : "TARGETDIR" ) ;
1326- var directoryRows = this . Data . TryGetTable ( "Directory" , out var table ) ? table . Rows . ToDictionary ( row => row . FieldAsString ( 0 ) ) : new Dictionary < string , Row > ( ) ;
13271324
13281325 var start = 0 ;
13291326 var end = directory . IndexOfAny ( PathSeparatorChars ) ;
@@ -1337,18 +1334,11 @@ private void EnsureModuleIgnoredTable(IntermediateSymbol symbol, string ignoredT
13371334 {
13381335 path = Path . Combine ( path , subdirectoryName ) ;
13391336
1340- var id = this . BackendHelper . GenerateIdentifier ( "d" , symbol . ParentDirectoryRef , path ) ;
1337+ var id = this . BackendHelper . GenerateIdentifier ( "d" , symbol . ParentDirectoryRef , path , /*shortName:*/ null , /*sourceName:*/ null , /*shortSourceName:*/ null ) ;
13411338 var shortnameSubdirectory = this . BackendHelper . IsValidShortFilename ( subdirectoryName , false ) ? null : this . CreateShortName ( subdirectoryName , false , "Directory" , symbol . ParentDirectoryRef ) ;
1339+ var defaultDir = CreateMsiFilename ( shortnameSubdirectory , subdirectoryName ) ;
13421340
1343- if ( ! directoryRows . ContainsKey ( id ) )
1344- {
1345- var subdirectoryRow = this . CreateRow ( symbol , "Directory" ) ;
1346- subdirectoryRow [ 0 ] = id ;
1347- subdirectoryRow [ 1 ] = parentDir ;
1348- subdirectoryRow [ 2 ] = CreateMsiFilename ( shortnameSubdirectory , subdirectoryName ) ;
1349-
1350- directoryRows . Add ( id , subdirectoryRow ) ;
1351- }
1341+ this . CreateOrAddDirectoryRow ( directoryRowsById , symbol , id , parentDir , defaultDir ) ;
13521342
13531343 parentDir = id ;
13541344 }
@@ -1362,6 +1352,25 @@ private void EnsureModuleIgnoredTable(IntermediateSymbol symbol, string ignoredT
13621352 return ( name , parentDir ) ;
13631353 }
13641354
1355+ private Row CreateOrAddDirectoryRow ( Dictionary < string , Row > directoryRowsById , DirectorySymbol symbol , string id , string parentDir , string defaultDir )
1356+ {
1357+ if ( ! directoryRowsById . TryGetValue ( id , out var directoryRow ) )
1358+ {
1359+ directoryRow = this . CreateRow ( symbol , "Directory" ) ;
1360+ directoryRow [ 0 ] = id ;
1361+ directoryRow [ 1 ] = parentDir ;
1362+ directoryRow [ 2 ] = defaultDir ;
1363+
1364+ directoryRowsById . Add ( id , directoryRow ) ;
1365+ }
1366+ else if ( directoryRow . FieldAsString ( 1 ) != parentDir || directoryRow . FieldAsString ( 2 ) != defaultDir )
1367+ {
1368+ throw new WixException ( WindowsInstallerBackendErrors . UnexpectedAnonymousDirectoryCollision ( symbol . SourceLineNumbers , symbol . Id . Id , parentDir , defaultDir , directoryRow . SourceLineNumbers , directoryRow . FieldAsString ( 1 ) , directoryRow . FieldAsString ( 2 ) ) ) ;
1369+ }
1370+
1371+ return directoryRow ;
1372+ }
1373+
13651374 private void EnsureRequiredTables ( )
13661375 {
13671376 // check for missing table and add them or display an error as appropriate
@@ -1412,7 +1421,7 @@ private void ReportIllegalTables()
14121421 "Upgrade" == table . Name ||
14131422 "WixMerge" == table . Name )
14141423 {
1415- foreach ( Row row in table . Rows )
1424+ foreach ( var row in table . Rows )
14161425 {
14171426 this . Messaging . Write ( ErrorMessages . UnexpectedTableInMergeModule ( row . SourceLineNumbers , table . Name ) ) ;
14181427 }
@@ -1609,8 +1618,10 @@ private string CreateShortName(string longName, bool keepExtension, params strin
16091618 longName = longName . ToLowerInvariant ( ) ;
16101619
16111620 // collect all the data
1612- var strings = new List < string > ( 1 + args . Length ) ;
1613- strings . Add ( longName ) ;
1621+ var strings = new List < string > ( 1 + args . Length )
1622+ {
1623+ longName
1624+ } ;
16141625 strings . AddRange ( args ) ;
16151626
16161627 // prepare for hashing
@@ -1625,8 +1636,10 @@ private string CreateShortName(string longName, bool keepExtension, params strin
16251636 }
16261637
16271638 // generate the short file/directory name without an extension
1628- var shortName = new StringBuilder ( Convert . ToBase64String ( hash ) ) ;
1629- shortName . Length = 8 ;
1639+ var shortName = new StringBuilder ( Convert . ToBase64String ( hash ) )
1640+ {
1641+ Length = 8
1642+ } ;
16301643 shortName . Replace ( '+' , '-' ) . Replace ( '/' , '_' ) ;
16311644
16321645 if ( keepExtension )
0 commit comments