private Win32.SHFILEINFO[] GetFilteredFiles(DirectoryInfo currentDir)
        {
            List <String> files = new List <String>();

            if (_filters != null && _filters.Length > 0)        //we have filters
            {
                foreach (string filter in _filters[FilterIndex].FilterStr.Split(';'))
                {
                    files.AddRange(Directory.GetFiles(currentDir.FullName, filter));
                }
            }
            else                                                // filter hasn't been set
            {
                files.AddRange(Directory.GetFiles(currentDir.FullName));
            }
            files.Sort();
            //files.Sort(delegate(FileInfo item1, FileInfo item2) //sort the files
            //{
            //    return String.Compare(item1.Name, item2.Name, true, CultureInfo.InvariantCulture);
            //});

            Win32.SHFILEINFO[] fileInfo = new Win32.SHFILEINFO[files.Count];

            for (int i = 0; i < files.Count; i++)
            {
                fileInfo[i] = this.GetFileInfo(files[i]);
                fileInfo[i].szDisplayName = files[i];
            }

            return(fileInfo);
        }
        private Win32.SHFILEINFO[] GetSubDirectories(DirectoryInfo currentDir)
        {
            try
            {
                String[] directories = Directory.GetDirectories(currentDir.FullName);        //sort our list of directories
                Array.Sort(directories);
                //Array.Sort(directories, delegate(DirectoryInfo item1, DirectoryInfo item2)
                //{
                //    return String.Compare(item1.Name, item2.Name, true, CultureInfo.InvariantCulture);
                //});

                Win32.SHFILEINFO[] dirInfo = new Win32.SHFILEINFO[directories.Length];
                for (int i = 0; i < directories.Length; i++)
                {
                    dirInfo[i] = GetFileInfo(directories[i]);
                    dirInfo[i].szDisplayName = directories[i];
                }

                return(dirInfo);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.ToString());
                MessageBox.Show("Unable to access selected folder");
                return(new Win32.SHFILEINFO[0]);//return empty array
            }
        }
        /// <summary>
        /// Initializes a new <see cref="OpenFileDialog"/> which shows the specified directory and file.
        /// </summary>
        /// <param name="currentPath">The current path.</param>
        /// <param name="selectedFile">The selected file.</param>
        //public OpenFileDialogRedux(string currentPath, string selectedFile)
        //    : this() {
        //    this.CurrentDirectory = currentPath;
        //    this.SelectedFile = selectedFile;
        //    this.txtFileName.Text = selectedFile;
        //}

        protected Win32.SHFILEINFO GetFileInfo(String path)
        {
            Win32.SHFILEINFO shinfo = new Win32.SHFILEINFO();                                                                //initialize a SHFILEINFO struct
            Win32.SHGetFileInfo(path, 0, ref shinfo,                                                                         //call native method to retrieve system image list
                                (uint)System.Runtime.InteropServices.Marshal.SizeOf(shinfo),                                 //provide size of SHFILEINFO struct
                                (uint)Win32.SHGetFileInfoFlags.SHGFI_ICON | (uint)Win32.SHGetFileInfoFlags.SHGFI_SMALLICON); //tell it we want the small image list;

            return(shinfo);
        }
        //protected String GetLastVisitedMRU()
        //{

        //Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\LastVisitedPidlMRULegacy");
        //key.GetValue(...)
        //AppDomain.CurrentDomain.FriendlyName
        //}

        //protected void SetLastVisitedMRU(DirectoryInfo dir)
        //{
        //
        //Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\LastVisitedPidlMRULegacy");
        //key.SetValue
        //AppDomain.CurrentDomain.FriendlyName
        //}



        private void InitializeListViewImageList()
        {
            Win32.SHFILEINFO shinfo = new Win32.SHFILEINFO();                                                                            //initialize a SHFILEINFO struct
            hImgSmall = Win32.SHGetFileInfo("\\", 0, ref shinfo,                                                                         //call native method to retrieve system image list
                                            (uint)System.Runtime.InteropServices.Marshal.SizeOf(shinfo),                                 //provide size of SHFILEINFO struct
                                            (uint)Win32.SHGetFileInfoFlags.SHGFI_ICON | (uint)Win32.SHGetFileInfoFlags.SHGFI_SMALLICON); //tell it we want the small image list;

            //instruct List View to not delete the image list when it closes, otherwise bad things could happen
            int currentLVStyle = Win32.GetWindowLong(lstFiles.Handle, Win32.GWL_STYLE);

            Win32.SetWindowLong(lstFiles.Handle, Win32.GWL_STYLE, currentLVStyle | Win32.LVS_SHAREIMAGELISTS);

            Win32.SendMessage(lstFiles.Handle, Win32.LVM_SETIMAGELIST, 1, hImgSmall); //attatch image list to list view
        }
        protected bool IsVisable(Win32.SHFILEINFO fsi)
        {
            int SFGAO_HIDDEN = 0x00080000; // see file atrubutes @ http://msdn.microsoft.com/en-us/library/windows/desktop/bb762589(v=vs.85).aspx

            return(ShowHidden || ((fsi.dwAttributes & SFGAO_HIDDEN) != SFGAO_HIDDEN));
        }