Mercurial > mplayer.hg
diff get_path.c @ 15145:a7f11c8091e4
allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
author | nplourde |
---|---|
date | Wed, 13 Apr 2005 11:46:35 +0000 |
parents | 54ea3d6e657c |
children | 55d9619d75e5 |
line wrap: on
line diff
--- a/get_path.c Wed Apr 13 07:38:31 2005 +0000 +++ b/get_path.c Wed Apr 13 11:46:35 2005 +0000 @@ -8,6 +8,16 @@ * by the caller. * */ +#ifdef MACOSX_BUNDLE +#include <Carbon/Carbon.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#endif + char *get_path(char *filename){ char *homedir; char *buff; @@ -17,6 +27,9 @@ static char *config_dir = "/.mplayer"; #endif int len; +#ifdef MACOSX_BUNDLE + struct stat dummy; +#endif if ((homedir = getenv("HOME")) == NULL) #if defined(__MINGW32__)||defined(__CYGWIN__) /*hack to get fonts etc. loaded outside of cygwin environment*/ @@ -42,6 +55,38 @@ return NULL; sprintf(buff, "%s%s/%s", homedir, config_dir, filename); } + +#ifdef MACOSX_BUNDLE + if(stat(buff, &dummy)) { + CFIndex maxlen=64; + CFURLRef resources=NULL; + + free(buff); + buff=NULL; + + resources=CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle()); + if(resources) { + + buff=malloc(maxlen); + *buff=0; + + while(!CFURLGetFileSystemRepresentation(resources, true, buff, maxlen)) { + maxlen*=2; + buff=realloc(buff, maxlen); + } + CFRelease(resources); + } + + if(buff&&filename) { + if((strlen(filename)+strlen(buff)+2)>maxlen) { + maxlen=strlen(filename)+strlen(buff)+2; + buff=realloc(buff, maxlen); + } + strcat(buff,"/"); + strcat(buff, filename); + } + } +#endif mp_msg(MSGT_GLOBAL,MSGL_V,"get_path('%s') -> '%s'\n",filename,buff); return buff; }