Beispiel #1
0
    public int CountChildren(bool showHiddenObjects, bool showNonFolders)
    {
        int result = 0;

        NativeMethods.IEnumIDList enumList = null;
        if (this.pidl == null || !this.pidl.IsFolder || folder == null)
        {
            return(0);
        }
        int hr = folder.EnumObjects(IntPtr.Zero, NativeMethods.SHCONTF.SHCONTF_FOLDERS | (showNonFolders ? NativeMethods.SHCONTF.SHCONTF_NONFOLDERS : 0) | (showHiddenObjects ? NativeMethods.SHCONTF.SHCONTF_INCLUDEHIDDEN : 0), out enumList);

        if (hr != 0)
        {
            return(0);
        }
        IntPtr pidl    = IntPtr.Zero;
        int    fetched = 0;

        while (enumList.Next(1, ref pidl, out fetched) == 0 && fetched == 1)
        {
            result++;
        }
        if (enumList != null)
        {
            Marshal.ReleaseComObject(enumList);
        }
        enumList = null;
        return(result);
    }
Beispiel #2
0
    public ArrayList GetChildren(bool showHiddenObjects, bool showNonFolders, bool sortResults)
    {
        Cancel = false;
        ArrayList children = new ArrayList();

        if (this.pidl == null || !this.pidl.IsFolder || folder == null)
        {
            return(children);
        }
        int hresult = folder.EnumObjects(IntPtr.Zero, NativeMethods.SHCONTF.SHCONTF_FOLDERS | (showNonFolders ? NativeMethods.SHCONTF.SHCONTF_NONFOLDERS : 0) | (showHiddenObjects ? NativeMethods.SHCONTF.SHCONTF_INCLUDEHIDDEN : 0), out enumList);

        if (hresult != 0)
        {
            return(null);
        }
        IntPtr pidl    = IntPtr.Zero;
        int    fetched = 0;

        while (enumList.Next(1, ref pidl, out fetched) == 0 && fetched == 1)
        {
            if (Cancel)
            {
                break;
            }
            children.Add(new PIDL(this.pidl.Pidl, pidl));
        }
        if (enumList != null)
        {
            Marshal.ReleaseComObject(enumList);
        }
        enumList = null;
        return(children);
    }
Beispiel #3
0
    public bool Children(bool showHiddenObjects, bool showNonFolders)
    {
        using (ShellFolder sf = new ShellFolder(this))
        {
            bool children = false;
            NativeMethods.IEnumIDList enumList = null;
            try
            {
                if (!this.IsFolder || sf.Folder == null)
                {
                    return(children);
                }
                int hr = sf.Folder.EnumObjects(
                    IntPtr.Zero,
                    NativeMethods.SHCONTF.SHCONTF_FOLDERS |
                    (showNonFolders ? NativeMethods.SHCONTF.SHCONTF_NONFOLDERS : 0) |
                    (showHiddenObjects ? NativeMethods.SHCONTF.SHCONTF_INCLUDEHIDDEN : 0),
                    out enumList
                    );
                if (hr != 0)
                {
                    return(children);
                }
                IntPtr pidl    = IntPtr.Zero;
                int    fetched = 0;
                while (enumList.Next(1, ref pidl, out fetched) == 0 && fetched == 1)
                {
                    Marshal.FreeCoTaskMem(pidl);
                    pidl     = IntPtr.Zero;
                    fetched  = 0;
                    children = true;
                    break;
                }
            }
            finally
            {
                if (enumList != null)
                {
                    Marshal.ReleaseComObject(enumList);
                }

                enumList = null;
            }
            return(children);
        }
    }
Beispiel #4
0
        private static void GetChildren(IntPtr pidl, bool getFolders, bool getFiles, ref Pidl[] _children)
        {
            NativeMethods.IShellFolder folder = null;

            if (LowLevelPidlWorks.GetSize(pidl) <= 2)
            {
                if (NativeMethods.SHGetDesktopFolder(out folder) != 0)
                {
                    return;
                }
            }
            else
            {
                GetIShellFolderForPidl(pidl, out folder);
            }

            if (folder == null)
            {
                return;
            }

            try
            {
                NativeMethods.IEnumIDList enumIdList = null;
                ArrayList items = new ArrayList();

                if (getFolders)
                {
                    uint itemsToInclude = NativeMethods.SHCONTF_FOLDERS /* | WinApiProvider.SHCONTF.SHCONTF_INCLUDEHIDDEN*/;
                    if (folder.EnumObjects(IntPtr.Zero, itemsToInclude, out enumIdList) == S_OK)
                    {
                        try
                        {
                            IntPtr newPidl = IntPtr.Zero;
                            IntPtr fetched = IntPtr.Zero;
                            enumIdList.Reset();
                            while (enumIdList.Next(1, out newPidl, out fetched) == 0)
                            {
                                IntPtr pidlConcat = IntPtr.Zero;
                                LowLevelPidlWorks.Concatenate(pidl, newPidl, out pidlConcat);
                                NativeMethods.CoTaskMemFree(newPidl);

                                Pidl item = new Pidl(pidlConcat, PidlType.Folder);
                                items.Add(item);

                                newPidl = IntPtr.Zero;
                            }
                        }
                        finally
                        {
                            Marshal.ReleaseComObject(enumIdList);
                        }
                    }
                }

                if (getFiles)
                {
                    uint itemsToInclude = NativeMethods.SHCONTF_NONFOLDERS /*| WinApiProvider.SHCONTF.SHCONTF_INCLUDEHIDDEN |  WinApiProvider.SHCONTF.SHCONTF_STORAGE*/;
                    if (folder.EnumObjects(IntPtr.Zero, itemsToInclude, out enumIdList) == S_OK)
                    {
                        try
                        {
                            IntPtr newPidl = IntPtr.Zero;
                            IntPtr fetched = IntPtr.Zero;
                            enumIdList.Reset();
                            while (enumIdList.Next(1, out newPidl, out fetched) == 0)
                            {
                                IntPtr pidlConcat = IntPtr.Zero;
                                LowLevelPidlWorks.Concatenate(pidl, newPidl, out pidlConcat);
                                NativeMethods.CoTaskMemFree(newPidl);

                                if (LowLevelPidlWorks.HasSuchAttributes(pidlConcat, NativeMethods.SFGAO_STREAM))
                                {
                                    Pidl item = new Pidl(pidlConcat, PidlType.File);
                                    items.Add(item);
                                }
                                else
                                {
                                    NativeMethods.CoTaskMemFree(pidlConcat);
                                }

                                newPidl = IntPtr.Zero;
                            }
                        }
                        finally
                        {
                            Marshal.ReleaseComObject(enumIdList);
                        }
                    }
                }

                _children = new Pidl[items.Count];
                for (int i = 0; i < _children.Length; i++)
                {
                    _children[i] = (Pidl)items[i];
                }
            }
            finally
            {
                Marshal.ReleaseComObject(folder);
            }
        }