Implement and use IParseHelper.ScheduleActionTuple
Rob Mensching committed
May 8, 2019 at 23:57 UTC
32b691d23c76fbe12790808d65b0b615640ebebe
4 files changed
+72
-121
src/WixToolset.Core/Compiler.cs
+7
-13
@@ -7284,34 +7284,28 @@ namespace WixToolset.Core
7284
}
7285
7286
// finally, schedule RemoveExistingProducts
7287
- var actionTuple = new WixActionTuple(sourceLineNumbers, new Identifier(AccessModifier.Public, "InstallExecuteSequence", "RemoveExistingProducts"))
7288
- {
7289
- SequenceTable = SequenceTable.InstallExecuteSequence,
7290
- Action = "RemoveExistingProducts",
7291
- Overridable = false,
7292
- };
7293
-
7287
+ string after = null;
7288
switch (schedule)
7289
{
7290
case null:
7291
case "afterInstallValidate":
7298
- actionTuple.After = "InstallValidate";
7292
+ after = "InstallValidate";
7293
break;
7294
case "afterInstallInitialize":
7301
- actionTuple.After = "InstallInitialize";
7295
+ after = "InstallInitialize";
7296
break;
7297
case "afterInstallExecute":
7304
- actionTuple.After = "InstallExecute";
7298
+ after = "InstallExecute";
7299
break;
7300
case "afterInstallExecuteAgain":
7307
- actionTuple.After = "InstallExecuteAgain";
7301
+ after = "InstallExecuteAgain";
7302
break;
7303
case "afterInstallFinalize":
7310
- actionTuple.After = "InstallFinalize";
7304
+ after = "InstallFinalize";
7305
break;
7306
}
7307
7314
- this.Core.AddTuple(actionTuple);
7308
+ this.Core.ScheduleActionTuple(sourceLineNumbers, AccessModifier.Public, SequenceTable.InstallExecuteSequence, "RemoveExistingProducts", afterAction: after);
7309
}
7310
}
7311
src/WixToolset.Core/CompilerCore.cs
+7
-52
@@ -402,7 +402,7 @@ namespace WixToolset.Core
402
/// <returns>Identifier of the leaf directory created.</returns>
403
public string CreateDirectoryReferenceFromInlineSyntax(SourceLineNumber sourceLineNumbers, XAttribute attribute, string parentId)
404
{
405
- return this.parseHelper.CreateDirectoryReferenceFromInlineSyntax(this.ActiveSection, sourceLineNumbers, attribute, parentId);
405
+ return this.parseHelper.CreateDirectoryReferenceFromInlineSyntax(this.ActiveSection, sourceLineNumbers, parentId, attribute, this.activeSectionInlinedDirectoryIds);
406
}
407
408
/// <summary>
@@ -1147,57 +1147,7 @@ namespace WixToolset.Core
1147
/// <returns>Identifier for the newly created row.</returns>
1148
internal Identifier CreateDirectoryRow(SourceLineNumber sourceLineNumbers, Identifier id, string parentId, string name, string shortName = null, string sourceName = null, string shortSourceName = null)
1149
{
1150
- //string defaultDir = null;
1151
-
1152
- //if (name.Equals("SourceDir") || this.IsValidShortFilename(name, false))
1153
- //{
1154
- // defaultDir = name;
1155
- //}
1156
- //else
1157
- //{
1158
- // if (String.IsNullOrEmpty(shortName))
1159
- // {
1160
- // shortName = this.CreateShortName(name, false, false, "Directory", parentId);
1161
- // }
1162
-
1163
- // defaultDir = String.Concat(shortName, "|", name);
1164
- //}
1165
-
1166
- //if (!String.IsNullOrEmpty(sourceName))
1167
- //{
1168
- // if (this.IsValidShortFilename(sourceName, false))
1169
- // {
1170
- // defaultDir = String.Concat(defaultDir, ":", sourceName);
1171
- // }
1172
- // else
1173
- // {
1174
- // if (String.IsNullOrEmpty(shortSourceName))
1175
- // {
1176
- // shortSourceName = this.CreateShortName(sourceName, false, false, "Directory", parentId);
1177
- // }
1178
-
1179
- // defaultDir = String.Concat(defaultDir, ":", shortSourceName, "|", sourceName);
1180
- // }
1181
- //}
1182
-
1183
- //// For anonymous directories, create the identifier. If this identifier already exists in the
1184
- //// active section, bail so we don't add duplicate anonymous directory rows (which are legal
1185
- //// but bloat the intermediate and ultimately make the linker do "busy work").
1186
- //if (null == id)
1187
- //{
1188
- // id = this.CreateIdentifier("dir", parentId, name, shortName, sourceName, shortSourceName);
1189
-
1190
- // if (!this.activeSectionInlinedDirectoryIds.Add(id.Id))
1191
- // {
1192
- // return id;
1193
- // }
1194
- //}
1195
-
1196
- //var row = this.CreateRow(sourceLineNumbers, TupleDefinitionType.Directory, id);
1197
- //row.Set(1, parentId);
1198
- //row.Set(2, defaultDir);
1199
- //return id;
1200
- return this.parseHelper.CreateDirectoryRow(this.ActiveSection, sourceLineNumbers, id, parentId, name, shortName, sourceName, shortSourceName, this.activeSectionInlinedDirectoryIds);
1150
+ return this.parseHelper.CreateDirectoryRow(this.ActiveSection, sourceLineNumbers, id, parentId, name, this.activeSectionInlinedDirectoryIds, shortName, sourceName, shortSourceName);
1151
}
1152
1153
/// <summary>
@@ -1212,6 +1162,11 @@ namespace WixToolset.Core
1162
return this.parseHelper.GetAttributeInlineDirectorySyntax(sourceLineNumbers, attribute, resultUsedToCreateReference);
1163
}
1164
1165
+ internal WixActionTuple ScheduleActionTuple(SourceLineNumber sourceLineNumbers, AccessModifier access, SequenceTable sequence, string actionName, string condition = null, string beforeAction = null, string afterAction = null, bool overridable = false)
1166
+ {
1167
+ return this.parseHelper.ScheduleActionTuple(this.ActiveSection, sourceLineNumbers, access, sequence, actionName, condition, beforeAction, afterAction, overridable);
1168
+ }
1169
+
1170
/// <summary>
1171
/// Finds a compiler extension by namespace URI.
1172
/// </summary>
src/WixToolset.Core/Compiler_2.cs
+2
-49
@@ -4126,18 +4126,7 @@ namespace WixToolset.Core
4126
4127
foreach (var sequence in sequences)
4128
{
4129
- var sequenceId = new Identifier(AccessModifier.Public, sequence.ToString(), actionName);
4130
-
4131
- var sequenceTuple = new WixActionTuple(sourceLineNumbers, sequenceId)
4132
- {
4133
- SequenceTable = sequence,
4134
- Action = actionName,
4135
- Condition = condition,
4136
- After = "CostInialize",
4137
- Overridable = false
4138
- };
4139
-
4140
- this.Core.AddTuple(tuple);
4129
+ this.Core.ScheduleActionTuple(sourceLineNumbers, AccessModifier.Public, sequence, actionName, condition, afterAction: "CostInitialize");
4130
}
4131
}
4132
}
@@ -4287,43 +4276,7 @@ namespace WixToolset.Core
4276
4277
foreach (var sequence in sequences)
4278
{
4290
- var sequenceId = new Identifier(AccessModifier.Public, sequence.ToString(), actionName);
4291
-
4292
- var sequenceTuple = new WixActionTuple(sourceLineNumbers, sequenceId)
4293
- {
4294
- SequenceTable = sequence,
4295
- Action = actionName,
4296
- Condition = condition,
4297
- Before = beforeAction,
4298
- After = afterAction,
4299
- Overridable = false
4300
- };
4301
-
4302
- this.Core.AddTuple(tuple);
4303
-
4304
- if (null != beforeAction)
4305
- {
4306
- if (WindowsInstallerStandard.IsStandardAction(beforeAction))
4307
- {
4308
- this.Core.CreateSimpleReference(sourceLineNumbers, "WixAction", sequence.ToString(), beforeAction);
4309
- }
4310
- else
4311
- {
4312
- this.Core.CreateSimpleReference(sourceLineNumbers, "CustomAction", beforeAction);
4313
- }
4314
- }
4315
-
4316
- if (null != afterAction)
4317
- {
4318
- if (WindowsInstallerStandard.IsStandardAction(afterAction))
4319
- {
4320
- this.Core.CreateSimpleReference(sourceLineNumbers, "WixAction", sequence.ToString(), afterAction);
4321
- }
4322
- else
4323
- {
4324
- this.Core.CreateSimpleReference(sourceLineNumbers, "CustomAction", afterAction);
4325
- }
4326
- }
4279
+ this.Core.ScheduleActionTuple(sourceLineNumbers, AccessModifier.Public, sequence, actionName, condition, beforeAction, afterAction);
4280
}
4281
}
4282
}
src/WixToolset.Core/ExtensibilityServices/ParseHelper.cs
+56
-7
@@ -13,6 +13,7 @@ namespace WixToolset.Core.ExtensibilityServices
13
using System.Xml.Linq;
14
using WixToolset.Data;
15
using WixToolset.Data.Tuples;
16
+ using WixToolset.Data.WindowsInstaller;
17
using WixToolset.Extensibility;
18
using WixToolset.Extensibility.Data;
19
using WixToolset.Extensibility.Services;
@@ -63,9 +64,9 @@ namespace WixToolset.Core.ExtensibilityServices
64
this.CreateWixGroupRow(section, sourceLineNumbers, parentType, parentId, childType, childId);
65
}
66
66
- public Identifier CreateDirectoryRow(IntermediateSection section, SourceLineNumber sourceLineNumbers, Identifier id, string parentId, string name, string shortName = null, string sourceName = null, string shortSourceName = null, ISet<string> sectionInlinedDirectoryIds = null)
67
+ public Identifier CreateDirectoryRow(IntermediateSection section, SourceLineNumber sourceLineNumbers, Identifier id, string parentId, string name, ISet<string> sectionInlinedDirectoryIds, string shortName = null, string sourceName = null, string shortSourceName = null)
68
{
68
- string defaultDir = null;
69
+ string defaultDir;
70
71
if (name.Equals("SourceDir") || this.IsValidShortFilename(name, false))
72
{
@@ -111,13 +112,18 @@ namespace WixToolset.Core.ExtensibilityServices
112
}
113
}
114
114
- var row = this.CreateRow(section, sourceLineNumbers, TupleDefinitionType.Directory, id);
115
- row.Set(1, parentId);
116
- row.Set(2, defaultDir);
115
+ var tuple = new DirectoryTuple(sourceLineNumbers, id)
116
+ {
117
+ Directory_Parent = parentId,
118
+ DefaultDir = defaultDir,
119
+ };
120
+
121
+ section.Tuples.Add(tuple);
122
+
123
return id;
124
}
125
120
- public string CreateDirectoryReferenceFromInlineSyntax(IntermediateSection section, SourceLineNumber sourceLineNumbers, XAttribute attribute, string parentId)
126
+ public string CreateDirectoryReferenceFromInlineSyntax(IntermediateSection section, SourceLineNumber sourceLineNumbers, string parentId, XAttribute attribute, ISet<string> sectionInlinedDirectoryIds)
127
{
128
string id = null;
129
string[] inlineSyntax = this.GetAttributeInlineDirectorySyntax(sourceLineNumbers, attribute, true);
@@ -152,7 +158,7 @@ namespace WixToolset.Core.ExtensibilityServices
158
159
for (int i = pathStartsAt; i < inlineSyntax.Length; ++i)
160
{
155
- Identifier inlineId = this.CreateDirectoryRow(section, sourceLineNumbers, null, id, inlineSyntax[i]);
161
+ Identifier inlineId = this.CreateDirectoryRow(section, sourceLineNumbers, null, id, inlineSyntax[i], sectionInlinedDirectoryIds);
162
id = inlineId.Id;
163
}
164
}
@@ -826,6 +832,49 @@ namespace WixToolset.Core.ExtensibilityServices
832
}
833
}
834
835
+ public WixActionTuple ScheduleActionTuple(IntermediateSection section, SourceLineNumber sourceLineNumbers, AccessModifier access, SequenceTable sequence, string actionName, string condition, string beforeAction, string afterAction, bool overridable = false)
836
+ {
837
+ var actionId = new Identifier(access, sequence, actionName);
838
+
839
+ var actionTuple = new WixActionTuple(sourceLineNumbers, actionId)
840
+ {
841
+ SequenceTable = sequence,
842
+ Action = actionName,
843
+ Condition = condition,
844
+ Before = beforeAction,
845
+ After = afterAction,
846
+ Overridable = overridable,
847
+ };
848
+
849
+ section.Tuples.Add(actionTuple);
850
+
851
+ if (null != beforeAction)
852
+ {
853
+ if (WindowsInstallerStandard.IsStandardAction(beforeAction))
854
+ {
855
+ this.CreateSimpleReference(section, sourceLineNumbers, "WixAction", sequence.ToString(), beforeAction);
856
+ }
857
+ else
858
+ {
859
+ this.CreateSimpleReference(section, sourceLineNumbers, "CustomAction", beforeAction);
860
+ }
861
+ }
862
+
863
+ if (null != afterAction)
864
+ {
865
+ if (WindowsInstallerStandard.IsStandardAction(afterAction))
866
+ {
867
+ this.CreateSimpleReference(section, sourceLineNumbers, "WixAction", sequence.ToString(), afterAction);
868
+ }
869
+ else
870
+ {
871
+ this.CreateSimpleReference(section, sourceLineNumbers, "CustomAction", afterAction);
872
+ }
873
+ }
874
+
875
+ return actionTuple;
876
+ }
877
+
878
public void UnexpectedAttribute(XElement element, XAttribute attribute)
879
{
880
var sourceLineNumbers = Preprocessor.GetSourceLineNumbers(element);