From 32b691d23c76fbe12790808d65b0b615640ebebe Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Wed, 8 May 2019 23:57:15 -0700 Subject: Implement and use IParseHelper.ScheduleActionTuple --- src/WixToolset.Core/Compiler.cs | 20 +++---- src/WixToolset.Core/CompilerCore.cs | 59 +++----------------- src/WixToolset.Core/Compiler_2.cs | 51 +----------------- .../ExtensibilityServices/ParseHelper.cs | 63 +++++++++++++++++++--- 4 files changed, 72 insertions(+), 121 deletions(-) (limited to 'src/WixToolset.Core') diff --git a/src/WixToolset.Core/Compiler.cs b/src/WixToolset.Core/Compiler.cs index 8eff4aac..48e22f6d 100644 --- a/src/WixToolset.Core/Compiler.cs +++ b/src/WixToolset.Core/Compiler.cs @@ -7284,34 +7284,28 @@ namespace WixToolset.Core } // finally, schedule RemoveExistingProducts - var actionTuple = new WixActionTuple(sourceLineNumbers, new Identifier(AccessModifier.Public, "InstallExecuteSequence", "RemoveExistingProducts")) - { - SequenceTable = SequenceTable.InstallExecuteSequence, - Action = "RemoveExistingProducts", - Overridable = false, - }; - + string after = null; switch (schedule) { case null: case "afterInstallValidate": - actionTuple.After = "InstallValidate"; + after = "InstallValidate"; break; case "afterInstallInitialize": - actionTuple.After = "InstallInitialize"; + after = "InstallInitialize"; break; case "afterInstallExecute": - actionTuple.After = "InstallExecute"; + after = "InstallExecute"; break; case "afterInstallExecuteAgain": - actionTuple.After = "InstallExecuteAgain"; + after = "InstallExecuteAgain"; break; case "afterInstallFinalize": - actionTuple.After = "InstallFinalize"; + after = "InstallFinalize"; break; } - this.Core.AddTuple(actionTuple); + this.Core.ScheduleActionTuple(sourceLineNumbers, AccessModifier.Public, SequenceTable.InstallExecuteSequence, "RemoveExistingProducts", afterAction: after); } } diff --git a/src/WixToolset.Core/CompilerCore.cs b/src/WixToolset.Core/CompilerCore.cs index d21e490f..ea235a97 100644 --- a/src/WixToolset.Core/CompilerCore.cs +++ b/src/WixToolset.Core/CompilerCore.cs @@ -402,7 +402,7 @@ namespace WixToolset.Core /// Identifier of the leaf directory created. public string CreateDirectoryReferenceFromInlineSyntax(SourceLineNumber sourceLineNumbers, XAttribute attribute, string parentId) { - return this.parseHelper.CreateDirectoryReferenceFromInlineSyntax(this.ActiveSection, sourceLineNumbers, attribute, parentId); + return this.parseHelper.CreateDirectoryReferenceFromInlineSyntax(this.ActiveSection, sourceLineNumbers, parentId, attribute, this.activeSectionInlinedDirectoryIds); } /// @@ -1147,57 +1147,7 @@ namespace WixToolset.Core /// Identifier for the newly created row. internal Identifier CreateDirectoryRow(SourceLineNumber sourceLineNumbers, Identifier id, string parentId, string name, string shortName = null, string sourceName = null, string shortSourceName = null) { - //string defaultDir = null; - - //if (name.Equals("SourceDir") || this.IsValidShortFilename(name, false)) - //{ - // defaultDir = name; - //} - //else - //{ - // if (String.IsNullOrEmpty(shortName)) - // { - // shortName = this.CreateShortName(name, false, false, "Directory", parentId); - // } - - // defaultDir = String.Concat(shortName, "|", name); - //} - - //if (!String.IsNullOrEmpty(sourceName)) - //{ - // if (this.IsValidShortFilename(sourceName, false)) - // { - // defaultDir = String.Concat(defaultDir, ":", sourceName); - // } - // else - // { - // if (String.IsNullOrEmpty(shortSourceName)) - // { - // shortSourceName = this.CreateShortName(sourceName, false, false, "Directory", parentId); - // } - - // defaultDir = String.Concat(defaultDir, ":", shortSourceName, "|", sourceName); - // } - //} - - //// For anonymous directories, create the identifier. If this identifier already exists in the - //// active section, bail so we don't add duplicate anonymous directory rows (which are legal - //// but bloat the intermediate and ultimately make the linker do "busy work"). - //if (null == id) - //{ - // id = this.CreateIdentifier("dir", parentId, name, shortName, sourceName, shortSourceName); - - // if (!this.activeSectionInlinedDirectoryIds.Add(id.Id)) - // { - // return id; - // } - //} - - //var row = this.CreateRow(sourceLineNumbers, TupleDefinitionType.Directory, id); - //row.Set(1, parentId); - //row.Set(2, defaultDir); - //return id; - return this.parseHelper.CreateDirectoryRow(this.ActiveSection, sourceLineNumbers, id, parentId, name, shortName, sourceName, shortSourceName, this.activeSectionInlinedDirectoryIds); + return this.parseHelper.CreateDirectoryRow(this.ActiveSection, sourceLineNumbers, id, parentId, name, this.activeSectionInlinedDirectoryIds, shortName, sourceName, shortSourceName); } /// @@ -1212,6 +1162,11 @@ namespace WixToolset.Core return this.parseHelper.GetAttributeInlineDirectorySyntax(sourceLineNumbers, attribute, resultUsedToCreateReference); } + internal WixActionTuple ScheduleActionTuple(SourceLineNumber sourceLineNumbers, AccessModifier access, SequenceTable sequence, string actionName, string condition = null, string beforeAction = null, string afterAction = null, bool overridable = false) + { + return this.parseHelper.ScheduleActionTuple(this.ActiveSection, sourceLineNumbers, access, sequence, actionName, condition, beforeAction, afterAction, overridable); + } + /// /// Finds a compiler extension by namespace URI. /// diff --git a/src/WixToolset.Core/Compiler_2.cs b/src/WixToolset.Core/Compiler_2.cs index f42c9da1..0efaec6e 100644 --- a/src/WixToolset.Core/Compiler_2.cs +++ b/src/WixToolset.Core/Compiler_2.cs @@ -4126,18 +4126,7 @@ namespace WixToolset.Core foreach (var sequence in sequences) { - var sequenceId = new Identifier(AccessModifier.Public, sequence.ToString(), actionName); - - var sequenceTuple = new WixActionTuple(sourceLineNumbers, sequenceId) - { - SequenceTable = sequence, - Action = actionName, - Condition = condition, - After = "CostInialize", - Overridable = false - }; - - this.Core.AddTuple(tuple); + this.Core.ScheduleActionTuple(sourceLineNumbers, AccessModifier.Public, sequence, actionName, condition, afterAction: "CostInitialize"); } } } @@ -4287,43 +4276,7 @@ namespace WixToolset.Core foreach (var sequence in sequences) { - var sequenceId = new Identifier(AccessModifier.Public, sequence.ToString(), actionName); - - var sequenceTuple = new WixActionTuple(sourceLineNumbers, sequenceId) - { - SequenceTable = sequence, - Action = actionName, - Condition = condition, - Before = beforeAction, - After = afterAction, - Overridable = false - }; - - this.Core.AddTuple(tuple); - - if (null != beforeAction) - { - if (WindowsInstallerStandard.IsStandardAction(beforeAction)) - { - this.Core.CreateSimpleReference(sourceLineNumbers, "WixAction", sequence.ToString(), beforeAction); - } - else - { - this.Core.CreateSimpleReference(sourceLineNumbers, "CustomAction", beforeAction); - } - } - - if (null != afterAction) - { - if (WindowsInstallerStandard.IsStandardAction(afterAction)) - { - this.Core.CreateSimpleReference(sourceLineNumbers, "WixAction", sequence.ToString(), afterAction); - } - else - { - this.Core.CreateSimpleReference(sourceLineNumbers, "CustomAction", afterAction); - } - } + this.Core.ScheduleActionTuple(sourceLineNumbers, AccessModifier.Public, sequence, actionName, condition, beforeAction, afterAction); } } } diff --git a/src/WixToolset.Core/ExtensibilityServices/ParseHelper.cs b/src/WixToolset.Core/ExtensibilityServices/ParseHelper.cs index 9d4a7cbd..73a78a1f 100644 --- a/src/WixToolset.Core/ExtensibilityServices/ParseHelper.cs +++ b/src/WixToolset.Core/ExtensibilityServices/ParseHelper.cs @@ -13,6 +13,7 @@ namespace WixToolset.Core.ExtensibilityServices using System.Xml.Linq; using WixToolset.Data; using WixToolset.Data.Tuples; + using WixToolset.Data.WindowsInstaller; using WixToolset.Extensibility; using WixToolset.Extensibility.Data; using WixToolset.Extensibility.Services; @@ -63,9 +64,9 @@ namespace WixToolset.Core.ExtensibilityServices this.CreateWixGroupRow(section, sourceLineNumbers, parentType, parentId, childType, childId); } - public Identifier CreateDirectoryRow(IntermediateSection section, SourceLineNumber sourceLineNumbers, Identifier id, string parentId, string name, string shortName = null, string sourceName = null, string shortSourceName = null, ISet sectionInlinedDirectoryIds = null) + public Identifier CreateDirectoryRow(IntermediateSection section, SourceLineNumber sourceLineNumbers, Identifier id, string parentId, string name, ISet sectionInlinedDirectoryIds, string shortName = null, string sourceName = null, string shortSourceName = null) { - string defaultDir = null; + string defaultDir; if (name.Equals("SourceDir") || this.IsValidShortFilename(name, false)) { @@ -111,13 +112,18 @@ namespace WixToolset.Core.ExtensibilityServices } } - var row = this.CreateRow(section, sourceLineNumbers, TupleDefinitionType.Directory, id); - row.Set(1, parentId); - row.Set(2, defaultDir); + var tuple = new DirectoryTuple(sourceLineNumbers, id) + { + Directory_Parent = parentId, + DefaultDir = defaultDir, + }; + + section.Tuples.Add(tuple); + return id; } - public string CreateDirectoryReferenceFromInlineSyntax(IntermediateSection section, SourceLineNumber sourceLineNumbers, XAttribute attribute, string parentId) + public string CreateDirectoryReferenceFromInlineSyntax(IntermediateSection section, SourceLineNumber sourceLineNumbers, string parentId, XAttribute attribute, ISet sectionInlinedDirectoryIds) { string id = null; string[] inlineSyntax = this.GetAttributeInlineDirectorySyntax(sourceLineNumbers, attribute, true); @@ -152,7 +158,7 @@ namespace WixToolset.Core.ExtensibilityServices for (int i = pathStartsAt; i < inlineSyntax.Length; ++i) { - Identifier inlineId = this.CreateDirectoryRow(section, sourceLineNumbers, null, id, inlineSyntax[i]); + Identifier inlineId = this.CreateDirectoryRow(section, sourceLineNumbers, null, id, inlineSyntax[i], sectionInlinedDirectoryIds); id = inlineId.Id; } } @@ -826,6 +832,49 @@ namespace WixToolset.Core.ExtensibilityServices } } + public WixActionTuple ScheduleActionTuple(IntermediateSection section, SourceLineNumber sourceLineNumbers, AccessModifier access, SequenceTable sequence, string actionName, string condition, string beforeAction, string afterAction, bool overridable = false) + { + var actionId = new Identifier(access, sequence, actionName); + + var actionTuple = new WixActionTuple(sourceLineNumbers, actionId) + { + SequenceTable = sequence, + Action = actionName, + Condition = condition, + Before = beforeAction, + After = afterAction, + Overridable = overridable, + }; + + section.Tuples.Add(actionTuple); + + if (null != beforeAction) + { + if (WindowsInstallerStandard.IsStandardAction(beforeAction)) + { + this.CreateSimpleReference(section, sourceLineNumbers, "WixAction", sequence.ToString(), beforeAction); + } + else + { + this.CreateSimpleReference(section, sourceLineNumbers, "CustomAction", beforeAction); + } + } + + if (null != afterAction) + { + if (WindowsInstallerStandard.IsStandardAction(afterAction)) + { + this.CreateSimpleReference(section, sourceLineNumbers, "WixAction", sequence.ToString(), afterAction); + } + else + { + this.CreateSimpleReference(section, sourceLineNumbers, "CustomAction", afterAction); + } + } + + return actionTuple; + } + public void UnexpectedAttribute(XElement element, XAttribute attribute) { var sourceLineNumbers = Preprocessor.GetSourceLineNumbers(element); -- cgit v1.2.3-55-g6feb