Fix classique titles display
[ryzomcore.git] / ryzom / client / src / app_bundle_utils.cpp
blob122ad187ec93166e641057be7eac3e043b161261
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2010 Robert TIMM (rti) <mail@rtti.de>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "stdpch.h"
21 #include "app_bundle_utils.h"
23 #ifdef NL_OS_MAC
24 #include <CoreFoundation/CoreFoundation.h>
25 #endif
27 #ifdef DEBUG_NEW
28 #define new DEBUG_NEW
29 #endif
31 std::string getAppBundlePath()
33 static std::string s_cachedPathToBundle;
35 if (!s_cachedPathToBundle.empty())
36 return s_cachedPathToBundle;
38 #if defined(NL_OS_MAC)
39 // get the bundle
40 CFBundleRef bundle = CFBundleGetMainBundle();
42 if (bundle)
44 // get the url to the bundles root
45 CFURLRef url = CFBundleCopyBundleURL(bundle);
47 if (url)
49 // get the file system path
50 CFStringRef str;
51 str = CFURLCopyFileSystemPath(CFURLCopyAbsoluteURL(url), kCFURLPOSIXPathStyle);
52 CFRelease(url);
54 if (str)
56 s_cachedPathToBundle = CFStringGetCStringPtr(str, CFStringGetSmallestEncoding(str));
57 CFRelease(str);
59 else
61 nlerror("CFStringGetCStringPtr");
64 else
66 nlerror("CFBundleCopyBundleURL");
69 else
71 nlerror("CFBundleGetMainBundle");
73 #elif defined(NL_OS_WINDOWS)
74 char buffer[MAX_PATH+1];
75 if (GetModuleFileNameA(NULL, buffer, MAX_PATH))
76 s_cachedPathToBundle = NLMISC::CPath::standardizePath(NLMISC::CFile::getPath(buffer), false);
77 #endif // defined(NL_OS_MAC)
79 return s_cachedPathToBundle;