aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2020-05-23 01:57:15 -0700
committerRob Mensching <rob@firegiant.com>2020-05-23 02:00:44 -0700
commitc4497aa78b2d85b2613af64311bf282756aff43a (patch)
tree152fd4c2402b195b9370de94d24022b137aa2415 /src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs
parentf08e7529967fa9870faeee6dfa00f326c65cef1e (diff)
downloadwix-c4497aa78b2d85b2613af64311bf282756aff43a.tar.gz
wix-c4497aa78b2d85b2613af64311bf282756aff43a.tar.bz2
wix-c4497aa78b2d85b2613af64311bf282756aff43a.zip
Support instance transforms
Diffstat (limited to 'src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs')
-rw-r--r--src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs243
1 files changed, 2 insertions, 241 deletions
diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs
index e09c12da..8e901d30 100644
--- a/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs
+++ b/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs
@@ -373,9 +373,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind
373 } 373 }
374 else // we can create instance transforms since Component Guids are set. 374 else // we can create instance transforms since Component Guids are set.
375 { 375 {
376#if TODO_FIX_INSTANCE_TRANSFORM 376 var command = new CreateInstanceTransformsCommand(section, output, tableDefinitions, this.BackendHelper);
377 this.CreateInstanceTransforms(this.Output); 377 command.Execute();
378#endif
379 } 378 }
380 379
381#if TODO_FINISH_UPDATE 380#if TODO_FINISH_UPDATE
@@ -640,244 +639,6 @@ namespace WixToolset.Core.WindowsInstaller.Bind
640 } 639 }
641#endif 640#endif
642 641
643
644#if TODO_FIX_INSTANCE_TRANSFORM
645 /// <summary>
646 /// Creates instance transform substorages in the output.
647 /// </summary>
648 /// <param name="output">Output containing instance transform definitions.</param>
649 private void CreateInstanceTransforms(Output output)
650 {
651 // Create and add substorages for instance transforms.
652 Table wixInstanceTransformsTable = output.Tables["WixInstanceTransforms"];
653 if (null != wixInstanceTransformsTable && 0 <= wixInstanceTransformsTable.Rows.Count)
654 {
655 string targetProductCode = null;
656 string targetUpgradeCode = null;
657 string targetProductVersion = null;
658
659 Table targetSummaryInformationTable = output.Tables["_SummaryInformation"];
660 Table targetPropertyTable = output.Tables["Property"];
661
662 // Get the data from target database
663 foreach (Row propertyRow in targetPropertyTable.Rows)
664 {
665 if ("ProductCode" == (string)propertyRow[0])
666 {
667 targetProductCode = (string)propertyRow[1];
668 }
669 else if ("ProductVersion" == (string)propertyRow[0])
670 {
671 targetProductVersion = (string)propertyRow[1];
672 }
673 else if ("UpgradeCode" == (string)propertyRow[0])
674 {
675 targetUpgradeCode = (string)propertyRow[1];
676 }
677 }
678
679 // Index the Instance Component Rows.
680 Dictionary<string, ComponentRow> instanceComponentGuids = new Dictionary<string, ComponentRow>();
681 Table targetInstanceComponentTable = output.Tables["WixInstanceComponent"];
682 if (null != targetInstanceComponentTable && 0 < targetInstanceComponentTable.Rows.Count)
683 {
684 foreach (Row row in targetInstanceComponentTable.Rows)
685 {
686 // Build up all the instances, we'll get the Components rows from the real Component table.
687 instanceComponentGuids.Add((string)row[0], null);
688 }
689
690 Table targetComponentTable = output.Tables["Component"];
691 foreach (ComponentRow componentRow in targetComponentTable.Rows)
692 {
693 string component = (string)componentRow[0];
694 if (instanceComponentGuids.ContainsKey(component))
695 {
696 instanceComponentGuids[component] = componentRow;
697 }
698 }
699 }
700
701 // Generate the instance transforms
702 foreach (Row instanceRow in wixInstanceTransformsTable.Rows)
703 {
704 string instanceId = (string)instanceRow[0];
705
706 Output instanceTransform = new Output(instanceRow.SourceLineNumbers);
707 instanceTransform.Type = OutputType.Transform;
708 instanceTransform.Codepage = output.Codepage;
709
710 Table instanceSummaryInformationTable = instanceTransform.EnsureTable(this.TableDefinitions["_SummaryInformation"]);
711 string targetPlatformAndLanguage = null;
712
713 foreach (Row summaryInformationRow in targetSummaryInformationTable.Rows)
714 {
715 if (7 == (int)summaryInformationRow[0]) // PID_TEMPLATE
716 {
717 targetPlatformAndLanguage = (string)summaryInformationRow[1];
718 }
719
720 // Copy the row's data to the transform.
721 Row copyOfSummaryRow = instanceSummaryInformationTable.CreateRow(null);
722 copyOfSummaryRow[0] = summaryInformationRow[0];
723 copyOfSummaryRow[1] = summaryInformationRow[1];
724 }
725
726 // Modify the appropriate properties.
727 Table propertyTable = instanceTransform.EnsureTable(this.TableDefinitions["Property"]);
728
729 // Change the ProductCode property
730 string productCode = (string)instanceRow[2];
731 if ("*" == productCode)
732 {
733 productCode = Common.GenerateGuid();
734 }
735
736 Row productCodeRow = propertyTable.CreateRow(instanceRow.SourceLineNumbers);
737 productCodeRow.Operation = RowOperation.Modify;
738 productCodeRow.Fields[1].Modified = true;
739 productCodeRow[0] = "ProductCode";
740 productCodeRow[1] = productCode;
741
742 // Change the instance property
743 Row instanceIdRow = propertyTable.CreateRow(instanceRow.SourceLineNumbers);
744 instanceIdRow.Operation = RowOperation.Modify;
745 instanceIdRow.Fields[1].Modified = true;
746 instanceIdRow[0] = (string)instanceRow[1];
747 instanceIdRow[1] = instanceId;
748
749 if (null != instanceRow[3])
750 {
751 // Change the ProductName property
752 Row productNameRow = propertyTable.CreateRow(instanceRow.SourceLineNumbers);
753 productNameRow.Operation = RowOperation.Modify;
754 productNameRow.Fields[1].Modified = true;
755 productNameRow[0] = "ProductName";
756 productNameRow[1] = (string)instanceRow[3];
757 }
758
759 if (null != instanceRow[4])
760 {
761 // Change the UpgradeCode property
762 Row upgradeCodeRow = propertyTable.CreateRow(instanceRow.SourceLineNumbers);
763 upgradeCodeRow.Operation = RowOperation.Modify;
764 upgradeCodeRow.Fields[1].Modified = true;
765 upgradeCodeRow[0] = "UpgradeCode";
766 upgradeCodeRow[1] = instanceRow[4];
767
768 // Change the Upgrade table
769 Table targetUpgradeTable = output.Tables["Upgrade"];
770 if (null != targetUpgradeTable && 0 <= targetUpgradeTable.Rows.Count)
771 {
772 string upgradeId = (string)instanceRow[4];
773 Table upgradeTable = instanceTransform.EnsureTable(this.TableDefinitions["Upgrade"]);
774 foreach (Row row in targetUpgradeTable.Rows)
775 {
776 // In case they are upgrading other codes to this new product, leave the ones that don't match the
777 // Product.UpgradeCode intact.
778 if (targetUpgradeCode == (string)row[0])
779 {
780 Row upgradeRow = upgradeTable.CreateRow(null);
781 upgradeRow.Operation = RowOperation.Add;
782 upgradeRow.Fields[0].Modified = true;
783 // I was hoping to be able to RowOperation.Modify, but that didn't appear to function.
784 // upgradeRow.Fields[0].PreviousData = (string)row[0];
785
786 // Inserting a new Upgrade record with the updated UpgradeCode
787 upgradeRow[0] = upgradeId;
788 upgradeRow[1] = row[1];
789 upgradeRow[2] = row[2];
790 upgradeRow[3] = row[3];
791 upgradeRow[4] = row[4];
792 upgradeRow[5] = row[5];
793 upgradeRow[6] = row[6];
794
795 // Delete the old row
796 Row upgradeRemoveRow = upgradeTable.CreateRow(null);
797 upgradeRemoveRow.Operation = RowOperation.Delete;
798 upgradeRemoveRow[0] = row[0];
799 upgradeRemoveRow[1] = row[1];
800 upgradeRemoveRow[2] = row[2];
801 upgradeRemoveRow[3] = row[3];
802 upgradeRemoveRow[4] = row[4];
803 upgradeRemoveRow[5] = row[5];
804 upgradeRemoveRow[6] = row[6];
805 }
806 }
807 }
808 }
809
810 // If there are instance Components generate new GUIDs for them.
811 if (0 < instanceComponentGuids.Count)
812 {
813 Table componentTable = instanceTransform.EnsureTable(this.TableDefinitions["Component"]);
814 foreach (ComponentRow targetComponentRow in instanceComponentGuids.Values)
815 {
816 string guid = targetComponentRow.Guid;
817 if (!String.IsNullOrEmpty(guid))
818 {
819 Row instanceComponentRow = componentTable.CreateRow(targetComponentRow.SourceLineNumbers);
820 instanceComponentRow.Operation = RowOperation.Modify;
821 instanceComponentRow.Fields[1].Modified = true;
822 instanceComponentRow[0] = targetComponentRow[0];
823 instanceComponentRow[1] = Uuid.NewUuid(BindDatabaseCommand.WixComponentGuidNamespace, String.Concat(guid, instanceId)).ToString("B").ToUpper(CultureInfo.InvariantCulture);
824 instanceComponentRow[2] = targetComponentRow[2];
825 instanceComponentRow[3] = targetComponentRow[3];
826 instanceComponentRow[4] = targetComponentRow[4];
827 instanceComponentRow[5] = targetComponentRow[5];
828 }
829 }
830 }
831
832 // Update the summary information
833 Hashtable summaryRows = new Hashtable(instanceSummaryInformationTable.Rows.Count);
834 foreach (Row row in instanceSummaryInformationTable.Rows)
835 {
836 summaryRows[row[0]] = row;
837
838 if ((int)SummaryInformation.Transform.UpdatedPlatformAndLanguage == (int)row[0])
839 {
840 row[1] = targetPlatformAndLanguage;
841 }
842 else if ((int)SummaryInformation.Transform.ProductCodes == (int)row[0])
843 {
844 row[1] = String.Concat(targetProductCode, targetProductVersion, ';', productCode, targetProductVersion, ';', targetUpgradeCode);
845 }
846 else if ((int)SummaryInformation.Transform.ValidationFlags == (int)row[0])
847 {
848 row[1] = 0;
849 }
850 else if ((int)SummaryInformation.Transform.Security == (int)row[0])
851 {
852 row[1] = "4";
853 }
854 }
855
856 if (!summaryRows.Contains((int)SummaryInformation.Transform.UpdatedPlatformAndLanguage))
857 {
858 Row summaryRow = instanceSummaryInformationTable.CreateRow(null);
859 summaryRow[0] = (int)SummaryInformation.Transform.UpdatedPlatformAndLanguage;
860 summaryRow[1] = targetPlatformAndLanguage;
861 }
862 else if (!summaryRows.Contains((int)SummaryInformation.Transform.ValidationFlags))
863 {
864 Row summaryRow = instanceSummaryInformationTable.CreateRow(null);
865 summaryRow[0] = (int)SummaryInformation.Transform.ValidationFlags;
866 summaryRow[1] = "0";
867 }
868 else if (!summaryRows.Contains((int)SummaryInformation.Transform.Security))
869 {
870 Row summaryRow = instanceSummaryInformationTable.CreateRow(null);
871 summaryRow[0] = (int)SummaryInformation.Transform.Security;
872 summaryRow[1] = "4";
873 }
874
875 output.SubStorages.Add(new SubStorage(instanceId, instanceTransform));
876 }
877 }
878 }
879#endif
880
881 /// <summary> 642 /// <summary>
882 /// Validate that there are no duplicate GUIDs in the output. 643 /// Validate that there are no duplicate GUIDs in the output.
883 /// </summary> 644 /// </summary>