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 ++++++++++++++++++++++ 3 files changed, 79 insertions(+), 74 deletions(-) delete mode 100644 src/WixToolset.Core.WindowsInstaller/Bind/UpdateControlTextCommand.cs create mode 100644 src/WixToolset.Core.WindowsInstaller/Bind/UpdateFromTextFilesCommand.cs (limited to 'src/WixToolset.Core.WindowsInstaller') 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; + } + } +} -- cgit v1.2.3-55-g6feb