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 --- src/WixToolset.Core.Burn/Bind/BindBundleCommand.cs | 8 ++--- ...CreateBootstrapperApplicationManifestCommand.cs | 2 +- .../CreateBundleExtensionManifestCommand.cs | 2 +- .../Bundles/ProcessMsiPackageCommand.cs | 12 ++++---- .../ExtensibilityServices/BurnBackendHelper.cs | 34 +++++++++++++++++++++- src/WixToolset.Core.Burn/RowIndexedList.cs | 21 ++++++------- src/WixToolset.Core.Burn/TableExtensions.cs | 24 --------------- 7 files changed, 53 insertions(+), 50 deletions(-) delete mode 100644 src/WixToolset.Core.Burn/TableExtensions.cs (limited to 'src/WixToolset.Core.Burn') diff --git a/src/WixToolset.Core.Burn/Bind/BindBundleCommand.cs b/src/WixToolset.Core.Burn/Bind/BindBundleCommand.cs index e58e2464..afaf65ee 100644 --- a/src/WixToolset.Core.Burn/Bind/BindBundleCommand.cs +++ b/src/WixToolset.Core.Burn/Bind/BindBundleCommand.cs @@ -130,10 +130,9 @@ namespace WixToolset.Core.Burn // Extract files that come from binary .wixlibs and WixExtensions (this does not extract files from merge modules). { - var command = new ExtractEmbeddedFilesCommand(this.BackendHelper, this.ExpectedEmbeddedFiles); - command.Execute(); + var extractedFiles = this.BackendHelper.ExtractEmbeddedFiles(this.ExpectedEmbeddedFiles); - trackedFiles.AddRange(command.TrackedFiles); + trackedFiles.AddRange(extractedFiles); } // Get the explicit payloads. @@ -367,8 +366,7 @@ namespace WixToolset.Core.Burn // Resolve any delayed fields before generating the manifest. if (this.DelayedFields.Any()) { - var resolveDelayedFieldsCommand = new ResolveDelayedFieldsCommand(this.Messaging, this.DelayedFields, variableCache); - resolveDelayedFieldsCommand.Execute(); + this.BackendHelper.ResolveDelayedFields(this.DelayedFields, variableCache); } Dictionary dependencySymbolsByKey; diff --git a/src/WixToolset.Core.Burn/Bundles/CreateBootstrapperApplicationManifestCommand.cs b/src/WixToolset.Core.Burn/Bundles/CreateBootstrapperApplicationManifestCommand.cs index a24137f3..63a168a0 100644 --- a/src/WixToolset.Core.Burn/Bundles/CreateBootstrapperApplicationManifestCommand.cs +++ b/src/WixToolset.Core.Burn/Bundles/CreateBootstrapperApplicationManifestCommand.cs @@ -244,7 +244,7 @@ namespace WixToolset.Core.Burn.Bundles private WixBundlePayloadSymbol CreateBootstrapperApplicationManifestPayloadRow(string baManifestPath) { - var generatedId = Common.GenerateIdentifier("ux", BurnCommon.BADataFileName); + var generatedId = this.InternalBurnBackendHelper.GenerateIdentifier("ux", BurnCommon.BADataFileName); var symbol = this.Section.AddSymbol(new WixBundlePayloadSymbol(this.BundleSymbol.SourceLineNumbers, new Identifier(AccessModifier.Section, generatedId)) { diff --git a/src/WixToolset.Core.Burn/Bundles/CreateBundleExtensionManifestCommand.cs b/src/WixToolset.Core.Burn/Bundles/CreateBundleExtensionManifestCommand.cs index 9e1f85bc..7b5b9656 100644 --- a/src/WixToolset.Core.Burn/Bundles/CreateBundleExtensionManifestCommand.cs +++ b/src/WixToolset.Core.Burn/Bundles/CreateBundleExtensionManifestCommand.cs @@ -66,7 +66,7 @@ namespace WixToolset.Core.Burn.Bundles private WixBundlePayloadSymbol CreateBundleExtensionManifestPayloadRow(string bextManifestPath) { - var generatedId = Common.GenerateIdentifier("ux", BurnCommon.BundleExtensionDataFileName); + var generatedId = this.InternalBurnBackendHelper.GenerateIdentifier("ux", BurnCommon.BundleExtensionDataFileName); var symbol = this.Section.AddSymbol(new WixBundlePayloadSymbol(this.BundleSymbol.SourceLineNumbers, new Identifier(AccessModifier.Section, generatedId)) { diff --git a/src/WixToolset.Core.Burn/Bundles/ProcessMsiPackageCommand.cs b/src/WixToolset.Core.Burn/Bundles/ProcessMsiPackageCommand.cs index 5ba1ad07..dc1a1913 100644 --- a/src/WixToolset.Core.Burn/Bundles/ProcessMsiPackageCommand.cs +++ b/src/WixToolset.Core.Burn/Bundles/ProcessMsiPackageCommand.cs @@ -94,7 +94,7 @@ namespace WixToolset.Core.Burn.Bundles msiPackage.ProductLanguage = Convert.ToInt32(ProcessMsiPackageCommand.GetProperty(db, "ProductLanguage"), CultureInfo.InvariantCulture); msiPackage.ProductVersion = ProcessMsiPackageCommand.GetProperty(db, "ProductVersion"); - if (!Common.IsValidModuleOrBundleVersion(msiPackage.ProductVersion)) + if (!this.BackendHelper.IsValidFourPartVersion(msiPackage.ProductVersion)) { // not a proper .NET version (e.g., five fields); can we get a valid four-part version number? string version = null; @@ -109,7 +109,7 @@ namespace WixToolset.Core.Burn.Bundles } } - if (!String.IsNullOrEmpty(version) && Common.IsValidModuleOrBundleVersion(version)) + if (!String.IsNullOrEmpty(version) && this.BackendHelper.IsValidFourPartVersion(version)) { this.Messaging.Write(WarningMessages.VersionTruncated(this.Facade.PackageSymbol.SourceLineNumbers, msiPackage.ProductVersion, sourcePath, version)); msiPackage.ProductVersion = version; @@ -394,7 +394,7 @@ namespace WixToolset.Core.Burn.Bundles if (!payloadNames.Contains(cabinetName)) { - var generatedId = Common.GenerateIdentifier("cab", packagePayload.Id.Id, cabinet); + var generatedId = this.BackendHelper.GenerateIdentifier("cab", packagePayload.Id.Id, cabinet); var payloadSourceFile = this.ResolveRelatedFile(packagePayload.SourceFile.Path, packagePayload.UnresolvedSourceFile, cabinet, "Cabinet", this.Facade.PackageSymbol.SourceLineNumbers); this.Section.AddSymbol(new WixBundlePayloadSymbol(this.Facade.PackageSymbol.SourceLineNumbers, new Identifier(AccessModifier.Section, generatedId)) @@ -437,7 +437,7 @@ namespace WixToolset.Core.Burn.Bundles break; } - var sourceName = Common.GetName(record.GetString(3), true, longNamesInImage); + var sourceName = this.BackendHelper.GetMsiFileName(record.GetString(3), true, longNamesInImage); var resolvedDirectory = this.BackendHelper.CreateResolvedDirectory(record.GetString(2), sourceName); @@ -471,7 +471,7 @@ namespace WixToolset.Core.Burn.Bundles if (!payloadNames.Contains(name)) { - var generatedId = Common.GenerateIdentifier("f", packagePayload.Id.Id, record.GetString(2)); + var generatedId = this.BackendHelper.GenerateIdentifier("f", packagePayload.Id.Id, record.GetString(2)); var payloadSourceFile = this.ResolveRelatedFile(packagePayload.SourceFile.Path, packagePayload.UnresolvedSourceFile, fileSourcePath, "File", this.Facade.PackageSymbol.SourceLineNumbers); this.Section.AddSymbol(new WixBundlePayloadSymbol(this.Facade.PackageSymbol.SourceLineNumbers, new Identifier(AccessModifier.Section, generatedId)) @@ -526,7 +526,7 @@ namespace WixToolset.Core.Burn.Bundles break; } - var id = new Identifier(AccessModifier.Section, Common.GenerateIdentifier("dep", msiPackage.Id.Id, record.GetString(1))); + var id = new Identifier(AccessModifier.Section, this.BackendHelper.GenerateIdentifier("dep", msiPackage.Id.Id, record.GetString(1))); // Import the provider key and attributes. this.Section.AddSymbol(new ProvidesDependencySymbol(msiPackage.SourceLineNumbers, id) diff --git a/src/WixToolset.Core.Burn/ExtensibilityServices/BurnBackendHelper.cs b/src/WixToolset.Core.Burn/ExtensibilityServices/BurnBackendHelper.cs index 59efcbc9..5502b43b 100644 --- a/src/WixToolset.Core.Burn/ExtensibilityServices/BurnBackendHelper.cs +++ b/src/WixToolset.Core.Burn/ExtensibilityServices/BurnBackendHelper.cs @@ -9,6 +9,8 @@ namespace WixToolset.Core.Burn.ExtensibilityServices using System.Xml; using WixToolset.Core.Burn.Bundles; using WixToolset.Data; + using WixToolset.Data.Symbols; + using WixToolset.Data.WindowsInstaller.Rows; using WixToolset.Extensibility.Data; using WixToolset.Extensibility.Services; @@ -30,14 +32,44 @@ namespace WixToolset.Core.Burn.ExtensibilityServices #region IBackendHelper interfaces + public IFileFacade CreateFileFacade(FileSymbol file, AssemblySymbol assembly) => this.backendHelper.CreateFileFacade(file, assembly); + + public IFileFacade CreateFileFacade(FileRow fileRow) => this.backendHelper.CreateFileFacade(fileRow); + + public IFileFacade CreateFileFacadeFromMergeModule(FileSymbol fileSymbol) => this.backendHelper.CreateFileFacadeFromMergeModule(fileSymbol); + public IFileTransfer CreateFileTransfer(string source, string destination, bool move, SourceLineNumber sourceLineNumbers = null) => this.backendHelper.CreateFileTransfer(source, destination, move, sourceLineNumbers); + public string CreateGuid() => this.backendHelper.CreateGuid(); + public string CreateGuid(Guid namespaceGuid, string value) => this.backendHelper.CreateGuid(namespaceGuid, value); public IResolvedDirectory CreateResolvedDirectory(string directoryParent, string name) => this.backendHelper.CreateResolvedDirectory(directoryParent, name); + public IEnumerable ExtractEmbeddedFiles(IEnumerable embeddedFiles) => this.backendHelper.ExtractEmbeddedFiles(embeddedFiles); + + public string GenerateIdentifier(string prefix, params string[] args) => this.backendHelper.GenerateIdentifier(prefix, args); + public string GetCanonicalRelativePath(SourceLineNumber sourceLineNumbers, string elementName, string attributeName, string relativePath) => this.backendHelper.GetCanonicalRelativePath(sourceLineNumbers, elementName, attributeName, relativePath); + public int GetValidCodePage(string value, bool allowNoChange, bool onlyAnsi = false, SourceLineNumber sourceLineNumbers = null) => this.backendHelper.GetValidCodePage(value, allowNoChange, onlyAnsi, sourceLineNumbers); + + public string GetMsiFileName(string value, bool source, bool longName) => this.backendHelper.GetMsiFileName(value, source, longName); + + public bool IsValidBinderVariable(string variable) => this.backendHelper.IsValidBinderVariable(variable); + + public bool IsValidFourPartVersion(string version) => this.backendHelper.IsValidFourPartVersion(version); + + public bool IsValidIdentifier(string id) => this.backendHelper.IsValidIdentifier(id); + + public bool IsValidLongFilename(string filename, bool allowWildcards, bool allowRelative) => this.backendHelper.IsValidLongFilename(filename, allowWildcards, allowRelative); + + public bool IsValidShortFilename(string filename, bool allowWildcards) => this.backendHelper.IsValidShortFilename(filename, allowWildcards); + + public void ResolveDelayedFields(IEnumerable delayedFields, Dictionary variableCache) => this.backendHelper.ResolveDelayedFields(delayedFields, variableCache); + + public string[] SplitMsiFileName(string value) => this.backendHelper.SplitMsiFileName(value); + public ITrackedFile TrackFile(string path, TrackedFileType type, SourceLineNumber sourceLineNumbers = null) => this.backendHelper.TrackFile(path, type, sourceLineNumbers); #endregion @@ -87,7 +119,7 @@ namespace WixToolset.Core.Burn.ExtensibilityServices private ManifestData GetBundleExtensionManifestData(string extensionId) { - if (!Common.IsIdentifier(extensionId)) + if (!this.backendHelper.IsValidIdentifier(extensionId)) { throw new ArgumentException($"'{extensionId}' is not a valid extensionId"); } diff --git a/src/WixToolset.Core.Burn/RowIndexedList.cs b/src/WixToolset.Core.Burn/RowIndexedList.cs index 73172dc2..fd762a24 100644 --- a/src/WixToolset.Core.Burn/RowIndexedList.cs +++ b/src/WixToolset.Core.Burn/RowIndexedList.cs @@ -13,9 +13,9 @@ namespace WixToolset.Core.Burn /// internal sealed class RowIndexedList : IList where T : Row { - private Dictionary index; - private List rows; - private List duplicates; + private readonly Dictionary index; + private readonly List rows; + private readonly List duplicates; /// /// Creates an empty . @@ -34,7 +34,7 @@ namespace WixToolset.Core.Burn public RowIndexedList(IEnumerable rows) : this() { - foreach (T row in rows) + foreach (var row in rows) { this.Add(row); } @@ -81,8 +81,7 @@ namespace WixToolset.Core.Burn /// Row or null if key is not found. public T Get(string key) { - T result; - return this.TryGet(key, out result) ? result : null; + return this.TryGet(key, out var result) ? result : null; } /// @@ -169,12 +168,11 @@ namespace WixToolset.Core.Burn /// Index to remove the row at. public void RemoveAt(int index) { - T row = this.rows[index]; + var row = this.rows[index]; this.rows.RemoveAt(index); - T indexRow; - if (this.index.TryGetValue(row.GetKey(), out indexRow) && indexRow == row) + if (this.index.TryGetValue(row.GetKey(), out var indexRow) && indexRow == row) { this.index.Remove(row.GetKey()); } @@ -264,11 +262,10 @@ namespace WixToolset.Core.Burn /// public bool Remove(T row) { - bool removed = this.rows.Remove(row); + var removed = this.rows.Remove(row); if (removed) { - T indexRow; - if (this.index.TryGetValue(row.GetKey(), out indexRow) && indexRow == row) + if (this.index.TryGetValue(row.GetKey(), out var indexRow) && indexRow == row) { this.index.Remove(row.GetKey()); } diff --git a/src/WixToolset.Core.Burn/TableExtensions.cs b/src/WixToolset.Core.Burn/TableExtensions.cs deleted file mode 100644 index 465bf870..00000000 --- a/src/WixToolset.Core.Burn/TableExtensions.cs +++ /dev/null @@ -1,24 +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.Burn -{ - using System.Collections.Generic; - using System.Linq; - using WixToolset.Data.WindowsInstaller; - - /// - /// Methods that extend . - /// - public static class TableExtensions - { - /// - /// Gets the rows contained in the table as a particular row type. - /// - /// Table to get rows from. - /// If the is null, an empty enumerable will be returned. - public static IEnumerable RowsAs(this Table table) where T : Row - { - return (null == table) ? Enumerable.Empty() : table.Rows.Cast(); - } - } -} -- cgit v1.2.3-55-g6feb