]> git.saurik.com Git - wxWidgets.git/blame - src/mac/corefoundation/stdpaths_cf.cpp
Fixes for wxPython site-packages location.
[wxWidgets.git] / src / mac / corefoundation / stdpaths_cf.cpp
CommitLineData
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
DE
28
29// See comment in include/wx/mac/corefoundation/stdpaths.h
30#ifndef wxStandardPaths
31#warning "wxStandardPaths should be defined to wxStandardPathsCF when compiling this file."
32#endif
33
34#if defined(__WXCOCOA__) || defined(__WXMAC_OSX__)
35#define kDefaultPathStyle kCFURLPOSIXPathStyle
36#else
37#define kDefaultPathStyle kCFURLHFSPathStyle
38#endif
39
40static wxString BundleRelativeURLToPath(CFURLRef relativeURL)
41{
42 CFURLRef absoluteURL = CFURLCopyAbsoluteURL(relativeURL);
43 wxCHECK_MSG(absoluteURL, wxEmptyString, wxT("Failed to resolve relative URL to absolute URL"));
44 CFStringRef cfStrPath = CFURLCopyFileSystemPath(absoluteURL,kDefaultPathStyle);
45 CFRelease(absoluteURL);
46 return wxMacCFStringHolder(cfStrPath).AsString(wxLocale::GetSystemEncoding());
47}
48
49
50static wxStandardPaths gs_stdPaths;
51/* static */ wxStandardPaths& wxStandardPaths::Get()
52{
53 return gs_stdPaths;
54}
55
56wxStandardPaths::wxStandardPaths()
57: m_bundle(CFBundleGetMainBundle())
58{
59 CFRetain(m_bundle);
60}
61
62wxStandardPaths::wxStandardPaths(struct __CFBundle *bundle)
63: m_bundle(bundle)
64{
65 CFRetain(m_bundle);
66}
67
68wxStandardPaths::~wxStandardPaths()
69{
70 CFRelease(m_bundle);
71}
72
73void wxStandardPaths::SetBundle(struct __CFBundle *bundle)
74{
75 CFRetain(bundle);
76 CFRelease(m_bundle);
77 m_bundle = bundle;
78}
79
80wxString wxStandardPaths::GetConfigDir() const
81{
82 // TODO: What do we do for pure Carbon?
83 return wxT("/Library/Preferences");
84}
85
86wxString wxStandardPaths::GetUserConfigDir() const
87{
88 // TODO: What do we do for pure Carbon?
89 return wxFileName::GetHomeDir() + wxT("/Library/Preferences");
90}
91
92wxString wxStandardPaths::GetDataDir() const
93{
94 wxCHECK_MSG(m_bundle, wxEmptyString, wxT("wxStandardPaths for CoreFoundation only works with bundled apps"));
95 CFURLRef relativeURL = CFBundleCopySharedSupportURL(m_bundle);
96 wxCHECK_MSG(relativeURL, wxEmptyString, wxT("Couldn't get SharedSupport URL"));
97 wxString ret(BundleRelativeURLToPath(relativeURL));
98 CFRelease(relativeURL);
99 return ret;
100}
101
102wxString wxStandardPaths::GetLocalDataDir() const
103{
104 return AppendAppName(wxT("/Library/Application Support"));
105}
106
107wxString wxStandardPaths::GetUserDataDir() const
108{
109 return AppendAppName(wxFileName::GetHomeDir() + _T("/Library/Application Support"));
110}
111
112wxString wxStandardPaths::GetPluginsDir() const
113{
114 wxCHECK_MSG(m_bundle, wxEmptyString, wxT("wxStandardPaths for CoreFoundation only works with bundled apps"));
115 CFURLRef relativeURL = CFBundleCopyBuiltInPlugInsURL(m_bundle);
116 wxCHECK_MSG(relativeURL, wxEmptyString, wxT("Couldn't get BuiltInPlugIns URL"));
117 wxString ret(BundleRelativeURLToPath(relativeURL));
118 CFRelease(relativeURL);
119 return ret;
120}
121