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.

86 lines
3.4KB

  1. #pragma once
  2. #include <JuceHeader.h>
  3. namespace Utils {
  4. inline const char* PLUGIN_SCAN_SERVER_UID = "pluginScanServer";
  5. inline const char* SCANNED_PLUGINS_FILE_NAME = "ScannedPlugins.txt";
  6. inline const char* CRASHED_PLUGINS_FILE_NAME = "CrashedPlugins.txt";
  7. inline const char* SCAN_CONFIGURATION_FILE_NAME = "ScanConfiguration.txt";
  8. inline const char* CONFIG_FILE_NAME = "Config.json";
  9. static inline juce::File getPluginScanServerBinary(juce::AudioProcessor::WrapperType wrapperType)
  10. {
  11. juce::File bin(juce::File::getSpecialLocation(juce::File::currentExecutableFile).getParentDirectory());
  12. switch (wrapperType)
  13. {
  14. case juce::AudioProcessor::wrapperType_LV2:
  15. break;
  16. case juce::AudioProcessor::wrapperType_VST:
  17. bin = bin.getChildFile("Resources");
  18. break;
  19. default:
  20. bin = bin.getSiblingFile("Resources");
  21. break;
  22. }
  23. #if _WIN32
  24. return bin.getChildFile("PluginScanServer.exe");
  25. #else
  26. return bin.getChildFile("PluginScanServer");
  27. #endif
  28. }
  29. #ifdef __APPLE__
  30. const juce::File DataDirectory(juce::File::getSpecialLocation(juce::File::userApplicationDataDirectory).getChildFile("WhiteElephantAudio/Syndicate"));
  31. const juce::File PluginLogDirectory(juce::File::getSpecialLocation(juce::File::userHomeDirectory).getChildFile("Library/Logs/WhiteElephantAudio/Syndicate/Syndicate"));
  32. const juce::File PluginScanServerLogDirectory(juce::File::getSpecialLocation(juce::File::userHomeDirectory).getChildFile("Library/Logs/WhiteElephantAudio/Syndicate/PluginScanServer"));
  33. #elif _WIN32
  34. const juce::File ApplicationDirectory(juce::File::getSpecialLocation(juce::File::userDocumentsDirectory).getChildFile("WhiteElephantAudio/Syndicate"));
  35. const juce::File DataDirectory(ApplicationDirectory.getChildFile("Data"));
  36. const juce::File PluginLogDirectory(ApplicationDirectory.getChildFile("Logs/Syndicate"));
  37. const juce::File PluginScanServerLogDirectory(ApplicationDirectory.getChildFile("Logs/PluginScanServer"));
  38. #elif __linux__
  39. const juce::File ApplicationDirectory(juce::File::getSpecialLocation(juce::File::userApplicationDataDirectory).getChildFile("WhiteElephantAudio/Syndicate"));
  40. const juce::File DataDirectory(ApplicationDirectory.getChildFile("Data"));
  41. const juce::File PluginLogDirectory(ApplicationDirectory.getChildFile("Logs/Syndicate"));
  42. const juce::File PluginScanServerLogDirectory(ApplicationDirectory.getChildFile("Logs/PluginScanServer"));
  43. #else
  44. #error Unsupported OS
  45. #endif
  46. struct Config {
  47. bool enableLogFile;
  48. Config() : enableLogFile(false) { }
  49. };
  50. inline Config LoadConfig() {
  51. Config config;
  52. juce::File configFile(DataDirectory.getChildFile(CONFIG_FILE_NAME));
  53. if (!configFile.exists()) {
  54. return config;
  55. }
  56. juce::FileInputStream input(configFile);
  57. if (!input.openedOk()) {
  58. return config;
  59. }
  60. const juce::var json = juce::JSON::parse(input.readEntireStreamAsString());
  61. if (!json.isObject()) {
  62. return config;
  63. }
  64. if (json.hasProperty("enableLogFile")) {
  65. const juce::var& enableLogFile = json["enableLogFile"];
  66. if (enableLogFile.isBool()) {
  67. config.enableLogFile = enableLogFile;
  68. }
  69. }
  70. return config;
  71. }
  72. }