Exemple #1
0
        /// <summary>
        /// Creates a ShellObject collection from an IShellItemArray
        /// </summary>
        /// <param name="iArray">IShellItemArray pointer</param>
        /// <param name="readOnly">Indicates whether the collection shouldbe read-only or not</param>
        internal ShellObjectCollection(IShellItemArray iArray, bool readOnly)
        {
            this.readOnly = readOnly;

            if (iArray != null)
            {
                try
                {
                    uint itemCount = 0;
                    iArray.GetCount(out itemCount);

                    content = new List <ShellObject>((int)itemCount);

                    for (uint index = 0; index < itemCount; index++)
                    {
                        IShellItem iShellItem = null;
                        iArray.GetItemAt(index, out iShellItem);
                        content.Add(ShellObjectFactory.Create(iShellItem));
                    }
                }
                finally
                {
                    Marshal.ReleaseComObject(iArray);
                }
            }
        }
        /// <summary>
        /// Creates a ShellObject given a parsing name
        /// </summary>
        /// <param name="parsingName"></param>
        /// <returns>A newly constructed ShellObject object</returns>
        public static ShellObject Create(string parsingName)
        {
            if (string.IsNullOrEmpty(parsingName))
            {
                throw new ArgumentNullException(nameof(parsingName));
            }

            // Create a native shellitem from our path
            var guid    = new Guid(NativeAPI.Guids.Shell.IShellItem2);
            int retCode = COMNative.Shell.Shell.SHCreateItemFromParsingName(parsingName, IntPtr.Zero, ref guid, out IShellItem2 nativeShellItem);

            return(CoreErrorHelper.Succeeded(retCode) ? ShellObjectFactory.Create(nativeShellItem) : throw new ShellException(LocalizedMessages.ShellObjectFactoryUnableToCreateItem, Marshal.GetExceptionForHR(retCode)));
        }
        /// <summary>Constructs a new Shell object from IDList pointer</summary>
        /// <param name="idListPtr"></param>
        /// <param name="parent"></param>
        /// <returns></returns>
        internal static ShellObject Create(IntPtr idListPtr, ShellContainer parent)
        {
            var retCode = ShellNativeMethods.SHCreateShellItem(
                IntPtr.Zero,
                parent.NativeShellFolder,
                idListPtr, out var nativeShellItem);

            if (!CoreErrorHelper.Succeeded(retCode))
            {
                return(null);
            }

            return(ShellObjectFactory.Create(nativeShellItem));
        }
        /// <summary>Constructs a new Shell object from IDList pointer</summary>
        /// <param name="idListPtr"></param>
        /// <returns></returns>
        internal static ShellObject Create(IntPtr idListPtr)
        {
            // Throw exception if not running on Win7 or newer.
            CoreHelpers.ThrowIfNotVista();

            var guid = new Guid(ShellIIDGuid.IShellItem2);

            var retCode = ShellNativeMethods.SHCreateItemFromIDList(idListPtr, ref guid, out var nativeShellItem);

            if (!CoreErrorHelper.Succeeded(retCode))
            {
                return(null);
            }
            return(ShellObjectFactory.Create(nativeShellItem));
        }
Exemple #5
0
        public bool MoveNext()
        {
            if (nativeEnumIdList == null)
            {
                return(false);
            }
            uint    itemsRequested = 1;
            HResult hr             = nativeEnumIdList.Next(itemsRequested, out var item, out var numItemsReturned);

            if (numItemsReturned < itemsRequested || hr != HResult.Ok)
            {
                return(false);
            }

            currentItem = ShellObjectFactory.Create(item, nativeShellFolder);

            return(true);
        }
        /// <summary>
        /// Creates a ShellObject given a parsing name
        /// </summary>
        /// <param name="parsingName"></param>
        /// <returns>A newly constructed ShellObject object</returns>
        internal static ShellObject Create(string parsingName)
        {
            if (string.IsNullOrEmpty(parsingName))
            {
                throw new ArgumentNullException("parsingName");
            }

            // Create a native shellitem from our path
            IShellItem2 nativeShellItem;
            Guid        guid    = new Guid(ShellIIDGuid.IShellItem2);
            int         retCode = ShellNativeMethods.SHCreateItemFromParsingName(parsingName, IntPtr.Zero, ref guid, out nativeShellItem);

            if (!CoreErrorHelper.Succeeded(retCode))
            {
                throw new ShellException(LocalizedMessages.ShellObjectFactoryUnableToCreateItem, Marshal.GetExceptionForHR(retCode));
            }
            return(ShellObjectFactory.Create(nativeShellItem));
        }
