Represents a registered non file system Known Folder
Inheritance: ShellItem, IKnownFolder
        /// <summary>
        /// Given a native KnownFolder (IKnownFolderNative), create the right type of
        /// IKnownFolder object (FileSystemKnownFolder or NonFileSystemKnownFolder)
        /// </summary>
        /// <param name="knownFolderNative">Native Known Folder</param>
        /// <returns></returns>
        private static IKnownFolder GetKnownFolder(IKnownFolderNative knownFolderNative)
        {
            Debug.Assert(knownFolderNative != null, "Native IKnownFolder should not be null.");

            // Get the native IShellItem2 from the native IKnownFolder
            IShellItem shellItem;
            Guid       guid = new Guid(InterfaceGuids.IShellItem);
            HResult    hr   = knownFolderNative.GetShellItem(0, ref guid, out shellItem);

            if (hr != HResult.S_OK)
            {
                return(null);
            }

            bool isFileSystem = false;

            // If we have a valid IShellItem, try to get the FileSystem attribute.
            if (shellItem != null)
            {
                SFGAO sfgao =
                    shellItem.GetAttributes(SFGAO.FILESYSTEM);

                // Is this item a FileSystem item?
                isFileSystem = (sfgao & SFGAO.FILESYSTEM) != 0;
            }

            // If it's FileSystem, create a FileSystemKnownFolder, else NonFileSystemKnownFolder
            if (isFileSystem)
            {
                FileSystemKnownFolder kf = new FileSystemKnownFolder(knownFolderNative);
                return(kf);
            }

            NonFileSystemKnownFolder knownFsFolder = new NonFileSystemKnownFolder(knownFolderNative);

            return(knownFsFolder);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Given a native KnownFolder (IKnownFolderNative), create the right type of
        /// IKnownFolder object (FileSystemKnownFolder or NonFileSystemKnownFolder)
        /// </summary>
        /// <param name="knownFolderNative">Native Known Folder</param>
        /// <returns></returns>
        private static IKnownFolder GetKnownFolder(IKnownFolderNative knownFolderNative)
        {
            Debug.Assert(knownFolderNative != null, "Native IKnownFolder should not be null.");

            // Get the native IShellItem2 from the native IKnownFolder
            IShellItem shellItem;
            Guid guid = new Guid(InterfaceGuids.IShellItem);
            HResult hr = knownFolderNative.GetShellItem(0, ref guid, out shellItem);

            if (hr != HResult.S_OK) return null;

            bool isFileSystem = false;

            // If we have a valid IShellItem, try to get the FileSystem attribute.
            if (shellItem != null)
            {
                SFGAO sfgao;
                shellItem.GetAttributes(SFGAO.FILESYSTEM, out sfgao);

                // Is this item a FileSystem item?
                isFileSystem = (sfgao & SFGAO.FILESYSTEM) != 0;
            }

            // If it's FileSystem, create a FileSystemKnownFolder, else NonFileSystemKnownFolder
            if (isFileSystem)
            {
                return FileSystemKnownFolder.Create(knownFolderNative);
            }

            var knownFsFolder = new NonFileSystemKnownFolder(knownFolderNative);
            return knownFsFolder;
        }