@joebigelow / wix-1 / commits / f18b9604

Move CustomAction script inner text to ScriptFile attribute

Rob Mensching committed Jun 22, 2020 at 23:09 UTC f18b96045088d6d989e70df19343a99092685e5e
3 files changed +26 -48
src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs
+2 -2
@@ -347,9 +347,9 @@ namespace WixToolset.Core.WindowsInstaller.Bind
347 command.Execute();
348 }
349
350 - // Update control text from files on disk.
350 + // Update tuples that reference text files on disk.
351 {
352 - var command = new UpdateControlTextCommand(this.Messaging, section);
352 + var command = new UpdateFromTextFilesCommand(this.Messaging, section);
353 command.Execute();
354 }
355
src/WixToolset.Core.WindowsInstaller/Bind/UpdateFromTextFilesCommand.cs renamed
+7 -2
@@ -9,9 +9,9 @@ namespace WixToolset.Core.WindowsInstaller.Bind
9 using WixToolset.Data.Tuples;
10 using WixToolset.Extensibility.Services;
11
12 - internal class UpdateControlTextCommand
12 + internal class UpdateFromTextFilesCommand
13 {
14 - public UpdateControlTextCommand(IMessaging messaging, IntermediateSection section)
14 + public UpdateFromTextFilesCommand(IMessaging messaging, IntermediateSection section)
15 {
16 this.Messaging = messaging;
17 this.Section = section;
@@ -32,6 +32,11 @@ namespace WixToolset.Core.WindowsInstaller.Bind
32 {
33 control.Text = this.ReadTextFile(control.SourceLineNumbers, control.SourceFile.Path);
34 }
35 +
36 + foreach (var customAction in this.Section.Tuples.OfType<CustomActionTuple>().Where(c => c.ScriptFile != null))
37 + {
38 + customAction.Target = this.ReadTextFile(customAction.SourceLineNumbers, customAction.ScriptFile.Path);
39 + }
40 }
41
42 /// <summary>
src/WixToolset.Core/Compiler.cs
+17 -44
@@ -3134,6 +3134,8 @@ namespace WixToolset.Core
3134 string target = null;
3135 var explicitWin64 = false;
3136
3137 + string scriptFile = null;
3138 +
3139 CustomActionSourceType? sourceType = null;
3140 CustomActionTargetType? targetType = null;
3141 var executionType = CustomActionExecutionType.Immediate;
@@ -3160,7 +3162,6 @@ namespace WixToolset.Core
3162 this.Core.Write(ErrorMessages.CustomActionMultipleSources(sourceLineNumbers, node.Name.LocalName, attrib.Name.LocalName, "BinaryKey", "Directory", "FileKey", "Property", "Script"));
3163 }
3164 source = this.Core.GetAttributeIdentifierValue(sourceLineNumbers, attrib);
3163 - //sourceBits = MsiInterop.MsidbCustomActionTypeBinaryData;
3165 sourceType = CustomActionSourceType.Binary;
3166 this.Core.CreateSimpleReference(sourceLineNumbers, TupleDefinitions.Binary, source); // add a reference to the appropriate Binary
3167 break;
@@ -3170,7 +3171,6 @@ namespace WixToolset.Core
3171 this.Core.Write(ErrorMessages.CustomActionMultipleSources(sourceLineNumbers, node.Name.LocalName, attrib.Name.LocalName, "BinaryKey", "Directory", "FileKey", "Property", "Script"));
3172 }
3173 source = this.Core.CreateDirectoryReferenceFromInlineSyntax(sourceLineNumbers, attrib, null);
3173 - //sourceBits = MsiInterop.MsidbCustomActionTypeDirectory;
3174 sourceType = CustomActionSourceType.Directory;
3175 break;
3176 case "DllEntry":
@@ -3179,7 +3179,6 @@ namespace WixToolset.Core
3179 this.Core.Write(ErrorMessages.CustomActionMultipleTargets(sourceLineNumbers, node.Name.LocalName, attrib.Name.LocalName, "DllEntry", "Error", "ExeCommand", "JScriptCall", "Script", "Value", "VBScriptCall"));
3180 }
3181 target = this.Core.GetAttributeValue(sourceLineNumbers, attrib);
3182 - //targetBits = MsiInterop.MsidbCustomActionTypeDll;
3182 targetType = CustomActionTargetType.Dll;
3183 break;
3184 case "Error":
@@ -3188,7 +3187,6 @@ namespace WixToolset.Core
3187 this.Core.Write(ErrorMessages.CustomActionMultipleTargets(sourceLineNumbers, node.Name.LocalName, attrib.Name.LocalName, "DllEntry", "Error", "ExeCommand", "JScriptCall", "Script", "Value", "VBScriptCall"));
3188 }
3189 target = this.Core.GetAttributeValue(sourceLineNumbers, attrib);
3191 - //targetBits = MsiInterop.MsidbCustomActionTypeTextData | MsiInterop.MsidbCustomActionTypeSourceFile;
3190 sourceType = CustomActionSourceType.File;
3191 targetType = CustomActionTargetType.TextData;
3192
@@ -3206,7 +3204,6 @@ namespace WixToolset.Core
3204 this.Core.Write(ErrorMessages.CustomActionMultipleTargets(sourceLineNumbers, node.Name.LocalName, attrib.Name.LocalName, "DllEntry", "Error", "ExeCommand", "JScriptCall", "Script", "Value", "VBScriptCall"));
3205 }
3206 target = this.Core.GetAttributeValue(sourceLineNumbers, attrib, EmptyRule.CanBeEmpty); // one of the few cases where an empty string value is valid
3209 - //targetBits = MsiInterop.MsidbCustomActionTypeExe;
3207 targetType = CustomActionTargetType.Exe;
3208 break;
3209 case "Execute":
@@ -3214,30 +3211,24 @@ namespace WixToolset.Core
3211 switch (execute)
3212 {
3213 case "commit":
3217 - //bits |= MsiInterop.MsidbCustomActionTypeInScript | MsiInterop.MsidbCustomActionTypeCommit;
3214 executionType = CustomActionExecutionType.Commit;
3215 break;
3216 case "deferred":
3221 - //bits |= MsiInterop.MsidbCustomActionTypeInScript;
3217 executionType = CustomActionExecutionType.Deferred;
3218 break;
3219 case "firstSequence":
3225 - //bits |= MsiInterop.MsidbCustomActionTypeFirstSequence;
3220 executionType = CustomActionExecutionType.FirstSequence;
3221 break;
3222 case "immediate":
3223 executionType = CustomActionExecutionType.Immediate;
3224 break;
3225 case "oncePerProcess":
3232 - //bits |= MsiInterop.MsidbCustomActionTypeOncePerProcess;
3226 executionType = CustomActionExecutionType.OncePerProcess;
3227 break;
3228 case "rollback":
3236 - //bits |= MsiInterop.MsidbCustomActionTypeInScript | MsiInterop.MsidbCustomActionTypeRollback;
3229 executionType = CustomActionExecutionType.Rollback;
3230 break;
3231 case "secondSequence":
3240 - //bits |= MsiInterop.MsidbCustomActionTypeClientRepeat;
3232 executionType = CustomActionExecutionType.ClientRepeat;
3233 break;
3234 default:
@@ -3251,23 +3242,14 @@ namespace WixToolset.Core
3242 this.Core.Write(ErrorMessages.CustomActionMultipleSources(sourceLineNumbers, node.Name.LocalName, attrib.Name.LocalName, "BinaryKey", "Directory", "FileKey", "Property", "Script"));
3243 }
3244 source = this.Core.GetAttributeIdentifierValue(sourceLineNumbers, attrib);
3254 - //sourceBits = MsiInterop.MsidbCustomActionTypeSourceFile;
3245 sourceType = CustomActionSourceType.File;
3246 this.Core.CreateSimpleReference(sourceLineNumbers, TupleDefinitions.File, source); // add a reference to the appropriate File
3247 break;
3248 case "HideTarget":
3249 hidden = YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib);
3260 - //if (YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib))
3261 - //{
3262 - // bits |= MsiInterop.MsidbCustomActionTypeHideTarget;
3263 - //}
3250 break;
3251 case "Impersonate":
3252 impersonate = YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib);
3267 - //if (YesNoType.No == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib))
3268 - //{
3269 - // bits |= MsiInterop.MsidbCustomActionTypeNoImpersonate;
3270 - //}
3253 break;
3254 case "JScriptCall":
3255 if (null != target)
@@ -3275,15 +3257,10 @@ namespace WixToolset.Core
3257 this.Core.Write(ErrorMessages.CustomActionMultipleTargets(sourceLineNumbers, node.Name.LocalName, attrib.Name.LocalName, "DllEntry", "Error", "ExeCommand", "JScriptCall", "Script", "Value", "VBScriptCall"));
3258 }
3259 target = this.Core.GetAttributeValue(sourceLineNumbers, attrib, EmptyRule.CanBeEmpty); // one of the few cases where an empty string value is valid
3278 - //targetBits = MsiInterop.MsidbCustomActionTypeJScript;
3260 targetType = CustomActionTargetType.JScript;
3261 break;
3262 case "PatchUninstall":
3263 patchUninstall = YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib);
3283 - //if (YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib))
3284 - //{
3285 - // extendedBits |= MsiInterop.MsidbCustomActionTypePatchUninstall;
3286 - //}
3264 break;
3265 case "Property":
3266 if (null != source)
@@ -3291,7 +3268,6 @@ namespace WixToolset.Core
3268 this.Core.Write(ErrorMessages.CustomActionMultipleSources(sourceLineNumbers, node.Name.LocalName, attrib.Name.LocalName, "BinaryKey", "Directory", "FileKey", "Property", "Script"));
3269 }
3270 source = this.Core.GetAttributeValue(sourceLineNumbers, attrib);
3294 - //sourceBits = MsiInterop.MsidbCustomActionTypeProperty;
3271 sourceType = CustomActionSourceType.Property;
3272 break;
3273 case "Return":
@@ -3299,18 +3275,15 @@ namespace WixToolset.Core
3275 switch (returnValue)
3276 {
3277 case "asyncNoWait":
3302 - //bits |= MsiInterop.MsidbCustomActionTypeAsync | MsiInterop.MsidbCustomActionTypeContinue;
3278 async = true;
3279 ignoreResult = true;
3280 break;
3281 case "asyncWait":
3307 - //bits |= MsiInterop.MsidbCustomActionTypeAsync;
3282 async = true;
3283 break;
3284 case "check":
3285 break;
3286 case "ignore":
3313 - //bits |= MsiInterop.MsidbCustomActionTypeContinue;
3287 ignoreResult = true;
3288 break;
3289 case "":
@@ -3341,15 +3314,11 @@ namespace WixToolset.Core
3314 switch (script)
3315 {
3316 case "jscript":
3344 - //sourceBits = MsiInterop.MsidbCustomActionTypeDirectory;
3317 sourceType = CustomActionSourceType.Directory;
3346 - //targetBits = MsiInterop.MsidbCustomActionTypeJScript;
3318 targetType = CustomActionTargetType.JScript;
3319 break;
3320 case "vbscript":
3350 - //sourceBits = MsiInterop.MsidbCustomActionTypeDirectory;
3321 sourceType = CustomActionSourceType.Directory;
3352 - //targetBits = MsiInterop.MsidbCustomActionTypeVBScript;
3322 targetType = CustomActionTargetType.VBScript;
3323 break;
3324 case "":
@@ -3359,15 +3328,14 @@ namespace WixToolset.Core
3328 break;
3329 }
3330 break;
3331 + case "ScriptFile":
3332 + scriptFile = this.Core.GetAttributeValue(sourceLineNumbers, attrib);
3333 + break;
3334 case "SuppressModularization":
3335 suppressModularization = this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib);
3336 break;
3337 case "TerminalServerAware":
3338 tsAware = YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib);
3367 - //if (YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib))
3368 - //{
3369 - // bits |= MsiInterop.MsidbCustomActionTypeTSAware;
3370 - //}
3339 break;
3340 case "Value":
3341 if (null != target)
@@ -3375,7 +3343,6 @@ namespace WixToolset.Core
3343 this.Core.Write(ErrorMessages.CustomActionMultipleTargets(sourceLineNumbers, node.Name.LocalName, attrib.Name.LocalName, "DllEntry", "Error", "ExeCommand", "JScriptCall", "Script", "Value", "VBScriptCall"));
3344 }
3345 target = this.Core.GetAttributeValue(sourceLineNumbers, attrib, EmptyRule.CanBeEmpty); // one of the few cases where an empty string value is valid
3378 - //targetBits = MsiInterop.MsidbCustomActionTypeTextData;
3346 targetType = CustomActionTargetType.TextData;
3347 break;
3348 case "VBScriptCall":
@@ -3384,16 +3351,11 @@ namespace WixToolset.Core
3351 this.Core.Write(ErrorMessages.CustomActionMultipleTargets(sourceLineNumbers, node.Name.LocalName, attrib.Name.LocalName, "DllEntry", "Error", "ExeCommand", "JScriptCall", "Script", "Value", "VBScriptCall"));
3352 }
3353 target = this.Core.GetAttributeValue(sourceLineNumbers, attrib, EmptyRule.CanBeEmpty); // one of the few cases where an empty string value is valid
3387 - //targetBits = MsiInterop.MsidbCustomActionTypeVBScript;
3354 targetType = CustomActionTargetType.VBScript;
3355 break;
3356 case "Win64":
3357 explicitWin64 = true;
3358 win64 = YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib);
3393 - //if (YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib))
3394 - //{
3395 - // bits |= MsiInterop.MsidbCustomActionType64BitScript;
3396 - //}
3359 break;
3360 default:
3361 this.Core.UnexpectedAttribute(node, attrib);
@@ -3423,7 +3385,12 @@ namespace WixToolset.Core
3385 // if we have an in-lined Script CustomAction ensure no source or target attributes were provided
3386 if (inlineScript)
3387 {
3426 - target = innerText;
3388 + if (String.IsNullOrEmpty(scriptFile))
3389 + {
3390 + this.Core.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "ScriptFile", "Script"));
3391 +
3392 + target = innerText;
3393 + }
3394 }
3395 else if (CustomActionTargetType.VBScript == targetType) // non-inline vbscript
3396 {
@@ -3463,6 +3430,11 @@ namespace WixToolset.Core
3430 this.Core.Write(ErrorMessages.CustomActionIllegalInnerText(sourceLineNumbers, node.Name.LocalName, innerText, "Script"));
3431 }
3432
3433 + if (!inlineScript && !String.IsNullOrEmpty(scriptFile))
3434 + {
3435 + this.Core.Write(ErrorMessages.IllegalAttributeWithoutOtherAttributes(sourceLineNumbers, node.Name.LocalName, "ScriptFile", "Script"));
3436 + }
3437 +
3438 if (win64 && CustomActionTargetType.VBScript != targetType && CustomActionTargetType.JScript != targetType)
3439 {
3440 this.Core.Write(ErrorMessages.IllegalAttributeWithoutOtherAttributes(sourceLineNumbers, node.Name.LocalName, "Win64", "Script", "VBScriptCall", "JScriptCall"));
@@ -3515,6 +3487,7 @@ namespace WixToolset.Core
3487 TSAware = tsAware,
3488 Win64 = win64,
3489 Hidden = hidden,
3490 + ScriptFile = new IntermediateFieldPathValue { Path = scriptFile }
3491 });
3492
3493 if (YesNoType.Yes == suppressModularization)