// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. namespace WixToolset.Core.Cab { using System; using WixToolset.Core.Native; /// /// Wrapper class around interop with wixcab.dll to extract files from a cabinet. /// public sealed class WixExtractCab : IDisposable { private bool disposed; /// /// Creates a cabinet extractor. /// public WixExtractCab() { NativeMethods.ExtractCabBegin(); } /// /// Destructor for cabinet extraction. /// ~WixExtractCab() { this.Dispose(); } /// /// Extracts all the files from a cabinet to a directory. /// /// Cabinet file to extract from. /// Directory to extract files to. public void Extract(string cabinetFile, string extractDir) { if (null == cabinetFile) { throw new ArgumentNullException("cabinetFile"); } if (null == extractDir) { throw new ArgumentNullException("extractDir"); } if (this.disposed) { throw new ObjectDisposedException("WixExtractCab"); } if (!extractDir.EndsWith("\\", StringComparison.Ordinal)) { extractDir = String.Concat(extractDir, "\\"); } NativeMethods.ExtractCab(cabinetFile, extractDir); } /// /// Disposes the managed and unmanaged objects in this object. /// public void Dispose() { if (!this.disposed) { NativeMethods.ExtractCabFinish(); GC.SuppressFinalize(this); this.disposed = true; } } } }