]> git.saurik.com Git - wxWidgets.git/commitdiff
attempt to get a 'correct' current working directory
authorStefan Csomor <csomor@advancedconcepts.ch>
Wed, 14 Jul 2004 18:04:02 +0000 (18:04 +0000)
committerStefan Csomor <csomor@advancedconcepts.ch>
Wed, 14 Jul 2004 18:04:02 +0000 (18:04 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@28234 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/mac/carbon/app.cpp

index e28fe3d9139aa7bba7045f95aa0e7b332baa1e2b..037fa35994415d91e4375eb889311a1b25f3235e 100644 (file)
@@ -630,6 +630,26 @@ bool wxApp::Initialize(int& argc, wxChar **argv)
     wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());
 #endif
 
+#if TARGET_API_MAC_OSX
+    // these might be the startup dirs, set them to the 'usual' dir containing the app bundle
+    wxString startupCwd = wxGetCwd() ;
+    if ( startupCwd == "/" || startupCwd.Right(15) == "/Contents/MacOS" )
+    {
+        wxString cwd ;
+        CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle() ) ;
+        CFURLRef urlParent = CFURLCreateCopyDeletingLastPathComponent( kCFAllocatorDefault , url ) ;
+        CFRelease( url ) ;
+        CFStringRef path = CFURLCopyFileSystemPath ( urlParent , kCFURLPOSIXPathStyle ) ;
+        CFRelease( urlParent ) ;
+        CFIndex len = CFStringGetLength( path )  ;
+        CFIndex max = CFStringGetMaximumSizeForEncoding( len, kCFStringEncodingUTF8 ) ;
+        wxChar* buf = cwd.GetWriteBuf( max ) ;
+        CFStringGetCString( path , buf , max + 1 , kCFStringEncodingUTF8 ) ;
+        CFRelease( path ) ;
+        cwd.UngetWriteBuf() ;
+        wxSetWorkingDirectory( cwd ) ;
+    }
+#endif
 
     wxMacCreateNotifierTable() ;