aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core.WindowsInstaller/Unbind/UnbindDatabaseCommand.cs
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2018-10-24 21:00:13 -0700
committerRob Mensching <rob@robmensching.com>2018-10-24 21:17:34 -0700
commit0ecb2ac1ba28d33b0b3d17a2d7134d2f5485814d (patch)
tree42ce582bfc472c8b1bada41696670ed94e6ddff6 /src/WixToolset.Core.WindowsInstaller/Unbind/UnbindDatabaseCommand.cs
parent0a67f66835c882763e1504895cbec3acb9284f3d (diff)
downloadwix-0ecb2ac1ba28d33b0b3d17a2d7134d2f5485814d.tar.gz
wix-0ecb2ac1ba28d33b0b3d17a2d7134d2f5485814d.tar.bz2
wix-0ecb2ac1ba28d33b0b3d17a2d7134d2f5485814d.zip
Minor code clean up to match .editorconfig
Diffstat (limited to 'src/WixToolset.Core.WindowsInstaller/Unbind/UnbindDatabaseCommand.cs')
-rw-r--r--src/WixToolset.Core.WindowsInstaller/Unbind/UnbindDatabaseCommand.cs460
1 files changed, 231 insertions, 229 deletions
diff --git a/src/WixToolset.Core.WindowsInstaller/Unbind/UnbindDatabaseCommand.cs b/src/WixToolset.Core.WindowsInstaller/Unbind/UnbindDatabaseCommand.cs
index f4e05489..3bbc29f1 100644
--- a/src/WixToolset.Core.WindowsInstaller/Unbind/UnbindDatabaseCommand.cs
+++ b/src/WixToolset.Core.WindowsInstaller/Unbind/UnbindDatabaseCommand.cs
@@ -1,4 +1,4 @@
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.Unbind 3namespace WixToolset.Core.WindowsInstaller.Unbind
4{ 4{
@@ -57,21 +57,23 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
57 public Output Execute() 57 public Output Execute()
58 { 58 {
59 string modularizationGuid = null; 59 string modularizationGuid = null;
60 Output output = new Output(new SourceLineNumber(this.DatabasePath)); 60 var output = new Output(new SourceLineNumber(this.DatabasePath));
61 View validationView = null; 61 View validationView = null;
62 62
63 // set the output type 63 // set the output type
64 output.Type = this.OutputType; 64 output.Type = this.OutputType;
65 65
66 Directory.CreateDirectory(this.IntermediateFolder);
67
66 // get the codepage 68 // get the codepage
67 this.Database.Export("_ForceCodepage", this.IntermediateFolder, "_ForceCodepage.idt"); 69 this.Database.Export("_ForceCodepage", this.IntermediateFolder, "_ForceCodepage.idt");
68 using (StreamReader sr = File.OpenText(Path.Combine(this.IntermediateFolder, "_ForceCodepage.idt"))) 70 using (var sr = File.OpenText(Path.Combine(this.IntermediateFolder, "_ForceCodepage.idt")))
69 { 71 {
70 string line; 72 string line;
71 73
72 while (null != (line = sr.ReadLine())) 74 while (null != (line = sr.ReadLine()))
73 { 75 {
74 string[] data = line.Split('\t'); 76 var data = line.Split('\t');
75 77
76 if (2 == data.Length) 78 if (2 == data.Length)
77 { 79 {
@@ -83,17 +85,17 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
83 // get the summary information table if it exists; it won't if unbinding a transform 85 // get the summary information table if it exists; it won't if unbinding a transform
84 if (!this.SkipSummaryInfo) 86 if (!this.SkipSummaryInfo)
85 { 87 {
86 using (SummaryInformation summaryInformation = new SummaryInformation(this.Database)) 88 using (var summaryInformation = new SummaryInformation(this.Database))
87 { 89 {
88 Table table = new Table(this.TableDefinitions["_SummaryInformation"]); 90 var table = new Table(this.TableDefinitions["_SummaryInformation"]);
89 91
90 for (int i = 1; 19 >= i; i++) 92 for (var i = 1; 19 >= i; i++)
91 { 93 {
92 string value = summaryInformation.GetProperty(i); 94 var value = summaryInformation.GetProperty(i);
93 95
94 if (0 < value.Length) 96 if (0 < value.Length)
95 { 97 {
96 Row row = table.CreateRow(output.SourceLineNumbers); 98 var row = table.CreateRow(output.SourceLineNumbers);
97 row[0] = i; 99 row[0] = i;
98 row[1] = value; 100 row[1] = value;
99 } 101 }
@@ -112,51 +114,51 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
112 } 114 }
113 115
114 // get the normal tables 116 // get the normal tables
115 using (View tablesView = this.Database.OpenExecuteView("SELECT * FROM _Tables")) 117 using (var tablesView = this.Database.OpenExecuteView("SELECT * FROM _Tables"))
116 { 118 {
117 while (true) 119 while (true)
118 { 120 {
119 using (Record tableRecord = tablesView.Fetch()) 121 using (var tableRecord = tablesView.Fetch())
120 { 122 {
121 if (null == tableRecord) 123 if (null == tableRecord)
122 { 124 {
123 break; 125 break;
124 } 126 }
125 127
126 string tableName = tableRecord.GetString(1); 128 var tableName = tableRecord.GetString(1);
127 129
128 using (View tableView = this.Database.OpenExecuteView(String.Format(CultureInfo.InvariantCulture, "SELECT * FROM `{0}`", tableName))) 130 using (var tableView = this.Database.OpenExecuteView(String.Format(CultureInfo.InvariantCulture, "SELECT * FROM `{0}`", tableName)))
129 { 131 {
130 ColumnDefinition[] columns; 132 ColumnDefinition[] columns;
131 using (Record columnNameRecord = tableView.GetColumnInfo(MsiInterop.MSICOLINFONAMES), 133 using (Record columnNameRecord = tableView.GetColumnInfo(MsiInterop.MSICOLINFONAMES),
132 columnTypeRecord = tableView.GetColumnInfo(MsiInterop.MSICOLINFOTYPES)) 134 columnTypeRecord = tableView.GetColumnInfo(MsiInterop.MSICOLINFOTYPES))
133 { 135 {
134 // index the primary keys 136 // index the primary keys
135 HashSet<string> tablePrimaryKeys = new HashSet<string>(); 137 var tablePrimaryKeys = new HashSet<string>();
136 using (Record primaryKeysRecord = this.Database.PrimaryKeys(tableName)) 138 using (var primaryKeysRecord = this.Database.PrimaryKeys(tableName))
137 { 139 {
138 int primaryKeysFieldCount = primaryKeysRecord.GetFieldCount(); 140 var primaryKeysFieldCount = primaryKeysRecord.GetFieldCount();
139 141
140 for (int i = 1; i <= primaryKeysFieldCount; i++) 142 for (var i = 1; i <= primaryKeysFieldCount; i++)
141 { 143 {
142 tablePrimaryKeys.Add(primaryKeysRecord.GetString(i)); 144 tablePrimaryKeys.Add(primaryKeysRecord.GetString(i));
143 } 145 }
144 } 146 }
145 147
146 int columnCount = columnNameRecord.GetFieldCount(); 148 var columnCount = columnNameRecord.GetFieldCount();
147 columns = new ColumnDefinition[columnCount]; 149 columns = new ColumnDefinition[columnCount];
148 for (int i = 1; i <= columnCount; i++) 150 for (var i = 1; i <= columnCount; i++)
149 { 151 {
150 string columnName = columnNameRecord.GetString(i); 152 var columnName = columnNameRecord.GetString(i);
151 string idtType = columnTypeRecord.GetString(i); 153 var idtType = columnTypeRecord.GetString(i);
152 154
153 ColumnType columnType; 155 ColumnType columnType;
154 int length; 156 int length;
155 bool nullable; 157 bool nullable;
156 158
157 ColumnCategory columnCategory = ColumnCategory.Unknown; 159 var columnCategory = ColumnCategory.Unknown;
158 ColumnModularizeType columnModularizeType = ColumnModularizeType.None; 160 var columnModularizeType = ColumnModularizeType.None;
159 bool primary = tablePrimaryKeys.Contains(columnName); 161 var primary = tablePrimaryKeys.Contains(columnName);
160 int? minValue = null; 162 int? minValue = null;
161 int? maxValue = null; 163 int? maxValue = null;
162 string keyTable = null; 164 string keyTable = null;
@@ -168,22 +170,22 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
168 // get the column type, length, and whether its nullable 170 // get the column type, length, and whether its nullable
169 switch (Char.ToLower(idtType[0], CultureInfo.InvariantCulture)) 171 switch (Char.ToLower(idtType[0], CultureInfo.InvariantCulture))
170 { 172 {
171 case 'i': 173 case 'i':
172 columnType = ColumnType.Number; 174 columnType = ColumnType.Number;
173 break; 175 break;
174 case 'l': 176 case 'l':
175 columnType = ColumnType.Localized; 177 columnType = ColumnType.Localized;
176 break; 178 break;
177 case 's': 179 case 's':
178 columnType = ColumnType.String; 180 columnType = ColumnType.String;
179 break; 181 break;
180 case 'v': 182 case 'v':
181 columnType = ColumnType.Object; 183 columnType = ColumnType.Object;
182 break; 184 break;
183 default: 185 default:
184 // TODO: error 186 // TODO: error
185 columnType = ColumnType.Unknown; 187 columnType = ColumnType.Unknown;
186 break; 188 break;
187 } 189 }
188 length = Convert.ToInt32(idtType.Substring(1), CultureInfo.InvariantCulture); 190 length = Convert.ToInt32(idtType.Substring(1), CultureInfo.InvariantCulture);
189 nullable = Char.IsUpper(idtType[0]); 191 nullable = Char.IsUpper(idtType[0]);
@@ -191,7 +193,7 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
191 // try to get validation information 193 // try to get validation information
192 if (null != validationView) 194 if (null != validationView)
193 { 195 {
194 using (Record validationRecord = new Record(2)) 196 using (var validationRecord = new Record(2))
195 { 197 {
196 validationRecord.SetString(1, tableName); 198 validationRecord.SetString(1, tableName);
197 validationRecord.SetString(2, columnName); 199 validationRecord.SetString(2, columnName);
@@ -199,11 +201,11 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
199 validationView.Execute(validationRecord); 201 validationView.Execute(validationRecord);
200 } 202 }
201 203
202 using (Record validationRecord = validationView.Fetch()) 204 using (var validationRecord = validationView.Fetch())
203 { 205 {
204 if (null != validationRecord) 206 if (null != validationRecord)
205 { 207 {
206 string validationNullable = validationRecord.GetString(3); 208 var validationNullable = validationRecord.GetString(3);
207 minValue = validationRecord.IsNull(4) ? null : (int?)validationRecord.GetInteger(4); 209 minValue = validationRecord.IsNull(4) ? null : (int?)validationRecord.GetInteger(4);
208 maxValue = validationRecord.IsNull(5) ? null : (int?)validationRecord.GetInteger(5); 210 maxValue = validationRecord.IsNull(5) ? null : (int?)validationRecord.GetInteger(5);
209 keyTable = validationRecord.IsNull(6) ? null : validationRecord.GetString(6); 211 keyTable = validationRecord.IsNull(6) ? null : validationRecord.GetString(6);
@@ -264,7 +266,7 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
264 } 266 }
265 } 267 }
266 268
267 TableDefinition tableDefinition = new TableDefinition(tableName, columns, false, false); 269 var tableDefinition = new TableDefinition(tableName, columns, false, false);
268 270
269 // use our table definitions if core properties are the same; this allows us to take advantage 271 // use our table definitions if core properties are the same; this allows us to take advantage
270 // of wix concepts like localizable columns which current code assumes 272 // of wix concepts like localizable columns which current code assumes
@@ -273,21 +275,21 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
273 tableDefinition = this.TableDefinitions[tableName]; 275 tableDefinition = this.TableDefinitions[tableName];
274 } 276 }
275 277
276 Table table = new Table(tableDefinition); 278 var table = new Table(tableDefinition);
277 279
278 while (true) 280 while (true)
279 { 281 {
280 using (Record rowRecord = tableView.Fetch()) 282 using (var rowRecord = tableView.Fetch())
281 { 283 {
282 if (null == rowRecord) 284 if (null == rowRecord)
283 { 285 {
284 break; 286 break;
285 } 287 }
286 288
287 int recordCount = rowRecord.GetFieldCount(); 289 var recordCount = rowRecord.GetFieldCount();
288 Row row = table.CreateRow(output.SourceLineNumbers); 290 var row = table.CreateRow(output.SourceLineNumbers);
289 291
290 for (int i = 0; recordCount > i && row.Fields.Length > i; i++) 292 for (var i = 0; recordCount > i && row.Fields.Length > i; i++)
291 { 293 {
292 if (rowRecord.IsNull(i + 1)) 294 if (rowRecord.IsNull(i + 1))
293 { 295 {
@@ -303,87 +305,87 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
303 { 305 {
304 switch (row.Fields[i].Column.Type) 306 switch (row.Fields[i].Column.Type)
305 { 307 {
306 case ColumnType.Number: 308 case ColumnType.Number:
307 bool success = false; 309 var success = false;
308 int intValue = rowRecord.GetInteger(i + 1); 310 var intValue = rowRecord.GetInteger(i + 1);
309 if (row.Fields[i].Column.IsLocalizable) 311 if (row.Fields[i].Column.IsLocalizable)
310 { 312 {
311 success = row.BestEffortSetField(i, Convert.ToString(intValue, CultureInfo.InvariantCulture)); 313 success = row.BestEffortSetField(i, Convert.ToString(intValue, CultureInfo.InvariantCulture));
312 } 314 }
313 else 315 else
314 { 316 {
315 success = row.BestEffortSetField(i, intValue); 317 success = row.BestEffortSetField(i, intValue);
316 } 318 }
317 319
318 if (!success) 320 if (!success)
319 { 321 {
320 this.Messaging.Write(WarningMessages.BadColumnDataIgnored(row.SourceLineNumbers, Convert.ToString(intValue, CultureInfo.InvariantCulture), tableName, row.Fields[i].Column.Name)); 322 this.Messaging.Write(WarningMessages.BadColumnDataIgnored(row.SourceLineNumbers, Convert.ToString(intValue, CultureInfo.InvariantCulture), tableName, row.Fields[i].Column.Name));
321 } 323 }
322 break; 324 break;
323 case ColumnType.Object: 325 case ColumnType.Object:
324 string sourceFile = "FILE NOT EXPORTED, USE THE dark.exe -x OPTION TO EXPORT BINARIES"; 326 var sourceFile = "FILE NOT EXPORTED, USE THE dark.exe -x OPTION TO EXPORT BINARIES";
325 327
326 if (null != this.ExportBasePath) 328 if (null != this.ExportBasePath)
327 { 329 {
328 string relativeSourceFile = Path.Combine(tableName, row.GetPrimaryKey('.')); 330 var relativeSourceFile = Path.Combine(tableName, row.GetPrimaryKey('.'));
329 sourceFile = Path.Combine(this.ExportBasePath, relativeSourceFile); 331 sourceFile = Path.Combine(this.ExportBasePath, relativeSourceFile);
330 332
331 // ensure the parent directory exists 333 // ensure the parent directory exists
332 System.IO.Directory.CreateDirectory(Path.Combine(this.ExportBasePath, tableName)); 334 System.IO.Directory.CreateDirectory(Path.Combine(this.ExportBasePath, tableName));
333 335
334 using (FileStream fs = System.IO.File.Create(sourceFile)) 336 using (var fs = System.IO.File.Create(sourceFile))
335 { 337 {
336 int bytesRead; 338 int bytesRead;
337 byte[] buffer = new byte[512]; 339 var buffer = new byte[512];
338 340
339 while (0 != (bytesRead = rowRecord.GetStream(i + 1, buffer, buffer.Length))) 341 while (0 != (bytesRead = rowRecord.GetStream(i + 1, buffer, buffer.Length)))
340 { 342 {
341 fs.Write(buffer, 0, bytesRead); 343 fs.Write(buffer, 0, bytesRead);
342 }
343 } 344 }
344 } 345 }
346 }
345 347
346 row[i] = sourceFile; 348 row[i] = sourceFile;
349 break;
350 default:
351 var value = rowRecord.GetString(i + 1);
352
353 switch (row.Fields[i].Column.Category)
354 {
355 case ColumnCategory.Guid:
356 value = value.ToUpper(CultureInfo.InvariantCulture);
347 break; 357 break;
348 default: 358 }
349 string value = rowRecord.GetString(i + 1);
350 359
351 switch (row.Fields[i].Column.Category) 360 // de-modularize
352 { 361 if (!this.SuppressDemodularization && OutputType.Module == output.Type && ColumnModularizeType.None != row.Fields[i].Column.ModularizeType)
353 case ColumnCategory.Guid: 362 {
354 value = value.ToUpper(CultureInfo.InvariantCulture); 363 var modularization = new Regex(@"\.[0-9A-Fa-f]{8}_[0-9A-Fa-f]{4}_[0-9A-Fa-f]{4}_[0-9A-Fa-f]{4}_[0-9A-Fa-f]{12}");
355 break;
356 }
357 364
358 // de-modularize 365 if (null == modularizationGuid)
359 if (!this.SuppressDemodularization && OutputType.Module == output.Type && ColumnModularizeType.None != row.Fields[i].Column.ModularizeType)
360 { 366 {
361 Regex modularization = new Regex(@"\.[0-9A-Fa-f]{8}_[0-9A-Fa-f]{4}_[0-9A-Fa-f]{4}_[0-9A-Fa-f]{4}_[0-9A-Fa-f]{12}"); 367 var match = modularization.Match(value);
362 368 if (match.Success)
363 if (null == modularizationGuid)
364 { 369 {
365 Match match = modularization.Match(value); 370 modularizationGuid = String.Concat('{', match.Value.Substring(1).Replace('_', '-'), '}');
366 if (match.Success)
367 {
368 modularizationGuid = String.Concat('{', match.Value.Substring(1).Replace('_', '-'), '}');
369 }
370 } 371 }
371
372 value = modularization.Replace(value, String.Empty);
373 } 372 }
374 373
375 // escape "$(" for the preprocessor 374 value = modularization.Replace(value, String.Empty);
376 value = value.Replace("$(", "$$("); 375 }
377 376
378 // escape things that look like wix variables 377 // escape "$(" for the preprocessor
379 MatchCollection matches = Common.WixVariableRegex.Matches(value); 378 value = value.Replace("$(", "$$(");
380 for (int j = matches.Count - 1; 0 <= j; j--)
381 {
382 value = value.Insert(matches[j].Index, "!");
383 }
384 379
385 row[i] = value; 380 // escape things that look like wix variables
386 break; 381 var matches = Common.WixVariableRegex.Matches(value);
382 for (var j = matches.Count - 1; 0 <= j; j--)
383 {
384 value = value.Insert(matches[j].Index, "!");
385 }
386
387 row[i] = value;
388 break;
387 } 389 }
388 } 390 }
389 } 391 }
@@ -408,9 +410,9 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
408 // set the modularization guid as the PackageCode 410 // set the modularization guid as the PackageCode
409 if (null != modularizationGuid) 411 if (null != modularizationGuid)
410 { 412 {
411 Table table = output.Tables["_SummaryInformation"]; 413 var table = output.Tables["_SummaryInformation"];
412 414
413 foreach (Row row in table.Rows) 415 foreach (var row in table.Rows)
414 { 416 {
415 if (9 == (int)row[0]) // PID_REVNUMBER 417 if (9 == (int)row[0]) // PID_REVNUMBER
416 { 418 {
@@ -421,8 +423,8 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
421 423
422 if (this.IsAdminImage) 424 if (this.IsAdminImage)
423 { 425 {
424 GenerateWixFileTable(this.DatabasePath, output); 426 this.GenerateWixFileTable(this.DatabasePath, output);
425 GenerateSectionIds(output); 427 this.GenerateSectionIds(output);
426 } 428 }
427 429
428 return output; 430 return output;
@@ -435,21 +437,21 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
435 /// <param name="output">The Output that represents the msi database.</param> 437 /// <param name="output">The Output that represents the msi database.</param>
436 private void GenerateWixFileTable(string databaseFile, Output output) 438 private void GenerateWixFileTable(string databaseFile, Output output)
437 { 439 {
438 string adminRootPath = Path.GetDirectoryName(databaseFile); 440 var adminRootPath = Path.GetDirectoryName(databaseFile);
439 441
440 Hashtable componentDirectoryIndex = new Hashtable(); 442 var componentDirectoryIndex = new Hashtable();
441 Table componentTable = output.Tables["Component"]; 443 var componentTable = output.Tables["Component"];
442 foreach (Row row in componentTable.Rows) 444 foreach (var row in componentTable.Rows)
443 { 445 {
444 componentDirectoryIndex.Add(row[0], row[2]); 446 componentDirectoryIndex.Add(row[0], row[2]);
445 } 447 }
446 448
447 // Index full source paths for all directories 449 // Index full source paths for all directories
448 Hashtable directoryDirectoryParentIndex = new Hashtable(); 450 var directoryDirectoryParentIndex = new Hashtable();
449 Hashtable directoryFullPathIndex = new Hashtable(); 451 var directoryFullPathIndex = new Hashtable();
450 Hashtable directorySourceNameIndex = new Hashtable(); 452 var directorySourceNameIndex = new Hashtable();
451 Table directoryTable = output.Tables["Directory"]; 453 var directoryTable = output.Tables["Directory"];
452 foreach (Row row in directoryTable.Rows) 454 foreach (var row in directoryTable.Rows)
453 { 455 {
454 directoryDirectoryParentIndex.Add(row[0], row[1]); 456 directoryDirectoryParentIndex.Add(row[0], row[1]);
455 if (null == row[1]) 457 if (null == row[1])
@@ -466,15 +468,15 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
466 { 468 {
467 if (!directoryFullPathIndex.ContainsKey(directoryEntry.Key)) 469 if (!directoryFullPathIndex.ContainsKey(directoryEntry.Key))
468 { 470 {
469 GetAdminFullPath((string)directoryEntry.Key, directoryDirectoryParentIndex, directorySourceNameIndex, directoryFullPathIndex); 471 this.GetAdminFullPath((string)directoryEntry.Key, directoryDirectoryParentIndex, directorySourceNameIndex, directoryFullPathIndex);
470 } 472 }
471 } 473 }
472 474
473 Table fileTable = output.Tables["File"]; 475 var fileTable = output.Tables["File"];
474 Table wixFileTable = output.EnsureTable(this.TableDefinitions["WixFile"]); 476 var wixFileTable = output.EnsureTable(this.TableDefinitions["WixFile"]);
475 foreach (Row row in fileTable.Rows) 477 foreach (var row in fileTable.Rows)
476 { 478 {
477 WixFileRow wixFileRow = new WixFileRow(null, this.TableDefinitions["WixFile"]); 479 var wixFileRow = new WixFileRow(null, this.TableDefinitions["WixFile"]);
478 wixFileRow.File = (string)row[0]; 480 wixFileRow.File = (string)row[0];
479 wixFileRow.Directory = (string)componentDirectoryIndex[(string)row[1]]; 481 wixFileRow.Directory = (string)componentDirectoryIndex[(string)row[1]];
480 wixFileRow.Source = Path.Combine((string)directoryFullPathIndex[wixFileRow.Directory], GetAdminSourceName((string)row[2])); 482 wixFileRow.Source = Path.Combine((string)directoryFullPathIndex[wixFileRow.Directory], GetAdminSourceName((string)row[2]));
@@ -498,8 +500,8 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
498 /// <returns>The full path to the directory.</returns> 500 /// <returns>The full path to the directory.</returns>
499 private string GetAdminFullPath(string directory, Hashtable directoryDirectoryParentIndex, Hashtable directorySourceNameIndex, Hashtable directoryFullPathIndex) 501 private string GetAdminFullPath(string directory, Hashtable directoryDirectoryParentIndex, Hashtable directorySourceNameIndex, Hashtable directoryFullPathIndex)
500 { 502 {
501 string parent = (string)directoryDirectoryParentIndex[directory]; 503 var parent = (string)directoryDirectoryParentIndex[directory];
502 string sourceName = (string)directorySourceNameIndex[directory]; 504 var sourceName = (string)directorySourceNameIndex[directory];
503 505
504 string parentFullPath; 506 string parentFullPath;
505 if (directoryFullPathIndex.ContainsKey(parent)) 507 if (directoryFullPathIndex.ContainsKey(parent))
@@ -508,7 +510,7 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
508 } 510 }
509 else 511 else
510 { 512 {
511 parentFullPath = GetAdminFullPath(parent, directoryDirectoryParentIndex, directorySourceNameIndex, directoryFullPathIndex); 513 parentFullPath = this.GetAdminFullPath(parent, directoryDirectoryParentIndex, directorySourceNameIndex, directoryFullPathIndex);
512 } 514 }
513 515
514 if (null == sourceName) 516 if (null == sourceName)
@@ -516,7 +518,7 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
516 sourceName = String.Empty; 518 sourceName = String.Empty;
517 } 519 }
518 520
519 string fullPath = Path.Combine(parentFullPath, sourceName); 521 var fullPath = Path.Combine(parentFullPath, sourceName);
520 directoryFullPathIndex.Add(directory, fullPath); 522 directoryFullPathIndex.Add(directory, fullPath);
521 523
522 return fullPath; 524 return fullPath;
@@ -596,104 +598,104 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
596 private void GenerateSectionIds(Output output) 598 private void GenerateSectionIds(Output output)
597 { 599 {
598 // First assign and index section ids for the tables that are in their own sections. 600 // First assign and index section ids for the tables that are in their own sections.
599 AssignSectionIdsToTable(output.Tables["Binary"], 0); 601 this.AssignSectionIdsToTable(output.Tables["Binary"], 0);
600 Hashtable componentSectionIdIndex = AssignSectionIdsToTable(output.Tables["Component"], 0); 602 var componentSectionIdIndex = this.AssignSectionIdsToTable(output.Tables["Component"], 0);
601 Hashtable customActionSectionIdIndex = AssignSectionIdsToTable(output.Tables["CustomAction"], 0); 603 var customActionSectionIdIndex = this.AssignSectionIdsToTable(output.Tables["CustomAction"], 0);
602 AssignSectionIdsToTable(output.Tables["Directory"], 0); 604 this.AssignSectionIdsToTable(output.Tables["Directory"], 0);
603 Hashtable featureSectionIdIndex = AssignSectionIdsToTable(output.Tables["Feature"], 0); 605 var featureSectionIdIndex = this.AssignSectionIdsToTable(output.Tables["Feature"], 0);
604 AssignSectionIdsToTable(output.Tables["Icon"], 0); 606 this.AssignSectionIdsToTable(output.Tables["Icon"], 0);
605 Hashtable digitalCertificateSectionIdIndex = AssignSectionIdsToTable(output.Tables["MsiDigitalCertificate"], 0); 607 var digitalCertificateSectionIdIndex = this.AssignSectionIdsToTable(output.Tables["MsiDigitalCertificate"], 0);
606 AssignSectionIdsToTable(output.Tables["Property"], 0); 608 this.AssignSectionIdsToTable(output.Tables["Property"], 0);
607 609
608 // Now handle all the tables that rely on the first set of indexes but also produce their own indexes. Order matters here. 610 // Now handle all the tables that rely on the first set of indexes but also produce their own indexes. Order matters here.
609 Hashtable fileSectionIdIndex = ConnectTableToSectionAndIndex(output.Tables["File"], componentSectionIdIndex, 1, 0); 611 var fileSectionIdIndex = ConnectTableToSectionAndIndex(output.Tables["File"], componentSectionIdIndex, 1, 0);
610 Hashtable appIdSectionIdIndex = ConnectTableToSectionAndIndex(output.Tables["Class"], componentSectionIdIndex, 2, 5); 612 var appIdSectionIdIndex = ConnectTableToSectionAndIndex(output.Tables["Class"], componentSectionIdIndex, 2, 5);
611 Hashtable odbcDataSourceSectionIdIndex = ConnectTableToSectionAndIndex(output.Tables["ODBCDataSource"], componentSectionIdIndex, 1, 0); 613 var odbcDataSourceSectionIdIndex = ConnectTableToSectionAndIndex(output.Tables["ODBCDataSource"], componentSectionIdIndex, 1, 0);
612 Hashtable odbcDriverSectionIdIndex = ConnectTableToSectionAndIndex(output.Tables["ODBCDriver"], componentSectionIdIndex, 1, 0); 614 var odbcDriverSectionIdIndex = ConnectTableToSectionAndIndex(output.Tables["ODBCDriver"], componentSectionIdIndex, 1, 0);
613 Hashtable registrySectionIdIndex = ConnectTableToSectionAndIndex(output.Tables["Registry"], componentSectionIdIndex, 5, 0); 615 var registrySectionIdIndex = ConnectTableToSectionAndIndex(output.Tables["Registry"], componentSectionIdIndex, 5, 0);
614 Hashtable serviceInstallSectionIdIndex = ConnectTableToSectionAndIndex(output.Tables["ServiceInstall"], componentSectionIdIndex, 11, 0); 616 var serviceInstallSectionIdIndex = ConnectTableToSectionAndIndex(output.Tables["ServiceInstall"], componentSectionIdIndex, 11, 0);
615 617
616 // Now handle all the tables which only rely on previous indexes and order does not matter. 618 // Now handle all the tables which only rely on previous indexes and order does not matter.
617 foreach (Table table in output.Tables) 619 foreach (var table in output.Tables)
618 { 620 {
619 switch (table.Name) 621 switch (table.Name)
620 { 622 {
621 case "WixFile": 623 case "WixFile":
622 case "MsiFileHash": 624 case "MsiFileHash":
623 ConnectTableToSection(table, fileSectionIdIndex, 0); 625 ConnectTableToSection(table, fileSectionIdIndex, 0);
624 break; 626 break;
625 case "MsiAssembly": 627 case "MsiAssembly":
626 case "MsiAssemblyName": 628 case "MsiAssemblyName":
627 ConnectTableToSection(table, componentSectionIdIndex, 0); 629 ConnectTableToSection(table, componentSectionIdIndex, 0);
628 break; 630 break;
629 case "MsiPackageCertificate": 631 case "MsiPackageCertificate":
630 case "MsiPatchCertificate": 632 case "MsiPatchCertificate":
631 ConnectTableToSection(table, digitalCertificateSectionIdIndex, 1); 633 ConnectTableToSection(table, digitalCertificateSectionIdIndex, 1);
632 break; 634 break;
633 case "CreateFolder": 635 case "CreateFolder":
634 case "FeatureComponents": 636 case "FeatureComponents":
635 case "MoveFile": 637 case "MoveFile":
636 case "ReserveCost": 638 case "ReserveCost":
637 case "ODBCTranslator": 639 case "ODBCTranslator":
638 ConnectTableToSection(table, componentSectionIdIndex, 1); 640 ConnectTableToSection(table, componentSectionIdIndex, 1);
639 break; 641 break;
640 case "TypeLib": 642 case "TypeLib":
641 ConnectTableToSection(table, componentSectionIdIndex, 2); 643 ConnectTableToSection(table, componentSectionIdIndex, 2);
642 break; 644 break;
643 case "Shortcut": 645 case "Shortcut":
644 case "Environment": 646 case "Environment":
645 ConnectTableToSection(table, componentSectionIdIndex, 3); 647 ConnectTableToSection(table, componentSectionIdIndex, 3);
646 break; 648 break;
647 case "RemoveRegistry": 649 case "RemoveRegistry":
648 ConnectTableToSection(table, componentSectionIdIndex, 4); 650 ConnectTableToSection(table, componentSectionIdIndex, 4);
649 break; 651 break;
650 case "ServiceControl": 652 case "ServiceControl":
651 ConnectTableToSection(table, componentSectionIdIndex, 5); 653 ConnectTableToSection(table, componentSectionIdIndex, 5);
652 break; 654 break;
653 case "IniFile": 655 case "IniFile":
654 case "RemoveIniFile": 656 case "RemoveIniFile":
655 ConnectTableToSection(table, componentSectionIdIndex, 7); 657 ConnectTableToSection(table, componentSectionIdIndex, 7);
656 break; 658 break;
657 case "AppId": 659 case "AppId":
658 ConnectTableToSection(table, appIdSectionIdIndex, 0); 660 ConnectTableToSection(table, appIdSectionIdIndex, 0);
659 break; 661 break;
660 case "Condition": 662 case "Condition":
661 ConnectTableToSection(table, featureSectionIdIndex, 0); 663 ConnectTableToSection(table, featureSectionIdIndex, 0);
662 break; 664 break;
663 case "ODBCSourceAttribute": 665 case "ODBCSourceAttribute":
664 ConnectTableToSection(table, odbcDataSourceSectionIdIndex, 0); 666 ConnectTableToSection(table, odbcDataSourceSectionIdIndex, 0);
665 break; 667 break;
666 case "ODBCAttribute": 668 case "ODBCAttribute":
667 ConnectTableToSection(table, odbcDriverSectionIdIndex, 0); 669 ConnectTableToSection(table, odbcDriverSectionIdIndex, 0);
668 break; 670 break;
669 case "AdminExecuteSequence": 671 case "AdminExecuteSequence":
670 case "AdminUISequence": 672 case "AdminUISequence":
671 case "AdvtExecuteSequence": 673 case "AdvtExecuteSequence":
672 case "AdvtUISequence": 674 case "AdvtUISequence":
673 case "InstallExecuteSequence": 675 case "InstallExecuteSequence":
674 case "InstallUISequence": 676 case "InstallUISequence":
675 ConnectTableToSection(table, customActionSectionIdIndex, 0); 677 ConnectTableToSection(table, customActionSectionIdIndex, 0);
676 break; 678 break;
677 case "LockPermissions": 679 case "LockPermissions":
678 case "MsiLockPermissions": 680 case "MsiLockPermissions":
679 foreach (Row row in table.Rows) 681 foreach (var row in table.Rows)
682 {
683 var lockObject = (string)row[0];
684 var tableName = (string)row[1];
685 switch (tableName)
680 { 686 {
681 string lockObject = (string)row[0]; 687 case "File":
682 string tableName = (string)row[1]; 688 row.SectionId = (string)fileSectionIdIndex[lockObject];
683 switch (tableName) 689 break;
684 { 690 case "Registry":
685 case "File": 691 row.SectionId = (string)registrySectionIdIndex[lockObject];
686 row.SectionId = (string)fileSectionIdIndex[lockObject]; 692 break;
687 break; 693 case "ServiceInstall":
688 case "Registry": 694 row.SectionId = (string)serviceInstallSectionIdIndex[lockObject];
689 row.SectionId = (string)registrySectionIdIndex[lockObject]; 695 break;
690 break;
691 case "ServiceInstall":
692 row.SectionId = (string)serviceInstallSectionIdIndex[lockObject];
693 break;
694 }
695 } 696 }
696 break; 697 }
698 break;
697 } 699 }
698 } 700 }
699 701
@@ -712,12 +714,12 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
712 /// <returns>A Hashtable containing the tables key for each row paired with its assigned section id.</returns> 714 /// <returns>A Hashtable containing the tables key for each row paired with its assigned section id.</returns>
713 private Hashtable AssignSectionIdsToTable(Table table, int rowPrimaryKeyIndex) 715 private Hashtable AssignSectionIdsToTable(Table table, int rowPrimaryKeyIndex)
714 { 716 {
715 Hashtable hashtable = new Hashtable(); 717 var hashtable = new Hashtable();
716 if (null != table) 718 if (null != table)
717 { 719 {
718 foreach (Row row in table.Rows) 720 foreach (var row in table.Rows)
719 { 721 {
720 row.SectionId = GetNewSectionId(); 722 row.SectionId = this.GetNewSectionId();
721 hashtable.Add(row[rowPrimaryKeyIndex], row.SectionId); 723 hashtable.Add(row[rowPrimaryKeyIndex], row.SectionId);
722 } 724 }
723 } 725 }
@@ -734,7 +736,7 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
734 { 736 {
735 if (null != table) 737 if (null != table)
736 { 738 {
737 foreach (Row row in table.Rows) 739 foreach (var row in table.Rows)
738 { 740 {
739 if (sectionIdIndex.ContainsKey(row[rowIndex])) 741 if (sectionIdIndex.ContainsKey(row[rowIndex]))
740 { 742 {
@@ -754,10 +756,10 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
754 /// <returns>A Hashtable containing the tables key for each row paired with its assigned section id.</returns> 756 /// <returns>A Hashtable containing the tables key for each row paired with its assigned section id.</returns>
755 private static Hashtable ConnectTableToSectionAndIndex(Table table, Hashtable sectionIdIndex, int rowIndex, int rowPrimaryKeyIndex) 757 private static Hashtable ConnectTableToSectionAndIndex(Table table, Hashtable sectionIdIndex, int rowIndex, int rowPrimaryKeyIndex)
756 { 758 {
757 Hashtable newHashTable = new Hashtable(); 759 var newHashTable = new Hashtable();
758 if (null != table) 760 if (null != table)
759 { 761 {
760 foreach (Row row in table.Rows) 762 foreach (var row in table.Rows)
761 { 763 {
762 if (!sectionIdIndex.ContainsKey(row[rowIndex])) 764 if (!sectionIdIndex.ContainsKey(row[rowIndex]))
763 { 765 {