Fixed basedir calculation on Mac OS X.
This commit is contained in:
parent
49a8ff3f86
commit
f94d227945
|
@ -16,6 +16,7 @@
|
||||||
#include <IOKit/storage/IOCDMedia.h>
|
#include <IOKit/storage/IOCDMedia.h>
|
||||||
#include <IOKit/storage/IODVDMedia.h>
|
#include <IOKit/storage/IODVDMedia.h>
|
||||||
#include <sys/mount.h>
|
#include <sys/mount.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
/* Seems to get defined in some system header... */
|
/* Seems to get defined in some system header... */
|
||||||
#ifdef Free
|
#ifdef Free
|
||||||
|
@ -219,12 +220,15 @@ static char *convertCFString(CFStringRef cfstr)
|
||||||
char *__PHYSFS_platformCalcBaseDir(const char *argv0)
|
char *__PHYSFS_platformCalcBaseDir(const char *argv0)
|
||||||
{
|
{
|
||||||
ProcessSerialNumber psn = { 0, kCurrentProcess };
|
ProcessSerialNumber psn = { 0, kCurrentProcess };
|
||||||
|
struct stat statbuf;
|
||||||
FSRef fsref;
|
FSRef fsref;
|
||||||
CFRange cfrange;
|
CFRange cfrange;
|
||||||
CFURLRef cfurl = NULL;
|
CFURLRef cfurl = NULL;
|
||||||
CFStringRef cfstr = NULL;
|
CFStringRef cfstr = NULL;
|
||||||
CFMutableStringRef cfmutstr = NULL;
|
CFMutableStringRef cfmutstr = NULL;
|
||||||
char *retval = NULL;
|
char *retval = NULL;
|
||||||
|
char *cstr = NULL;
|
||||||
|
int rc = 0;
|
||||||
|
|
||||||
BAIL_IF_MACRO(GetProcessBundleLocation(&psn, &fsref) != noErr, NULL, NULL);
|
BAIL_IF_MACRO(GetProcessBundleLocation(&psn, &fsref) != noErr, NULL, NULL);
|
||||||
cfurl = CFURLCreateFromFSRef(cfallocator, &fsref);
|
cfurl = CFURLCreateFromFSRef(cfallocator, &fsref);
|
||||||
|
@ -236,27 +240,46 @@ char *__PHYSFS_platformCalcBaseDir(const char *argv0)
|
||||||
CFRelease(cfstr);
|
CFRelease(cfstr);
|
||||||
BAIL_IF_MACRO(cfmutstr == NULL, NULL, NULL);
|
BAIL_IF_MACRO(cfmutstr == NULL, NULL, NULL);
|
||||||
|
|
||||||
/* Find last dirsep so we can chop the binary's filename from the path. */
|
/* we have to decide if we got a binary's path, or the .app dir... */
|
||||||
cfrange = CFStringFind(cfmutstr, CFSTR("/"), kCFCompareBackwards);
|
cstr = convertCFString(cfmutstr);
|
||||||
if (cfrange.location == kCFNotFound)
|
if (cstr == NULL)
|
||||||
{
|
{
|
||||||
assert(0); /* shouldn't ever hit this... */
|
|
||||||
CFRelease(cfmutstr);
|
CFRelease(cfmutstr);
|
||||||
return NULL;
|
return NULL;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
/* chop the "/exename" from the end of the path string... */
|
rc = stat(cstr, &statbuf);
|
||||||
cfrange.length = CFStringGetLength(cfmutstr) - cfrange.location;
|
allocator.Free(cstr); /* done with this. */
|
||||||
CFStringDelete(cfmutstr, cfrange);
|
if (rc == -1)
|
||||||
|
{
|
||||||
|
CFRelease(cfmutstr);
|
||||||
|
return NULL; /* maybe default behaviour will work? */
|
||||||
|
} /* if */
|
||||||
|
|
||||||
/* If we're an Application Bundle, chop everything but the base. */
|
if (S_ISREG(statbuf.st_mode))
|
||||||
cfrange = CFStringFind(cfmutstr, CFSTR("/Contents/MacOS"),
|
{
|
||||||
kCFCompareCaseInsensitive |
|
/* Find last dirsep so we can chop the filename from the path. */
|
||||||
kCFCompareBackwards |
|
cfrange = CFStringFind(cfmutstr, CFSTR("/"), kCFCompareBackwards);
|
||||||
kCFCompareAnchored);
|
if (cfrange.location == kCFNotFound)
|
||||||
|
{
|
||||||
|
assert(0); /* shouldn't ever hit this... */
|
||||||
|
CFRelease(cfmutstr);
|
||||||
|
return NULL;
|
||||||
|
} /* if */
|
||||||
|
|
||||||
if (cfrange.location != kCFNotFound)
|
/* chop the "/exename" from the end of the path string... */
|
||||||
CFStringDelete(cfmutstr, cfrange); /* chop that, too. */
|
cfrange.length = CFStringGetLength(cfmutstr) - cfrange.location;
|
||||||
|
CFStringDelete(cfmutstr, cfrange);
|
||||||
|
|
||||||
|
/* If we're an Application Bundle, chop everything but the base. */
|
||||||
|
cfrange = CFStringFind(cfmutstr, CFSTR("/Contents/MacOS"),
|
||||||
|
kCFCompareCaseInsensitive |
|
||||||
|
kCFCompareBackwards |
|
||||||
|
kCFCompareAnchored);
|
||||||
|
|
||||||
|
if (cfrange.location != kCFNotFound)
|
||||||
|
CFStringDelete(cfmutstr, cfrange); /* chop that, too. */
|
||||||
|
} /* if */
|
||||||
|
|
||||||
retval = convertCFString(cfmutstr);
|
retval = convertCFString(cfmutstr);
|
||||||
CFRelease(cfmutstr);
|
CFRelease(cfmutstr);
|
||||||
|
|
Loading…
Reference in New Issue