diff --git a/tools/yabridgectl/src/actions.rs b/tools/yabridgectl/src/actions.rs index f9af093e..7698a7bb 100644 --- a/tools/yabridgectl/src/actions.rs +++ b/tools/yabridgectl/src/actions.rs @@ -28,6 +28,8 @@ use crate::files::{self, LibArchitecture, NativeFile, Plugin, Vst2Plugin}; use crate::utils; use crate::utils::{verify_path_setup, verify_wine_setup}; +pub mod blacklist; + /// Add a direcotry to the plugin locations. Duplicates get ignord because we're using ordered sets. pub fn add_directory(config: &mut Config, path: PathBuf) -> Result<()> { config.plugin_dirs.insert(path); diff --git a/tools/yabridgectl/src/actions/blacklist.rs b/tools/yabridgectl/src/actions/blacklist.rs new file mode 100644 index 00000000..f19f8ccc --- /dev/null +++ b/tools/yabridgectl/src/actions/blacklist.rs @@ -0,0 +1,45 @@ +// yabridge: a Wine VST bridge +// Copyright (C) 2020-2021 Robbert van der Helm +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +//! Handlers for the blacklist subcommands, just to keep `main.rs` clean. + +use anyhow::Result; +use std::path::{Path, PathBuf}; + +use crate::config::Config; + +/// Add a path to the blacklist. Duplicates get ignord because we're using ordered sets. +pub fn add_path(config: &mut Config, path: PathBuf) -> Result<()> { + config.blacklist.insert(path); + config.write() +} + +/// Remove a path from the blacklist. The path is assumed to be part of `config.blacklist`, +/// otherwise this is silently ignored. +pub fn remove_path(config: &mut Config, path: &Path) -> Result<()> { + // We've already verified that this path is in `config.blacklist` + config.blacklist.remove(path); + config.write() +} + +/// List the paths in the blacklist. +pub fn list_paths(config: &Config) -> Result<()> { + for directory in &config.blacklist { + println!("{}", directory.display()); + } + + Ok(()) +} diff --git a/tools/yabridgectl/src/main.rs b/tools/yabridgectl/src/main.rs index 43927e43..df350c80 100644 --- a/tools/yabridgectl/src/main.rs +++ b/tools/yabridgectl/src/main.rs @@ -47,17 +47,26 @@ fn main() -> Result<()> { .iter() .map(|path| path.to_str().expect("Path contains invalid unicode")) .collect(); + // Used for validation in `yabridgectl blacklist rm ` + let blacklist_entries: Vec<&str> = config + .blacklist + .iter() + .map(|path| path.to_str().expect("Path contains invalid unicode")) + .collect(); let matches = app_from_crate!() .setting(AppSettings::SubcommandRequiredElseHelp) .subcommand( - App::new("add").about("Add a plugin install location").display_order(1).arg( - Arg::new("path") - .about("Path to a directory containing Windows VST plugins") - .validator(validate_path) - .takes_value(true) - .required(true), - ), + App::new("add") + .about("Add a plugin install location") + .display_order(1) + .arg( + Arg::new("path") + .about("Path to a directory containing Windows VST plugins") + .validator(validate_path) + .takes_value(true) + .required(true), + ), ) .subcommand( App::new("rm") @@ -71,8 +80,16 @@ fn main() -> Result<()> { .required(true), ), ) - .subcommand(App::new("list").about("List the plugin install locations").display_order(3)) - .subcommand(App::new("status").about("Show the installation status for all plugins").display_order(4)) + .subcommand( + App::new("list") + .about("List the plugin install locations") + .display_order(3), + ) + .subcommand( + App::new("status") + .about("Show the installation status for all plugins") + .display_order(4), + ) .subcommand( App::new("sync") .about("Set up or update yabridge for all plugins") @@ -160,6 +177,47 @@ fn main() -> Result<()> { .takes_value(true), ), ) + .subcommand( + App::new("blacklist") + .about("Manage the indexing blacklist (advanced)") + .display_order(201) + .setting(AppSettings::SubcommandRequiredElseHelp) + .long_about( + "Manage the indexing blacklist (advanced)\n\ + \n\ + This lets you skip over individual files and entire directories in the \ + indexing process. You most likely won't have to use this feature.", + ) + .subcommand( + App::new("add") + .about("Add a path to the blacklist") + .display_order(1) + .arg( + Arg::new("path") + .about("Path to a file or a directory") + .validator(validate_path) + .takes_value(true) + .required(true), + ), + ) + .subcommand( + App::new("rm") + .about("Remove a path from the blacklist") + .display_order(2) + .arg( + Arg::new("path") + .about("Path to a previously added file or directory") + .possible_values(&blacklist_entries) + .takes_value(true) + .required(true), + ), + ) + .subcommand( + App::new("list") + .about("List the blacklisted paths") + .display_order(3), + ), + ) .get_matches(); // We're calling canonicalize when adding and setting paths since relative paths would cause @@ -202,6 +260,20 @@ fn main() -> Result<()> { no_verify: options.value_of("no_verify").map(|value| value == "true"), }, ), + Some(("blacklist", blacklist)) => match blacklist.subcommand() { + Some(("add", options)) => actions::blacklist::add_path( + &mut config, + options + .value_of_t_or_exit::("path") + .canonicalize()?, + ), + Some(("rm", options)) => actions::blacklist::remove_path( + &mut config, + &options.value_of_t_or_exit::("path"), + ), + Some(("list", _)) => actions::blacklist::list_paths(&config), + _ => unreachable!(), + }, _ => unreachable!(), } }