1

I've successfully obtained an IPropertyBag for the view state of a folder. I obtained it using SHGetViewStatePropertyBag, and I've confirmed that the bag is valid by checking some property values.

What I'd like to do now is persist the property bag to disk as a blob, if possible. I've been running QueryInterface on the bag, and I haven't been able to obtain any helpful interfaces. Unfortunately, it appears that the property bag doesn't support an IPersistStream interface. And I haven't been able to successfully query the IPersistPropertyBag interface either.

Is there a trick to getting some sort of persist interface for a property bag? Or do the properties essentially have to be saved individually, in an ad hoc manner? Thanks in advance for any guidance.

  • If there's no persist interface, or if IPropertBag2::Write is not implemented, it means it's a read-only bag (the Shell doesn't want you to do that and break its things). I don't know of any builtin IPersistPropertyBag(2) implementation that we can reuse. So, you'll have to enumerate properties and save/read them the way you like. – Simon Mourier Jun 18 '20 at 18:31
  • Okay, thank you very much. –  Jun 18 '20 at 18:36
  • How about IPersistStreamInit? It's very similar to IPersistStream but does not actually derive from IPersistStream. And if all else fails you might query for IProvideClassInfo and write out the ITypeInfo (I know this would be a PITA but if implemented it will likely give you a much better idea of what interfaces are actually available). – SoronelHaetir Jun 18 '20 at 19:29
  • @SoronelHaetir Thanks, but `IPersistStreamInit` didn't work. –  Jun 18 '20 at 19:39

1 Answers1

0

Calling Write on the IPropertyBag should write the change to disk automagically.

In general, IPersistXXX interface is implemented by objects that can save themselves into an XXX (where XXX is either Stream or PropertyBag), meanwhile IPropertyBag and IStream are expected to be backed by something - a disk, or a memory block, or a socket.

Or do want to take all properties from the bag and somehow save them elsewhere? In that case, you'd want to query for IPropertyBag2 and enumerate them.

Seva Alekseyev
  • 59,826
  • 25
  • 160
  • 281
  • Yes, to clarify, I meant I wanted to save the bag elsewhere, ideally as just a blob. I should have clarified. And unfornately, `IPropertyBag2` is not implemented by the bag. I think you can obtain the interface, but the methods aren't implemented. –  Jun 18 '20 at 17:58
  • What's the larger context? What are you trying to do in the first place? – Seva Alekseyev Jun 18 '20 at 18:12
  • I'm trying to implement a feature that allows the user to save the current folder layout (columns, sort order, etc.) by name, and then apply that layout to other folders as desired. –  Jun 18 '20 at 18:15
  • What I'd pursue instead, get a `IShellFolder` or `IShelLFolderView`, see if one of *those* supports `IPersistPropertyBag`, implement your own `IPropertyBag` and tell the folder object to save to *that*. – Seva Alekseyev Jun 18 '20 at 18:19
  • I'm trying that method. Do you know how to create an empty property bag for use with `IPersistPropertyBag`? –  Jun 18 '20 at 23:07
  • Implement your own. `class MyPropertyBag: public IPropertyBag { /* and so forth */ };` – Seva Alekseyev Jun 19 '20 at 01:21