From cc31d17a4aad95aa8e0a367ed580ea64b35478b0 Mon Sep 17 00:00:00 2001 From: Richard Webb Date: Sun, 1 Dec 2024 12:24:16 +0000 Subject: [PATCH] Read the PropertySet Locale property into the PropertyContext if the property is present in the file --- OpenMcdf.Ole.Tests/OlePropertiesExtensionsTests.cs | 1 + OpenMcdf.Ole/OlePropertiesContainer.cs | 3 ++- OpenMcdf.Ole/PropertySet.cs | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/OpenMcdf.Ole.Tests/OlePropertiesExtensionsTests.cs b/OpenMcdf.Ole.Tests/OlePropertiesExtensionsTests.cs index 4f6c327..5e4eebf 100644 --- a/OpenMcdf.Ole.Tests/OlePropertiesExtensionsTests.cs +++ b/OpenMcdf.Ole.Tests/OlePropertiesExtensionsTests.cs @@ -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 diff --git a/OpenMcdf.Ole/OlePropertiesContainer.cs b/OpenMcdf.Ole/OlePropertiesContainer.cs index 2e935c5..ee1ccb1 100644 --- a/OpenMcdf.Ole/OlePropertiesContainer.cs +++ b/OpenMcdf.Ole/OlePropertiesContainer.cs @@ -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++) diff --git a/OpenMcdf.Ole/PropertySet.cs b/OpenMcdf.Ole/PropertySet.cs index 2d666b3..7583735 100644 --- a/OpenMcdf.Ole/PropertySet.cs +++ b/OpenMcdf.Ole/PropertySet.cs @@ -13,6 +13,8 @@ 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); @@ -20,6 +22,18 @@ public void LoadContext(int propertySetOffset, BinaryReader br) 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; }