Esempio n. 1
0
        public HResult GetAttributes(SFGAO sfgaoMask, out SFGAO psfgaoAttribs)
        {
            IShellFolder parentFolder = GetParent().GetIShellFolder();
            SFGAO        result       = sfgaoMask;

            parentFolder.GetAttributesOf(1, new IntPtr[] { Shell32.ILFindLastID(Pidl) }, ref result);
            psfgaoAttribs = result & sfgaoMask;
            return(HResult.S_OK);
        }
Esempio n. 2
0
        public SFGAO GetAttributes(SFGAO sfgaoMask)
        {
            IShellFolder parentFolder = GetParent().GetIShellFolder();
            SFGAO        result       = sfgaoMask;

            parentFolder.GetAttributesOf(1,
                                         new IntPtr[] { Shell32.ILFindLastID(m_Pidl) },
                                         ref result);
            return(result & sfgaoMask);
        }
Esempio n. 3
0
        public Int32 ShouldShow(
            Object psf,        // A pointer to the folder's IShellFolder interface.
            IntPtr pidlFolder, // The folder's PIDL.
            IntPtr pidlItem)   // The item's PIDL.
        {
            // check extension, and if not ok return 1 (S_FALSE)

            // get display name of item
            IShellFolder isf = (IShellFolder)psf;

            ShellApi.STRRET ptrDisplayName;
            isf.GetDisplayNameOf(pidlItem, (uint)ShellApi.SHGNO.SHGDN_NORMAL | (uint)ShellApi.SHGNO.SHGDN_FORPARSING,
                                 out ptrDisplayName);

            String sDisplay;

            ShellApi.StrRetToBSTR(ref ptrDisplayName, (IntPtr)0, out sDisplay);

            // check if item is file or folder
            IntPtr[] aPidl = new IntPtr[1];
            aPidl[0] = pidlItem;
            uint Attrib;

            Attrib = (uint)ShellApi.SFGAO.SFGAO_FOLDER;

            int temp;

            temp = isf.GetAttributesOf(1, aPidl, ref Attrib);

            // if item is a folder, accept
            if ((Attrib & (uint)ShellApi.SFGAO.SFGAO_FOLDER) == (uint)ShellApi.SFGAO.SFGAO_FOLDER)
            {
                return(0);
            }

            // if item is file, check if it has a valid extension
            for (int i = 0; i < ValidExtension.Length; i++)
            {
                if (sDisplay.ToUpper().EndsWith("." + ValidExtension[i].ToUpper()))
                {
                    return(0);
                }
            }

            return(1);
        }
Esempio n. 4
0
        /// <summary>
        /// Constructor. Create a sub-item shell item object.
        /// </summary>
        /// <param name="shDesktop">IShellFolder interface of the Desktop</param>
        /// <param name="pIDL">The fully qualified PIDL for this shell item</param>
        /// <param name="shParent">The ShellItem object for this item's parent</param>
        public ShellItem(IShellFolder shDesktop, IntPtr pIDL, ShellItem shParent)
        {
            // We need the Desktop shell item to exist first.
            if (m_bHaveRootShell == false)
            {
                throw new Exception("The root shell item must be created before creating a sub-item");
            }

            // Create the FQ PIDL for this new item.
            m_pIDL = NativeShellApi.ILCombine(shParent.PIDL, pIDL);

            // Get the properties of this item.
            SFGAOF uFlags = SFGAOF.SFGAO_FOLDER | SFGAOF.SFGAO_HASSUBFOLDER;

            // Here we get some basic attributes.
            shDesktop.GetAttributesOf(1, out m_pIDL, out uFlags);
            IsFolder     = Convert.ToBoolean(uFlags & SFGAOF.SFGAO_FOLDER);
            HasSubFolder = Convert.ToBoolean(uFlags & SFGAOF.SFGAO_HASSUBFOLDER);

            // Now we want to get extended attributes such as the icon index etc.
            SHFILEINFO shInfo = new SHFILEINFO();
            SHGFI      vFlags =
                SHGFI.SHGFI_SMALLICON |
                SHGFI.SHGFI_SYSICONINDEX |
                SHGFI.SHGFI_PIDL |
                SHGFI.SHGFI_DISPLAYNAME;

            NativeShellApi.SHGetFileInfo(m_pIDL, 0, out shInfo, (uint)Marshal.SizeOf(shInfo), vFlags);
            DisplayName = shInfo.szDisplayName;
            IconIndex   = shInfo.iIcon;
            Path        = GetPath();

            // Create the IShellFolder interface for this item.
            if (IsFolder)
            {
                uint hRes = shParent.m_shShellFolder.BindToObject(pIDL, IntPtr.Zero, ref NativeShellApi.IID_IShellFolder, out m_shShellFolder);
                if (hRes != 0)
                {
                    Marshal.ThrowExceptionForHR((int)hRes);
                }
            }
        }
