]> git.saurik.com Git - wxWidgets.git/blob - src/mac/corefoundation/stdpaths_cf.cpp
Removed debug output.
[wxWidgets.git] / src / mac / corefoundation / stdpaths_cf.cpp
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
21 #include <CoreFoundation/CFBundle.h>
22 #include <CoreFoundation/CFURL.h>
23
24 // See comment in include/wx/mac/corefoundation/stdpaths.h
25 #ifndef wxStandardPaths
26 #warning "wxStandardPaths should be defined to wxStandardPathsCF when compiling this file."
27 #endif
28
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
44
45 static wxStandardPaths gs_stdPaths;
46 /* static */ wxStandardPaths& wxStandardPaths::Get()
47 {
48 return gs_stdPaths;
49 }
50
51 wxStandardPaths::wxStandardPaths()
52 : m_bundle(CFBundleGetMainBundle())
53 {
54 CFRetain(m_bundle);
55 }
56
57 wxStandardPaths::wxStandardPaths(struct __CFBundle *bundle)
58 : m_bundle(bundle)
59 {
60 CFRetain(m_bundle);
61 }
62
63 wxStandardPaths::~wxStandardPaths()
64 {
65 CFRelease(m_bundle);
66 }
67
68 void wxStandardPaths::SetBundle(struct __CFBundle *bundle)
69 {
70 CFRetain(bundle);
71 CFRelease(m_bundle);
72 m_bundle = bundle;
73 }
74
75 wxString wxStandardPaths::GetConfigDir() const
76 {
77 // TODO: What do we do for pure Carbon?
78 return wxT("/Library/Preferences");
79 }
80
81 wxString wxStandardPaths::GetUserConfigDir() const
82 {
83 // TODO: What do we do for pure Carbon?
84 return wxFileName::GetHomeDir() + wxT("/Library/Preferences");
85 }
86
87 wxString wxStandardPaths::GetDataDir() const
88 {
89 wxCHECK_MSG(m_bundle, wxEmptyString, wxT("wxStandardPaths for CoreFoundation only works with bundled apps"));
90 CFURLRef relativeURL = CFBundleCopySharedSupportURL(m_bundle);
91 wxCHECK_MSG(relativeURL, wxEmptyString, wxT("Couldn't get SharedSupport URL"));
92 wxString ret(BundleRelativeURLToPath(relativeURL));
93 CFRelease(relativeURL);
94 return ret;
95 }
96
97 wxString wxStandardPaths::GetLocalDataDir() const
98 {
99 return AppendAppName(wxT("/Library/Application Support"));
100 }
101
102 wxString wxStandardPaths::GetUserDataDir() const
103 {
104 return AppendAppName(wxFileName::GetHomeDir() + _T("/Library/Application Support"));
105 }
106
107 wxString wxStandardPaths::GetPluginsDir() const
108 {
109 wxCHECK_MSG(m_bundle, wxEmptyString, wxT("wxStandardPaths for CoreFoundation only works with bundled apps"));
110 CFURLRef relativeURL = CFBundleCopyBuiltInPlugInsURL(m_bundle);
111 wxCHECK_MSG(relativeURL, wxEmptyString, wxT("Couldn't get BuiltInPlugIns URL"));
112 wxString ret(BundleRelativeURLToPath(relativeURL));
113 CFRelease(relativeURL);
114 return ret;
115 }
116