1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: mac/corefoundation/stdpaths.cpp
3 // Purpose: wxStandardPaths implementation for CoreFoundation systems
4 // Author: David Elliott
8 // Copyright: (c) 2004 David Elliott <dfe@cox.net>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
15 #endif //ndef WX_PRECOMP
17 #include "wx/stdpaths.h"
18 #include "wx/filename.h"
19 #include "wx/mac/corefoundation/cfstring.h"
21 #if defined(__DARWIN__)
22 #include <CoreFoundation/CFBundle.h>
23 #include <CoreFoundation/CFURL.h>
29 // See comment in include/wx/mac/corefoundation/stdpaths.h
30 #ifndef wxStandardPaths
31 #warning "wxStandardPaths should be defined to wxStandardPathsCF when compiling this file."
34 #if defined(__WXCOCOA__) || defined(__WXMAC_OSX__)
35 #define kDefaultPathStyle kCFURLPOSIXPathStyle
37 #define kDefaultPathStyle kCFURLHFSPathStyle
40 static wxString
BundleRelativeURLToPath(CFURLRef relativeURL
)
42 CFURLRef absoluteURL
= CFURLCopyAbsoluteURL(relativeURL
);
43 wxCHECK_MSG(absoluteURL
, wxEmptyString
, wxT("Failed to resolve relative URL to absolute URL"));
44 CFStringRef cfStrPath
= CFURLCopyFileSystemPath(absoluteURL
,kDefaultPathStyle
);
45 CFRelease(absoluteURL
);
46 return wxMacCFStringHolder(cfStrPath
).AsString(wxLocale::GetSystemEncoding());
50 static wxStandardPaths gs_stdPaths
;
51 /* static */ wxStandardPaths
& wxStandardPaths::Get()
56 wxStandardPaths::wxStandardPaths()
57 : m_bundle(CFBundleGetMainBundle())
62 wxStandardPaths::wxStandardPaths(struct __CFBundle
*bundle
)
68 wxStandardPaths::~wxStandardPaths()
73 void wxStandardPaths::SetBundle(struct __CFBundle
*bundle
)
80 wxString
wxStandardPaths::GetConfigDir() const
82 // TODO: What do we do for pure Carbon?
83 return wxT("/Library/Preferences");
86 wxString
wxStandardPaths::GetUserConfigDir() const
88 // TODO: What do we do for pure Carbon?
89 return wxFileName::GetHomeDir() + wxT("/Library/Preferences");
92 wxString
wxStandardPaths::GetDataDir() const
94 wxCHECK_MSG(m_bundle
, wxEmptyString
, wxT("wxStandardPaths for CoreFoundation only works with bundled apps"));
95 CFURLRef relativeURL
= CFBundleCopySharedSupportURL(m_bundle
);
96 wxCHECK_MSG(relativeURL
, wxEmptyString
, wxT("Couldn't get SharedSupport URL"));
97 wxString
ret(BundleRelativeURLToPath(relativeURL
));
98 CFRelease(relativeURL
);
102 wxString
wxStandardPaths::GetLocalDataDir() const
104 return AppendAppName(wxT("/Library/Application Support"));
107 wxString
wxStandardPaths::GetUserDataDir() const
109 return AppendAppName(wxFileName::GetHomeDir() + _T("/Library/Application Support"));
112 wxString
wxStandardPaths::GetPluginsDir() const
114 wxCHECK_MSG(m_bundle
, wxEmptyString
, wxT("wxStandardPaths for CoreFoundation only works with bundled apps"));
115 CFURLRef relativeURL
= CFBundleCopyBuiltInPlugInsURL(m_bundle
);
116 wxCHECK_MSG(relativeURL
, wxEmptyString
, wxT("Couldn't get BuiltInPlugIns URL"));
117 wxString
ret(BundleRelativeURLToPath(relativeURL
));
118 CFRelease(relativeURL
);