@joebigelow / wix-1 / commits / 236f9584

Minor code cleanup

Rob Mensching committed May 22, 2020 at 14:51 UTC 236f958468923f65a8f02e406601fb47e71cd58e
4 files changed +50 -79
src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs
+2 -3
@@ -452,7 +452,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
452 command.FileRowsByCabinet = filesByCabinetMedia;
453 command.ResolveMedia = this.ResolveMedia;
454 command.TableDefinitions = tableDefinitions;
455 - command.TempFilesLocation = this.IntermediateFolder;
455 + command.IntermediateFolder = this.IntermediateFolder;
456 command.Execute();
457
458 fileTransfers.AddRange(command.FileTransfers);
@@ -887,8 +887,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
887 /// </remarks>
888 private void ValidateComponentGuids(WindowsInstallerData output)
889 {
890 - Table componentTable = output.Tables["Component"];
891 - if (null != componentTable)
890 + if (output.TryGetTable("Component", out var componentTable))
891 {
892 Dictionary<string, bool> componentGuidConditions = new Dictionary<string, bool>(componentTable.Rows.Count);
893
src/WixToolset.Core.WindowsInstaller/Bind/CabinetBuilder.cs
+5 -6
@@ -150,13 +150,12 @@ namespace WixToolset.Core.WindowsInstaller.Bind
150 // Get the Value for Max Uncompressed Media Size
151 maxPreCompressedSizeInBytes = (ulong)this.MaximumUncompressedMediaSize * 1024 * 1024;
152
153 - foreach (FileFacade facade in cabinetWorkItem.FileFacades) // No other easy way than looping to get the only row
153 + var facade = cabinetWorkItem.FileFacades.First();
154 +
155 + // If the file is larger than MaximumUncompressedFileSize set Maximum Cabinet Size for Cabinet Splitting
156 + if ((ulong)facade.FileSize >= maxPreCompressedSizeInBytes)
157 {
155 - if ((ulong)facade.FileSize >= maxPreCompressedSizeInBytes)
156 - {
157 - // If file is larger than MaximumUncompressedFileSize set Maximum Cabinet Size for Cabinet Splitting
158 - maxCabinetSize = this.MaximumCabinetSizeForLargeFileSplitting;
159 - }
158 + maxCabinetSize = this.MaximumCabinetSizeForLargeFileSplitting;
159 }
160 }
161 }
src/WixToolset.Core.WindowsInstaller/Bind/CabinetWorkItem.cs
+9 -27
@@ -11,11 +11,6 @@ namespace WixToolset.Core.WindowsInstaller.Bind
11 /// </summary>
12 internal sealed class CabinetWorkItem
13 {
14 - private string cabinetFile;
15 - private CompressionLevel compressionLevel;
16 - //private BinderFileManager binderFileManager;
17 - private int maxThreshold;
18 -
14 /// <summary>
15 /// Instantiate a new CabinetWorkItem.
16 /// </summary>
@@ -24,34 +19,27 @@ namespace WixToolset.Core.WindowsInstaller.Bind
19 /// <param name="maxThreshold">Maximum threshold for each cabinet.</param>
20 /// <param name="compressionLevel">The compression level of the cabinet.</param>
21 /// <param name="binderFileManager">The binder file manager.</param>
27 - public CabinetWorkItem(IEnumerable<FileFacade> fileFacades, string cabinetFile, int maxThreshold, CompressionLevel compressionLevel /*, BinderFileManager binderFileManager*/)
22 public CabinetWorkItem(IEnumerable<FileFacade> fileFacades, string cabinetFile, int maxThreshold, CompressionLevel compressionLevel, string modularizationSuffix /*, BinderFileManager binderFileManager*/)
23 {
30 - this.cabinetFile = cabinetFile;
31 - this.compressionLevel = compressionLevel;
24 + this.CabinetFile = cabinetFile;
25 + this.CompressionLevel = compressionLevel;
26 this.ModularizationSuffix = modularizationSuffix;
27 this.FileFacades = fileFacades;
34 - //this.binderFileManager = binderFileManager;
35 - this.maxThreshold = maxThreshold;
28 + //this.BinderFileManager = binderFileManager;
29 + this.MaxThreshold = maxThreshold;
30 }
31
32 /// <summary>
33 /// Gets the cabinet file.
34 /// </summary>
35 /// <value>The cabinet file.</value>
42 - public string CabinetFile
43 - {
44 - get { return this.cabinetFile; }
45 - }
36 + public string CabinetFile { get; }
37
38 /// <summary>
39 /// Gets the compression level of the cabinet.
40 /// </summary>
41 /// <value>The compression level of the cabinet.</value>
51 - public CompressionLevel CompressionLevel
52 - {
53 - get { return this.compressionLevel; }
54 - }
42 + public CompressionLevel CompressionLevel { get; }
43
44 /// <summary>
45 /// Gets the modularization suffix used when building a Merge Module.
@@ -62,24 +50,18 @@ namespace WixToolset.Core.WindowsInstaller.Bind
50 /// Gets the collection of files in this cabinet.
51 /// </summary>
52 /// <value>The collection of files in this cabinet.</value>
65 - public IEnumerable<FileFacade> FileFacades { get; private set; }
53 + public IEnumerable<FileFacade> FileFacades { get; }
54
55 /// <summary>
56 /// Gets the binder file manager.
57 /// </summary>
58 /// <value>The binder file manager.</value>
71 - //public BinderFileManager BinderFileManager
72 - //{
73 - // get { return this.binderFileManager; }
74 - //}
59 + //public BinderFileManager BinderFileManager { get; private set; }
60
61 /// <summary>
62 /// Gets the max threshold.
63 /// </summary>
64 /// <value>The maximum threshold for a folder in a cabinet.</value>
80 - public int MaxThreshold
81 - {
82 - get { return this.maxThreshold; }
83 - }
65 + public int MaxThreshold { get; }
66 }
67 }
src/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs
+34 -43
@@ -59,7 +59,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
59
60 public IMessaging Messaging { private get; set; }
61
62 - public string TempFilesLocation { private get; set; }
62 + public string IntermediateFolder { private get; set; }
63
64 /// <summary>
65 /// Sets the default compression level to use for cabinets
@@ -95,15 +95,19 @@ namespace WixToolset.Core.WindowsInstaller.Bind
95 {
96 this.lastCabinetAddedToMediaTable = new Dictionary<string, string>();
97
98 - this.SetCabbingThreadCount();
98 + // If the cabbing thread count wasn't provided, default the number of cabbing threads to the number of processors.
99 + if (this.CabbingThreadCount <= 0)
100 + {
101 + this.CabbingThreadCount = this.CalculateCabbingThreadCount();
102 + }
103
104 // Send Binder object to Facilitate NewCabNamesCallBack Callback
105 var cabinetBuilder = new CabinetBuilder(this.Messaging, this.CabbingThreadCount, Marshal.GetFunctionPointerForDelegate(this.newCabNamesCallBack));
106
107 // Supply Compile MediaTemplate Attributes to Cabinet Builder
104 - this.GetMediaTemplateAttributes(out var MaximumCabinetSizeForLargeFileSplitting, out var MaximumUncompressedMediaSize);
105 - cabinetBuilder.MaximumCabinetSizeForLargeFileSplitting = MaximumCabinetSizeForLargeFileSplitting;
106 - cabinetBuilder.MaximumUncompressedMediaSize = MaximumUncompressedMediaSize;
108 + this.GetMediaTemplateAttributes(out var maximumCabinetSizeForLargeFileSplitting, out var maximumUncompressedMediaSize);
109 + cabinetBuilder.MaximumCabinetSizeForLargeFileSplitting = maximumCabinetSizeForLargeFileSplitting;
110 + cabinetBuilder.MaximumUncompressedMediaSize = maximumUncompressedMediaSize;
111
112 foreach (var entry in this.FileRowsByCabinet)
113 {
@@ -133,44 +137,36 @@ namespace WixToolset.Core.WindowsInstaller.Bind
137 }
138 }
139
136 - /// <summary>
137 - /// Sets the thead count to the number of processors if the current thread count is set to 0.
138 - /// </summary>
139 - /// <remarks>The thread count value must be greater than 0 otherwise and exception will be thrown.</remarks>
140 - private void SetCabbingThreadCount()
140 + private int CalculateCabbingThreadCount()
141 {
142 - // default the number of cabbing threads to the number of processors if it wasn't specified
143 - if (0 == this.CabbingThreadCount)
144 - {
145 - string numberOfProcessors = System.Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS");
142 + var cabbingThreadCount = 1; // default to 1 if the environment variable is not set.
143
147 - try
144 + var numberOfProcessors = Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS");
145 +
146 + try
147 + {
148 + if (!String.IsNullOrEmpty(numberOfProcessors))
149 {
149 - if (null != numberOfProcessors)
150 - {
151 - this.CabbingThreadCount = Convert.ToInt32(numberOfProcessors, CultureInfo.InvariantCulture.NumberFormat);
150 + cabbingThreadCount = Convert.ToInt32(numberOfProcessors, CultureInfo.InvariantCulture.NumberFormat);
151
153 - if (0 >= this.CabbingThreadCount)
154 - {
155 - throw new WixException(ErrorMessages.IllegalEnvironmentVariable("NUMBER_OF_PROCESSORS", numberOfProcessors));
156 - }
157 - }
158 - else // default to 1 if the environment variable is not set
152 + if (cabbingThreadCount <= 0)
153 {
160 - this.CabbingThreadCount = 1;
154 + throw new WixException(ErrorMessages.IllegalEnvironmentVariable("NUMBER_OF_PROCESSORS", numberOfProcessors));
155 }
162 -
163 - this.Messaging.Write(VerboseMessages.SetCabbingThreadCount(this.CabbingThreadCount.ToString()));
164 - }
165 - catch (ArgumentException)
166 - {
167 - throw new WixException(ErrorMessages.IllegalEnvironmentVariable("NUMBER_OF_PROCESSORS", numberOfProcessors));
168 - }
169 - catch (FormatException)
170 - {
171 - throw new WixException(ErrorMessages.IllegalEnvironmentVariable("NUMBER_OF_PROCESSORS", numberOfProcessors));
156 }
157 +
158 + this.Messaging.Write(VerboseMessages.SetCabbingThreadCount(this.CabbingThreadCount.ToString()));
159 + }
160 + catch (ArgumentException)
161 + {
162 + throw new WixException(ErrorMessages.IllegalEnvironmentVariable("NUMBER_OF_PROCESSORS", numberOfProcessors));
163 }
164 + catch (FormatException)
165 + {
166 + throw new WixException(ErrorMessages.IllegalEnvironmentVariable("NUMBER_OF_PROCESSORS", numberOfProcessors));
167 + }
168 +
169 + return cabbingThreadCount;
170 }
171
172
@@ -185,18 +181,13 @@ namespace WixToolset.Core.WindowsInstaller.Bind
181 private CabinetWorkItem CreateCabinetWorkItem(WindowsInstallerData output, string cabinetDir, MediaTuple mediaRow, CompressionLevel compressionLevel, IEnumerable<FileFacade> fileFacades)
182 {
183 CabinetWorkItem cabinetWorkItem = null;
188 - string tempCabinetFileX = Path.Combine(this.TempFilesLocation, mediaRow.Cabinet);
184 + string tempCabinetFileX = Path.Combine(this.IntermediateFolder, mediaRow.Cabinet);
185
186 // check for an empty cabinet
187 if (!fileFacades.Any())
188 {
193 - string cabinetName = mediaRow.Cabinet;
194 -
195 - // remove the leading '#' from the embedded cabinet name to make the warning easier to understand
196 - if (cabinetName.StartsWith("#", StringComparison.Ordinal))
197 - {
198 - cabinetName = cabinetName.Substring(1);
199 - }
189 + // Remove the leading '#' from the embedded cabinet name to make the warning easier to understand
190 + var cabinetName = mediaRow.Cabinet.TrimStart('#');
191
192 // If building a patch, remind them to run -p for torch.
193 if (OutputType.Patch == output.Type)