Skip to content

Commit

Permalink
feat: prompt for directory if path can't be resolved for bundle with …
Browse files Browse the repository at this point in the history
…multiple formats
  • Loading branch information
DropSnorz committed Aug 19, 2024
1 parent 87df432 commit e315cbe
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -158,6 +159,46 @@ public Iterable<Plugin> 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -64,6 +66,8 @@ public class ExploreService extends BaseService {
private RemotePackageDAO remotePackageDAO;
@Autowired
private ExploreTaskFactory exploreTaskFactory;
@Autowired
private PluginService pluginService;

@PostConstruct
private void init() {
Expand Down Expand Up @@ -246,6 +250,23 @@ public void delete(RemoteSource remoteSource) {
remoteSourceDAO.delete(remoteSource);
}

public boolean canDeterminateBundleInstallFolder(PackageBundle bundle) {

List<PluginFormat> formats = filterEnabledFormats(bundle.getFormats());
if (formats.size() == 1) {
return true;
} else if (formats.size() > 1) {
List<String> 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
Expand All @@ -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<PluginFormat> filterEnabledFormats(List<String> formats) {
List<PluginFormat> filtered = new ArrayList<>();
for (String formatVal : formats) {
PluginFormat format = PluginFormat.fromBundleString(formatVal);
if (this.pluginService.isFormatEnabled(format)) {
filtered.add(format);
}
}
return filtered;
}

/**
Expand Down

0 comments on commit e315cbe

Please sign in to comment.