Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read the PropertySet Locale property into the PropertyContext #259

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait. Should Context even be a member of OlePropertiesContainer? Can the one from PropertySet be used instead? I'm not sure of the reason for interaction, but its seems just like duplication at a glance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, don't know why it was cloning the context originally, and I didn't think to just use the existing context instance directly on read :-(

The write side at

PropertyContext = Context
is already just using the same context instead of cloning it, so it'd make sense to make them consistent

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
Loading