diff --git a/owlplug-client/src/main/java/com/owlplug/core/services/PluginService.java b/owlplug-client/src/main/java/com/owlplug/core/services/PluginService.java index 0424eebd..1b6328be 100644 --- a/owlplug-client/src/main/java/com/owlplug/core/services/PluginService.java +++ b/owlplug-client/src/main/java/com/owlplug/core/services/PluginService.java @@ -19,6 +19,7 @@ package com.owlplug.core.services; import com.google.common.collect.Iterables; +import com.owlplug.core.components.ApplicationDefaults; import com.owlplug.core.components.CoreTaskFactory; import com.owlplug.core.dao.PluginDAO; import com.owlplug.core.dao.PluginFootprintDAO; @@ -158,6 +159,46 @@ public Iterable findByComponentName(String name, PluginFormat pluginForm return pluginDAO.findAll(spec); } + + /** + * Get the plugin path based on plugin format. + * @param format plugin format + * @return the directory path + */ + public String getPluginPathByFormat(PluginFormat format) { + + if (PluginFormat.VST2.equals(format)) { + return this.getPreferences().get(ApplicationDefaults.VST_DIRECTORY_KEY, ""); + } else if (PluginFormat.VST3.equals(format)) { + return this.getPreferences().get(ApplicationDefaults.VST3_DIRECTORY_KEY, ""); + } else if (PluginFormat.AU.equals(format)) { + return this.getPreferences().get(ApplicationDefaults.AU_DIRECTORY_KEY, ""); + } else if (PluginFormat.LV2.equals(format)) { + return this.getPreferences().get(ApplicationDefaults.LV2_DIRECTORY_KEY, ""); + } + + return this.getPreferences().get(ApplicationDefaults.VST_DIRECTORY_KEY, ""); + } + + /** + * Check if format discovery is enabled. + * @param format pluginFormat + * @return true if discovery is enabled. + */ + public boolean isFormatEnabled(PluginFormat format) { + + if (PluginFormat.VST2.equals(format)) { + return this.getPreferences().getBoolean(ApplicationDefaults.VST2_DISCOVERY_ENABLED_KEY, false); + } else if (PluginFormat.VST3.equals(format)) { + return this.getPreferences().getBoolean(ApplicationDefaults.VST3_DISCOVERY_ENABLED_KEY, false); + } else if (PluginFormat.AU.equals(format)) { + return this.getPreferences().getBoolean(ApplicationDefaults.AU_DISCOVERY_ENABLED_KEY, false); + } else if (PluginFormat.LV2.equals(format)) { + return this.getPreferences().getBoolean(ApplicationDefaults.LV2_DISCOVERY_ENABLED_KEY, false); + } + + return false; + } /** * Removes a plugin reference from database. diff --git a/owlplug-client/src/main/java/com/owlplug/explore/controllers/ExploreController.java b/owlplug-client/src/main/java/com/owlplug/explore/controllers/ExploreController.java index c23614fc..23c64c17 100644 --- a/owlplug-client/src/main/java/com/owlplug/explore/controllers/ExploreController.java +++ b/owlplug-client/src/main/java/com/owlplug/explore/controllers/ExploreController.java @@ -378,18 +378,22 @@ public boolean installBundle(PackageBundle bundle) { File selectedDirectory = null; - String baseDirectoryPath = exploreService.getBundleInstallFolder(bundle); + String baseDirectoryPath = null; + + // Compute base directory using format if possible + if (exploreService.canDeterminateBundleInstallFolder(bundle)) { + baseDirectoryPath = exploreService.getBundleInstallFolder(bundle); + } // A custom root directory to store plugin is defined and the base directory for - // the bundle type is defined or not blank. + // the bundle format is defined or not blank. if (this.getPreferences().getBoolean(ApplicationDefaults.STORE_DIRECTORY_ENABLED_KEY, false) && baseDirectoryPath != null && !baseDirectoryPath.isBlank()) { // Store install target is already defined - String relativeDirectoryPath = this.getPreferences().get(ApplicationDefaults.STORE_DIRECTORY_KEY, ""); Boolean shouldGroupByCreator = this.getPreferences().getBoolean(ApplicationDefaults.STORE_BY_CREATOR_ENABLED_KEY, false); - //if the enduser wishes to group plugins by their creator, + //if the user wishes to group plugins by their creator, //then we need to include the subdirectory as well. if (shouldGroupByCreator) { String creator = FileUtils.sanitizeFileName(bundle.getRemotePackage().getCreator()); @@ -403,7 +407,9 @@ public boolean installBundle(PackageBundle bundle) { // Open dialog chooser to define store installation target DirectoryChooser directoryChooser = new DirectoryChooser(); // Open the VST directory - File initialDirectory = new File(baseDirectoryPath); + String vstDirectory = this.getPreferences().get(ApplicationDefaults.VST_DIRECTORY_KEY, + this.getApplicationDefaults().getDefaultPluginPath(PluginFormat.VST2)); + File initialDirectory = new File(vstDirectory); if (initialDirectory.isDirectory()) { directoryChooser.setInitialDirectory(initialDirectory); } diff --git a/owlplug-client/src/main/java/com/owlplug/explore/services/ExploreService.java b/owlplug-client/src/main/java/com/owlplug/explore/services/ExploreService.java index 8fc8db59..c7dfeb20 100644 --- a/owlplug-client/src/main/java/com/owlplug/explore/services/ExploreService.java +++ b/owlplug-client/src/main/java/com/owlplug/explore/services/ExploreService.java @@ -25,6 +25,7 @@ import com.owlplug.core.model.PluginFormat; import com.owlplug.core.model.platform.RuntimePlatform; import com.owlplug.core.services.BaseService; +import com.owlplug.core.services.PluginService; import com.owlplug.explore.components.ExploreTaskFactory; import com.owlplug.explore.dao.RemotePackageDAO; import com.owlplug.explore.dao.RemoteSourceDAO; @@ -41,6 +42,7 @@ import jakarta.annotation.PostConstruct; import java.io.IOException; import java.nio.charset.StandardCharsets; +import java.util.ArrayList; import java.util.List; import org.apache.hc.client5.http.classic.methods.HttpGet; import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; @@ -64,6 +66,8 @@ public class ExploreService extends BaseService { private RemotePackageDAO remotePackageDAO; @Autowired private ExploreTaskFactory exploreTaskFactory; + @Autowired + private PluginService pluginService; @PostConstruct private void init() { @@ -246,6 +250,23 @@ public void delete(RemoteSource remoteSource) { remoteSourceDAO.delete(remoteSource); } + public boolean canDeterminateBundleInstallFolder(PackageBundle bundle) { + + List formats = filterEnabledFormats(bundle.getFormats()); + if (formats.size() == 1) { + return true; + } else if (formats.size() > 1) { + List paths = new ArrayList<>(); + for (PluginFormat format : formats) { + paths.add(this.pluginService.getPluginPathByFormat(format)); + } + // check if all path are equals + return paths.stream().allMatch(s -> s.equals(paths.get(0))); + } + + return false; + } + /** * Returns the bundle installation folder based on the plugin format. * Multiple formats can be embedded in the same bundle, in this case @@ -256,21 +277,20 @@ public void delete(RemoteSource remoteSource) { */ public String getBundleInstallFolder(PackageBundle bundle) { - String formatValue = bundle.getFormats().getFirst(); - PluginFormat format = PluginFormat.fromBundleString(formatValue); - - if (PluginFormat.VST2.equals(format)) { - return this.getPreferences().get(ApplicationDefaults.VST_DIRECTORY_KEY, ""); - } else if (PluginFormat.VST3.equals(format)) { - return this.getPreferences().get(ApplicationDefaults.VST3_DIRECTORY_KEY, ""); - } else if (PluginFormat.AU.equals(format)) { - return this.getPreferences().get(ApplicationDefaults.AU_DIRECTORY_KEY, ""); - } else if (PluginFormat.LV2.equals(format)) { - return this.getPreferences().get(ApplicationDefaults.LV2_DIRECTORY_KEY, ""); - } + PluginFormat format = filterEnabledFormats(bundle.getFormats()).getFirst(); + return pluginService.getPluginPathByFormat(format); - return this.getPreferences().get(ApplicationDefaults.VST_DIRECTORY_KEY, ""); + } + private List filterEnabledFormats(List formats) { + List filtered = new ArrayList<>(); + for (String formatVal : formats) { + PluginFormat format = PluginFormat.fromBundleString(formatVal); + if (this.pluginService.isFormatEnabled(format)) { + filtered.add(format); + } + } + return filtered; } /**