private bool deleteRecursive(ConsoleContext console, string directory, bool force) { foreach (var dir in _fs.GetDirectories(directory)) { if (_futils.GetNameFromPath(dir) == ".." || _futils.GetNameFromPath(dir) == ".") { continue; } if (!deleteRecursive(console, dir, force)) { return(false); } if (!force) { console.Write($"Are you sure you want to remove {dir}? [y/N]"); if (console.ReadLine().ToLower() != "y") { console.WriteLine("rm: Operation cancelled by user."); return(false); } } } foreach (var file in _fs.GetFiles(directory)) { if (!force) { console.Write($"Are you sure you want to remove {file}? [y/N]"); if (console.ReadLine().ToLower() != "y") { console.WriteLine("rm: Operation cancelled by user."); return(false); } } _fs.Delete(file); } if (!force) { console.Write($"Are you sure you want to remove {directory}? [y/N]"); if (console.ReadLine().ToLower() != "y") { console.WriteLine("rm: Operation cancelled by user."); return(false); } } _fs.Delete(directory); return(true); }
private void Desktop_RightClick(object sender, EventArgs e) { _desktopRightClick.ClearItems(); var newFolder = new MenuItem { Text = "New Folder..." }; newFolder.Activated += () => { string folderPath = "/home/Desktop"; _infobox.PromptText("New folder", "Please enter a name for your new folder.", (name) => { string fullPath = (folderPath.EndsWith("/")) ? folderPath + name : folderPath + "/" + name; _fs.CreateDirectory(fullPath); }, (proposedName) => { if (string.IsNullOrWhiteSpace(proposedName)) { _infobox.Show("New folder", "Your folder's name must not be blank."); return(false); } foreach (char c in proposedName) { if (char.IsLetterOrDigit(c)) { continue; } if (c == '_' || c == ' ' || c == '-' || c == '.') { continue; } _infobox.Show("Invalid path character", "Your new folder's name contains an invalid character. Valid characters include any letter or number as well as '.', '_', '-' or a space."); return(false); } string fullPath = (folderPath.EndsWith("/")) ? folderPath + proposedName : folderPath + "/" + proposedName; if (_fs.DirectoryExists(fullPath) || _fs.FileExists(fullPath)) { _infobox.Show("New folder", "A folder or file already exists with that name."); return(false); } return(true); }); }; var changeDesktopBackground = new MenuItem { Text = "Change Desktop Background..." }; changeDesktopBackground.Activated += () => { var appearance = new Applications.Appearance(WindowSystem); appearance.Show(); }; _desktopRightClick.AddItem(newFolder); if (_desktopIconsView.SelectedItem != null) { var path = _desktopIconsView.SelectedItem.Tag.ToString(); var name = _desktopIconsView.SelectedItem.Value; var delete = new MenuItem { Text = (_fs.DirectoryExists(path)) ? "Delete folder" : "Delete file" }; delete.Activated += () => { _infobox.ShowYesNo(delete.Text, "Are you sure you want to delete \"" + path + "\"?", (answer) => { if (answer) { _fs.Delete(path); } }); }; _desktopRightClick.AddItem(delete); } _desktopRightClick.AddItem(changeDesktopBackground); _desktopRightClick.Show(MouseX, MouseY); }