mirror of https://github.com/dahall/Vanara.git
Corrected bug in ShellItem.Open that would incorrectly try to open .url files as IShellLink. Now opens them as IShellItem. (#82)
parent
4ced0d98da
commit
19bbc90234
|
@ -336,6 +336,7 @@ namespace Vanara.Windows.Shell
|
|||
{
|
||||
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 PROPERTYKEY pkItemType = PROPERTYKEY.System.ItemType;
|
||||
internal IShellItem iShellItem;
|
||||
internal IShellItem2 iShellItem2;
|
||||
private static Dictionary<Type, BHID> bhidLookup;
|
||||
|
@ -476,29 +477,20 @@ namespace Vanara.Windows.Shell
|
|||
/// <returns>A ShellItem derivative for the supplied IShellItem.</returns>
|
||||
public static ShellItem Open(IShellItem iItem)
|
||||
{
|
||||
if (iItem.GetAttributes(SFGAO.SFGAO_LINK) != 0)
|
||||
return new ShellLink(iItem);
|
||||
string itemType = null;
|
||||
try { itemType = (iItem as IShellItem2)?.GetString(pkItemType)?.ToString().ToLowerInvariant(); } catch { }
|
||||
|
||||
// If not a folder, get the ShellItem
|
||||
if (iItem.GetAttributes(SFGAO.SFGAO_FOLDER) == 0)
|
||||
return new ShellItem(iItem);
|
||||
var isFolder = iItem.GetAttributes(SFGAO.SFGAO_FOLDER) != 0;
|
||||
|
||||
// Try to get specialized folder type from property
|
||||
var pk = PROPERTYKEY.System.ItemType;
|
||||
string itemType = null;
|
||||
try { itemType = (iItem as IShellItem2)?.GetString(pk)?.ToString().ToLowerInvariant(); } catch { }
|
||||
switch (itemType)
|
||||
return itemType switch
|
||||
{
|
||||
case ".library-ms":
|
||||
return new ShellLibrary(iItem);
|
||||
|
||||
case ".searchconnector-ms":
|
||||
// TODO: Return a search connector
|
||||
case ".search-ms":
|
||||
// TODO: Return a saved search connection
|
||||
default:
|
||||
return new ShellFolder(iItem);
|
||||
}
|
||||
".lnk" => new ShellLink(iItem),
|
||||
".library-ms" => new ShellLibrary(iItem),
|
||||
// TODO: ".searchconnector-ms" => Return a search connector
|
||||
// TODO: ".search-ms" => Return a saved search connection
|
||||
_ => isFolder ? new ShellFolder(iItem) : new ShellItem(iItem),
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>Implements the operator !=.</summary>
|
||||
|
|
Loading…
Reference in New Issue