Writing properties #1 – Simple beginnings
Writing properties #2 – Filetype support?
Writing properties #3 – Which properties are writable?
Writing properties #4 – Which properties are writable?
Writing properties #5 – Property lists
Writing properties #6 – GPS_READWRITE omits read-only data sources
The deal with IPropertyStoreCapabilities
Writing properties #8 – Canonical Values
Gotcha: You must release property stores quickly
Writing properties is very simple at the core: you just call SetValue() and then Commit(). But then there are a bunch of details surrounding this task that make it a little more complicated. To close this topic, I want to give one more tip:
The best way to determine if the file/filesystem/filetype itself is writable is to simply call IShellItem2::GetPropertyStore(GPS_READWRITE). This performs the necessary ACL checks, attribute checks, etc. The only downside is that the return value is non-actionable. If you want to display a more specifical error message or offer corrective options, you’ll have to program those yourself.
Thus, a property editing user interface will typically do the following:
- Test writability by opening the file with GPS_READWRITE and then release that interface
- Reopen the file with GPS_DEFAULT
- Use a property list to populate the UI
- Test writability using IPropertyDescription::GetTypeFlags
- Test writability using IPropertyStoreCapabilities::IsPropertyWritable
- Release the read-only property store
Then to save changes, it…
- Opens the file with GPS_READWRITE
- Calls IPropertyStore::SetValue for each change
- Calls IPropertyStore::Commit to save the changes
- Releases the read-write store
ps. There is an even simpler way to write properties using IFileOperation. I’ll have to revisit that another time.