From f9deb8c201720e161bb8659b99206c476e2a39fc Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Wed, 15 Jul 2020 14:03:50 +0200 Subject: [PATCH] Print skipped files on `yabridgectl sync -v` --- tools/yabridgectl/src/files.rs | 38 +++++++++++++++++----------------- tools/yabridgectl/src/main.rs | 22 ++++++++++++++------ 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/tools/yabridgectl/src/files.rs b/tools/yabridgectl/src/files.rs index 35be3ef0..05c2dc9e 100644 --- a/tools/yabridgectl/src/files.rs +++ b/tools/yabridgectl/src/files.rs @@ -31,9 +31,9 @@ use walkdir::WalkDir; pub struct SearchResults { /// Absolute paths to the found VST2 `.dll` files. pub vst2_files: Vec, - /// The number of skipped `.dll` files. Only used for printing statistics, so we don't keep - /// track of the exact files. - pub num_skipped_files: usize, + /// `.dll` files skipped over during the serach. Used for printing statistics and shown when + /// running `yabridgectl sync --verbose`. + pub skipped_files: Vec, /// Absolute paths to any `.so` files inside of the directory, and whether they're a symlink or /// a regular file. pub so_files: Vec, @@ -122,15 +122,15 @@ pub fn index(directory: &Path) -> Result { } } - // Then we'll filter out any .dll files that are not VST2 plugins by checking whether the - // exptected entry points for VST2 plugins are present lazy_static! { static ref VST2_AUTOMATON: AhoCorasick = AhoCorasick::new_auto_configured(&["VSTPluginMain", "main", "main_plugin"]); } - let dll_file_count = dll_files.len(); - let vst2_files: Vec = dll_files + // THne we'll figure out which `.dll` files are VST2 plugins and which should be skipped by + // checking whether the file contains one of the VST2 entry point functions. The boolean flag in + // this vector indicates whether it is a VST2 plugin. + let dll_files: Vec<(PathBuf, bool)> = dll_files .into_par_iter() .map(|path| { let exported_functions = Command::new("winedump") @@ -140,23 +140,23 @@ pub fn index(directory: &Path) -> Result { .output()? .stdout; - Ok((path, exported_functions)) - }) - .filter_map(|result| match result { - Ok((path, exported_functions)) => { - if VST2_AUTOMATON.is_match(exported_functions) { - Some(Ok(path)) - } else { - None - } - } - Err(err) => Some(Err(err)), + Ok((path, VST2_AUTOMATON.is_match(exported_functions))) }) .collect::>()?; + let mut vst2_files = Vec::new(); + let mut skipped_files = Vec::new(); + for (path, is_vst2_plugin) in dll_files { + if is_vst2_plugin { + vst2_files.push(path); + } else { + skipped_files.push(path); + } + } + Ok(SearchResults { - num_skipped_files: dll_file_count - vst2_files.len(), vst2_files, + skipped_files, so_files, }) } diff --git a/tools/yabridgectl/src/main.rs b/tools/yabridgectl/src/main.rs index c723c79b..5496577c 100644 --- a/tools/yabridgectl/src/main.rs +++ b/tools/yabridgectl/src/main.rs @@ -32,8 +32,6 @@ mod files; // TODO: When creating copies, check whether `yabridge-host.exe` is in the PATH for the login shell // TODO: Check for left over files when removing directory // TODO: Reward parts of the readme -// TODO: Record .dll files processed, .dll files skipped and orphan .so files. Print a summary of -// the work done, and allow a --verbose option to print everything. fn main() { let mut config = match Config::read() { @@ -204,12 +202,12 @@ fn do_sync(config: &Config, prune: bool, verbose: bool) { // Keep track of some global statistics let mut num_installed = 0; - let mut num_skipped = 0; + let mut skipped_dll_files: Vec = Vec::new(); let mut orphan_so_files: Vec = Vec::new(); for (path, search_results) in results { - orphan_so_files.extend(search_results.orphans().into_iter().cloned()); num_installed += search_results.vst2_files.len(); - num_skipped += search_results.num_skipped_files; + orphan_so_files.extend(search_results.orphans().into_iter().cloned()); + skipped_dll_files.extend(search_results.skipped_files); if verbose { println!("{}:", path.display()); @@ -259,6 +257,18 @@ fn do_sync(config: &Config, prune: bool, verbose: bool) { } } + // We'll print the skipped files all at once to prevetn clutter + let num_skipped_files = skipped_dll_files.len(); + if verbose && !skipped_dll_files.is_empty() { + println!("Skipped files:"); + for path in skipped_dll_files { + println!("- {}", path.display()); + } + println!(); + } + + // Always warn about leftover files sicne those might cause warnings or errors when a VST host + // tries to load them if !orphan_so_files.is_empty() { if prune { println!("Removing {} leftover '.so' file(s):", orphan_so_files.len()); @@ -286,7 +296,7 @@ fn do_sync(config: &Config, prune: bool, verbose: bool) { println!( "Finished setting up {} plugins, skipped {} non-plugin '.dll' files.", - num_installed, num_skipped + num_installed, num_skipped_files ) }