Exemple #7
0
        /// <summary>
        /// Constructs a new Shell object from IDList pointer
        /// </summary>
        /// <param name="idListPtr"></param>
        /// <param name="parent"></param>
        /// <returns></returns>
        internal static ShellObject Create(IntPtr idListPtr, ShellContainer parent)
        {
            IShellItem nativeShellItem;

            int retCode = ShellNativeMethods.SHCreateShellItem(
                IntPtr.Zero,
                parent.NativeShellFolder,
                idListPtr, out nativeShellItem);

            if (CoreErrorHelper.Succeeded(retCode))
            {
                return(ShellObjectFactory.Create(nativeShellItem));
            }
            else
            {
                // Since this is an internal method, return null instead of throwing an exception.
                // Let the caller know we weren't able to create a valid ShellObject with the given PIDL
                return(null);
            }
        }
Exemple #8
0
        /// <summary>
        /// Constructs a new Shell object from IDList pointer
        /// </summary>
        /// <param name="idListPtr"></param>
        /// <returns></returns>
        internal static ShellObject Create(IntPtr idListPtr)
        {
            // Throw exception if not running on Win7 or newer.
            CoreHelpers.ThrowIfNotVista();

            Guid        guid = new Guid(ShellIIDGuid.IShellItem2);
            IShellItem2 nativeShellItem;
            int         retCode = ShellNativeMethods.SHCreateItemFromIDList(idListPtr, ref guid, out nativeShellItem);

            if (CoreErrorHelper.Succeeded(retCode))
            {
                return(ShellObjectFactory.Create(nativeShellItem));
            }
            else
            {
                // Since this is an internal method, return null instead of throwing an exception.
                // Let the caller know we weren't able to create a valid ShellObject with the given PIDL
                return(null);
            }
        }
Exemple #9
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public bool MoveNext()
        {
            if (nativeEnumIdList == null)
            {
                return(false);
            }

            IntPtr  item;
            uint    numItemsReturned;
            uint    itemsRequested = 1;
            HRESULT hr             = nativeEnumIdList.Next(itemsRequested, out item, out numItemsReturned);

            if (numItemsReturned < itemsRequested || hr != HRESULT.S_OK)
            {
                return(false);
            }

            currentItem = ShellObjectFactory.Create(item, nativeShellFolder);

            return(true);
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public bool MoveNext()
        {
            if (this.nativeEnumIdList == null)
            {
                return(false);
            }

            IntPtr  item;
            uint    numItemsReturned;
            uint    itemsRequested = 1;
            HResult hr             = this.nativeEnumIdList.Next(itemsRequested, out item, out numItemsReturned);

            if (numItemsReturned < itemsRequested || hr != HResult.Ok)
            {
                return(false);
            }

            this.currentItem = ShellObjectFactory.Create(item, this.nativeShellFolder);

            return(true);
        }
        /// <summary>Creates a ShellObject collection from an IShellItemArray</summary>
        /// <param name="iArray">IShellItemArray pointer</param>
        /// <param name="readOnly">Indicates whether the collection shouldbe read-only or not</param>
        internal ShellObjectCollection(IShellItemArray iArray, bool readOnly)
        {
            this.readOnly = readOnly;

            if (iArray != null)
            {
                try
                {
                    iArray.GetCount(out var itemCount);
                    content.Capacity = (int)itemCount;
                    for (uint index = 0; index < itemCount; index++)
                    {
                        iArray.GetItemAt(index, out var iShellItem);
                        content.Add(ShellObjectFactory.Create(iShellItem));
                    }
                }
                finally
                {
                    Marshal.ReleaseComObject(iArray);
                }
            }
        }
        /// <summary>
        /// Creates a ShellObject collection from an IShellItemArray
        /// </summary>
        /// <param name="iArray">IShellItemArray pointer</param>
        /// <param name="readOnly">Indicates whether the collection shouldbe read-only or not</param>
        internal ShellObjectCollection(IShellItemArray iArray, bool readOnly)
        {
            IsReadOnly = readOnly;

            if (iArray != null)
            {
                try
                {
                    Marshal.ThrowExceptionForHR((int)iArray.GetCount(out uint itemCount));
                    content.Capacity = (int)itemCount;

                    for (uint index = 0; index < itemCount; index++)
                    {
                        Marshal.ThrowExceptionForHR((int)iArray.GetItemAt(index, out IShellItem iShellItem));
                        content.Add(ShellObjectFactory.Create(iShellItem));
                    }
                }
                finally
                {
                    _ = Marshal.ReleaseComObject(iArray);
                }
            }
        }
Exemple #13
0
 public static ShellObject FromParsingName(string parsingName)
 {
     return(ShellObjectFactory.Create(parsingName));
 }
Exemple #14
0
 /// <summary>
 /// Creates a ShellObject subclass given a parsing name.
 /// For file system items, this method will only accept absolute paths.
 /// </summary>
 /// <param name="parsingName">The parsing name of the object.</param>
 /// <returns>A newly constructed ShellObject object.</returns>
 public static ShellObject FromParsingName(string parsingName) => ShellObjectFactory.Create(parsingName);
Exemple #15
0
 public static ShellObject CreateFromSpecName(string Name)
 {
     return(ShellObjectFactory.Create(Name));
 }