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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
// 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.Dtf.Resources
{
using System;
using System.IO;
using System.Text;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Diagnostics.CodeAnalysis;
/// <summary>
/// Represents a string table of a file version resource.
/// </summary>
[SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")]
public sealed class VersionStringTable : IDictionary<string, string>
{
private VersionResource parent;
private VersionInfo rawStringVersionInfo;
internal VersionStringTable(VersionResource parent, VersionInfo rawStringVersionInfo)
{
this.parent = parent;
this.rawStringVersionInfo = rawStringVersionInfo;
}
/// <summary>
/// Gets the locale (LCID) of the string table.
/// </summary>
public int Locale
{
get
{
return UInt16.Parse(rawStringVersionInfo.Key.Substring(0, 4), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
}
set
{
rawStringVersionInfo.Key = ((ushort) value).ToString("x4", CultureInfo.InvariantCulture) + rawStringVersionInfo.Key.Substring(4, 4);
this.parent.dirty = true;
}
}
/// <summary>
/// Gets or sets a string value.
/// </summary>
/// <param name="key">Name of the string.</param>
public string this[string key]
{
get
{
VersionInfo verValue = this.rawStringVersionInfo[key];
if (verValue == null)
{
return null;
}
else
{
return Encoding.Unicode.GetString(verValue.Data, 0, verValue.Data.Length - 2);
}
}
set
{
if (value == null)
{
rawStringVersionInfo.Remove(key);
}
else
{
VersionInfo verValue = rawStringVersionInfo[key];
if (verValue == null)
{
verValue = new VersionInfo(key);
verValue.IsString = true;
rawStringVersionInfo.Add(verValue);
}
verValue.Data = new byte[Encoding.Unicode.GetByteCount(value) + 2];
Encoding.Unicode.GetBytes(value, 0, value.Length, verValue.Data, 0);
}
this.parent.dirty = true;
}
}
bool ICollection<KeyValuePair<string, string>>.IsReadOnly
{
get
{
return false;
}
}
bool IDictionary<string, string>.TryGetValue(string key, out string value)
{
value = this[key];
return value != null;
}
void ICollection<KeyValuePair<string, string>>.Add(KeyValuePair<string, string> item)
{
this[item.Key] = item.Value;
}
bool ICollection<KeyValuePair<string, string>>.Remove(KeyValuePair<string, string> item)
{
string value = this[item.Key];
if (value == item.Value)
{
this[item.Key] = null;
return true;
}
else
{
return false;
}
}
bool ICollection<KeyValuePair<string, string>>.Contains(KeyValuePair<string, string> item)
{
string value = this[item.Key];
if (value == item.Value)
{
return true;
}
else
{
return false;
}
}
bool IDictionary<string, string>.ContainsKey(string key)
{
return this[key] != null;
}
void IDictionary<string, string>.Add(string key, string value)
{
this[key] = value;
}
bool IDictionary<string, string>.Remove(string key)
{
if (this[key] != null)
{
this[key] = null;
return true;
}
else
{
return false;
}
}
/// <summary>
/// Removes all strings from the string table.
/// </summary>
public void Clear()
{
this.rawStringVersionInfo.Clear();
}
/// <summary>
/// Gets a collection of all the names of the strings in the table.
/// </summary>
public ICollection<string> Keys
{
get
{
List<string> keys = new List<string>(this.rawStringVersionInfo.Count);
foreach (VersionInfo verValue in this.rawStringVersionInfo)
{
keys.Add(verValue.Key);
}
return keys;
}
}
/// <summary>
/// Gets a collection of all the values in the table.
/// </summary>
public ICollection<string> Values
{
get
{
List<string> values = new List<string>(this.rawStringVersionInfo.Count);
foreach (VersionInfo verValue in this.rawStringVersionInfo)
{
values.Add(Encoding.Unicode.GetString(verValue.Data, 0, verValue.Data.Length - 2));
}
return values;
}
}
/// <summary>
/// Gets the number of strings in the table.
/// </summary>
public int Count
{
get
{
return this.rawStringVersionInfo.Count;
}
}
void ICollection<KeyValuePair<string, string>>.CopyTo(KeyValuePair<string, string>[] array, int index)
{
foreach (VersionInfo verValue in this.rawStringVersionInfo)
{
array[index++] = new KeyValuePair<string, string>(verValue.Key, Encoding.Unicode.GetString(verValue.Data, 0, verValue.Data.Length - 2));
}
}
/// <summary>
/// Gets an enumeration over all strings in the table.
/// </summary>
/// <returns>Enumeration of string name and value pairs</returns>
public IEnumerator<KeyValuePair<string, string>> GetEnumerator()
{
foreach (VersionInfo verValue in this.rawStringVersionInfo)
{
yield return new KeyValuePair<string, string>(verValue.Key, Encoding.Unicode.GetString(verValue.Data, 0, verValue.Data.Length - 2));
}
}
IEnumerator IEnumerable.GetEnumerator()
{
return this.GetEnumerator();
}
}
}
|