]>
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 | ||
12 | #include "wx/wxprec.h" | |
13 | #ifndef WX_PRECOMP | |
14 | #include "wx/intl.h" | |
15 | #endif //ndef WX_PRECOMP | |
16 | ||
17 | #include "wx/stdpaths.h" | |
18 | #include "wx/filename.h" | |
19 | #include "wx/mac/corefoundation/cfstring.h" | |
20 | ||
072a99f4 | 21 | #if defined(__DARWIN__) |
726b98e9 DE |
22 | #include <CoreFoundation/CFBundle.h> |
23 | #include <CoreFoundation/CFURL.h> | |
072a99f4 DE |
24 | #else |
25 | #include <CFBundle.h> | |
26 | #include <CFURL.h> | |
27 | #endif | |
726b98e9 | 28 | |
726b98e9 DE |
29 | #if defined(__WXCOCOA__) || defined(__WXMAC_OSX__) |
30 | #define kDefaultPathStyle kCFURLPOSIXPathStyle | |
31 | #else | |
32 | #define kDefaultPathStyle kCFURLHFSPathStyle | |
33 | #endif | |
34 | ||
35 | static wxString BundleRelativeURLToPath(CFURLRef relativeURL) | |
36 | { | |
37 | CFURLRef absoluteURL = CFURLCopyAbsoluteURL(relativeURL); | |
38 | wxCHECK_MSG(absoluteURL, wxEmptyString, wxT("Failed to resolve relative URL to absolute URL")); | |
39 | CFStringRef cfStrPath = CFURLCopyFileSystemPath(absoluteURL,kDefaultPathStyle); | |
40 | CFRelease(absoluteURL); | |
41 | return wxMacCFStringHolder(cfStrPath).AsString(wxLocale::GetSystemEncoding()); | |
42 | } | |
43 | ||
fc480dc1 | 44 | wxStandardPathsCF::wxStandardPathsCF() |
726b98e9 DE |
45 | : m_bundle(CFBundleGetMainBundle()) |
46 | { | |
47 | CFRetain(m_bundle); | |
48 | } | |
49 | ||
fc480dc1 | 50 | wxStandardPathsCF::wxStandardPathsCF(struct __CFBundle *bundle) |
726b98e9 DE |
51 | : m_bundle(bundle) |
52 | { | |
53 | CFRetain(m_bundle); | |
54 | } | |
55 | ||
fc480dc1 | 56 | wxStandardPathsCF::~wxStandardPathsCF() |
726b98e9 DE |
57 | { |
58 | CFRelease(m_bundle); | |
59 | } | |
60 | ||
fc480dc1 | 61 | void wxStandardPathsCF::SetBundle(struct __CFBundle *bundle) |
726b98e9 DE |
62 | { |
63 | CFRetain(bundle); | |
64 | CFRelease(m_bundle); | |
65 | m_bundle = bundle; | |
66 | } | |
67 | ||
fc480dc1 | 68 | wxString wxStandardPathsCF::GetConfigDir() const |
726b98e9 DE |
69 | { |
70 | // TODO: What do we do for pure Carbon? | |
71 | return wxT("/Library/Preferences"); | |
72 | } | |
73 | ||
fc480dc1 | 74 | wxString wxStandardPathsCF::GetUserConfigDir() const |
726b98e9 DE |
75 | { |
76 | // TODO: What do we do for pure Carbon? | |
77 | return wxFileName::GetHomeDir() + wxT("/Library/Preferences"); | |
78 | } | |
79 | ||
fc480dc1 | 80 | wxString wxStandardPathsCF::GetDataDir() const |
726b98e9 DE |
81 | { |
82 | wxCHECK_MSG(m_bundle, wxEmptyString, wxT("wxStandardPaths for CoreFoundation only works with bundled apps")); | |
83 | CFURLRef relativeURL = CFBundleCopySharedSupportURL(m_bundle); | |
84 | wxCHECK_MSG(relativeURL, wxEmptyString, wxT("Couldn't get SharedSupport URL")); | |
85 | wxString ret(BundleRelativeURLToPath(relativeURL)); | |
86 | CFRelease(relativeURL); | |
87 | return ret; | |
88 | } | |
89 | ||
fc480dc1 | 90 | wxString wxStandardPathsCF::GetLocalDataDir() const |
726b98e9 DE |
91 | { |
92 | return AppendAppName(wxT("/Library/Application Support")); | |
93 | } | |
94 | ||
fc480dc1 | 95 | wxString wxStandardPathsCF::GetUserDataDir() const |
726b98e9 DE |
96 | { |
97 | return AppendAppName(wxFileName::GetHomeDir() + _T("/Library/Application Support")); | |
98 | } | |
99 | ||
fc480dc1 | 100 | wxString wxStandardPathsCF::GetPluginsDir() const |
726b98e9 DE |
101 | { |
102 | wxCHECK_MSG(m_bundle, wxEmptyString, wxT("wxStandardPaths for CoreFoundation only works with bundled apps")); | |
103 | CFURLRef relativeURL = CFBundleCopyBuiltInPlugInsURL(m_bundle); | |
104 | wxCHECK_MSG(relativeURL, wxEmptyString, wxT("Couldn't get BuiltInPlugIns URL")); | |
105 | wxString ret(BundleRelativeURLToPath(relativeURL)); | |
106 | CFRelease(relativeURL); | |
107 | return ret; | |
108 | } | |
109 |