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.

99 lines
2.0KB

  1. #include "asset.hpp"
  2. #include "util/common.hpp"
  3. #include <sys/stat.h> // for mkdir
  4. #include "osdialog.h"
  5. #if ARCH_MAC
  6. #include <CoreFoundation/CoreFoundation.h>
  7. #include <pwd.h>
  8. #endif
  9. #if ARCH_WIN
  10. #include <Windows.h>
  11. #include <Shlobj.h>
  12. #endif
  13. #if ARCH_LIN
  14. #include <unistd.h>
  15. #include <sys/types.h>
  16. #include <pwd.h>
  17. #endif
  18. namespace rack {
  19. std::string assetGlobal(std::string filename) {
  20. std::string dir;
  21. #if defined(RELEASE)
  22. #if ARCH_MAC
  23. CFBundleRef bundle = CFBundleGetMainBundle();
  24. assert(bundle);
  25. CFURLRef resourcesUrl = CFBundleCopyResourcesDirectoryURL(bundle);
  26. char buf[PATH_MAX];
  27. Boolean success = CFURLGetFileSystemRepresentation(resourcesUrl, TRUE, (UInt8 *)buf, sizeof(buf));
  28. assert(success);
  29. CFRelease(resourcesUrl);
  30. dir = buf;
  31. #endif
  32. #if ARCH_WIN
  33. // Must launch Rack with the "Start In" directory as the global directory
  34. dir = ".";
  35. #endif
  36. #if ARCH_LIN
  37. // TODO For now, users should launch Rack from their terminal in the global directory
  38. dir = ".";
  39. #endif
  40. #else // RELEASE
  41. dir = ".";
  42. #endif // RELEASE
  43. return dir + "/" + filename;
  44. }
  45. std::string assetLocal(std::string filename) {
  46. std::string dir;
  47. #if defined(RELEASE)
  48. #if ARCH_MAC
  49. // Get home directory
  50. struct passwd *pw = getpwuid(getuid());
  51. assert(pw);
  52. dir = pw->pw_dir;
  53. dir += "/Documents/Rack";
  54. mkdir(dir.c_str(), 0755);
  55. #endif
  56. #if ARCH_WIN
  57. // Get "My Documents" folder
  58. char buf[MAX_PATH];
  59. HRESULT result = SHGetFolderPath(NULL, CSIDL_MYDOCUMENTS, NULL, SHGFP_TYPE_CURRENT, buf);
  60. assert(result == S_OK);
  61. dir = buf;
  62. dir += "/Rack";
  63. CreateDirectory(dir.c_str(), NULL);
  64. #endif
  65. #if ARCH_LIN
  66. const char *home = getenv("HOME");
  67. if (!home) {
  68. struct passwd *pw = getpwuid(getuid());
  69. assert(pw);
  70. home = pw->pw_dir;
  71. }
  72. dir = home;
  73. dir += "/.Rack";
  74. mkdir(dir.c_str(), 0755);
  75. #endif
  76. #else // RELEASE
  77. dir = ".";
  78. #endif // RELEASE
  79. return dir + "/" + filename;
  80. }
  81. std::string assetPlugin(Plugin *plugin, std::string filename) {
  82. assert(plugin);
  83. return plugin->path + "/" + filename;
  84. }
  85. } // namespace rack