BREAKING CHANGE: Changed default behavior of ShellItem.Properties so that it is read-only. It was failing for all shell items that didn't have their own properties. To get previous behavior, simply set "shellItem.Properties.ReadOnly = false" before setting properties.

pull/133/head
dahall 2020-06-01 10:43:51 -06:00
parent 24031bc4d1
commit 491c26e0d6
3 changed files with 34 additions and 7 deletions

View File

@ -3,6 +3,9 @@ using System;
using System.Collections; using System.Collections;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices;
using Vanara.PInvoke.Tests;
using static Vanara.PInvoke.Ole32;
namespace Vanara.Windows.Shell.Tests namespace Vanara.Windows.Shell.Tests
{ {
@ -14,9 +17,9 @@ namespace Vanara.Windows.Shell.Tests
[Test] [Test]
public void DescriptionTest() public void DescriptionTest()
{ {
using var i = new ShellItem(testDoc); using var i = new ShellItem(TestCaseSources.LogFile);
var c = 0; var c = 0;
foreach (var d in i.Properties.Descriptions) foreach (var d in i.PropertyDescriptions)
{ {
c++; c++;
Assert.That(d, Is.Not.Null); Assert.That(d, Is.Not.Null);
@ -75,6 +78,22 @@ namespace Vanara.Windows.Shell.Tests
Assert.That(c, Is.EqualTo(i.Properties.Count)); Assert.That(c, Is.EqualTo(i.Properties.Count));
} }
[Test]
public void WritableTest()
{
// Try accessing a text file's writable properties and assert a failure.
using (var i = new ShellItem(TestCaseSources.LogFile))
{
i.Properties.ReadOnly = false;
Assert.That(() => i.Properties.TryGetValue(PROPERTYKEY.System.Size, out var val), Throws.TypeOf<InvalidOperationException>());
}
// Try accessing a Word file's writable properties and assert successs.
using var w = new ShellItem(testDoc);
w.Properties.ReadOnly = false;
Assert.That(w.Properties.TryGetValue(PROPERTYKEY.System.Size, out _), Is.True);
}
[Test] [Test]
public void ShellItemPropertyStoreTest1() public void ShellItemPropertyStoreTest1()
{ {

View File

@ -6,7 +6,6 @@ using System.Drawing;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes; using System.Runtime.InteropServices.ComTypes;
using System.Text; using System.Text;
using System.Threading;
using Vanara.Extensions; using Vanara.Extensions;
using Vanara.InteropServices; using Vanara.InteropServices;
using Vanara.PInvoke; using Vanara.PInvoke;
@ -458,13 +457,21 @@ namespace Vanara.Windows.Shell
} }
} }
/// <summary>Gets the property store for the item.</summary> /// <summary>
/// <para>Gets the property store for the item.</para>
/// <note>Initially, this property store is the read-only store (change from R/W in v3.2.9) and should always have properties.
/// However, setting any of the properties of this value change the function of all subsequent uses. For example, if you set the
/// <see cref="ShellItemPropertyStore.ReadOnly"/> value to <see langword="false"/>, all subsequent calls to <see
/// cref="ShellItem.Properties"/> will access the read-write property store. If this <see cref="ShellItem"/> does not support
/// properties directly, your use of this property will fail. It is important that you check for exceptions when changing the
/// properties of this value to prevent unexpected failures.</note>
/// </summary>
/// <value>The dictionary of properties.</value> /// <value>The dictionary of properties.</value>
public ShellItemPropertyStore Properties => props ?? (props = new ShellItemPropertyStore(this) { ReadOnly = false }); public ShellItemPropertyStore Properties => props ??= new ShellItemPropertyStore(this);
/// <summary>Gets a property description list object containing descriptions of all properties.</summary> /// <summary>Gets a property description list object containing descriptions of all properties suitable to be shown in the UI.</summary>
/// <returns>A complete <see cref="PropertyDescriptionList"/> instance.</returns> /// <returns>A complete <see cref="PropertyDescriptionList"/> instance.</returns>
public PropertyDescriptionList PropertyDescriptions => propDescList ?? (propDescList = GetPropertyDescriptionList(PROPERTYKEY.System.PropList.FullDetails)); public PropertyDescriptionList PropertyDescriptions => propDescList ??= GetPropertyDescriptionList(PROPERTYKEY.System.PropList.FullDetails);
/// <summary>Gets the normal tool tip text associated with this item.</summary> /// <summary>Gets the normal tool tip text associated with this item.</summary>
/// <value>The tool tip text.</value> /// <value>The tool tip text.</value>

View File

@ -17,6 +17,7 @@ Enumerations
ChangeFilters, ExecutableType, FolderItemFilter, LibraryFolderFilter, LibraryViewTemplate, LinkResolution, OperationFlags, ShellIconType, ShellImageSize, ShellItemAttribute, ShellItemComparison, ShellItemDisplayString, ShellItemGetImageOptions, ShellItemToolTipOptions, TaskbarButtonProgressState, TaskbarItemTabThumbnailOption, TransferFlags, VerbMultiSelectModel, VerbPosition, VerbSelectionModel, Visibility ChangeFilters, ExecutableType, FolderItemFilter, LibraryFolderFilter, LibraryViewTemplate, LinkResolution, OperationFlags, ShellIconType, ShellImageSize, ShellItemAttribute, ShellItemComparison, ShellItemDisplayString, ShellItemGetImageOptions, ShellItemToolTipOptions, TaskbarButtonProgressState, TaskbarItemTabThumbnailOption, TransferFlags, VerbMultiSelectModel, VerbPosition, VerbSelectionModel, Visibility
</PackageReleaseNotes> </PackageReleaseNotes>
<RootNamespace>Vanara.Windows.Shell</RootNamespace>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Compile Remove="_InProgress_\**\*" /> <Compile Remove="_InProgress_\**\*" />