main
cs 214 lines 7.38 KB
Raw
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
3 namespace WixToolset.Data.WindowsInstaller.Rows
4 {
5 using System.Diagnostics;
6
7 /// <summary>
8 /// Specialization of a row for the file table.
9 /// </summary>
10 public sealed class FileRow : Row
11 {
12 /// <summary>
13 /// Creates a File row that belongs to a table.
14 /// </summary>
15 /// <param name="sourceLineNumbers">Original source lines for this row.</param>
16 /// <param name="table">Table this File row belongs to and should get its column definitions from.</param>
17 public FileRow(SourceLineNumber sourceLineNumbers, Table table)
18 : base(sourceLineNumbers, table)
19 {
20 }
21
22 /// <summary>
23 /// Creates a File row that does not belong to a table.
24 /// </summary>
25 /// <param name="sourceLineNumbers">Original source lines for this row.</param>
26 /// <param name="tableDefinition">TableDefinition this Media row belongs to and should get its column definitions from.</param>
27 public FileRow(SourceLineNumber sourceLineNumbers, TableDefinition tableDefinition)
28 : base(sourceLineNumbers, tableDefinition)
29 {
30 }
31
32 /// <summary>
33 /// Gets or sets the primary key of the file row.
34 /// </summary>
35 /// <value>Primary key of the file row.</value>
36 public string File
37 {
38 get => this.FieldAsString(0);
39 set => this.Fields[0].Data = value;
40 }
41
42 /// <summary>
43 /// Gets or sets the component this file row belongs to.
44 /// </summary>
45 /// <value>Component this file row belongs to.</value>
46 public string Component
47 {
48 get => this.FieldAsString(1);
49 set => this.Fields[1].Data = value;
50 }
51
52 /// <summary>
53 /// Gets or sets the name of the file.
54 /// </summary>
55 /// <value>Name of the file.</value>
56 public string FileName
57 {
58 get => this.FieldAsString(2);
59 set => this.Fields[2].Data = value;
60 }
61
62 /// <summary>
63 /// Gets or sets the real filesystem name of the file (without a pipe). This is typically the long name of the file.
64 /// However, if no long name is available, falls back to the short name.
65 /// </summary>
66 /// <value>Long Name of the file - or if no long name is available, falls back to the short name.</value>
67 public string LongFileName
68 {
69 get
70 {
71 var fileName = this.FileName;
72 var index = fileName.IndexOf('|');
73
74 // If it doesn't contain a pipe, just return the whole string
75 // otherwise, extract the part of the string after the pipe.
76 return (-1 == index) ? fileName : fileName.Substring(index + 1);
77 }
78 }
79
80 /// <summary>
81 /// Gets or sets the size of the file.
82 /// </summary>
83 /// <value>Size of the file.</value>
84 public int FileSize
85 {
86 get => this.FieldAsInteger(3);
87 set => this.Fields[3].Data = value;
88 }
89
90 /// <summary>
91 /// Gets or sets the version of the file.
92 /// </summary>
93 /// <value>Version of the file.</value>
94 public string Version
95 {
96 get => this.FieldAsString(4);
97 set => this.Fields[4].Data = value;
98 }
99
100 /// <summary>
101 /// Gets or sets the LCID of the file.
102 /// </summary>
103 /// <value>LCID of the file.</value>
104 public string Language
105 {
106 get => this.FieldAsString(5);
107 set => this.Fields[5].Data = value;
108 }
109
110 /// <summary>
111 /// Gets or sets the attributes on a file.
112 /// </summary>
113 /// <value>Attributes on a file.</value>
114 public int Attributes
115 {
116 get => this.FieldAsInteger(6);
117 set => this.Fields[6].Data = value;
118 }
119
120 /// <summary>
121 /// Gets or sets whether this file should be compressed.
122 /// </summary>
123 /// <value>Whether this file should be compressed.</value>
124 public YesNoType Compressed
125 {
126 get
127 {
128 var compressedFlag = (0 < (this.Attributes & WindowsInstallerConstants.MsidbFileAttributesCompressed));
129 var noncompressedFlag = (0 < (this.Attributes & WindowsInstallerConstants.MsidbFileAttributesNoncompressed));
130
131 if (compressedFlag && noncompressedFlag)
132 {
133 throw new WixException(ErrorMessages.IllegalFileCompressionAttributes(this.SourceLineNumbers));
134 }
135 else if (compressedFlag)
136 {
137 return YesNoType.Yes;
138 }
139 else if (noncompressedFlag)
140 {
141 return YesNoType.No;
142 }
143 else
144 {
145 return YesNoType.NotSet;
146 }
147 }
148
149 set
150 {
151 if (YesNoType.Yes == value)
152 {
153 // these are mutually exclusive
154 this.Attributes |= WindowsInstallerConstants.MsidbFileAttributesCompressed;
155 this.Attributes &= ~WindowsInstallerConstants.MsidbFileAttributesNoncompressed;
156 }
157 else if (YesNoType.No == value)
158 {
159 // these are mutually exclusive
160 this.Attributes |= WindowsInstallerConstants.MsidbFileAttributesNoncompressed;
161 this.Attributes &= ~WindowsInstallerConstants.MsidbFileAttributesCompressed;
162 }
163 else // not specified
164 {
165 Debug.Assert(YesNoType.NotSet == value);
166
167 // clear any compression bits
168 this.Attributes &= ~WindowsInstallerConstants.MsidbFileAttributesCompressed;
169 this.Attributes &= ~WindowsInstallerConstants.MsidbFileAttributesNoncompressed;
170 }
171 }
172 }
173
174 /// <summary>
175 /// Gets or sets the sequence of the file row.
176 /// </summary>
177 /// <value>Sequence of the file row.</value>
178 public int Sequence
179 {
180 get => this.FieldAsInteger(7);
181 set => this.Fields[7].Data = value;
182 }
183
184 /// <summary>
185 /// Gets or sets the disk id for this file.
186 /// </summary>
187 /// <value>Disk id for the file.</value>
188 public int DiskId
189 {
190 get => this.FieldAsInteger(8);
191 set => this.Fields[8].Data = value;
192 }
193
194 /// <summary>
195 /// Gets or sets the source location to the file.
196 /// </summary>
197 /// <value>Source location to the file.</value>
198 public string Source
199 {
200 get => this.FieldAsString(9);
201 set => this.Fields[9].Data = value;
202 }
203
204 /// <summary>
205 /// Gets or sets the source location to the previous file.
206 /// </summary>
207 /// <value>Source location to the previous file.</value>
208 public string PreviousSource
209 {
210 get => this.Fields[9].PreviousData;
211 set => this.Fields[9].PreviousData = value;
212 }
213 }
214 }