Patch #1399 2006-08-25 19:57
afb
make wxMac find the resources by itself- Download
- 1399-make_wxMac_fin.patch (1.9 KB)
Index: src/src/app.cpp
===================================================================
--- src/src/app.cpp (revision 2898)
+++ src/src/app.cpp (arbetskopia)
@@ -135,6 +135,26 @@
EVT_COMPILER_FINISHED(CodeBlocksApp::OnBatchBuildDone)
END_EVENT_TABLE()
+#ifdef __WXMAC__
+#include "wx/mac/corefoundation/cfstring.h"
+#include "wx/intl.h"
+
+#include <CoreFoundation/CFBundle.h>
+#include <CoreFoundation/CFURL.h>
+
+// returns e.g. "/Applications/appname.app/Contents/Resources" if application is bundled,
+// or the directory of the binary, e.g. "/usr/local/bin/appname", if it is *not* bundled.
+static wxString GetResourcesDir()
+{
+ CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
+ CFURLRef absoluteURL = CFURLCopyAbsoluteURL(resourcesURL); // relative -> absolute
+ CFRelease(resourcesURL);
+ CFStringRef cfStrPath = CFURLCopyFileSystemPath(absoluteURL,kCFURLPOSIXPathStyle);
+ CFRelease(absoluteURL);
+ return wxMacCFStringHolder(cfStrPath).AsString(wxLocale::GetSystemEncoding());
+}
+#endif
+
bool CodeBlocksApp::LoadConfig()
{
if (ParseCmdLine(0L) != 0)
@@ -147,6 +167,8 @@
// find out about data path
#ifdef __WXMSW__
wxString data = GetAppPath(); // under windows it is under the exe dir
+#elif defined(__WXMAC__)
+ wxString data = GetResourcesDir(); // CodeBlocks.app/Contents/Resources
#else
#ifdef APP_PREFIX
wxString data = wxT(APP_PREFIX); // under linux, get the preprocessor value
@@ -155,7 +177,12 @@
#endif
#endif
wxString actualData = _T("/share/codeblocks");
+#ifdef __WXMAC__
+ if (!data.Contains(wxString(_T("/Resources"))))
+ data << _T("/..") << actualData; // not a bundle, use relative path
+#else
data << actualData;
+#endif
// check if the user has passed --prefix in the command line
if (!m_Prefix.IsEmpty())
data = m_Prefix + actualData;
History
afb 2006-08-25 20:00
This patch will make C::B look in CodeBlocks.app/Contents/Resources for a bundled application, and in $PREFIX/bin/../share/codeblocks for a non-bundled application - should avoid the application having to use --prefix anymore, so that we can get rid of that pesky shell wrapper.
Couldn't find a suitable/working function for it in wxWidgets, so I made it a small local helper function instead (but it only uses CoreFoundation)