/// <summary> /// Adds a file to the cabinet with an optional MSI file hash. /// </summary> /// <param name="file">The file to add.</param> /// <param name="token">The token for the file.</param> /// <param name="fileHash">The MSI file hash of the file.</param> private void AddFile(string file, string token, MsiInterop.MSIFILEHASHINFO fileHash) { try { NativeMethods.CreateCabAddFile(file, token, fileHash, this.handle); } catch (COMException ce) { if (0x80004005 == unchecked ((uint)ce.ErrorCode)) // E_FAIL { throw new WixException(WixErrors.CreateCabAddFileFailed()); } else if (0x80070070 == unchecked ((uint)ce.ErrorCode)) // ERROR_DISK_FULL { throw new WixException(WixErrors.CreateCabInsufficientDiskSpace()); } else { throw; } } catch (DirectoryNotFoundException) { throw new WixFileNotFoundException(file); } catch (FileNotFoundException) { throw new WixFileNotFoundException(file); } }
/// <summary> /// Complete/commit the cabinet - this must be called before Dispose so that errors will be /// reported on the same thread. /// </summary> public void Complete() { if (IntPtr.Zero != this.handle) { try { NativeMethods.CreateCabFinish(this.handle); GC.SuppressFinalize(this); this.disposed = true; } catch (COMException ce) { if (0x80004005 == unchecked ((uint)ce.ErrorCode)) // E_FAIL { // This error seems to happen, among other situations, when cabbing more than 0xFFFF files throw new WixException(WixErrors.FinishCabFailed()); } else if (0x80070070 == unchecked ((uint)ce.ErrorCode)) // ERROR_DISK_FULL { throw new WixException(WixErrors.CreateCabInsufficientDiskSpace()); } else { throw; } } finally { this.handle = IntPtr.Zero; } } }