diff options
Diffstat (limited to 'src/WixToolset.Core/Bind/Databases/GetFileFacadesCommand.cs')
| -rw-r--r-- | src/WixToolset.Core/Bind/Databases/GetFileFacadesCommand.cs | 148 |
1 files changed, 148 insertions, 0 deletions
diff --git a/src/WixToolset.Core/Bind/Databases/GetFileFacadesCommand.cs b/src/WixToolset.Core/Bind/Databases/GetFileFacadesCommand.cs new file mode 100644 index 00000000..b6bcd3af --- /dev/null +++ b/src/WixToolset.Core/Bind/Databases/GetFileFacadesCommand.cs | |||
| @@ -0,0 +1,148 @@ | |||
| 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.Bind.Databases | ||
| 4 | { | ||
| 5 | using System; | ||
| 6 | using System.Collections.Generic; | ||
| 7 | using System.Globalization; | ||
| 8 | using System.Linq; | ||
| 9 | using WixToolset.Data; | ||
| 10 | using WixToolset.Data.Rows; | ||
| 11 | |||
| 12 | internal class GetFileFacadesCommand : ICommand | ||
| 13 | { | ||
| 14 | public Table FileTable { private get; set; } | ||
| 15 | |||
| 16 | public Table WixFileTable { private get; set; } | ||
| 17 | |||
| 18 | public Table WixDeltaPatchFileTable { private get; set; } | ||
| 19 | |||
| 20 | public Table WixDeltaPatchSymbolPathsTable { private get; set; } | ||
| 21 | |||
| 22 | public List<FileFacade> FileFacades { get; private set; } | ||
| 23 | |||
| 24 | public void Execute() | ||
| 25 | { | ||
| 26 | List<FileFacade> facades = new List<FileFacade>(this.FileTable.Rows.Count); | ||
| 27 | |||
| 28 | RowDictionary<WixFileRow> wixFiles = new RowDictionary<WixFileRow>(this.WixFileTable); | ||
| 29 | RowDictionary<WixDeltaPatchFileRow> deltaPatchFiles = new RowDictionary<WixDeltaPatchFileRow>(this.WixDeltaPatchFileTable); | ||
| 30 | |||
| 31 | foreach (FileRow file in this.FileTable.Rows) | ||
| 32 | { | ||
| 33 | WixDeltaPatchFileRow deltaPatchFile = null; | ||
| 34 | |||
| 35 | deltaPatchFiles.TryGetValue(file.File, out deltaPatchFile); | ||
| 36 | |||
| 37 | facades.Add(new FileFacade(file, wixFiles[file.File], deltaPatchFile)); | ||
| 38 | } | ||
| 39 | |||
| 40 | if (null != this.WixDeltaPatchSymbolPathsTable) | ||
| 41 | { | ||
| 42 | this.ResolveDeltaPatchSymbolPaths(deltaPatchFiles, facades); | ||
| 43 | } | ||
| 44 | |||
| 45 | this.FileFacades = facades; | ||
| 46 | } | ||
| 47 | |||
| 48 | /// <summary> | ||
| 49 | /// Merge data from the WixPatchSymbolPaths rows into the WixDeltaPatchFile rows. | ||
| 50 | /// </summary> | ||
| 51 | public RowDictionary<WixDeltaPatchFileRow> ResolveDeltaPatchSymbolPaths(RowDictionary<WixDeltaPatchFileRow> deltaPatchFiles, IEnumerable<FileFacade> facades) | ||
| 52 | { | ||
| 53 | ILookup<string, FileFacade> filesByComponent = null; | ||
| 54 | ILookup<string, FileFacade> filesByDirectory = null; | ||
| 55 | ILookup<string, FileFacade> filesByDiskId = null; | ||
| 56 | |||
| 57 | foreach (WixDeltaPatchSymbolPathsRow row in this.WixDeltaPatchSymbolPathsTable.RowsAs<WixDeltaPatchSymbolPathsRow>().OrderBy(r => r.Type)) | ||
| 58 | { | ||
| 59 | switch (row.Type) | ||
| 60 | { | ||
| 61 | case SymbolPathType.File: | ||
| 62 | this.MergeSymbolPaths(row, deltaPatchFiles[row.Id]); | ||
| 63 | break; | ||
| 64 | |||
| 65 | case SymbolPathType.Component: | ||
| 66 | if (null == filesByComponent) | ||
| 67 | { | ||
| 68 | filesByComponent = facades.ToLookup(f => f.File.Component); | ||
| 69 | } | ||
| 70 | |||
| 71 | foreach (FileFacade facade in filesByComponent[row.Id]) | ||
| 72 | { | ||
| 73 | this.MergeSymbolPaths(row, deltaPatchFiles[facade.File.File]); | ||
| 74 | } | ||
| 75 | break; | ||
| 76 | |||
| 77 | case SymbolPathType.Directory: | ||
| 78 | if (null == filesByDirectory) | ||
| 79 | { | ||
| 80 | filesByDirectory = facades.ToLookup(f => f.WixFile.Directory); | ||
| 81 | } | ||
| 82 | |||
| 83 | foreach (FileFacade facade in filesByDirectory[row.Id]) | ||
| 84 | { | ||
| 85 | this.MergeSymbolPaths(row, deltaPatchFiles[facade.File.File]); | ||
| 86 | } | ||
| 87 | break; | ||
| 88 | |||
| 89 | case SymbolPathType.Media: | ||
| 90 | if (null == filesByDiskId) | ||
| 91 | { | ||
| 92 | filesByDiskId = facades.ToLookup(f => f.WixFile.DiskId.ToString(CultureInfo.InvariantCulture)); | ||
| 93 | } | ||
| 94 | |||
| 95 | foreach (FileFacade facade in filesByDiskId[row.Id]) | ||
| 96 | { | ||
| 97 | this.MergeSymbolPaths(row, deltaPatchFiles[facade.File.File]); | ||
| 98 | } | ||
| 99 | break; | ||
| 100 | |||
| 101 | case SymbolPathType.Product: | ||
| 102 | foreach (WixDeltaPatchFileRow fileRow in deltaPatchFiles.Values) | ||
| 103 | { | ||
| 104 | this.MergeSymbolPaths(row, fileRow); | ||
| 105 | } | ||
| 106 | break; | ||
| 107 | |||
| 108 | default: | ||
| 109 | // error | ||
| 110 | break; | ||
| 111 | } | ||
| 112 | } | ||
| 113 | |||
| 114 | return deltaPatchFiles; | ||
| 115 | } | ||
| 116 | |||
| 117 | /// <summary> | ||
| 118 | /// Merge data from a row in the WixPatchSymbolsPaths table into an associated WixDeltaPatchFile row. | ||
| 119 | /// </summary> | ||
| 120 | /// <param name="row">Row from the WixPatchSymbolsPaths table.</param> | ||
| 121 | /// <param name="file">FileRow into which to set symbol information.</param> | ||
| 122 | /// <comment>This includes PreviousData as well.</comment> | ||
| 123 | private void MergeSymbolPaths(WixDeltaPatchSymbolPathsRow row, WixDeltaPatchFileRow file) | ||
| 124 | { | ||
| 125 | if (null == file.Symbols) | ||
| 126 | { | ||
| 127 | file.Symbols = row.SymbolPaths; | ||
| 128 | } | ||
| 129 | else | ||
| 130 | { | ||
| 131 | file.Symbols = String.Concat(file.Symbols, ";", row.SymbolPaths); | ||
| 132 | } | ||
| 133 | |||
| 134 | Field field = row.Fields[2]; | ||
| 135 | if (null != field.PreviousData) | ||
| 136 | { | ||
| 137 | if (null == file.PreviousSymbols) | ||
| 138 | { | ||
| 139 | file.PreviousSymbols = field.PreviousData; | ||
| 140 | } | ||
| 141 | else | ||
| 142 | { | ||
| 143 | file.PreviousSymbols = String.Concat(file.PreviousSymbols, ";", field.PreviousData); | ||
| 144 | } | ||
| 145 | } | ||
| 146 | } | ||
| 147 | } | ||
| 148 | } | ||
