aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2020-05-22 14:51:59 -0700
committerRob Mensching <rob@firegiant.com>2020-05-22 15:25:19 -0700
commit236f958468923f65a8f02e406601fb47e71cd58e (patch)
tree1d5d415618e44e6387f68fbc1c2232931cd82198 /src/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs
parente8030ca17ff96a794a3fecd66bb01b81581a5451 (diff)
downloadwix-236f958468923f65a8f02e406601fb47e71cd58e.tar.gz
wix-236f958468923f65a8f02e406601fb47e71cd58e.tar.bz2
wix-236f958468923f65a8f02e406601fb47e71cd58e.zip
Minor code cleanup
Diffstat (limited to 'src/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs')
-rw-r--r--src/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs77
1 files changed, 34 insertions, 43 deletions
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
59 59
60 public IMessaging Messaging { private get; set; } 60 public IMessaging Messaging { private get; set; }
61 61
62 public string TempFilesLocation { private get; set; } 62 public string IntermediateFolder { private get; set; }
63 63
64 /// <summary> 64 /// <summary>
65 /// Sets the default compression level to use for cabinets 65 /// Sets the default compression level to use for cabinets
@@ -95,15 +95,19 @@ namespace WixToolset.Core.WindowsInstaller.Bind
95 { 95 {
96 this.lastCabinetAddedToMediaTable = new Dictionary<string, string>(); 96 this.lastCabinetAddedToMediaTable = new Dictionary<string, string>();
97 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 }
99 103
100 // Send Binder object to Facilitate NewCabNamesCallBack Callback 104 // Send Binder object to Facilitate NewCabNamesCallBack Callback
101 var cabinetBuilder = new CabinetBuilder(this.Messaging, this.CabbingThreadCount, Marshal.GetFunctionPointerForDelegate(this.newCabNamesCallBack)); 105 var cabinetBuilder = new CabinetBuilder(this.Messaging, this.CabbingThreadCount, Marshal.GetFunctionPointerForDelegate(this.newCabNamesCallBack));
102 106
103 // Supply Compile MediaTemplate Attributes to Cabinet Builder 107 // Supply Compile MediaTemplate Attributes to Cabinet Builder
104 this.GetMediaTemplateAttributes(out var MaximumCabinetSizeForLargeFileSplitting, out var MaximumUncompressedMediaSize); 108 this.GetMediaTemplateAttributes(out var maximumCabinetSizeForLargeFileSplitting, out var maximumUncompressedMediaSize);
105 cabinetBuilder.MaximumCabinetSizeForLargeFileSplitting = MaximumCabinetSizeForLargeFileSplitting; 109 cabinetBuilder.MaximumCabinetSizeForLargeFileSplitting = maximumCabinetSizeForLargeFileSplitting;
106 cabinetBuilder.MaximumUncompressedMediaSize = MaximumUncompressedMediaSize; 110 cabinetBuilder.MaximumUncompressedMediaSize = maximumUncompressedMediaSize;
107 111
108 foreach (var entry in this.FileRowsByCabinet) 112 foreach (var entry in this.FileRowsByCabinet)
109 { 113 {
@@ -133,44 +137,36 @@ namespace WixToolset.Core.WindowsInstaller.Bind
133 } 137 }
134 } 138 }
135 139
136 /// <summary> 140 private int CalculateCabbingThreadCount()
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()
141 { 141 {
142 // default the number of cabbing threads to the number of processors if it wasn't specified 142 var cabbingThreadCount = 1; // default to 1 if the environment variable is not set.
143 if (0 == this.CabbingThreadCount)
144 {
145 string numberOfProcessors = System.Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS");
146 143
147 try 144 var numberOfProcessors = Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS");
145
146 try
147 {
148 if (!String.IsNullOrEmpty(numberOfProcessors))
148 { 149 {
149 if (null != numberOfProcessors) 150 cabbingThreadCount = Convert.ToInt32(numberOfProcessors, CultureInfo.InvariantCulture.NumberFormat);
150 {
151 this.CabbingThreadCount = Convert.ToInt32(numberOfProcessors, CultureInfo.InvariantCulture.NumberFormat);
152 151
153 if (0 >= this.CabbingThreadCount) 152 if (cabbingThreadCount <= 0)
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
159 { 153 {
160 this.CabbingThreadCount = 1; 154 throw new WixException(ErrorMessages.IllegalEnvironmentVariable("NUMBER_OF_PROCESSORS", numberOfProcessors));
161 } 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));
172 } 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));
173 } 163 }
164 catch (FormatException)
165 {
166 throw new WixException(ErrorMessages.IllegalEnvironmentVariable("NUMBER_OF_PROCESSORS", numberOfProcessors));
167 }
168
169 return cabbingThreadCount;
174 } 170 }
175 171
176 172
@@ -185,18 +181,13 @@ namespace WixToolset.Core.WindowsInstaller.Bind
185 private CabinetWorkItem CreateCabinetWorkItem(WindowsInstallerData output, string cabinetDir, MediaTuple mediaRow, CompressionLevel compressionLevel, IEnumerable<FileFacade> fileFacades) 181 private CabinetWorkItem CreateCabinetWorkItem(WindowsInstallerData output, string cabinetDir, MediaTuple mediaRow, CompressionLevel compressionLevel, IEnumerable<FileFacade> fileFacades)
186 { 182 {
187 CabinetWorkItem cabinetWorkItem = null; 183 CabinetWorkItem cabinetWorkItem = null;
188 string tempCabinetFileX = Path.Combine(this.TempFilesLocation, mediaRow.Cabinet); 184 string tempCabinetFileX = Path.Combine(this.IntermediateFolder, mediaRow.Cabinet);
189 185
190 // check for an empty cabinet 186 // check for an empty cabinet
191 if (!fileFacades.Any()) 187 if (!fileFacades.Any())
192 { 188 {
193 string cabinetName = mediaRow.Cabinet; 189 // Remove the leading '#' from the embedded cabinet name to make the warning easier to understand
194 190 var cabinetName = mediaRow.Cabinet.TrimStart('#');
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 }
200 191
201 // If building a patch, remind them to run -p for torch. 192 // If building a patch, remind them to run -p for torch.
202 if (OutputType.Patch == output.Type) 193 if (OutputType.Patch == output.Type)