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/osx/private.h"
33 #include "wx/osx/core/cfstring.h"
35 #include <CoreFoundation/CFBundle.h>
36 #include <CoreFoundation/CFURL.h>
38 #define kDefaultPathStyle kCFURLPOSIXPathStyle
40 // ============================================================================
42 // ============================================================================
44 // ----------------------------------------------------------------------------
45 // wxStandardPathsCF ctors/dtor
46 // ----------------------------------------------------------------------------
48 wxStandardPathsCF::wxStandardPathsCF()
49 : m_bundle(CFBundleGetMainBundle())
52 UseAppInfo(AppInfo_AppName
| AppInfo_VendorName
);
55 wxStandardPathsCF::wxStandardPathsCF(wxCFBundleRef bundle
)
59 UseAppInfo(AppInfo_AppName
| AppInfo_VendorName
);
62 wxStandardPathsCF::~wxStandardPathsCF()
67 // ----------------------------------------------------------------------------
68 // wxStandardPathsCF Mac-specific methods
69 // ----------------------------------------------------------------------------
71 void wxStandardPathsCF::SetBundle(wxCFBundleRef bundle
)
78 // ----------------------------------------------------------------------------
79 // generic functions in terms of which the other ones are implemented
80 // ----------------------------------------------------------------------------
82 static wxString
BundleRelativeURLToPath(CFURLRef relativeURL
)
84 CFURLRef absoluteURL
= CFURLCopyAbsoluteURL(relativeURL
);
85 wxCHECK_MSG(absoluteURL
, wxEmptyString
, wxT("Failed to resolve relative URL to absolute URL"));
86 CFStringRef cfStrPath
= CFURLCopyFileSystemPath(absoluteURL
,kDefaultPathStyle
);
87 CFRelease(absoluteURL
);
88 return wxCFStringRef(cfStrPath
).AsString(wxLocale::GetSystemEncoding());
91 wxString
wxStandardPathsCF::GetFromFunc(wxCFURLRef (*func
)(wxCFBundleRef
)) const
93 wxCHECK_MSG(m_bundle
, wxEmptyString
,
94 wxT("wxStandardPaths for CoreFoundation only works with bundled apps"));
95 CFURLRef relativeURL
= (*func
)(m_bundle
);
96 wxCHECK_MSG(relativeURL
, wxEmptyString
, wxT("Couldn't get URL"));
97 wxString
ret(BundleRelativeURLToPath(relativeURL
));
98 CFRelease(relativeURL
);
102 wxString
wxStandardPathsCF::GetDocumentsDir() const
104 #if defined( __WXMAC__ ) && wxOSX_USE_CARBON
105 return wxMacFindFolderNoSeparator
108 kDocumentsFolderType
,
112 return wxFileName::GetHomeDir() + wxT("/Documents");
116 // ----------------------------------------------------------------------------
117 // wxStandardPathsCF public API
118 // ----------------------------------------------------------------------------
120 wxString
wxStandardPathsCF::GetConfigDir() const
122 #if defined( __WXMAC__ ) && wxOSX_USE_CARBON
123 return wxMacFindFolder((short)kLocalDomain
, kPreferencesFolderType
, kCreateFolder
);
125 return wxT("/Library/Preferences");
129 wxString
wxStandardPathsCF::GetUserConfigDir() const
131 #if defined( __WXMAC__ ) && wxOSX_USE_CARBON
132 return wxMacFindFolder((short)kUserDomain
, kPreferencesFolderType
, kCreateFolder
);
134 return wxFileName::GetHomeDir() + wxT("/Library/Preferences");
138 wxString
wxStandardPathsCF::GetDataDir() const
140 return GetFromFunc(CFBundleCopySharedSupportURL
);
143 wxString
wxStandardPathsCF::GetExecutablePath() const
147 return GetFromFunc(CFBundleCopyBundleURL
);
149 // TODO remove if cf implementation ok
150 ProcessInfoRec processinfo
;
151 ProcessSerialNumber procno
;
158 procno
.highLongOfPSN
= 0 ;
159 procno
.lowLongOfPSN
= kCurrentProcess
;
160 processinfo
.processInfoLength
= sizeof(ProcessInfoRec
);
161 processinfo
.processName
= NULL
;
163 processinfo
.processAppRef
= &fsRef
;
165 processinfo
.processAppSpec
= &fsSpec
;
168 GetProcessInformation( &procno
, &processinfo
) ;
170 return wxMacFSRefToPath(&fsRef
);
172 return wxMacFSSpec2MacFilename(&fsSpec
);
177 return wxStandardPathsBase::GetExecutablePath();
181 wxString
wxStandardPathsCF::GetLocalDataDir() const
183 #if defined( __WXMAC__ ) && wxOSX_USE_CARBON
184 return AppendAppInfo(wxMacFindFolder((short)kLocalDomain
, kApplicationSupportFolderType
, kCreateFolder
));
186 return AppendAppInfo(wxT("/Library/Application Support"));
190 wxString
wxStandardPathsCF::GetUserDataDir() const
192 #if defined( __WXMAC__ ) && wxOSX_USE_CARBON
193 return AppendAppInfo(wxMacFindFolder((short)kUserDomain
, kApplicationSupportFolderType
, kCreateFolder
));
195 return AppendAppInfo(wxFileName::GetHomeDir() + wxT("/Library/Application Support"));
199 wxString
wxStandardPathsCF::GetPluginsDir() const
201 return GetFromFunc(CFBundleCopyBuiltInPlugInsURL
);
204 wxString
wxStandardPathsCF::GetResourcesDir() const
206 return GetFromFunc(CFBundleCopyResourcesDirectoryURL
);
210 wxStandardPathsCF::GetLocalizedResourcesDir(const wxString
& lang
,
211 ResourceCat category
) const
213 return wxStandardPathsBase::
214 GetLocalizedResourcesDir(lang
, category
) + wxT(".lproj");
217 #endif // wxUSE_STDPATHS