]>
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" | |
30 | #include "wx/mac/corefoundation/cfstring.h" | |
31 | ||
072a99f4 | 32 | #if defined(__DARWIN__) |
726b98e9 DE |
33 | #include <CoreFoundation/CFBundle.h> |
34 | #include <CoreFoundation/CFURL.h> | |
072a99f4 DE |
35 | #else |
36 | #include <CFBundle.h> | |
37 | #include <CFURL.h> | |
38 | #endif | |
726b98e9 | 39 | |
726b98e9 DE |
40 | #if defined(__WXCOCOA__) || defined(__WXMAC_OSX__) |
41 | #define kDefaultPathStyle kCFURLPOSIXPathStyle | |
42 | #else | |
43 | #define kDefaultPathStyle kCFURLHFSPathStyle | |
44 | #endif | |
45 | ||
3af9f2de VZ |
46 | // ============================================================================ |
47 | // implementation | |
48 | // ============================================================================ | |
49 | ||
50 | // ---------------------------------------------------------------------------- | |
51 | // wxStandardPathsCF ctors/dtor | |
52 | // ---------------------------------------------------------------------------- | |
726b98e9 | 53 | |
fc480dc1 | 54 | wxStandardPathsCF::wxStandardPathsCF() |
3af9f2de | 55 | : m_bundle(CFBundleGetMainBundle()) |
726b98e9 DE |
56 | { |
57 | CFRetain(m_bundle); | |
58 | } | |
59 | ||
3af9f2de VZ |
60 | wxStandardPathsCF::wxStandardPathsCF(wxCFBundleRef bundle) |
61 | : m_bundle(bundle) | |
726b98e9 DE |
62 | { |
63 | CFRetain(m_bundle); | |
64 | } | |
65 | ||
fc480dc1 | 66 | wxStandardPathsCF::~wxStandardPathsCF() |
726b98e9 DE |
67 | { |
68 | CFRelease(m_bundle); | |
69 | } | |
70 | ||
3af9f2de VZ |
71 | // ---------------------------------------------------------------------------- |
72 | // wxStandardPathsCF Mac-specific methods | |
73 | // ---------------------------------------------------------------------------- | |
74 | ||
75 | void wxStandardPathsCF::SetBundle(wxCFBundleRef bundle) | |
726b98e9 DE |
76 | { |
77 | CFRetain(bundle); | |
78 | CFRelease(m_bundle); | |
79 | m_bundle = bundle; | |
80 | } | |
81 | ||
3af9f2de VZ |
82 | // ---------------------------------------------------------------------------- |
83 | // generic functions in terms of which the other ones are implemented | |
84 | // ---------------------------------------------------------------------------- | |
85 | ||
86 | static wxString BundleRelativeURLToPath(CFURLRef relativeURL) | |
87 | { | |
88 | CFURLRef absoluteURL = CFURLCopyAbsoluteURL(relativeURL); | |
89 | wxCHECK_MSG(absoluteURL, wxEmptyString, wxT("Failed to resolve relative URL to absolute URL")); | |
90 | CFStringRef cfStrPath = CFURLCopyFileSystemPath(absoluteURL,kDefaultPathStyle); | |
91 | CFRelease(absoluteURL); | |
92 | return wxMacCFStringHolder(cfStrPath).AsString(wxLocale::GetSystemEncoding()); | |
93 | } | |
94 | ||
95 | wxString wxStandardPathsCF::GetFromFunc(wxCFURLRef (*func)(wxCFBundleRef)) const | |
96 | { | |
97 | wxCHECK_MSG(m_bundle, wxEmptyString, | |
98 | wxT("wxStandardPaths for CoreFoundation only works with bundled apps")); | |
99 | CFURLRef relativeURL = (*func)(m_bundle); | |
100 | wxCHECK_MSG(relativeURL, wxEmptyString, wxT("Couldn't get URL")); | |
101 | wxString ret(BundleRelativeURLToPath(relativeURL)); | |
102 | CFRelease(relativeURL); | |
103 | return ret; | |
104 | } | |
105 | ||
106 | // ---------------------------------------------------------------------------- | |
107 | // wxStandardPathsCF public API | |
108 | // ---------------------------------------------------------------------------- | |
109 | ||
fc480dc1 | 110 | wxString wxStandardPathsCF::GetConfigDir() const |
726b98e9 DE |
111 | { |
112 | // TODO: What do we do for pure Carbon? | |
113 | return wxT("/Library/Preferences"); | |
114 | } | |
115 | ||
fc480dc1 | 116 | wxString wxStandardPathsCF::GetUserConfigDir() const |
726b98e9 DE |
117 | { |
118 | // TODO: What do we do for pure Carbon? | |
119 | return wxFileName::GetHomeDir() + wxT("/Library/Preferences"); | |
120 | } | |
121 | ||
fc480dc1 | 122 | wxString wxStandardPathsCF::GetDataDir() const |
726b98e9 | 123 | { |
3af9f2de | 124 | return GetFromFunc(CFBundleCopySharedSupportURL); |
726b98e9 DE |
125 | } |
126 | ||
fc480dc1 | 127 | wxString wxStandardPathsCF::GetLocalDataDir() const |
726b98e9 DE |
128 | { |
129 | return AppendAppName(wxT("/Library/Application Support")); | |
130 | } | |
131 | ||
fc480dc1 | 132 | wxString wxStandardPathsCF::GetUserDataDir() const |
726b98e9 DE |
133 | { |
134 | return AppendAppName(wxFileName::GetHomeDir() + _T("/Library/Application Support")); | |
135 | } | |
136 | ||
fc480dc1 | 137 | wxString wxStandardPathsCF::GetPluginsDir() const |
726b98e9 | 138 | { |
3af9f2de VZ |
139 | return GetFromFunc(CFBundleCopyBuiltInPlugInsURL); |
140 | } | |
141 | ||
142 | wxString wxStandardPathsCF::GetResourcesDir() const | |
143 | { | |
144 | return GetFromFunc(CFBundleCopyResourcesDirectoryURL); | |
145 | } | |
146 | ||
147 | wxString | |
148 | wxStandardPathsCF::GetLocalizedResourcesDir(const wxChar *lang, | |
149 | ResourceCat category) const | |
150 | { | |
151 | return wxStandardPathsBase:: | |
152 | GetLocalizedResourcesDir(lang, category) + _T(".lproj"); | |
726b98e9 DE |
153 | } |
154 | ||
07158944 | 155 | #endif // wxUSE_STDPATHS |