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.

117 lines
3.0KB

  1. #include "global_pre.hpp"
  2. #include "asset.hpp"
  3. #include "util/common.hpp"
  4. #include "osdialog.h"
  5. #include "global.hpp"
  6. #if ARCH_MAC
  7. #include <CoreFoundation/CoreFoundation.h>
  8. #include <pwd.h>
  9. #endif
  10. #if ARCH_WIN
  11. #include <Windows.h>
  12. #include <Shlobj.h>
  13. #include <Shlwapi.h>
  14. #endif
  15. #if ARCH_LIN
  16. #include <unistd.h>
  17. #include <sys/types.h>
  18. #include <pwd.h>
  19. #endif
  20. namespace rack {
  21. void assetInit(bool devMode) {
  22. if (devMode) {
  23. // Use current working directory if running in development mode
  24. global->asset.globalDir = ".";
  25. global->asset.localDir = ".";
  26. return;
  27. }
  28. #if ARCH_MAC
  29. CFBundleRef bundle = CFBundleGetMainBundle();
  30. assert(bundle);
  31. CFURLRef resourcesUrl = CFBundleCopyResourcesDirectoryURL(bundle);
  32. char resourcesBuf[PATH_MAX];
  33. Boolean success = CFURLGetFileSystemRepresentation(resourcesUrl, TRUE, (UInt8*) resourcesBuf, sizeof(resourcesBuf));
  34. assert(success);
  35. CFRelease(resourcesUrl);
  36. global->asset.globalDir = resourcesBuf;
  37. // Get home directory
  38. struct passwd *pw = getpwuid(getuid());
  39. assert(pw);
  40. global->asset.localDir = pw->pw_dir;
  41. global->asset.localDir += "/Documents/Rack";
  42. #endif
  43. #if ARCH_WIN
  44. #ifndef USE_VST2
  45. char moduleBuf[MAX_PATH];
  46. DWORD length = GetModuleFileName(NULL, moduleBuf, sizeof(moduleBuf));
  47. assert(length > 0);
  48. PathRemoveFileSpec(moduleBuf);
  49. global->asset.globalDir = moduleBuf;
  50. // Get "My Documents" folder
  51. char documentsBuf[MAX_PATH];
  52. HRESULT result = SHGetFolderPath(NULL, CSIDL_MYDOCUMENTS, NULL, SHGFP_TYPE_CURRENT, documentsBuf);
  53. assert(result == S_OK);
  54. global->asset.localDir = documentsBuf;
  55. global->asset.localDir += "/Rack";
  56. #else
  57. global->asset.globalDir = global->vst2.program_dir;
  58. global->asset.localDir = global->vst2.program_dir;
  59. #endif // USE_VST2
  60. #endif
  61. #if ARCH_LIN
  62. // TODO For now, users should launch Rack from their terminal in the global directory
  63. global->asset.globalDir = ".";
  64. // Get home directory
  65. const char *homeBuf = getenv("HOME");
  66. if (!homeBuf) {
  67. struct passwd *pw = getpwuid(getuid());
  68. assert(pw);
  69. homeBuf = pw->pw_dir;
  70. }
  71. global->asset.localDir = homeBuf;
  72. global->asset.localDir += "/.Rack";
  73. #endif
  74. systemCreateDirectory(global->asset.localDir);
  75. }
  76. std::string assetGlobal(std::string filename) {
  77. return global->asset.globalDir + "/" + filename;
  78. }
  79. std::string assetLocal(std::string filename) {
  80. return global->asset.localDir + "/" + filename;
  81. }
  82. std::string assetPlugin(Plugin *plugin, std::string filename) {
  83. printf("xxx assetPlugin(plugin=%p)\n");
  84. printf("xxx assetPlugin: filename=\"%s\"\n", filename.c_str());
  85. assert(plugin);
  86. return plugin->path + "/" + filename;
  87. }
  88. #ifdef USE_VST2
  89. std::string assetStaticPlugin(const char *name/*e.g. "Fundamentals"*/, const char *_relPathOrNull) {
  90. return global->asset.localDir + "plugins/" + name + "/" + ((NULL != _relPathOrNull)?_relPathOrNull:"");
  91. }
  92. std::string assetPlugin(const char *name/*e.g. "Fundamentals"*/, const char *_relPathOrNull) {
  93. return assetStaticPlugin(name, _relPathOrNull);
  94. }
  95. #endif // USE_VST2
  96. } // namespace rack