From f18b96045088d6d989e70df19343a99092685e5e Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Mon, 22 Jun 2020 23:09:30 -0700 Subject: Move CustomAction script inner text to ScriptFile attribute --- .../Bind/BindDatabaseCommand.cs | 4 +- .../Bind/UpdateControlTextCommand.cs | 72 -------------------- .../Bind/UpdateFromTextFilesCommand.cs | 77 ++++++++++++++++++++++ src/WixToolset.Core/Compiler.cs | 61 +++++------------ 4 files changed, 96 insertions(+), 118 deletions(-) delete mode 100644 src/WixToolset.Core.WindowsInstaller/Bind/UpdateControlTextCommand.cs create mode 100644 src/WixToolset.Core.WindowsInstaller/Bind/UpdateFromTextFilesCommand.cs diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs index da92be69..ea6d49a0 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs @@ -347,9 +347,9 @@ namespace WixToolset.Core.WindowsInstaller.Bind command.Execute(); } - // Update control text from files on disk. + // Update tuples that reference text files on disk. { - var command = new UpdateControlTextCommand(this.Messaging, section); + var command = new UpdateFromTextFilesCommand(this.Messaging, section); command.Execute(); } diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/UpdateControlTextCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/UpdateControlTextCommand.cs deleted file mode 100644 index 104a3a37..00000000 --- a/src/WixToolset.Core.WindowsInstaller/Bind/UpdateControlTextCommand.cs +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. - -namespace WixToolset.Core.WindowsInstaller.Bind -{ - using System; - using System.IO; - using System.Linq; - using WixToolset.Data; - using WixToolset.Data.Tuples; - using WixToolset.Extensibility.Services; - - internal class UpdateControlTextCommand - { - public UpdateControlTextCommand(IMessaging messaging, IntermediateSection section) - { - this.Messaging = messaging; - this.Section = section; - } - - private IMessaging Messaging { get; } - - private IntermediateSection Section { get; } - - public void Execute() - { - foreach (var bbControl in this.Section.Tuples.OfType().Where(t => t.SourceFile != null)) - { - bbControl.Text = this.ReadTextFile(bbControl.SourceLineNumbers, bbControl.SourceFile.Path); - } - - foreach (var control in this.Section.Tuples.OfType().Where(t => t.SourceFile != null)) - { - control.Text = this.ReadTextFile(control.SourceLineNumbers, control.SourceFile.Path); - } - } - - /// - /// Reads a text file and returns the contents. - /// - /// Source line numbers for row from source. - /// Source path to file to read. - /// Text string read from file. - private string ReadTextFile(SourceLineNumber sourceLineNumbers, string source) - { - try - { - using (var reader = new StreamReader(source)) - { - return reader.ReadToEnd(); - } - } - catch (DirectoryNotFoundException e) - { - this.Messaging.Write(ErrorMessages.BinderFileManagerMissingFile(sourceLineNumbers, e.Message)); - } - catch (FileNotFoundException e) - { - this.Messaging.Write(ErrorMessages.BinderFileManagerMissingFile(sourceLineNumbers, e.Message)); - } - catch (IOException e) - { - this.Messaging.Write(ErrorMessages.BinderFileManagerMissingFile(sourceLineNumbers, e.Message)); - } - catch (NotSupportedException) - { - this.Messaging.Write(ErrorMessages.FileNotFound(sourceLineNumbers, source)); - } - - return null; - } - } -} diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/UpdateFromTextFilesCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/UpdateFromTextFilesCommand.cs new file mode 100644 index 00000000..4d09ff6b --- /dev/null +++ b/src/WixToolset.Core.WindowsInstaller/Bind/UpdateFromTextFilesCommand.cs @@ -0,0 +1,77 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. + +namespace WixToolset.Core.WindowsInstaller.Bind +{ + using System; + using System.IO; + using System.Linq; + using WixToolset.Data; + using WixToolset.Data.Tuples; + using WixToolset.Extensibility.Services; + + internal class UpdateFromTextFilesCommand + { + public UpdateFromTextFilesCommand(IMessaging messaging, IntermediateSection section) + { + this.Messaging = messaging; + this.Section = section; + } + + private IMessaging Messaging { get; } + + private IntermediateSection Section { get; } + + public void Execute() + { + foreach (var bbControl in this.Section.Tuples.OfType().Where(t => t.SourceFile != null)) + { + bbControl.Text = this.ReadTextFile(bbControl.SourceLineNumbers, bbControl.SourceFile.Path); + } + + foreach (var control in this.Section.Tuples.OfType().Where(t => t.SourceFile != null)) + { + control.Text = this.ReadTextFile(control.SourceLineNumbers, control.SourceFile.Path); + } + + foreach (var customAction in this.Section.Tuples.OfType().Where(c => c.ScriptFile != null)) + { + customAction.Target = this.ReadTextFile(customAction.SourceLineNumbers, customAction.ScriptFile.Path); + } + } + + /// + /// Reads a text file and returns the contents. + /// + /// Source line numbers for row from source. + /// Source path to file to read. + /// Text string read from file. + private string ReadTextFile(SourceLineNumber sourceLineNumbers, string source) + { + try + { + using (var reader = new StreamReader(source)) + { + return reader.ReadToEnd(); + } + } + catch (DirectoryNotFoundException e) + { + this.Messaging.Write(ErrorMessages.BinderFileManagerMissingFile(sourceLineNumbers, e.Message)); + } + catch (FileNotFoundException e) + { + this.Messaging.Write(ErrorMessages.BinderFileManagerMissingFile(sourceLineNumbers, e.Message)); + } + catch (IOException e) + { + this.Messaging.Write(ErrorMessages.BinderFileManagerMissingFile(sourceLineNumbers, e.Message)); + } + catch (NotSupportedException) + { + this.Messaging.Write(ErrorMessages.FileNotFound(sourceLineNumbers, source)); + } + + return null; + } + } +} diff --git a/src/WixToolset.Core/Compiler.cs b/src/WixToolset.Core/Compiler.cs index d6c96b28..358f8844 100644 --- a/src/WixToolset.Core/Compiler.cs +++ b/src/WixToolset.Core/Compiler.cs @@ -3134,6 +3134,8 @@ namespace WixToolset.Core string target = null; var explicitWin64 = false; + string scriptFile = null; + CustomActionSourceType? sourceType = null; CustomActionTargetType? targetType = null; var executionType = CustomActionExecutionType.Immediate; @@ -3160,7 +3162,6 @@ namespace WixToolset.Core this.Core.Write(ErrorMessages.CustomActionMultipleSources(sourceLineNumbers, node.Name.LocalName, attrib.Name.LocalName, "BinaryKey", "Directory", "FileKey", "Property", "Script")); } source = this.Core.GetAttributeIdentifierValue(sourceLineNumbers, attrib); - //sourceBits = MsiInterop.MsidbCustomActionTypeBinaryData; sourceType = CustomActionSourceType.Binary; this.Core.CreateSimpleReference(sourceLineNumbers, TupleDefinitions.Binary, source); // add a reference to the appropriate Binary break; @@ -3170,7 +3171,6 @@ namespace WixToolset.Core this.Core.Write(ErrorMessages.CustomActionMultipleSources(sourceLineNumbers, node.Name.LocalName, attrib.Name.LocalName, "BinaryKey", "Directory", "FileKey", "Property", "Script")); } source = this.Core.CreateDirectoryReferenceFromInlineSyntax(sourceLineNumbers, attrib, null); - //sourceBits = MsiInterop.MsidbCustomActionTypeDirectory; sourceType = CustomActionSourceType.Directory; break; case "DllEntry": @@ -3179,7 +3179,6 @@ namespace WixToolset.Core this.Core.Write(ErrorMessages.CustomActionMultipleTargets(sourceLineNumbers, node.Name.LocalName, attrib.Name.LocalName, "DllEntry", "Error", "ExeCommand", "JScriptCall", "Script", "Value", "VBScriptCall")); } target = this.Core.GetAttributeValue(sourceLineNumbers, attrib); - //targetBits = MsiInterop.MsidbCustomActionTypeDll; targetType = CustomActionTargetType.Dll; break; case "Error": @@ -3188,7 +3187,6 @@ namespace WixToolset.Core this.Core.Write(ErrorMessages.CustomActionMultipleTargets(sourceLineNumbers, node.Name.LocalName, attrib.Name.LocalName, "DllEntry", "Error", "ExeCommand", "JScriptCall", "Script", "Value", "VBScriptCall")); } target = this.Core.GetAttributeValue(sourceLineNumbers, attrib); - //targetBits = MsiInterop.MsidbCustomActionTypeTextData | MsiInterop.MsidbCustomActionTypeSourceFile; sourceType = CustomActionSourceType.File; targetType = CustomActionTargetType.TextData; @@ -3206,7 +3204,6 @@ namespace WixToolset.Core this.Core.Write(ErrorMessages.CustomActionMultipleTargets(sourceLineNumbers, node.Name.LocalName, attrib.Name.LocalName, "DllEntry", "Error", "ExeCommand", "JScriptCall", "Script", "Value", "VBScriptCall")); } target = this.Core.GetAttributeValue(sourceLineNumbers, attrib, EmptyRule.CanBeEmpty); // one of the few cases where an empty string value is valid - //targetBits = MsiInterop.MsidbCustomActionTypeExe; targetType = CustomActionTargetType.Exe; break; case "Execute": @@ -3214,30 +3211,24 @@ namespace WixToolset.Core switch (execute) { case "commit": - //bits |= MsiInterop.MsidbCustomActionTypeInScript | MsiInterop.MsidbCustomActionTypeCommit; executionType = CustomActionExecutionType.Commit; break; case "deferred": - //bits |= MsiInterop.MsidbCustomActionTypeInScript; executionType = CustomActionExecutionType.Deferred; break; case "firstSequence": - //bits |= MsiInterop.MsidbCustomActionTypeFirstSequence; executionType = CustomActionExecutionType.FirstSequence; break; case "immediate": executionType = CustomActionExecutionType.Immediate; break; case "oncePerProcess": - //bits |= MsiInterop.MsidbCustomActionTypeOncePerProcess; executionType = CustomActionExecutionType.OncePerProcess; break; case "rollback": - //bits |= MsiInterop.MsidbCustomActionTypeInScript | MsiInterop.MsidbCustomActionTypeRollback; executionType = CustomActionExecutionType.Rollback; break; case "secondSequence": - //bits |= MsiInterop.MsidbCustomActionTypeClientRepeat; executionType = CustomActionExecutionType.ClientRepeat; break; default: @@ -3251,23 +3242,14 @@ namespace WixToolset.Core this.Core.Write(ErrorMessages.CustomActionMultipleSources(sourceLineNumbers, node.Name.LocalName, attrib.Name.LocalName, "BinaryKey", "Directory", "FileKey", "Property", "Script")); } source = this.Core.GetAttributeIdentifierValue(sourceLineNumbers, attrib); - //sourceBits = MsiInterop.MsidbCustomActionTypeSourceFile; sourceType = CustomActionSourceType.File; this.Core.CreateSimpleReference(sourceLineNumbers, TupleDefinitions.File, source); // add a reference to the appropriate File break; case "HideTarget": hidden = YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib); - //if (YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib)) - //{ - // bits |= MsiInterop.MsidbCustomActionTypeHideTarget; - //} break; case "Impersonate": impersonate = YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib); - //if (YesNoType.No == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib)) - //{ - // bits |= MsiInterop.MsidbCustomActionTypeNoImpersonate; - //} break; case "JScriptCall": if (null != target) @@ -3275,15 +3257,10 @@ namespace WixToolset.Core this.Core.Write(ErrorMessages.CustomActionMultipleTargets(sourceLineNumbers, node.Name.LocalName, attrib.Name.LocalName, "DllEntry", "Error", "ExeCommand", "JScriptCall", "Script", "Value", "VBScriptCall")); } target = this.Core.GetAttributeValue(sourceLineNumbers, attrib, EmptyRule.CanBeEmpty); // one of the few cases where an empty string value is valid - //targetBits = MsiInterop.MsidbCustomActionTypeJScript; targetType = CustomActionTargetType.JScript; break; case "PatchUninstall": patchUninstall = YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib); - //if (YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib)) - //{ - // extendedBits |= MsiInterop.MsidbCustomActionTypePatchUninstall; - //} break; case "Property": if (null != source) @@ -3291,7 +3268,6 @@ namespace WixToolset.Core this.Core.Write(ErrorMessages.CustomActionMultipleSources(sourceLineNumbers, node.Name.LocalName, attrib.Name.LocalName, "BinaryKey", "Directory", "FileKey", "Property", "Script")); } source = this.Core.GetAttributeValue(sourceLineNumbers, attrib); - //sourceBits = MsiInterop.MsidbCustomActionTypeProperty; sourceType = CustomActionSourceType.Property; break; case "Return": @@ -3299,18 +3275,15 @@ namespace WixToolset.Core switch (returnValue) { case "asyncNoWait": - //bits |= MsiInterop.MsidbCustomActionTypeAsync | MsiInterop.MsidbCustomActionTypeContinue; async = true; ignoreResult = true; break; case "asyncWait": - //bits |= MsiInterop.MsidbCustomActionTypeAsync; async = true; break; case "check": break; case "ignore": - //bits |= MsiInterop.MsidbCustomActionTypeContinue; ignoreResult = true; break; case "": @@ -3341,15 +3314,11 @@ namespace WixToolset.Core switch (script) { case "jscript": - //sourceBits = MsiInterop.MsidbCustomActionTypeDirectory; sourceType = CustomActionSourceType.Directory; - //targetBits = MsiInterop.MsidbCustomActionTypeJScript; targetType = CustomActionTargetType.JScript; break; case "vbscript": - //sourceBits = MsiInterop.MsidbCustomActionTypeDirectory; sourceType = CustomActionSourceType.Directory; - //targetBits = MsiInterop.MsidbCustomActionTypeVBScript; targetType = CustomActionTargetType.VBScript; break; case "": @@ -3359,15 +3328,14 @@ namespace WixToolset.Core break; } break; + case "ScriptFile": + scriptFile = this.Core.GetAttributeValue(sourceLineNumbers, attrib); + break; case "SuppressModularization": suppressModularization = this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib); break; case "TerminalServerAware": tsAware = YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib); - //if (YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib)) - //{ - // bits |= MsiInterop.MsidbCustomActionTypeTSAware; - //} break; case "Value": if (null != target) @@ -3375,7 +3343,6 @@ namespace WixToolset.Core this.Core.Write(ErrorMessages.CustomActionMultipleTargets(sourceLineNumbers, node.Name.LocalName, attrib.Name.LocalName, "DllEntry", "Error", "ExeCommand", "JScriptCall", "Script", "Value", "VBScriptCall")); } target = this.Core.GetAttributeValue(sourceLineNumbers, attrib, EmptyRule.CanBeEmpty); // one of the few cases where an empty string value is valid - //targetBits = MsiInterop.MsidbCustomActionTypeTextData; targetType = CustomActionTargetType.TextData; break; case "VBScriptCall": @@ -3384,16 +3351,11 @@ namespace WixToolset.Core this.Core.Write(ErrorMessages.CustomActionMultipleTargets(sourceLineNumbers, node.Name.LocalName, attrib.Name.LocalName, "DllEntry", "Error", "ExeCommand", "JScriptCall", "Script", "Value", "VBScriptCall")); } target = this.Core.GetAttributeValue(sourceLineNumbers, attrib, EmptyRule.CanBeEmpty); // one of the few cases where an empty string value is valid - //targetBits = MsiInterop.MsidbCustomActionTypeVBScript; targetType = CustomActionTargetType.VBScript; break; case "Win64": explicitWin64 = true; win64 = YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib); - //if (YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib)) - //{ - // bits |= MsiInterop.MsidbCustomActionType64BitScript; - //} break; default: this.Core.UnexpectedAttribute(node, attrib); @@ -3423,7 +3385,12 @@ namespace WixToolset.Core // if we have an in-lined Script CustomAction ensure no source or target attributes were provided if (inlineScript) { - target = innerText; + if (String.IsNullOrEmpty(scriptFile)) + { + this.Core.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "ScriptFile", "Script")); + + target = innerText; + } } else if (CustomActionTargetType.VBScript == targetType) // non-inline vbscript { @@ -3463,6 +3430,11 @@ namespace WixToolset.Core this.Core.Write(ErrorMessages.CustomActionIllegalInnerText(sourceLineNumbers, node.Name.LocalName, innerText, "Script")); } + if (!inlineScript && !String.IsNullOrEmpty(scriptFile)) + { + this.Core.Write(ErrorMessages.IllegalAttributeWithoutOtherAttributes(sourceLineNumbers, node.Name.LocalName, "ScriptFile", "Script")); + } + if (win64 && CustomActionTargetType.VBScript != targetType && CustomActionTargetType.JScript != targetType) { this.Core.Write(ErrorMessages.IllegalAttributeWithoutOtherAttributes(sourceLineNumbers, node.Name.LocalName, "Win64", "Script", "VBScriptCall", "JScriptCall")); @@ -3515,6 +3487,7 @@ namespace WixToolset.Core TSAware = tsAware, Win64 = win64, Hidden = hidden, + ScriptFile = new IntermediateFieldPathValue { Path = scriptFile } }); if (YesNoType.Yes == suppressModularization) -- cgit v1.2.3-55-g6feb