Corrected bug in ShellItem.Open that would incorrectly try to open .url files as IShellLink. Now opens them as IShellItem. (#82)

pull/90/head
David Hall 2019-12-30 14:21:15 -07:00
parent 4ced0d98da
commit 19bbc90234
1 changed files with 11 additions and 19 deletions

View File

@ -336,6 +336,7 @@ namespace Vanara.Windows.Shell
{ {
internal static readonly bool IsMin7 = Environment.OSVersion.Version >= new Version(6, 1); internal static readonly bool IsMin7 = Environment.OSVersion.Version >= new Version(6, 1);
internal static readonly bool IsMinVista = Environment.OSVersion.Version.Major >= 6; internal static readonly bool IsMinVista = Environment.OSVersion.Version.Major >= 6;
internal static readonly PROPERTYKEY pkItemType = PROPERTYKEY.System.ItemType;
internal IShellItem iShellItem; internal IShellItem iShellItem;
internal IShellItem2 iShellItem2; internal IShellItem2 iShellItem2;
private static Dictionary<Type, BHID> bhidLookup; private static Dictionary<Type, BHID> bhidLookup;
@ -476,29 +477,20 @@ namespace Vanara.Windows.Shell
/// <returns>A ShellItem derivative for the supplied IShellItem.</returns> /// <returns>A ShellItem derivative for the supplied IShellItem.</returns>
public static ShellItem Open(IShellItem iItem) public static ShellItem Open(IShellItem iItem)
{ {
if (iItem.GetAttributes(SFGAO.SFGAO_LINK) != 0) string itemType = null;
return new ShellLink(iItem); try { itemType = (iItem as IShellItem2)?.GetString(pkItemType)?.ToString().ToLowerInvariant(); } catch { }
// If not a folder, get the ShellItem var isFolder = iItem.GetAttributes(SFGAO.SFGAO_FOLDER) != 0;
if (iItem.GetAttributes(SFGAO.SFGAO_FOLDER) == 0)
return new ShellItem(iItem);
// Try to get specialized folder type from property // Try to get specialized folder type from property
var pk = PROPERTYKEY.System.ItemType; return itemType switch
string itemType = null;
try { itemType = (iItem as IShellItem2)?.GetString(pk)?.ToString().ToLowerInvariant(); } catch { }
switch (itemType)
{ {
case ".library-ms": ".lnk" => new ShellLink(iItem),
return new ShellLibrary(iItem); ".library-ms" => new ShellLibrary(iItem),
// TODO: ".searchconnector-ms" => Return a search connector
case ".searchconnector-ms": // TODO: ".search-ms" => Return a saved search connection
// TODO: Return a search connector _ => isFolder ? new ShellFolder(iItem) : new ShellItem(iItem),
case ".search-ms": };
// TODO: Return a saved search connection
default:
return new ShellFolder(iItem);
}
} }
/// <summary>Implements the operator !=.</summary> /// <summary>Implements the operator !=.</summary>