From 236f958468923f65a8f02e406601fb47e71cd58e Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Fri, 22 May 2020 14:51:59 -0700 Subject: Minor code cleanup --- .../Bind/CreateCabinetsCommand.cs | 77 ++++++++++------------ 1 file changed, 34 insertions(+), 43 deletions(-) (limited to 'src/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs') diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs index 6852772e..f2f9895d 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs @@ -59,7 +59,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind public IMessaging Messaging { private get; set; } - public string TempFilesLocation { private get; set; } + public string IntermediateFolder { private get; set; } /// /// Sets the default compression level to use for cabinets @@ -95,15 +95,19 @@ namespace WixToolset.Core.WindowsInstaller.Bind { this.lastCabinetAddedToMediaTable = new Dictionary(); - this.SetCabbingThreadCount(); + // If the cabbing thread count wasn't provided, default the number of cabbing threads to the number of processors. + if (this.CabbingThreadCount <= 0) + { + this.CabbingThreadCount = this.CalculateCabbingThreadCount(); + } // Send Binder object to Facilitate NewCabNamesCallBack Callback var cabinetBuilder = new CabinetBuilder(this.Messaging, this.CabbingThreadCount, Marshal.GetFunctionPointerForDelegate(this.newCabNamesCallBack)); // Supply Compile MediaTemplate Attributes to Cabinet Builder - this.GetMediaTemplateAttributes(out var MaximumCabinetSizeForLargeFileSplitting, out var MaximumUncompressedMediaSize); - cabinetBuilder.MaximumCabinetSizeForLargeFileSplitting = MaximumCabinetSizeForLargeFileSplitting; - cabinetBuilder.MaximumUncompressedMediaSize = MaximumUncompressedMediaSize; + this.GetMediaTemplateAttributes(out var maximumCabinetSizeForLargeFileSplitting, out var maximumUncompressedMediaSize); + cabinetBuilder.MaximumCabinetSizeForLargeFileSplitting = maximumCabinetSizeForLargeFileSplitting; + cabinetBuilder.MaximumUncompressedMediaSize = maximumUncompressedMediaSize; foreach (var entry in this.FileRowsByCabinet) { @@ -133,44 +137,36 @@ namespace WixToolset.Core.WindowsInstaller.Bind } } - /// - /// Sets the thead count to the number of processors if the current thread count is set to 0. - /// - /// The thread count value must be greater than 0 otherwise and exception will be thrown. - private void SetCabbingThreadCount() + private int CalculateCabbingThreadCount() { - // default the number of cabbing threads to the number of processors if it wasn't specified - if (0 == this.CabbingThreadCount) - { - string numberOfProcessors = System.Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS"); + var cabbingThreadCount = 1; // default to 1 if the environment variable is not set. - try + var numberOfProcessors = Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS"); + + try + { + if (!String.IsNullOrEmpty(numberOfProcessors)) { - if (null != numberOfProcessors) - { - this.CabbingThreadCount = Convert.ToInt32(numberOfProcessors, CultureInfo.InvariantCulture.NumberFormat); + cabbingThreadCount = Convert.ToInt32(numberOfProcessors, CultureInfo.InvariantCulture.NumberFormat); - if (0 >= this.CabbingThreadCount) - { - throw new WixException(ErrorMessages.IllegalEnvironmentVariable("NUMBER_OF_PROCESSORS", numberOfProcessors)); - } - } - else // default to 1 if the environment variable is not set + if (cabbingThreadCount <= 0) { - this.CabbingThreadCount = 1; + throw new WixException(ErrorMessages.IllegalEnvironmentVariable("NUMBER_OF_PROCESSORS", numberOfProcessors)); } - - this.Messaging.Write(VerboseMessages.SetCabbingThreadCount(this.CabbingThreadCount.ToString())); - } - catch (ArgumentException) - { - throw new WixException(ErrorMessages.IllegalEnvironmentVariable("NUMBER_OF_PROCESSORS", numberOfProcessors)); - } - catch (FormatException) - { - throw new WixException(ErrorMessages.IllegalEnvironmentVariable("NUMBER_OF_PROCESSORS", numberOfProcessors)); } + + this.Messaging.Write(VerboseMessages.SetCabbingThreadCount(this.CabbingThreadCount.ToString())); + } + catch (ArgumentException) + { + throw new WixException(ErrorMessages.IllegalEnvironmentVariable("NUMBER_OF_PROCESSORS", numberOfProcessors)); } + catch (FormatException) + { + throw new WixException(ErrorMessages.IllegalEnvironmentVariable("NUMBER_OF_PROCESSORS", numberOfProcessors)); + } + + return cabbingThreadCount; } @@ -185,18 +181,13 @@ namespace WixToolset.Core.WindowsInstaller.Bind private CabinetWorkItem CreateCabinetWorkItem(WindowsInstallerData output, string cabinetDir, MediaTuple mediaRow, CompressionLevel compressionLevel, IEnumerable fileFacades) { CabinetWorkItem cabinetWorkItem = null; - string tempCabinetFileX = Path.Combine(this.TempFilesLocation, mediaRow.Cabinet); + string tempCabinetFileX = Path.Combine(this.IntermediateFolder, mediaRow.Cabinet); // check for an empty cabinet if (!fileFacades.Any()) { - string cabinetName = mediaRow.Cabinet; - - // remove the leading '#' from the embedded cabinet name to make the warning easier to understand - if (cabinetName.StartsWith("#", StringComparison.Ordinal)) - { - cabinetName = cabinetName.Substring(1); - } + // Remove the leading '#' from the embedded cabinet name to make the warning easier to understand + var cabinetName = mediaRow.Cabinet.TrimStart('#'); // If building a patch, remind them to run -p for torch. if (OutputType.Patch == output.Type) -- cgit v1.2.3-55-g6feb