aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core.WindowsInstaller/Bind/ExtractMergeModuleFilesCommand.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.Core.WindowsInstaller/Bind/ExtractMergeModuleFilesCommand.cs')
-rw-r--r--src/WixToolset.Core.WindowsInstaller/Bind/ExtractMergeModuleFilesCommand.cs51
1 files changed, 27 insertions, 24 deletions
diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/ExtractMergeModuleFilesCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/ExtractMergeModuleFilesCommand.cs
index 0d3e7bd1..32d1cfda 100644
--- a/src/WixToolset.Core.WindowsInstaller/Bind/ExtractMergeModuleFilesCommand.cs
+++ b/src/WixToolset.Core.WindowsInstaller/Bind/ExtractMergeModuleFilesCommand.cs
@@ -1,6 +1,6 @@
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. 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 2
3namespace WixToolset.Core.WindowsInstaller.Databases 3namespace WixToolset.Core.WindowsInstaller.Bind
4{ 4{
5 using System; 5 using System;
6 using System.Collections.Generic; 6 using System.Collections.Generic;
@@ -10,7 +10,6 @@ namespace WixToolset.Core.WindowsInstaller.Databases
10 using System.Linq; 10 using System.Linq;
11 using System.Runtime.InteropServices; 11 using System.Runtime.InteropServices;
12 using WixToolset.Data; 12 using WixToolset.Data;
13 using WixToolset.Data.Rows;
14 using WixToolset.MergeMod; 13 using WixToolset.MergeMod;
15 using WixToolset.Msi; 14 using WixToolset.Msi;
16 using WixToolset.Core.Native; 15 using WixToolset.Core.Native;
@@ -23,13 +22,17 @@ namespace WixToolset.Core.WindowsInstaller.Databases
23 /// </summary> 22 /// </summary>
24 internal class ExtractMergeModuleFilesCommand 23 internal class ExtractMergeModuleFilesCommand
25 { 24 {
26 public IEnumerable<FileFacade> FileFacades { private get; set; } 25 public ExtractMergeModuleFilesCommand(IntermediateSection section, List<WixMergeTuple> wixMergeTuples)
26 {
27 this.Section = section;
28 this.WixMergeTuples = wixMergeTuples;
29 }
27 30
28 public Table FileTable { private get; set; } 31 private IntermediateSection Section { get; }
29 32
30 public Table WixFileTable { private get; set; } 33 private List<WixMergeTuple> WixMergeTuples { get; }
31 34
32 public Table WixMergeTable { private get; set; } 35 public IEnumerable<FileFacade> FileFacades { private get; set; }
33 36
34 public int OutputInstallerVersion { private get; set; } 37 public int OutputInstallerVersion { private get; set; }
35 38
@@ -41,7 +44,7 @@ namespace WixToolset.Core.WindowsInstaller.Databases
41 44
42 public void Execute() 45 public void Execute()
43 { 46 {
44 List<FileFacade> mergeModulesFileFacades = new List<FileFacade>(); 47 var mergeModulesFileFacades = new List<FileFacade>();
45 48
46 IMsmMerge2 merge = MsmInterop.GetMsmMerge(); 49 IMsmMerge2 merge = MsmInterop.GetMsmMerge();
47 50
@@ -52,9 +55,9 @@ namespace WixToolset.Core.WindowsInstaller.Databases
52 // Now since Merge Modules are already slow and generally less desirable than .wixlibs we'll let 55 // Now since Merge Modules are already slow and generally less desirable than .wixlibs we'll let
53 // this case be slightly more expensive because the cost of maintaining an indexed file row collection 56 // this case be slightly more expensive because the cost of maintaining an indexed file row collection
54 // is a lot more costly for the common cases. 57 // is a lot more costly for the common cases.
55 Dictionary<string, FileFacade> indexedFileFacades = this.FileFacades.ToDictionary(f => f.File.File, StringComparer.Ordinal); 58 var indexedFileFacades = this.FileFacades.ToDictionary(f => f.File.File, StringComparer.Ordinal);
56 59
57 foreach (WixMergeRow wixMergeRow in this.WixMergeTable.Rows) 60 foreach (var wixMergeRow in this.WixMergeTuples)
58 { 61 {
59 bool containsFiles = this.CreateFacadesForMergeModuleFiles(wixMergeRow, mergeModulesFileFacades, indexedFileFacades); 62 bool containsFiles = this.CreateFacadesForMergeModuleFiles(wixMergeRow, mergeModulesFileFacades, indexedFileFacades);
60 63
@@ -68,7 +71,7 @@ namespace WixToolset.Core.WindowsInstaller.Databases
68 this.MergeModulesFileFacades = mergeModulesFileFacades; 71 this.MergeModulesFileFacades = mergeModulesFileFacades;
69 } 72 }
70 73
71 private bool CreateFacadesForMergeModuleFiles(WixMergeRow wixMergeRow, List<FileFacade> mergeModulesFileFacades, Dictionary<string, FileFacade> indexedFileFacades) 74 private bool CreateFacadesForMergeModuleFiles(WixMergeTuple wixMergeRow, List<FileFacade> mergeModulesFileFacades, Dictionary<string, FileFacade> indexedFileFacades)
72 { 75 {
73 bool containsFiles = false; 76 bool containsFiles = false;
74 77
@@ -98,7 +101,7 @@ namespace WixToolset.Core.WindowsInstaller.Databases
98 // rows are created by merging in the actual modules. 101 // rows are created by merging in the actual modules.
99 var fileRow = new FileTuple(wixMergeRow.SourceLineNumbers, new Identifier(record[1], AccessModifier.Private)); 102 var fileRow = new FileTuple(wixMergeRow.SourceLineNumbers, new Identifier(record[1], AccessModifier.Private));
100 fileRow.File = record[1]; 103 fileRow.File = record[1];
101 fileRow.Compressed = (wixMergeRow.FileCompression == YesNoType.Yes) ? true : (wixMergeRow.FileCompression == YesNoType.No) ? (bool?)false : null; 104 fileRow.Compressed = wixMergeRow.FileCompression;
102 //FileRow fileRow = (FileRow)this.FileTable.CreateRow(wixMergeRow.SourceLineNumbers, false); 105 //FileRow fileRow = (FileRow)this.FileTable.CreateRow(wixMergeRow.SourceLineNumbers, false);
103 //fileRow.File = record[1]; 106 //fileRow.File = record[1];
104 //fileRow.Compressed = wixMergeRow.FileCompression; 107 //fileRow.Compressed = wixMergeRow.FileCompression;
@@ -107,7 +110,7 @@ namespace WixToolset.Core.WindowsInstaller.Databases
107 wixFileRow.Directory_ = record[2]; 110 wixFileRow.Directory_ = record[2];
108 wixFileRow.DiskId = wixMergeRow.DiskId; 111 wixFileRow.DiskId = wixMergeRow.DiskId;
109 wixFileRow.PatchGroup = -1; 112 wixFileRow.PatchGroup = -1;
110 wixFileRow.Source = Path.Combine(this.IntermediateFolder, "MergeId.", wixMergeRow.Number.ToString(CultureInfo.InvariantCulture), record[1]); 113 wixFileRow.Source = Path.Combine(this.IntermediateFolder, wixMergeRow.Id.Id, record[1]);
111 //WixFileRow wixFileRow = (WixFileRow)this.WixFileTable.CreateRow(wixMergeRow.SourceLineNumbers, false); 114 //WixFileRow wixFileRow = (WixFileRow)this.WixFileTable.CreateRow(wixMergeRow.SourceLineNumbers, false);
112 //wixFileRow.Directory = record[2]; 115 //wixFileRow.Directory = record[2];
113 //wixFileRow.DiskId = wixMergeRow.DiskId; 116 //wixFileRow.DiskId = wixMergeRow.DiskId;
@@ -119,11 +122,11 @@ namespace WixToolset.Core.WindowsInstaller.Databases
119 // If case-sensitive collision with another merge module or a user-authored file identifier. 122 // If case-sensitive collision with another merge module or a user-authored file identifier.
120 if (indexedFileFacades.TryGetValue(mergeModuleFileFacade.File.File, out var collidingFacade)) 123 if (indexedFileFacades.TryGetValue(mergeModuleFileFacade.File.File, out var collidingFacade))
121 { 124 {
122 Messaging.Instance.OnMessage(WixErrors.DuplicateModuleFileIdentifier(wixMergeRow.SourceLineNumbers, wixMergeRow.Id, collidingFacade.File.File)); 125 Messaging.Instance.OnMessage(WixErrors.DuplicateModuleFileIdentifier(wixMergeRow.SourceLineNumbers, wixMergeRow.Id.Id, collidingFacade.File.File));
123 } 126 }
124 else if (uniqueModuleFileIdentifiers.TryGetValue(mergeModuleFileFacade.File.File, out collidingFacade)) // case-insensitive collision with another file identifier in the same merge module 127 else if (uniqueModuleFileIdentifiers.TryGetValue(mergeModuleFileFacade.File.File, out collidingFacade)) // case-insensitive collision with another file identifier in the same merge module
125 { 128 {
126 Messaging.Instance.OnMessage(WixErrors.DuplicateModuleCaseInsensitiveFileIdentifier(wixMergeRow.SourceLineNumbers, wixMergeRow.Id, mergeModuleFileFacade.File.File, collidingFacade.File.File)); 129 Messaging.Instance.OnMessage(WixErrors.DuplicateModuleCaseInsensitiveFileIdentifier(wixMergeRow.SourceLineNumbers, wixMergeRow.Id.Id, mergeModuleFileFacade.File.File, collidingFacade.File.File));
127 } 130 }
128 else // no collision 131 else // no collision
129 { 132 {
@@ -150,12 +153,12 @@ namespace WixToolset.Core.WindowsInstaller.Databases
150 int moduleInstallerVersion = Convert.ToInt32(moduleInstallerVersionString, CultureInfo.InvariantCulture); 153 int moduleInstallerVersion = Convert.ToInt32(moduleInstallerVersionString, CultureInfo.InvariantCulture);
151 if (moduleInstallerVersion > this.OutputInstallerVersion) 154 if (moduleInstallerVersion > this.OutputInstallerVersion)
152 { 155 {
153 Messaging.Instance.OnMessage(WixWarnings.InvalidHigherInstallerVersionInModule(wixMergeRow.SourceLineNumbers, wixMergeRow.Id, moduleInstallerVersion, this.OutputInstallerVersion)); 156 Messaging.Instance.OnMessage(WixWarnings.InvalidHigherInstallerVersionInModule(wixMergeRow.SourceLineNumbers, wixMergeRow.Id.Id, moduleInstallerVersion, this.OutputInstallerVersion));
154 } 157 }
155 } 158 }
156 catch (FormatException) 159 catch (FormatException)
157 { 160 {
158 throw new WixException(WixErrors.MissingOrInvalidModuleInstallerVersion(wixMergeRow.SourceLineNumbers, wixMergeRow.Id, wixMergeRow.SourceFile, moduleInstallerVersionString)); 161 throw new WixException(WixErrors.MissingOrInvalidModuleInstallerVersion(wixMergeRow.SourceLineNumbers, wixMergeRow.Id.Id, wixMergeRow.SourceFile, moduleInstallerVersionString));
159 } 162 }
160 } 163 }
161 } 164 }
@@ -166,24 +169,26 @@ namespace WixToolset.Core.WindowsInstaller.Databases
166 } 169 }
167 catch (Win32Exception) 170 catch (Win32Exception)
168 { 171 {
169 throw new WixException(WixErrors.CannotOpenMergeModule(wixMergeRow.SourceLineNumbers, wixMergeRow.Id, wixMergeRow.SourceFile)); 172 throw new WixException(WixErrors.CannotOpenMergeModule(wixMergeRow.SourceLineNumbers, wixMergeRow.Id.Id, wixMergeRow.SourceFile));
170 } 173 }
171 174
172 return containsFiles; 175 return containsFiles;
173 } 176 }
174 177
175 private void ExtractFilesFromMergeModule(IMsmMerge2 merge, WixMergeRow wixMergeRow) 178 private void ExtractFilesFromMergeModule(IMsmMerge2 merge, WixMergeTuple wixMergeRow)
176 { 179 {
177 bool moduleOpen = false; 180 bool moduleOpen = false;
178 short mergeLanguage; 181 short mergeLanguage;
179 182
183 var mergeId = wixMergeRow.Id.Id;
184
180 try 185 try
181 { 186 {
182 mergeLanguage = Convert.ToInt16(wixMergeRow.Language, CultureInfo.InvariantCulture); 187 mergeLanguage = Convert.ToInt16(wixMergeRow.Language, CultureInfo.InvariantCulture);
183 } 188 }
184 catch (System.FormatException) 189 catch (FormatException)
185 { 190 {
186 Messaging.Instance.OnMessage(WixErrors.InvalidMergeLanguage(wixMergeRow.SourceLineNumbers, wixMergeRow.Id, wixMergeRow.Language)); 191 Messaging.Instance.OnMessage(WixErrors.InvalidMergeLanguage(wixMergeRow.SourceLineNumbers, mergeId, wixMergeRow.Language.ToString()));
187 return; 192 return;
188 } 193 }
189 194
@@ -192,13 +197,11 @@ namespace WixToolset.Core.WindowsInstaller.Databases
192 merge.OpenModule(wixMergeRow.SourceFile, mergeLanguage); 197 merge.OpenModule(wixMergeRow.SourceFile, mergeLanguage);
193 moduleOpen = true; 198 moduleOpen = true;
194 199
195 string safeMergeId = wixMergeRow.Number.ToString(CultureInfo.InvariantCulture.NumberFormat);
196
197 // extract the module cabinet, then explode all of the files to a temp directory 200 // extract the module cabinet, then explode all of the files to a temp directory
198 string moduleCabPath = String.Concat(this.IntermediateFolder, Path.DirectorySeparatorChar, safeMergeId, ".module.cab"); 201 string moduleCabPath = Path.Combine(this.IntermediateFolder, mergeId + ".cab");
199 merge.ExtractCAB(moduleCabPath); 202 merge.ExtractCAB(moduleCabPath);
200 203
201 string mergeIdPath = String.Concat(this.IntermediateFolder, Path.DirectorySeparatorChar, "MergeId.", safeMergeId); 204 string mergeIdPath = Path.Combine(this.IntermediateFolder, mergeId);
202 Directory.CreateDirectory(mergeIdPath); 205 Directory.CreateDirectory(mergeIdPath);
203 206
204 using (var extractCab = new WixExtractCab()) 207 using (var extractCab = new WixExtractCab())