Skip to content

Commit

Permalink
Merge pull request #138 from conormcg94/users/cmcg/clsid_property
Browse files Browse the repository at this point in the history
Added CLSID property to OLEProperties
  • Loading branch information
ironfede authored Aug 6, 2024
2 parents 2c60fa8 + c5545d8 commit 4d1a331
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
24 changes: 24 additions & 0 deletions sources/OpenMcdf.Extensions/OLEProperties/PropertyFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ public ITypedPropertyValue NewProperty(VTPropertyType vType, int codePage, bool
case VTPropertyType.VT_BLOB:
pr = new VT_BLOB_Property(vType, isVariant);
break;
case VTPropertyType.VT_CLSID:
pr = new VT_CLSID_Property(vType, isVariant);
break;
default:
throw new Exception("Unrecognized property type");
}
Expand Down Expand Up @@ -699,6 +702,27 @@ public override void WriteScalarValue(BinaryWriter bw, object pValue)

}

private class VT_CLSID_Property : TypedPropertyValue<object>
{
public VT_CLSID_Property(VTPropertyType vType, bool isVariant) : base(vType, isVariant)
{

}

public override object ReadScalarValue(System.IO.BinaryReader br)
{
byte[] data = br.ReadBytes(16);
return new Guid(data);
}

public override void WriteScalarValue(BinaryWriter bw, object pValue)
{
byte[] r = pValue as byte[];
if (r != null)
bw.Write(r);
}
}

private class VT_VariantVector : TypedPropertyValue<object>
{
private readonly int codePage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,5 +442,17 @@ public void Test_DOCUMENT_SUMMARY_INFO_ADD_CUSTOM()
Assert.AreEqual(VTPropertyType.VT_FILETIME, propArray[4].VTType);
}
}

[TestMethod]
public void Test_CLSID_PROPERTY()
{
var guid = new Guid("15891a95-bf6e-4409-b7d0-3a31c391fa31");
using (CompoundFile cf = new CompoundFile("CLSIDPropertyTest.file"))
{
var co = cf.RootStorage.GetStream("\u0005C3teagxwOttdbfkuIaamtae3Ie").AsOLEPropertiesContainer();
var clsidProp = co.Properties.First(x => x.PropertyName == "DocumentID");
Assert.AreEqual(guid, clsidProp.Value);
}
}
}
}
Binary file added sources/Test/TestFiles/CLSIDPropertyTest.file
Binary file not shown.

0 comments on commit 4d1a331

Please sign in to comment.