@joebigelow / wix-1 / commits / 13c7babf

Minor code cleanup

Rob Mensching committed Mar 19, 2021 at 10:29 UTC 13c7babf53b7c87e0147ea21732d2473477ac8cb
3 files changed +21 -28
src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs
+2 -2
@@ -502,9 +502,9 @@ namespace WixToolset.Core.WindowsInstaller.Bind
502 }
503
504 // Generate database file.
505 - this.Messaging.Write(VerboseMessages.GeneratingDatabase());
506 -
505 {
506 + this.Messaging.Write(VerboseMessages.GeneratingDatabase());
507 +
508 var trackMsi = this.WindowsInstallerBackendHelper.TrackFile(this.OutputPath, TrackedFileType.Final);
509 trackedFiles.Add(trackMsi);
510
src/WixToolset.Core.WindowsInstaller/Bind/CabinetBuilder.cs
+11 -16
@@ -3,7 +3,7 @@
3 namespace WixToolset.Core.WindowsInstaller.Bind
4 {
5 using System;
6 - using System.Collections;
6 + using System.Collections.Generic;
7 using System.IO;
8 using System.Linq;
9 using System.Threading;
@@ -17,9 +17,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
17 /// </summary>
18 internal sealed class CabinetBuilder
19 {
20 - private readonly object lockObject = new object();
21 -
22 - private readonly Queue cabinetWorkItems;
20 + private readonly Queue<CabinetWorkItem> cabinetWorkItems;
21 private int threadCount;
22
23 // Address of Binder's callback function for Cabinet Splitting
@@ -35,10 +33,10 @@ namespace WixToolset.Core.WindowsInstaller.Bind
33 {
34 if (0 >= threadCount)
35 {
38 - throw new ArgumentOutOfRangeException("threadCount");
36 + throw new ArgumentOutOfRangeException(nameof(threadCount));
37 }
38
41 - this.cabinetWorkItems = new Queue();
39 + this.cabinetWorkItems = new Queue<CabinetWorkItem>();
40 this.Messaging = messaging;
41 this.threadCount = threadCount;
42
@@ -65,23 +63,20 @@ namespace WixToolset.Core.WindowsInstaller.Bind
63 public void CreateQueuedCabinets()
64 {
65 // don't create more threads than the number of cabinets to build
68 - if (this.cabinetWorkItems.Count < this.threadCount)
69 - {
70 - this.threadCount = this.cabinetWorkItems.Count;
71 - }
66 + var numberOfThreads = Math.Min(this.threadCount, this.cabinetWorkItems.Count);
67
73 - if (0 < this.threadCount)
68 + if (0 < numberOfThreads)
69 {
75 - Thread[] threads = new Thread[this.threadCount];
70 + var threads = new Thread[numberOfThreads];
71
77 - for (int i = 0; i < threads.Length; i++)
72 + for (var i = 0; i < threads.Length; i++)
73 {
74 threads[i] = new Thread(new ThreadStart(this.ProcessWorkItems));
75 threads[i].Start();
76 }
77
78 // wait for all threads to finish
84 - foreach (Thread thread in threads)
79 + foreach (var thread in threads)
80 {
81 thread.Join();
82 }
@@ -109,7 +104,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
104 break;
105 }
106
112 - cabinetWorkItem = (CabinetWorkItem)this.cabinetWorkItems.Dequeue();
107 + cabinetWorkItem = this.cabinetWorkItems.Dequeue();
108 }
109
110 // create a cabinet
@@ -134,7 +129,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
129 {
130 this.Messaging.Write(VerboseMessages.CreateCabinet(cabinetWorkItem.CabinetFile));
131
137 - int maxCabinetSize = 0; // The value of 0 corresponds to default of 2GB which means no cabinet splitting
132 + var maxCabinetSize = 0; // The value of 0 corresponds to default of 2GB which means no cabinet splitting
133 ulong maxPreCompressedSizeInBytes = 0;
134
135 if (this.MaximumCabinetSizeForLargeFileSplitting != 0)
src/WixToolset.Core.WindowsInstaller/Bind/GenerateDatabaseCommand.cs
+8 -10
@@ -16,6 +16,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind
16
17 internal class GenerateDatabaseCommand
18 {
19 + private const string IdtsSubFolder = "_idts";
20 +
21 public GenerateDatabaseCommand(IMessaging messaging, IBackendHelper backendHelper, FileSystemManager fileSystemManager, WindowsInstallerData data, string outputPath, TableDefinitionCollection tableDefinitions, string intermediateFolder, int codepage, bool keepAddedColumns, bool suppressAddingValidationRows, bool useSubdirectory)
22 {
23 this.Messaging = messaging;
@@ -77,7 +79,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
79 baseDirectory = Path.Combine(baseDirectory, filename);
80 }
81
80 - var idtFolder = Path.Combine(baseDirectory, "_idts");
82 + var idtFolder = Path.Combine(baseDirectory, IdtsSubFolder);
83
84 var type = OpenDatabase.CreateDirect;
85
@@ -94,10 +96,6 @@ namespace WixToolset.Core.WindowsInstaller.Bind
96
97 try
98 {
97 -#if DEBUG
98 - Console.WriteLine("Opening database at: {0}", this.OutputPath);
99 -#endif
100 -
99 Directory.CreateDirectory(Path.GetDirectoryName(this.OutputPath));
100
101 Directory.CreateDirectory(idtFolder);
@@ -221,8 +219,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind
219 var command = new CreateIdtFileCommand(this.Messaging, importTable, this.Data.Codepage, idtDirectory, this.KeepAddedColumns);
220 command.Execute();
221
224 - var buildOutput = this.BackendHelper.TrackFile(command.IdtPath, TrackedFileType.Temporary);
225 - this.GeneratedTemporaryFiles.Add(buildOutput);
222 + var trackIdt = this.BackendHelper.TrackFile(command.IdtPath, TrackedFileType.Temporary);
223 + this.GeneratedTemporaryFiles.Add(trackIdt);
224
225 db.Import(command.IdtPath);
226 }
@@ -401,8 +399,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind
399 idtFile.WriteLine("\t_ForceCodepage");
400 }
401
404 - var trackId = this.BackendHelper.TrackFile(idtPath, TrackedFileType.Temporary);
405 - this.GeneratedTemporaryFiles.Add(trackId);
402 + var trackIdt = this.BackendHelper.TrackFile(idtPath, TrackedFileType.Temporary);
403 + this.GeneratedTemporaryFiles.Add(trackIdt);
404
405 // Try to import the table into the MSI.
406 try
@@ -411,7 +409,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
409 }
410 catch (WixInvalidIdtException)
411 {
414 - // The IDT should be valid, so an invalid code page was given.
412 + // The IDT should always be generated correctly, so an invalid code page was given.
413 throw new WixException(ErrorMessages.IllegalCodepage(codepage));
414 }
415 }