Esempio n. 5
0
 public static uint GetAttributes(IntPtr pIDL, bool fValidate)
 {
     if (pIDL != IntPtr.Zero)
     {
         uint rgfInOut = 0x60010100;
         if (fValidate)
         {
             rgfInOut |= 0x1000000;
         }
         Guid         riid = ExplorerGUIDs.IID_IShellFolder;
         IShellFolder ppv  = null;
         try {
             IntPtr ptr;
             if (PInvoke.SHBindToParent(pIDL, riid, out ppv, out ptr) == 0)
             {
                 IntPtr[] apidl = new IntPtr[] { ptr };
                 int      num2  = ppv.GetAttributesOf(1, apidl, ref rgfInOut);
                 if (fValidate)
                 {
                     return((uint)num2);
                 }
                 if (num2 == 0L)
                 {
                     return(rgfInOut);
                 }
             }
             return(uint.MaxValue);
         }
         catch {
         }
         finally {
             if (ppv != null)
             {
                 Marshal.ReleaseComObject(ppv);
             }
         }
     }
     return(uint.MaxValue);
 }
Esempio n. 6
0
 public int GetAttributesOf(uint cidl, IntPtr[] apidl, ref ShellAPI.SFGAO rgfInOut)
 {
     checkDisposed();
     return(_iShellFolder.GetAttributesOf(cidl, apidl, ref rgfInOut));
 }
Esempio n. 7
0
        /// <summary>
        /// Constructor. Create a sub-item shell item object.
        /// </summary>
        /// <param name="shDesktop">IShellFolder interface of the Desktop</param>
        /// <param name="pIDL">The fully qualified PIDL for this shell item</param>
        /// <param name="shParent">The ShellItem object for this item's parent</param>
        public ShellItem(IShellFolder shDesktop, IntPtr pIDL, ShellItem shParent)
        {
            // We need the Desktop shell item to exist first.
            if (m_bHaveRootShell == false)
                throw new Exception("The root shell item must be created before creating a sub-item");

            // Create the FQ PIDL for this new item.
            m_pIDL = NativeShellApi.ILCombine(shParent.PIDL, pIDL);

            // Get the properties of this item.
            SFGAOF uFlags = SFGAOF.SFGAO_FOLDER | SFGAOF.SFGAO_HASSUBFOLDER;

            // Here we get some basic attributes.
            shDesktop.GetAttributesOf(1, out m_pIDL, out uFlags);
            IsFolder = Convert.ToBoolean(uFlags & SFGAOF.SFGAO_FOLDER);
            HasSubFolder = Convert.ToBoolean(uFlags & SFGAOF.SFGAO_HASSUBFOLDER);

            // Now we want to get extended attributes such as the icon index etc.
            SHFILEINFO shInfo = new SHFILEINFO();
            SHGFI vFlags =
                SHGFI.SHGFI_SMALLICON |
                SHGFI.SHGFI_SYSICONINDEX |
                SHGFI.SHGFI_PIDL |
                SHGFI.SHGFI_DISPLAYNAME;
            NativeShellApi.SHGetFileInfo(m_pIDL, 0, out shInfo, (uint)Marshal.SizeOf(shInfo), vFlags);
            DisplayName = shInfo.szDisplayName;
            IconIndex = shInfo.iIcon;
            Path = GetPath();

            // Create the IShellFolder interface for this item.
            if (IsFolder)
            {
                uint hRes = shParent.m_shShellFolder.BindToObject(pIDL, IntPtr.Zero, ref NativeShellApi.IID_IShellFolder, out m_shShellFolder);
                if (hRes != 0)
                    Marshal.ThrowExceptionForHR((int)hRes);
            }
        }