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