Skip to content

Commit

Permalink
Start adding some constants for properties that are treated specially
Browse files Browse the repository at this point in the history
Rather than having the numerical identifiers in multiple places
  • Loading branch information
Numpsy authored and jeremy-visionaid committed Dec 4, 2024
1 parent 11ad394 commit 0c7308d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions OpenMcdf.Ole/OlePropertiesContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public OlePropertiesContainer(CfbStream cfStream)
for (int i = 0; i < pStream.PropertySet0.Properties.Count; i++)
{
PropertyIdentifierAndOffset propertyIdentifierAndOffset = pStream.PropertySet0.PropertyIdentifierAndOffsets[i];
if (propertyIdentifierAndOffset.PropertyIdentifier == 0) continue;
if (propertyIdentifierAndOffset.PropertyIdentifier == SpecialPropertyIdentifiers.Dictionary) continue;
//if (propertyIdentifierAndOffset.PropertyIdentifier == 1) continue;
//if (propertyIdentifierAndOffset.PropertyIdentifier == 0x80000000) continue;

Expand All @@ -95,7 +95,7 @@ public OlePropertiesContainer(CfbStream cfStream)
for (int i = 0; i < propertySet1.Properties.Count; i++)
{
PropertyIdentifierAndOffset propertyIdentifierAndOffset = propertySet1.PropertyIdentifierAndOffsets[i];
if (propertyIdentifierAndOffset.PropertyIdentifier is 0 or 0x80000000)
if (propertyIdentifierAndOffset.PropertyIdentifier is SpecialPropertyIdentifiers.Dictionary or SpecialPropertyIdentifiers.Locale)
continue;

var p = (ITypedPropertyValue)propertySet1.Properties[i];
Expand Down
4 changes: 2 additions & 2 deletions OpenMcdf.Ole/PropertySet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal sealed class PropertySet
public void LoadContext(int propertySetOffset, BinaryReader br)
{
long currPos = br.BaseStream.Position;
int codePageOffset = (int)(propertySetOffset + PropertyIdentifierAndOffsets.First(pio => pio.PropertyIdentifier == 1).Offset);
int codePageOffset = (int)(propertySetOffset + PropertyIdentifierAndOffsets.First(pio => pio.PropertyIdentifier == SpecialPropertyIdentifiers.CodePage).Offset);
br.BaseStream.Seek(codePageOffset, SeekOrigin.Begin);

var vType = (VTPropertyType)br.ReadUInt16();
Expand All @@ -30,6 +30,6 @@ public void Add(IDictionary<uint, string> propertyNames)
Value = propertyNames
};
Properties.Add(dictionaryProperty);
PropertyIdentifierAndOffsets.Add(new PropertyIdentifierAndOffset() { PropertyIdentifier = 0, Offset = 0 });
PropertyIdentifierAndOffsets.Add(new PropertyIdentifierAndOffset() { PropertyIdentifier = SpecialPropertyIdentifiers.Dictionary, Offset = 0 });
}
}
2 changes: 1 addition & 1 deletion OpenMcdf.Ole/PropertySetStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public void Write(BinaryWriter bw)

private static IProperty ReadProperty(uint propertyIdentifier, int codePage, BinaryReader br, PropertyFactory factory)
{
if (propertyIdentifier == 0)
if (propertyIdentifier == SpecialPropertyIdentifiers.Dictionary)
{
DictionaryProperty dictionaryProperty = new(codePage);
dictionaryProperty.Read(br);
Expand Down
9 changes: 9 additions & 0 deletions OpenMcdf.Ole/SpecialPropertyIdentifiers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace OpenMcdf.Ole;

// Identifiers for properties that we treat specially.
internal static class SpecialPropertyIdentifiers
{
public const uint Dictionary = 0;
public const uint CodePage = 1;
public const uint Locale = 0x80000000;
}

0 comments on commit 0c7308d

Please sign in to comment.