Пример #1
0
        internal ShellItem(ShellBrowserComponent browser, IntPtr pidl, IntPtr shellFolderPtr)
        {
            this.browser = browser;

            this.shellFolderPtr = shellFolderPtr;
            this.shellFolder = (IShellFolder)Marshal.GetTypedObjectForIUnknown(shellFolderPtr, typeof(IShellFolder));
            subFiles = new ShellItemCollection(this);
            subFolders = new ShellItemCollection(this);

            pidlRel = new PIDL(pidl, false);

            text = "Desktop";
            path = "Desktop";

            SetAttributesDesktop(this);

            NativeShellAPI.SHFILEINFO info = new NativeShellAPI.SHFILEINFO();
            NativeShellAPI.SHGetFileInfo(pidlRel.Ptr, 0, ref info, NativeShellAPI.cbFileInfo,
                NativeShellAPI.SHGFI.PIDL | NativeShellAPI.SHGFI.TYPENAME | NativeShellAPI.SHGFI.SYSICONINDEX);

            type = info.szTypeName;

            ShellImageList.SetIconIndex(this, info.iIcon, false);
            ShellImageList.SetIconIndex(this, info.iIcon, true);

            sortFlag = 1;
        }
Пример #2
0
        static ShellImageList()
        {
            imageTable = new Hashtable();

            NativeShellAPI.SHGFI flag = NativeShellAPI.SHGFI.USEFILEATTRIBUTES | NativeShellAPI.SHGFI.SYSICONINDEX | NativeShellAPI.SHGFI.SMALLICON;
            NativeShellAPI.SHFILEINFO shfiSmall = new NativeShellAPI.SHFILEINFO();
            smallImageListHandle = NativeShellAPI.SHGetFileInfo(".txt", NativeShellAPI.FILE_ATTRIBUTE.NORMAL, ref shfiSmall, NativeShellAPI.cbFileInfo, flag);

            flag = NativeShellAPI.SHGFI.USEFILEATTRIBUTES | NativeShellAPI.SHGFI.SYSICONINDEX | NativeShellAPI.SHGFI.LARGEICON;
            NativeShellAPI.SHFILEINFO shfiLarge = new NativeShellAPI.SHFILEINFO();
            largeImageListHandle = NativeShellAPI.SHGetFileInfo(".txt", NativeShellAPI.FILE_ATTRIBUTE.NORMAL, ref shfiLarge, NativeShellAPI.cbFileInfo, flag);
        }
Пример #3
0
        private void InitVars()
        {
            IntPtr tempPidl;
            NativeShellAPI.SHFILEINFO info;

            //My Computer
            info = new NativeShellAPI.SHFILEINFO();
            tempPidl = IntPtr.Zero;
            NativeShellAPI.SHGetSpecialFolderLocation(IntPtr.Zero, NativeShellAPI.CSIDL.DRIVES, out tempPidl);

            NativeShellAPI.SHGetFileInfo(tempPidl, 0, ref info, NativeShellAPI.cbFileInfo,
                NativeShellAPI.SHGFI.PIDL | NativeShellAPI.SHGFI.DISPLAYNAME | NativeShellAPI.SHGFI.TYPENAME);

            sysfolderName = info.szTypeName;
            mycompName = info.szDisplayName;
            Marshal.FreeCoTaskMem(tempPidl);
            //

            //Dekstop
            tempPidl = IntPtr.Zero;
            NativeShellAPI.SHGetSpecialFolderLocation(IntPtr.Zero, NativeShellAPI.CSIDL.DESKTOP, out tempPidl);
            IntPtr desktopFolderPtr;
            NativeShellAPI.SHGetDesktopFolder(out desktopFolderPtr);
            desktopItem = new ShellItem(this, tempPidl, desktopFolderPtr);
            //

            //My Documents
            uint pchEaten = 0;
            NativeShellAPI.SFGAO pdwAttributes = 0;
            desktopItem.ShellFolder.ParseDisplayName(
                IntPtr.Zero,
                IntPtr.Zero,
                "::{450d8fba-ad25-11d0-98a8-0800361b1103}",
                ref pchEaten,
                out tempPidl,
                ref pdwAttributes);

            info = new NativeShellAPI.SHFILEINFO();
            NativeShellAPI.SHGetFileInfo(tempPidl, 0, ref info, NativeShellAPI.cbFileInfo,
                NativeShellAPI.SHGFI.PIDL | NativeShellAPI.SHGFI.DISPLAYNAME);

            mydocsName = info.szDisplayName;
            Marshal.FreeCoTaskMem(tempPidl);

            StringBuilder path = new StringBuilder(NativeShellAPI.MAX_PATH);
            NativeShellAPI.SHGetFolderPath(
                    IntPtr.Zero, NativeShellAPI.CSIDL.PERSONAL,
                    IntPtr.Zero, NativeShellAPI.SHGFP.TYPE_CURRENT, path);
            mydocsPath = path.ToString();
            //
        }
