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"
31 #include "wx/mac/private.h"
33 #include "wx/mac/corefoundation/cfstring.h"
34 #include "wx/mac/private.h"
36 #if defined(__DARWIN__)
37 #include <CoreFoundation/CFBundle.h>
38 #include <CoreFoundation/CFURL.h>
44 #if defined(__WXCOCOA__) || defined(__WXMAC_OSX__)
45 #define kDefaultPathStyle kCFURLPOSIXPathStyle
47 #define kDefaultPathStyle kCFURLHFSPathStyle
50 // ============================================================================
52 // ============================================================================
54 // ----------------------------------------------------------------------------
55 // wxStandardPathsCF ctors/dtor
56 // ----------------------------------------------------------------------------
58 wxStandardPathsCF::wxStandardPathsCF()
59 : m_bundle(CFBundleGetMainBundle())
64 wxStandardPathsCF::wxStandardPathsCF(wxCFBundleRef bundle
)
70 wxStandardPathsCF::~wxStandardPathsCF()
75 // ----------------------------------------------------------------------------
76 // wxStandardPathsCF Mac-specific methods
77 // ----------------------------------------------------------------------------
79 void wxStandardPathsCF::SetBundle(wxCFBundleRef bundle
)
86 // ----------------------------------------------------------------------------
87 // generic functions in terms of which the other ones are implemented
88 // ----------------------------------------------------------------------------
90 static wxString
BundleRelativeURLToPath(CFURLRef relativeURL
)
92 CFURLRef absoluteURL
= CFURLCopyAbsoluteURL(relativeURL
);
93 wxCHECK_MSG(absoluteURL
, wxEmptyString
, wxT("Failed to resolve relative URL to absolute URL"));
94 CFStringRef cfStrPath
= CFURLCopyFileSystemPath(absoluteURL
,kDefaultPathStyle
);
95 CFRelease(absoluteURL
);
96 return wxMacCFStringHolder(cfStrPath
).AsString(wxLocale::GetSystemEncoding());
99 wxString
wxStandardPathsCF::GetFromFunc(wxCFURLRef (*func
)(wxCFBundleRef
)) const
101 wxCHECK_MSG(m_bundle
, wxEmptyString
,
102 wxT("wxStandardPaths for CoreFoundation only works with bundled apps"));
103 CFURLRef relativeURL
= (*func
)(m_bundle
);
104 wxCHECK_MSG(relativeURL
, wxEmptyString
, wxT("Couldn't get URL"));
105 wxString
ret(BundleRelativeURLToPath(relativeURL
));
106 CFRelease(relativeURL
);
110 wxString
wxStandardPathsCF::GetDocumentsDir() const
112 return wxMacFindFolderNoSeparator
114 #if TARGET_API_MAC_OSX
119 kDocumentsFolderType
,
124 // ----------------------------------------------------------------------------
125 // wxStandardPathsCF public API
126 // ----------------------------------------------------------------------------
128 wxString
wxStandardPathsCF::GetConfigDir() const
131 return wxMacFindFolder((short)kLocalDomain
, kPreferencesFolderType
, kCreateFolder
);
133 return wxT("/Library/Preferences");
137 wxString
wxStandardPathsCF::GetUserConfigDir() const
140 return wxMacFindFolder((short)kUserDomain
, kPreferencesFolderType
, kCreateFolder
);
142 return wxFileName::GetHomeDir() + wxT("/Library/Preferences");
146 wxString
wxStandardPathsCF::GetDataDir() const
148 return GetFromFunc(CFBundleCopySharedSupportURL
);
151 wxString
wxStandardPathsCF::GetLocalDataDir() const
154 return AppendAppName(wxMacFindFolder((short)kLocalDomain
, kApplicationSupportFolderType
, kCreateFolder
));
156 return AppendAppName(wxT("/Library/Application Support"));
160 wxString
wxStandardPathsCF::GetUserDataDir() const
163 return AppendAppName(wxMacFindFolder((short)kUserDomain
, kApplicationSupportFolderType
, kCreateFolder
));
165 return AppendAppName(wxFileName::GetHomeDir() + _T("/Library/Application Support"));
169 wxString
wxStandardPathsCF::GetPluginsDir() const
171 return GetFromFunc(CFBundleCopyBuiltInPlugInsURL
);
174 wxString
wxStandardPathsCF::GetResourcesDir() const
176 return GetFromFunc(CFBundleCopyResourcesDirectoryURL
);
180 wxStandardPathsCF::GetLocalizedResourcesDir(const wxChar
*lang
,
181 ResourceCat category
) const
183 return wxStandardPathsBase::
184 GetLocalizedResourcesDir(lang
, category
) + _T(".lproj");
187 #endif // wxUSE_STDPATHS