Chameleon Applications

Chameleon Applications Svn Source Tree

Root/trunk/ChameleonPrefPane/Sources/PropertyList.h

1/*
2 * property_list.h
3 *
4 * Created by Rekursor on 1/17/10.
5 *
6 */
7#ifndef __CHPROPERTYLIST_LIST_H
8#define __CHPROPERTYLIST_LIST_H
9
10#include <CoreFoundation/CFPropertyList.h>
11#include <CoreFoundation/CFURLAccess.h>
12#include <Security/Authorization.h>
13#include <string>
14
15//----------------------------------------------------------------------------
16
17static const bool CreateIfNotExist = true;
18static const bool DontCreate = false;
19
20
21//----------------------------------------------------------------------------
22/// Run priviledged command for cmds like property chmods and restard command
23//----------------------------------------------------------------------------
24bool executePrivilegedCmd(AuthorizationRef auth,
25 const char* pathToTool,
26 const char* args=NULL,
27 AuthorizationFlags flags=kAuthorizationFlagDefaults);
28
29
30//----------------------------------------------------------------------------
31/// Simple PropertyList Abstraction
32//----------------------------------------------------------------------------
33class PropertyList
34{
35
36public:
37// Create a property list
38PropertyList() : _proplistRef(0), _CFURLRef(0) {}
39virtual ~PropertyList();
40
41/// Tell if a valid property list successfully opened
42bool isValid() const { return _proplistRef!=NULL;}
43/// release the current proplist if it exists
44void cleanup();
45
46/// Open a property list
47bool open(const char *propListPath, bool createIfNotExist,
48 AuthorizationRef auth=NULL,
49 AuthorizationFlags flags=kAuthorizationFlagDefaults);
50
51/// Save a property list
52bool save(AuthorizationRef auth=NULL,
53 AuthorizationFlags flags=kAuthorizationFlagDefaults);
54
55/// Return last error status, used in open()
56CFStringRef lastError() const { return _errorString;}
57
58/// Get a corresponding string content from a key spec
59const char * getStringForKey(const char *key);
60const char * getStringForKey(const std::string& key)
61{
62std::string str= key;
63return getStringForKey(str.c_str());
64}
65
66/// Set a content from a string, at specified key
67bool setStringForKey(const char* key, const char* value);
68bool setStringForKey(const std::string& key, const std::string& value)
69{
70return setStringForKey(key.c_str(), value.c_str());
71}
72
73/// Remove a key from the Proplist
74bool removeKeyAndValue(const char *key);
75
76/// Get the property list path
77const char * propFilePath() const {return _propFilePath.c_str(); }
78
79/// permit to execute a priviledge chmod to access system files
80static bool chmodFile(const char * path, const char * chmodMask,
81 AuthorizationRef auth, AuthorizationFlags flags=kAuthorizationFlagDefaults);
82protected:
83CFPropertyListRef _proplistRef;
84CFURLRef _CFURLRef;
85std::string _propFilePath; // keep a track of the proplist filename
86CFStringRef _errorString;
87};
88
89#endif
90

Archive Download this file

Revision: 383