/// <summary> /// Adds a SetProperty CA for a Directory. /// </summary> /// <param name="propertyId">The Id of the Property to set.</param> /// <param name="value">The value to set the Property to.</param> private void AddSetPropertyCustomAction(string propertyId, string value) { // Add the action Wix.CustomAction customAction = new Wix.CustomAction(); customAction.Id = propertyId; customAction.Property = propertyId; customAction.Value = value; this.fragment.AddChild(customAction); // Schedule the action Wix.InstallExecuteSequence installExecuteSequence = new Wix.InstallExecuteSequence(); Wix.Custom custom = new Wix.Custom(); custom.Action = customAction.Id; custom.Before = "CostInitialize"; installExecuteSequence.AddChild(custom); this.fragment.AddChild(installExecuteSequence); }
/// <summary> /// Creates an action element. /// </summary> /// <param name="actionRow">The action row from which the element should be created.</param> private void CreateActionElement(WixActionRow actionRow) { Wix.ISchemaElement actionElement = null; if (null != this.core.GetIndexedElement("CustomAction", actionRow.Action)) // custom action { Wix.Custom custom = new Wix.Custom(); custom.Action = actionRow.Action; if (null != actionRow.Condition) { custom.Content = actionRow.Condition; } switch (actionRow.Sequence) { case (-4): custom.OnExit = Wix.ExitType.suspend; break; case (-3): custom.OnExit = Wix.ExitType.error; break; case (-2): custom.OnExit = Wix.ExitType.cancel; break; case (-1): custom.OnExit = Wix.ExitType.success; break; default: if (null != actionRow.Before) { custom.Before = actionRow.Before; } else if (null != actionRow.After) { custom.After = actionRow.After; } else if (0 < actionRow.Sequence) { custom.Sequence = actionRow.Sequence; } break; } actionElement = custom; } else if (null != this.core.GetIndexedElement("Dialog", actionRow.Action)) // dialog { Wix.Show show = new Wix.Show(); show.Dialog = actionRow.Action; if (null != actionRow.Condition) { show.Content = actionRow.Condition; } switch (actionRow.Sequence) { case (-4): show.OnExit = Wix.ExitType.suspend; break; case (-3): show.OnExit = Wix.ExitType.error; break; case (-2): show.OnExit = Wix.ExitType.cancel; break; case (-1): show.OnExit = Wix.ExitType.success; break; default: if (null != actionRow.Before) { show.Before = actionRow.Before; } else if (null != actionRow.After) { show.After = actionRow.After; } else if (0 < actionRow.Sequence) { show.Sequence = actionRow.Sequence; } break; } actionElement = show; } else // possibly a standard action without suggested sequence information { actionElement = this.CreateStandardActionElement(actionRow); } // add the action element to the appropriate sequence element if (null != actionElement) { string sequenceTable = actionRow.SequenceTable.ToString(); Wix.IParentElement sequenceElement = (Wix.IParentElement)this.sequenceElements[sequenceTable]; if (null == sequenceElement) { switch (actionRow.SequenceTable) { case SequenceTable.AdminExecuteSequence: sequenceElement = new Wix.AdminExecuteSequence(); break; case SequenceTable.AdminUISequence: sequenceElement = new Wix.AdminUISequence(); break; case SequenceTable.AdvtExecuteSequence: sequenceElement = new Wix.AdvertiseExecuteSequence(); break; case SequenceTable.InstallExecuteSequence: sequenceElement = new Wix.InstallExecuteSequence(); break; case SequenceTable.InstallUISequence: sequenceElement = new Wix.InstallUISequence(); break; default: throw new InvalidOperationException(WixStrings.EXP_UnknowSequenceTable); } this.core.RootElement.AddChild((Wix.ISchemaElement)sequenceElement); this.sequenceElements.Add(sequenceTable, sequenceElement); } try { sequenceElement.AddChild(actionElement); } catch (System.ArgumentException) // action/dialog is not valid for this sequence { this.core.OnMessage(WixWarnings.IllegalActionInSequence(actionRow.SourceLineNumbers, actionRow.SequenceTable.ToString(), actionRow.Action)); } } }
/// <summary> /// Converts a Module to a ComponentGroup and adds all of its relevant elements to the main fragment. /// </summary> /// <param name="wix">The output object representing an unbound merge module.</param> private void ConvertModule(Wix.Wix wix) { Wix.Product product = Melter.GetProduct(wix); List <string> customActionsRemoved = new List <string>(); Dictionary <Wix.Custom, Wix.InstallExecuteSequence> customsToRemove = new Dictionary <Wix.Custom, Wix.InstallExecuteSequence>(); foreach (Wix.ISchemaElement child in product.Children) { Wix.Directory childDir = child as Wix.Directory; if (null != childDir) { bool isTargetDir = this.WalkDirectory(childDir); if (isTargetDir) { continue; } } else { Wix.Dependency childDep = child as Wix.Dependency; if (null != childDep) { this.AddPropertyRef(childDep.RequiredId); continue; } else if (child is Wix.Package) { continue; } else if (child is Wix.CustomAction) { Wix.CustomAction customAction = child as Wix.CustomAction; string directoryId; if (StartsWithStandardDirectoryId(customAction.Id, out directoryId) && customAction.Property == customAction.Id) { customActionsRemoved.Add(customAction.Id); continue; } } else if (child is Wix.InstallExecuteSequence) { Wix.InstallExecuteSequence installExecuteSequence = child as Wix.InstallExecuteSequence; foreach (Wix.ISchemaElement sequenceChild in installExecuteSequence.Children) { Wix.Custom custom = sequenceChild as Wix.Custom; string directoryId; if (custom != null && StartsWithStandardDirectoryId(custom.Action, out directoryId)) { customsToRemove.Add(custom, installExecuteSequence); } } } } this.fragment.AddChild(child); } // For any customaction that we removed, also remove the scheduling of that action. foreach (Wix.Custom custom in customsToRemove.Keys) { if (customActionsRemoved.Contains(custom.Action)) { ((Wix.InstallExecuteSequence)customsToRemove[custom]).RemoveChild(custom); } } AddProperty(this.moduleId, this.id); wix.RemoveChild(product); wix.AddChild(this.fragment); this.fragment.AddChild(this.componentGroup); this.fragment.AddChild(this.primaryDirectoryRef); }
public override void VisitCustom(Custom node) { IVertex action = Parent.AddVertex(node.Action); if (node.Before!=null) { IVertex before = Parent.AddVertex(node.Before); this.Parent.Graph.AddEdge(before, action); } if (node.After != null) { IVertex after = Parent.AddVertex(node.After); this.Parent.Graph.AddEdge(action, after); } }