From 3ccd5e439da4296d6f2b66ce47075ab20d039676 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Sun, 14 Mar 2021 07:38:48 -0700 Subject: Minimize public surface area of Core Fixes wixtoolset/issues#6374 --- .../Bind/AssignMediaCommand.cs | 36 +- .../Bind/AttachPatchTransformsCommand.cs | 9 +- .../Bind/BindDatabaseCommand.cs | 31 +- .../Bind/BindSummaryInfoCommand.cs | 15 +- .../Bind/BindTransformCommand.cs | 4 +- .../Bind/CabinetResolver.cs | 5 +- .../Bind/CabinetWorkItem.cs | 6 +- .../Bind/CalculateComponentGuids.cs | 4 +- .../Bind/CopyTransformDataCommand.cs | 630 --------------------- .../Bind/CreateCabinetsCommand.cs | 4 +- .../Bind/CreateDeltaPatchesCommand.cs | 7 +- .../Bind/CreateInstanceTransformsCommand.cs | 2 +- .../Bind/CreatePatchTransformsCommand.cs | 9 +- .../CreateWindowsInstallerDataFromIRCommand.cs | 83 +-- .../Bind/ExtractMergeModuleFilesCommand.cs | 19 +- .../Bind/GetFileFacadesCommand.cs | 21 +- .../Bind/GetFileFacadesFromTransforms.cs | 21 +- .../Bind/MergeModulesCommand.cs | 6 +- .../Bind/ModularizeCommand.cs | 12 +- .../Bind/OptimizeFileFacadesOrderCommand.cs | 11 +- .../Bind/ProcessDependencyReferencesCommand.cs | 15 +- .../Bind/ProcessUncompressedFilesCommand.cs | 15 +- .../Bind/UpdateFileFacadesCommand.cs | 12 +- .../Bind/UpdateMediaSequencesCommand.cs | 14 +- .../Bind/UpdateTransformsWithFileFacades.cs | 12 +- 25 files changed, 204 insertions(+), 799 deletions(-) delete mode 100644 src/WixToolset.Core.WindowsInstaller/Bind/CopyTransformDataCommand.cs (limited to 'src/WixToolset.Core.WindowsInstaller/Bind') diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/AssignMediaCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/AssignMediaCommand.cs index f6c61866..d7faa382 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/AssignMediaCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/AssignMediaCommand.cs @@ -6,9 +6,9 @@ namespace WixToolset.Core.WindowsInstaller.Bind using System.Collections.Generic; using System.Globalization; using System.Linq; - using WixToolset.Core.Bind; using WixToolset.Data; using WixToolset.Data.Symbols; + using WixToolset.Extensibility.Data; using WixToolset.Extensibility.Services; /// @@ -18,7 +18,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind { private const int DefaultMaximumUncompressedMediaSize = 200; // Default value is 200 MB - public AssignMediaCommand(IntermediateSection section, IMessaging messaging, IEnumerable fileFacades, bool compressed) + public AssignMediaCommand(IntermediateSection section, IMessaging messaging, IEnumerable fileFacades, bool compressed) { this.CabinetNameTemplate = "Cab{0}.cab"; this.Section = section; @@ -31,7 +31,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind private IMessaging Messaging { get; } - private IEnumerable FileFacades { get; } + private IEnumerable FileFacades { get; } private bool FilesCompressed { get; } @@ -40,13 +40,13 @@ namespace WixToolset.Core.WindowsInstaller.Bind /// /// Gets cabinets with their file rows. /// - public Dictionary> FileFacadesByCabinetMedia { get; private set; } + public Dictionary> FileFacadesByCabinetMedia { get; private set; } /// /// Get uncompressed file rows. This will contain file rows of File elements that are marked with compression=no. /// This contains all the files when Package element is marked with compression=no /// - public IEnumerable UncompressedFileFacades { get; private set; } + public IEnumerable UncompressedFileFacades { get; private set; } public void Execute() { @@ -79,34 +79,34 @@ namespace WixToolset.Core.WindowsInstaller.Bind Cabinet = "#MergeModule.CABinet", }); - this.FileFacadesByCabinetMedia = new Dictionary> + this.FileFacadesByCabinetMedia = new Dictionary> { { mergeModuleMediaSymbol, this.FileFacades } }; - this.UncompressedFileFacades = Array.Empty(); + this.UncompressedFileFacades = Array.Empty(); } else if (mediaTemplateSymbols.Count == 0) { - var filesByCabinetMedia = new Dictionary>(); + var filesByCabinetMedia = new Dictionary>(); - var uncompressedFiles = new List(); + var uncompressedFiles = new List(); this.ManuallyAssignFiles(mediaSymbols, filesByCabinetMedia, uncompressedFiles); - this.FileFacadesByCabinetMedia = filesByCabinetMedia.ToDictionary(kvp => kvp.Key, kvp => (IEnumerable)kvp.Value); + this.FileFacadesByCabinetMedia = filesByCabinetMedia.ToDictionary(kvp => kvp.Key, kvp => (IEnumerable)kvp.Value); this.UncompressedFileFacades = uncompressedFiles; } else { - var filesByCabinetMedia = new Dictionary>(); + var filesByCabinetMedia = new Dictionary>(); - var uncompressedFiles = new List(); + var uncompressedFiles = new List(); this.AutoAssignFiles(mediaSymbols, filesByCabinetMedia, uncompressedFiles); - this.FileFacadesByCabinetMedia = filesByCabinetMedia.ToDictionary(kvp => kvp.Key, kvp => (IEnumerable)kvp.Value); + this.FileFacadesByCabinetMedia = filesByCabinetMedia.ToDictionary(kvp => kvp.Key, kvp => (IEnumerable)kvp.Value); this.UncompressedFileFacades = uncompressedFiles; } @@ -115,7 +115,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind /// /// Assign files to cabinets based on MediaTemplate authoring. /// - private void AutoAssignFiles(List mediaTable, Dictionary> filesByCabinetMedia, List uncompressedFiles) + private void AutoAssignFiles(List mediaTable, Dictionary> filesByCabinetMedia, List uncompressedFiles) { const int MaxCabIndex = 999; @@ -194,7 +194,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind { currentMediaRow = this.AddMediaSymbol(mediaTemplateRow, ++currentCabIndex); mediaSymbolsByDiskId.Add(currentMediaRow.DiskId, currentMediaRow); - filesByCabinetMedia.Add(currentMediaRow, new List()); + filesByCabinetMedia.Add(currentMediaRow, new List()); // Now files larger than MaxUncompressedMediaSize will be the only file in its cabinet so as to respect MaxUncompressedMediaSize currentPreCabSize = (ulong)facade.FileSize; @@ -206,7 +206,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind // Create new cab and MediaRow currentMediaRow = this.AddMediaSymbol(mediaTemplateRow, ++currentCabIndex); mediaSymbolsByDiskId.Add(currentMediaRow.DiskId, currentMediaRow); - filesByCabinetMedia.Add(currentMediaRow, new List()); + filesByCabinetMedia.Add(currentMediaRow, new List()); } } } @@ -232,7 +232,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind /// /// Assign files to cabinets based on Media authoring. /// - private void ManuallyAssignFiles(List mediaSymbols, Dictionary> filesByCabinetMedia, List uncompressedFiles) + private void ManuallyAssignFiles(List mediaSymbols, Dictionary> filesByCabinetMedia, List uncompressedFiles) { var mediaSymbolsByDiskId = new Dictionary(); @@ -254,7 +254,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind cabinetMediaSymbols.Add(mediaSymbol.Cabinet, mediaSymbol); } - filesByCabinetMedia.Add(mediaSymbol, new List()); + filesByCabinetMedia.Add(mediaSymbol, new List()); } mediaSymbolsByDiskId.Add(mediaSymbol.DiskId, mediaSymbol); diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/AttachPatchTransformsCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/AttachPatchTransformsCommand.cs index 2249faf8..b2052b90 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/AttachPatchTransformsCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/AttachPatchTransformsCommand.cs @@ -55,16 +55,19 @@ namespace WixToolset.Core.WindowsInstaller.Bind private readonly TableDefinitionCollection tableDefinitions; - public AttachPatchTransformsCommand(IMessaging messaging, Intermediate intermediate, IEnumerable transforms) + public AttachPatchTransformsCommand(IMessaging messaging, IBackendHelper backendHelper, Intermediate intermediate, IEnumerable transforms) { this.tableDefinitions = new TableDefinitionCollection(WindowsInstallerTableDefinitions.All); this.Messaging = messaging; + this.BackendHelper = backendHelper; this.Intermediate = intermediate; this.Transforms = transforms; } private IMessaging Messaging { get; } + private IBackendHelper BackendHelper { get; } + private Intermediate Intermediate { get; } private IEnumerable Transforms { get; } @@ -797,7 +800,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind if (!deletedComponent.ContainsKey(componentId)) { var foundRemoveFileEntry = false; - var filename = Common.GetName(row.FieldAsString(2), false, true); + var filename = this.BackendHelper.GetMsiFileName(row.FieldAsString(2), false, true); if (transform.TryGetTable("RemoveFile", out var removeFileTable)) { @@ -813,7 +816,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind // Check if there is a RemoveFile entry for this file if (null != removeFileRow[2]) { - var removeFileName = Common.GetName(removeFileRow.FieldAsString(2), false, true); + var removeFileName = this.BackendHelper.GetMsiFileName(removeFileRow.FieldAsString(2), false, true); // Convert the MSI format for a wildcard string to Regex format. removeFileName = removeFileName.Replace('.', '|').Replace('?', '.').Replace("*", ".*").Replace("|", "\\."); diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs index 292f1572..b6244a6e 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs @@ -6,7 +6,6 @@ namespace WixToolset.Core.WindowsInstaller.Bind using System.Collections.Generic; using System.IO; using System.Linq; - using WixToolset.Core.Bind; using WixToolset.Data; using WixToolset.Data.Symbols; using WixToolset.Data.WindowsInstaller; @@ -133,7 +132,9 @@ namespace WixToolset.Core.WindowsInstaller.Bind Platform platform; string modularizationSuffix; { - var command = new BindSummaryInfoCommand(section); + var branding = this.ServiceProvider.GetService(); + + var command = new BindSummaryInfoCommand(section, this.WindowsInstallerBackendHelper, branding); command.Execute(); compressed = command.Compressed; @@ -151,7 +152,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind // Set the ProductCode if it is to be generated. if ("ProductCode".Equals(propertyRow.Id.Id, StringComparison.Ordinal) && "*".Equals(propertyRow.Value, StringComparison.Ordinal)) { - propertyRow.Value = Common.GenerateGuid(); + propertyRow.Value = this.WindowsInstallerBackendHelper.CreateGuid(); #if TODO_PATCHING // Is this still necessary? @@ -235,24 +236,23 @@ namespace WixToolset.Core.WindowsInstaller.Bind // Extract files that come from binary .wixlibs and WixExtensions (this does not extract files from merge modules). { - var command = new ExtractEmbeddedFilesCommand(this.WindowsInstallerBackendHelper, this.ExpectedEmbeddedFiles); - command.Execute(); + var extractedFiles = this.WindowsInstallerBackendHelper.ExtractEmbeddedFiles(this.ExpectedEmbeddedFiles); - trackedFiles.AddRange(command.TrackedFiles); + trackedFiles.AddRange(extractedFiles); } // This must occur after all variables and source paths have been resolved. - List fileFacades; + List fileFacades; if (SectionType.Patch == section.Type) { - var command = new GetFileFacadesFromTransforms(this.Messaging, this.FileSystemManager, this.SubStorages); + var command = new GetFileFacadesFromTransforms(this.Messaging, this.WindowsInstallerBackendHelper, this.FileSystemManager, this.SubStorages); command.Execute(); fileFacades = command.FileFacades; } else { - var command = new GetFileFacadesCommand(section); + var command = new GetFileFacadesCommand(section, this.WindowsInstallerBackendHelper); command.Execute(); fileFacades = command.FileFacades; @@ -267,7 +267,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind { containsMergeModules = true; - var command = new ExtractMergeModuleFilesCommand(this.Messaging, wixMergeSymbols, fileFacades, installerVersion, this.IntermediateFolder, this.SuppressLayout); + var command = new ExtractMergeModuleFilesCommand(this.Messaging, this.WindowsInstallerBackendHelper, wixMergeSymbols, fileFacades, installerVersion, this.IntermediateFolder, this.SuppressLayout); command.Execute(); fileFacades.AddRange(command.MergeModulesFileFacades); @@ -307,8 +307,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind // Now that the variable cache is populated, resolve any delayed fields. if (this.DelayedFields.Any()) { - var command = new ResolveDelayedFieldsCommand(this.Messaging, this.DelayedFields, variableCache); - command.Execute(); + this.WindowsInstallerBackendHelper.ResolveDelayedFields(this.DelayedFields, variableCache); } // Update symbols that reference text files on disk. @@ -330,7 +329,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind if (dependencyRefs.Any()) { - var command = new ProcessDependencyReferencesCommand(section, dependencyRefs); + var command = new ProcessDependencyReferencesCommand(this.WindowsInstallerBackendHelper, section, dependencyRefs); command.Execute(); } } @@ -379,8 +378,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind } // Assign files to media and update file sequences. - Dictionary> filesByCabinetMedia; - IEnumerable uncompressedFiles; + Dictionary> filesByCabinetMedia; + IEnumerable uncompressedFiles; { var order = new OptimizeFileFacadesOrderCommand(this.WindowsInstallerBackendHelper, this.PathResolver, section, platform, fileFacades); order.Execute(); @@ -414,7 +413,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind if (data.Type == OutputType.Module) { // Modularize identifiers. - var modularize = new ModularizeCommand(data, modularizationSuffix, section.Symbols.OfType()); + var modularize = new ModularizeCommand(this.WindowsInstallerBackendHelper, data, modularizationSuffix, section.Symbols.OfType()); modularize.Execute(); // Ensure all sequence tables in place because, mergemod.dll requires them. diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/BindSummaryInfoCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/BindSummaryInfoCommand.cs index a496c7ce..babe0c1b 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/BindSummaryInfoCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/BindSummaryInfoCommand.cs @@ -7,19 +7,26 @@ namespace WixToolset.Core.WindowsInstaller.Bind using System.Linq; using WixToolset.Data; using WixToolset.Data.Symbols; + using WixToolset.Extensibility.Services; /// /// Binds the summary information table of a database. /// internal class BindSummaryInfoCommand { - public BindSummaryInfoCommand(IntermediateSection section) + public BindSummaryInfoCommand(IntermediateSection section, IBackendHelper backendHelper, IWixBranding branding) { this.Section = section; + this.BackendHelper = backendHelper; + this.Branding = branding; } private IntermediateSection Section { get; } + private IBackendHelper BackendHelper { get; } + + private IWixBranding Branding { get; } + /// /// Returns a flag indicating if files are compressed by default. /// @@ -66,7 +73,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind } else { - summaryInformationSymbol.Value = Common.GetValidCodePage(codepage, false, false, summaryInformationSymbol.SourceLineNumbers).ToString(CultureInfo.InvariantCulture); + summaryInformationSymbol.Value = this.BackendHelper.GetValidCodePage(codepage, false, false, summaryInformationSymbol.SourceLineNumbers).ToString(CultureInfo.InvariantCulture); } break; case SummaryInformationType.PlatformAndLanguage: @@ -116,7 +123,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind this.Section.AddSymbol(new SummaryInformationSymbol(null) { PropertyId = SummaryInformationType.PackageCode, - Value = Common.GenerateGuid(), + Value = this.BackendHelper.CreateGuid(), }); } @@ -146,7 +153,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind this.Section.AddSymbol(new SummaryInformationSymbol(null) { PropertyId = SummaryInformationType.CreatingApplication, - Value = String.Format(CultureInfo.InvariantCulture, AppCommon.GetCreatingApplicationString()), + Value = this.Branding.GetCreatingApplication(), }); } } diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/BindTransformCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/BindTransformCommand.cs index bc5c6853..28e1d9ee 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/BindTransformCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/BindTransformCommand.cs @@ -99,7 +99,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind } else { - codePage = Common.GetValidCodePage(codePage).ToString(CultureInfo.InvariantCulture); + codePage = this.BackendHelper.GetValidCodePage(codePage).ToString(CultureInfo.InvariantCulture); } var previousCodePage = row.Fields[1].PreviousData; @@ -109,7 +109,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind } else { - previousCodePage = Common.GetValidCodePage(previousCodePage).ToString(CultureInfo.InvariantCulture); + previousCodePage = this.BackendHelper.GetValidCodePage(previousCodePage).ToString(CultureInfo.InvariantCulture); } var targetCodePageRow = targetSummaryInfo.CreateRow(null); diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/CabinetResolver.cs b/src/WixToolset.Core.WindowsInstaller/Bind/CabinetResolver.cs index 6dbcb1a1..e47e5b64 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/CabinetResolver.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/CabinetResolver.cs @@ -6,7 +6,6 @@ namespace WixToolset.Core.WindowsInstaller.Bind using System.Collections.Generic; using System.IO; using System.Linq; - using WixToolset.Core.Bind; using WixToolset.Core.Native; using WixToolset.Data; using WixToolset.Extensibility; @@ -30,7 +29,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind private IEnumerable BackendExtensions { get; } - public IResolvedCabinet ResolveCabinet(string cabinetPath, IEnumerable fileFacades) + public IResolvedCabinet ResolveCabinet(string cabinetPath, IEnumerable fileFacades) { var filesWithPath = fileFacades.Select(this.CreateBindFileWithPath).ToList(); @@ -109,7 +108,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind return resolved; } - private IBindFileWithPath CreateBindFileWithPath(FileFacade facade) + private IBindFileWithPath CreateBindFileWithPath(IFileFacade facade) { var result = this.ServiceProvider.GetService(); result.Id = facade.Id; diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/CabinetWorkItem.cs b/src/WixToolset.Core.WindowsInstaller/Bind/CabinetWorkItem.cs index 48f0574e..1990ea78 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/CabinetWorkItem.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/CabinetWorkItem.cs @@ -3,8 +3,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind { using System.Collections.Generic; - using WixToolset.Core.Bind; using WixToolset.Data; + using WixToolset.Extensibility.Data; /// /// A cabinet builder work item. @@ -20,7 +20,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind /// The compression level of the cabinet. /// Modularization suffix used when building a Merge Module. /// - public CabinetWorkItem(IEnumerable fileFacades, string cabinetFile, int maxThreshold, CompressionLevel compressionLevel, string modularizationSuffix /*, BinderFileManager binderFileManager*/) + public CabinetWorkItem(IEnumerable fileFacades, string cabinetFile, int maxThreshold, CompressionLevel compressionLevel, string modularizationSuffix /*, BinderFileManager binderFileManager*/) { this.CabinetFile = cabinetFile; this.CompressionLevel = compressionLevel; @@ -51,7 +51,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind /// Gets the collection of files in this cabinet. /// /// The collection of files in this cabinet. - public IEnumerable FileFacades { get; } + public IEnumerable FileFacades { get; } // // Gets the binder file manager. diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/CalculateComponentGuids.cs b/src/WixToolset.Core.WindowsInstaller/Bind/CalculateComponentGuids.cs index 55cda9ea..5cb297e5 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/CalculateComponentGuids.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/CalculateComponentGuids.cs @@ -138,8 +138,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind if (fileRow.Id.Id == componentSymbol.KeyPath) { // calculate the key file's canonical target path - string directoryPath = this.PathResolver.GetCanonicalDirectoryPath(targetPathsByDirectoryId, componentIdGenSeeds, componentSymbol.DirectoryRef, this.Platform); - string fileName = Common.GetName(fileRow.Name, false, true).ToLowerInvariant(); + var directoryPath = this.PathResolver.GetCanonicalDirectoryPath(targetPathsByDirectoryId, componentIdGenSeeds, componentSymbol.DirectoryRef, this.Platform); + var fileName = this.BackendHelper.GetMsiFileName(fileRow.Name, false, true).ToLowerInvariant(); path = Path.Combine(directoryPath, fileName); // find paths that are not canonicalized diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/CopyTransformDataCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/CopyTransformDataCommand.cs deleted file mode 100644 index 8a85a975..00000000 --- a/src/WixToolset.Core.WindowsInstaller/Bind/CopyTransformDataCommand.cs +++ /dev/null @@ -1,630 +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. - -#if DELETE - -namespace WixToolset.Core.WindowsInstaller.Bind -{ - using System; - using System.Collections.Generic; - using System.Diagnostics; - using System.IO; - using System.Linq; - using WixToolset.Core.Bind; - using WixToolset.Data; - using WixToolset.Data.Symbols; - using WixToolset.Data.WindowsInstaller; - using WixToolset.Data.WindowsInstaller.Rows; - using WixToolset.Extensibility; - using WixToolset.Extensibility.Services; - - internal class CopyTransformDataCommand - { - public CopyTransformDataCommand(IMessaging messaging, WindowsInstallerData output, TableDefinitionCollection tableDefinitions, bool copyOutFileRows) - { - this.Messaging = messaging; - this.Output = output; - this.TableDefinitions = tableDefinitions; - this.CopyOutFileRows = copyOutFileRows; - } - - private bool CopyOutFileRows { get; } - - public IEnumerable Extensions { get; } - - private IMessaging Messaging { get; } - - private WindowsInstallerData Output { get; } - - private TableDefinitionCollection TableDefinitions { get; } - - public IEnumerable FileFacades { get; private set; } - - public void Execute() - { - Debug.Assert(OutputType.Patch != this.Output.Type); - - var allFileRows = this.CopyOutFileRows ? new List() : null; - - var copyToPatch = (allFileRows != null); - var copyFromPatch = !copyToPatch; - - var patchMediaRows = new RowDictionary(); - - var patchMediaFileRows = new Dictionary>(); - - var patchActualFileTable = this.Output.EnsureTable(this.TableDefinitions["File"]); - var patchFileTable = this.Output.EnsureTable(this.TableDefinitions["WixFile"]); - - if (copyFromPatch) - { - // index patch files by diskId+fileId - foreach (WixFileRow patchFileRow in patchFileTable.Rows) - { - int diskId = patchFileRow.DiskId; - if (!patchMediaFileRows.TryGetValue(diskId, out var mediaFileRows)) - { - mediaFileRows = new RowDictionary(); - patchMediaFileRows.Add(diskId, mediaFileRows); - } - - mediaFileRows.Add(patchFileRow); - } - - var patchMediaTable = this.Output.EnsureTable(this.TableDefinitions["Media"]); - patchMediaRows = new RowDictionary(patchMediaTable); - } - - // Index paired transforms by name without the "#" prefix. - var pairedTransforms = this.Output.SubStorages.Where(s => s.Name.StartsWith("#")).ToDictionary(s => s.Name.Substring(1), s => s.Data); - //Dictionary pairedTransforms = new Dictionary(); - //foreach (SubStorage substorage in this.Output.SubStorages) - //{ - // if (substorage.Name.StartsWith("#")) - // { - // pairedTransforms.Add(substorage.Name.Substring(1), substorage.Data); - // } - //} - - try - { - // Copy File bind data into substorages - foreach (var substorage in this.Output.SubStorages) - { - if (substorage.Name.StartsWith("#")) - { - // no changes necessary for paired transforms - continue; - } - - var mainTransform = substorage.Data; - var mainWixFileTable = mainTransform.Tables["WixFile"]; - var mainMsiFileHashTable = mainTransform.Tables["MsiFileHash"]; - - this.FileManagerCore.ActiveSubStorage = substorage; - - var mainWixFiles = new RowDictionary(mainWixFileTable); - var mainMsiFileHashIndex = new RowDictionary(); - - var mainFileTable = mainTransform.Tables["File"]; - var pairedTransform = pairedTransforms[substorage.Name]; - - // copy Media.LastSequence and index the MsiFileHash table if it exists. - if (copyFromPatch) - { - var pairedMediaTable = pairedTransform.Tables["Media"]; - foreach (MediaRow pairedMediaRow in pairedMediaTable.Rows) - { - var patchMediaRow = patchMediaRows.Get(pairedMediaRow.DiskId); - pairedMediaRow.Fields[1] = patchMediaRow.Fields[1]; - } - - if (null != mainMsiFileHashTable) - { - mainMsiFileHashIndex = new RowDictionary(mainMsiFileHashTable); - } - - // Validate file row changes for keypath-related issues - this.ValidateFileRowChanges(mainTransform); - } - - // Index File table of pairedTransform - var pairedFileTable = pairedTransform.Tables["File"]; - var pairedFileRows = new RowDictionary(pairedFileTable); - - if (null != mainFileTable) - { - if (copyFromPatch) - { - // Remove the MsiFileHash table because it will be updated later with the final file hash for each file - mainTransform.Tables.Remove("MsiFileHash"); - } - - foreach (FileRow mainFileRow in mainFileTable.Rows) - { - if (RowOperation.Delete == mainFileRow.Operation) - { - continue; - } - else if (RowOperation.None == mainFileRow.Operation && !copyToPatch) - { - continue; - } - - var mainWixFileRow = mainWixFiles.Get(mainFileRow.File); - - if (copyToPatch) // when copying to the patch, we need compare the underlying files and include all file changes. - { - var objectField = (ObjectField)mainWixFileRow.Fields[6]; - var pairedFileRow = pairedFileRows.Get(mainFileRow.File); - - // If the file is new, we always need to add it to the patch. - if (mainFileRow.Operation != RowOperation.Add) - { - // If PreviousData doesn't exist, target and upgrade layout point to the same location. No need to compare. - if (null == objectField.PreviousData) - { - if (mainFileRow.Operation == RowOperation.None) - { - continue; - } - } - else - { - // TODO: should this entire condition be placed in the binder file manager? - if ((0 == (PatchAttributeType.Ignore & mainWixFileRow.PatchAttributes)) && - !this.CompareFiles(objectField.PreviousData.ToString(), objectField.Data.ToString())) - { - // If the file is different, we need to mark the mainFileRow and pairedFileRow as modified. - mainFileRow.Operation = RowOperation.Modify; - if (null != pairedFileRow) - { - // Always patch-added, but never non-compressed. - pairedFileRow.Attributes |= WindowsInstallerConstants.MsidbFileAttributesPatchAdded; - pairedFileRow.Attributes &= ~WindowsInstallerConstants.MsidbFileAttributesNoncompressed; - pairedFileRow.Fields[6].Modified = true; - pairedFileRow.Operation = RowOperation.Modify; - } - } - else - { - // The File is same. We need mark all the attributes as unchanged. - mainFileRow.Operation = RowOperation.None; - foreach (var field in mainFileRow.Fields) - { - field.Modified = false; - } - - if (null != pairedFileRow) - { - pairedFileRow.Attributes &= ~WindowsInstallerConstants.MsidbFileAttributesPatchAdded; - pairedFileRow.Fields[6].Modified = false; - pairedFileRow.Operation = RowOperation.None; - } - continue; - } - } - } - else if (null != pairedFileRow) // RowOperation.Add - { - // Always patch-added, but never non-compressed. - pairedFileRow.Attributes |= WindowsInstallerConstants.MsidbFileAttributesPatchAdded; - pairedFileRow.Attributes &= ~WindowsInstallerConstants.MsidbFileAttributesNoncompressed; - pairedFileRow.Fields[6].Modified = true; - pairedFileRow.Operation = RowOperation.Add; - } - } - - // index patch files by diskId+fileId - int diskId = mainWixFileRow.DiskId; - - if (!patchMediaFileRows.TryGetValue(diskId, out var mediaFileRows)) - { - mediaFileRows = new RowDictionary(); - patchMediaFileRows.Add(diskId, mediaFileRows); - } - - var fileId = mainFileRow.File; - var patchFileRow = mediaFileRows.Get(fileId); - if (copyToPatch) - { - if (null == patchFileRow) - { - var patchActualFileRow = (FileRow)patchFileTable.CreateRow(mainFileRow.SourceLineNumbers); - patchActualFileRow.CopyFrom(mainFileRow); - - patchFileRow = (WixFileRow)patchFileTable.CreateRow(mainFileRow.SourceLineNumbers); - patchFileRow.CopyFrom(mainWixFileRow); - - mediaFileRows.Add(patchFileRow); - - allFileRows.Add(new FileFacade(patchActualFileRow, patchFileRow, null)); // TODO: should we be passing along delta information? Probably, right? - } - else - { - // TODO: confirm the rest of data is identical? - - // make sure Source is same. Otherwise we are silently ignoring a file. - if (0 != String.Compare(patchFileRow.Source, mainWixFileRow.Source, StringComparison.OrdinalIgnoreCase)) - { - this.Messaging.Write(ErrorMessages.SameFileIdDifferentSource(mainFileRow.SourceLineNumbers, fileId, patchFileRow.Source, mainWixFileRow.Source)); - } - - // capture the previous file versions (and associated data) from this targeted instance of the baseline into the current filerow. - patchFileRow.AppendPreviousDataFrom(mainWixFileRow); - } - } - else - { - // copy data from the patch back to the transform - if (null != patchFileRow) - { - var pairedFileRow = pairedFileRows.Get(fileId); - for (var i = 0; i < patchFileRow.Fields.Length; i++) - { - var patchValue = patchFileRow[i] == null ? String.Empty : patchFileRow.FieldAsString(i); - var mainValue = mainFileRow[i] == null ? String.Empty : mainFileRow.FieldAsString(i); - - if (1 == i) - { - // File.Component_ changes should not come from the shared file rows - // that contain the file information as each individual transform might - // have different changes (or no changes at all). - } - // File.Attributes should not changed for binary deltas - else if (6 == i) - { - if (null != patchFileRow.Patch) - { - // File.Attribute should not change for binary deltas - pairedFileRow.Attributes = mainFileRow.Attributes; - mainFileRow.Fields[i].Modified = false; - } - } - // File.Sequence is updated in pairedTransform, not mainTransform - else if (7 == i) - { - // file sequence is updated in Patch table instead of File table for delta patches - if (null != patchFileRow.Patch) - { - pairedFileRow.Fields[i].Modified = false; - } - else - { - pairedFileRow[i] = patchFileRow[i]; - pairedFileRow.Fields[i].Modified = true; - } - mainFileRow.Fields[i].Modified = false; - } - else if (patchValue != mainValue) - { - mainFileRow[i] = patchFileRow[i]; - mainFileRow.Fields[i].Modified = true; - if (mainFileRow.Operation == RowOperation.None) - { - mainFileRow.Operation = RowOperation.Modify; - } - } - } - - // copy MsiFileHash row for this File - if (!mainMsiFileHashIndex.TryGetValue(patchFileRow.File, out var patchHashRow)) - { - patchHashRow = patchFileRow.Hash; - } - - if (null != patchHashRow) - { - var mainHashTable = mainTransform.EnsureTable(this.TableDefinitions["MsiFileHash"]); - var mainHashRow = mainHashTable.CreateRow(mainFileRow.SourceLineNumbers); - for (var i = 0; i < patchHashRow.Fields.Length; i++) - { - mainHashRow[i] = patchHashRow[i]; - if (i > 1) - { - // assume all hash fields have been modified - mainHashRow.Fields[i].Modified = true; - } - } - - // assume the MsiFileHash operation follows the File one - mainHashRow.Operation = mainFileRow.Operation; - } - - // copy MsiAssemblyName rows for this File - List patchAssemblyNameRows = patchFileRow.AssemblyNames; - if (null != patchAssemblyNameRows) - { - var mainAssemblyNameTable = mainTransform.EnsureTable(this.TableDefinitions["MsiAssemblyName"]); - foreach (var patchAssemblyNameRow in patchAssemblyNameRows) - { - // Copy if there isn't an identical modified/added row already in the transform. - var foundMatchingModifiedRow = false; - foreach (var mainAssemblyNameRow in mainAssemblyNameTable.Rows) - { - if (RowOperation.None != mainAssemblyNameRow.Operation && mainAssemblyNameRow.GetPrimaryKey('/').Equals(patchAssemblyNameRow.GetPrimaryKey('/'))) - { - foundMatchingModifiedRow = true; - break; - } - } - - if (!foundMatchingModifiedRow) - { - var mainAssemblyNameRow = mainAssemblyNameTable.CreateRow(mainFileRow.SourceLineNumbers); - for (var i = 0; i < patchAssemblyNameRow.Fields.Length; i++) - { - mainAssemblyNameRow[i] = patchAssemblyNameRow[i]; - } - - // assume value field has been modified - mainAssemblyNameRow.Fields[2].Modified = true; - mainAssemblyNameRow.Operation = mainFileRow.Operation; - } - } - } - - // Add patch header for this file - if (null != patchFileRow.Patch) - { - // Add the PatchFiles action automatically to the AdminExecuteSequence and InstallExecuteSequence tables. - this.AddPatchFilesActionToSequenceTable(SequenceTable.AdminExecuteSequence, mainTransform, pairedTransform, mainFileRow); - this.AddPatchFilesActionToSequenceTable(SequenceTable.InstallExecuteSequence, mainTransform, pairedTransform, mainFileRow); - - // Add to Patch table - var patchTable = pairedTransform.EnsureTable(this.TableDefinitions["Patch"]); - if (0 == patchTable.Rows.Count) - { - patchTable.Operation = TableOperation.Add; - } - - var patchRow = patchTable.CreateRow(mainFileRow.SourceLineNumbers); - patchRow[0] = patchFileRow.File; - patchRow[1] = patchFileRow.Sequence; - - var patchFile = new FileInfo(patchFileRow.Source); - patchRow[2] = (int)patchFile.Length; - patchRow[3] = 0 == (PatchAttributeType.AllowIgnoreOnError & patchFileRow.PatchAttributes) ? 0 : 1; - - var streamName = patchTable.Name + "." + patchRow[0] + "." + patchRow[1]; - if (Msi.MsiInterop.MsiMaxStreamNameLength < streamName.Length) - { - streamName = "_" + Guid.NewGuid().ToString("D").ToUpperInvariant().Replace('-', '_'); - - var patchHeadersTable = pairedTransform.EnsureTable(this.TableDefinitions["MsiPatchHeaders"]); - if (0 == patchHeadersTable.Rows.Count) - { - patchHeadersTable.Operation = TableOperation.Add; - } - - var patchHeadersRow = patchHeadersTable.CreateRow(mainFileRow.SourceLineNumbers); - patchHeadersRow[0] = streamName; - patchHeadersRow[1] = patchFileRow.Patch; - patchRow[5] = streamName; - patchHeadersRow.Operation = RowOperation.Add; - } - else - { - patchRow[4] = patchFileRow.Patch; - } - patchRow.Operation = RowOperation.Add; - } - } - else - { - // TODO: throw because all transform rows should have made it into the patch - } - } - } - } - - if (copyFromPatch) - { - this.Output.Tables.Remove("Media"); - this.Output.Tables.Remove("File"); - this.Output.Tables.Remove("MsiFileHash"); - this.Output.Tables.Remove("MsiAssemblyName"); - } - } - } - finally - { - this.FileManagerCore.ActiveSubStorage = null; - } - - this.FileFacades = allFileRows; - } - - /// - /// Adds the PatchFiles action to the sequence table if it does not already exist. - /// - /// The sequence table to check or modify. - /// The primary authoring transform. - /// The secondary patch transform. - /// The file row that contains information about the patched file. - private void AddPatchFilesActionToSequenceTable(SequenceTable table, WindowsInstallerData mainTransform, WindowsInstallerData pairedTransform, Row mainFileRow) - { - var tableName = table.ToString(); - - // Find/add PatchFiles action (also determine sequence for it). - // Search mainTransform first, then pairedTransform (pairedTransform overrides). - var hasPatchFilesAction = false; - var installFilesSequence = 0; - var duplicateFilesSequence = 0; - - TestSequenceTableForPatchFilesAction( - mainTransform.Tables[tableName], - ref hasPatchFilesAction, - ref installFilesSequence, - ref duplicateFilesSequence); - TestSequenceTableForPatchFilesAction( - pairedTransform.Tables[tableName], - ref hasPatchFilesAction, - ref installFilesSequence, - ref duplicateFilesSequence); - if (!hasPatchFilesAction) - { - WindowsInstallerStandard.TryGetStandardAction(tableName, "PatchFiles", out var patchFilesActionSymbol); - - var sequence = patchFilesActionSymbol.Sequence; - - // Test for default sequence value's appropriateness - if (installFilesSequence >= sequence || (0 != duplicateFilesSequence && duplicateFilesSequence <= sequence)) - { - if (0 != duplicateFilesSequence) - { - if (duplicateFilesSequence < installFilesSequence) - { - throw new WixException(ErrorMessages.InsertInvalidSequenceActionOrder(mainFileRow.SourceLineNumbers, tableName, "InstallFiles", "DuplicateFiles", patchFilesActionSymbol.Action)); - } - else - { - sequence = (duplicateFilesSequence + installFilesSequence) / 2; - if (installFilesSequence == sequence || duplicateFilesSequence == sequence) - { - throw new WixException(ErrorMessages.InsertSequenceNoSpace(mainFileRow.SourceLineNumbers, tableName, "InstallFiles", "DuplicateFiles", patchFilesActionSymbol.Action)); - } - } - } - else - { - sequence = installFilesSequence + 1; - } - } - - var sequenceTable = pairedTransform.EnsureTable(this.TableDefinitions[tableName]); - if (0 == sequenceTable.Rows.Count) - { - sequenceTable.Operation = TableOperation.Add; - } - - var patchAction = sequenceTable.CreateRow(null); - patchAction[0] = patchFilesActionSymbol.Action; - patchAction[1] = patchFilesActionSymbol.Condition; - patchAction[2] = sequence; - patchAction.Operation = RowOperation.Add; - } - } - - /// - /// Tests sequence table for PatchFiles and associated actions - /// - /// The table to test. - /// Set to true if PatchFiles action is found. Left unchanged otherwise. - /// Set to sequence value of InstallFiles action if found. Left unchanged otherwise. - /// Set to sequence value of DuplicateFiles action if found. Left unchanged otherwise. - private static void TestSequenceTableForPatchFilesAction(Table sequenceTable, ref bool hasPatchFilesAction, ref int installFilesSequence, ref int duplicateFilesSequence) - { - if (null != sequenceTable) - { - foreach (var row in sequenceTable.Rows) - { - var actionName = row.FieldAsString(0); - switch (actionName) - { - case "PatchFiles": - hasPatchFilesAction = true; - break; - - case "InstallFiles": - installFilesSequence = row.FieldAsInteger(2); - break; - - case "DuplicateFiles": - duplicateFilesSequence = row.FieldAsInteger(2); - break; - } - } - } - } - - /// - /// Signal a warning if a non-keypath file was changed in a patch without also changing the keypath file of the component. - /// - /// The output to validate. - private void ValidateFileRowChanges(WindowsInstallerData transform) - { - var componentTable = transform.Tables["Component"]; - var fileTable = transform.Tables["File"]; - - // There's no sense validating keypaths if the transform has no component or file table - if (componentTable == null || fileTable == null) - { - return; - } - - var componentKeyPath = new Dictionary(componentTable.Rows.Count); - - // Index the Component table for non-directory & non-registry key paths. - foreach (var row in componentTable.Rows) - { - var keyPath = row.FieldAsString(5); - if (keyPath != null && 0 != (row.FieldAsInteger(3) & WindowsInstallerConstants.MsidbComponentAttributesRegistryKeyPath)) - { - componentKeyPath.Add(row.FieldAsString(0), keyPath); - } - } - - var componentWithChangedKeyPath = new Dictionary(); - var componentWithNonKeyPathChanged = new Dictionary(); - // Verify changes in the file table, now that file diffing has occurred - foreach (FileRow row in fileTable.Rows) - { - if (RowOperation.Modify != row.Operation) - { - continue; - } - - var fileId = row.FieldAsString(0); - var componentId = row.FieldAsString(1); - - // If this file is the keypath of a component - if (componentKeyPath.ContainsValue(fileId)) - { - if (!componentWithChangedKeyPath.ContainsKey(componentId)) - { - componentWithChangedKeyPath.Add(componentId, fileId); - } - } - else - { - if (!componentWithNonKeyPathChanged.ContainsKey(componentId)) - { - componentWithNonKeyPathChanged.Add(componentId, fileId); - } - } - } - - foreach (var componentFile in componentWithNonKeyPathChanged) - { - // Make sure all changes to non keypath files also had a change in the keypath. - if (!componentWithChangedKeyPath.ContainsKey(componentFile.Key) && componentKeyPath.TryGetValue(componentFile.Key, out var keyPath)) - { - this.Messaging.Write(WarningMessages.UpdateOfNonKeyPathFile(componentFile.Value, componentFile.Key, keyPath)); - } - } - } - - private bool CompareFiles(string targetFile, string updatedFile) - { - bool? compared = null; - foreach (var extension in this.Extensions) - { - compared = extension.CompareFiles(targetFile, updatedFile); - - if (compared.HasValue) - { - break; - } - } - - if (!compared.HasValue) - { - throw new InvalidOperationException(); // TODO: something needs to be said here that none of the binder file managers returned a result. - } - - return compared.Value; - } - } -} - -#endif diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs index 9f94b2c7..0a543650 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs @@ -80,7 +80,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind public string ModularizationSuffix { private get; set; } - public Dictionary> FileFacadesByCabinet { private get; set; } + public Dictionary> FileFacadesByCabinet { private get; set; } public Func ResolveMedia { private get; set; } @@ -177,7 +177,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind /// Desired compression level. /// Collection of files in this cabinet. /// created CabinetWorkItem object - private CabinetWorkItem CreateCabinetWorkItem(WindowsInstallerData data, string cabinetDir, MediaSymbol mediaSymbol, CompressionLevel compressionLevel, IEnumerable fileFacades) + private CabinetWorkItem CreateCabinetWorkItem(WindowsInstallerData data, string cabinetDir, MediaSymbol mediaSymbol, CompressionLevel compressionLevel, IEnumerable fileFacades) { CabinetWorkItem cabinetWorkItem = null; var tempCabinetFileX = Path.Combine(this.IntermediateFolder, mediaSymbol.Cabinet); diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/CreateDeltaPatchesCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/CreateDeltaPatchesCommand.cs index 93ac50ff..640322e6 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/CreateDeltaPatchesCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/CreateDeltaPatchesCommand.cs @@ -9,20 +9,21 @@ namespace WixToolset.Core.WindowsInstaller.Bind using WixToolset.Core.Bind; using WixToolset.Data; using WixToolset.Data.Symbols; + using WixToolset.Extensibility.Data; /// /// Creates delta patches and updates the appropriate rows to point to the newly generated patches. /// internal class CreateDeltaPatchesCommand { - public CreateDeltaPatchesCommand(List fileFacades, string intermediateFolder, WixPatchIdSymbol wixPatchId) + public CreateDeltaPatchesCommand(List fileFacades, string intermediateFolder, WixPatchIdSymbol wixPatchId) { this.FileFacades = fileFacades; this.IntermediateFolder = intermediateFolder; this.WixPatchId = wixPatchId; } - private IEnumerable FileFacades { get; } + private IEnumerable FileFacades { get; } private WixPatchIdSymbol WixPatchId { get; } @@ -31,7 +32,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind public void Execute() { var optimizePatchSizeForLargeFiles = this.WixPatchId?.OptimizePatchSizeForLargeFiles ?? false; - var apiPatchingSymbolFlags = (PatchSymbolFlagsType)(this.WixPatchId?.ApiPatchingSymbolFlags ?? 0); + var apiPatchingSymbolFlags = (PatchSymbolFlags)(this.WixPatchId?.ApiPatchingSymbolFlags ?? 0); #if TODO_PATCHING_DELTA foreach (FileFacade facade in this.FileFacades) diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/CreateInstanceTransformsCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/CreateInstanceTransformsCommand.cs index 33afca77..9a631754 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/CreateInstanceTransformsCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/CreateInstanceTransformsCommand.cs @@ -110,7 +110,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind var productCode = instanceSymbol.ProductCode; if ("*" == productCode) { - productCode = Common.GenerateGuid(); + productCode = this.BackendHelper.CreateGuid(); } var productCodeRow = propertyTable.CreateRow(instanceSymbol.SourceLineNumbers); diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/CreatePatchTransformsCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/CreatePatchTransformsCommand.cs index 76e6dd56..7bc1a8bd 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/CreatePatchTransformsCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/CreatePatchTransformsCommand.cs @@ -15,15 +15,18 @@ namespace WixToolset.Core.WindowsInstaller.Bind internal class CreatePatchTransformsCommand { - public CreatePatchTransformsCommand(IMessaging messaging, Intermediate intermediate, string intermediateFolder) + public CreatePatchTransformsCommand(IMessaging messaging, IBackendHelper backendHelper, Intermediate intermediate, string intermediateFolder) { this.Messaging = messaging; + this.BackendHelper = backendHelper; this.Intermediate = intermediate; this.IntermediateFolder = intermediateFolder; } private IMessaging Messaging { get; } + private IBackendHelper BackendHelper { get; } + private Intermediate Intermediate { get; } private string IntermediateFolder { get; } @@ -52,7 +55,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind { var exportBasePath = Path.Combine(this.IntermediateFolder, "_trans"); // TODO: come up with a better path. - var command = new UnbindTransformCommand(this.Messaging, symbol.TransformFile.Path, exportBasePath, this.IntermediateFolder); + var command = new UnbindTransformCommand(this.Messaging, this.BackendHelper, symbol.TransformFile.Path, exportBasePath, this.IntermediateFolder); transform = command.Execute(); } @@ -76,7 +79,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind var isAdminImage = false; // TODO: need a better way to set this - var command = new UnbindDatabaseCommand(this.Messaging, database, path, OutputType.Product, exportBasePath, this.IntermediateFolder, isAdminImage, suppressDemodularization: true, skipSummaryInfo: true); + var command = new UnbindDatabaseCommand(this.Messaging, this.BackendHelper, database, path, OutputType.Product, exportBasePath, this.IntermediateFolder, isAdminImage, suppressDemodularization: true, skipSummaryInfo: true); return command.Execute(); } } diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/CreateWindowsInstallerDataFromIRCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/CreateWindowsInstallerDataFromIRCommand.cs index 9ec26964..0ce67591 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/CreateWindowsInstallerDataFromIRCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/CreateWindowsInstallerDataFromIRCommand.cs @@ -481,18 +481,18 @@ namespace WixToolset.Core.WindowsInstaller.Bind private void AddDirectorySymbol(DirectorySymbol symbol) { - if (String.IsNullOrEmpty(symbol.ShortName) && symbol.Name != null && !symbol.Name.Equals(".") && !symbol.Name.Equals("SourceDir") && !Common.IsValidShortFilename(symbol.Name, false)) + if (String.IsNullOrEmpty(symbol.ShortName) && symbol.Name != null && !symbol.Name.Equals(".") && !symbol.Name.Equals("SourceDir") && !this.BackendHelper.IsValidShortFilename(symbol.Name, false)) { - symbol.ShortName = CreateShortName(symbol.Name, false, false, "Directory", symbol.ParentDirectoryRef); + symbol.ShortName = this.CreateShortName(symbol.Name, false, "Directory", symbol.ParentDirectoryRef); } - if (String.IsNullOrEmpty(symbol.SourceShortName) && !String.IsNullOrEmpty(symbol.SourceName) && !Common.IsValidShortFilename(symbol.SourceName, false)) + if (String.IsNullOrEmpty(symbol.SourceShortName) && !String.IsNullOrEmpty(symbol.SourceName) && !this.BackendHelper.IsValidShortFilename(symbol.SourceName, false)) { - symbol.SourceShortName = CreateShortName(symbol.SourceName, false, false, "Directory", symbol.ParentDirectoryRef); + symbol.SourceShortName = this.CreateShortName(symbol.SourceName, false, "Directory", symbol.ParentDirectoryRef); } - var sourceName = GetMsiFilenameValue(symbol.SourceShortName, symbol.SourceName); - var targetName = GetMsiFilenameValue(symbol.ShortName, symbol.Name); + var sourceName = CreateMsiFilename(symbol.SourceShortName, symbol.SourceName); + var targetName = CreateMsiFilename(symbol.ShortName, symbol.Name); if (String.IsNullOrEmpty(targetName)) { @@ -542,16 +542,16 @@ namespace WixToolset.Core.WindowsInstaller.Bind private void AddDuplicateFileSymbol(DuplicateFileSymbol symbol) { var name = symbol.DestinationName; - if (null == symbol.DestinationShortName && null != name && !Common.IsValidShortFilename(name, false)) + if (null == symbol.DestinationShortName && null != name && !this.BackendHelper.IsValidShortFilename(name, false)) { - symbol.DestinationShortName = CreateShortName(name, true, false, "CopyFile", symbol.ComponentRef, symbol.FileRef); + symbol.DestinationShortName = this.CreateShortName(name, true, "CopyFile", symbol.ComponentRef, symbol.FileRef); } var row = this.CreateRow(symbol, "DuplicateFile"); row[0] = symbol.Id.Id; row[1] = symbol.ComponentRef; row[2] = symbol.FileRef; - row[3] = GetMsiFilenameValue(symbol.DestinationShortName, symbol.DestinationName); + row[3] = CreateMsiFilename(symbol.DestinationShortName, symbol.DestinationName); row[4] = symbol.DestinationFolder; } @@ -621,9 +621,9 @@ namespace WixToolset.Core.WindowsInstaller.Bind private void AddFileSymbol(FileSymbol symbol) { var name = symbol.Name; - if (null == symbol.ShortName && null != name && !Common.IsValidShortFilename(name, false)) + if (null == symbol.ShortName && null != name && !this.BackendHelper.IsValidShortFilename(name, false)) { - symbol.ShortName = CreateShortName(name, true, false, "File", symbol.DirectoryRef); + symbol.ShortName = this.CreateShortName(name, true, "File", symbol.DirectoryRef); if (!this.GeneratedShortNames.TryGetValue(symbol.ShortName, out var potentialConflicts)) { @@ -637,7 +637,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind var row = (FileRow)this.CreateRow(symbol, "File"); row.File = symbol.Id.Id; row.Component = symbol.ComponentRef; - row.FileName = GetMsiFilenameValue(symbol.ShortName, name); + row.FileName = CreateMsiFilename(symbol.ShortName, name); row.FileSize = symbol.FileSize; row.Version = symbol.Version; row.Language = symbol.Language; @@ -674,14 +674,14 @@ namespace WixToolset.Core.WindowsInstaller.Bind var tableName = (IniFileActionType.AddLine == symbol.Action || IniFileActionType.AddTag == symbol.Action || IniFileActionType.CreateLine == symbol.Action) ? "IniFile" : "RemoveIniFile"; var name = symbol.FileName; - if (null == symbol.ShortFileName && null != name && !Common.IsValidShortFilename(name, false)) + if (null == symbol.ShortFileName && null != name && !this.BackendHelper.IsValidShortFilename(name, false)) { - symbol.ShortFileName = CreateShortName(name, true, false, "IniFile", symbol.ComponentRef); + symbol.ShortFileName = this.CreateShortName(name, true, "IniFile", symbol.ComponentRef); } var row = this.CreateRow(symbol, tableName); row[0] = symbol.Id.Id; - row[1] = GetMsiFilenameValue(symbol.ShortFileName, name); + row[1] = CreateMsiFilename(symbol.ShortFileName, name); row[2] = symbol.DirProperty; row[3] = symbol.Section; row[4] = symbol.Key; @@ -693,14 +693,14 @@ namespace WixToolset.Core.WindowsInstaller.Bind private void AddIniLocatorSymbol(IniLocatorSymbol symbol) { var name = symbol.FileName; - if (null == symbol.ShortFileName && null != name && !Common.IsValidShortFilename(name, false)) + if (null == symbol.ShortFileName && null != name && !this.BackendHelper.IsValidShortFilename(name, false)) { - symbol.ShortFileName = CreateShortName(name, true, false, "IniFileSearch"); + symbol.ShortFileName = this.CreateShortName(name, true, "IniFileSearch"); } var row = this.CreateRow(symbol, "IniLocator"); row[0] = symbol.Id.Id; - row[1] = GetMsiFilenameValue(symbol.ShortFileName, name); + row[1] = CreateMsiFilename(symbol.ShortFileName, name); row[2] = symbol.Section; row[3] = symbol.Key; row[4] = symbol.Field; @@ -786,16 +786,16 @@ namespace WixToolset.Core.WindowsInstaller.Bind private void AddMoveFileSymbol(MoveFileSymbol symbol) { var name = symbol.DestinationName; - if (null == symbol.DestinationShortName && null != name && !Common.IsValidShortFilename(name, false)) + if (null == symbol.DestinationShortName && null != name && !this.BackendHelper.IsValidShortFilename(name, false)) { - symbol.DestinationShortName = CreateShortName(name, true, false, "MoveFile", symbol.ComponentRef); + symbol.DestinationShortName = this.CreateShortName(name, true, "MoveFile", symbol.ComponentRef); } var row = this.CreateRow(symbol, "MoveFile"); row[0] = symbol.Id.Id; row[1] = symbol.ComponentRef; row[2] = symbol.SourceName; - row[3] = GetMsiFilenameValue(symbol.DestinationShortName, symbol.DestinationName); + row[3] = CreateMsiFilename(symbol.DestinationShortName, symbol.DestinationName); row[4] = symbol.SourceFolder; row[5] = symbol.DestFolder; row[6] = symbol.Delete ? WindowsInstallerConstants.MsidbMoveFileOptionsMove : 0; @@ -816,9 +816,9 @@ namespace WixToolset.Core.WindowsInstaller.Bind private void AddRemoveFileSymbol(RemoveFileSymbol symbol) { var name = symbol.FileName; - if (null == symbol.ShortFileName && null != name && !Common.IsValidShortFilename(name, false)) + if (null == symbol.ShortFileName && null != name && !this.BackendHelper.IsValidShortFilename(name, false)) { - symbol.ShortFileName = CreateShortName(name, true, false, "RemoveFile", symbol.ComponentRef); + symbol.ShortFileName = this.CreateShortName(name, true, "RemoveFile", symbol.ComponentRef); } var installMode = symbol.OnInstall == true ? WindowsInstallerConstants.MsidbRemoveFileInstallModeOnInstall : 0; @@ -827,7 +827,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind var row = this.CreateRow(symbol, "RemoveFile"); row[0] = symbol.Id.Id; row[1] = symbol.ComponentRef; - row[2] = GetMsiFilenameValue(symbol.ShortFileName, symbol.FileName); + row[2] = CreateMsiFilename(symbol.ShortFileName, symbol.FileName); row[3] = symbol.DirPropertyRef; row[4] = installMode; } @@ -966,15 +966,15 @@ namespace WixToolset.Core.WindowsInstaller.Bind private void AddShortcutSymbol(ShortcutSymbol symbol) { var name = symbol.Name; - if (null == symbol.ShortName && null != name && !Common.IsValidShortFilename(name, false)) + if (null == symbol.ShortName && null != name && !this.BackendHelper.IsValidShortFilename(name, false)) { - symbol.ShortName = CreateShortName(name, true, false, "Shortcut", symbol.ComponentRef, symbol.DirectoryRef); + symbol.ShortName = this.CreateShortName(name, true, "Shortcut", symbol.ComponentRef, symbol.DirectoryRef); } var row = this.CreateRow(symbol, "Shortcut"); row[0] = symbol.Id.Id; row[1] = symbol.DirectoryRef; - row[2] = GetMsiFilenameValue(symbol.ShortName, name); + row[2] = CreateMsiFilename(symbol.ShortName, name); row[3] = symbol.ComponentRef; row[4] = symbol.Target; row[5] = symbol.Arguments; @@ -1177,7 +1177,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind } else if (rowField.Column.Category == ColumnCategory.Identifier) { - if (Common.IsIdentifier(data) || Common.IsValidBinderVariable(data) || ColumnCategory.Formatted == rowField.Column.Category) + if (this.BackendHelper.IsValidIdentifier(data) || this.BackendHelper.IsValidBinderVariable(data) || ColumnCategory.Formatted == rowField.Column.Category) { rowField.Data = data; } @@ -1488,19 +1488,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind private Row CreateRow(IntermediateSymbol symbol, TableDefinition tableDefinition) => this.BackendHelper.CreateRow(this.Section, symbol, this.Data, tableDefinition); - private static string GetMsiFilenameValue(string shortName, string longName) - { - if (String.IsNullOrEmpty(shortName) || String.Equals(shortName, longName, StringComparison.OrdinalIgnoreCase)) - { - return longName; - } - else - { - return shortName + "|" + longName; - } - } - private static string CreateShortName(string longName, bool keepExtension, bool allowWildcards, params string[] args) + private string CreateShortName(string longName, bool keepExtension, params string[] args) { longName = longName.ToLowerInvariant(); @@ -1537,7 +1526,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind shortName.Append(extension); // check the generated short name to ensure its still legal (the extension may not be legal) - if (!Common.IsValidShortFilename(shortName.ToString(), allowWildcards)) + if (!this.BackendHelper.IsValidShortFilename(shortName.ToString(), false)) { // remove the extension (by truncating the generated file name back to the generated characters) shortName.Length -= extension.Length; @@ -1546,5 +1535,17 @@ namespace WixToolset.Core.WindowsInstaller.Bind return shortName.ToString().ToLowerInvariant(); } + + private static string CreateMsiFilename(string shortName, string longName) + { + if (String.IsNullOrEmpty(shortName) || String.Equals(shortName, longName, StringComparison.OrdinalIgnoreCase)) + { + return longName; + } + else + { + return shortName + "|" + longName; + } + } } } diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/ExtractMergeModuleFilesCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/ExtractMergeModuleFilesCommand.cs index e33b38b1..d4de2dd3 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/ExtractMergeModuleFilesCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/ExtractMergeModuleFilesCommand.cs @@ -11,19 +11,20 @@ namespace WixToolset.Core.WindowsInstaller.Bind using System.Runtime.InteropServices; using WixToolset.Data; using WixToolset.Core.Native; - using WixToolset.Core.Bind; using WixToolset.Data.Symbols; using WixToolset.Extensibility.Services; using WixToolset.Core.WindowsInstaller.Msi; + using WixToolset.Extensibility.Data; /// /// Retrieve files information and extract them from merge modules. /// internal class ExtractMergeModuleFilesCommand { - public ExtractMergeModuleFilesCommand(IMessaging messaging, IEnumerable wixMergeSymbols, IEnumerable fileFacades, int installerVersion, string intermediateFolder, bool suppressLayout) + public ExtractMergeModuleFilesCommand(IMessaging messaging, IWindowsInstallerBackendHelper backendHelper, IEnumerable wixMergeSymbols, IEnumerable fileFacades, int installerVersion, string intermediateFolder, bool suppressLayout) { this.Messaging = messaging; + this.BackendHelper = backendHelper; this.WixMergeSymbols = wixMergeSymbols; this.FileFacades = fileFacades; this.OutputInstallerVersion = installerVersion; @@ -33,9 +34,11 @@ namespace WixToolset.Core.WindowsInstaller.Bind private IMessaging Messaging { get; } + private IWindowsInstallerBackendHelper BackendHelper { get; } + private IEnumerable WixMergeSymbols { get; } - private IEnumerable FileFacades { get; } + private IEnumerable FileFacades { get; } private int OutputInstallerVersion { get; } @@ -43,11 +46,11 @@ namespace WixToolset.Core.WindowsInstaller.Bind private bool SuppressLayout { get; } - public IEnumerable MergeModulesFileFacades { get; private set; } + public IEnumerable MergeModulesFileFacades { get; private set; } public void Execute() { - var mergeModulesFileFacades = new List(); + var mergeModulesFileFacades = new List(); var interop = new MsmInterop(); var merge = interop.GetMsmMerge(); @@ -75,7 +78,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind this.MergeModulesFileFacades = mergeModulesFileFacades; } - private bool CreateFacadesForMergeModuleFiles(WixMergeSymbol wixMergeRow, List mergeModulesFileFacades, Dictionary indexedFileFacades) + private bool CreateFacadesForMergeModuleFiles(WixMergeSymbol wixMergeRow, List mergeModulesFileFacades, Dictionary indexedFileFacades) { var containsFiles = false; @@ -86,7 +89,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind { if (db.TableExists("File") && db.TableExists("Component")) { - var uniqueModuleFileIdentifiers = new Dictionary(StringComparer.OrdinalIgnoreCase); + var uniqueModuleFileIdentifiers = new Dictionary(StringComparer.OrdinalIgnoreCase); using (var view = db.OpenExecuteView("SELECT `File`, `Directory_` FROM `File`, `Component` WHERE `Component_`=`Component`")) { @@ -102,7 +105,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind fileSymbol.DiskId = wixMergeRow.DiskId; fileSymbol.Source = new IntermediateFieldPathValue { Path = Path.Combine(this.IntermediateFolder, wixMergeRow.Id.Id, record[1]) }; - var mergeModuleFileFacade = new FileFacade(true, fileSymbol); + var mergeModuleFileFacade = this.BackendHelper.CreateFileFacadeFromMergeModule(fileSymbol); // If case-sensitive collision with another merge module or a user-authored file identifier. if (indexedFileFacades.TryGetValue(mergeModuleFileFacade.Id, out var collidingFacade)) diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/GetFileFacadesCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/GetFileFacadesCommand.cs index c918e866..949d5e18 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/GetFileFacadesCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/GetFileFacadesCommand.cs @@ -6,36 +6,45 @@ namespace WixToolset.Core.WindowsInstaller.Bind using System.Collections.Generic; using System.Globalization; using System.Linq; - using WixToolset.Core.Bind; using WixToolset.Data; using WixToolset.Data.Symbols; + using WixToolset.Extensibility.Data; + using WixToolset.Extensibility.Services; internal class GetFileFacadesCommand { - public GetFileFacadesCommand(IntermediateSection section) + public GetFileFacadesCommand(IntermediateSection section, IWindowsInstallerBackendHelper backendHelper) { this.Section = section; + this.BackendHelper = backendHelper; } private IntermediateSection Section { get; } - public List FileFacades { get; private set; } + private IWindowsInstallerBackendHelper BackendHelper { get; } + + public List FileFacades { get; private set; } public void Execute() { - var facades = new List(); + var facades = new List(); var assemblyFile = this.Section.Symbols.OfType().ToDictionary(t => t.Id.Id); +#if TODO_PATCHING_DELTA //var deltaPatchFiles = this.Section.Symbols.OfType().ToDictionary(t => t.Id.Id); +#endif foreach (var file in this.Section.Symbols.OfType()) { assemblyFile.TryGetValue(file.Id.Id, out var assembly); +#if TODO_PATCHING_DELTA //deltaPatchFiles.TryGetValue(file.Id.Id, out var deltaPatchFile); + // TODO: should we be passing along delta information to the file facade? Probably, right? +#endif + var fileFacade = this.BackendHelper.CreateFileFacade(file, assembly); - facades.Add(new FileFacade(file, assembly)); - //facades.Add(new FileFacade(file, wixFile, deltaPatchFile)); + facades.Add(fileFacade); } #if TODO_PATCHING_DELTA diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/GetFileFacadesFromTransforms.cs b/src/WixToolset.Core.WindowsInstaller/Bind/GetFileFacadesFromTransforms.cs index 585bdac0..ca074631 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/GetFileFacadesFromTransforms.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/GetFileFacadesFromTransforms.cs @@ -5,35 +5,35 @@ namespace WixToolset.Core.WindowsInstaller.Bind using System; using System.Collections.Generic; using System.Linq; - using WixToolset.Core.Bind; using WixToolset.Data; using WixToolset.Data.WindowsInstaller; using WixToolset.Data.WindowsInstaller.Rows; - using WixToolset.Extensibility; + using WixToolset.Extensibility.Data; using WixToolset.Extensibility.Services; internal class GetFileFacadesFromTransforms { - public GetFileFacadesFromTransforms(IMessaging messaging, FileSystemManager fileSystemManager, IEnumerable subStorages) + public GetFileFacadesFromTransforms(IMessaging messaging, IWindowsInstallerBackendHelper backendHelper, FileSystemManager fileSystemManager, IEnumerable subStorages) { this.Messaging = messaging; + this.BackendHelper = backendHelper; this.FileSystemManager = fileSystemManager; this.SubStorages = subStorages; } private IMessaging Messaging { get; } + private IWindowsInstallerBackendHelper BackendHelper { get; } + private FileSystemManager FileSystemManager { get; } private IEnumerable SubStorages { get; } - public List FileFacades { get; private set; } + public List FileFacades { get; private set; } public void Execute() { - var allFileRows = new List(); - - var patchMediaRows = new RowDictionary(); + var allFileRows = new List(); var patchMediaFileRows = new Dictionary>(); @@ -143,7 +143,12 @@ namespace WixToolset.Core.WindowsInstaller.Bind mediaFileRows.Add(patchFileRow); - allFileRows.Add(new FileFacade(patchFileRow)); // TODO: should we be passing along delta information? Probably, right? +#if TODO_PATCHING_DELTA + // TODO: should we be passing along delta information to the file facade? Probably, right? +#endif + var fileFacade = this.BackendHelper.CreateFileFacade(patchFileRow); + + allFileRows.Add(fileFacade); } else { diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/MergeModulesCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/MergeModulesCommand.cs index 80684e7c..f8a1efd6 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/MergeModulesCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/MergeModulesCommand.cs @@ -9,12 +9,12 @@ namespace WixToolset.Core.WindowsInstaller.Bind using System.Linq; using System.Runtime.InteropServices; using System.Text; - using WixToolset.Core.Bind; using WixToolset.Core.Native; using WixToolset.Core.WindowsInstaller.Msi; using WixToolset.Data; using WixToolset.Data.Symbols; using WixToolset.Data.WindowsInstaller; + using WixToolset.Extensibility.Data; using WixToolset.Extensibility.Services; /// @@ -22,7 +22,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind /// internal class MergeModulesCommand { - public MergeModulesCommand(IMessaging messaging, IEnumerable fileFacades, IntermediateSection section, IEnumerable suppressedTableNames, string outputPath, string intermediateFolder) + public MergeModulesCommand(IMessaging messaging, IEnumerable fileFacades, IntermediateSection section, IEnumerable suppressedTableNames, string outputPath, string intermediateFolder) { this.Messaging = messaging; this.FileFacades = fileFacades; @@ -34,7 +34,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind private IMessaging Messaging { get; } - private IEnumerable FileFacades { get; } + private IEnumerable FileFacades { get; } private IntermediateSection Section { get; } diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/ModularizeCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/ModularizeCommand.cs index 49ef1adf..04f1b771 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/ModularizeCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/ModularizeCommand.cs @@ -12,11 +12,13 @@ namespace WixToolset.Core.WindowsInstaller.Bind using WixToolset.Data; using WixToolset.Data.Symbols; using WixToolset.Data.WindowsInstaller; + using WixToolset.Extensibility.Services; internal class ModularizeCommand { - public ModularizeCommand(WindowsInstallerData output, string modularizationSuffix, IEnumerable suppressSymbols) + public ModularizeCommand(IBackendHelper backendHelper, WindowsInstallerData output, string modularizationSuffix, IEnumerable suppressSymbols) { + this.BackendHelper = backendHelper; this.Output = output; this.ModularizationSuffix = modularizationSuffix; @@ -24,6 +26,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind this.SuppressModularizationIdentifiers = new HashSet(suppressSymbols.Select(s => s.SuppressIdentifier)); } + private IBackendHelper BackendHelper { get; } + private WindowsInstallerData Output { get; } private string ModularizationSuffix { get; } @@ -90,7 +94,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind case "SetTargetPath": case "SpawnDialog": case "SpawnWaitDialog": - if (Common.IsIdentifier(fieldData)) + if (this.BackendHelper.IsValidIdentifier(fieldData)) { modularizeType = ColumnModularizeType.Column; } @@ -107,7 +111,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind else if (ColumnModularizeType.ControlText == field.Column.ModularizeType) { // icons are stored in the Binary table, so they get column-type modularization - if (("Bitmap" == row[2].ToString() || "Icon" == row[2].ToString()) && Common.IsIdentifier(fieldData)) + if (("Bitmap" == row[2].ToString() || "Icon" == row[2].ToString()) && this.BackendHelper.IsValidIdentifier(fieldData)) { modularizeType = ColumnModularizeType.Column; } @@ -121,7 +125,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind { case ColumnModularizeType.Column: // ensure the value is an identifier (otherwise it shouldn't be modularized this way) - if (!Common.IsIdentifier(fieldData)) + if (!this.BackendHelper.IsValidIdentifier(fieldData)) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentUICulture, WixDataStrings.EXP_CannotModularizeIllegalID, fieldData)); } diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/OptimizeFileFacadesOrderCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/OptimizeFileFacadesOrderCommand.cs index 67515154..5dd4d3ea 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/OptimizeFileFacadesOrderCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/OptimizeFileFacadesOrderCommand.cs @@ -5,7 +5,6 @@ namespace WixToolset.Core.WindowsInstaller.Bind using System; using System.Collections.Generic; using System.Linq; - using WixToolset.Core.Bind; using WixToolset.Data; using WixToolset.Data.Symbols; using WixToolset.Extensibility.Data; @@ -13,7 +12,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind internal class OptimizeFileFacadesOrderCommand { - public OptimizeFileFacadesOrderCommand(IBackendHelper helper, IPathResolver pathResolver, IntermediateSection section, Platform platform, List fileFacades) + public OptimizeFileFacadesOrderCommand(IBackendHelper helper, IPathResolver pathResolver, IntermediateSection section, Platform platform, List fileFacades) { this.BackendHelper = helper; this.PathResolver = pathResolver; @@ -22,7 +21,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind this.FileFacades = fileFacades; } - public List FileFacades { get; private set; } + public List FileFacades { get; private set; } private IBackendHelper BackendHelper { get; } @@ -32,7 +31,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind private Platform Platform { get; } - public List Execute() + public List Execute() { var canonicalComponentTargetPaths = this.ComponentTargetPaths(); @@ -69,7 +68,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind return targetPathsByDirectoryId; } - private class FileFacadeOptimizer : IComparer + private class FileFacadeOptimizer : IComparer { public FileFacadeOptimizer(Dictionary componentTargetPaths, bool optimizingMergeModule) { @@ -81,7 +80,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind private bool OptimizingMergeModule { get; } - public int Compare(FileFacade x, FileFacade y) + public int Compare(IFileFacade x, IFileFacade y) { // First group files by DiskId but ignore if processing a Merge Module // because Merge Modules don't have separate disks. diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/ProcessDependencyReferencesCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/ProcessDependencyReferencesCommand.cs index 7a7c2649..5ec93f49 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/ProcessDependencyReferencesCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/ProcessDependencyReferencesCommand.cs @@ -17,12 +17,15 @@ namespace WixToolset.Core.WindowsInstaller.Bind private const string DependencyRegistryRoot = @"Software\Classes\Installer\Dependencies\"; private const string RegistryDependents = "Dependents"; - public ProcessDependencyReferencesCommand(IntermediateSection section, IEnumerable dependencyRefSymbols) + public ProcessDependencyReferencesCommand(IBackendHelper backendHelper, IntermediateSection section, IEnumerable dependencyRefSymbols) { + this.BackendHelper = backendHelper; this.Section = section; this.DependencyRefSymbols = dependencyRefSymbols; } + private IBackendHelper BackendHelper { get; } + private IntermediateSection Section { get; } private IEnumerable DependencyRefSymbols { get; } @@ -57,7 +60,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind // Get the component ID from the provider. var componentId = wixDependencyProviderRow.ComponentRef; - var id = Common.GenerateIdentifier("reg", providesId, requiresId, "(Default)"); + var id = this.BackendHelper.GenerateIdentifier("reg", providesId, requiresId, "(Default)"); this.Section.AddSymbol(new RegistrySymbol(wixDependencyRefRow.SourceLineNumbers, new Identifier(AccessModifier.Section, id)) { ComponentRef = componentId, @@ -68,7 +71,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind if (!String.IsNullOrEmpty(wixDependencyRow.MinVersion)) { - id = Common.GenerateIdentifier("reg", providesId, requiresId, "MinVersion"); + id = this.BackendHelper.GenerateIdentifier("reg", providesId, requiresId, "MinVersion"); this.Section.AddSymbol(new RegistrySymbol(wixDependencyRefRow.SourceLineNumbers, new Identifier(AccessModifier.Section, id)) { ComponentRef = componentId, @@ -79,10 +82,10 @@ namespace WixToolset.Core.WindowsInstaller.Bind }); } - string maxVersion = (string)wixDependencyRow[3]; + var maxVersion = (string)wixDependencyRow[3]; if (!String.IsNullOrEmpty(wixDependencyRow.MaxVersion)) { - id = Common.GenerateIdentifier("reg", providesId, requiresId, "MaxVersion"); + id = this.BackendHelper.GenerateIdentifier("reg", providesId, requiresId, "MaxVersion"); this.Section.AddSymbol(new RegistrySymbol(wixDependencyRefRow.SourceLineNumbers, new Identifier(AccessModifier.Section, id)) { ComponentRef = componentId, @@ -95,7 +98,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind if (wixDependencyRow.Attributes != WixDependencySymbolAttributes.None) { - id = Common.GenerateIdentifier("reg", providesId, requiresId, "Attributes"); + id = this.BackendHelper.GenerateIdentifier("reg", providesId, requiresId, "Attributes"); this.Section.AddSymbol(new RegistrySymbol(wixDependencyRefRow.SourceLineNumbers, new Identifier(AccessModifier.Section, id)) { ComponentRef = componentId, diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/ProcessUncompressedFilesCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/ProcessUncompressedFilesCommand.cs index ab5ebd4b..8c66a9e1 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/ProcessUncompressedFilesCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/ProcessUncompressedFilesCommand.cs @@ -6,7 +6,6 @@ namespace WixToolset.Core.WindowsInstaller.Bind using System.Collections.Generic; using System.IO; using System.Linq; - using WixToolset.Core.Bind; using WixToolset.Core.WindowsInstaller.Msi; using WixToolset.Data; using WixToolset.Data.Symbols; @@ -33,7 +32,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind public string DatabasePath { private get; set; } - public IEnumerable FileFacades { private get; set; } + public IEnumerable FileFacades { private get; set; } public string LayoutDirectory { private get; set; } @@ -63,7 +62,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind { foreach (var directoryRecord in directoryView.Records) { - var sourceName = Common.GetName(directoryRecord.GetString(3), true, this.LongNamesInImage); + var sourceName = this.BackendHelper.GetMsiFileName(directoryRecord.GetString(3), true, this.LongNamesInImage); var resolvedDirectory = this.BackendHelper.CreateResolvedDirectory(directoryRecord.GetString(2), sourceName); @@ -71,16 +70,16 @@ namespace WixToolset.Core.WindowsInstaller.Bind } } - using (View fileView = db.OpenView("SELECT `Directory_`, `FileName` FROM `Component`, `File` WHERE `Component`.`Component`=`File`.`Component_` AND `File`.`File`=?")) + using (var fileView = db.OpenView("SELECT `Directory_`, `FileName` FROM `Component`, `File` WHERE `Component`.`Component`=`File`.`Component_` AND `File`.`File`=?")) { - using (Record fileQueryRecord = new Record(1)) + using (var fileQueryRecord = new Record(1)) { // for each file in the array of uncompressed files - foreach (FileFacade facade in this.FileFacades) + foreach (var facade in this.FileFacades) { var mediaSymbol = mediaRows[facade.DiskId]; string relativeFileLayoutPath = null; - string mediaLayoutFolder = mediaSymbol.Layout; + var mediaLayoutFolder = mediaSymbol.Layout; var mediaLayoutDirectory = this.ResolveMedia(mediaSymbol, mediaLayoutFolder, this.LayoutDirectory); @@ -89,7 +88,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind fileQueryRecord[1] = facade.Id; fileView.Execute(fileQueryRecord); - using (Record fileRecord = fileView.Fetch()) + using (var fileRecord = fileView.Fetch()) { if (null == fileRecord) { diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs index f8819a0e..9cd14cfa 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs @@ -8,10 +8,10 @@ namespace WixToolset.Core.WindowsInstaller.Bind using System.Globalization; using System.IO; using System.Linq; - using WixToolset.Core.Bind; using WixToolset.Core.WindowsInstaller.Msi; using WixToolset.Data; using WixToolset.Data.Symbols; + using WixToolset.Extensibility.Data; using WixToolset.Extensibility.Services; /// @@ -19,7 +19,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind /// internal class UpdateFileFacadesCommand { - public UpdateFileFacadesCommand(IMessaging messaging, IntermediateSection section, IEnumerable fileFacades, IEnumerable updateFileFacades, IDictionary variableCache, bool overwriteHash) + public UpdateFileFacadesCommand(IMessaging messaging, IntermediateSection section, IEnumerable fileFacades, IEnumerable updateFileFacades, IDictionary variableCache, bool overwriteHash) { this.Messaging = messaging; this.Section = section; @@ -33,9 +33,9 @@ namespace WixToolset.Core.WindowsInstaller.Bind private IntermediateSection Section { get; } - private IEnumerable FileFacades { get; } + private IEnumerable FileFacades { get; } - private IEnumerable UpdateFileFacades { get; } + private IEnumerable UpdateFileFacades { get; } private bool OverwriteHash { get; } @@ -51,7 +51,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind } } - private void UpdateFileFacade(FileFacade facade, Dictionary assemblyNameSymbols) + private void UpdateFileFacade(IFileFacade facade, Dictionary assemblyNameSymbols) { FileInfo fileInfo = null; try @@ -314,7 +314,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind /// FileFacade containing the assembly read for the MsiAssemblyName row. /// MsiAssemblyName name. /// MsiAssemblyName value. - private void SetMsiAssemblyName(Dictionary assemblyNameSymbols, FileFacade facade, string name, string value) + private void SetMsiAssemblyName(Dictionary assemblyNameSymbols, IFileFacade facade, string name, string value) { // check for null value (this can occur when grabbing the file version from an assembly without one) if (String.IsNullOrEmpty(value)) diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/UpdateMediaSequencesCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/UpdateMediaSequencesCommand.cs index d3f2b9ea..affec09f 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/UpdateMediaSequencesCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/UpdateMediaSequencesCommand.cs @@ -4,13 +4,13 @@ namespace WixToolset.Core.WindowsInstaller.Bind { using System.Collections.Generic; using System.Linq; - using WixToolset.Core.Bind; using WixToolset.Data; using WixToolset.Data.Symbols; + using WixToolset.Extensibility.Data; internal class UpdateMediaSequencesCommand { - public UpdateMediaSequencesCommand(IntermediateSection section, List fileFacades) + public UpdateMediaSequencesCommand(IntermediateSection section, IEnumerable fileFacades) { this.Section = section; this.FileFacades = fileFacades; @@ -18,7 +18,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind private IntermediateSection Section { get; } - private List FileFacades { get; } + private IEnumerable FileFacades { get; } public void Execute() { @@ -38,9 +38,9 @@ namespace WixToolset.Core.WindowsInstaller.Bind { var lastSequence = 0; MediaSymbol mediaSymbol = null; - var patchGroups = new Dictionary>(); + var patchGroups = new Dictionary>(); - // sequence the non-patch-added files + // Sequence the non-patch-added files. foreach (var facade in this.FileFacades) { if (null == mediaSymbol) @@ -62,7 +62,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind { if (patchGroups.TryGetValue(facade.PatchGroup.Value, out var patchGroup)) { - patchGroup = new List(); + patchGroup = new List(); patchGroups.Add(facade.PatchGroup.Value, patchGroup); } @@ -80,7 +80,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind mediaSymbol = null; } - // sequence the patch-added files + // Sequence the patch-added files. foreach (var patchGroup in patchGroups.Values) { foreach (var facade in patchGroup) diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/UpdateTransformsWithFileFacades.cs b/src/WixToolset.Core.WindowsInstaller/Bind/UpdateTransformsWithFileFacades.cs index 4e716a47..981fa0a4 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/UpdateTransformsWithFileFacades.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/UpdateTransformsWithFileFacades.cs @@ -5,16 +5,16 @@ namespace WixToolset.Core.WindowsInstaller.Bind using System; using System.Collections.Generic; using System.Linq; - using WixToolset.Core.Bind; using WixToolset.Data; using WixToolset.Data.Symbols; using WixToolset.Data.WindowsInstaller; using WixToolset.Data.WindowsInstaller.Rows; + using WixToolset.Extensibility.Data; using WixToolset.Extensibility.Services; internal class UpdateTransformsWithFileFacades { - public UpdateTransformsWithFileFacades(IMessaging messaging, WindowsInstallerData output, IEnumerable subStorages, TableDefinitionCollection tableDefinitions, IEnumerable fileFacades) + public UpdateTransformsWithFileFacades(IMessaging messaging, WindowsInstallerData output, IEnumerable subStorages, TableDefinitionCollection tableDefinitions, IEnumerable fileFacades) { this.Messaging = messaging; this.Output = output; @@ -31,18 +31,18 @@ namespace WixToolset.Core.WindowsInstaller.Bind private TableDefinitionCollection TableDefinitions { get; } - private IEnumerable FileFacades { get; } + private IEnumerable FileFacades { get; } public void Execute() { - var fileFacadesByDiskId = new Dictionary>(); + var fileFacadesByDiskId = new Dictionary>(); // Index patch file facades by diskId+fileId. foreach (var facade in this.FileFacades) { if (!fileFacadesByDiskId.TryGetValue(facade.DiskId, out var mediaFacades)) { - mediaFacades = new Dictionary(); + mediaFacades = new Dictionary(); fileFacadesByDiskId.Add(facade.DiskId, mediaFacades); } @@ -97,7 +97,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind // Index patch files by diskId+fileId if (!fileFacadesByDiskId.TryGetValue(mainFileRow.DiskId, out var mediaFacades)) { - mediaFacades = new Dictionary(); + mediaFacades = new Dictionary(); fileFacadesByDiskId.Add(mainFileRow.DiskId, mediaFacades); } -- cgit v1.2.3-55-g6feb