예제 #1
0
        public FileNode(string path)
        {
            if (!File.Exists(path))
                throw new FileNotFoundException("The file added to MediaFile was not found.", path);

            _fileIcon = null;
            _path = path;

            FileInfo fileInfo = new FileInfo(_path);
            _name = fileInfo.Name;
            _sizeOnDisc = fileInfo.Length;

            //
            // Get the File icon
            //
            Shell.SHFILEINFO shinfo = new Shell.SHFILEINFO();
            IntPtr hImg = Shell.SHGetFileInfo(_path, 0, ref shinfo,
                (uint)Marshal.SizeOf(shinfo), Shell.SHGFI_ICON | Shell.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
                {
                    _fileIcon = (System.Drawing.Image)imageConverter.ConvertTo(icon, typeof(System.Drawing.Image));
                }
                catch (NotSupportedException)
                {
                }

                Shell.DestroyIcon(shinfo.hIcon);
            }
        }
예제 #2
0
        public DirectoryNode(string path)
        {
            if (!Directory.Exists(path))
                throw new FileNotFoundException("The directory added to MediaDirectory was not found.", path);

            _path = path;
            _nodes = new List<IMediaNode>();
            _name = new FileInfo(_path).Name;

            string[] files = Directory.GetFiles(_path);
            foreach (string file in files)
                _nodes.Add(new FileNode(file));

            string[] directories = Directory.GetDirectories(_path);
            foreach (string directory in directories)
                _nodes.Add(new DirectoryNode(directory));

            _sizeOnDisc = 0;
            foreach (IMediaNode node in _nodes)
                _sizeOnDisc += node.SizeOnDisc;

            //
            // Get the Directory icon
            //
            Shell.SHFILEINFO shinfo = new Shell.SHFILEINFO();
            IntPtr hImg = Shell.SHGetFileInfo(_path, 0, ref shinfo,
                (uint)Marshal.SizeOf(shinfo), Shell.SHGFI_ICON | Shell.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
                {
                    _fileIcon = (System.Drawing.Image)imageConverter.ConvertTo(icon, typeof(System.Drawing.Image));
                }
                catch (NotSupportedException)
                {
                }

                Shell.DestroyIcon(shinfo.hIcon);
            }
        }