1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2010 Robert TIMM (rti) <mail@rtti.de>
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/>.
21 #include "app_bundle_utils.h"
24 #include <CoreFoundation/CoreFoundation.h>
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)
40 CFBundleRef bundle
= CFBundleGetMainBundle();
44 // get the url to the bundles root
45 CFURLRef url
= CFBundleCopyBundleURL(bundle
);
49 // get the file system path
51 str
= CFURLCopyFileSystemPath(CFURLCopyAbsoluteURL(url
), kCFURLPOSIXPathStyle
);
56 s_cachedPathToBundle
= CFStringGetCStringPtr(str
, CFStringGetSmallestEncoding(str
));
61 nlerror("CFStringGetCStringPtr");
66 nlerror("CFBundleCopyBundleURL");
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
;