summaryrefslogtreecommitdiff
path: root/src/porting.cpp
diff options
context:
space:
mode:
authorPavel Puchkin <i@neoascetic.me>2015-03-10 19:29:13 +0200
committerLoic Blot <loic.blot@unix-experience.fr>2015-03-17 15:37:23 +0100
commitca5df44edb1963d4c634390d33229ec928e284dc (patch)
tree9cebdc66e6a1da7cc79bf7a3f0ed5e5581d4fa63 /src/porting.cpp
parent768596927458d4d1d4ae7914526311471d242555 (diff)
downloadminetest-ca5df44edb1963d4c634390d33229ec928e284dc.tar.gz
minetest-ca5df44edb1963d4c634390d33229ec928e284dc.tar.bz2
minetest-ca5df44edb1963d4c634390d33229ec928e284dc.zip
Standalone bundle for OSX (w/ dependencies!)
Diffstat (limited to 'src/porting.cpp')
-rw-r--r--src/porting.cpp37
1 files changed, 14 insertions, 23 deletions
diff --git a/src/porting.cpp b/src/porting.cpp
index 64a51c7f5..710446363 100644
--- a/src/porting.cpp
+++ b/src/porting.cpp
@@ -387,16 +387,16 @@ void initializePaths()
*/
#elif defined(__APPLE__)
- //https://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/dyld.3.html
- //TODO: Test this code
- char buf[BUFSIZ];
- uint32_t len = sizeof(buf);
- FATAL_ERROR_IF(_NSGetExecutablePath(buf, &len) == -1, "");
-
- pathRemoveFile(buf, '/');
-
- path_share = std::string(buf) + "/..";
- path_user = std::string(buf) + "/..";
+ CFBundleRef main_bundle = CFBundleGetMainBundle();
+ CFURLRef resources_url = CFBundleCopyResourcesDirectoryURL(main_bundle);
+ char path[PATH_MAX];
+ if (CFURLGetFileSystemRepresentation(resources_url, TRUE, (UInt8 *)path, PATH_MAX)) {
+ path_share = std::string(path);
+ path_user = std::string(path) + "/../User";
+ } else {
+ dstream << "WARNING: Could not determine bundle resource path" << std::endl;
+ }
+ CFRelease(resources_url);
/*
FreeBSD
@@ -523,24 +523,15 @@ void initializePaths()
*/
#elif defined(__APPLE__)
- // Code based on
- // http://stackoverflow.com/questions/516200/relative-paths-not-working-in-xcode-c
CFBundleRef main_bundle = CFBundleGetMainBundle();
CFURLRef resources_url = CFBundleCopyResourcesDirectoryURL(main_bundle);
char path[PATH_MAX];
- if(CFURLGetFileSystemRepresentation(resources_url, TRUE, (UInt8 *)path, PATH_MAX))
- {
- dstream<<"Bundle resource path: "<<path<<std::endl;
- //chdir(path);
- path_share = std::string(path) + DIR_DELIM + STATIC_SHAREDIR;
- }
- else
- {
- // error!
- dstream<<"WARNING: Could not determine bundle resource path"<<std::endl;
+ if (CFURLGetFileSystemRepresentation(resources_url, TRUE, (UInt8 *)path, PATH_MAX)) {
+ path_share = std::string(path);
+ } else {
+ dstream << "WARNING: Could not determine bundle resource path" << std::endl;
}
CFRelease(resources_url);
-
path_user = std::string(getenv("HOME")) + "/Library/Application Support/" + PROJECT_NAME;
#else // FreeBSD, and probably many other POSIX-like systems.