private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     FileOperator.InitilalDirs();
     rightSortChooseBox.ItemsSource = FileOperator.sortTypes;
     leftSortChooseBox.ItemsSource  = FileOperator.sortTypes;
     UpdateAllViews();
 }
 private void cmdHere_Click(object sender, RoutedEventArgs e)
 {
     if (!FileOperator.StartCmd(File_Containers.FileDualContainer.ChooseContainer(FileOperator.ActiveDirectory).StoredDirectory))
     {
         MessageBox.Show("Error opening cmd from this directory", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
        async private void copyBut_Click(object sender, RoutedEventArgs e)
        {
            IEnumerable <IFileObject> selectedItems = GetSelectedItemsData();

            if (selectedItems.Count() == 0)
            {
                MessageBox.Show("No elements selected", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            File_Containers.FileContainer receiver = FileOperator.ActiveDirectory == FileOperator.Side.Left ? File_Containers.FileDualContainer.ChooseContainer(FileOperator.Side.Right) :
                                                     File_Containers.FileDualContainer.ChooseContainer(FileOperator.Side.Left);
            Task delTask = Task.Run(() => DeletePreviouslyCreated(receiver, selectedItems));

            delTask.Wait();
            if (MessageBox.Show($"{selectedItems.Count()} items will be copied. Continue?", "Information", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                try
                {
                    NotifyAboutFileOperations($"Copy files to {receiver}");
                    await FileOperator.CopyFiles(selectedItems, receiver);

                    ClearNotifyAboutFileOperations();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Unable to copy in this directory", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }
            await Task.Run(() => UpdateView(FileOperator.ActiveDirectory == FileOperator.Side.Left ? FileOperator.Side.Right : FileOperator.Side.Left));
        }
        async Task UpdateAllViews()
        {
            List <IFileObject> leftList  = FileOperator.GetDirContainsList(FileOperator.Side.Left).ToList();
            List <IFileObject> rightList = FileOperator.GetDirContainsList(FileOperator.Side.Right).ToList();

            while (true)
            {
                await Task.Delay(1000);

                //FileOperator.Side s = FileOperator.ActiveDirectory;
                List <IFileObject> leftNewList  = FileOperator.GetDirContainsList(FileOperator.Side.Left).ToList();
                List <IFileObject> rightNewList = FileOperator.GetDirContainsList(FileOperator.Side.Right).ToList();
                List <String>      drives       = FileOperator.GetAllLogicalDrives().ToList();
                if (!CompareSortedFileLists(leftList, leftNewList) || !CompareSortedFileLists(rightList, rightNewList) || drives.Count != (rootComboBoxL.ItemsSource.Cast <string>().Count()))
                {
                    //lock (synclock)
                    {
                        await Task.Run(() => UpdateView(FileOperator.Side.Left, leftNewList, false));

                        await Task.Run(() => UpdateView(FileOperator.Side.Right, rightNewList, false));
                    }
                    leftList  = leftNewList;
                    rightList = rightNewList;
                }
            }
        }
        async private void rootComboBoxR_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            String selectedItemR = null;

            try
            {
                selectedItemR = (sender as ComboBox).SelectedItem.ToString();
                FileOperator.HandleOpenFileOrDir(new Dir(selectedItemR), FileOperator.Side.Right);
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Directory {selectedItemR} doesnt exist or unavailable", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            await Task.Run(() => UpdateView(FileOperator.Side.Right));
        }
        async private void rightViewItem_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            object obj = (sender as ListBoxItem).DataContext;

            if (obj != null)
            {
                try
                {
                    FileOperator.HandleOpenFileOrDir(obj, FileOperator.Side.Right);
                }
                catch (Exception ex)
                {
                }
                await Task.Run(() => UpdateView(FileOperator.Side.Right));
            }
        }
示例#7
0
        private void ListBoxItem_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            object obj = (sender as ListBoxItem).DataContext;

            if (obj != null)
            {
                try
                {
                    FileOperator.HandleOpenFileOrDir(obj, FileOperator.Side.Left);
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"This item can not be opened. Error: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }
        }
示例#8
0
        private void acceptButton_Click(object sender, RoutedEventArgs e)
        {
            String filename = pathRow.Text;

            if (filename != String.Empty)
            {
                if (prototype == null)
                {
                    try
                    {
                        FileOperator.MkDirFile(filename, isCreateDir);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show($"Unable to create file {filename}: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
                else
                {
                    if (!prototype.Exists())
                    {
                        MessageBox.Show($"File {prototype.Info.ShortName} is not exist", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }
                    if (MessageBox.Show($"Rename {prototype.Info.ShortName} to {filename}", "Confirm", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                    {
                        try
                        {
                            FileOperator.Rename(prototype, filename);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show($"Unable to rename file {filename}: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                }
            }
            DialogResult = true;
            Close();
        }
        async private void movBut_Click(object sender, RoutedEventArgs e)
        {
            List <IFileObject> selectedItems = GetSelectedItemsData().ToList();

            if (selectedItems.Count() == 0)
            {
                MessageBox.Show("No elements selected", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            File_Containers.FileContainer receiver = FileOperator.ActiveDirectory == FileOperator.Side.Left ? File_Containers.FileDualContainer.ChooseContainer(FileOperator.Side.Right) :
                                                     File_Containers.FileDualContainer.ChooseContainer(FileOperator.Side.Left);
            DeletePreviouslyCreated(receiver, selectedItems);
            if (MessageBox.Show($"{selectedItems.Count()} items will be moved. Continue?", "Information", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                try
                {
                    NotifyAboutFileOperations($"Move files to {receiver.StoredDirectory.Info.ShortName}");
                    await FileOperator.MoveFiles(selectedItems, receiver);

                    ClearNotifyAboutFileOperations();
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"Unable to move in {receiver.StoredDirectory.Info.ShortName}: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                try
                {
                    await Task.Run(() => UpdateView(FileOperator.Side.Left));

                    await Task.Run(() => UpdateView(FileOperator.Side.Right));
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"Unable to renew views: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }
        }
        private void delBut_Click(object sender, RoutedEventArgs e)
        {
            IEnumerable <IFileObject> selectedItems = GetSelectedItemsData();

            if (selectedItems.Count() == 0)
            {
                MessageBox.Show("No elements selected", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            if (MessageBox.Show($"{selectedItems.Count()} items will be removed. THIS ACTION CAN NOT BE UNDONE. Continue?", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
            {
                try
                {
                    FileOperator.Delete(selectedItems);
                    //await Task.Run(() => UpdateView(FileOperator.ActiveDirectory));
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"Cannot delete files : {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }
        }
        async private Task DropHandler(object _sender, object _e, FileOperator.Side _side)
        {
            ListBox parent = (ListBox)_sender;

            if (parent == dragSource)
            {
                return;
            }
            String             data      = (String)(((DragEventArgs)_e).Data.GetData(typeof(String)));
            List <IFileObject> objToMove = ((IList <IFileObject>)dragSource.ItemsSource).Where((item) => item.Info.FullName == data).ToList();

            File_Containers.FileContainer receiver = File_Containers.FileDualContainer.ChooseContainer(_side);
            try
            {
                await Task.Run(() => FileOperator.CopyFiles(objToMove, receiver));
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to copy in this directory", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            ((IList <IFileObject>)dragSource.ItemsSource).Remove(objToMove[0]);
            await Task.Run(() => UpdateView(_side));
        }
        private void UpdateView(FileOperator.Side _s, IEnumerable <IFileObject> _files = null, bool isMakeActive = true)
        {
            ListBox   someView         = null;
            ComboBox  someRootComboBox = null;
            TextBlock somePathRow      = null;
            Grid      someStatusStr    = null;
            ComboBox  someSortComboBox = null;

            if (_s == FileOperator.Side.Left)
            {
                Dispatcher.Invoke(() => someView         = leftView);
                Dispatcher.Invoke(() => someRootComboBox = rootComboBoxL);
                Dispatcher.Invoke(() => somePathRow      = pathRowL);
                Dispatcher.Invoke(() => someStatusStr    = StatusStrL);
                Dispatcher.Invoke(() => someSortComboBox = leftSortChooseBox);
            }
            else if (_s == FileOperator.Side.Right)
            {
                Dispatcher.Invoke(() => someView         = rightView);
                Dispatcher.Invoke(() => someRootComboBox = rootComboBoxR);
                Dispatcher.Invoke(() => somePathRow      = pathRowR);
                Dispatcher.Invoke(() => someStatusStr    = StatusStrR);
                Dispatcher.Invoke(() => someSortComboBox = rightSortChooseBox);
            }
            lock (synclock)
            {
                Dispatcher.Invoke(() => someView.ItemsSource = null);
                List <IFileObject> listOfContFiles = null;
                try
                {
                    listOfContFiles = (_files == null) ? FileOperator.GetDirContainsList(_s).ToList() : _files.ToList();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Files list can not be get", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                try
                {
                    Dispatcher.Invoke(() => someView.ItemsSource = FileOperator.SetActionForSort(listOfContFiles, someSortComboBox.SelectedIndex));
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"Cannot sort items: {ex.Message}. Show unsorted list", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    Dispatcher.Invoke(() => someView.ItemsSource = listOfContFiles);
                }
                List <String> drives       = FileOperator.GetAllLogicalDrives().ToList();
                String        logicalDrive = File_Containers.FileDualContainer.ChooseContainer(_s).StoredDirectory.Info.LogicalDrive;
                try
                {
                    Dispatcher.Invoke(() => someRootComboBox.ItemsSource = drives);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("This disk is not availbale. Chack other disk", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                Dispatcher.Invoke(() => someRootComboBox.SelectedItem = drives.Find((item) => logicalDrive.Equals(item)));
                Dispatcher.Invoke(() => somePathRow.Text          = File_Containers.FileDualContainer.ChooseContainer(_s).StoredDirectory.Info.ShortName);
                Dispatcher.Invoke(() => someStatusStr.DataContext = File_Containers.FileDualContainer.ChooseContainer(_s).StoredDirectory.Info);
                if (isMakeActive)
                {
                    MakeDirActive(_s);
                }
            }
        }
 async private void toParentDirButR_Click(object sender, RoutedEventArgs e)
 {
     FileOperator.NavigateToPreviousDirectory(FileOperator.Side.Right);
     await Task.Run(() => UpdateView(FileOperator.Side.Right));
 }
示例#14
0
        private void startSearchBut_Click(object sender, RoutedEventArgs e)
        {
            List <FileObjects.Dir> DirsToFind = new List <Dir>();

            try
            {
                string[] strdirs = new TextRange(dirsToFindBox.Document.ContentStart, dirsToFindBox.Document.ContentEnd).Text.Trim().Split(';');
                foreach (String d in strdirs)
                {
                    try
                    {
                        DirsToFind.Add(new Dir(d));
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show($"File {d} does not find: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Error: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            if (byNameRadio.IsChecked == true)
            {
                String   searchConditionsAll = condByNameStr.Text;
                String[] searchConditions    = searchConditionsAll.Split(',');
                try
                {
                    IEnumerable <IFileObject> foundedFiles = FileOperator.Find(DirsToFind, Dir.FindMode.Name, searchConditions);
                    resultBox.ItemsSource = foundedFiles;
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"Search can not be executed: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }
            else if (byDateRadio.IsChecked == true)
            {
                DateTime startDate = lowDate.SelectedDate.Value;
                DateTime endDate   = highDate.SelectedDate.Value;
                if (DateTime.Compare(startDate, endDate) > 0)
                {
                    MessageBox.Show("Start date is later than end date", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                List <String> conditionsDate = new List <string> {
                    startDate.ToString(), endDate.ToString()
                };
                try
                {
                    IEnumerable <IFileObject> foundedFiles = FileOperator.Find(DirsToFind, Dir.FindMode.Date, conditionsDate);
                    resultBox.ItemsSource = foundedFiles;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Search can not be executed", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }
            else if (bySizeRadio.IsChecked == true)
            {
                String   sizeAll     = sizeSearchValue.Text;
                String[] searchSizes = sizeAll.Split('-');
                String   modeSearch  = ((ComboBoxItem)modeSelectionSize.SelectedItem).Content.ToString();
                String   sizeSearch  = ((ComboBoxItem)sizeSearchSize.SelectedItem).Content.ToString();
                double   multCoef;
                if (sizeSearch == "KB")
                {
                    multCoef = 1024;
                }
                else if (sizeSearch == "MB")
                {
                    multCoef = Math.Pow(1024, 2);
                }
                else if (sizeSearch == "GB")
                {
                    multCoef = Math.Pow(1024, 3);
                }
                else
                {
                    throw new Exception("Undefined size mode");
                }
                List <String> conditions = new List <String>();
                List <double> sizes      = new List <double>();
                foreach (String size in searchSizes)
                {
                    double outVal;
                    if (double.TryParse(size, out outVal))
                    {
                        outVal *= multCoef;
                        sizes.Add(outVal);
                    }
                    else
                    {
                        MessageBox.Show("Require digit parameter", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }
                }
                if (modeSearch == "more" && sizes.Count == 1)
                {
                    conditions.Add(sizes[0].ToString());
                    conditions.Add(Int32.MaxValue.ToString());
                }
                else if (modeSearch == "less" && sizes.Count == 1)
                {
                    conditions.Add(Int32.MinValue.ToString());
                    conditions.Add(sizes[0].ToString());
                }
                else if (modeSearch == "equals" && sizes.Count == 1)
                {
                    conditions.Add(sizes[0].ToString());
                    conditions.Add(sizes[0].ToString());
                }
                else if (modeSearch == "between" && sizes.Count == 2)
                {
                    conditions.Add(sizes[0].ToString());
                    conditions.Add(sizes[1].ToString());
                }
                else
                {
                    MessageBox.Show("These conditions are not achievable", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                try
                {
                    IEnumerable <IFileObject> foundedFiles = FileOperator.Find(DirsToFind, Dir.FindMode.Size, conditions);
                    resultBox.ItemsSource = foundedFiles;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Search can not be executed", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }
        }