blob: e776b08ee2f126ca2f6b3323a930ee7554a1aab2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
// 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;
/// <summary>
/// Wrapper class around interop with wixcab.dll to extract files from a cabinet.
/// </summary>
public sealed class WixExtractCab : IDisposable
{
private bool disposed;
/// <summary>
/// Creates a cabinet extractor.
/// </summary>
public WixExtractCab()
{
NativeMethods.ExtractCabBegin();
}
/// <summary>
/// Destructor for cabinet extraction.
/// </summary>
~WixExtractCab()
{
this.Dispose();
}
/// <summary>
/// Extracts all the files from a cabinet to a directory.
/// </summary>
/// <param name="cabinetFile">Cabinet file to extract from.</param>
/// <param name="extractDir">Directory to extract files to.</param>
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);
}
/// <summary>
/// Disposes the managed and unmanaged objects in this object.
/// </summary>
public void Dispose()
{
if (!this.disposed)
{
NativeMethods.ExtractCabFinish();
GC.SuppressFinalize(this);
this.disposed = true;
}
}
}
}
|