-
Notifications
You must be signed in to change notification settings - Fork 78
/
DictionaryEntry.cs
65 lines (51 loc) · 1.49 KB
/
DictionaryEntry.cs
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace OpenMcdf.Extensions.OLEProperties
{
public class DictionaryEntry
{
private const int CP_WINUNICODE = 0x04B0;
int codePage;
public DictionaryEntry(int codePage)
{
this.codePage = codePage;
}
public uint PropertyIdentifier { get; set; }
public int Length { get; set; }
public String Name { get { return GetName(); } }
private byte[] nameBytes;
public void Read(BinaryReader br)
{
PropertyIdentifier = br.ReadUInt32();
Length = br.ReadInt32();
if (codePage != CP_WINUNICODE)
{
nameBytes = br.ReadBytes(Length);
}
else
{
nameBytes = br.ReadBytes(Length << 1);
int m = (Length * 2) % 4;
if (m > 0)
br.ReadBytes(m);
}
}
public void Write(BinaryWriter bw)
{
bw.Write(PropertyIdentifier);
bw.Write(Length);
bw.Write(nameBytes);
//if (codePage == CP_WINUNICODE)
// int m = Length % 4;
//if (m > 0)
// for (int i = 0; i < m; i++)
// bw.Write((byte)m);
}
private string GetName()
{
return Encoding.GetEncoding(this.codePage).GetString(nameBytes);
}
}
}