Skip to content

Commit

Permalink
Add some definitions of known property set names
Browse files Browse the repository at this point in the history
  • Loading branch information
Numpsy authored and jeremy-visionaid committed Nov 17, 2024
1 parent f4bf712 commit 6316bb0
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 23 deletions.
44 changes: 22 additions & 22 deletions OpenMcdf.Ole.Tests/OlePropertiesExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class OlePropertiesExtensionsTests
public void ReadSummaryInformation()
{
using var cf = RootStorage.OpenRead("_Test.ppt");
using CfbStream stream = cf.OpenStream("\u0005SummaryInformation");
using CfbStream stream = cf.OpenStream(PropertySetNames.SummaryInformation);
OlePropertiesContainer co = new(stream);

foreach (OleProperty p in co.Properties)
Expand All @@ -26,7 +26,7 @@ public void ReadSummaryInformation()
public void ReadDocumentSummaryInformation()
{
using var cf = RootStorage.OpenRead("_Test.ppt");
using CfbStream stream = cf.OpenStream("\u0005DocumentSummaryInformation");
using CfbStream stream = cf.OpenStream(PropertySetNames.DocSummaryInformation);
OlePropertiesContainer co = new(stream);

foreach (OleProperty p in co.Properties)
Expand All @@ -39,11 +39,11 @@ public void ReadDocumentSummaryInformation()
public void ReadThenWriteDocumentSummaryInformation()
{
using var cf = RootStorage.OpenRead("_Test.ppt");
using CfbStream stream = cf.OpenStream("\u0005DocumentSummaryInformation");
using CfbStream stream = cf.OpenStream(PropertySetNames.DocSummaryInformation);
OlePropertiesContainer co = new(stream);

using var cf2 = RootStorage.CreateInMemory();
using CfbStream stream2 = cf2.CreateStream("\u0005DocumentSummaryInformation");
using CfbStream stream2 = cf2.CreateStream(PropertySetNames.DocSummaryInformation);
co.Save(stream2);
}

Expand All @@ -58,7 +58,7 @@ public void ModifyDocumentSummaryInformation()
// Verify initial properties, and then create a modified document
using (var cf = RootStorage.Open(modifiedStream, StorageModeFlags.LeaveOpen))
{
using CfbStream dsiStream = cf.OpenStream("\u0005DocumentSummaryInformation");
using CfbStream dsiStream = cf.OpenStream(PropertySetNames.DocSummaryInformation);
OlePropertiesContainer co = new(dsiStream);

// The company property should exist but be empty
Expand All @@ -83,7 +83,7 @@ public void ModifyDocumentSummaryInformation()

using (var cf = RootStorage.Open(modifiedStream))
{
using CfbStream stream = cf.OpenStream("\u0005DocumentSummaryInformation");
using CfbStream stream = cf.OpenStream(PropertySetNames.DocSummaryInformation);
OlePropertiesContainer co = new(stream);

OleProperty companyProperty = co.Properties.First(prop => prop.PropertyName == "PIDDSI_COMPANY");
Expand All @@ -102,15 +102,15 @@ public void ReadSummaryInformationUtf8()
{
// Regression test for #33
using var cf = RootStorage.Open("wstr_presets.doc", FileMode.Open);
using CfbStream stream = cf.OpenStream("\u0005SummaryInformation");
using CfbStream stream = cf.OpenStream(PropertySetNames.SummaryInformation);
OlePropertiesContainer co = new(stream);

foreach (OleProperty p in co.Properties)
{
Debug.WriteLine(p);
}

using CfbStream stream2 = cf.OpenStream("\u0005DocumentSummaryInformation");
using CfbStream stream2 = cf.OpenStream(PropertySetNames.DocSummaryInformation);
OlePropertiesContainer co2 = new(stream2);

foreach (OleProperty p in co2.Properties)
Expand All @@ -124,15 +124,15 @@ public void ReadSummaryInformationUtf8Part2()
{
// Regression test for #34
using var cf = RootStorage.OpenRead("2custom.doc");
using CfbStream stream = cf.OpenStream("\u0005SummaryInformation");
using CfbStream stream = cf.OpenStream(PropertySetNames.SummaryInformation);
OlePropertiesContainer co = new(stream);

foreach (OleProperty p in co.Properties)
{
Debug.WriteLine(p);
}

using CfbStream stream2 = cf.OpenStream("\u0005DocumentSummaryInformation");
using CfbStream stream2 = cf.OpenStream(PropertySetNames.DocSummaryInformation);
OlePropertiesContainer co2 = new(stream2);

foreach (OleProperty p in co2.Properties)
Expand All @@ -153,7 +153,7 @@ public void ReadSummaryInformationUtf8Part2()
public void SummaryInformationReadLpwstring()
{
using var cf = RootStorage.OpenRead("english.presets.doc");
using CfbStream stream = cf.OpenStream("\u0005SummaryInformation");
using CfbStream stream = cf.OpenStream(PropertySetNames.SummaryInformation);
OlePropertiesContainer co = new(stream);

foreach (OleProperty p in co.Properties)
Expand All @@ -173,7 +173,7 @@ public void SummaryInformationModifyLpwstring()
// Modify some LPWSTR properties, and save to a new file
using (var cf = RootStorage.Open(modifiedStream, StorageModeFlags.LeaveOpen))
{
using CfbStream dsiStream = cf.OpenStream("\u0005SummaryInformation");
using CfbStream dsiStream = cf.OpenStream(PropertySetNames.SummaryInformation);
OlePropertiesContainer co = new(dsiStream);

OleProperty authorProperty = co.Properties.First(prop => prop.PropertyName == "PIDSI_AUTHOR");
Expand All @@ -192,7 +192,7 @@ public void SummaryInformationModifyLpwstring()
// Open the new file and check for the expected values
using (var cf = RootStorage.Open(modifiedStream))
{
using CfbStream stream = cf.OpenStream("\u0005SummaryInformation");
using CfbStream stream = cf.OpenStream(PropertySetNames.SummaryInformation);
OlePropertiesContainer co = new(stream);

OleProperty authorProperty = co.Properties.First(prop => prop.PropertyName == "PIDSI_AUTHOR");
Expand All @@ -210,7 +210,7 @@ public void SummaryInformationModifyLpwstring()
public void TestReadUnicodeUserPropertiesDictionary()
{
using var cf = RootStorage.OpenRead("winUnicodeDictionary.doc");
CfbStream dsiStream = cf.OpenStream("\u0005DocumentSummaryInformation");
CfbStream dsiStream = cf.OpenStream(PropertySetNames.DocSummaryInformation);
OlePropertiesContainer co = new(dsiStream);
OlePropertiesContainer? userProps = co.UserDefinedProperties;

Expand Down Expand Up @@ -259,7 +259,7 @@ public void AddDocumentSummaryInformationCustomInfo()
// english.presets.doc has a user defined property section, but no properties other than the codepage
using (var cf = RootStorage.Open(modifiedStream, StorageModeFlags.LeaveOpen))
{
using CfbStream dsiStream = cf.OpenStream("\u0005DocumentSummaryInformation");
using CfbStream dsiStream = cf.OpenStream(PropertySetNames.DocSummaryInformation);
OlePropertiesContainer co = new(dsiStream);
OlePropertiesContainer? userProperties = co.UserDefinedProperties;

Expand Down Expand Up @@ -296,7 +296,7 @@ public void AddDocumentSummaryInformationCustomInfo()

using (var cf = RootStorage.Open(modifiedStream))
{
using CfbStream stream = cf.OpenStream("\u0005DocumentSummaryInformation");
using CfbStream stream = cf.OpenStream(PropertySetNames.DocSummaryInformation);
OlePropertiesContainer co = new(stream);

Assert.IsNotNull(co.UserDefinedProperties);
Expand Down Expand Up @@ -341,7 +341,7 @@ public void TestAddUserDefinedProperty()
// english.presets.doc has a user defined property section, but no properties other than the codepage
using (var cf = RootStorage.Open(modifiedStream, StorageModeFlags.LeaveOpen))
{
CfbStream dsiStream = cf.OpenStream("\u0005DocumentSummaryInformation");
CfbStream dsiStream = cf.OpenStream(PropertySetNames.DocSummaryInformation);
OlePropertiesContainer co = new(dsiStream);
OlePropertiesContainer userProperties = co.UserDefinedProperties!;
userProperties.AddUserDefinedProperty(VTPropertyType.VT_LPSTR, "StringProperty").Value = "Hello";
Expand All @@ -360,7 +360,7 @@ public void TestAddUserDefinedProperty()
private static void ValidateAddedUserDefinedProperties(MemoryStream stream, DateTime testFileTimeValue)
{
using var cf = RootStorage.Open(stream);
using CfbStream cfbStream = cf.OpenStream("\u0005DocumentSummaryInformation");
using CfbStream cfbStream = cf.OpenStream(PropertySetNames.DocSummaryInformation);
OlePropertiesContainer co = new(cfbStream);
IList<OleProperty> propArray = co.UserDefinedProperties!.Properties;
Assert.AreEqual(6, propArray.Count);
Expand Down Expand Up @@ -397,7 +397,7 @@ public void TestAddUserDefinedPropertyShouldPreventDuplicates()
stream.CopyTo(modifiedStream);

using var cf = RootStorage.Open(modifiedStream);
CfbStream dsiStream = cf.OpenStream("\u0005DocumentSummaryInformation");
CfbStream dsiStream = cf.OpenStream(PropertySetNames.DocSummaryInformation);
OlePropertiesContainer co = new(dsiStream);
OlePropertiesContainer userProperties = co.UserDefinedProperties!;

Expand All @@ -415,7 +415,7 @@ public void TestAddUserDefinedPropertyShouldPreventDuplicates()
public void ReadLpwstringVector()
{
using var cf = RootStorage.OpenRead("SampleWorkBook_bug98.xls");
using CfbStream stream = cf.OpenStream("\u0005DocumentSummaryInformation");
using CfbStream stream = cf.OpenStream(PropertySetNames.DocSummaryInformation);
OlePropertiesContainer co = new(stream);

OleProperty? docPartsProperty = co.Properties.FirstOrDefault(property => property.PropertyIdentifier == 13); //13 == PIDDSI_DOCPARTS
Expand Down Expand Up @@ -452,7 +452,7 @@ public void AddUserDefinedPropertiesSection()

using (var cf = RootStorage.Open(modifiedStream, StorageModeFlags.LeaveOpen))
{
using CfbStream dsiStream = cf.OpenStream("\u0005DocumentSummaryInformation");
using CfbStream dsiStream = cf.OpenStream(PropertySetNames.DocSummaryInformation);
OlePropertiesContainer co = new(dsiStream);

Assert.IsNull(co.UserDefinedProperties);
Expand All @@ -471,7 +471,7 @@ public void AddUserDefinedPropertiesSection()

using (var cf = RootStorage.Open(modifiedStream))
{
using CfbStream stream = cf.OpenStream("\u0005DocumentSummaryInformation");
using CfbStream stream = cf.OpenStream(PropertySetNames.DocSummaryInformation);
OlePropertiesContainer co = new(stream);

// User defined properties should be present now
Expand Down
17 changes: 17 additions & 0 deletions OpenMcdf.Ole/PropertySetNames.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace OpenMcdf.Ole;


/// <summary>
/// Some well known property set names.
/// </summary>
/// <remarks>
/// As defined at https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-oleps/e5484a83-3cc1-43a6-afcf-6558059fe36e
/// </remarks>
public static class PropertySetNames
{
public const string SummaryInformation = "\u0005SummaryInformation";
public const string DocSummaryInformation = "\u0005DocumentSummaryInformation";
public const string GlobalInfo = "\u0005GlobalInfo";
public const string ImageContents = "\u000505ImageContents";
public const string ImageInfo = "\u0005ImageInfo";
}
2 changes: 1 addition & 1 deletion StructuredStorageExplorer/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ private void UpdateOleTab(CfbStream stream)
dgvUserDefinedProperties.DataSource = null;
dgvOLEProps.DataSource = null;

if (stream.EntryInfo.Name is "\u0005SummaryInformation" or "\u0005DocumentSummaryInformation")
if (stream.EntryInfo.Name is PropertySetNames.SummaryInformation or PropertySetNames.DocSummaryInformation)
{
OlePropertiesContainer c = new(stream);

Expand Down

0 comments on commit 6316bb0

Please sign in to comment.