Beispiel #1
0
        public FileItem(string path)
        {
            if (!File.Exists(path))
            {
                throw new FileNotFoundException("The file added to FileItem was not found!", path);
            }

            filePath = path;

            var fileInfo = new FileInfo(filePath);
            displayName = fileInfo.Name;
            m_fileLength = fileInfo.Length;

            // Get the File icon
            var shinfo = new SHFILEINFO();
            IntPtr hImg = NativeMethods.SHGetFileInfo(filePath, 0, ref shinfo,
                (uint)Marshal.SizeOf(shinfo), NativeMethods.SHGFI_ICON | NativeMethods.SHGFI_SMALLICON);

            //The icon is returned in the hIcon member of the shinfo struct
            var imageConverter = new System.Drawing.IconConverter();
            var icon = System.Drawing.Icon.FromHandle(shinfo.hIcon);
            try
            {
                fileIconImage = (System.Drawing.Image)
                    imageConverter.ConvertTo(icon, typeof(System.Drawing.Image));
            }
            catch (NotSupportedException)
            {
            }

            NativeMethods.DestroyIcon(shinfo.hIcon);
        }
Beispiel #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="directoryPath"></param>
        public DirectoryItem(string directoryPath)
        {
            if (Directory.Exists(directoryPath))
            {
                //throw new FileNotFoundException("The directory added to DirectoryItem was not found!", directoryPath);

                m_directoryPath = directoryPath;
                FileInfo fileInfo = new FileInfo(m_directoryPath);
                displayName = fileInfo.Name;

                //
                // Get all the files in the directory
                //
                string[] files = Directory.GetFiles(m_directoryPath);
                foreach (string file in files)
                {
                    mediaItems.Add(new FileItem(file));
                }

                //
                // Get all the subdirectories
                //
                string[] directories = Directory.GetDirectories(m_directoryPath);
                foreach (string directory in directories)
                {
                    mediaItems.Add(new DirectoryItem(directory));
                }

                //
                // Get the Directory icon
                //
                SHFILEINFO shinfo = new SHFILEINFO();
                IntPtr hImg = Win32.SHGetFileInfo(m_directoryPath, 0, ref shinfo,
                    (uint)Marshal.SizeOf(shinfo), Win32.SHGFI_ICON | Win32.SHGFI_SMALLICON);

                if (shinfo.hIcon != null)
                {
                    //The icon is returned in the hIcon member of the shinfo struct
                    System.Drawing.IconConverter imageConverter = new System.Drawing.IconConverter();
                    System.Drawing.Icon icon = System.Drawing.Icon.FromHandle(shinfo.hIcon);
                    try
                    {
                        fileIconImage = (System.Drawing.Image)
                            imageConverter.ConvertTo(icon, typeof(System.Drawing.Image));
                    }
                    catch (NotSupportedException)
                    {
                    }

                    Win32.DestroyIcon(shinfo.hIcon);
                }
            }
        }
Beispiel #3
0
        public MediaFile(string path)
        {
            if (!File.Exists(path))
                throw new FileNotFoundException("The file added to FileItem was not found!", path);

            filePath = path;

            var fileInfo = new FileInfo(filePath);
            displayName = fileInfo.Name;
            m_fileLength = fileInfo.Length;

            var shinfo = new SHFILEINFO();
            IntPtr hImg = NativeMethods.SHGetFileInfo(filePath, 0, ref shinfo,
                (uint)Marshal.SizeOf(shinfo), SHGFI_ICON | SHGFI_SMALLICON);

            //The icon is returned in the hIcon member of the shinfo struct
            fileIcon = System.Drawing.Icon.FromHandle(shinfo.hIcon);
        }
        public DirectoryItem(string directoryPath)
        {
            if (!Directory.Exists(directoryPath))
            {
                throw new FileNotFoundException("The directory added to DirectoryItem was not found!", directoryPath);
            }

            m_directoryPath = directoryPath;
            var fileInfo = new FileInfo(m_directoryPath);
            DisplayName = fileInfo.Name;

            string[] files = Directory.GetFiles(m_directoryPath);
            foreach (string file in files)
                mediaItems.Add(new FileItem(file));

            string[] directories = Directory.GetDirectories(m_directoryPath);
            foreach (string directory in directories)
                mediaItems.Add(new DirectoryItem(directory));

            var shinfo = new SHFILEINFO();
            IntPtr hImg = NativeMethods.SHGetFileInfo(m_directoryPath, 0, ref shinfo,
                (uint)Marshal.SizeOf(shinfo), NativeMethods.SHGFI_ICON | NativeMethods.SHGFI_SMALLICON);

            //The icon is returned in the hIcon member of the shinfo struct
            var imageConverter = new System.Drawing.IconConverter();
            var icon = System.Drawing.Icon.FromHandle(shinfo.hIcon);
            try
            {
                fileIconImage = (System.Drawing.Image)
                    imageConverter.ConvertTo(icon, typeof(System.Drawing.Image));
            }
            catch (NotSupportedException)
            {
            }

            NativeMethods.DestroyIcon(shinfo.hIcon);
        }
Beispiel #5
0
 public static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbSizeFileInfo, uint uFlags);