aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core.WindowsInstaller/Bind/CreateWindowsInstallerDataFromIRCommand.cs
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2021-03-14 07:38:48 -0700
committerRob Mensching <rob@firegiant.com>2021-03-14 07:47:48 -0700
commit3ccd5e439da4296d6f2b66ce47075ab20d039676 (patch)
treeb5546552613b869367d09f444492a0bbcfadcfe0 /src/WixToolset.Core.WindowsInstaller/Bind/CreateWindowsInstallerDataFromIRCommand.cs
parent574785ab1421c9b67336c13ade5c2263e665ca07 (diff)
downloadwix-3ccd5e439da4296d6f2b66ce47075ab20d039676.tar.gz
wix-3ccd5e439da4296d6f2b66ce47075ab20d039676.tar.bz2
wix-3ccd5e439da4296d6f2b66ce47075ab20d039676.zip
Minimize public surface area of Core
Fixes wixtoolset/issues#6374
Diffstat (limited to 'src/WixToolset.Core.WindowsInstaller/Bind/CreateWindowsInstallerDataFromIRCommand.cs')
-rw-r--r--src/WixToolset.Core.WindowsInstaller/Bind/CreateWindowsInstallerDataFromIRCommand.cs83
1 files changed, 42 insertions, 41 deletions
diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/CreateWindowsInstallerDataFromIRCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/CreateWindowsInstallerDataFromIRCommand.cs
index 9ec26964..0ce67591 100644
--- a/src/WixToolset.Core.WindowsInstaller/Bind/CreateWindowsInstallerDataFromIRCommand.cs
+++ b/src/WixToolset.Core.WindowsInstaller/Bind/CreateWindowsInstallerDataFromIRCommand.cs
@@ -481,18 +481,18 @@ namespace WixToolset.Core.WindowsInstaller.Bind
481 481
482 private void AddDirectorySymbol(DirectorySymbol symbol) 482 private void AddDirectorySymbol(DirectorySymbol symbol)
483 { 483 {
484 if (String.IsNullOrEmpty(symbol.ShortName) && symbol.Name != null && !symbol.Name.Equals(".") && !symbol.Name.Equals("SourceDir") && !Common.IsValidShortFilename(symbol.Name, false)) 484 if (String.IsNullOrEmpty(symbol.ShortName) && symbol.Name != null && !symbol.Name.Equals(".") && !symbol.Name.Equals("SourceDir") && !this.BackendHelper.IsValidShortFilename(symbol.Name, false))
485 { 485 {
486 symbol.ShortName = CreateShortName(symbol.Name, false, false, "Directory", symbol.ParentDirectoryRef); 486 symbol.ShortName = this.CreateShortName(symbol.Name, false, "Directory", symbol.ParentDirectoryRef);
487 } 487 }
488 488
489 if (String.IsNullOrEmpty(symbol.SourceShortName) && !String.IsNullOrEmpty(symbol.SourceName) && !Common.IsValidShortFilename(symbol.SourceName, false)) 489 if (String.IsNullOrEmpty(symbol.SourceShortName) && !String.IsNullOrEmpty(symbol.SourceName) && !this.BackendHelper.IsValidShortFilename(symbol.SourceName, false))
490 { 490 {
491 symbol.SourceShortName = CreateShortName(symbol.SourceName, false, false, "Directory", symbol.ParentDirectoryRef); 491 symbol.SourceShortName = this.CreateShortName(symbol.SourceName, false, "Directory", symbol.ParentDirectoryRef);
492 } 492 }
493 493
494 var sourceName = GetMsiFilenameValue(symbol.SourceShortName, symbol.SourceName); 494 var sourceName = CreateMsiFilename(symbol.SourceShortName, symbol.SourceName);
495 var targetName = GetMsiFilenameValue(symbol.ShortName, symbol.Name); 495 var targetName = CreateMsiFilename(symbol.ShortName, symbol.Name);
496 496
497 if (String.IsNullOrEmpty(targetName)) 497 if (String.IsNullOrEmpty(targetName))
498 { 498 {
@@ -542,16 +542,16 @@ namespace WixToolset.Core.WindowsInstaller.Bind
542 private void AddDuplicateFileSymbol(DuplicateFileSymbol symbol) 542 private void AddDuplicateFileSymbol(DuplicateFileSymbol symbol)
543 { 543 {
544 var name = symbol.DestinationName; 544 var name = symbol.DestinationName;
545 if (null == symbol.DestinationShortName && null != name && !Common.IsValidShortFilename(name, false)) 545 if (null == symbol.DestinationShortName && null != name && !this.BackendHelper.IsValidShortFilename(name, false))
546 { 546 {
547 symbol.DestinationShortName = CreateShortName(name, true, false, "CopyFile", symbol.ComponentRef, symbol.FileRef); 547 symbol.DestinationShortName = this.CreateShortName(name, true, "CopyFile", symbol.ComponentRef, symbol.FileRef);
548 } 548 }
549 549
550 var row = this.CreateRow(symbol, "DuplicateFile"); 550 var row = this.CreateRow(symbol, "DuplicateFile");
551 row[0] = symbol.Id.Id; 551 row[0] = symbol.Id.Id;
552 row[1] = symbol.ComponentRef; 552 row[1] = symbol.ComponentRef;
553 row[2] = symbol.FileRef; 553 row[2] = symbol.FileRef;
554 row[3] = GetMsiFilenameValue(symbol.DestinationShortName, symbol.DestinationName); 554 row[3] = CreateMsiFilename(symbol.DestinationShortName, symbol.DestinationName);
555 row[4] = symbol.DestinationFolder; 555 row[4] = symbol.DestinationFolder;
556 } 556 }
557 557
@@ -621,9 +621,9 @@ namespace WixToolset.Core.WindowsInstaller.Bind
621 private void AddFileSymbol(FileSymbol symbol) 621 private void AddFileSymbol(FileSymbol symbol)
622 { 622 {
623 var name = symbol.Name; 623 var name = symbol.Name;
624 if (null == symbol.ShortName && null != name && !Common.IsValidShortFilename(name, false)) 624 if (null == symbol.ShortName && null != name && !this.BackendHelper.IsValidShortFilename(name, false))
625 { 625 {
626 symbol.ShortName = CreateShortName(name, true, false, "File", symbol.DirectoryRef); 626 symbol.ShortName = this.CreateShortName(name, true, "File", symbol.DirectoryRef);
627 627
628 if (!this.GeneratedShortNames.TryGetValue(symbol.ShortName, out var potentialConflicts)) 628 if (!this.GeneratedShortNames.TryGetValue(symbol.ShortName, out var potentialConflicts))
629 { 629 {
@@ -637,7 +637,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
637 var row = (FileRow)this.CreateRow(symbol, "File"); 637 var row = (FileRow)this.CreateRow(symbol, "File");
638 row.File = symbol.Id.Id; 638 row.File = symbol.Id.Id;
639 row.Component = symbol.ComponentRef; 639 row.Component = symbol.ComponentRef;
640 row.FileName = GetMsiFilenameValue(symbol.ShortName, name); 640 row.FileName = CreateMsiFilename(symbol.ShortName, name);
641 row.FileSize = symbol.FileSize; 641 row.FileSize = symbol.FileSize;
642 row.Version = symbol.Version; 642 row.Version = symbol.Version;
643 row.Language = symbol.Language; 643 row.Language = symbol.Language;
@@ -674,14 +674,14 @@ namespace WixToolset.Core.WindowsInstaller.Bind
674 var tableName = (IniFileActionType.AddLine == symbol.Action || IniFileActionType.AddTag == symbol.Action || IniFileActionType.CreateLine == symbol.Action) ? "IniFile" : "RemoveIniFile"; 674 var tableName = (IniFileActionType.AddLine == symbol.Action || IniFileActionType.AddTag == symbol.Action || IniFileActionType.CreateLine == symbol.Action) ? "IniFile" : "RemoveIniFile";
675 675
676 var name = symbol.FileName; 676 var name = symbol.FileName;
677 if (null == symbol.ShortFileName && null != name && !Common.IsValidShortFilename(name, false)) 677 if (null == symbol.ShortFileName && null != name && !this.BackendHelper.IsValidShortFilename(name, false))
678 { 678 {
679 symbol.ShortFileName = CreateShortName(name, true, false, "IniFile", symbol.ComponentRef); 679 symbol.ShortFileName = this.CreateShortName(name, true, "IniFile", symbol.ComponentRef);
680 } 680 }
681 681
682 var row = this.CreateRow(symbol, tableName); 682 var row = this.CreateRow(symbol, tableName);
683 row[0] = symbol.Id.Id; 683 row[0] = symbol.Id.Id;
684 row[1] = GetMsiFilenameValue(symbol.ShortFileName, name); 684 row[1] = CreateMsiFilename(symbol.ShortFileName, name);
685 row[2] = symbol.DirProperty; 685 row[2] = symbol.DirProperty;
686 row[3] = symbol.Section; 686 row[3] = symbol.Section;
687 row[4] = symbol.Key; 687 row[4] = symbol.Key;
@@ -693,14 +693,14 @@ namespace WixToolset.Core.WindowsInstaller.Bind
693 private void AddIniLocatorSymbol(IniLocatorSymbol symbol) 693 private void AddIniLocatorSymbol(IniLocatorSymbol symbol)
694 { 694 {
695 var name = symbol.FileName; 695 var name = symbol.FileName;
696 if (null == symbol.ShortFileName && null != name && !Common.IsValidShortFilename(name, false)) 696 if (null == symbol.ShortFileName && null != name && !this.BackendHelper.IsValidShortFilename(name, false))
697 { 697 {
698 symbol.ShortFileName = CreateShortName(name, true, false, "IniFileSearch"); 698 symbol.ShortFileName = this.CreateShortName(name, true, "IniFileSearch");
699 } 699 }
700 700
701 var row = this.CreateRow(symbol, "IniLocator"); 701 var row = this.CreateRow(symbol, "IniLocator");
702 row[0] = symbol.Id.Id; 702 row[0] = symbol.Id.Id;
703 row[1] = GetMsiFilenameValue(symbol.ShortFileName, name); 703 row[1] = CreateMsiFilename(symbol.ShortFileName, name);
704 row[2] = symbol.Section; 704 row[2] = symbol.Section;
705 row[3] = symbol.Key; 705 row[3] = symbol.Key;
706 row[4] = symbol.Field; 706 row[4] = symbol.Field;
@@ -786,16 +786,16 @@ namespace WixToolset.Core.WindowsInstaller.Bind
786 private void AddMoveFileSymbol(MoveFileSymbol symbol) 786 private void AddMoveFileSymbol(MoveFileSymbol symbol)
787 { 787 {
788 var name = symbol.DestinationName; 788 var name = symbol.DestinationName;
789 if (null == symbol.DestinationShortName && null != name && !Common.IsValidShortFilename(name, false)) 789 if (null == symbol.DestinationShortName && null != name && !this.BackendHelper.IsValidShortFilename(name, false))
790 { 790 {
791 symbol.DestinationShortName = CreateShortName(name, true, false, "MoveFile", symbol.ComponentRef); 791 symbol.DestinationShortName = this.CreateShortName(name, true, "MoveFile", symbol.ComponentRef);
792 } 792 }
793 793
794 var row = this.CreateRow(symbol, "MoveFile"); 794 var row = this.CreateRow(symbol, "MoveFile");
795 row[0] = symbol.Id.Id; 795 row[0] = symbol.Id.Id;
796 row[1] = symbol.ComponentRef; 796 row[1] = symbol.ComponentRef;
797 row[2] = symbol.SourceName; 797 row[2] = symbol.SourceName;
798 row[3] = GetMsiFilenameValue(symbol.DestinationShortName, symbol.DestinationName); 798 row[3] = CreateMsiFilename(symbol.DestinationShortName, symbol.DestinationName);
799 row[4] = symbol.SourceFolder; 799 row[4] = symbol.SourceFolder;
800 row[5] = symbol.DestFolder; 800 row[5] = symbol.DestFolder;
801 row[6] = symbol.Delete ? WindowsInstallerConstants.MsidbMoveFileOptionsMove : 0; 801 row[6] = symbol.Delete ? WindowsInstallerConstants.MsidbMoveFileOptionsMove : 0;
@@ -816,9 +816,9 @@ namespace WixToolset.Core.WindowsInstaller.Bind
816 private void AddRemoveFileSymbol(RemoveFileSymbol symbol) 816 private void AddRemoveFileSymbol(RemoveFileSymbol symbol)
817 { 817 {
818 var name = symbol.FileName; 818 var name = symbol.FileName;
819 if (null == symbol.ShortFileName && null != name && !Common.IsValidShortFilename(name, false)) 819 if (null == symbol.ShortFileName && null != name && !this.BackendHelper.IsValidShortFilename(name, false))
820 { 820 {
821 symbol.ShortFileName = CreateShortName(name, true, false, "RemoveFile", symbol.ComponentRef); 821 symbol.ShortFileName = this.CreateShortName(name, true, "RemoveFile", symbol.ComponentRef);
822 } 822 }
823 823
824 var installMode = symbol.OnInstall == true ? WindowsInstallerConstants.MsidbRemoveFileInstallModeOnInstall : 0; 824 var installMode = symbol.OnInstall == true ? WindowsInstallerConstants.MsidbRemoveFileInstallModeOnInstall : 0;
@@ -827,7 +827,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
827 var row = this.CreateRow(symbol, "RemoveFile"); 827 var row = this.CreateRow(symbol, "RemoveFile");
828 row[0] = symbol.Id.Id; 828 row[0] = symbol.Id.Id;
829 row[1] = symbol.ComponentRef; 829 row[1] = symbol.ComponentRef;
830 row[2] = GetMsiFilenameValue(symbol.ShortFileName, symbol.FileName); 830 row[2] = CreateMsiFilename(symbol.ShortFileName, symbol.FileName);
831 row[3] = symbol.DirPropertyRef; 831 row[3] = symbol.DirPropertyRef;
832 row[4] = installMode; 832 row[4] = installMode;
833 } 833 }
@@ -966,15 +966,15 @@ namespace WixToolset.Core.WindowsInstaller.Bind
966 private void AddShortcutSymbol(ShortcutSymbol symbol) 966 private void AddShortcutSymbol(ShortcutSymbol symbol)
967 { 967 {
968 var name = symbol.Name; 968 var name = symbol.Name;
969 if (null == symbol.ShortName && null != name && !Common.IsValidShortFilename(name, false)) 969 if (null == symbol.ShortName && null != name && !this.BackendHelper.IsValidShortFilename(name, false))
970 { 970 {
971 symbol.ShortName = CreateShortName(name, true, false, "Shortcut", symbol.ComponentRef, symbol.DirectoryRef); 971 symbol.ShortName = this.CreateShortName(name, true, "Shortcut", symbol.ComponentRef, symbol.DirectoryRef);
972 } 972 }
973 973
974 var row = this.CreateRow(symbol, "Shortcut"); 974 var row = this.CreateRow(symbol, "Shortcut");
975 row[0] = symbol.Id.Id; 975 row[0] = symbol.Id.Id;
976 row[1] = symbol.DirectoryRef; 976 row[1] = symbol.DirectoryRef;
977 row[2] = GetMsiFilenameValue(symbol.ShortName, name); 977 row[2] = CreateMsiFilename(symbol.ShortName, name);
978 row[3] = symbol.ComponentRef; 978 row[3] = symbol.ComponentRef;
979 row[4] = symbol.Target; 979 row[4] = symbol.Target;
980 row[5] = symbol.Arguments; 980 row[5] = symbol.Arguments;
@@ -1177,7 +1177,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
1177 } 1177 }
1178 else if (rowField.Column.Category == ColumnCategory.Identifier) 1178 else if (rowField.Column.Category == ColumnCategory.Identifier)
1179 { 1179 {
1180 if (Common.IsIdentifier(data) || Common.IsValidBinderVariable(data) || ColumnCategory.Formatted == rowField.Column.Category) 1180 if (this.BackendHelper.IsValidIdentifier(data) || this.BackendHelper.IsValidBinderVariable(data) || ColumnCategory.Formatted == rowField.Column.Category)
1181 { 1181 {
1182 rowField.Data = data; 1182 rowField.Data = data;
1183 } 1183 }
@@ -1488,19 +1488,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind
1488 private Row CreateRow(IntermediateSymbol symbol, TableDefinition tableDefinition) => 1488 private Row CreateRow(IntermediateSymbol symbol, TableDefinition tableDefinition) =>
1489 this.BackendHelper.CreateRow(this.Section, symbol, this.Data, tableDefinition); 1489 this.BackendHelper.CreateRow(this.Section, symbol, this.Data, tableDefinition);
1490 1490
1491 private static string GetMsiFilenameValue(string shortName, string longName)
1492 {
1493 if (String.IsNullOrEmpty(shortName) || String.Equals(shortName, longName, StringComparison.OrdinalIgnoreCase))
1494 {
1495 return longName;
1496 }
1497 else
1498 {
1499 return shortName + "|" + longName;
1500 }
1501 }
1502 1491
1503 private static string CreateShortName(string longName, bool keepExtension, bool allowWildcards, params string[] args) 1492 private string CreateShortName(string longName, bool keepExtension, params string[] args)
1504 { 1493 {
1505 longName = longName.ToLowerInvariant(); 1494 longName = longName.ToLowerInvariant();
1506 1495
@@ -1537,7 +1526,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
1537 shortName.Append(extension); 1526 shortName.Append(extension);
1538 1527
1539 // check the generated short name to ensure its still legal (the extension may not be legal) 1528 // check the generated short name to ensure its still legal (the extension may not be legal)
1540 if (!Common.IsValidShortFilename(shortName.ToString(), allowWildcards)) 1529 if (!this.BackendHelper.IsValidShortFilename(shortName.ToString(), false))
1541 { 1530 {
1542 // remove the extension (by truncating the generated file name back to the generated characters) 1531 // remove the extension (by truncating the generated file name back to the generated characters)
1543 shortName.Length -= extension.Length; 1532 shortName.Length -= extension.Length;
@@ -1546,5 +1535,17 @@ namespace WixToolset.Core.WindowsInstaller.Bind
1546 1535
1547 return shortName.ToString().ToLowerInvariant(); 1536 return shortName.ToString().ToLowerInvariant();
1548 } 1537 }
1538
1539 private static string CreateMsiFilename(string shortName, string longName)
1540 {
1541 if (String.IsNullOrEmpty(shortName) || String.Equals(shortName, longName, StringComparison.OrdinalIgnoreCase))
1542 {
1543 return longName;
1544 }
1545 else
1546 {
1547 return shortName + "|" + longName;
1548 }
1549 }
1549 } 1550 }
1550} 1551}