]>
Commit | Line | Data |
---|---|---|
489468fe SC |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: mac/corefoundation/stdpaths.cpp | |
3 | // Purpose: wxStandardPaths implementation for CoreFoundation systems | |
4 | // Author: David Elliott | |
5 | // Modified by: | |
6 | // Created: 2004-10-27 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 2004 David Elliott <dfe@cox.net> | |
9 | // Licence: wxWindows licence | |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | #include "wx/wxprec.h" | |
21 | ||
22 | #if wxUSE_STDPATHS | |
23 | ||
24 | #ifndef WX_PRECOMP | |
25 | #include "wx/intl.h" | |
26 | #endif //ndef WX_PRECOMP | |
27 | ||
28 | #include "wx/stdpaths.h" | |
29 | #include "wx/filename.h" | |
30 | #ifdef __WXMAC__ | |
c8ef3d55 | 31 | #include "wx/osx/private.h" |
489468fe | 32 | #endif |
c8ef3d55 | 33 | #include "wx/osx/core/cfstring.h" |
489468fe SC |
34 | |
35 | #include <CoreFoundation/CFBundle.h> | |
36 | #include <CoreFoundation/CFURL.h> | |
37 | ||
38 | #define kDefaultPathStyle kCFURLPOSIXPathStyle | |
39 | ||
40 | // ============================================================================ | |
41 | // implementation | |
42 | // ============================================================================ | |
43 | ||
44 | // ---------------------------------------------------------------------------- | |
45 | // wxStandardPathsCF ctors/dtor | |
46 | // ---------------------------------------------------------------------------- | |
47 | ||
48 | wxStandardPathsCF::wxStandardPathsCF() | |
49 | : m_bundle(CFBundleGetMainBundle()) | |
50 | { | |
51 | CFRetain(m_bundle); | |
52 | UseAppInfo(AppInfo_AppName | AppInfo_VendorName); | |
53 | } | |
54 | ||
55 | wxStandardPathsCF::wxStandardPathsCF(wxCFBundleRef bundle) | |
56 | : m_bundle(bundle) | |
57 | { | |
58 | CFRetain(m_bundle); | |
59 | UseAppInfo(AppInfo_AppName | AppInfo_VendorName); | |
60 | } | |
61 | ||
62 | wxStandardPathsCF::~wxStandardPathsCF() | |
63 | { | |
64 | CFRelease(m_bundle); | |
65 | } | |
66 | ||
67 | // ---------------------------------------------------------------------------- | |
68 | // wxStandardPathsCF Mac-specific methods | |
69 | // ---------------------------------------------------------------------------- | |
70 | ||
71 | void wxStandardPathsCF::SetBundle(wxCFBundleRef bundle) | |
72 | { | |
73 | CFRetain(bundle); | |
74 | CFRelease(m_bundle); | |
75 | m_bundle = bundle; | |
76 | } | |
77 | ||
78 | // ---------------------------------------------------------------------------- | |
79 | // generic functions in terms of which the other ones are implemented | |
80 | // ---------------------------------------------------------------------------- | |
81 | ||
82 | static wxString BundleRelativeURLToPath(CFURLRef relativeURL) | |
83 | { | |
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()); | |
89 | } | |
90 | ||
91 | wxString wxStandardPathsCF::GetFromFunc(wxCFURLRef (*func)(wxCFBundleRef)) const | |
92 | { | |
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); | |
99 | return ret; | |
100 | } | |
101 | ||
102 | wxString wxStandardPathsCF::GetDocumentsDir() const | |
103 | { | |
56869c54 | 104 | #if defined( __WXMAC__ ) && wxOSX_USE_CARBON |
489468fe SC |
105 | return wxMacFindFolderNoSeparator |
106 | ( | |
107 | kUserDomain, | |
108 | kDocumentsFolderType, | |
109 | kCreateFolder | |
110 | ); | |
111 | #else | |
112 | return wxFileName::GetHomeDir() + wxT("/Documents"); | |
113 | #endif | |
114 | } | |
115 | ||
116 | // ---------------------------------------------------------------------------- | |
117 | // wxStandardPathsCF public API | |
118 | // ---------------------------------------------------------------------------- | |
119 | ||
120 | wxString wxStandardPathsCF::GetConfigDir() const | |
121 | { | |
56869c54 | 122 | #if defined( __WXMAC__ ) && wxOSX_USE_CARBON |
489468fe SC |
123 | return wxMacFindFolder((short)kLocalDomain, kPreferencesFolderType, kCreateFolder); |
124 | #else | |
125 | return wxT("/Library/Preferences"); | |
126 | #endif | |
127 | } | |
128 | ||
129 | wxString wxStandardPathsCF::GetUserConfigDir() const | |
130 | { | |
56869c54 | 131 | #if defined( __WXMAC__ ) && wxOSX_USE_CARBON |
489468fe SC |
132 | return wxMacFindFolder((short)kUserDomain, kPreferencesFolderType, kCreateFolder); |
133 | #else | |
134 | return wxFileName::GetHomeDir() + wxT("/Library/Preferences"); | |
135 | #endif | |
136 | } | |
137 | ||
138 | wxString wxStandardPathsCF::GetDataDir() const | |
139 | { | |
140 | return GetFromFunc(CFBundleCopySharedSupportURL); | |
141 | } | |
142 | ||
143 | wxString wxStandardPathsCF::GetExecutablePath() const | |
144 | { | |
145 | #ifdef __WXMAC__ | |
146 | #if 1 | |
147 | return GetFromFunc(CFBundleCopyBundleURL); | |
148 | #else | |
149 | // TODO remove if cf implementation ok | |
150 | ProcessInfoRec processinfo; | |
151 | ProcessSerialNumber procno ; | |
152 | #ifdef __LP64__ | |
153 | FSRef fsRef; | |
154 | #else | |
155 | FSSpec fsSpec; | |
156 | #endif | |
03647350 | 157 | |
489468fe SC |
158 | procno.highLongOfPSN = 0 ; |
159 | procno.lowLongOfPSN = kCurrentProcess ; | |
160 | processinfo.processInfoLength = sizeof(ProcessInfoRec); | |
161 | processinfo.processName = NULL; | |
162 | #ifdef __LP64__ | |
163 | processinfo.processAppRef = &fsRef; | |
164 | #else | |
165 | processinfo.processAppSpec = &fsSpec; | |
166 | #endif | |
03647350 | 167 | |
489468fe SC |
168 | GetProcessInformation( &procno , &processinfo ) ; |
169 | #ifdef __LP64__ | |
170 | return wxMacFSRefToPath(&fsRef); | |
171 | #else | |
172 | return wxMacFSSpec2MacFilename(&fsSpec); | |
173 | #endif | |
174 | #endif | |
03647350 | 175 | |
489468fe SC |
176 | #else |
177 | return wxStandardPathsBase::GetExecutablePath(); | |
178 | #endif | |
179 | } | |
180 | ||
181 | wxString wxStandardPathsCF::GetLocalDataDir() const | |
182 | { | |
56869c54 | 183 | #if defined( __WXMAC__ ) && wxOSX_USE_CARBON |
489468fe SC |
184 | return AppendAppInfo(wxMacFindFolder((short)kLocalDomain, kApplicationSupportFolderType, kCreateFolder)); |
185 | #else | |
186 | return AppendAppInfo(wxT("/Library/Application Support")); | |
187 | #endif | |
188 | } | |
189 | ||
190 | wxString wxStandardPathsCF::GetUserDataDir() const | |
191 | { | |
56869c54 | 192 | #if defined( __WXMAC__ ) && wxOSX_USE_CARBON |
489468fe SC |
193 | return AppendAppInfo(wxMacFindFolder((short)kUserDomain, kApplicationSupportFolderType, kCreateFolder)); |
194 | #else | |
9a83f860 | 195 | return AppendAppInfo(wxFileName::GetHomeDir() + wxT("/Library/Application Support")); |
489468fe SC |
196 | #endif |
197 | } | |
198 | ||
199 | wxString wxStandardPathsCF::GetPluginsDir() const | |
200 | { | |
201 | return GetFromFunc(CFBundleCopyBuiltInPlugInsURL); | |
202 | } | |
203 | ||
204 | wxString wxStandardPathsCF::GetResourcesDir() const | |
205 | { | |
206 | return GetFromFunc(CFBundleCopyResourcesDirectoryURL); | |
207 | } | |
208 | ||
209 | wxString | |
210 | wxStandardPathsCF::GetLocalizedResourcesDir(const wxString& lang, | |
211 | ResourceCat category) const | |
212 | { | |
213 | return wxStandardPathsBase:: | |
9a83f860 | 214 | GetLocalizedResourcesDir(lang, category) + wxT(".lproj"); |
489468fe SC |
215 | } |
216 | ||
217 | #endif // wxUSE_STDPATHS |