Пример #4
0
        internal static void SetIconIndex(ShellItem item, int index, bool SelectedIcon)
        {
            bool HasOverlay = false; //true if it's an overlay
            int rVal = 0; //The returned Index

            NativeShellAPI.SHGFI dwflag = NativeShellAPI.SHGFI.SYSICONINDEX | NativeShellAPI.SHGFI.PIDL | NativeShellAPI.SHGFI.ICON;
            NativeShellAPI.FILE_ATTRIBUTE dwAttr = 0;
            //build Key into HashTable for this Item
            int Key = index * 256;
            if (item.IsLink)
            {
                Key = Key | 1;
                dwflag = dwflag | NativeShellAPI.SHGFI.LINKOVERLAY;
                HasOverlay = true;
            }
            if (item.IsShared)
            {
                Key = Key | 2;
                dwflag = dwflag | NativeShellAPI.SHGFI.ADDOVERLAYS;
                HasOverlay = true;
            }
            if (SelectedIcon)
            {
                Key = Key | 4;
                dwflag = dwflag | NativeShellAPI.SHGFI.OPENICON;
                HasOverlay = true; //not really an overlay, but handled the same
            }
            
            if (imageTable.ContainsKey(Key))
            {
                rVal = (int)imageTable[Key];
            }
            else if (!HasOverlay && !item.IsHidden) //for non-overlay icons, we already have
            {                
                rVal = (int)System.Math.Floor((double)Key / 256); // the right index -- put in table
                imageTable[Key] = rVal;
            }
            else //don't have iconindex for an overlay, get it.
            {
                if (item.IsFileSystem & !item.IsDisk & !item.IsFolder)
                {
                    dwflag = dwflag | NativeShellAPI.SHGFI.USEFILEATTRIBUTES;
                    dwAttr = dwAttr | NativeShellAPI.FILE_ATTRIBUTE.NORMAL;
                }

                PIDL pidlFull = item.PIDLFull;

                NativeShellAPI.SHFILEINFO shfiSmall = new NativeShellAPI.SHFILEINFO();
                NativeShellAPI.SHGetFileInfo(pidlFull.Ptr, dwAttr, ref shfiSmall, NativeShellAPI.cbFileInfo, dwflag | NativeShellAPI.SHGFI.SMALLICON);

                NativeShellAPI.SHFILEINFO shfiLarge = new NativeShellAPI.SHFILEINFO();
                NativeShellAPI.SHGetFileInfo(pidlFull.Ptr, dwAttr, ref shfiLarge, NativeShellAPI.cbFileInfo, dwflag | NativeShellAPI.SHGFI.LARGEICON);

                Marshal.FreeCoTaskMem(pidlFull.Ptr);

                lock (imageTable)
                {
                    rVal = NativeShellAPI.ImageList_ReplaceIcon(smallImageListHandle, -1, shfiSmall.hIcon);
                    NativeShellAPI.ImageList_ReplaceIcon(largeImageListHandle, -1, shfiLarge.hIcon);
                }

                NativeShellAPI.DestroyIcon(shfiSmall.hIcon);
                NativeShellAPI.DestroyIcon(shfiLarge.hIcon);
                imageTable[Key] = rVal;
            }

            if (SelectedIcon)
                item.SelectedImageIndex = rVal;
            else
                item.ImageIndex = rVal;
        }
Пример #5
0
        private static void SetInfo(ShellItem item)
        {
            PIDL pidlFull = item.PIDLFull;

            NativeShellAPI.SHFILEINFO info = new NativeShellAPI.SHFILEINFO();
            NativeShellAPI.SHGetFileInfo(pidlFull.Ptr, 0, ref info, NativeShellAPI.cbFileInfo,
                NativeShellAPI.SHGFI.PIDL | NativeShellAPI.SHGFI.TYPENAME | NativeShellAPI.SHGFI.SYSICONINDEX);

            pidlFull.Free();

            ShellImageList.SetIconIndex(item, info.iIcon, false);
            ShellImageList.SetIconIndex(item, info.iIcon, true);

            item.type = info.szTypeName;
        }
Пример #6
0
        /// <summary>
        /// This method uses SHGetFileInfo to check whether a path to a directory exists.
        /// </summary>
        /// <param name="path">The path to check</param>
        /// <returns>true if it exists, false otherwise</returns>
        private bool PathExists(string path)
        {
            string realPath = ConvertPath(path);

            if (string.IsNullOrEmpty(realPath))
                return false;
            else if (string.Compare(path, "desktop", true) == 0)
                return true;

            string[] pathParts = realPath.Split('\\');

            for (int i = 0; i < pathParts.Length; i++)
            {
                bool found = false;
                if (ShellBrowserComponent.DesktopItem.SubFolders.Contains(pathParts[i]))
                {
                    pathParts[i] = ShellItem.GetRealPath(
                        ShellBrowserComponent.DesktopItem.SubFolders[pathParts[i]]);

                    found = true;
                }
                else
                {
                    ShellItem myComp =
                        ShellBrowserComponent.DesktopItem.SubFolders[ShellBrowserComponent.MyComputerName];

                    if (myComp.SubFolders.Contains(pathParts[i]))
                    {
                        pathParts[i] = ShellItem.GetRealPath(
                            myComp.SubFolders[pathParts[i]]);

                        found = true;
                    }
                }

                if (!found)
                    break;
            }

            realPath = string.Join("\\", pathParts);

            if (realPath.EndsWith(":"))
                realPath += "\\";

            NativeShellAPI.SHFILEINFO info = new NativeShellAPI.SHFILEINFO();
            IntPtr ptr = NativeShellAPI.SHGetFileInfo(realPath, 0, ref info, NativeShellAPI.cbFileInfo, NativeShellAPI.SHGFI.DISPLAYNAME);
            bool exists = (ptr != IntPtr.Zero);

            Marshal.FreeCoTaskMem(ptr);
            return exists;
        }