You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
3.8KB

  1. #include "ScanConfiguration.hpp"
  2. #include "AllUtils.h"
  3. namespace {
  4. const char* XML_SCAN_VST_DEFAULT_PATHS_STR {"vstDefaultPaths"};
  5. const char* XML_CUSTOM_VST_PATHS_STR {"vstCustomPaths"};
  6. const char* XML_SCAN_VST3_DEFAULT_PATHS_STR {"vst3DefaultPaths"};
  7. const char* XML_CUSTOM_VST3_PATHS_STR {"vst3CustomPaths"};
  8. }
  9. ScanConfiguration::ScanConfiguration() : VSTDefaultPaths(true), VST3DefaultPaths(true) {
  10. }
  11. juce::FileSearchPath ScanConfiguration::getAUPaths() {
  12. // Audiounit scanning is managed by macOS, so no custom paths
  13. #ifdef __APPLE__
  14. return auFormat.getDefaultLocationsToSearch();
  15. #else
  16. return juce::FileSearchPath();
  17. #endif
  18. }
  19. juce::FileSearchPath ScanConfiguration::getVSTPaths() {
  20. juce::FileSearchPath paths = customVSTPaths;
  21. if (VSTDefaultPaths) {
  22. paths.addPath(vstFormat.getDefaultLocationsToSearch());
  23. }
  24. return paths;
  25. }
  26. juce::FileSearchPath ScanConfiguration::getVST3Paths() {
  27. juce::FileSearchPath paths = customVST3Paths;
  28. if (VST3DefaultPaths) {
  29. paths.addPath(vst3Format.getDefaultLocationsToSearch());
  30. }
  31. return paths;
  32. }
  33. void ScanConfiguration::restoreFromXml() {
  34. juce::File configFile = Utils::DataDirectory.getChildFile(Utils::SCAN_CONFIGURATION_FILE_NAME);
  35. if (!configFile.existsAsFile()) {
  36. juce::Logger::writeToLog("Scan configuration file doesn't exist");
  37. return;
  38. }
  39. std::unique_ptr<juce::XmlElement> element = juce::XmlDocument::parse(configFile);
  40. if (element == nullptr) {
  41. juce::Logger::writeToLog("Failed to parse XML from scan configuration file");
  42. return;
  43. }
  44. if (element->hasAttribute(XML_SCAN_VST_DEFAULT_PATHS_STR)) {
  45. VSTDefaultPaths = element->getBoolAttribute(XML_SCAN_VST_DEFAULT_PATHS_STR);
  46. } else {
  47. juce::Logger::writeToLog("Missing attribute " + juce::String(XML_SCAN_VST_DEFAULT_PATHS_STR));
  48. }
  49. if (element->hasAttribute(XML_CUSTOM_VST_PATHS_STR)) {
  50. // Clear existing paths
  51. while (customVSTPaths.getNumPaths() > 0) {
  52. customVSTPaths.remove(0);
  53. }
  54. auto paths = juce::StringArray::fromTokens(element->getStringAttribute(XML_CUSTOM_VST_PATHS_STR), ";", "");
  55. for (juce::String path : paths) {
  56. customVSTPaths.addIfNotAlreadyThere(juce::File(path));
  57. }
  58. } else {
  59. juce::Logger::writeToLog("Missing attribute " + juce::String(XML_CUSTOM_VST_PATHS_STR));
  60. }
  61. if (element->hasAttribute(XML_SCAN_VST3_DEFAULT_PATHS_STR)) {
  62. VST3DefaultPaths = element->getBoolAttribute(XML_SCAN_VST3_DEFAULT_PATHS_STR);
  63. } else {
  64. juce::Logger::writeToLog("Missing attribute " + juce::String(XML_SCAN_VST3_DEFAULT_PATHS_STR));
  65. }
  66. if (element->hasAttribute(XML_CUSTOM_VST3_PATHS_STR)) {
  67. // Clear existing paths
  68. while (customVST3Paths.getNumPaths() > 0) {
  69. customVST3Paths.remove(0);
  70. }
  71. auto paths = juce::StringArray::fromTokens(element->getStringAttribute(XML_CUSTOM_VST3_PATHS_STR), ";", "");
  72. for (juce::String path : paths) {
  73. customVST3Paths.addIfNotAlreadyThere(juce::File(path));
  74. }
  75. } else {
  76. juce::Logger::writeToLog("Missing attribute " + juce::String(XML_CUSTOM_VST3_PATHS_STR));
  77. }
  78. }
  79. void ScanConfiguration::writeToXml() const {
  80. juce::File configFile = Utils::DataDirectory.getChildFile(Utils::SCAN_CONFIGURATION_FILE_NAME);
  81. configFile.deleteFile();
  82. auto element = std::make_unique<juce::XmlElement>("scanConfiguration");
  83. element->setAttribute(XML_SCAN_VST_DEFAULT_PATHS_STR, VSTDefaultPaths);
  84. element->setAttribute(XML_CUSTOM_VST_PATHS_STR, customVSTPaths.toString());
  85. element->setAttribute(XML_SCAN_VST3_DEFAULT_PATHS_STR, VST3DefaultPaths);
  86. element->setAttribute(XML_CUSTOM_VST3_PATHS_STR, customVST3Paths.toString());
  87. element->writeTo(configFile);
  88. }