Ejemplo n.º 1
0
        public OpenFolderRoot GetFavorites()
        {
            OpenFolderRoot root = new OpenFolderRoot();

            root.Name  = "Favorites";
            root.Image = FileInfoHelper.GetFavoritesImage(false);
            root.Path  = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Links");

            if (Directory.Exists(root.Path))
            {
                List <OpenFolderItem> items = new List <OpenFolderItem>();
                foreach (string file in Directory.GetFiles(root.Path))
                {
                    if (ShortcutHelper.IsShortcut(file))
                    {
                        OpenFolderItem item     = new OpenFolderItem();
                        string         resolved = ShortcutHelper.ResolveShortcut(file);
                        item.Path  = resolved;
                        item.Name  = Path.GetFileNameWithoutExtension(file);
                        item.Image = FileInfoHelper.GetImage(file, false);
                        items.Add(item);
                    }
                }
                root.Children = items;
            }
            return(root);
        }
Ejemplo n.º 2
0
        internal static ImageSource GetSmallImage(string filename, bool useCache)
        {
            string extension = Path.GetExtension(filename).ToLower();

            if (useCache)
            {
                if (_Cache.ContainsKey(filename))
                {
                    return(_Cache[filename]);
                }

                if (_Cache.ContainsKey(extension))
                {
                    return(_Cache[extension]);
                }

                FileAttributes attributes = File.GetAttributes(filename);
                if ((attributes & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    if (!ShortcutHelper.IsShortcut(filename))
                    {
                        if (_Cache.ContainsKey("!!!"))
                        {
                            return(_Cache["!!!"]);
                        }
                        else
                        {
                            ImageSource folderImage = GetFolderImage(false);
                            _Cache.Add("!!!", folderImage);
                            return(folderImage);
                        }
                    }
                }
            }

            IntPtr     hImgSmall;         //the handle to the system image list
            SHFILEINFO shinfo = new SHFILEINFO();

            //Use this to get the small Icon
            hImgSmall = Win32.SHGetFileInfo(filename, Win32.FILE_ATTRIBUTE_NORMAL, ref shinfo, (uint)Marshal.SizeOf(shinfo), Win32.SHGFI_ICON | Win32.SHGFI_SMALLICON | Win32.SHGFI_USEFILEATTRIBUTES);

            ImageSource image = GetImage(shinfo.hIcon);

            Win32.DestroyIcon(hImgSmall);

            if (useCache)
            {
                if (extension == ".exe" || extension == ".ico" || extension == string.Empty || ShortcutHelper.IsShortcut(filename))
                {
                    _Cache.Add(filename, image);
                }
                else
                {
                    _Cache.Add(extension, image);
                }
            }

            return(image);
        }
Ejemplo n.º 3
0
        internal static ImageSource GetImage(string filename, bool useCache)
        {
            string extension = Path.GetExtension(filename).ToLower();

            if (useCache)
            {
                if (_Cache.ContainsKey(filename))
                {
                    return(_Cache[filename]);
                }
                if (_Cache.ContainsKey(extension))
                {
                    return(_Cache[extension]);
                }

                FileAttributes attributes = File.GetAttributes(filename);
                if ((attributes & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    if (!ShortcutHelper.IsShortcut(filename))
                    {
                        if (_Cache.ContainsKey("!!!"))
                        {
                            return(_Cache["!!!"]);
                        }
                        else
                        {
                            ImageSource folderImage = GetFolderImage(false);
                            _Cache.Add("!!!", folderImage);
                            return(folderImage);
                        }
                    }
                }
            }

            SHFILEINFO shinfo = new SHFILEINFO();

            IntPtr      ptrIconList = Win32.SHGetFileInfo(filename, Win32.FILE_ATTRIBUTE_NORMAL, ref shinfo, (uint)Marshal.SizeOf(shinfo), Win32.SHGFI_SYSICONINDEX | Win32.SHGFI_SMALLICON | Win32.SHGFI_USEFILEATTRIBUTES);
            IntPtr      ptrIcon     = Win32.ImageList_GetIcon(ptrIconList, shinfo.iIcon.ToInt32(), Win32.ILD_TRANSPARENT);
            ImageSource image       = GetImage(ptrIcon);

            Win32.DestroyIcon(ptrIcon);
            Win32.DestroyIcon(ptrIconList);

            if (useCache)
            {
                if (extension == ".exe" || extension == ".ico" || extension == string.Empty || ShortcutHelper.IsShortcut(filename))
                {
                    _Cache.Add(filename, image);
                }
                else
                {
                    _Cache.Add(extension, image);
                }
            }

            return(image);
        }