Browse Source

Cleanup of Mac asset management

tags/v0.4.0
Andrew Belt 7 years ago
parent
commit
ecfaa878b2
1 changed files with 25 additions and 16 deletions
  1. +25
    -16
      src/asset.cpp

+ 25
- 16
src/asset.cpp View File

@@ -15,14 +15,18 @@ std::string assetGlobal(std::string filename) {
std::string path;
#if ARCH_MAC
CFBundleRef bundle = CFBundleGetMainBundle();
CFURLRef resourcesUrl = CFBundleCopyResourcesDirectoryURL(bundle);
char buf[PATH_MAX];
Boolean success = CFURLGetFileSystemRepresentation(resourcesUrl, TRUE, (UInt8 *)buf, sizeof(buf));
assert(success);
CFRelease(resourcesUrl);
path = buf;
path += "/";
path += filename;
if (bundle) {
CFURLRef resourcesUrl = CFBundleCopyResourcesDirectoryURL(bundle);
char buf[PATH_MAX];
Boolean success = CFURLGetFileSystemRepresentation(resourcesUrl, TRUE, (UInt8 *)buf, sizeof(buf));
assert(success);
CFRelease(resourcesUrl);
path = buf;
}
else {
path = ".";
}
path += "/" + filename;
#endif
#if ARCH_WIN
path = "./" + filename;
@@ -36,14 +40,19 @@ std::string assetGlobal(std::string filename) {
std::string assetLocal(std::string filename) {
std::string path;
#if ARCH_MAC
// Get home directory
struct passwd *pw = getpwuid(getuid());
assert(pw);
path = pw->pw_dir;
path += "/Documents/Rack";
mkdir(path.c_str(), 0755);
path += "/";
path += filename;
// TODO Need some way to determine whether it's running from an app bundle
if (1) {
// Get home directory
struct passwd *pw = getpwuid(getuid());
assert(pw);
path = pw->pw_dir;
path += "/Documents/Rack";
mkdir(path.c_str(), 0755);
}
else {
path = ".";
}
path += "/" + filename;
#endif
#if ARCH_WIN
// TODO


Loading…
Cancel
Save