aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core.WindowsInstaller/Unbind
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2020-01-24 15:27:20 -0800
committerRob Mensching <rob@firegiant.com>2020-02-05 16:15:47 -0800
commit6ff680e386b1543ad1a58d1b1d465ce8aa20bc7d (patch)
treec717333cd10d5592e59dfb898b391275bba1f389 /src/WixToolset.Core.WindowsInstaller/Unbind
parent6e2e67ab55c75f4655397588c0dcc64f50d22f92 (diff)
downloadwix-6ff680e386b1543ad1a58d1b1d465ce8aa20bc7d.tar.gz
wix-6ff680e386b1543ad1a58d1b1d465ce8aa20bc7d.tar.bz2
wix-6ff680e386b1543ad1a58d1b1d465ce8aa20bc7d.zip
Start on new patch infrastructure
Diffstat (limited to 'src/WixToolset.Core.WindowsInstaller/Unbind')
-rw-r--r--src/WixToolset.Core.WindowsInstaller/Unbind/UnbindMsiOrMsmCommand.cs2
-rw-r--r--src/WixToolset.Core.WindowsInstaller/Unbind/UnbindTranformCommand.cs125
2 files changed, 59 insertions, 68 deletions
diff --git a/src/WixToolset.Core.WindowsInstaller/Unbind/UnbindMsiOrMsmCommand.cs b/src/WixToolset.Core.WindowsInstaller/Unbind/UnbindMsiOrMsmCommand.cs
index eca51caf..eea0fe23 100644
--- a/src/WixToolset.Core.WindowsInstaller/Unbind/UnbindMsiOrMsmCommand.cs
+++ b/src/WixToolset.Core.WindowsInstaller/Unbind/UnbindMsiOrMsmCommand.cs
@@ -19,7 +19,7 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
19 19
20 public Intermediate Execute() 20 public Intermediate Execute()
21 { 21 {
22#if REVISIT_FOR_PATCHING 22#if TODO_PATCHING
23 Output output; 23 Output output;
24 24
25 try 25 try
diff --git a/src/WixToolset.Core.WindowsInstaller/Unbind/UnbindTranformCommand.cs b/src/WixToolset.Core.WindowsInstaller/Unbind/UnbindTranformCommand.cs
index bdf8d542..9261fda0 100644
--- a/src/WixToolset.Core.WindowsInstaller/Unbind/UnbindTranformCommand.cs
+++ b/src/WixToolset.Core.WindowsInstaller/Unbind/UnbindTranformCommand.cs
@@ -4,6 +4,7 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
4{ 4{
5 using System; 5 using System;
6 using System.Collections; 6 using System.Collections;
7 using System.Collections.Generic;
7 using System.ComponentModel; 8 using System.ComponentModel;
8 using System.Globalization; 9 using System.Globalization;
9 using System.IO; 10 using System.IO;
@@ -12,7 +13,6 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
12 using WixToolset.Core.WindowsInstaller.Msi; 13 using WixToolset.Core.WindowsInstaller.Msi;
13 using WixToolset.Data; 14 using WixToolset.Data;
14 using WixToolset.Data.WindowsInstaller; 15 using WixToolset.Data.WindowsInstaller;
15 using WixToolset.Extensibility;
16 using WixToolset.Extensibility.Services; 16 using WixToolset.Extensibility.Services;
17 17
18 internal class UnbindTransformCommand 18 internal class UnbindTransformCommand
@@ -41,21 +41,21 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
41 41
42 public WindowsInstallerData Execute() 42 public WindowsInstallerData Execute()
43 { 43 {
44 WindowsInstallerData transform = new WindowsInstallerData(new SourceLineNumber(this.TransformFile)); 44 var transform = new WindowsInstallerData(new SourceLineNumber(this.TransformFile));
45 transform.Type = OutputType.Transform; 45 transform.Type = OutputType.Transform;
46 46
47 // get the summary information table 47 // get the summary information table
48 using (SummaryInformation summaryInformation = new SummaryInformation(this.TransformFile)) 48 using (var summaryInformation = new SummaryInformation(this.TransformFile))
49 { 49 {
50 Table table = transform.EnsureTable(this.TableDefinitions["_SummaryInformation"]); 50 var table = transform.EnsureTable(this.TableDefinitions["_SummaryInformation"]);
51 51
52 for (int i = 1; 19 >= i; i++) 52 for (var i = 1; 19 >= i; i++)
53 { 53 {
54 string value = summaryInformation.GetProperty(i); 54 var value = summaryInformation.GetProperty(i);
55 55
56 if (0 < value.Length) 56 if (0 < value.Length)
57 { 57 {
58 Row row = table.CreateRow(transform.SourceLineNumbers); 58 var row = table.CreateRow(transform.SourceLineNumbers);
59 row[0] = i; 59 row[0] = i;
60 row[1] = value; 60 row[1] = value;
61 } 61 }
@@ -63,9 +63,9 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
63 } 63 }
64 64
65 // create a schema msi which hopefully matches the table schemas in the transform 65 // create a schema msi which hopefully matches the table schemas in the transform
66 WindowsInstallerData schemaOutput = new WindowsInstallerData(null); 66 var schemaOutput = new WindowsInstallerData(null);
67 string msiDatabaseFile = Path.Combine(this.IntermediateFolder, "schema.msi"); 67 var msiDatabaseFile = Path.Combine(this.IntermediateFolder, "schema.msi");
68 foreach (TableDefinition tableDefinition in this.TableDefinitions) 68 foreach (var tableDefinition in this.TableDefinitions)
69 { 69 {
70 // skip unreal tables and the Patch table 70 // skip unreal tables and the Patch table
71 if (!tableDefinition.Unreal && "Patch" != tableDefinition.Name) 71 if (!tableDefinition.Unreal && "Patch" != tableDefinition.Name)
@@ -74,40 +74,40 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
74 } 74 }
75 } 75 }
76 76
77 Hashtable addedRows = new Hashtable(); 77 var addedRows = new Dictionary<string, Row>();
78 Table transformViewTable; 78 Table transformViewTable;
79 79
80 // Bind the schema msi. 80 // Bind the schema msi.
81 this.GenerateDatabase(schemaOutput, msiDatabaseFile); 81 this.GenerateDatabase(schemaOutput, msiDatabaseFile);
82 82
83 // apply the transform to the database and retrieve the modifications 83 // apply the transform to the database and retrieve the modifications
84 using (Database msiDatabase = new Database(msiDatabaseFile, OpenDatabase.Transact)) 84 using (var msiDatabase = new Database(msiDatabaseFile, OpenDatabase.Transact))
85 { 85 {
86 // apply the transform with the ViewTransform option to collect all the modifications 86 // apply the transform with the ViewTransform option to collect all the modifications
87 msiDatabase.ApplyTransform(this.TransformFile, TransformErrorConditions.All | TransformErrorConditions.ViewTransform); 87 msiDatabase.ApplyTransform(this.TransformFile, TransformErrorConditions.All | TransformErrorConditions.ViewTransform);
88 88
89 // unbind the database 89 // unbind the database
90 var unbindCommand = new UnbindDatabaseCommand(this.Messaging, msiDatabase, msiDatabaseFile, OutputType.Product, this.ExportBasePath, this.IntermediateFolder, false, false, skipSummaryInfo: true); 90 var unbindCommand = new UnbindDatabaseCommand(this.Messaging, msiDatabase, msiDatabaseFile, OutputType.Product, this.ExportBasePath, this.IntermediateFolder, false, false, skipSummaryInfo: true);
91 WindowsInstallerData transformViewOutput = unbindCommand.Execute(); 91 var transformViewOutput = unbindCommand.Execute();
92 92
93 // index the added and possibly modified rows (added rows may also appears as modified rows) 93 // index the added and possibly modified rows (added rows may also appears as modified rows)
94 transformViewTable = transformViewOutput.Tables["_TransformView"]; 94 transformViewTable = transformViewOutput.Tables["_TransformView"];
95 Hashtable modifiedRows = new Hashtable(); 95 var modifiedRows = new Hashtable();
96 foreach (Row row in transformViewTable.Rows) 96 foreach (var row in transformViewTable.Rows)
97 { 97 {
98 string tableName = (string)row[0]; 98 var tableName = (string)row[0];
99 string columnName = (string)row[1]; 99 var columnName = (string)row[1];
100 string primaryKeys = (string)row[2]; 100 var primaryKeys = (string)row[2];
101 101
102 if ("INSERT" == columnName) 102 if ("INSERT" == columnName)
103 { 103 {
104 string index = String.Concat(tableName, ':', primaryKeys); 104 var index = String.Concat(tableName, ':', primaryKeys);
105 105
106 addedRows.Add(index, null); 106 addedRows.Add(index, null);
107 } 107 }
108 else if ("CREATE" != columnName && "DELETE" != columnName && "DROP" != columnName && null != primaryKeys) // modified row 108 else if ("CREATE" != columnName && "DELETE" != columnName && "DROP" != columnName && null != primaryKeys) // modified row
109 { 109 {
110 string index = String.Concat(tableName, ':', primaryKeys); 110 var index = String.Concat(tableName, ':', primaryKeys);
111 111
112 modifiedRows[index] = row; 112 modifiedRows[index] = row;
113 } 113 }
@@ -116,16 +116,16 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
116 // create placeholder rows for modified rows to make the transform insert the updated values when its applied 116 // create placeholder rows for modified rows to make the transform insert the updated values when its applied
117 foreach (Row row in modifiedRows.Values) 117 foreach (Row row in modifiedRows.Values)
118 { 118 {
119 string tableName = (string)row[0]; 119 var tableName = (string)row[0];
120 string columnName = (string)row[1]; 120 var columnName = (string)row[1];
121 string primaryKeys = (string)row[2]; 121 var primaryKeys = (string)row[2];
122 122
123 string index = String.Concat(tableName, ':', primaryKeys); 123 var index = String.Concat(tableName, ':', primaryKeys);
124 124
125 // ignore information for added rows 125 // ignore information for added rows
126 if (!addedRows.Contains(index)) 126 if (!addedRows.ContainsKey(index))
127 { 127 {
128 Table table = schemaOutput.Tables[tableName]; 128 var table = schemaOutput.Tables[tableName];
129 this.CreateRow(table, primaryKeys, true); 129 this.CreateRow(table, primaryKeys, true);
130 } 130 }
131 } 131 }
@@ -135,7 +135,7 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
135 this.GenerateDatabase(schemaOutput, msiDatabaseFile); 135 this.GenerateDatabase(schemaOutput, msiDatabaseFile);
136 136
137 // apply the transform to the database and retrieve the modifications 137 // apply the transform to the database and retrieve the modifications
138 using (Database msiDatabase = new Database(msiDatabaseFile, OpenDatabase.Transact)) 138 using (var msiDatabase = new Database(msiDatabaseFile, OpenDatabase.Transact))
139 { 139 {
140 try 140 try
141 { 141 {
@@ -158,26 +158,26 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
158 158
159 // unbind the database 159 // unbind the database
160 var unbindCommand = new UnbindDatabaseCommand(this.Messaging, msiDatabase, msiDatabaseFile, OutputType.Product, this.ExportBasePath, this.IntermediateFolder, false, false, skipSummaryInfo: true); 160 var unbindCommand = new UnbindDatabaseCommand(this.Messaging, msiDatabase, msiDatabaseFile, OutputType.Product, this.ExportBasePath, this.IntermediateFolder, false, false, skipSummaryInfo: true);
161 WindowsInstallerData output = unbindCommand.Execute(); 161 var output = unbindCommand.Execute();
162 162
163 // index all the rows to easily find modified rows 163 // index all the rows to easily find modified rows
164 Hashtable rows = new Hashtable(); 164 var rows = new Dictionary<string, Row>();
165 foreach (Table table in output.Tables) 165 foreach (var table in output.Tables)
166 { 166 {
167 foreach (Row row in table.Rows) 167 foreach (var row in table.Rows)
168 { 168 {
169 rows.Add(String.Concat(table.Name, ':', row.GetPrimaryKey('\t', " ")), row); 169 rows.Add(String.Concat(table.Name, ':', row.GetPrimaryKey('\t', " ")), row);
170 } 170 }
171 } 171 }
172 172
173 // process the _TransformView rows into transform rows 173 // process the _TransformView rows into transform rows
174 foreach (Row row in transformViewTable.Rows) 174 foreach (var row in transformViewTable.Rows)
175 { 175 {
176 string tableName = (string)row[0]; 176 var tableName = (string)row[0];
177 string columnName = (string)row[1]; 177 var columnName = (string)row[1];
178 string primaryKeys = (string)row[2]; 178 var primaryKeys = (string)row[2];
179 179
180 Table table = transform.EnsureTable(this.TableDefinitions[tableName]); 180 var table = transform.EnsureTable(this.TableDefinitions[tableName]);
181 181
182 if ("CREATE" == columnName) // added table 182 if ("CREATE" == columnName) // added table
183 { 183 {
@@ -185,7 +185,7 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
185 } 185 }
186 else if ("DELETE" == columnName) // deleted row 186 else if ("DELETE" == columnName) // deleted row
187 { 187 {
188 Row deletedRow = this.CreateRow(table, primaryKeys, false); 188 var deletedRow = this.CreateRow(table, primaryKeys, false);
189 deletedRow.Operation = RowOperation.Delete; 189 deletedRow.Operation = RowOperation.Delete;
190 } 190 }
191 else if ("DROP" == columnName) // dropped table 191 else if ("DROP" == columnName) // dropped table
@@ -194,24 +194,24 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
194 } 194 }
195 else if ("INSERT" == columnName) // added row 195 else if ("INSERT" == columnName) // added row
196 { 196 {
197 string index = String.Concat(tableName, ':', primaryKeys); 197 var index = String.Concat(tableName, ':', primaryKeys);
198 Row addedRow = (Row)rows[index]; 198 var addedRow = rows[index];
199 addedRow.Operation = RowOperation.Add; 199 addedRow.Operation = RowOperation.Add;
200 table.Rows.Add(addedRow); 200 table.Rows.Add(addedRow);
201 } 201 }
202 else if (null != primaryKeys) // modified row 202 else if (null != primaryKeys) // modified row
203 { 203 {
204 string index = String.Concat(tableName, ':', primaryKeys); 204 var index = String.Concat(tableName, ':', primaryKeys);
205 205
206 // the _TransformView table includes information for added rows 206 // the _TransformView table includes information for added rows
207 // that looks like modified rows so it sometimes needs to be ignored 207 // that looks like modified rows so it sometimes needs to be ignored
208 if (!addedRows.Contains(index)) 208 if (!addedRows.ContainsKey(index))
209 { 209 {
210 Row modifiedRow = (Row)rows[index]; 210 var modifiedRow = rows[index];
211 211
212 // mark the field as modified 212 // mark the field as modified
213 int indexOfModifiedValue = -1; 213 var indexOfModifiedValue = -1;
214 for (int i = 0; i < modifiedRow.TableDefinition.Columns.Length; ++i) 214 for (var i = 0; i < modifiedRow.TableDefinition.Columns.Length; ++i)
215 { 215 {
216 if (columnName.Equals(modifiedRow.TableDefinition.Columns[i].Name, StringComparison.Ordinal)) 216 if (columnName.Equals(modifiedRow.TableDefinition.Columns[i].Name, StringComparison.Ordinal))
217 { 217 {
@@ -231,7 +231,7 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
231 } 231 }
232 else // added column 232 else // added column
233 { 233 {
234 ColumnDefinition column = table.Definition.Columns.Single(c => c.Name.Equals(columnName, StringComparison.Ordinal)); 234 var column = table.Definition.Columns.Single(c => c.Name.Equals(columnName, StringComparison.Ordinal));
235 column.Added = true; 235 column.Added = true;
236 } 236 }
237 } 237 }
@@ -240,21 +240,6 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
240 return transform; 240 return transform;
241 } 241 }
242 242
243 private void GenerateDatabase(WindowsInstallerData output, string databaseFile)
244 {
245 var command = new GenerateDatabaseCommand();
246 command.Extensions = Array.Empty<IFileSystemExtension>();
247 command.Output = output;
248 command.OutputPath = databaseFile;
249 command.KeepAddedColumns = true;
250 command.UseSubDirectory = false;
251 command.SuppressAddingValidationRows = true;
252 command.TableDefinitions = this.TableDefinitions;
253 command.IntermediateFolder = this.IntermediateFolder;
254 command.Codepage = -1;
255 command.Execute();
256 }
257
258 /// <summary> 243 /// <summary>
259 /// Create a deleted or modified row. 244 /// Create a deleted or modified row.
260 /// </summary> 245 /// </summary>
@@ -264,14 +249,14 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
264 /// <returns>The new row.</returns> 249 /// <returns>The new row.</returns>
265 private Row CreateRow(Table table, string primaryKeys, bool setRequiredFields) 250 private Row CreateRow(Table table, string primaryKeys, bool setRequiredFields)
266 { 251 {
267 Row row = table.CreateRow(null); 252 var row = table.CreateRow(null);
268 253
269 string[] primaryKeyParts = primaryKeys.Split('\t'); 254 var primaryKeyParts = primaryKeys.Split('\t');
270 int primaryKeyPartIndex = 0; 255 var primaryKeyPartIndex = 0;
271 256
272 for (int i = 0; i < table.Definition.Columns.Length; i++) 257 for (var i = 0; i < table.Definition.Columns.Length; i++)
273 { 258 {
274 ColumnDefinition columnDefinition = table.Definition.Columns[i]; 259 var columnDefinition = table.Definition.Columns[i];
275 260
276 if (columnDefinition.PrimaryKey) 261 if (columnDefinition.PrimaryKey)
277 { 262 {
@@ -294,8 +279,8 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
294 { 279 {
295 if (null == this.EmptyFile) 280 if (null == this.EmptyFile)
296 { 281 {
297 this.EmptyFile = Path.GetTempFileName() + ".empty"; 282 this.EmptyFile = Path.Combine(this.IntermediateFolder, ".empty");
298 using (FileStream fileStream = File.Create(this.EmptyFile)) 283 using (var fileStream = File.Create(this.EmptyFile))
299 { 284 {
300 } 285 }
301 } 286 }
@@ -311,5 +296,11 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
311 296
312 return row; 297 return row;
313 } 298 }
299
300 private void GenerateDatabase(WindowsInstallerData output, string databaseFile)
301 {
302 var command = new GenerateDatabaseCommand(this.Messaging, null, null, output, databaseFile, this.TableDefinitions, this.IntermediateFolder, codepage: -1, keepAddedColumns: true, suppressAddingValidationRows: true, useSubdirectory: false);
303 command.Execute();
304 }
314 } 305 }
315} 306}