aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core/Cab/WixExtractCab.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.Core/Cab/WixExtractCab.cs')
-rw-r--r--src/WixToolset.Core/Cab/WixExtractCab.cs76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/WixToolset.Core/Cab/WixExtractCab.cs b/src/WixToolset.Core/Cab/WixExtractCab.cs
new file mode 100644
index 00000000..debdaf15
--- /dev/null
+++ b/src/WixToolset.Core/Cab/WixExtractCab.cs
@@ -0,0 +1,76 @@
1// 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.
2
3namespace WixToolset.Cab
4{
5 using System;
6 using System.Runtime.InteropServices;
7 using WixToolset.Core.Native;
8
9 /// <summary>
10 /// Wrapper class around interop with wixcab.dll to extract files from a cabinet.
11 /// </summary>
12 public sealed class WixExtractCab : IDisposable
13 {
14 private bool disposed;
15
16 /// <summary>
17 /// Creates a cabinet extractor.
18 /// </summary>
19 public WixExtractCab()
20 {
21 NativeMethods.ExtractCabBegin();
22 }
23
24 /// <summary>
25 /// Destructor for cabinet extraction.
26 /// </summary>
27 ~WixExtractCab()
28 {
29 this.Dispose();
30 }
31
32 /// <summary>
33 /// Extracts all the files from a cabinet to a directory.
34 /// </summary>
35 /// <param name="cabinetFile">Cabinet file to extract from.</param>
36 /// <param name="extractDir">Directory to extract files to.</param>
37 public void Extract(string cabinetFile, string extractDir)
38 {
39 if (null == cabinetFile)
40 {
41 throw new ArgumentNullException("cabinetFile");
42 }
43
44 if (null == extractDir)
45 {
46 throw new ArgumentNullException("extractDir");
47 }
48
49 if (this.disposed)
50 {
51 throw new ObjectDisposedException("WixExtractCab");
52 }
53
54 if (!extractDir.EndsWith("\\", StringComparison.Ordinal))
55 {
56 extractDir = String.Concat(extractDir, "\\");
57 }
58
59 NativeMethods.ExtractCab(cabinetFile, extractDir);
60 }
61
62 /// <summary>
63 /// Disposes the managed and unmanaged objects in this object.
64 /// </summary>
65 public void Dispose()
66 {
67 if (!this.disposed)
68 {
69 NativeMethods.ExtractCabFinish();
70
71 GC.SuppressFinalize(this);
72 this.disposed = true;
73 }
74 }
75 }
76}