Skip to content

Commit

Permalink
Read the PropertySet Locale property into the PropertyContext if the …
Browse files Browse the repository at this point in the history
…property is present in the file
  • Loading branch information
Numpsy committed Dec 4, 2024
1 parent 0c7308d commit 9463e0a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions OpenMcdf.Ole.Tests/OlePropertiesExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ public void TestRetainDictionaryPropertyInAppSpecificStreams()

Assert.AreEqual(ContainerType.AppSpecific, co.ContainerType);
Assert.AreEqual(expectedFmtid0, co.FMTID0);
Assert.AreEqual(1040u, co.Context.Locale);
CollectionAssert.AreEqual(expectedPropertyNames, co.PropertyNames);

// Write test file
Expand Down
3 changes: 2 additions & 1 deletion OpenMcdf.Ole/OlePropertiesContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public OlePropertiesContainer(CfbStream cfStream)

Context = new PropertyContext()
{
CodePage = pStream.PropertySet0.PropertyContext.CodePage
CodePage = pStream.PropertySet0.PropertyContext.CodePage,
Locale = pStream.PropertySet0.PropertyContext.Locale
};

for (int i = 0; i < pStream.PropertySet0.Properties.Count; i++)
Expand Down
14 changes: 14 additions & 0 deletions OpenMcdf.Ole/PropertySet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,27 @@ internal sealed class PropertySet
public void LoadContext(int propertySetOffset, BinaryReader br)
{
long currPos = br.BaseStream.Position;

// Read the code page - this should always be present
int codePageOffset = (int)(propertySetOffset + PropertyIdentifierAndOffsets.First(pio => pio.PropertyIdentifier == SpecialPropertyIdentifiers.CodePage).Offset);
br.BaseStream.Seek(codePageOffset, SeekOrigin.Begin);

var vType = (VTPropertyType)br.ReadUInt16();
br.ReadUInt16(); // Ushort Padding
PropertyContext.CodePage = (ushort)br.ReadInt16();

// Read the Locale, if present
PropertyIdentifierAndOffset? localeProperty = PropertyIdentifierAndOffsets.FirstOrDefault(pio => pio.PropertyIdentifier == SpecialPropertyIdentifiers.Locale);
if (localeProperty is not null)
{
long localeOffset = (propertySetOffset + localeProperty.Offset);
br.BaseStream.Seek(localeOffset, SeekOrigin.Begin);

vType = (VTPropertyType)br.ReadUInt16();
br.ReadUInt16(); // Ushort Padding
PropertyContext.Locale = br.ReadUInt32();
}

br.BaseStream.Position = currPos;
}

Expand Down

0 comments on commit 9463e0a

Please sign in to comment.