diff options
author | Rob Mensching <rob@firegiant.com> | 2021-03-19 10:30:45 -0700 |
---|---|---|
committer | Rob Mensching <rob@firegiant.com> | 2021-03-19 11:25:39 -0700 |
commit | 84d70d16e4ab2051d881251440fe4729f301b265 (patch) | |
tree | dd9bf98bbb57beaaa344bb87994c79f6f0fbec1d /src | |
parent | 13c7babf53b7c87e0147ea21732d2473477ac8cb (diff) | |
download | wix-84d70d16e4ab2051d881251440fe4729f301b265.tar.gz wix-84d70d16e4ab2051d881251440fe4729f301b265.tar.bz2 wix-84d70d16e4ab2051d881251440fe4729f301b265.zip |
Default to 1 if NUMBER_OF_PROCESSORS environment variable is invalid
Also, use Environment.ProcessorCount to access NUMBER_OF_PROCESSORS
Fixes wixtoolset/issues#5628
Diffstat (limited to 'src')
-rw-r--r-- | src/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs | 28 |
1 files changed, 6 insertions, 22 deletions
diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs index d4faabeb..83a4949e 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs | |||
@@ -97,6 +97,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind | |||
97 | if (this.CabbingThreadCount <= 0) | 97 | if (this.CabbingThreadCount <= 0) |
98 | { | 98 | { |
99 | this.CabbingThreadCount = this.CalculateCabbingThreadCount(); | 99 | this.CabbingThreadCount = this.CalculateCabbingThreadCount(); |
100 | |||
101 | this.Messaging.Write(VerboseMessages.SetCabbingThreadCount(this.CabbingThreadCount.ToString())); | ||
100 | } | 102 | } |
101 | 103 | ||
102 | // Send Binder object to Facilitate NewCabNamesCallBack Callback | 104 | // Send Binder object to Facilitate NewCabNamesCallBack Callback |
@@ -137,31 +139,13 @@ namespace WixToolset.Core.WindowsInstaller.Bind | |||
137 | 139 | ||
138 | private int CalculateCabbingThreadCount() | 140 | private int CalculateCabbingThreadCount() |
139 | { | 141 | { |
140 | var cabbingThreadCount = 1; // default to 1 if the environment variable is not set. | 142 | var cabbingThreadCount = Environment.ProcessorCount; |
141 | 143 | ||
142 | var numberOfProcessors = Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS"); | 144 | if (cabbingThreadCount <= 0) |
143 | |||
144 | try | ||
145 | { | 145 | { |
146 | if (!String.IsNullOrEmpty(numberOfProcessors)) | 146 | cabbingThreadCount = 1; // reset to 1 when the environment variable is invalid. |
147 | { | ||
148 | cabbingThreadCount = Convert.ToInt32(numberOfProcessors, CultureInfo.InvariantCulture.NumberFormat); | ||
149 | |||
150 | if (cabbingThreadCount <= 0) | ||
151 | { | ||
152 | throw new WixException(ErrorMessages.IllegalEnvironmentVariable("NUMBER_OF_PROCESSORS", numberOfProcessors)); | ||
153 | } | ||
154 | } | ||
155 | 147 | ||
156 | this.Messaging.Write(VerboseMessages.SetCabbingThreadCount(this.CabbingThreadCount.ToString())); | 148 | this.Messaging.Write(WarningMessages.InvalidEnvironmentVariable("NUMBER_OF_PROCESSORS", Environment.ProcessorCount.ToString(), cabbingThreadCount.ToString())); |
157 | } | ||
158 | catch (ArgumentException) | ||
159 | { | ||
160 | throw new WixException(ErrorMessages.IllegalEnvironmentVariable("NUMBER_OF_PROCESSORS", numberOfProcessors)); | ||
161 | } | ||
162 | catch (FormatException) | ||
163 | { | ||
164 | throw new WixException(ErrorMessages.IllegalEnvironmentVariable("NUMBER_OF_PROCESSORS", numberOfProcessors)); | ||
165 | } | 149 | } |
166 | 150 | ||
167 | return cabbingThreadCount; | 151 | return cabbingThreadCount; |