1 #if defined(__APPLE__) || defined(SC_IPHONE)
5 #include <cstring> // for strncpy
6 #include <mach-o/dyld.h> // for _NSGetExecutablePath
10 #include <CoreFoundation/CFString.h>
11 #include <CoreFoundation/CFBundle.h>
12 //#include <CoreServices/CoreServices.h>
14 #include "SC_StandAloneInfo_Darwin.h"
16 bool SC_StandAloneInfo::haveCheckedBundleStatus
;
17 char SC_StandAloneInfo::dirPath
[PATH_MAX
];
19 void SC_StandAloneInfo::SC_StandAloneInfoInit() {
20 char relDir
[PATH_MAX
];
21 CFStringEncoding encoding
= kCFStringEncodingASCII
;
22 if(!haveCheckedBundleStatus
) {
23 haveCheckedBundleStatus
= true;
24 CFURLRef enablerURL
= CFBundleCopyResourceURL (
25 CFBundleGetMainBundle(),
26 CFSTR("SCClassLibrary"),
31 // If sclang or SuperCollider binary is run within the .app bundle,
32 // this is how we find the Resources path.
33 CFStringRef rawPath
= CFURLCopyFileSystemPath(enablerURL
, kCFURLPOSIXPathStyle
);
34 rawPath
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("%@/.."), rawPath
);
35 CFStringGetCString(rawPath
, relDir
, PATH_MAX
, encoding
);
37 // when sclang is run from a symlink, the resource URL above will not be found,
38 // so we need to find the path of the executable.
41 if(_NSGetExecutablePath(relDir
, bufsize
)==0) {
42 realpath(relDir
, dirPath
); // resolve symlink
43 char *dir
= dirname(dirPath
);
47 // in case it failed, fall back to current directory
48 getcwd(dirPath
, PATH_MAX
);
51 realpath(relDir
, dirPath
);
55 bool SC_StandAloneInfo::IsStandAlone() {
63 void SC_StandAloneInfo::GetResourceDir(char* pathBuf
, int length
)
65 if ( !haveCheckedBundleStatus
)
67 SC_StandAloneInfoInit();
69 strncpy(pathBuf
, dirPath
, length
);