示例#1
0
        private ImageSource ExtractIcon(NativeShellFolder shellFolder, PIDLIST pidl, int iconSize, GILI iconFlags)
        {
            using (NativeExtractIcon extractIcon = shellFolder.GetUIObjectOf <IExtractIcon>(pidl).ToNative()) {
                string iconFile;
                int    iconIndex;
                GILR   iconResultFlags;
                if (!extractIcon.GetIconLocation(iconFlags, out iconFile, out iconIndex, out iconResultFlags).GetValueOrDefault())
                {
                    return(null); // TODO return default icon, schedule async icon extraction
                }
                HICON hicon;
                // TODO check cache

                /*if (!iconResultFlags.Has(GILR.NOTFILENAME))
                 *  Native.PrivateExtractIcons(iconFile, iconIndex, iconSize, out hicon, LR.LOADFROMFILE);*/
                if (!extractIcon.Extract(iconFile, iconIndex, (ushort)iconSize, out hicon) && !iconResultFlags.Has(GILR.NOTFILENAME))
                {
                    Native.PrivateExtractIcons(iconFile, iconIndex, iconSize, out hicon, LR.LOADFROMFILE);
                }
                if (hicon == IntPtr.Zero)
                {
                    return(null);
                }

                return(Native.CreateBitmapSourceFromHIcon(hicon));
            }
        }
示例#2
0
 internal ShellItem(ShellTree tree, ShellItem parent, PIDLIST pidl, NativeShellFolder shellFolder)
 {
     _tree        = tree;
     _parent      = parent;
     _pidl        = pidl;
     _shellFolder = shellFolder;
     _children    = _childrenFiles = _childrenFolders = DummyChildren;
     UpdateAttrs(SFGAO.HASSUBFOLDER | SFGAO.FILESYSTEM | SFGAO.FILESYSANCESTOR | SFGAO.FOLDER);
     if (!HasSubFolder)
     {
         _childrenFolders = NoChildren;
     }
 }
示例#3
0
 private void ReplaceDummyChildren()
 {
     if (_children == DummyChildren)
     {
         var children = new List <ShellItem>();
         try {
             foreach (PIDLIST childPidl in _shellFolder.EnumObjects(_tree.WindowHandle, SHCONTF.FOLDERS | SHCONTF.NONFOLDERS))
             {
                 NativeShellFolder childShellFolder = _shellFolder.BindToObject <IShellFolder>(childPidl).ToNative();
                 ShellItem         childItem        = new ShellItem(_tree, this, childPidl, childShellFolder);
                 children.Add(childItem);
             }
         }
         catch (Exception e) {
             if (e.IsAnyType <FileNotFoundException, Win32Exception>())
             {
                 Log.Error("Failed to enumerate items of folder '{0}'.".Fmt(DisplayName), e);
             }
         }
         finally {
             children.Sort(new ShellItemComparer(ParentShellFolder));
             _children        = new ObservableCollectionEx <ShellItem>();
             _childrenFiles   = new ObservableCollectionEx <ShellItem>();
             _childrenFolders = new ObservableCollectionEx <ShellItem>();
             foreach (ShellItem childItem in children)
             {
                 _children.Add(childItem);
                 if (childItem.IsFolder)
                 {
                     _childrenFolders.Add(childItem);
                 }
                 else
                 {
                     _childrenFiles.Add(childItem);
                 }
             }
         }
         OnPropertyChanged("Children", "ChildrenUnexpanded",
                           "ChildrenFiles", "ChildrenFilesUnexpanded",
                           "ChildrenFolders", "ChildrenFoldersUnexpanded");
     }
 }
示例#4
0
 public ImageSource ExtractIcon(NativeShellFolder shellFolder, PIDLIST pidl, SHIL iconSize, GILI iconFlags)
 {
     return(ExtractIcon(shellFolder, pidl, IconSizeToPixels(iconSize), iconFlags));
 }
示例#5
0
 public ShellItemComparer(NativeShellFolder shellFolder)
 {
     _shellFolder = shellFolder;
 }