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 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #include "wx/wxprec.h"
26 #endif //ndef WX_PRECOMP
28 #include "wx/stdpaths.h"
29 #include "wx/filename.h"
30 #include "wx/mac/corefoundation/cfstring.h"
32 #if defined(__DARWIN__)
33 #include <CoreFoundation/CFBundle.h>
34 #include <CoreFoundation/CFURL.h>
40 #if defined(__WXCOCOA__) || defined(__WXMAC_OSX__)
41 #define kDefaultPathStyle kCFURLPOSIXPathStyle
43 #define kDefaultPathStyle kCFURLHFSPathStyle
46 // ============================================================================
48 // ============================================================================
50 // ----------------------------------------------------------------------------
51 // wxStandardPathsCF ctors/dtor
52 // ----------------------------------------------------------------------------
54 wxStandardPathsCF::wxStandardPathsCF()
55 : m_bundle(CFBundleGetMainBundle())
60 wxStandardPathsCF::wxStandardPathsCF(wxCFBundleRef bundle
)
66 wxStandardPathsCF::~wxStandardPathsCF()
71 // ----------------------------------------------------------------------------
72 // wxStandardPathsCF Mac-specific methods
73 // ----------------------------------------------------------------------------
75 void wxStandardPathsCF::SetBundle(wxCFBundleRef bundle
)
82 // ----------------------------------------------------------------------------
83 // generic functions in terms of which the other ones are implemented
84 // ----------------------------------------------------------------------------
86 static wxString
BundleRelativeURLToPath(CFURLRef relativeURL
)
88 CFURLRef absoluteURL
= CFURLCopyAbsoluteURL(relativeURL
);
89 wxCHECK_MSG(absoluteURL
, wxEmptyString
, wxT("Failed to resolve relative URL to absolute URL"));
90 CFStringRef cfStrPath
= CFURLCopyFileSystemPath(absoluteURL
,kDefaultPathStyle
);
91 CFRelease(absoluteURL
);
92 return wxMacCFStringHolder(cfStrPath
).AsString(wxLocale::GetSystemEncoding());
95 wxString
wxStandardPathsCF::GetFromFunc(wxCFURLRef (*func
)(wxCFBundleRef
)) const
97 wxCHECK_MSG(m_bundle
, wxEmptyString
,
98 wxT("wxStandardPaths for CoreFoundation only works with bundled apps"));
99 CFURLRef relativeURL
= (*func
)(m_bundle
);
100 wxCHECK_MSG(relativeURL
, wxEmptyString
, wxT("Couldn't get URL"));
101 wxString
ret(BundleRelativeURLToPath(relativeURL
));
102 CFRelease(relativeURL
);
106 // ----------------------------------------------------------------------------
107 // wxStandardPathsCF public API
108 // ----------------------------------------------------------------------------
110 wxString
wxStandardPathsCF::GetConfigDir() const
112 // TODO: What do we do for pure Carbon?
113 return wxT("/Library/Preferences");
116 wxString
wxStandardPathsCF::GetUserConfigDir() const
118 // TODO: What do we do for pure Carbon?
119 return wxFileName::GetHomeDir() + wxT("/Library/Preferences");
122 wxString
wxStandardPathsCF::GetDataDir() const
124 return GetFromFunc(CFBundleCopySharedSupportURL
);
127 wxString
wxStandardPathsCF::GetLocalDataDir() const
129 return AppendAppName(wxT("/Library/Application Support"));
132 wxString
wxStandardPathsCF::GetUserDataDir() const
134 return AppendAppName(wxFileName::GetHomeDir() + _T("/Library/Application Support"));
137 wxString
wxStandardPathsCF::GetPluginsDir() const
139 return GetFromFunc(CFBundleCopyBuiltInPlugInsURL
);
142 wxString
wxStandardPathsCF::GetResourcesDir() const
144 return GetFromFunc(CFBundleCopyResourcesDirectoryURL
);
148 wxStandardPathsCF::GetLocalizedResourcesDir(const wxChar
*lang
,
149 ResourceCat category
) const
151 return wxStandardPathsBase::
152 GetLocalizedResourcesDir(lang
, category
) + _T(".lproj");
155 #endif // wxUSE_STDPATHS