private void Paste(object parameter) { try { foreach (var source in _clipboard) { var sourcePath = source.Path + source.Name; var destinationPath = CurrentPath.GetChild(source.Name).DisplayPath; if (!_manipulator.Exists(sourcePath)) { MessageBox.Show("File or folder to copy does not exist", "Path not found!", MessageBoxButton.OK, MessageBoxImage.Error); continue; } if (_manipulator.Exists(destinationPath)) { var result = MessageBox.Show("Replace file?", "File already exists!", MessageBoxButton.YesNo, MessageBoxImage.Information); if (result == MessageBoxResult.No) continue; _manipulator.Delete(destinationPath); var listItem = Items.First(l => l.Name == source.Name); Items.Remove(listItem); } if (_copy) { var vm = new OperationProgressViewModel(); ViewModelHelper.RunAsyncAction(() => _manipulator.Copy(sourcePath, destinationPath, vm.Callbacks)); vm.ShowDialog(); } else _manipulator.Move(sourcePath, destinationPath); } RefreshCurrentDirectory (); } catch (Exception ex) { UserMessage.Exception(ex); } UpdateVersion(); }
private void Import(string source, string name, bool isDirectory) { try { var virtualPath = CurrentPath.GetChild(name).DisplayPath; if (_manipulator.Exists(virtualPath)) { var messageBoxText = string.Format("Replace {0}?", isDirectory ? "folder" : "file"); var caption = string.Format("{0} already exists!", isDirectory ? "Folder" : "File"); var res = MessageBox.Show(messageBoxText, caption, MessageBoxButton.YesNo, MessageBoxImage.Information); if (res == MessageBoxResult.No) return; _manipulator.Delete(virtualPath); var listItem = Items.First(l => l.Name == name); Items.Remove(listItem); } var vm = new OperationProgressViewModel(); ViewModelHelper.RunAsyncAction(() => _manipulator.Import(source, virtualPath, vm.Callbacks)); vm.ShowDialog(); RefreshCurrentDirectory(); } catch (Exception ex) { UserMessage.Exception(ex); } UpdateVersion(); }
private void Open(object parameter) { var item = parameter as ListItem; if (item == null) return; try { if (item.IsDirectory) { if (item.Name == "..") { if (CurrentPath.IsRoot) return; CurrentPath.SwitchToParent(); RefreshCurrentDirectory(); } else { CurrentPath = new DirectoryPath(item.Path, item.Name); } } else { var tmpFile = Path.GetTempPath() + item.Name; if (File.Exists(tmpFile)) File.Delete(tmpFile); var vm = new OperationProgressViewModel(); ViewModelHelper.RunAsyncAction(() => _manipulator.Export(item.Path + item.Name, tmpFile, vm.Callbacks)); vm.ShowDialog(); Process.Start("explorer", tmpFile); } } catch (Exception ex) { UserMessage.Exception(ex); } }
private void Export(object parameter) { var items = parameter as ObservableCollection<object>; if (items == null) return; var dlg = new FolderBrowserDialog { ShowNewFolderButton = true }; if (dlg.ShowDialog() != DialogResult.OK) return; try { foreach (ListItem item in items) { var exportPath = Path.Combine(dlg.SelectedPath, item.Name); var vfsExportPath = item.Path + item.Name; if (File.Exists(exportPath) || Directory.Exists(exportPath)) { var messageBoxText = string.Format("Replace {0}? (Current item will be deleted if you choose yes!)", Path.GetFullPath(exportPath)); var result = MessageBox.Show(messageBoxText, "Object already exists!", MessageBoxButton.YesNo, MessageBoxImage.Information); if (result == MessageBoxResult.No) continue; if (Directory.Exists(exportPath)) { try { Directory.Delete(exportPath, true); } catch (IOException) { // Give the OS time to release potential resources Thread.Sleep(0); Directory.Delete(exportPath, true); } } if (File.Exists(exportPath)) File.Delete(exportPath); } var vm = new OperationProgressViewModel(); ViewModelHelper.RunAsyncAction(() => _manipulator.Export(vfsExportPath, exportPath, vm.Callbacks)); vm.ShowDialog(); } } catch (Exception ex) { UserMessage.Exception(ex); } }