Skip to content

Commit

Permalink
Merge pull request #105 from Numpsy/users/rw/user_defined_1
Browse files Browse the repository at this point in the history
When writing user defined properties, add a DictionaryProperty before…
  • Loading branch information
ironfede authored Feb 25, 2024
2 parents 7d8129f + 3a2aff0 commit 5ce1c26
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ public void Save(CFStream cfStream)

ps.PropertySet1 = new PropertySet
{
NumProperties = (uint)this.UserDefinedProperties.Properties.Count(),
// Number of user defined properties, plus 1 for the name dictionary
NumProperties = (uint)this.UserDefinedProperties.Properties.Count() + 1,
PropertyIdentifierAndOffsets = new List<PropertyIdentifierAndOffset>(),
Properties = new List<Interfaces.IProperty>(),
PropertyContext = UserDefinedProperties.Context
Expand All @@ -251,13 +252,21 @@ public void Save(CFStream cfStream)
ps.FMTID1 = new Guid(WellKnownFMTID.FMTID_UserDefinedProperties);
ps.Offset1 = 0;

// Add the dictionary containing the property names
IDictionaryProperty dictionaryProperty = new DictionaryProperty(ps.PropertySet1.PropertyContext.CodePage)
{
Value = this.UserDefinedProperties.PropertyNames
};
ps.PropertySet1.Properties.Add(dictionaryProperty);
ps.PropertySet1.PropertyIdentifierAndOffsets.Add(new PropertyIdentifierAndOffset() { PropertyIdentifier = 0, Offset = 0 });

// Add the properties themselves
foreach (var op in this.UserDefinedProperties.Properties)
{
ITypedPropertyValue p = PropertyFactory.Instance.NewProperty(op.VTType, ps.PropertySet1.PropertyContext.CodePage);
p.Value = op.Value;
ps.PropertySet1.Properties.Add(p);
ps.PropertySet1.PropertyIdentifierAndOffsets.Add(new PropertyIdentifierAndOffset() { PropertyIdentifier = op.PropertyIdentifier, Offset = 0 });

}
}

Expand Down

0 comments on commit 5ce1c26

Please sign in to comment.