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.

77 lines
1.5KB

  1. #include "asset.hpp"
  2. #include <assert.h>
  3. #include <sys/stat.h> // for mkdir
  4. #if ARCH_MAC
  5. #include <CoreFoundation/CoreFoundation.h>
  6. #include <pwd.h>
  7. #endif
  8. namespace rack {
  9. std::string assetGlobal(std::string filename) {
  10. std::string path;
  11. #if ARCH_MAC
  12. CFBundleRef bundle = CFBundleGetMainBundle();
  13. if (bundle) {
  14. CFURLRef resourcesUrl = CFBundleCopyResourcesDirectoryURL(bundle);
  15. char buf[PATH_MAX];
  16. Boolean success = CFURLGetFileSystemRepresentation(resourcesUrl, TRUE, (UInt8 *)buf, sizeof(buf));
  17. assert(success);
  18. CFRelease(resourcesUrl);
  19. path = buf;
  20. }
  21. else {
  22. path = ".";
  23. }
  24. path += "/" + filename;
  25. #endif
  26. #if ARCH_WIN
  27. path = "./" + filename;
  28. #endif
  29. #if ARCH_LIN
  30. path = "./" + filename;
  31. #endif
  32. return path;
  33. }
  34. std::string assetLocal(std::string filename) {
  35. std::string path;
  36. #if ARCH_MAC
  37. // TODO Need some way to determine whether it's running from an app bundle
  38. if (1) {
  39. // Get home directory
  40. struct passwd *pw = getpwuid(getuid());
  41. assert(pw);
  42. path = pw->pw_dir;
  43. path += "/Documents/Rack";
  44. mkdir(path.c_str(), 0755);
  45. }
  46. else {
  47. path = ".";
  48. }
  49. path += "/" + filename;
  50. #endif
  51. #if ARCH_WIN
  52. // TODO
  53. #endif
  54. #if ARCH_LIN
  55. // TODO
  56. // If Rack is "installed" (however that may be defined), look in ~/.Rack or something instead
  57. path = "./" + filename;
  58. #endif
  59. return path;
  60. }
  61. std::string assetPlugin(Plugin *plugin, std::string filename) {
  62. assert(plugin);
  63. std::string path;
  64. path = plugin->path + "/" + filename;
  65. return path;
  66. }
  67. } // namespace rack