@joebigelow / wix / commits / 6f2511f5

Elevate known cab failures to messages.

Fixes https://github.com/wixtoolset/issues/issues/7169.

Bob Arnson committed Feb 10, 2023 at 16:29 UTC 6f2511f58f60e63a15357a2fe37f83343dea3090
2 files changed +34 -12
src/api/wix/WixToolset.Data/ErrorMessages.cs
+2 -2
@@ -180,12 +180,12 @@ namespace WixToolset.Data
180
181 public static Message CreateCabAddFileFailed()
182 {
183 - return Message(null, Ids.CreateCabAddFileFailed, "An error (E_FAIL) was returned while adding files to a CAB file. This most commonly happens when creating a CAB file 2 GB or larger. Either reduce the size of your installation package, raise Media/@CompressionLevel to a higher compression level, or split your installation package's files into more than one CAB file.");
183 + return Message(null, Ids.CreateCabAddFileFailed, "An error (E_FAIL) was returned while creating a CAB file. The most common cause of this error is attempting to create a CAB file larger than 2GB. You can reduce the size of your installation package, use a higher compression level, or split your files into more than one CAB file.");
184 }
185
186 public static Message CreateCabInsufficientDiskSpace()
187 {
188 - return Message(null, Ids.CreateCabInsufficientDiskSpace, "An error (ERROR_DISK_FULL) was returned while creating a CAB file. This means you have insufficient disk space - please clear more disk space and try this operation again.");
188 + return Message(null, Ids.CreateCabInsufficientDiskSpace, "An error (ERROR_DISK_FULL) was returned while creating a CAB file. This means you have insufficient disk space. Clear disk space and try again.");
189 }
190
191 public static Message CubeFileNotFound(string cubeFile)
src/wix/WixToolset.Core.WindowsInstaller/Bind/CabinetBuilder.cs
+32 -10
@@ -4,6 +4,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
4 {
5 using System;
6 using System.Collections.Generic;
7 + using System.ComponentModel;
8 using System.IO;
9 using System.Linq;
10 using System.Threading;
@@ -122,9 +123,12 @@ namespace WixToolset.Core.WindowsInstaller.Bind
123 var created = this.CreateCabinet(cabinetWorkItem);
124
125 // Update the cabinet work item to report back what cabinets were created.
125 - lock (this.completedCabinets)
126 + if (created?.Any() == true)
127 {
127 - this.completedCabinets.Add(new CompletedCabinetWorkItem(cabinetWorkItem.DiskId, created));
128 + lock (this.completedCabinets)
129 + {
130 + this.completedCabinets.Add(new CompletedCabinetWorkItem(cabinetWorkItem.DiskId, created));
131 + }
132 }
133 }
134 }
@@ -186,22 +190,40 @@ namespace WixToolset.Core.WindowsInstaller.Bind
190 // create the cabinet file
191 var cabinetPath = Path.GetFullPath(cabinetWorkItem.CabinetFile);
192 var cab = new Cabinet(cabinetPath);
189 - var created = cab.Compress(compressFiles, cabinetWorkItem.CompressionLevel, maxCabinetSize, cabinetWorkItem.MaxThreshold);
193
191 - // Best effort check to see if the cabinet is too large for the Windows Installer.
194 try
195 {
194 - var fi = new FileInfo(cabinetPath);
195 - if (fi.Length > Int32.MaxValue)
196 + var created = cab.Compress(compressFiles, cabinetWorkItem.CompressionLevel, maxCabinetSize, cabinetWorkItem.MaxThreshold);
197 +
198 + // Best effort check to see if the cabinet is too large for the Windows Installer.
199 + try
200 {
197 - this.Messaging.Write(WarningMessages.WindowsInstallerFileTooLarge(cabinetWorkItem.SourceLineNumber, cabinetPath, "cabinet"));
201 + var fi = new FileInfo(cabinetPath);
202 + if (fi.Length > Int32.MaxValue)
203 + {
204 + this.Messaging.Write(WarningMessages.WindowsInstallerFileTooLarge(cabinetWorkItem.SourceLineNumber, cabinetPath, "cabinet"));
205 + }
206 }
207 + catch
208 + {
209 + }
210 +
211 + return created;
212 }
200 - catch
213 + catch (Exception e) when (e.InnerException is Win32Exception win32Exception)
214 {
215 + switch (win32Exception.NativeErrorCode)
216 + {
217 + case 0x4005:
218 + this.Messaging.Write(ErrorMessages.CreateCabAddFileFailed());
219 + return null;
220 + case 0x0070:
221 + this.Messaging.Write(ErrorMessages.CreateCabInsufficientDiskSpace());
222 + return null;
223 + default:
224 + throw;
225 + }
226 }
203 -
204 - return created;
227 }
228 }
229 }