-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.cpp
27 lines (23 loc) · 820 Bytes
/
utils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#ifdef __APPLE__
#include "CoreFoundation/CoreFoundation.h"
#endif
#include "utils.h"
std::string GetProperPath(std::string filename) {
// This makes relative paths work in C++ in Xcode by changing directory to the Resources folder inside the .app bundle
#ifdef __APPLE__
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
char path[PATH_MAX];
if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX))
{
return "";
}
CFRelease(resourcesURL);
std::string cwd(path);
cwd = cwd.substr(0, cwd.find_last_of('/'));
cwd = cwd.substr(0, cwd.find_last_of('/'));
cwd = cwd.substr(0, cwd.find_last_of('/'));
filename = cwd + "/" + filename;
#endif
return filename;
}