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"
35 #if defined(__DARWIN__)
36 #include <CoreFoundation/CFBundle.h>
37 #include <CoreFoundation/CFURL.h>
43 #if defined(__WXCOCOA__) || defined(__WXMAC_OSX__)
44 #define kDefaultPathStyle kCFURLPOSIXPathStyle
46 #define kDefaultPathStyle kCFURLHFSPathStyle
49 // ============================================================================
51 // ============================================================================
53 // ----------------------------------------------------------------------------
54 // wxStandardPathsCF ctors/dtor
55 // ----------------------------------------------------------------------------
57 wxStandardPathsCF::wxStandardPathsCF()
58 : m_bundle(CFBundleGetMainBundle())
63 wxStandardPathsCF::wxStandardPathsCF(wxCFBundleRef bundle
)
69 wxStandardPathsCF::~wxStandardPathsCF()
74 // ----------------------------------------------------------------------------
75 // wxStandardPathsCF Mac-specific methods
76 // ----------------------------------------------------------------------------
78 void wxStandardPathsCF::SetBundle(wxCFBundleRef bundle
)
85 // ----------------------------------------------------------------------------
86 // generic functions in terms of which the other ones are implemented
87 // ----------------------------------------------------------------------------
89 static wxString
BundleRelativeURLToPath(CFURLRef relativeURL
)
91 CFURLRef absoluteURL
= CFURLCopyAbsoluteURL(relativeURL
);
92 wxCHECK_MSG(absoluteURL
, wxEmptyString
, wxT("Failed to resolve relative URL to absolute URL"));
93 CFStringRef cfStrPath
= CFURLCopyFileSystemPath(absoluteURL
,kDefaultPathStyle
);
94 CFRelease(absoluteURL
);
95 return wxMacCFStringHolder(cfStrPath
).AsString(wxLocale::GetSystemEncoding());
98 wxString
wxStandardPathsCF::GetFromFunc(wxCFURLRef (*func
)(wxCFBundleRef
)) const
100 wxCHECK_MSG(m_bundle
, wxEmptyString
,
101 wxT("wxStandardPaths for CoreFoundation only works with bundled apps"));
102 CFURLRef relativeURL
= (*func
)(m_bundle
);
103 wxCHECK_MSG(relativeURL
, wxEmptyString
, wxT("Couldn't get URL"));
104 wxString
ret(BundleRelativeURLToPath(relativeURL
));
105 CFRelease(relativeURL
);
109 // ----------------------------------------------------------------------------
110 // wxStandardPathsCF public API
111 // ----------------------------------------------------------------------------
113 wxString
wxStandardPathsCF::GetConfigDir() const
116 return wxMacFindFolder((short)kLocalDomain
, kPreferencesFolderType
, kCreateFolder
);
118 return wxT("/Library/Preferences");
122 wxString
wxStandardPathsCF::GetUserConfigDir() const
125 return wxMacFindFolder((short)kUserDomain
, kPreferencesFolderType
, kCreateFolder
);
127 return wxFileName::GetHomeDir() + wxT("/Library/Preferences");
131 wxString
wxStandardPathsCF::GetDataDir() const
133 return GetFromFunc(CFBundleCopySharedSupportURL
);
136 wxString
wxStandardPathsCF::GetLocalDataDir() const
139 return AppendAppName(wxMacFindFolder((short)kLocalDomain
, kApplicationSupportFolderType
, kCreateFolder
));
141 return AppendAppName(wxT("/Library/Application Support"));
145 wxString
wxStandardPathsCF::GetUserDataDir() const
148 return AppendAppName(wxMacFindFolder((short)kUserDomain
, kApplicationSupportFolderType
, kCreateFolder
));
150 return AppendAppName(wxFileName::GetHomeDir() + _T("/Library/Application Support"));
154 wxString
wxStandardPathsCF::GetPluginsDir() const
156 return GetFromFunc(CFBundleCopyBuiltInPlugInsURL
);
159 wxString
wxStandardPathsCF::GetResourcesDir() const
161 return GetFromFunc(CFBundleCopyResourcesDirectoryURL
);
165 wxStandardPathsCF::GetLocalizedResourcesDir(const wxChar
*lang
,
166 ResourceCat category
) const
168 return wxStandardPathsBase::
169 GetLocalizedResourcesDir(lang
, category
) + _T(".lproj");
172 #endif // wxUSE_STDPATHS