aboutsummaryrefslogtreecommitdiff
path: root/src/dtf/WixToolset.Dtf.Compression.Cab/CabFileInfo.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/dtf/WixToolset.Dtf.Compression.Cab/CabFileInfo.cs141
1 files changed, 141 insertions, 0 deletions
diff --git a/src/dtf/WixToolset.Dtf.Compression.Cab/CabFileInfo.cs b/src/dtf/WixToolset.Dtf.Compression.Cab/CabFileInfo.cs
new file mode 100644
index 00000000..ad4a813c
--- /dev/null
+++ b/src/dtf/WixToolset.Dtf.Compression.Cab/CabFileInfo.cs
@@ -0,0 +1,141 @@
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.Dtf.Compression.Cab
4{
5 using System;
6 using System.IO;
7 using System.Runtime.Serialization;
8
9 /// <summary>
10 /// Object representing a compressed file within a cabinet package; provides operations for getting
11 /// the file properties and extracting the file.
12 /// </summary>
13 [Serializable]
14 public class CabFileInfo : ArchiveFileInfo
15 {
16 private int cabFolder;
17
18 /// <summary>
19 /// Creates a new CabinetFileInfo object representing a file within a cabinet in a specified path.
20 /// </summary>
21 /// <param name="cabinetInfo">An object representing the cabinet containing the file.</param>
22 /// <param name="filePath">The path to the file within the cabinet. Usually, this is a simple file
23 /// name, but if the cabinet contains a directory structure this may include the directory.</param>
24 public CabFileInfo(CabInfo cabinetInfo, string filePath)
25 : base(cabinetInfo, filePath)
26 {
27 if (cabinetInfo == null)
28 {
29 throw new ArgumentNullException("cabinetInfo");
30 }
31
32 this.cabFolder = -1;
33 }
34
35 /// <summary>
36 /// Creates a new CabinetFileInfo object with all parameters specified,
37 /// used internally when reading the metadata out of a cab.
38 /// </summary>
39 /// <param name="filePath">The internal path and name of the file in the cab.</param>
40 /// <param name="cabFolder">The folder number containing the file.</param>
41 /// <param name="cabNumber">The cabinet number where the file starts.</param>
42 /// <param name="attributes">The stored attributes of the file.</param>
43 /// <param name="lastWriteTime">The stored last write time of the file.</param>
44 /// <param name="length">The uncompressed size of the file.</param>
45 internal CabFileInfo(
46 string filePath,
47 int cabFolder,
48 int cabNumber,
49 FileAttributes attributes,
50 DateTime lastWriteTime,
51 long length)
52 : base(filePath, cabNumber, attributes, lastWriteTime, length)
53 {
54 this.cabFolder = cabFolder;
55 }
56
57 /// <summary>
58 /// Initializes a new instance of the CabinetFileInfo class with serialized data.
59 /// </summary>
60 /// <param name="info">The SerializationInfo that holds the serialized object data about the exception being thrown.</param>
61 /// <param name="context">The StreamingContext that contains contextual information about the source or destination.</param>
62 protected CabFileInfo(SerializationInfo info, StreamingContext context)
63 : base(info, context)
64 {
65 this.cabFolder = info.GetInt32("cabFolder");
66 }
67
68 /// <summary>
69 /// Sets the SerializationInfo with information about the archive.
70 /// </summary>
71 /// <param name="info">The SerializationInfo that holds the serialized object data.</param>
72 /// <param name="context">The StreamingContext that contains contextual information
73 /// about the source or destination.</param>
74 public override void GetObjectData(SerializationInfo info, StreamingContext context)
75 {
76 base.GetObjectData(info, context);
77 info.AddValue("cabFolder", this.cabFolder);
78 }
79
80 /// <summary>
81 /// Gets or sets the cabinet that contains this file.
82 /// </summary>
83 /// <value>
84 /// The CabinetInfo instance that retrieved this file information -- this
85 /// may be null if the CabinetFileInfo object was returned directly from a
86 /// stream.
87 /// </value>
88 public CabInfo Cabinet
89 {
90 get
91 {
92 return (CabInfo) this.Archive;
93 }
94 }
95
96 /// <summary>
97 /// Gets the full path of the cabinet that contains this file.
98 /// </summary>
99 /// <value>The full path of the cabinet that contains this file.</value>
100 public string CabinetName
101 {
102 get
103 {
104 return this.ArchiveName;
105 }
106 }
107
108 /// <summary>
109 /// Gets the number of the folder containing this file.
110 /// </summary>
111 /// <value>The number of the cabinet folder containing this file.</value>
112 /// <remarks>A single folder or the first folder of a cabinet
113 /// (or chain of cabinets) is numbered 0.</remarks>
114 public int CabinetFolderNumber
115 {
116 get
117 {
118 if (this.cabFolder < 0)
119 {
120 this.Refresh();
121 }
122 return this.cabFolder;
123 }
124 }
125
126 /// <summary>
127 /// Refreshes the information in this object with new data retrieved
128 /// from an archive.
129 /// </summary>
130 /// <param name="newFileInfo">Fresh instance for the same file just
131 /// read from the archive.</param>
132 /// <remarks>
133 /// This implementation refreshes the <see cref="CabinetFolderNumber"/>.
134 /// </remarks>
135 protected override void Refresh(ArchiveFileInfo newFileInfo)
136 {
137 base.Refresh(newFileInfo);
138 this.cabFolder = ((CabFileInfo) newFileInfo).cabFolder;
139 }
140 }
141}