Exemplo n.º 1
0
        private async void listView_DoubleClick(object sender, EventArgs e)
        {
            await StopProcesses();

            SelectedListViewItemCollection itemCollection = listView.SelectedItems;
            ListViewFileItem item = (ListViewFileItem)itemCollection[0];

            if (item.Attributes.HasFlag(FileAttributes.Directory))
            {
                ChangeDirectory(item.Name);
            }
            else
            {
                try
                {
                    fileOperator.OpenFile(item.Name);
                }
                catch (FileNotFoundException)
                {
                    MessageBox.Show("File not found");
                }
                catch (ObjectDisposedException)
                {
                    MessageBox.Show("Failed to open file");
                }
                catch (Win32Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Exemplo n.º 2
0
        public virtual ListViewFileItem ConvertToListViewFileItem(FileSystemInfo file)
        {
            ListViewFileItem item = new ListViewFileItem(file.Name);

            item.Name       = file.FullName;
            item.ImageKey   = item.Name;
            item.Attributes = file.Attributes;

            return(item);
        }
Exemplo n.º 3
0
        public void FillListView()
        {
            Stopped = false;
            listViewManager.ClearListView();
            listViewManager.SetColumns(columns);
            try
            {
                var files = from fileSys in Dir.EnumerateFiles()
                            select fileSys;

                foreach (var file in files)
                {
                    if (!Stopped)
                    {
                        ListViewFileItem item = ConvertToListViewFileItem(file);
                        columns.AddSubItem(file, item);
                        listViewManager.AddListViewItem(item, GetFileIcon(file));
                    }
                    else
                    {
                        break;
                    }
                }

                var dirs = from fileSys in Dir.EnumerateDirectories()
                           select fileSys;

                foreach (var directory in dirs)
                {
                    if (!Stopped)
                    {
                        ListViewFileItem item = ConvertToListViewFileItem(directory);
                        columns.AddSubItem(directory, item);
                        listViewManager.AddListViewItem(item, GetDirectoryIcon(directory));
                    }
                    else
                    {
                        break;
                    }
                }
            }
            catch (UnauthorizedAccessException)
            {
                //Nothing to do if the file isn't accessible
            }
        }
Exemplo n.º 4
0
 private void viewListContext_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
 {
     if (e.ClickedItem == copyToolStripMenuItem)
     {
         var arr = new ListViewFileItem[getSelectedItems().Count];
         getSelectedItems().CopyTo(arr, 0);
         fileOperator.SelectFiles(arr);
     }
     else if (e.ClickedItem == pasteToolStripMenuItem)
     {
         fileOperator.PasteFile(directoryDisplayer.Dir.ToString());
     }
     else if (e.ClickedItem == deleteToolStripMenuItem)
     {
         var arr = new ListViewFileItem[getSelectedItems().Count];
         getSelectedItems().CopyTo(arr, 0);
         fileOperator.DeleteFile(arr);
     }
 }
        public void FillListView()
        {
            listViewManager.ClearListView();
            listViewManager.SetColumns(columns);

            DriveInfo[] allDrives = DriveInfo.GetDrives();
            foreach (DriveInfo drive in allDrives)
            {
                if (!Stopped)
                {
                    ListViewFileItem item = new ListViewFileItem(drive.Name);
                    item.Name       = drive.Name;
                    item.Attributes = FileAttributes.Directory;
                    item.ImageKey   = item.Name;
                    Icon icon = IconReader.GetFolderIcon(null, IconReader.IconSize.Large, IconReader.FolderType.Open);
                    listViewManager.AddListViewItem(item, icon);
                }
            }
        }
Exemplo n.º 6
0
        private void SearchAll(string searchName, DirectoryInfo dir)
        {
            try
            {
                foreach (FileSystemInfo file in dir.GetFileSystemInfos())
                {
                    if (!Stopped)
                    {
                        if (file.Name.Contains(searchName, StringComparison.OrdinalIgnoreCase))
                        {
                            if (DateFilter != null && file.CreationTime > DateFilter)
                            {
                                ListViewFileItem item = ConvertToListViewFileItem(file);

                                if (file.Attributes.HasFlag(FileAttributes.Directory))                                  //If Directory
                                {
                                    DirectoryInfo dirFile = new DirectoryInfo(file.FullName);
                                    columns.AddSubItem(dirFile, item);
                                }
                                else                                  //If File
                                {
                                    columns.AddSubItem((FileInfo)file, item);
                                }
                                listViewManager.AddListViewItem(item, GetFileSystemIcon(file));
                            }
                        }
                        if (file.Attributes.HasFlag(FileAttributes.Directory))
                        {
                            SearchAll(searchName, new DirectoryInfo(file.FullName));
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
            catch (UnauthorizedAccessException)
            {
                //Nothing to do, user can't access this particular folder
            }
        }