Changed: Minor changes
This commit is contained in:
parent
6ea1a24dad
commit
bbaa223662
1 changed files with 17 additions and 13 deletions
|
@ -17,53 +17,57 @@
|
||||||
#include "stdpch.h"
|
#include "stdpch.h"
|
||||||
#include "app_bundle_utils.h"
|
#include "app_bundle_utils.h"
|
||||||
|
|
||||||
#if defined(NL_OS_MAC)
|
#ifdef NL_OS_MAC
|
||||||
#include <CoreFoundation/CoreFoundation.h>
|
#include <CoreFoundation/CoreFoundation.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::string getAppBundlePath()
|
std::string getAppBundlePath()
|
||||||
{
|
{
|
||||||
static std::string cachedPathToBundle;
|
static std::string s_cachedPathToBundle;
|
||||||
|
|
||||||
if(cachedPathToBundle.size())
|
if (!s_cachedPathToBundle.empty())
|
||||||
return cachedPathToBundle;
|
return s_cachedPathToBundle;
|
||||||
|
|
||||||
#if defined(NL_OS_MAC)
|
#if defined(NL_OS_MAC)
|
||||||
// get the bundle
|
// get the bundle
|
||||||
CFBundleRef bundle = CFBundleGetMainBundle();
|
CFBundleRef bundle = CFBundleGetMainBundle();
|
||||||
|
|
||||||
if(bundle)
|
if (bundle)
|
||||||
{
|
{
|
||||||
// get the url to the bundles root
|
// get the url to the bundles root
|
||||||
CFURLRef url = CFBundleCopyBundleURL(bundle);
|
CFURLRef url = CFBundleCopyBundleURL(bundle);
|
||||||
|
|
||||||
if(url)
|
if (url)
|
||||||
{
|
{
|
||||||
// get the file system path
|
// get the file system path
|
||||||
CFStringRef str;
|
CFStringRef str;
|
||||||
str = CFURLCopyFileSystemPath(
|
str = CFURLCopyFileSystemPath(CFURLCopyAbsoluteURL(url), kCFURLPOSIXPathStyle);
|
||||||
CFURLCopyAbsoluteURL(url), kCFURLPOSIXPathStyle);
|
|
||||||
CFRelease(url);
|
CFRelease(url);
|
||||||
|
|
||||||
if(str)
|
if (str)
|
||||||
{
|
{
|
||||||
cachedPathToBundle = CFStringGetCStringPtr(
|
s_cachedPathToBundle = CFStringGetCStringPtr(str, CFStringGetSmallestEncoding(str));
|
||||||
str, CFStringGetSmallestEncoding(str));
|
|
||||||
CFRelease(str);
|
CFRelease(str);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
nlerror("CFStringGetCStringPtr");
|
nlerror("CFStringGetCStringPtr");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
nlerror("CFBundleCopyBundleURL");
|
nlerror("CFBundleCopyBundleURL");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
nlerror("CFBundleGetMainBundle");
|
nlerror("CFBundleGetMainBundle");
|
||||||
|
}
|
||||||
#elif defined(NL_OS_WINDOWS)
|
#elif defined(NL_OS_WINDOWS)
|
||||||
char buffer[MAX_PATH+1];
|
char buffer[MAX_PATH+1];
|
||||||
if (GetModuleFileNameA(NULL, buffer, MAX_PATH))
|
if (GetModuleFileNameA(NULL, buffer, MAX_PATH))
|
||||||
cachedPathToBundle = NLMISC::CPath::standardizePath(NLMISC::CFile::getPath(buffer), false);
|
s_cachedPathToBundle = NLMISC::CPath::standardizePath(NLMISC::CFile::getPath(buffer), false);
|
||||||
#endif // defined(NL_OS_MAC)
|
#endif // defined(NL_OS_MAC)
|
||||||
|
|
||||||
return cachedPathToBundle;
|
return s_cachedPathToBundle;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue