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