1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/core/stdpaths_cf.cpp
3 // Purpose: wxStandardPaths implementation for CoreFoundation systems
4 // Author: David Elliott
7 // Copyright: (c) 2004 David Elliott <dfe@cox.net>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 #include "wx/wxprec.h"
25 #endif //ndef WX_PRECOMP
27 #include "wx/stdpaths.h"
28 #include "wx/filename.h"
30 #include "wx/osx/private.h"
32 #include "wx/osx/core/cfstring.h"
34 #include <CoreFoundation/CFBundle.h>
35 #include <CoreFoundation/CFURL.h>
37 #define kDefaultPathStyle kCFURLPOSIXPathStyle
39 // ============================================================================
41 // ============================================================================
43 // ----------------------------------------------------------------------------
44 // wxStandardPathsCF ctors/dtor
45 // ----------------------------------------------------------------------------
47 wxStandardPathsCF::wxStandardPathsCF()
48 : m_bundle(CFBundleGetMainBundle())
53 wxStandardPathsCF::wxStandardPathsCF(wxCFBundleRef bundle
)
59 wxStandardPathsCF::~wxStandardPathsCF()
64 // ----------------------------------------------------------------------------
65 // wxStandardPathsCF Mac-specific methods
66 // ----------------------------------------------------------------------------
68 void wxStandardPathsCF::SetBundle(wxCFBundleRef bundle
)
75 // ----------------------------------------------------------------------------
76 // generic functions in terms of which the other ones are implemented
77 // ----------------------------------------------------------------------------
79 static wxString
BundleRelativeURLToPath(CFURLRef relativeURL
)
81 CFURLRef absoluteURL
= CFURLCopyAbsoluteURL(relativeURL
);
82 wxCHECK_MSG(absoluteURL
, wxEmptyString
, wxT("Failed to resolve relative URL to absolute URL"));
83 CFStringRef cfStrPath
= CFURLCopyFileSystemPath(absoluteURL
,kDefaultPathStyle
);
84 CFRelease(absoluteURL
);
85 return wxCFStringRef::AsStringWithNormalizationFormC(cfStrPath
);
88 wxString
wxStandardPathsCF::GetFromFunc(wxCFURLRef (*func
)(wxCFBundleRef
)) const
90 wxCHECK_MSG(m_bundle
, wxEmptyString
,
91 wxT("wxStandardPaths for CoreFoundation only works with bundled apps"));
92 CFURLRef relativeURL
= (*func
)(m_bundle
);
93 wxCHECK_MSG(relativeURL
, wxEmptyString
, wxT("Couldn't get URL"));
94 wxString
ret(BundleRelativeURLToPath(relativeURL
));
95 CFRelease(relativeURL
);
99 wxString
wxStandardPathsCF::GetDocumentsDir() const
101 #if defined( __WXMAC__ ) && wxOSX_USE_CARBON
102 return wxMacFindFolderNoSeparator
105 kDocumentsFolderType
,
109 return wxFileName::GetHomeDir() + wxT("/Documents");
113 // ----------------------------------------------------------------------------
114 // wxStandardPathsCF public API
115 // ----------------------------------------------------------------------------
117 wxString
wxStandardPathsCF::GetConfigDir() const
119 #if defined( __WXMAC__ ) && wxOSX_USE_CARBON
120 return wxMacFindFolderNoSeparator((short)kLocalDomain
, kPreferencesFolderType
, kCreateFolder
);
122 return wxT("/Library/Preferences");
126 wxString
wxStandardPathsCF::GetUserConfigDir() const
128 #if defined( __WXMAC__ ) && wxOSX_USE_CARBON
129 return wxMacFindFolderNoSeparator((short)kUserDomain
, kPreferencesFolderType
, kCreateFolder
);
131 return wxFileName::GetHomeDir() + wxT("/Library/Preferences");
135 wxString
wxStandardPathsCF::GetDataDir() const
137 return GetFromFunc(CFBundleCopySharedSupportURL
);
140 wxString
wxStandardPathsCF::GetExecutablePath() const
143 return GetFromFunc(CFBundleCopyExecutableURL
);
145 return wxStandardPathsBase::GetExecutablePath();
149 wxString
wxStandardPathsCF::GetLocalDataDir() const
151 #if defined( __WXMAC__ ) && wxOSX_USE_CARBON
152 return AppendAppInfo(wxMacFindFolderNoSeparator((short)kLocalDomain
, kApplicationSupportFolderType
, kCreateFolder
));
154 return AppendAppInfo(wxT("/Library/Application Support"));
158 wxString
wxStandardPathsCF::GetUserDataDir() const
160 #if defined( __WXMAC__ ) && wxOSX_USE_CARBON
161 return AppendAppInfo(wxMacFindFolderNoSeparator((short)kUserDomain
, kApplicationSupportFolderType
, kCreateFolder
));
163 return AppendAppInfo(wxFileName::GetHomeDir() + wxT("/Library/Application Support"));
167 wxString
wxStandardPathsCF::GetPluginsDir() const
169 return GetFromFunc(CFBundleCopyBuiltInPlugInsURL
);
172 wxString
wxStandardPathsCF::GetResourcesDir() const
174 return GetFromFunc(CFBundleCopyResourcesDirectoryURL
);
178 wxStandardPathsCF::GetLocalizedResourcesDir(const wxString
& lang
,
179 ResourceCat category
) const
181 return wxStandardPathsBase::
182 GetLocalizedResourcesDir(lang
, category
) + wxT(".lproj");
185 #endif // wxUSE_STDPATHS