diff options
| author | Rob Mensching <rob@firegiant.com> | 2020-06-25 14:43:50 -0700 |
|---|---|---|
| committer | Rob Mensching <rob@firegiant.com> | 2020-06-25 14:50:31 -0700 |
| commit | 38afa9e7bc7eacc021f8805f607368a05751e3c3 (patch) | |
| tree | 803b0a8d9a06a7d6f7c4df408437017ae21a883e /src/WixToolset.Core.WindowsInstaller/Bind/AssignMediaCommand.cs | |
| parent | 8968578d50858721317d410549a9f9b5c62bf1f7 (diff) | |
| download | wix-38afa9e7bc7eacc021f8805f607368a05751e3c3.tar.gz wix-38afa9e7bc7eacc021f8805f607368a05751e3c3.tar.bz2 wix-38afa9e7bc7eacc021f8805f607368a05751e3c3.zip | |
The Great Tuple to Symbol Rename (tm)
Diffstat (limited to 'src/WixToolset.Core.WindowsInstaller/Bind/AssignMediaCommand.cs')
| -rw-r--r-- | src/WixToolset.Core.WindowsInstaller/Bind/AssignMediaCommand.cs | 100 |
1 files changed, 50 insertions, 50 deletions
diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/AssignMediaCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/AssignMediaCommand.cs index 773b3225..eccc97d2 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/AssignMediaCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/AssignMediaCommand.cs | |||
| @@ -8,7 +8,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind | |||
| 8 | using System.Linq; | 8 | using System.Linq; |
| 9 | using WixToolset.Core.Bind; | 9 | using WixToolset.Core.Bind; |
| 10 | using WixToolset.Data; | 10 | using WixToolset.Data; |
| 11 | using WixToolset.Data.Tuples; | 11 | using WixToolset.Data.Symbols; |
| 12 | using WixToolset.Extensibility.Services; | 12 | using WixToolset.Extensibility.Services; |
| 13 | 13 | ||
| 14 | /// <summary> | 14 | /// <summary> |
| @@ -40,7 +40,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind | |||
| 40 | /// <summary> | 40 | /// <summary> |
| 41 | /// Gets cabinets with their file rows. | 41 | /// Gets cabinets with their file rows. |
| 42 | /// </summary> | 42 | /// </summary> |
| 43 | public Dictionary<MediaTuple, IEnumerable<FileFacade>> FileFacadesByCabinetMedia { get; private set; } | 43 | public Dictionary<MediaSymbol, IEnumerable<FileFacade>> FileFacadesByCabinetMedia { get; private set; } |
| 44 | 44 | ||
| 45 | /// <summary> | 45 | /// <summary> |
| 46 | /// Get uncompressed file rows. This will contain file rows of File elements that are marked with compression=no. | 46 | /// Get uncompressed file rows. This will contain file rows of File elements that are marked with compression=no. |
| @@ -50,49 +50,49 @@ namespace WixToolset.Core.WindowsInstaller.Bind | |||
| 50 | 50 | ||
| 51 | public void Execute() | 51 | public void Execute() |
| 52 | { | 52 | { |
| 53 | var mediaTuples = this.Section.Tuples.OfType<MediaTuple>().ToList(); | 53 | var mediaSymbols = this.Section.Symbols.OfType<MediaSymbol>().ToList(); |
| 54 | var mediaTemplateTuples = this.Section.Tuples.OfType<WixMediaTemplateTuple>().ToList(); | 54 | var mediaTemplateSymbols = this.Section.Symbols.OfType<WixMediaTemplateSymbol>().ToList(); |
| 55 | 55 | ||
| 56 | // If both tuples are authored, it is an error. | 56 | // If both symbols are authored, it is an error. |
| 57 | if (mediaTemplateTuples.Count > 0 && mediaTuples.Count > 1) | 57 | if (mediaTemplateSymbols.Count > 0 && mediaSymbols.Count > 1) |
| 58 | { | 58 | { |
| 59 | throw new WixException(ErrorMessages.MediaTableCollision(null)); | 59 | throw new WixException(ErrorMessages.MediaTableCollision(null)); |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | // If neither tuple is authored, default to a media template. | 62 | // If neither symbol is authored, default to a media template. |
| 63 | if (SectionType.Product == this.Section.Type && mediaTemplateTuples.Count == 0 && mediaTuples.Count == 0) | 63 | if (SectionType.Product == this.Section.Type && mediaTemplateSymbols.Count == 0 && mediaSymbols.Count == 0) |
| 64 | { | 64 | { |
| 65 | var mediaTemplate = new WixMediaTemplateTuple() | 65 | var mediaTemplate = new WixMediaTemplateSymbol() |
| 66 | { | 66 | { |
| 67 | CabinetTemplate = "cab{0}.cab", | 67 | CabinetTemplate = "cab{0}.cab", |
| 68 | }; | 68 | }; |
| 69 | 69 | ||
| 70 | this.Section.AddTuple(mediaTemplate); | 70 | this.Section.AddSymbol(mediaTemplate); |
| 71 | mediaTemplateTuples.Add(mediaTemplate); | 71 | mediaTemplateSymbols.Add(mediaTemplate); |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | // When building merge module, all the files go to "#MergeModule.CABinet". | 74 | // When building merge module, all the files go to "#MergeModule.CABinet". |
| 75 | if (SectionType.Module == this.Section.Type) | 75 | if (SectionType.Module == this.Section.Type) |
| 76 | { | 76 | { |
| 77 | var mergeModuleMediaTuple = this.Section.AddTuple(new MediaTuple | 77 | var mergeModuleMediaSymbol = this.Section.AddSymbol(new MediaSymbol |
| 78 | { | 78 | { |
| 79 | Cabinet = "#MergeModule.CABinet", | 79 | Cabinet = "#MergeModule.CABinet", |
| 80 | }); | 80 | }); |
| 81 | 81 | ||
| 82 | this.FileFacadesByCabinetMedia = new Dictionary<MediaTuple, IEnumerable<FileFacade>> | 82 | this.FileFacadesByCabinetMedia = new Dictionary<MediaSymbol, IEnumerable<FileFacade>> |
| 83 | { | 83 | { |
| 84 | { mergeModuleMediaTuple, this.FileFacades } | 84 | { mergeModuleMediaSymbol, this.FileFacades } |
| 85 | }; | 85 | }; |
| 86 | 86 | ||
| 87 | this.UncompressedFileFacades = Array.Empty<FileFacade>(); | 87 | this.UncompressedFileFacades = Array.Empty<FileFacade>(); |
| 88 | } | 88 | } |
| 89 | else if (mediaTemplateTuples.Count == 0) | 89 | else if (mediaTemplateSymbols.Count == 0) |
| 90 | { | 90 | { |
| 91 | var filesByCabinetMedia = new Dictionary<MediaTuple, List<FileFacade>>(); | 91 | var filesByCabinetMedia = new Dictionary<MediaSymbol, List<FileFacade>>(); |
| 92 | 92 | ||
| 93 | var uncompressedFiles = new List<FileFacade>(); | 93 | var uncompressedFiles = new List<FileFacade>(); |
| 94 | 94 | ||
| 95 | this.ManuallyAssignFiles(mediaTuples, filesByCabinetMedia, uncompressedFiles); | 95 | this.ManuallyAssignFiles(mediaSymbols, filesByCabinetMedia, uncompressedFiles); |
| 96 | 96 | ||
| 97 | this.FileFacadesByCabinetMedia = filesByCabinetMedia.ToDictionary(kvp => kvp.Key, kvp => (IEnumerable<FileFacade>)kvp.Value); | 97 | this.FileFacadesByCabinetMedia = filesByCabinetMedia.ToDictionary(kvp => kvp.Key, kvp => (IEnumerable<FileFacade>)kvp.Value); |
| 98 | 98 | ||
| @@ -100,11 +100,11 @@ namespace WixToolset.Core.WindowsInstaller.Bind | |||
| 100 | } | 100 | } |
| 101 | else | 101 | else |
| 102 | { | 102 | { |
| 103 | var filesByCabinetMedia = new Dictionary<MediaTuple, List<FileFacade>>(); | 103 | var filesByCabinetMedia = new Dictionary<MediaSymbol, List<FileFacade>>(); |
| 104 | 104 | ||
| 105 | var uncompressedFiles = new List<FileFacade>(); | 105 | var uncompressedFiles = new List<FileFacade>(); |
| 106 | 106 | ||
| 107 | this.AutoAssignFiles(mediaTuples, filesByCabinetMedia, uncompressedFiles); | 107 | this.AutoAssignFiles(mediaSymbols, filesByCabinetMedia, uncompressedFiles); |
| 108 | 108 | ||
| 109 | this.FileFacadesByCabinetMedia = filesByCabinetMedia.ToDictionary(kvp => kvp.Key, kvp => (IEnumerable<FileFacade>)kvp.Value); | 109 | this.FileFacadesByCabinetMedia = filesByCabinetMedia.ToDictionary(kvp => kvp.Key, kvp => (IEnumerable<FileFacade>)kvp.Value); |
| 110 | 110 | ||
| @@ -116,7 +116,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind | |||
| 116 | /// Assign files to cabinets based on MediaTemplate authoring. | 116 | /// Assign files to cabinets based on MediaTemplate authoring. |
| 117 | /// </summary> | 117 | /// </summary> |
| 118 | /// <param name="fileFacades">FileRowCollection</param> | 118 | /// <param name="fileFacades">FileRowCollection</param> |
| 119 | private void AutoAssignFiles(List<MediaTuple> mediaTable, Dictionary<MediaTuple, List<FileFacade>> filesByCabinetMedia, List<FileFacade> uncompressedFiles) | 119 | private void AutoAssignFiles(List<MediaSymbol> mediaTable, Dictionary<MediaSymbol, List<FileFacade>> filesByCabinetMedia, List<FileFacade> uncompressedFiles) |
| 120 | { | 120 | { |
| 121 | const int MaxCabIndex = 999; | 121 | const int MaxCabIndex = 999; |
| 122 | 122 | ||
| @@ -125,15 +125,15 @@ namespace WixToolset.Core.WindowsInstaller.Bind | |||
| 125 | var maxPreCabSizeInMB = 0; | 125 | var maxPreCabSizeInMB = 0; |
| 126 | var currentCabIndex = 0; | 126 | var currentCabIndex = 0; |
| 127 | 127 | ||
| 128 | MediaTuple currentMediaRow = null; | 128 | MediaSymbol currentMediaRow = null; |
| 129 | 129 | ||
| 130 | var mediaTemplateTable = this.Section.Tuples.OfType<WixMediaTemplateTuple>(); | 130 | var mediaTemplateTable = this.Section.Symbols.OfType<WixMediaTemplateSymbol>(); |
| 131 | 131 | ||
| 132 | // Remove all previous media tuples since they will be replaced with | 132 | // Remove all previous media symbols since they will be replaced with |
| 133 | // media template. | 133 | // media template. |
| 134 | foreach (var mediaTuple in mediaTable) | 134 | foreach (var mediaSymbol in mediaTable) |
| 135 | { | 135 | { |
| 136 | this.Section.Tuples.Remove(mediaTuple); | 136 | this.Section.Symbols.Remove(mediaSymbol); |
| 137 | } | 137 | } |
| 138 | 138 | ||
| 139 | // Auto assign files to cabinets based on maximum uncompressed media size | 139 | // Auto assign files to cabinets based on maximum uncompressed media size |
| @@ -169,7 +169,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind | |||
| 169 | throw new WixException(ErrorMessages.MaximumUncompressedMediaSizeTooLarge(null, maxPreCabSizeInMB)); | 169 | throw new WixException(ErrorMessages.MaximumUncompressedMediaSizeTooLarge(null, maxPreCabSizeInMB)); |
| 170 | } | 170 | } |
| 171 | 171 | ||
| 172 | var mediaTuplesByDiskId = new Dictionary<int, MediaTuple>(); | 172 | var mediaSymbolsByDiskId = new Dictionary<int, MediaSymbol>(); |
| 173 | 173 | ||
| 174 | foreach (var facade in this.FileFacades) | 174 | foreach (var facade in this.FileFacades) |
| 175 | { | 175 | { |
| @@ -193,8 +193,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind | |||
| 193 | // Overflow due to current file | 193 | // Overflow due to current file |
| 194 | if (currentPreCabSize > maxPreCabSizeInBytes) | 194 | if (currentPreCabSize > maxPreCabSizeInBytes) |
| 195 | { | 195 | { |
| 196 | currentMediaRow = this.AddMediaTuple(mediaTemplateRow, ++currentCabIndex); | 196 | currentMediaRow = this.AddMediaSymbol(mediaTemplateRow, ++currentCabIndex); |
| 197 | mediaTuplesByDiskId.Add(currentMediaRow.DiskId, currentMediaRow); | 197 | mediaSymbolsByDiskId.Add(currentMediaRow.DiskId, currentMediaRow); |
| 198 | filesByCabinetMedia.Add(currentMediaRow, new List<FileFacade>()); | 198 | filesByCabinetMedia.Add(currentMediaRow, new List<FileFacade>()); |
| 199 | 199 | ||
| 200 | // Now files larger than MaxUncompressedMediaSize will be the only file in its cabinet so as to respect MaxUncompressedMediaSize | 200 | // Now files larger than MaxUncompressedMediaSize will be the only file in its cabinet so as to respect MaxUncompressedMediaSize |
| @@ -205,8 +205,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind | |||
| 205 | if (currentMediaRow == null) | 205 | if (currentMediaRow == null) |
| 206 | { | 206 | { |
| 207 | // Create new cab and MediaRow | 207 | // Create new cab and MediaRow |
| 208 | currentMediaRow = this.AddMediaTuple(mediaTemplateRow, ++currentCabIndex); | 208 | currentMediaRow = this.AddMediaSymbol(mediaTemplateRow, ++currentCabIndex); |
| 209 | mediaTuplesByDiskId.Add(currentMediaRow.DiskId, currentMediaRow); | 209 | mediaSymbolsByDiskId.Add(currentMediaRow.DiskId, currentMediaRow); |
| 210 | filesByCabinetMedia.Add(currentMediaRow, new List<FileFacade>()); | 210 | filesByCabinetMedia.Add(currentMediaRow, new List<FileFacade>()); |
| 211 | } | 211 | } |
| 212 | } | 212 | } |
| @@ -219,52 +219,52 @@ namespace WixToolset.Core.WindowsInstaller.Bind | |||
| 219 | } | 219 | } |
| 220 | 220 | ||
| 221 | // If there are uncompressed files and no MediaRow, create a default one. | 221 | // If there are uncompressed files and no MediaRow, create a default one. |
| 222 | if (uncompressedFiles.Count > 0 && !this.Section.Tuples.OfType<MediaTuple>().Any()) | 222 | if (uncompressedFiles.Count > 0 && !this.Section.Symbols.OfType<MediaSymbol>().Any()) |
| 223 | { | 223 | { |
| 224 | var defaultMediaRow = this.Section.AddTuple(new MediaTuple(null, new Identifier(AccessModifier.Private, 1)) | 224 | var defaultMediaRow = this.Section.AddSymbol(new MediaSymbol(null, new Identifier(AccessModifier.Private, 1)) |
| 225 | { | 225 | { |
| 226 | DiskId = 1, | 226 | DiskId = 1, |
| 227 | }); | 227 | }); |
| 228 | 228 | ||
| 229 | mediaTuplesByDiskId.Add(1, defaultMediaRow); | 229 | mediaSymbolsByDiskId.Add(1, defaultMediaRow); |
| 230 | } | 230 | } |
| 231 | } | 231 | } |
| 232 | 232 | ||
| 233 | /// <summary> | 233 | /// <summary> |
| 234 | /// Assign files to cabinets based on Media authoring. | 234 | /// Assign files to cabinets based on Media authoring. |
| 235 | /// </summary> | 235 | /// </summary> |
| 236 | private void ManuallyAssignFiles(List<MediaTuple> mediaTuples, Dictionary<MediaTuple, List<FileFacade>> filesByCabinetMedia, List<FileFacade> uncompressedFiles) | 236 | private void ManuallyAssignFiles(List<MediaSymbol> mediaSymbols, Dictionary<MediaSymbol, List<FileFacade>> filesByCabinetMedia, List<FileFacade> uncompressedFiles) |
| 237 | { | 237 | { |
| 238 | var mediaTuplesByDiskId = new Dictionary<int, MediaTuple>(); | 238 | var mediaSymbolsByDiskId = new Dictionary<int, MediaSymbol>(); |
| 239 | 239 | ||
| 240 | if (mediaTuples.Any()) | 240 | if (mediaSymbols.Any()) |
| 241 | { | 241 | { |
| 242 | var cabinetMediaTuples = new Dictionary<string, MediaTuple>(StringComparer.OrdinalIgnoreCase); | 242 | var cabinetMediaSymbols = new Dictionary<string, MediaSymbol>(StringComparer.OrdinalIgnoreCase); |
| 243 | foreach (var mediaTuple in mediaTuples) | 243 | foreach (var mediaSymbol in mediaSymbols) |
| 244 | { | 244 | { |
| 245 | // If the Media row has a cabinet, make sure it is unique across all Media rows. | 245 | // If the Media row has a cabinet, make sure it is unique across all Media rows. |
| 246 | if (!String.IsNullOrEmpty(mediaTuple.Cabinet)) | 246 | if (!String.IsNullOrEmpty(mediaSymbol.Cabinet)) |
| 247 | { | 247 | { |
| 248 | if (cabinetMediaTuples.TryGetValue(mediaTuple.Cabinet, out var existingRow)) | 248 | if (cabinetMediaSymbols.TryGetValue(mediaSymbol.Cabinet, out var existingRow)) |
| 249 | { | 249 | { |
| 250 | this.Messaging.Write(ErrorMessages.DuplicateCabinetName(mediaTuple.SourceLineNumbers, mediaTuple.Cabinet)); | 250 | this.Messaging.Write(ErrorMessages.DuplicateCabinetName(mediaSymbol.SourceLineNumbers, mediaSymbol.Cabinet)); |
| 251 | this.Messaging.Write(ErrorMessages.DuplicateCabinetName2(existingRow.SourceLineNumbers, existingRow.Cabinet)); | 251 | this.Messaging.Write(ErrorMessages.DuplicateCabinetName2(existingRow.SourceLineNumbers, existingRow.Cabinet)); |
| 252 | } | 252 | } |
| 253 | else | 253 | else |
| 254 | { | 254 | { |
| 255 | cabinetMediaTuples.Add(mediaTuple.Cabinet, mediaTuple); | 255 | cabinetMediaSymbols.Add(mediaSymbol.Cabinet, mediaSymbol); |
| 256 | } | 256 | } |
| 257 | 257 | ||
| 258 | filesByCabinetMedia.Add(mediaTuple, new List<FileFacade>()); | 258 | filesByCabinetMedia.Add(mediaSymbol, new List<FileFacade>()); |
| 259 | } | 259 | } |
| 260 | 260 | ||
| 261 | mediaTuplesByDiskId.Add(mediaTuple.DiskId, mediaTuple); | 261 | mediaSymbolsByDiskId.Add(mediaSymbol.DiskId, mediaSymbol); |
| 262 | } | 262 | } |
| 263 | } | 263 | } |
| 264 | 264 | ||
| 265 | foreach (var facade in this.FileFacades) | 265 | foreach (var facade in this.FileFacades) |
| 266 | { | 266 | { |
| 267 | if (!mediaTuplesByDiskId.TryGetValue(facade.DiskId, out var mediaTuple)) | 267 | if (!mediaSymbolsByDiskId.TryGetValue(facade.DiskId, out var mediaSymbol)) |
| 268 | { | 268 | { |
| 269 | this.Messaging.Write(ErrorMessages.MissingMedia(facade.SourceLineNumber, facade.DiskId)); | 269 | this.Messaging.Write(ErrorMessages.MissingMedia(facade.SourceLineNumber, facade.DiskId)); |
| 270 | continue; | 270 | continue; |
| @@ -280,7 +280,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind | |||
| 280 | } | 280 | } |
| 281 | else // file is marked compressed. | 281 | else // file is marked compressed. |
| 282 | { | 282 | { |
| 283 | if (filesByCabinetMedia.TryGetValue(mediaTuple, out var cabinetFiles)) | 283 | if (filesByCabinetMedia.TryGetValue(mediaSymbol, out var cabinetFiles)) |
| 284 | { | 284 | { |
| 285 | cabinetFiles.Add(facade); | 285 | cabinetFiles.Add(facade); |
| 286 | } | 286 | } |
| @@ -293,18 +293,18 @@ namespace WixToolset.Core.WindowsInstaller.Bind | |||
| 293 | } | 293 | } |
| 294 | 294 | ||
| 295 | /// <summary> | 295 | /// <summary> |
| 296 | /// Adds a tuple to the section with cab name template filled in. | 296 | /// Adds a symbol to the section with cab name template filled in. |
| 297 | /// </summary> | 297 | /// </summary> |
| 298 | /// <param name="mediaTable"></param> | 298 | /// <param name="mediaTable"></param> |
| 299 | /// <param name="cabIndex"></param> | 299 | /// <param name="cabIndex"></param> |
| 300 | /// <returns></returns> | 300 | /// <returns></returns> |
| 301 | private MediaTuple AddMediaTuple(WixMediaTemplateTuple mediaTemplateTuple, int cabIndex) | 301 | private MediaSymbol AddMediaSymbol(WixMediaTemplateSymbol mediaTemplateSymbol, int cabIndex) |
| 302 | { | 302 | { |
| 303 | return this.Section.AddTuple(new MediaTuple(mediaTemplateTuple.SourceLineNumbers, new Identifier(AccessModifier.Private, cabIndex)) | 303 | return this.Section.AddSymbol(new MediaSymbol(mediaTemplateSymbol.SourceLineNumbers, new Identifier(AccessModifier.Private, cabIndex)) |
| 304 | { | 304 | { |
| 305 | DiskId = cabIndex, | 305 | DiskId = cabIndex, |
| 306 | Cabinet = String.Format(CultureInfo.InvariantCulture, this.CabinetNameTemplate, cabIndex), | 306 | Cabinet = String.Format(CultureInfo.InvariantCulture, this.CabinetNameTemplate, cabIndex), |
| 307 | CompressionLevel = mediaTemplateTuple.CompressionLevel, | 307 | CompressionLevel = mediaTemplateSymbol.CompressionLevel, |
| 308 | }); | 308 | }); |
| 309 | } | 309 | } |
| 310 | } | 310 | } |
