| 1 | // 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. |
| 2 | |
| 3 | namespace WixToolset.Core.WindowsInstaller.ExtensibilityServices |
| 4 | { |
| 5 | using System; |
| 6 | using System.Collections.Generic; |
| 7 | using System.Linq; |
| 8 | using WixToolset.Data; |
| 9 | using WixToolset.Data.Symbols; |
| 10 | using WixToolset.Data.WindowsInstaller; |
| 11 | using WixToolset.Data.WindowsInstaller.Rows; |
| 12 | using WixToolset.Extensibility.Data; |
| 13 | using WixToolset.Extensibility.Services; |
| 14 | |
| 15 | internal class WindowsInstallerBackendHelper : IWindowsInstallerBackendHelper |
| 16 | { |
| 17 | private readonly IBackendHelper backendHelper; |
| 18 | |
| 19 | public WindowsInstallerBackendHelper(IServiceProvider serviceProvider) |
| 20 | { |
| 21 | this.backendHelper = serviceProvider.GetService<IBackendHelper>(); |
| 22 | } |
| 23 | |
| 24 | #region IBackendHelper interfaces |
| 25 | |
| 26 | public IFileFacade CreateFileFacade(FileSymbol file) |
| 27 | { |
| 28 | return new FileFacade(file); |
| 29 | } |
| 30 | |
| 31 | public IFileFacade CreateFileFacade(FileRow fileRow) |
| 32 | { |
| 33 | return new FileFacade(fileRow); |
| 34 | } |
| 35 | |
| 36 | public IFileTransfer CreateFileTransfer(string source, string destination, bool move, SourceLineNumber sourceLineNumbers = null) |
| 37 | { |
| 38 | return this.backendHelper.CreateFileTransfer(source, destination, move, sourceLineNumbers); |
| 39 | } |
| 40 | |
| 41 | public string CreateGuid() |
| 42 | { |
| 43 | return this.backendHelper.CreateGuid(); |
| 44 | } |
| 45 | |
| 46 | public string CreateGuid(Guid namespaceGuid, string value) |
| 47 | { |
| 48 | return this.backendHelper.CreateGuid(namespaceGuid, value); |
| 49 | } |
| 50 | |
| 51 | public IResolvedDirectory CreateResolvedDirectory(string directoryParent, string name) |
| 52 | { |
| 53 | return this.backendHelper.CreateResolvedDirectory(directoryParent, name); |
| 54 | } |
| 55 | |
| 56 | public IReadOnlyList<ITrackedFile> ExtractEmbeddedFiles(IEnumerable<IExpectedExtractFile> embeddedFiles) |
| 57 | { |
| 58 | return this.backendHelper.ExtractEmbeddedFiles(embeddedFiles); |
| 59 | } |
| 60 | |
| 61 | public string GenerateIdentifier(string prefix, params string[] args) |
| 62 | { |
| 63 | return this.backendHelper.GenerateIdentifier(prefix, args); |
| 64 | } |
| 65 | |
| 66 | public int GetValidCodePage(string value, bool allowNoChange, bool onlyAnsi = false, SourceLineNumber sourceLineNumbers = null) |
| 67 | { |
| 68 | return this.backendHelper.GetValidCodePage(value, allowNoChange, onlyAnsi, sourceLineNumbers); |
| 69 | } |
| 70 | |
| 71 | public string GetMsiFileName(string value, bool source, bool longName) |
| 72 | { |
| 73 | return this.backendHelper.GetMsiFileName(value, source, longName); |
| 74 | } |
| 75 | |
| 76 | public bool IsValidBinderVariable(string variable) |
| 77 | { |
| 78 | return this.backendHelper.IsValidBinderVariable(variable); |
| 79 | } |
| 80 | |
| 81 | public bool IsValidFourPartVersion(string version) |
| 82 | { |
| 83 | return this.backendHelper.IsValidFourPartVersion(version); |
| 84 | } |
| 85 | |
| 86 | public bool IsValidIdentifier(string id) |
| 87 | { |
| 88 | return this.backendHelper.IsValidIdentifier(id); |
| 89 | } |
| 90 | |
| 91 | public bool IsValidMsiProductVersion(string version) |
| 92 | { |
| 93 | return this.backendHelper.IsValidMsiProductVersion(version); |
| 94 | } |
| 95 | |
| 96 | public bool IsValidWixVersion(string version) |
| 97 | { |
| 98 | return this.backendHelper.IsValidWixVersion(version); |
| 99 | } |
| 100 | |
| 101 | public bool IsValidLongFilename(string filename, bool allowWildcards, bool allowRelative) |
| 102 | { |
| 103 | return this.backendHelper.IsValidLongFilename(filename, allowWildcards, allowRelative); |
| 104 | } |
| 105 | |
| 106 | public bool IsValidShortFilename(string filename, bool allowWildcards) |
| 107 | { |
| 108 | return this.backendHelper.IsValidShortFilename(filename, allowWildcards); |
| 109 | } |
| 110 | |
| 111 | public void ResolveDelayedFields(IEnumerable<IDelayedField> delayedFields, Dictionary<string, string> variableCache) |
| 112 | { |
| 113 | this.backendHelper.ResolveDelayedFields(delayedFields, variableCache); |
| 114 | } |
| 115 | |
| 116 | public string[] SplitMsiFileName(string value) |
| 117 | { |
| 118 | return this.backendHelper.SplitMsiFileName(value); |
| 119 | } |
| 120 | |
| 121 | public bool TryParseFourPartVersion(string version, out string parsedVersion) |
| 122 | { |
| 123 | return this.backendHelper.TryParseFourPartVersion(version, out parsedVersion); |
| 124 | } |
| 125 | |
| 126 | public bool TryParseMsiProductVersion(string version, bool strict, out string parsedVersion) |
| 127 | { |
| 128 | return this.backendHelper.TryParseMsiProductVersion(version, strict, out parsedVersion); |
| 129 | } |
| 130 | |
| 131 | public ITrackedFile TrackFile(string path, TrackedFileType type, SourceLineNumber sourceLineNumbers = null) |
| 132 | { |
| 133 | return this.backendHelper.TrackFile(path, type, sourceLineNumbers); |
| 134 | } |
| 135 | |
| 136 | #endregion |
| 137 | |
| 138 | #region IWindowsInstallerBackendHelper interfaces |
| 139 | |
| 140 | public Row CreateRow(IntermediateSection section, IntermediateSymbol symbol, WindowsInstallerData data, TableDefinition tableDefinition) |
| 141 | { |
| 142 | var table = data.EnsureTable(tableDefinition); |
| 143 | |
| 144 | return table.CreateRow(symbol.SourceLineNumbers); |
| 145 | } |
| 146 | |
| 147 | public bool TryAddSymbolToMatchingTableDefinitions(IntermediateSection section, IntermediateSymbol symbol, WindowsInstallerData data, TableDefinitionCollection tableDefinitions) |
| 148 | { |
| 149 | var tableDefinition = tableDefinitions.FirstOrDefault(t => t.SymbolDefinition?.Name == symbol.Definition.Name); |
| 150 | if (tableDefinition == null) |
| 151 | { |
| 152 | return false; |
| 153 | } |
| 154 | |
| 155 | var row = this.CreateRow(section, symbol, data, tableDefinition); |
| 156 | var rowOffset = 0; |
| 157 | |
| 158 | if (tableDefinition.SymbolIdIsPrimaryKey) |
| 159 | { |
| 160 | row[0] = symbol.Id.Id; |
| 161 | rowOffset = 1; |
| 162 | } |
| 163 | |
| 164 | for (var i = 0; i < symbol.Fields.Length; ++i) |
| 165 | { |
| 166 | if (i < tableDefinition.Columns.Length) |
| 167 | { |
| 168 | var column = tableDefinition.Columns[i + rowOffset]; |
| 169 | |
| 170 | switch (column.Type) |
| 171 | { |
| 172 | case ColumnType.Number: |
| 173 | row[i + rowOffset] = column.Nullable ? symbol.AsNullableNumber(i) : symbol.AsNumber(i); |
| 174 | break; |
| 175 | |
| 176 | default: |
| 177 | row[i + rowOffset] = symbol.AsString(i); |
| 178 | break; |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | return true; |
| 184 | } |
| 185 | |
| 186 | #endregion |
| 187 | } |
| 188 | } |