1 #if defined(__APPLE__) || defined(SC_IPHONE)
5 #include <cstring> // for strncpy
7 #include <CoreFoundation/CFString.h>
8 #include <CoreFoundation/CFBundle.h>
9 //#include <CoreServices/CoreServices.h>
11 #include "SC_StandAloneInfo_Darwin.h"
13 bool SC_StandAloneInfo::sIsStandAlone
;
14 bool SC_StandAloneInfo::haveCheckedBundleStatus
;
15 char SC_StandAloneInfo::dirPath
[PATH_MAX
];
17 void SC_StandAloneInfo::SC_StandAloneInfoInit() {
18 CFStringEncoding encoding
= kCFStringEncodingASCII
;
20 if ( !haveCheckedBundleStatus
)
22 haveCheckedBundleStatus
= true;
23 CFStringRef stringToFind
= CFSTR("SCClassLibrary");
24 CFURLRef enablerURL
= CFBundleCopyResourceURL (
25 CFBundleGetMainBundle(),
32 CFStringRef string2ToFind
= CFSTR(".app/");
33 CFRange findResult
= CFStringFind(CFURLGetString(enablerURL
), string2ToFind
, kCFCompareCaseInsensitive
);
34 if(findResult
.length
!= 0)
36 // You'd think we could get an absolute path to the Resources directory. But
37 // we can't, we can only get a relative path, or an absolute path to a
38 // specific resource. Since we don't know the application name, we get the
39 // latter, and then hack off the resource name.
42 CFStringRef rawPath
= CFURLCopyFileSystemPath(enablerURL
, kCFURLPOSIXPathStyle
);
44 CFRange discardRange
= CFStringFind (
45 CFURLCopyFileSystemPath(enablerURL
, kCFURLPOSIXPathStyle
),
51 validRange
.location
= 0;
52 validRange
.length
= discardRange
.location
- 1;
54 CFStringRef dirPathCFString
= CFStringCreateWithSubstring (
68 getcwd(dirPath
, PATH_MAX
);
73 getcwd(dirPath
, PATH_MAX
);
78 bool SC_StandAloneInfo::IsStandAlone() {
79 if ( !haveCheckedBundleStatus
)
81 SC_StandAloneInfoInit();
86 void SC_StandAloneInfo::GetResourceDir(char* pathBuf
, int length
)
88 if ( !haveCheckedBundleStatus
)
90 SC_StandAloneInfoInit();
92 strncpy(pathBuf
, dirPath
, length
);