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
44/// Open a property list
45bool open(const char *propListPath, bool createIfNotExist,
46 AuthorizationRef auth=NULL,
47 AuthorizationFlags flags=kAuthorizationFlagDefaults);
48
49/// Save a property list
50bool save(AuthorizationRef auth=NULL,
51 AuthorizationFlags flags=kAuthorizationFlagDefaults);
52
53/// Return last error status, used in open()
54CFStringRef lastError() const { return _errorString;}
55
56/// Get a corresponding string content from a key spec
57const char * getStringForKey(const char *key);
58const char * getStringForKey(const std::string& key)
59{
60std::string str= key;
61return getStringForKey(str.c_str());
62}
63
64/// Set a content from a string, at specified key
65bool setStringForKey(const char* key, const char* value);
66bool setStringForKey(const std::string& key, const std::string& value)
67{
68return setStringForKey(key.c_str(), value.c_str());
69}
70
71/// Remove a key from the Proplist
72bool removeKeyAndValue(const char *key);
73
74/// Get the property list path
75const char * propFilePath() const {return _propFilePath.c_str(); }
76
77/// permit to execute a priviledge chmod to access system files
78static bool chmodFile(const char * path, const char * chmodMask,
79 AuthorizationRef auth, AuthorizationFlags flags=kAuthorizationFlagDefaults);
80protected:
81CFPropertyListRef _proplistRef;
82CFURLRef _CFURLRef;
83std::string _propFilePath; // keep a track of the proplist filename
84CFStringRef _errorString;
85};
86
87#endif
88

Archive Download this file

Revision: 378