public static IResolveLink Create(ShellLink link)
 {
     if (link == null)
     {
         throw new ArgumentNullException();
     }
     string targetPath = GetTargetPath(link);
     return (string.IsNullOrEmpty(targetPath) ? null : ((IResolveLink) new ResolveShellLink(link, targetPath)));
 }
 public static IResolveLink ResolveShellLink(ShellLink link)
 {
     if (link == null)
     {
         throw new ArgumentNullException("link");
     }
     IntPtr idList = link.IdList;
     if (idList != IntPtr.Zero)
     {
         try
         {
             SafeShellItem item = new SafeShellItem(idList);
             IVirtualItem target = ShellFolder.CreateShellItem(item, item.GetAttributesOf(SFGAO.SFGAO_FOLDER | SFGAO.SFGAO_STREAM), null);
             if (target != null)
             {
                 return new Nomad.FileSystem.Virtual.ResolveShellLink(link, target);
             }
         }
         catch (ArgumentException)
         {
         }
     }
     return null;
 }
 internal ResolveShellLink(ShellLink link, string targetPath)
 {
     this.FTargetPath = targetPath;
     this.Initialize(link);
 }
 private void Initialize(ShellLink link)
 {
     this.FHotkey = link.Hotkey;
     this.FDescription = link.Description;
 }
 internal ResolveShellLink(ShellLink link, IVirtualItem target)
 {
     this.FTarget = target;
     this.Initialize(link);
 }
 private static string GetTargetPath(ShellLink link)
 {
     string path = link.Path;
     if (string.IsNullOrEmpty(path))
     {
         IntPtr idList = link.IdList;
         if (!(idList != IntPtr.Zero))
         {
             return path;
         }
         IShellFolder desktopFolder = ShellItem.GetDesktopFolder();
         try
         {
             path = desktopFolder.GetDisplayNameOf(idList, SHGNO.SHGDN_FORPARSING);
         }
         catch (ArgumentException)
         {
         }
         finally
         {
             Marshal.ReleaseComObject(desktopFolder);
         }
     }
     return path;
 }
        public static IResolveLink ResolveShellLink(ShellLink link)
        {
            if (link == null)
            {
                throw new ArgumentNullException("link");
            }
            string path = null;
            IShellFolder desktopFolder = ShellItem.GetDesktopFolder();
            try
            {
                IntPtr idList = link.IdList;
                if (idList == IntPtr.Zero)
                {
                    return null;
                }
                path = desktopFolder.GetDisplayNameOf(idList, SHGNO.SHGDN_FORPARSING);
                if (path != null)
                {
                    switch (PathHelper.GetPathType(path))
                    {
                        case PathType.NetworkServer:
                        case PathType.NetworkShare:
                            return new Nomad.FileSystem.Virtual.ResolveShellLink(link, path);
                    }
                    if (OS.IsWinVista && string.Equals(path, Microsoft.Shell.Shell32.GetClsidFolderParseName(CLSID.CLSID_NETWORK), StringComparison.OrdinalIgnoreCase))
                    {
                        return new Nomad.FileSystem.Virtual.ResolveShellLink(link, UriScheme + Uri.SchemeDelimiter + "./");
                    }
                }
                StringBuilder builder = new StringBuilder();
                ITEMIDLIST itemidlist = ITEMIDLIST.FromPidl(idList);
                IntPtr pidl = Marshal.AllocCoTaskMem(itemidlist.Size);
                try
                {
                    for (int i = 0; i < itemidlist.mkid.Length; i++)
                    {
                        itemidlist.ToPidl(pidl, i + 1);
                        string a = desktopFolder.GetDisplayNameOf(pidl, SHGNO.SHGDN_FORPARSING);
                        switch (i)
                        {
                            case 0:
                                if (string.Equals(a, Microsoft.Shell.Shell32.GetClsidFolderParseName(CLSID.CLSID_NETWORK_NEIGHBORHOOD), StringComparison.OrdinalIgnoreCase))
                                {
                                    break;
                                }
                                return null;

                            case 1:
                                if (!(a != "EntireNetwork"))
                                {
                                    continue;
                                }
                                return null;

                            case 2:
                            {
                                builder.Append(a);
                                builder.Append('/');
                                continue;
                            }
                            case 3:
                            {
                                builder.Append(a);
                                builder.Append('/');
                                continue;
                            }
                            default:
                                return null;
                        }
                        builder.Append(UriScheme);
                        builder.Append(Uri.SchemeDelimiter);
                        builder.Append('.');
                        builder.Append('/');
                    }
                    path = builder.ToString();
                    if (path.Length > 0)
                    {
                        return new Nomad.FileSystem.Virtual.ResolveShellLink(link, path);
                    }
                }
                finally
                {
                    Marshal.FreeCoTaskMem(pidl);
                }
            }
            catch (ArgumentException)
            {
            }
            finally
            {
                Marshal.ReleaseComObject(desktopFolder);
            }
            return null;
        }
 protected override Image GetShellLinkIcon(ShellLink link, ref Size size)
 {
     string str;
     int num;
     link.GetIconLocation(out str, out num);
     if (!string.IsNullOrEmpty(str))
     {
         IconLocation iconLocation = new IconLocation(Environment.ExpandEnvironmentVariables(str), num);
         return LoadIconFromLocation2(iconLocation, ref size);
     }
     return null;
 }
        protected Image GetShellLinkIcon(string fileName, ref Size size)
        {
            Image shellLinkIcon = null;
            try
            {
                string path = null;
                using (ShellLink link = new ShellLink(fileName))
                {
                    shellLinkIcon = this.GetShellLinkIcon(link, ref size);
                    if (shellLinkIcon != null)
                    {
                        return shellLinkIcon;
                    }
                    path = link.Path;
                    if (string.IsNullOrEmpty(path))
                    {
                        IShellFolder desktopFolder = ShellItem.GetDesktopFolder();
                        try
                        {
                            path = desktopFolder.GetDisplayNameOf(link.IdList, SHGNO.SHGDN_FORPARSING);
                        }
                        finally
                        {
                            Marshal.ReleaseComObject(desktopFolder);
                        }
                    }
                }
                if (!string.IsNullOrEmpty(path))
                {
                    switch (PathHelper.GetPathType(path))
                    {
                        case PathType.Volume:
                            return this.GetDriveIcon(new DriveInfo(path), size);

                        case PathType.Folder:
                        case PathType.File:
                            return shellLinkIcon;

                        case (PathType.Folder | PathType.Volume):
                            return this.GetFolderIcon(path, size);

                        case (PathType.File | PathType.Volume):
                            if (!Directory.Exists(path))
                            {
                                goto Label_0125;
                            }
                            return this.GetFolderIcon(path, size);

                        case PathType.NetworkServer:
                            return this.GetDefaultIcon(DefaultIcon.NetworkServer, size);

                        case PathType.NetworkShare:
                            return this.GetDefaultIcon(DefaultIcon.NetworkFolder, size);
                    }
                }
                return shellLinkIcon;
            Label_0125:
                shellLinkIcon = this.GetFileIcon(path, size);
            }
            catch (Exception exception)
            {
                Nomad.Trace.Error.TraceException(TraceEventType.Error, exception);
            }
            return shellLinkIcon;
        }
Exemplo n.º 10
0
 protected virtual Image GetShellLinkIcon(ShellLink link, ref Size size)
 {
     return null;
 }