]>
Commit | Line | Data |
---|---|---|
726b98e9 DE |
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 | ||
3af9f2de VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
726b98e9 | 20 | #include "wx/wxprec.h" |
07158944 VZ |
21 | |
22 | #if wxUSE_STDPATHS | |
23 | ||
726b98e9 DE |
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" | |
f5158fa6 SC |
30 | #ifdef __WXMAC__ |
31 | #include "wx/mac/private.h" | |
32 | #endif | |
726b98e9 DE |
33 | #include "wx/mac/corefoundation/cfstring.h" |
34 | ||
072a99f4 | 35 | #if defined(__DARWIN__) |
726b98e9 DE |
36 | #include <CoreFoundation/CFBundle.h> |
37 | #include <CoreFoundation/CFURL.h> | |
072a99f4 DE |
38 | #else |
39 | #include <CFBundle.h> | |
40 | #include <CFURL.h> | |
41 | #endif | |
726b98e9 | 42 | |
726b98e9 DE |
43 | #if defined(__WXCOCOA__) || defined(__WXMAC_OSX__) |
44 | #define kDefaultPathStyle kCFURLPOSIXPathStyle | |
45 | #else | |
46 | #define kDefaultPathStyle kCFURLHFSPathStyle | |
47 | #endif | |
48 | ||
3af9f2de VZ |
49 | // ============================================================================ |
50 | // implementation | |
51 | // ============================================================================ | |
52 | ||
53 | // ---------------------------------------------------------------------------- | |
54 | // wxStandardPathsCF ctors/dtor | |
55 | // ---------------------------------------------------------------------------- | |
726b98e9 | 56 | |
fc480dc1 | 57 | wxStandardPathsCF::wxStandardPathsCF() |
3af9f2de | 58 | : m_bundle(CFBundleGetMainBundle()) |
726b98e9 DE |
59 | { |
60 | CFRetain(m_bundle); | |
61 | } | |
62 | ||
3af9f2de VZ |
63 | wxStandardPathsCF::wxStandardPathsCF(wxCFBundleRef bundle) |
64 | : m_bundle(bundle) | |
726b98e9 DE |
65 | { |
66 | CFRetain(m_bundle); | |
67 | } | |
68 | ||
fc480dc1 | 69 | wxStandardPathsCF::~wxStandardPathsCF() |
726b98e9 DE |
70 | { |
71 | CFRelease(m_bundle); | |
72 | } | |
73 | ||
3af9f2de VZ |
74 | // ---------------------------------------------------------------------------- |
75 | // wxStandardPathsCF Mac-specific methods | |
76 | // ---------------------------------------------------------------------------- | |
77 | ||
78 | void wxStandardPathsCF::SetBundle(wxCFBundleRef bundle) | |
726b98e9 DE |
79 | { |
80 | CFRetain(bundle); | |
81 | CFRelease(m_bundle); | |
82 | m_bundle = bundle; | |
83 | } | |
84 | ||
3af9f2de VZ |
85 | // ---------------------------------------------------------------------------- |
86 | // generic functions in terms of which the other ones are implemented | |
87 | // ---------------------------------------------------------------------------- | |
88 | ||
89 | static wxString BundleRelativeURLToPath(CFURLRef relativeURL) | |
90 | { | |
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()); | |
96 | } | |
97 | ||
98 | wxString wxStandardPathsCF::GetFromFunc(wxCFURLRef (*func)(wxCFBundleRef)) const | |
99 | { | |
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); | |
106 | return ret; | |
107 | } | |
108 | ||
109 | // ---------------------------------------------------------------------------- | |
110 | // wxStandardPathsCF public API | |
111 | // ---------------------------------------------------------------------------- | |
112 | ||
fc480dc1 | 113 | wxString wxStandardPathsCF::GetConfigDir() const |
726b98e9 | 114 | { |
f5158fa6 SC |
115 | #ifdef __WXMAC__ |
116 | return wxMacFindFolder((short)kLocalDomain, kPreferencesFolderType, kCreateFolder); | |
117 | #else | |
726b98e9 | 118 | return wxT("/Library/Preferences"); |
f5158fa6 | 119 | #endif |
726b98e9 DE |
120 | } |
121 | ||
fc480dc1 | 122 | wxString wxStandardPathsCF::GetUserConfigDir() const |
726b98e9 | 123 | { |
f5158fa6 SC |
124 | #ifdef __WXMAC__ |
125 | return wxMacFindFolder((short)kUserDomain, kPreferencesFolderType, kCreateFolder); | |
126 | #else | |
726b98e9 | 127 | return wxFileName::GetHomeDir() + wxT("/Library/Preferences"); |
f5158fa6 | 128 | #endif |
726b98e9 DE |
129 | } |
130 | ||
fc480dc1 | 131 | wxString wxStandardPathsCF::GetDataDir() const |
726b98e9 | 132 | { |
3af9f2de | 133 | return GetFromFunc(CFBundleCopySharedSupportURL); |
726b98e9 DE |
134 | } |
135 | ||
fc480dc1 | 136 | wxString wxStandardPathsCF::GetLocalDataDir() const |
726b98e9 | 137 | { |
f5158fa6 SC |
138 | #ifdef __WXMAC__ |
139 | return AppendAppName(wxMacFindFolder((short)kLocalDomain, kApplicationSupportFolderType, kCreateFolder)); | |
140 | #else | |
726b98e9 | 141 | return AppendAppName(wxT("/Library/Application Support")); |
f5158fa6 | 142 | #endif |
726b98e9 DE |
143 | } |
144 | ||
fc480dc1 | 145 | wxString wxStandardPathsCF::GetUserDataDir() const |
726b98e9 | 146 | { |
f5158fa6 SC |
147 | #ifdef __WXMAC__ |
148 | return AppendAppName(wxMacFindFolder((short)kUserDomain, kApplicationSupportFolderType, kCreateFolder)); | |
149 | #else | |
726b98e9 | 150 | return AppendAppName(wxFileName::GetHomeDir() + _T("/Library/Application Support")); |
f5158fa6 | 151 | #endif |
726b98e9 DE |
152 | } |
153 | ||
fc480dc1 | 154 | wxString wxStandardPathsCF::GetPluginsDir() const |
726b98e9 | 155 | { |
3af9f2de VZ |
156 | return GetFromFunc(CFBundleCopyBuiltInPlugInsURL); |
157 | } | |
158 | ||
159 | wxString wxStandardPathsCF::GetResourcesDir() const | |
160 | { | |
161 | return GetFromFunc(CFBundleCopyResourcesDirectoryURL); | |
162 | } | |
163 | ||
164 | wxString | |
165 | wxStandardPathsCF::GetLocalizedResourcesDir(const wxChar *lang, | |
166 | ResourceCat category) const | |
167 | { | |
168 | return wxStandardPathsBase:: | |
169 | GetLocalizedResourcesDir(lang, category) + _T(".lproj"); | |
726b98e9 DE |
170 | } |
171 | ||
07158944 | 172 | #endif // wxUSE_STDPATHS |