From a3e76b337021693030fbce17b70bb961217c099f Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Thu, 24 Dec 2020 12:30:38 +0100 Subject: [PATCH] [yabridgectl] Warn for duplicate VST3 plugins Since we can't have multiple plugins with the same name this way. --- tools/yabridgectl/src/actions.rs | 37 ++++++++++++++++++++++---------- tools/yabridgectl/src/files.rs | 12 ++++++++++- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/tools/yabridgectl/src/actions.rs b/tools/yabridgectl/src/actions.rs index f2b6ca9a..7aa565d7 100644 --- a/tools/yabridgectl/src/actions.rs +++ b/tools/yabridgectl/src/actions.rs @@ -18,13 +18,12 @@ use anyhow::{Context, Result}; use colored::Colorize; -use std::collections::BTreeSet; +use std::collections::{BTreeMap, BTreeSet}; use std::fs; use std::path::{Path, PathBuf}; use crate::config::{yabridge_vst3_home, Config, InstallationMethod, YabridgeFiles}; -use crate::files; -use crate::files::NativeFile; +use crate::files::{self, LibArchitecture, NativeFile}; use crate::utils; use crate::utils::{verify_path_setup, verify_wine_setup}; @@ -199,17 +198,11 @@ pub fn do_sync(config: &mut Config, options: &SyncOptions) -> Result<()> { let mut orphan_files: Vec = Vec::new(); // All the VST3 modules we have set up yabridge for. We need this to detect leftover VST3 // modules in `~/.vst3/yabridge`. - let mut yabridge_vst3_bundles: BTreeSet = BTreeSet::new(); + let mut yabridge_vst3_bundles: BTreeMap> = BTreeMap::new(); for (path, search_results) in results { num_installed += search_results.vst2_files.len(); num_installed += search_results.vst3_modules.len(); orphan_files.extend(search_results.vst2_orphans().into_iter().cloned()); - yabridge_vst3_bundles.extend( - search_results - .vst3_modules - .iter() - .map(|module| module.yabridge_bundle_home()), - ); skipped_dll_files.extend(search_results.skipped_files); if options.verbose { @@ -241,6 +234,28 @@ pub fn do_sync(config: &mut Config, options: &SyncOptions) -> Result<()> { // https://steinbergmedia.github.io/vst3_doc/vstinterfaces/vst3loc.html#mergedbundles if let Some(libyabridge_vst3_hash) = libyabridge_vst3_hash { for module in search_results.vst3_modules { + // Check if we already set up the same architecture version of the plugin (since + // 32-bit and 64-bit versions of the plugin cna live inside of the same bundle), and + // show a warning if we come across any duplicates. + let already_installed_architectures = yabridge_vst3_bundles + .entry(module.yabridge_bundle_home()) + .or_insert_with(|| BTreeSet::new()); + if !already_installed_architectures.insert(module.architecture()) { + eprintln!( + "{}", + utils::wrap(&format!( + "{}: The {} version of '{}' has already been provided by another Wine \ + prefix, skipping '{}'\n", + "WARNING".red(), + module.architecture(), + module.yabridge_bundle_home().display(), + module.original_module_path().display(), + )) + ); + + continue; + } + let native_module_path = module.yabridge_native_module_path(); // For VST3 plugins we'll first have to create the bundle structure @@ -298,7 +313,7 @@ pub fn do_sync(config: &mut Config, options: &SyncOptions) -> Result<()> { .filter_map(|path| { // Add all files and directories in `~/.vst3/yabridge` to `orphan_files` if they // are not a VST3 module we just created - if !yabridge_vst3_bundles.contains(&path) { + if !yabridge_vst3_bundles.contains_key(&path) { utils::get_file_type(path) } else { None diff --git a/tools/yabridgectl/src/files.rs b/tools/yabridgectl/src/files.rs index af284480..1c82331b 100644 --- a/tools/yabridgectl/src/files.rs +++ b/tools/yabridgectl/src/files.rs @@ -21,6 +21,7 @@ use anyhow::{Context, Result}; use lazy_static::lazy_static; use rayon::prelude::*; use std::collections::{BTreeMap, HashMap}; +use std::fmt::Display; use std::path::{Path, PathBuf}; use std::process::Command; use walkdir::WalkDir; @@ -177,12 +178,21 @@ impl Vst3Module { } /// The architecture of a `.dll` file. Needed so we can create a merged bundle for VST3 plugins. -#[derive(Debug, Clone, PartialEq, Eq, Copy)] +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Copy)] pub enum LibArchitecture { Dll32, Dll64, } +impl Display for LibArchitecture { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match &self { + LibArchitecture::Dll32 => write!(f, "32-bit"), + LibArchitecture::Dll64 => write!(f, "64-bit"), + } + } +} + impl LibArchitecture { /// Get the corresponding VST3 architecture directory name. See /// https://steinbergmedia.github.io/vst3_doc/vstinterfaces/vst3loc.html.