コード例 #1
0
        /// <summary>
        /// Retrieves file creation date and file size.
        /// </summary>
        /// <param name="pidl">Source object for which info should be retrieved.</param>
        /// <param name="size">Reference to variable where to store file size.</param>
        /// <param name="time">Reference to variable where to file creation date.</param>
        /// <returns>True if succeeded, false otherwise.</returns>
        public static bool RetrieveFileSizeAndTime(Pidl pidl, ref long size, ref long time)
        {
            if (pidl.Path == null || pidl.Path.Length == 0)
            {
                return(false);
            }

            FileInfo info = new FileInfo(pidl.Path);

            if (info == null)
            {
                return(false);
            }

            if (pidl.Type == PidlType.Folder)
            {
                size = 0;
            }
            else
            {
                size = info.Length;
            }

            time = info.CreationTime.ToFileTime();
            return(true);
        }
コード例 #2
0
        /// <summary>
        /// Retrieves thumbnail for specified file.
        /// </summary>
        /// <param name="pidl">Source object for which info should be retrieved.</param>
        /// <param name="width">Desired thumbnail width.</param>
        /// <param name="height">Desired thumbnail heigth</param>
        /// <param name="image">Reference to variable where to store result thumbnail.</param>
        /// <param name="icon">Reference to variable where to store large icon handle, in case when file thumbnail cannot be created.</param>
        public static void RetrieveThumbnail(Pidl pidl, int width, int height, ref Aurigma.GraphicsMill.Bitmap image, ref IntPtr icon)
        {
            image = null;
            icon  = IntPtr.Zero;

            try
            {
                using (var stream = pidl.Stream)
                    using (var reader = Aurigma.GraphicsMill.Codecs.ImageReader.Create(stream))
                    {
                        if (reader != null)
                        {
                            image = ExtractExifThumbnail(reader, width, height);

                            if (image == null)
                            {
                                image = reader.Frames[0].GetBitmap();
                                image.Transforms.Resize(width, height, Transforms.ResizeInterpolationMode.High, Transforms.ResizeMode.Fit);
                            }
                        }
                    }
            }
            catch
            {
                image = null;
            }

            if (image == null)
            {
                icon = FileInfoRetriever.GetIcon(pidl, false);
            }
        }
コード例 #3
0
ファイル: Pidl.cs プロジェクト: lanicon/WinControls
        public static Pidl Create(Pidl pidl)
        {
            if (pidl == null)
            {
                return(null);
            }
            IntPtr pidlNew = IntPtr.Zero;

            LowLevelPidlWorks.Duplicate(pidl._pidl, out pidlNew);
            return(new Pidl(pidlNew));
        }
コード例 #4
0
        /// <summary>
        /// Returns icon handle (small or large) for specified file.
        /// </summary>
        /// <param name="pidl">Source object for which icon should be retrieved.</param>
        /// <param name="bSmall">If value of the parameter is true small icon handle will be returned, large icon handle otherwise.</param>
        /// <returns>Returns icon handle for specified file.</returns>
        public static IntPtr GetIcon(Pidl pidl, bool small)
        {
            NativeMethods.SHFILEINFO info = new NativeMethods.SHFILEINFO(true);
            int cbFileInfo = Marshal.SizeOf(info);

            uint flags = NativeMethods.SHGFI_ICON | NativeMethods.SHGFI_PIDL | NativeMethods.SHGFI_USEFILEATTRIBUTES | (small ? NativeMethods.SHGFI_SMALLICON : NativeMethods.SHGFI_LARGEICON);

            if (NativeMethods.SHGetFileInfo(pidl.Handle, 0, out info, (uint)cbFileInfo, flags) == IntPtr.Zero)
            {
                return(IntPtr.Zero);
            }

            return(info.hIcon);
        }
コード例 #5
0
        /// <summary>
        /// Retrieves general file information.
        /// </summary>
        /// <param name="pidl">Source object for which info should be retrieved.</param>
        /// <param name="displayName">Reference to variable where to store file display name.</param>
        /// <param name="type">Reference to variable where to store file type.</param>
        /// <param name="iconIndexSmall">Reference to variable where to store small icon index.</param>
        /// <param name="iconSmall">Reference to variable where to store small icon handle.</param>
        /// <param name="iconIndexLarge">Reference to variable where to store large icon index.</param>
        /// <param name="iconLarge">Reference to variable where to store large icon handle.</param>
        /// <returns>True if succeeded, false otherwise.</returns>
        public static bool RetrieveFileInfo(Pidl pidl, ref string displayName, ref string type, ref int iconIndexSmall, ref IntPtr iconSmall, ref int iconIndexLarge, ref IntPtr iconLarge)
        {
            NativeMethods.SHFILEINFO info = new NativeMethods.SHFILEINFO(true);
            int  cbFileInfo = Marshal.SizeOf(info);
            uint flags      = NativeMethods.SHGFI_PIDL |
                              NativeMethods.SHGFI_USEFILEATTRIBUTES |
                              NativeMethods.SHGFI_DISPLAYNAME |
                              NativeMethods.SHGFI_TYPENAME |
                              NativeMethods.SHGFI_SYSICONINDEX |
                              NativeMethods.SHGFI_ICON |
                              NativeMethods.SHGFI_SMALLICON;

            if (NativeMethods.SHGetFileInfo(pidl.Handle, 0, out info, (uint)cbFileInfo, flags) == IntPtr.Zero)
            {
                return(false);
            }

            displayName    = info.szDisplayName;
            type           = info.szTypeName;
            iconIndexSmall = info.iIcon;
            iconSmall      = info.hIcon;

            info.hIcon = IntPtr.Zero;
            flags      = NativeMethods.SHGFI_PIDL |
                         NativeMethods.SHGFI_USEFILEATTRIBUTES |
                         NativeMethods.SHGFI_SYSICONINDEX |
                         NativeMethods.SHGFI_ICON |
                         NativeMethods.SHGFI_LARGEICON;

            if (NativeMethods.SHGetFileInfo(pidl.Handle, 0, out info, (uint)cbFileInfo, flags) == IntPtr.Zero)
            {
                NativeMethods.DestroyIcon(info.hIcon);
                return(false);
            }

            iconIndexLarge = info.iIcon;
            iconLarge      = info.hIcon;
            return(true);
        }
コード例 #6
0
ファイル: Pidl.cs プロジェクト: lanicon/WinControls
        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);
            }
        }