Chameleon Applications

Chameleon Applications Commit Details

Date:2010-01-25 11:04:57 (14 years 2 months ago)
Author:Rekursor
Commit:51
Parents: 50
Message:published 2.0b1 binaries for testing purposes. Make a backup of your bootConfig file before testing.
Changes:
R/trunk/ChameleonPrefPane/Sources/BootPropertyList.cpp → /trunk/ChameleonPrefPane/Sources/ChameleonPropertyList.cpp
R/trunk/ChameleonPrefPane/Sources/BootPropertyList.h → /trunk/ChameleonPrefPane/Sources/ChameleonPropertyList.h
A/trunk/ChameleonPrefPane/Sources/file_util.h
A/trunk/ChameleonPrefPane/Sources/GroupControllerProtocol.h
M/trunk/ChameleonPrefPane/Sources/BootSetupController.mm
M/trunk/ChameleonPrefPane/Sources/PropertyList.cpp
M/trunk/ChameleonPrefPane/Sources/AdvancedSetupController.mm
M/trunk/ChameleonPrefPane/Sources/PropertyList.h
M/trunk/ChameleonPrefPane/Sources/PreferencesControllerBase.mm
M/trunk/ChameleonPrefPane/Sources/PeripheralsController.h
M/trunk/ChameleonPrefPane/Sources/KernOptionsParser.cpp
M/trunk/ChameleonPrefPane/Sources/BootFlagsController.h
M/trunk/ChameleonPrefPane/Sources/BootSetupController.h
M/trunk/ChameleonPrefPane/Sources/AdvancedSetupController.h
M/trunk/ChameleonPrefPane/Sources/ChameleonPrefPane.mm
M/trunk/ChameleonPrefPane/Sources/PreferencesControllerBase.h
M/trunk/ChameleonPrefPane/Sources/PeripheralsController.mm
M/trunk/ChameleonPrefPane/Sources/ShellProcess.h
M/trunk/ChameleonPrefPane/Sources/BootFlagsController.mm

File differences

trunk/ChameleonPrefPane/Sources/BootPropertyList.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*
* BootPropertyList.cpp
* ChameleonPrefPane
*
* Created by Rekursor on 1/22/10.
*
*/
#include "BootPropertyList.h"
void BootPropertyList::deleteOptionDesc()
{
// delete all alloc'ed pointers
std::map<void*, BootOptionDesc*>::iterator bod;
for (bod=_idToDescDict.begin(); bod!=_idToDescDict.end(); bod++)
if(bod->second) delete bod->second;
for (bod=_contentIdToDescDict.begin(); bod!=_contentIdToDescDict.end(); bod++)
if(bod->second) delete bod->second;
}
void BootPropertyList::clearOptionDesc()
{
deleteOptionDesc();
_idToDescDict.clear();// now clear the pairs
_contentIdToDescDict.clear();// now clear the pairs
}
trunk/ChameleonPrefPane/Sources/BootPropertyList.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
* BootPropertyList.h
* ChameleonPrefPane
*
* Created by Rekursor on 1/22/10.
*
*/
#ifndef __CHBOOT_PROPERTYLIST_LIST_H
#define __CHBOOT_PROPERTYLIST_LIST_H
#include "PropertyList.h"
#include <map>
//--------------------------------------------------------------------------
// Chameleon Boot options type
typedef enum
{
OptionYesNo=0,// "Yes" or "No"
OptionString,// String Content
OptionUnix,// Unix like command option like -x, -v ...
OptionKernel,// kernel cmd like "mach_kernel" or "blacklist=0"
OptionKernel1// kernel cmd like "mach_kernel" or "blacklist=0"
} BootOptionType;
typedef enum PropertyKind
{
KindPreferencesFile,
KindBootConfigFile,
KindSmbiosConfigFile
};
struct BootOptionDesc;
typedef bool (*FieldValidator) (BootOptionDesc* bod);
//--------------------------------------------------------------------------
// Boot Option descriptor : used by all derived class to permit parameters handling automation ...
struct BootOptionDesc
{
BootOptionDesc(void* i, void * c, BootOptionType t, const char* n, const char* d,
FieldValidator validator=NULL, PropertyKind kind=KindBootConfigFile) :
ID(i), contentID(c), Type(t), Name(n), Default(d),
Validator(validator), Kind(kind)
{
}
void*ID; // the corresponding button or textfield in the interface
void*contentID; // the corresponding content ID (i.e: the string content for text fields)
BootOptionTypeType;
const char *Name;
FieldValidatorValidator;
PropertyKindKind;
const char *Default;
} ;
//--------------------------------------------------------------------------
/**
* Specialization of PropertyList with Chameleon Boot Config, fast id key to desc search features
*/
class BootPropertyList : public PropertyList
{
public:
BootPropertyList() {}
virtual ~BootPropertyList() {deleteOptionDesc(); }
// id to map BootOptionDesc handling
void addOptionDesc(void * ID, void* cID, BootOptionType t, const char * szName, const char* szDefault,
FieldValidator validator=NULL, PropertyKind kind=KindBootConfigFile)
{
if (ID) _idToDescDict[ID] =
new BootOptionDesc(ID, cID, t, szName? szName : "", szDefault ? szDefault : "");
if (cID) _contentIdToDescDict[cID] =
new BootOptionDesc(ID, cID, t, szName? szName : "", szDefault ? szDefault : "");
}
// find the desc corresponding to id:
const BootOptionDesc* findOption(void *ID) const
{
std::map<void*, BootOptionDesc*>::const_iterator bod;
if (!ID || (bod=_idToDescDict.find(ID))==_idToDescDict.end()) return NULL;
return bod->second;
}
// find the option bod corresponding to contentID
const BootOptionDesc* findOptionContent(void *cID) const
{
std::map<void*, BootOptionDesc*>::const_iterator bod;
if (!cID || (bod=_contentIdToDescDict.find(cID))==_contentIdToDescDict.end()) return NULL;
return bod->second;
}
// opaque enumeration for the map
const BootOptionDesc* firstOption()
{
_bod=_idToDescDict.begin();
if (_bod!= _idToDescDict.end()) return _bod->second; else return NULL;
}
const BootOptionDesc* nextOption()
{
if(_bod++ ==_idToDescDict.end()) return NULL;
if (_bod != _idToDescDict.end()) return _bod->second; else return NULL;
}
// remove all elements in dict, calls deleteOptionsDesc()
void clearOptionDesc();
protected:
void deleteOptionDesc();
private:
// dictionary for id -> desc and contentID -> desc association type
std::map<void *, BootOptionDesc*> _idToDescDict, _contentIdToDescDict;
std::map<void*, BootOptionDesc*>::const_iterator _bod;
};
#endif
trunk/ChameleonPrefPane/Sources/AdvancedSetupController.h
1111
1212
1313
14
14
1515
1616
1717
......
4949
5050
5151
52
5253
5354
5455
// TabView subpane controller definition
@interface AdvancedSetupController : PreferencesControllerBase <PreferenceController>
@interface AdvancedSetupController : PreferencesControllerBase <GroupControllerProtocol>
{
IBOutlet NSButton*mKernel;
IBOutlet NSTextField*mKernelText;
- (IBAction) onCheckButtonChange: (NSButton*) sender;
- (IBAction) onTextFiedChange: (NSTextField*) sender;
- (void) setDefaultsValues: (NSMutableDictionary*) dict;
+ (AdvancedSetupController *)instance;
trunk/ChameleonPrefPane/Sources/ChameleonPropertyList.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
* ChameleonPropertyList.h
* ChameleonPrefPane
*
* Created by Rekursor on 1/22/10.
*
*/
#ifndef __CHBOOT_PROPERTYLIST_LIST_H
#define __CHBOOT_PROPERTYLIST_LIST_H
#include "PropertyList.h"
#include <map>
//--------------------------------------------------------------------------
// Chameleon Boot options type
//--------------------------------------------------------------------------
typedef enum
{
OptionYesNo=0,// "Yes" or "No"
OptionString,// String Content
OptionUnix,// Unix like command option like -x, -v ...
OptionKernel,// kernel cmd like "mach_kernel" or "blacklist=0"
OptionKernel1// kernel cmd like "mach_kernel" or "blacklist=0"
} BootOptionType;
typedef enum PropertyKind
{
KindPreferencesFile,
KindBootConfigFile,
KindSmbiosConfigFile
};
struct BootOptionDesc;
typedef bool (*FieldValidator) (BootOptionDesc* bod);
//--------------------------------------------------------------------------
// Boot Option descriptor :
// used by all derived class to permit parameters handling automation ...
//--------------------------------------------------------------------------
struct BootOptionDesc
{
BootOptionDesc(void* i, void * c, BootOptionType t, const char* n, const char* d,
FieldValidator validator=NULL, PropertyKind kind=KindBootConfigFile) :
ID(i), contentID(c), Type(t), Name(n), Default(d),
Validator(validator), Kind(kind)
{
}
void*ID; // the corresponding button or textfield in the interface
void*contentID; // the corresponding content ID (i.e: the string content for text fields)
BootOptionTypeType;
const char *Name;
FieldValidatorValidator;
PropertyKindKind;
const char *Default;
} ;
//--------------------------------------------------------------------------
/**
* Specialization of PropertyList with Chameleon Boot Config, fast id key to desc search features
*/
class ChameleonPropertyList : public PropertyList
{
protected:
ChameleonPropertyList() {}
public:
virtual ~ChameleonPropertyList() {deleteOptionDesc(); }
// id to map BootOptionDesc handling
void addOptionDesc(void * ID, void* cID, BootOptionType t, const char * szName, const char* szDefault,
FieldValidator validator=NULL, PropertyKind kind=KindBootConfigFile)
{
if (ID) _idToDescDict[ID] =
new BootOptionDesc(ID, cID, t, szName? szName : "", szDefault ? szDefault : "");
if (cID) _contentIdToDescDict[cID] =
new BootOptionDesc(ID, cID, t, szName? szName : "", szDefault ? szDefault : "");
}
// find the desc corresponding to id:
const BootOptionDesc* findOption(void *ID) const
{
std::map<void*, BootOptionDesc*>::const_iterator bod;
if (!ID || (bod=_idToDescDict.find(ID))==_idToDescDict.end()) return NULL;
return bod->second;
}
// find the option bod corresponding to contentID
const BootOptionDesc* findOptionContent(void *cID) const
{
std::map<void*, BootOptionDesc*>::const_iterator bod;
if (!cID || (bod=_contentIdToDescDict.find(cID))==_contentIdToDescDict.end()) return NULL;
return bod->second;
}
// opaque enumeration for the map
const BootOptionDesc* firstOption()
{
_bod=_idToDescDict.begin();
if (_bod!= _idToDescDict.end()) return _bod->second; else return NULL;
}
const BootOptionDesc* nextOption()
{
if(_bod++ ==_idToDescDict.end()) return NULL;
if (_bod != _idToDescDict.end()) return _bod->second; else return NULL;
}
// remove all elements in dict, calls deleteOptionsDesc()
void clearOptionDesc();
protected:
void deleteOptionDesc();
// dictionary for id -> desc and contentID -> desc association type
std::map<void *, BootOptionDesc*> _idToDescDict, _contentIdToDescDict;
std::map<void*, BootOptionDesc*>::const_iterator _bod;
};
//--------------------------------------------------------------------------
// Concrete definition of Chameleon property lists
// implements the Singleton DP
//--------------------------------------------------------------------------
class BootProp : public ChameleonPropertyList {
public:
static BootProp& instance()
{
return _instance ? *_instance : *(_instance=new BootProp());
}
protected:
BootProp() : ChameleonPropertyList() {}
private:
static BootProp* _instance;
};
//--------------------------------------------------------------------------
class PrefsProp : public ChameleonPropertyList {
public:
static PrefsProp& instance()
{
return _instance ? *_instance : *(_instance=new PrefsProp());
}
protected:
PrefsProp() : ChameleonPropertyList() {}
private:
static PrefsProp* _instance;
};
//--------------------------------------------------------------------------
class SmbiosProp : public ChameleonPropertyList {
public:
static SmbiosProp& instance()
{
return _instance ? *_instance : *(_instance=new SmbiosProp());
}
protected:
SmbiosProp() : ChameleonPropertyList() {}
private:
static SmbiosProp* _instance;
};
#endif
trunk/ChameleonPrefPane/Sources/ChameleonPrefPane.mm
1111
1212
1313
14
14
1515
1616
1717
......
3737
3838
3939
40
40
4141
4242
4343
......
6161
6262
6363
64
65
66
67
64
6865
6966
7067
......
9188
9289
9390
94
91
92
9593
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
94
13695
13796
13897
......
145104
146105
147106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
148125
149126
150127
......
187164
188165
189166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
190208
191209
192210
193211
194
195
196
197
198
199
200
201
202
212
213
214
203215
204216
205
206217
207218
208219
......
210221
211222
212223
213
224
214225
215226
216227
217228
218229
219230
220
231
221232
222233
223234
......
235246
236247
237248
238
249
239250
251
252
253
240254
241255
242
256
243257
244258
245259
246
247
260
261
248262
249263
250264
......
257271
258272
259273
260
261274
275
262276
263277
264278
......
271285
272286
273287
274
288
275289
276
290
277291
278292
279293
......
335349
336350
337351
338
339
352
353
340354
341355
342356
343357
344
358
345359
346360
347361
#import "AdvancedSetupController.h"
#include "ShellProcess.h"
#import "BootPropertyList.h"
#import "ChameleonPropertyList.h"
#include <string>
//--------------------------------------------------------------------------
static std::string sCurrentDefaultPartition;
PartitionExtractor * partExtractor=NULL;
BootPropertyList * prop = NULL;
static int currentRowSel = -1;
static ChameleonPrefPane *gInstance = NULL;
mUnknownImage = [self getImageResource: @"Chameleon" ofType: @"tiff"];
// create the propertylist object that will handle com.apple.Boot.plist
if(!prop) prop = new BootPropertyList();
// create the process that will extract the diskutil list infos
// create the process that will extract the diskutil list infos
if(!partExtractor) partExtractor = new PartitionExtractor();
// Retrieve the com.chameleon.prefPane.plist config
}
//--------------------------------------------------------------------------
- (void) loadPreferences
// SFAuthorization implementaion
//--------------------------------------------------------------------------
{
id oldGlobalPreferences = [ [NSDictionary dictionaryWithContentsOfFile:
kPreferencesFilePath ] retain];
mPartitionsDict = [[NSMutableDictionary alloc] init];
[mPartitionsDict retain];
// Initialize bootConfig desc dict
[PreferencesControllerBase doForEachGroup: AddOptionsDesc withOption: nil];
if (oldGlobalPreferences!=nil)
{
mPreferenceFileVersion= [[oldGlobalPreferences objectForKey: keyPreferencesFileVersion] intValue ];
[PreferencesControllerBase setDefaultValues: oldGlobalPreferences];
[mPartitionsDict addEntriesFromDictionary: [oldGlobalPreferences objectForKey: keyPartitionsList] ];
}
else
{ // Create a preference plist file with Defaults values
oldGlobalPreferences = [[NSMutableDictionary alloc] init];
[PreferencesControllerBase doForEachGroup: LoadPreferencesOptions withOption: oldGlobalPreferences];
// Initialize defaults
[oldGlobalPreferences setObject: [[NSNumber alloc] initWithInt: CurrentPreferencesFileVersion]
forKey: keyPreferencesFileVersion];
[oldGlobalPreferences setObject: mPartitionsDict forKey: keyPartitionsList];
// Save the preferences file
[ self savePreferences:oldGlobalPreferences ];
}
mOptionsDict = [[NSMutableDictionary alloc] init];
[mOptionsDict addEntriesFromDictionary:oldGlobalPreferences];
if (mPartitionsDict!=nil) [mPartitionsDict retain];
[oldGlobalPreferences release];
}
//--------------------------------------------------------------------------
/**
* SFAuthorization delegates
*/
// SFAuthorization delegates
- (void)authorizationViewDidAuthorize:(SFAuthorizationView *)view {
[self selectDefaultPartition];
[self refreshLockStates];
}
//--------------------------------------------------------------------------
// Setup security for changing boot options
-(void) initAuthorization
{
AuthorizationItem items = {kAuthorizationRightExecute, 0, NULL, 0};
AuthorizationRights rights = {1, &items};
[authView setAuthorizationRights:&rights];
authView.delegate = self;
[authView updateStatus:nil];
}
//--------------------------------------------------------------------------
- (AuthorizationRef) auth
{
return [self isUnlocked] ? [[authView authorization] authorizationRef] : NULL;
}
//--------------------------------------------------------------------------
- (void) refreshLockStates
{
[mPartitionsTable setEnabled:[self isUnlocked]];
}
//--------------------------------------------------------------------------
- (void) loadPreferences
{
//PrefsProp::instance().open([kPreferencesFilePath UTF8String], CreateIfNotExist,
// [self auth]);
id oldGlobalPreferences = [ [NSDictionary dictionaryWithContentsOfFile:
kPreferencesFilePath ] retain];
mPartitionsDict = [[NSMutableDictionary alloc] init];
[mPartitionsDict retain];
// Initialize bootConfig desc dict
[PreferencesControllerBase doForEachGroup: AddOptionsDesc withOption: nil];
if (oldGlobalPreferences!=nil)
{
mPreferenceFileVersion= [[oldGlobalPreferences objectForKey: keyPreferencesFileVersion] intValue ];
[PreferencesControllerBase doForEachGroup: LoadPreferencesOptions withOption: oldGlobalPreferences];
[mPartitionsDict addEntriesFromDictionary: [oldGlobalPreferences objectForKey: keyPartitionsList] ];
}
else
{ // Create a preference plist file with Defaults values
oldGlobalPreferences = [[NSMutableDictionary alloc] init];
[PreferencesControllerBase loadAllValues: oldGlobalPreferences];
// Initialize defaults
[oldGlobalPreferences setObject: [[NSNumber alloc] initWithInt: CurrentPreferencesFileVersion]
forKey: keyPreferencesFileVersion];
[oldGlobalPreferences setObject: mPartitionsDict forKey: keyPartitionsList];
// Save the preferences file
[ self savePreferences:oldGlobalPreferences ];
}
mOptionsDict = [[NSMutableDictionary alloc] init];
[mOptionsDict addEntriesFromDictionary:oldGlobalPreferences];
if (mPartitionsDict!=nil) [mPartitionsDict retain];
[oldGlobalPreferences release];
}
//--------------------------------------------------------------------------
- (void) initBootConfig
{
static bool ft=true;
// Setup security for changing boot options
AuthorizationItem items = {kAuthorizationRightExecute, 0, NULL, 0};
AuthorizationRights rights = {1, &items};
[authView setAuthorizationRights:&rights];
authView.delegate = self;
[authView updateStatus:nil];
if (!prop->isValid())
[self initAuthorization];
if (!BootProp::instance().isValid())
{
std::string sPath;
AuthorizationRef auth = [self isUnlocked] ? [[authView authorization] authorizationRef] : NULL;
CFStringRef errorString=NULL;
bool cont =true;
const char * szForcedPath = sForcedPath!=nil ? [sForcedPath UTF8String] : NULL;
if (szForcedPath && *szForcedPath)
{
cont = !prop->open(szForcedPath, &errorString, auth);
cont = !BootProp::instance().open(szForcedPath, [self auth]);
}
else {
for(int i=0; szBootPaths[i] && cont; i++)
{
sPath = szBootPaths[i];
sPath += szPropFileName;
cont = !prop->open(sPath.c_str(), &errorString, auth);
cont = !BootProp::instance().open(sPath.c_str(), [self auth]);
}
}
if (cont)
else
{
[mStatusText setTextColor: [NSColor grayColor] ];
NSString* ns = [ [NSString alloc] initWithUTF8String:prop->propFilePath() ];
NSString* ns = [ [NSString alloc] initWithUTF8String:BootProp::instance().propFilePath() ];
[mStatusText setStringValue: [NSString stringWithFormat: @"bootConfig: %@", ns] ];
[[BootSetupController instance]->mBootConfigPathText setStringValue:
[[NSString alloc] initWithUTF8String: BootProp::instance().propFilePath()] ];
}
if (prop->isValid())
if (BootProp::instance().isValid())
{
// read options in the plist file
partExtractor->hidePartitions(prop->getStringForKey(kHidePartition));
partExtractor->renamedPartitions(prop->getStringForKey(kRenamePartition));
partExtractor->hidePartitions(BootProp::instance().getStringForKey(kHidePartition));
partExtractor->renamedPartitions(BootProp::instance().getStringForKey(kRenamePartition));
// partExtractor->resetSwapping();
id val = [mOptionsDict valueForKey: keySwapHD01];
// Load all boot Options into the interface components
[PreferencesControllerBase loadOptionsFromBootFile];
[self selectDefaultPartition];
}
}
[self refreshLockStates];
// try to get the current default partition if any
if(partExtractor && prop && prop->isValid())
if(partExtractor && BootProp::instance().isValid())
{
const char *sdp = prop->getStringForKey(kDefaultPartition);
const char *sdp = BootProp::instance().getStringForKey(kDefaultPartition);
sCurrentDefaultPartition = sdp ? sdp : "";
if (sCurrentDefaultPartition.size())
{
hd[3]= ('0'+partInfo[currentRowSel].disk());
hd[5]= ('0'+partInfo[currentRowSel].partition());
AuthorizationRef auth= [self isUnlocked] ? [[authView authorization] authorizationRef] : NULL;
if(prop->setStringForKey(kDefaultPartition, hd))
prop->save(auth);
if(BootProp::instance().setStringForKey(kDefaultPartition, hd))
BootProp::instance().save(auth);
[ PreferencesControllerBase loadOptionsFromBootFile];
}
else
{ // no line selected
prop->removeKeyAndValue(kDefaultPartition);
BootProp::instance().removeKeyAndValue(kDefaultPartition);
[ PreferencesControllerBase loadOptionsFromBootFile];
}
trunk/ChameleonPrefPane/Sources/PreferencesControllerBase.h
66
77
88
9
9
10
11
1012
11
12
13
1314
1415
1516
......
3132
3233
3334
34
3535
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
5936
6037
6138
6239
6340
64
65
41
42
6643
6744
6845
//
#import <Cocoa/Cocoa.h>
#import <ChameleonPrefPane.h>
#import "ChameleonPrefPane.h"
#import "ChameleonPropertyList.h"
#import "ShellProcess.h"
#import "string_util.h"
#import "BootPropertyList.h"
#import <ShellProcess.h>
#import "GroupControllerProtocol.h"
//--------------------------------------------------------------------------
// ENHANCE ME: remove this globals and integrate them in ChameleonPrefPane or at least
// add function accessor entry points
extern PartitionExtractor * partExtractor;
extern BootPropertyList * prop;
// Defintion of the required protocol for any derived classes of PreferencesControllerBase
@protocol PreferenceController
@required
// must be implemented in all derived classes
// Called by all buttons of each group in therface
- (IBAction) onCheckButtonChange: (NSButton*) sender;
// Called by all text fields of each group in therface
- (IBAction) onTextFiedChange: (NSTextField*) sender;
// Add the boot config options descriptors to the consolidated dictionary
- (void) addOptionsDesc;
// Set refresh all group states {enabled | disabled} depending on the authorizations state
- (void) refreshLockStates;
// load the corresponding pref filer options from the interface
- (void) loadOptionsFromPreferencesFile: (NSMutableDictionary*) dict;
@end
// Define common expected behavior for all derived controllers
@interface PreferencesControllerBase : NSObject
{
}
// from the id to desc map in prop, set all default values for dict
+ (void) setDefaultValues: (NSMutableDictionary*) dict;
// from the id to desc map in BootProp::instance(), load all default values for dict
+ (void) loadAllValues: (NSMutableDictionary*) dict;
// Register the Group panel for further automatic iteration matters
+ (void) registerPreferencesGroup:(id) myGroup;
trunk/ChameleonPrefPane/Sources/PeripheralsController.mm
2121
2222
2323
24
25
26
27
28
29
30
31
32
33
24
25
26
27
28
29
30
31
32
33
3434
3535
3636
37
38
39
40
41
3742
3843
3944
//--------------------------------------------------------------------------
- (void) addOptionsDesc
{
prop->addOptionDesc(mLegacyLogo, nil, OptionYesNo, "Legacy Logo", "No");
prop->addOptionDesc(mBootBanner, nil, OptionYesNo, "Boot Banner", "Yes");
prop->addOptionDesc(mVBIOS, nil, OptionYesNo, "VBIOS", "No");
prop->addOptionDesc(mVideoROM, mVideoROMText, OptionString, "VideoROM", "");
prop->addOptionDesc(mGraphicsMode, mGraphicsModeText, OptionString, "Graphics Mode", "");
prop->addOptionDesc(mGraphicsEnabler, nil, OptionYesNo, "GraphicsEnabler", "No");
prop->addOptionDesc(mUSBBusFix, nil, OptionYesNo, "USBBusFix", "No");
prop->addOptionDesc(mEHCIacquire, nil, OptionYesNo, "EHCIacquire", "No");
prop->addOptionDesc(mUHCIreset, nil,OptionYesNo, "UHCIreset", "No");
prop->addOptionDesc(mEthernetBuiltIn, nil, OptionYesNo, "EthernetBuiltIn", "No");
BootProp::instance().addOptionDesc(mLegacyLogo, nil, OptionYesNo, "Legacy Logo", "No");
BootProp::instance().addOptionDesc(mBootBanner, nil, OptionYesNo, "Boot Banner", "Yes");
BootProp::instance().addOptionDesc(mVBIOS, nil, OptionYesNo, "VBIOS", "No");
BootProp::instance().addOptionDesc(mVideoROM, mVideoROMText, OptionString, "VideoROM", "");
BootProp::instance().addOptionDesc(mGraphicsMode, mGraphicsModeText, OptionString, "Graphics Mode", "");
BootProp::instance().addOptionDesc(mGraphicsEnabler, nil, OptionYesNo, "GraphicsEnabler", "No");
BootProp::instance().addOptionDesc(mUSBBusFix, nil, OptionYesNo, "USBBusFix", "No");
BootProp::instance().addOptionDesc(mEHCIacquire, nil, OptionYesNo, "EHCIacquire", "No");
BootProp::instance().addOptionDesc(mUHCIreset, nil,OptionYesNo, "UHCIreset", "No");
BootProp::instance().addOptionDesc(mEthernetBuiltIn, nil, OptionYesNo, "EthernetBuiltIn", "No");
}
//--------------------------------------------------------------------------
-(void) setDefaultsValues: (NSMutableDictionary*) dict
{
}
//--------------------------------------------------------------------------
- (void) refreshLockStates
{
// automatic, nothing to do
trunk/ChameleonPrefPane/Sources/ShellProcess.h
1414
1515
1616
17
17
1818
1919
2020
2121
22
23
24
25
26
27
28
29
30
31
32
33
34
35
3622
3723
3824
#include <sys/stat.h>
#include <vector>
#include <string>
#include "file_util.h"
//----------------------------------------------------------------
const int MAX_HD = 10;
//----------------------------------------------------------------
/**
* Check whether file exists:
*/
inline bool fileExists(const char * str)
{
struct stat stFileInfo;
if((stat(str,&stFileInfo)) == 0) return true;
else return false;
}
inline bool fileExists(std::string str) {return fileExists(str.c_str());}
//----------------------------------------------------------------
class ShellProcess
{
public:
trunk/ChameleonPrefPane/Sources/BootFlagsController.mm
2525
2626
2727
28
29
30
31
32
33
34
35
36
37
38
28
29
30
31
32
33
34
35
36
37
38
3939
4040
4141
42
43
44
45
4246
4347
4448
//--------------------------------------------------------------------------
-(void) addOptionsDesc
{
prop->addOptionDesc(mVerbose, nil, OptionUnix, "-v", "");
prop->addOptionDesc(mSafeBoot, nil, OptionUnix, "-x", "");
prop->addOptionDesc(mIgnoreBootConfig, nil, OptionUnix, "-F", "");
prop->addOptionDesc(mSingleUser, nil, OptionUnix, "-s", "");
prop->addOptionDesc(mTimeOut, mTimeOutText, OptionString,"Timeout", "5");
prop->addOptionDesc(mQuietBoot, nil, OptionYesNo, "Quiet Boot", "No");
prop->addOptionDesc(mInstantMenu, nil, OptionYesNo, "Instant Menu", "No");
prop->addOptionDesc(mWait, nil, OptionYesNo, "Wait", "No");
prop->addOptionDesc(mRescan, nil, OptionYesNo, "Rescan", "No");
prop->addOptionDesc(mRescanPrompt, nil, OptionYesNo, "Rescan Prompt", "No");
prop->addOptionDesc(mRescanSingleDrive, nil, OptionYesNo, "Rescan SingleDrive", "No");
BootProp::instance().addOptionDesc(mVerbose, nil, OptionUnix, "-v", "");
BootProp::instance().addOptionDesc(mSafeBoot, nil, OptionUnix, "-x", "");
BootProp::instance().addOptionDesc(mIgnoreBootConfig, nil, OptionUnix, "-F", "");
BootProp::instance().addOptionDesc(mSingleUser, nil, OptionUnix, "-s", "");
BootProp::instance().addOptionDesc(mTimeOut, mTimeOutText, OptionString,"Timeout", "5");
BootProp::instance().addOptionDesc(mQuietBoot, nil, OptionYesNo, "Quiet Boot", "No");
BootProp::instance().addOptionDesc(mInstantMenu, nil, OptionYesNo, "Instant Menu", "No");
BootProp::instance().addOptionDesc(mWait, nil, OptionYesNo, "Wait", "No");
BootProp::instance().addOptionDesc(mRescan, nil, OptionYesNo, "Rescan", "No");
BootProp::instance().addOptionDesc(mRescanPrompt, nil, OptionYesNo, "Rescan Prompt", "No");
BootProp::instance().addOptionDesc(mRescanSingleDrive, nil, OptionYesNo, "Rescan SingleDrive", "No");
}
//--------------------------------------------------------------------------
-(void) setDefaultsValues: (NSMutableDictionary*) dict
{
}
//--------------------------------------------------------------------------
- (void) refreshLockStates
{
// automatic, nothing to do
trunk/ChameleonPrefPane/Sources/BootSetupController.mm
2525
2626
2727
28
29
30
28
29
30
3131
3232
3333
......
3838
3939
4040
41
4142
4243
4344
44
45
4546
46
47
48
47
48
49
4950
5051
5152
5253
5354
54
55
56
55
56
57
58
59
60
61
62
5763
5864
5965
......
106112
107113
108114
109
115
110116
111117
112118
......
205211
206212
207213
208
209214
210215
211
212
213
214
215
216
217
218
219
216220
217221
218
219
220
222
223
221224
222225
223226
......
249252
250253
251254
252
253255
254256
255257
......
266268
267269
268270
271
269272
273
274
275
276
277
278
270279
271280
272281
//--------------------------------------------------------------------------
- (void) addOptionsDesc
{
prop->addOptionDesc(mDefaultPartition, mDefaultPartitionText, OptionString, "Default Partition", "");
prop->addOptionDesc(mHidePartition , mHidePartitionText, OptionString, "Hide Partition", "");
prop->addOptionDesc(mRenamePartition , mRenamePartitionText, OptionString, "Rename Partition", "");
BootProp::instance().addOptionDesc(mDefaultPartition, mDefaultPartitionText, OptionString, "Default Partition", "");
BootProp::instance().addOptionDesc(mHidePartition , mHidePartitionText, OptionString, "Hide Partition", "");
BootProp::instance().addOptionDesc(mRenamePartition , mRenamePartitionText, OptionString, "Rename Partition", "");
}
//--------------------------------------------------------------------------
[PreferencesControllerBase refreshLockState: mSwapHD02 ];
[PreferencesControllerBase refreshLockState: mFreezeParts ];
[PreferencesControllerBase refreshLockState: mInjectFrozenParts ];
[PreferencesControllerBase refreshLockState: mBootConfigPath ];
}
//--------------------------------------------------------------------------
-(void) setDefaultsValues: (NSMutableDictionary*) dict
- (void) setDefaultsValues: (NSMutableDictionary*) dict
{
[mSwapHD01 setIntValue: [[dict objectForKey:keySwapHD01] intValue]];
[mSwapHD02 setIntValue: [[dict objectForKey:keySwapHD02] intValue]];
[mFreezeParts setIntValue: [[dict objectForKey: keyUseFrozenParts] intValue] ];
[dict setObject: [[NSNumber alloc] initWithBool: false] forKey: keySwapHD01];
[dict setObject: [[NSNumber alloc] initWithBool: false] forKey: keySwapHD02];
[dict setObject:[[NSNumber alloc] initWithBool: false] forKey: keyUseFrozenParts];
}
//--------------------------------------------------------------------------
-(void) loadOptionsFromPreferencesFile: (NSMutableDictionary*) dict
{
[dict setObject: [[NSNumber alloc] initWithBool: false] forKey: keySwapHD01];
[dict setObject: [[NSNumber alloc] initWithBool: false] forKey: keySwapHD02];
[dict setObject:[[NSNumber alloc] initWithBool: false] forKey: keyUseFrozenParts];
[mSwapHD01 setIntValue: [[dict objectForKey:keySwapHD01] intValue]];
[mSwapHD02 setIntValue: [[dict objectForKey:keySwapHD02] intValue]];
[mFreezeParts setIntValue: [[dict objectForKey: keyUseFrozenParts] intValue] ];
id obj = [dict objectForKey: keyForceBootConfigPath];
[mBootConfigPathText setStringValue: obj ];
int val = ([[mBootConfigPathText stringValue] length] >0 ? 1 : 0);
[mBootConfigPath setIntValue: val];
}
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
- (void) swapDisks: (bool) bSwap src: (int) iSrc dst: (int) iDst;
{
if(!partExtractor || !prop || !prop->isValid()) return;
if(!partExtractor || !BootProp::instance().isValid()) return;
if (bSwap)
{
partExtractor->swapHD(iSrc, iDst);
if (sender == mBootConfigPath)
{
int val = [mBootConfigPath intValue];
std::string content = [[mBootConfigPathText stringValue] UTF8String];
[mBootConfigPathText setEnabled: val ? true : false];
[mBootConfigPathText setEditable: val ? true : false];
if (val)
{
}
[[self preferencesFile] setObject:
val ? [mBootConfigPathText stringValue] : [[NSString alloc] initWithUTF8String: ""]
forKey: keyForceBootConfigPath];
}
else
{ // TextField
}
[[self preferencesFile] setObject: [mBootConfigPathText stringValue] forKey: keyForceBootConfigPath];
[self savePreferences ];
[PreferencesControllerBase loadOptionsFromBootFile ];
|| sender == mRenamePartition )
{ // sync with other panels
[self handleSender:sender];
[PreferencesControllerBase loadOptionsFromBootFile ];
}
else if (sender == mBootConfigPath || (NSTextField*)sender == mBootConfigPathText)
{ // sync with other panels
sender == mRenamePartitionText )
{
[self handleSender:sender];
[PreferencesControllerBase loadOptionsFromBootFile ];
partExtractor->extractPartitions(
[[mHidePartitionText stringValue] UTF8String],
[[mRenamePartitionText stringValue] UTF8String]
);
[self doSwapHD: [mSwapHD01 intValue] save:true src:0 dst:1];
[self doSwapHD: [mSwapHD02 intValue] save:true src:0 dst:2];
}
}
trunk/ChameleonPrefPane/Sources/PropertyList.cpp
55
66
77
8
8
9
910
1011
1112
12
13
14
15
13
14
15
16
1617
1718
1819
......
9899
99100
100101
101
102
103
104
102105
103106
104107
......
118121
119122
120123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
121143
122
123
124
125
144
145
146
126147
127148
128149
......
143164
144165
145166
146
147
148
149
150
167
168
169
170
171
172
173
151174
152175
153176
154177
155
178
179
180
181
182
183
184
185
186
187
188
189
190
156191
157192
158193
......
174209
175210
176211
177
178
179
180
212
213
214
215
181216
182217
183218
......
186221
187222
188223
189
190
191
192
224
225
226
193227
194228
195229
196230
197231
198232
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215233
216
217
218
219
220
234
235
236
237
221238
222239
223240
......
225242
226243
227244
228
229
230
231245
232246
233247
......
242256
243257
244258
245
259
260
261
246262
263
264
265
266
267
247268
248269
249270
250271
251272
252
253
254273
255274
256275
257276
258
259
260
261
277
278
279
262280
263281
264282
......
279297
280298
281299
282
283
284
285
286
300
301
302
303
287304
288305
289306
......
300317
301318
302319
303
304
305
306
307
320
321
322
323
324
308325
309326
310327
......
323340
324341
325342
326
327
328
329
343
344
345
330346
331347
332348
*
*/
#import "BootPropertyList.h"
#import "ChameleonPropertyList.h"
#include "file_util.h"
#include <string.h>
#include <sys/stat.h>
/****************************************************************************/
/**
* Simple parsing and splitting args function, does handle env. vars
*/
//--------------------------------------------------------------------------
// Simple parsing and splitting args function, does handle env. vars
//--------------------------------------------------------------------------
static void parseArgs(const char * args, const char* argv[], int argvlen)
{
// Create a list of args fron the space delimited args parameters
argv[n]=NULL;
}
/****************************************************************************/
//--------------------------------------------------------------------------
// Execute a priviledge shell command
//--------------------------------------------------------------------------
bool executePrivilegedCmd(AuthorizationRef auth,
const char* pathToTool,
const char* args,
return status ? false : true;
}
//--------------------------------------------------------------------------
// Execute priviledged chmod for accessing system files
//--------------------------------------------------------------------------
bool PropertyList::chmodFile(const char * path, const char * chmodMask,
AuthorizationRef auth, AuthorizationFlags flags)
{
if (!path || !*path) return false;
if (auth)
{ // give write temporary write rights to the file
std::string args = chmodMask;
args += ' ';
args += path;
if(!executePrivilegedCmd(auth, "/bin/chmod", args.c_str(), flags))
return false;
}
return true;
}
/****************************************************************************/
/**
* Write a property list from a file
*/
//--------------------------------------------------------------------------
// Write a property list from a file
//--------------------------------------------------------------------------
bool WritePropertyListToFile( CFPropertyListRef propertyList, CFURLRef fileURL )
{
CFDataRef xmlData;
return status ? true: false;
}
/****************************************************************************/
/**
* Read a property list from a file
*/
static CFPropertyListRef CreatePropertyListFromFile( CFURLRef fileURL, CFStringRef * errorString ) {
//--------------------------------------------------------------------------
// Read a property list from a file
//--------------------------------------------------------------------------
static CFPropertyListRef CreatePropertyListFromFile( CFURLRef fileURL,
const std::string& filePath,
CFStringRef * errorString,
bool createIfNotExist) {
CFPropertyListRef propertyList;
CFDataRef resourceData;
Boolean status;
SInt32 errorCode;
//
if (!fileExists(filePath))
{
if (createIfNotExist)
{
CFMutableDictionaryRef dict =
CFDictionaryCreateMutable( kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks );
WritePropertyListToFile(dict, fileURL);
}
}
// Read the XML file.
status = CFURLCreateDataAndPropertiesFromResource(
kCFAllocatorDefault,
return propertyList;
}
/****************************************************************************/
/*
* Always return a valid static const string, if the CFSTR is not valid, then we return ""
*/
//--------------------------------------------------------------------------
// Always return a valid static const string,
// if the CFSTR is not valid, then we return ""
//--------------------------------------------------------------------------
static const char * CfsToCs(CFStringRef inRef)
{
static char buffer[512]="";
return "";
}
/****************************************************************************/
/**
* Creates a PropertyList Incstance
*/
//--------------------------------------------------------------------------
// Destruct a PropertyList Instance
//--------------------------------------------------------------------------
PropertyList::~PropertyList()
{
if (_CFURLRef) CFRelease(_CFURLRef);
if (_proplistRef) CFRelease(_proplistRef);
}
bool PropertyList::chmodFile(const char * path, const char * chmodMask,
AuthorizationRef auth, AuthorizationFlags flags)
{
if (!path || !*path) return false;
if (auth)
{ // give write temporary write rights to the file
std::string args = chmodMask;
args += ' ';
args += path;
if(!executePrivilegedCmd(auth, "/bin/chmod", args.c_str(), flags))
return false;
}
return true;
}
/****************************************************************************/
/**
* Open a properlist from a path name
*/
bool PropertyList::open(const char * path, CFStringRef * errorString, AuthorizationRef auth, AuthorizationFlags flags)
//--------------------------------------------------------------------------
// Open a property list from a path name with auth
//--------------------------------------------------------------------------
bool PropertyList::open(const char * path, bool createIfNotExist, AuthorizationRef auth, AuthorizationFlags flags)
{
bool ret = false;
struct stat st;
if(stat(path,&st) != 0) return false; // file does not exist;
// give write temporary write rights to the file
if (!chmodFile(path,"0777", auth, flags)) return false;
_propFilePath = path;
CFStringRef cfPath = CFStringCreateWithCString (kCFAllocatorDefault, path, kCFStringEncodingUTF8);
if (_CFURLRef)
{
CFRetain(_CFURLRef);
_proplistRef = CreatePropertyListFromFile(inURL, errorString);
// give write temporary write rights to the file
if (!chmodFile(path,"0777", auth, flags)) return false;
_proplistRef = CreatePropertyListFromFile(inURL, _propFilePath, &_errorString, createIfNotExist);
// restore rights
ret= chmodFile(path,"0644", auth, flags);
if (_proplistRef) {
CFRetain(_proplistRef);
ret= true;
}
}
// restore rights
ret= chmodFile(path,"0644", auth, flags);
return ret;
}
/****************************************************************************/
/**
* Save the current property list
*/
//--------------------------------------------------------------------------
// Save the current property list
//--------------------------------------------------------------------------
bool PropertyList::save(AuthorizationRef auth, AuthorizationFlags flags)
{
bool ret=false;
return ret;
}
/****************************************************************************/
/**
* Extract a sring value from a property list key,
* value returned is not owned by caller, copy it necessary.
*/
//--------------------------------------------------------------------------
// Get a string value from a property list key,
// value returned is not owned by caller, copy it necessary.
//--------------------------------------------------------------------------
const char * PropertyList::getStringForKey(const char *key)
{
if (!_proplistRef) return NULL;
if(cfKey) CFRelease(cfKey);
return NULL;
}
/****************************************************************************/
/**
* replace a sring value from a property list key,
* value returned is not owned by caller, copy it necessary.
*/
//--------------------------------------------------------------------------
// Replace or add a string value from a property list key,
// value returned is not owned by caller, copy it necessary.
//--------------------------------------------------------------------------
bool PropertyList::setStringForKey(const char *key, const char * value)
{
if (!_proplistRef) return false;
return ret;
}
/****************************************************************************/
/**
* delete a key and its value from the dictionary
*/
//--------------------------------------------------------------------------
// Delete a key and its value from the dictionary
//--------------------------------------------------------------------------
bool PropertyList::removeKeyAndValue(const char *key)
{
if (!_proplistRef) return false;
trunk/ChameleonPrefPane/Sources/file_util.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/*
* file_util.h
* ChameleonPrefPane
*
* Created by Rekursor on 1/24/10.
*
*/
#ifndef __CHFILE_UTIL_H
#define __CHFILE_UTIL_H
#include <sys/stat.h>
/**
* Check whether file exists:
*/
inline bool fileExists(const char * str)
{
struct stat stFileInfo;
if((stat(str,&stFileInfo)) == 0) return true;
else return false;
}
inline bool fileExists(std::string str) {return fileExists(str.c_str());}
#endif
trunk/ChameleonPrefPane/Sources/AdvancedSetupController.mm
2121
2222
2323
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
4040
4141
4242
43
44
45
46
47
4348
4449
4550
//--------------------------------------------------------------------------
- (void) addOptionsDesc
{
prop->addOptionDesc(mKernel, mKernelText, OptionKernel1, "Kernel", "mach_kernel"); // empty field for 1 field only "i.e: mach_kernel" syntax
prop->addOptionDesc(mDeviceRd, mDeviceRdText, OptionKernel, "rd", "");
prop->addOptionDesc(mArch, mArchText, OptionKernel, "arch", "");
prop->addOptionDesc(mCPU, mCPUText, OptionKernel, "cpus", "");
prop->addOptionDesc(mBusRatio, mBusRatioText, OptionKernel, "busratio", "");
prop->addOptionDesc(mDebug, mDebugText, OptionString, "debug", "");
prop->addOptionDesc(mIO, mIOText, OptionString, "io", "");
prop->addOptionDesc(mDisableKextsBlacklisting, nil, OptionString, "blacklist", "");
prop->addOptionDesc(mDSDTFile, mDSDTFileText, OptionString, "DSDT", "");
prop->addOptionDesc(mDSDTDrop, nil, OptionYesNo, "DropSSDT", "No");
prop->addOptionDesc(mSMBIOSFile,mSMBIOSFileText, OptionString, "SMBIOS", "");
prop->addOptionDesc(mSMBIOSDefaults, nil, OptionYesNo, "SMBIOSdefaults", "No");
prop->addOptionDesc(mWake, nil, OptionYesNo, "Wake", "No");
prop->addOptionDesc(mForceWake, nil, OptionYesNo, "ForceWake", "No");
prop->addOptionDesc(mWakeImage, mWakeImageText, OptionString, "WakeImage", "");
prop->addOptionDesc(mSystemId, mSystemIdText, OptionString, "SystemId", "");
BootProp::instance().addOptionDesc(mKernel, mKernelText, OptionKernel1, "Kernel", "mach_kernel"); // empty field for 1 field only "i.e: mach_kernel" syntax
BootProp::instance().addOptionDesc(mDeviceRd, mDeviceRdText, OptionKernel, "rd", "");
BootProp::instance().addOptionDesc(mArch, mArchText, OptionKernel, "arch", "");
BootProp::instance().addOptionDesc(mCPU, mCPUText, OptionKernel, "cpus", "");
BootProp::instance().addOptionDesc(mBusRatio, mBusRatioText, OptionKernel, "busratio", "");
BootProp::instance().addOptionDesc(mDebug, mDebugText, OptionString, "debug", "");
BootProp::instance().addOptionDesc(mIO, mIOText, OptionString, "io", "");
BootProp::instance().addOptionDesc(mDisableKextsBlacklisting, nil, OptionString, "blacklist", "");
BootProp::instance().addOptionDesc(mDSDTFile, mDSDTFileText, OptionString, "DSDT", "");
BootProp::instance().addOptionDesc(mDSDTDrop, nil, OptionYesNo, "DropSSDT", "No");
BootProp::instance().addOptionDesc(mSMBIOSFile,mSMBIOSFileText, OptionString, "SMBIOS", "");
BootProp::instance().addOptionDesc(mSMBIOSDefaults, nil, OptionYesNo, "SMBIOSdefaults", "No");
BootProp::instance().addOptionDesc(mWake, nil, OptionYesNo, "Wake", "No");
BootProp::instance().addOptionDesc(mForceWake, nil, OptionYesNo, "ForceWake", "No");
BootProp::instance().addOptionDesc(mWakeImage, mWakeImageText, OptionString, "WakeImage", "");
BootProp::instance().addOptionDesc(mSystemId, mSystemIdText, OptionString, "SystemId", "");
}
//--------------------------------------------------------------------------
-(void) setDefaultsValues: (NSMutableDictionary*) dict
{
}
//--------------------------------------------------------------------------
- (void) refreshLockStates
{
// automatic, nothing to do
trunk/ChameleonPrefPane/Sources/PropertyList.h
1212
1313
1414
15
15
1616
17
18
19
17
18
19
20
21
22
23
2024
2125
2226
2327
2428
25
2629
27
28
29
30
31
32
3033
3134
3235
3336
37
3438
3539
3640
41
3742
3843
39
40
41
44
45
46
47
48
49
50
51
4252
53
54
55
56
4357
4458
4559
4660
4761
4862
63
64
4965
5066
5167
5268
5369
70
71
5472
5573
74
5675
5776
77
5878
5979
6080
6181
6282
6383
84
6485
6586
6687
#include <Security/Authorization.h>
#include <string>
/****************************************************************/
//----------------------------------------------------------------------------
/**
* priviledged command run for cmds like property chmods and restard command
*/
static const bool CreateIfNotExist = true;
static const bool DontCreate = false;
//----------------------------------------------------------------------------
/// Run priviledged command for cmds like property chmods and restard command
//----------------------------------------------------------------------------
bool executePrivilegedCmd(AuthorizationRef auth,
const char* pathToTool,
const char* args=NULL,
AuthorizationFlags flags=kAuthorizationFlagDefaults);
/****************************************************************/
/**
* Simple PropertyList Abstraction
*/
//----------------------------------------------------------------------------
/// Simple PropertyList Abstraction
//----------------------------------------------------------------------------
class PropertyList
{
public:
// Create a property list
PropertyList() : _proplistRef(0), _CFURLRef(0) {}
virtual ~PropertyList();
/// Tell if a valid property list successfully opened
bool isValid() const { return _proplistRef!=NULL;}
bool open(const char *propListPath, CFStringRef* errString,
AuthorizationRef auth=NULL, AuthorizationFlags flags=kAuthorizationFlagDefaults);
bool save(AuthorizationRef auth=NULL, AuthorizationFlags flags=kAuthorizationFlagDefaults);
/// Open a property list
bool open(const char *propListPath, bool createIfNotExist,
AuthorizationRef auth=NULL,
AuthorizationFlags flags=kAuthorizationFlagDefaults);
/// Save a property list
bool save(AuthorizationRef auth=NULL,
AuthorizationFlags flags=kAuthorizationFlagDefaults);
/// Return last error status, used in open()
CFStringRef lastError() const { return _errorString;}
/// Get a corresponding string content from a key spec
const char * getStringForKey(const char *key);
const char * getStringForKey(const std::string& key)
{
std::string str= key;
return getStringForKey(str.c_str());
}
/// Set a content from a string, at specified key
bool setStringForKey(const char* key, const char* value);
bool setStringForKey(const std::string& key, const std::string& value)
{
return setStringForKey(key.c_str(), value.c_str());
}
/// Remove a key from the Proplist
bool removeKeyAndValue(const char *key);
/// Get the property list path
const char * propFilePath() const {return _propFilePath.c_str(); }
/// permit to execute a priviledge chmod to access system files
static bool chmodFile(const char * path, const char * chmodMask,
AuthorizationRef auth, AuthorizationFlags flags=kAuthorizationFlagDefaults);
protected:
CFPropertyListRef _proplistRef;
CFURLRef _CFURLRef;
std::string _propFilePath; // keep a track of the proplist filename
CFStringRef _errorString;
};
#endif
trunk/ChameleonPrefPane/Sources/PeripheralsController.h
1010
1111
1212
13
13
1414
1515
1616
......
3333
3434
3535
36
3637
3738
3839
// TabView subpane controller definition
@interface PeripheralsController : PreferencesControllerBase <PreferenceController>
@interface PeripheralsController : PreferencesControllerBase <GroupControllerProtocol>
{
IBOutlet NSButton*mLegacyLogo;
- (IBAction) onCheckButtonChange: (NSButton*) sender;
- (IBAction) onTextFiedChange: (NSTextField*) sender;
- (void) setDefaultsValues: (NSMutableDictionary*) dict;
+ (PeripheralsController *)instance;
trunk/ChameleonPrefPane/Sources/GroupControllerProtocol.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//
// GroupControllerProtocol.h
// ChameleonPrefPane
//
// Created by Fabien on 1/25/10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import <Cocoa/Cocoa.h>
// Defintion of the required protocol for any derived classes of PreferencesControllerBase
@protocol GroupControllerProtocol
@required
// must be implemented in all derived classes
// Called by all buttons of each group in therface
- (IBAction) onCheckButtonChange: (NSButton*) sender;
// Called by all text fields of each group in therface
- (IBAction) onTextFiedChange: (NSTextField*) sender;
// Add the boot config options descriptors to the consolidated dictionary
- (void) addOptionsDesc;
// Permit to each group to customize his default settings
- (void) setDefaultsValues: (NSMutableDictionary*) dict;
// Set refresh all group states {enabled | disabled} depending on the authorizations state
- (void) refreshLockStates;
// load the corresponding pref filer options from the interface
- (void) loadOptionsFromPreferencesFile: (NSMutableDictionary*) dict;
@end
trunk/ChameleonPrefPane/Sources/PreferencesControllerBase.mm
1414
1515
1616
17
17
1818
1919
2020
......
3939
4040
4141
42
43
42
43
4444
45
45
46
4647
4748
4849
......
9091
9192
9293
93
94
94
95
96
9597
9698
9799
......
106108
107109
108110
109
111
110112
111113
112114
......
133135
134136
135137
136
138
137139
138
140
141
142
139143
140144
141145
......
145149
146150
147151
148
152
149153
150154
151155
152156
153157
154158
155
159
156160
157161
158162
......
244248
245249
246250
251
247252
248253
249254
......
252257
253258
254259
255
260
256261
257
262
258263
259264
260265
261
262
263
266
267
268
264269
265270
266271
267272
268
269
273
274
270275
271
276
272277
273
278
274279
275280
281
276282
277283
278
284
279285
280286
281287
......
283289
284290
285291
286
292
287293
288294
289295
290296
291297
292
298
293299
294300
295301
......
302308
303309
304310
305
311
306312
307313
308314
......
322328
323329
324330
325
331
326332
327333
328
334
329335
330336
331337
//--------------------------------------------------------------------------
static std::list<id> groupList;
static std::list< id<GroupControllerProtocol> > groupList;
// for unix-like options types
static std::map<void*, std::string> IdToUCmdList;
}
//--------------------------------------------------------------------------
// from the id to desc map in prop, set all default values for dict
+ (void) setDefaultValues: (NSMutableDictionary*) dict
// from the id to desc map in BootProp()., set all default values for dict
+ (void) loadAllValues: (NSMutableDictionary*) dict
{
for(const BootOptionDesc* bod = prop->firstOption();bod; bod=prop->nextOption())
[self doForEachGroup:LoadPreferencesOptions withOption: dict];
for(const BootOptionDesc* bod = BootProp::instance().firstOption();bod; bod=BootProp::instance().nextOption())
{
switch (bod->Type)
{
//--------------------------------------------------------------------------
+ (void) refreshLockStates
{
for (const BootOptionDesc* bod=prop->firstOption(); bod; bod=prop->nextOption())
for (const BootOptionDesc* bod=BootProp::instance().firstOption();
bod;
bod=BootProp::instance().nextOption())
{
[self refreshLockState: (id) bod->ID ];
if (bod->contentID) [self refreshLockState: (id) bod->contentID ];
{
switch (action) {
case SetDefaultValues:
[*it setDefaultValues: option];
[*it setDefaultsValues: option];
break;
case RefreshLockStates:
[*it refreshLockStates ];
+ (void) loadOptionsFromBootFile
{
// parse unix like command string:
kernelFlags.parseOptions(prop->getStringForKey(kKernelFlags));
kernelFlags.parseOptions(BootProp::instance().getStringForKey(kKernelFlags));
for (const BootOptionDesc* bod=prop->firstOption(); bod; bod=prop->nextOption())
for (const BootOptionDesc* bod=BootProp::instance().firstOption();
bod;
bod=BootProp::instance().nextOption())
{
[PreferencesControllerBase loadOptionFromBootFile:(id)bod->ID ];
}
+ (void) loadOptionFromBootFile:(id) optionID
{
const BootOptionDesc* bod = prop->findOption(optionID);
const BootOptionDesc* bod = BootProp::instance().findOption(optionID);
if (!bod)
{
NSRunAlertPanel(@"Error Parsing Option",@"loadOptionFromBootFile failed",@"OK", nil, nil);
return;
}
const char * stringForKey = prop->getStringForKey(bod->Name);
const char * stringForKey = BootProp::instance().getStringForKey(bod->Name);
std::string s = stringForKey ? trim(stringForKey) : "";
switch (bod->Type)
int val = [(NSButton*) sender intValue ];
std::string sDefaultValue = trim(bod->Default ? bod->Default : "");
bool status = false;
std::string name = trim(bod->Name);
switch (bod->Type) {
case OptionYesNo:
if (sDefaultValue.length()==0) sDefaultValue= "No";
// Avoid populating bootConfig with unnecessary options:
if (sVal == sDefaultValue)
status = prop->removeKeyAndValue(bod->Name);
status = BootProp::instance().removeKeyAndValue(name.c_str());
else
status = prop->setStringForKey(bod->Name, sVal.c_str());
status = BootProp::instance().setStringForKey(name, sVal.c_str());
}
break;
case OptionUnix:
if (!val)kernelFlags.removeFlag(bod->Name);
elsekernelFlags.addFlag(bod->Name);
prop->setStringForKey(kKernelFlags,kernelFlags.options());
if (!val)kernelFlags.removeFlag(name);
elsekernelFlags.addFlag(name);
BootProp::instance().setStringForKey(kKernelFlags,kernelFlags.options());
status = true;
break;
case OptionKernel:
{
std::string contentValue =
[ [(NSTextField*) bod->contentID stringValue] UTF8String ];
std::string contentValue = trim(
[ [(NSTextField*) bod->contentID stringValue] UTF8String ]);
kernelFlags.removeFlag(kernelFlags.stringFromKey(bod->Name));
if(val)
if(val && contentValue.length()>0)
{
std::string concat = bod->Name;
std::string concat = trim(name);
concat+= "=";
concat+= trim(contentValue);
kernelFlags.addFlag(concat);
}
prop->setStringForKey(kKernelFlags,kernelFlags.options());
BootProp::instance().setStringForKey(kKernelFlags,kernelFlags.options());
status = true;
}
break;
case OptionString:
// Avoid populating bootConfig with unnecessary options:
if (val == 0 && bod->Type!=OptionKernel1)
status = prop->removeKeyAndValue(bod->Name);
status = BootProp::instance().removeKeyAndValue(bod->Name);
else
{
std::string contentValue =
[ [(NSTextField*) bod->contentID stringValue] UTF8String ];
if (contentValue.length()>0)
status = prop->setStringForKey(bod->Name, contentValue.c_str());
status = BootProp::instance().setStringForKey(bod->Name, contentValue.c_str());
else {
return false; // no content to save so don't save it
}
// Now save the bootConfig
AuthorizationRef auth = [self getAuthorization ];
if (status)status = prop->save(auth);
if (status)status = BootProp::instance().save(auth);
return status;
}
- (bool) handleSender: (id) sender
{
const BootOptionDesc * bod = prop->findOption(sender);
const BootOptionDesc * bod = BootProp::instance().findOption(sender);
if (!bod) {
bod = prop->findOptionContent(sender);
bod = BootProp::instance().findOptionContent(sender);
NSTextField* textField = (NSTextField*) sender;
std::string content = [[textField stringValue] UTF8String ];
if(bod->ID!=nil) sender = (id) bod->ID;
trunk/ChameleonPrefPane/Sources/KernOptionsParser.cpp
6262
6363
6464
65
6566
6667
6768
......
7172
7273
7374
75
7476
std::string::size_type found = _options.find(flag);
if (found==std::string::npos) return;
_options.erase(found, found+flag.length());
_options = trim(_options);
}
// remove a flag in the string
if (found!=std::string::npos) return;
_options = " " + _options;
_options = flag + _options;
_options = trim(_options);
}
trunk/ChameleonPrefPane/Sources/BootFlagsController.h
1010
1111
1212
13
13
1414
1515
1616
......
3232
3333
3434
35
3536
3637
3738
// TabView subpane controller definition
@interface BootFlagsController : PreferencesControllerBase <PreferenceController>
@interface BootFlagsController : PreferencesControllerBase <GroupControllerProtocol>
{
IBOutlet NSButton*mVerbose;
- (IBAction) onCheckButtonChange: (NSButton*) sender;
- (IBAction) onTextFiedChange: (NSTextField*) sender;
- (void) setDefaultsValues: (NSMutableDictionary*) dict;
+ (BootFlagsController *)instance;
trunk/ChameleonPrefPane/Sources/ChameleonPropertyList.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
* ChameleonPropertyList.cpp
* ChameleonPrefPane
*
* Created by Rekursor on 1/22/10.
*
*/
#include "ChameleonPropertyList.h"
PrefsProp* PrefsProp::_instance = NULL;
BootProp* BootProp::_instance = NULL;
SmbiosProp* SmbiosProp::_instance = NULL;
void ChameleonPropertyList::deleteOptionDesc()
{
// delete all alloc'ed pointers
std::map<void*, BootOptionDesc*>::iterator bod;
for (bod=_idToDescDict.begin(); bod!=_idToDescDict.end(); bod++)
if(bod->second) delete bod->second;
for (bod=_contentIdToDescDict.begin(); bod!=_contentIdToDescDict.end(); bod++)
if(bod->second) delete bod->second;
}
void ChameleonPropertyList::clearOptionDesc()
{
deleteOptionDesc();
_idToDescDict.clear();// now clear the pairs
_contentIdToDescDict.clear();// now clear the pairs
}
trunk/ChameleonPrefPane/Sources/BootSetupController.h
1414
1515
1616
17
17
1818
1919
2020
......
3838
3939
4040
41
41
4242
4343
44
4445
4546
4647
static const char* const kRenamePartition = "Rename Partition";
// TabView subpane controller definition
@interface BootSetupController : PreferencesControllerBase <PreferenceController>
@interface BootSetupController : PreferencesControllerBase <GroupControllerProtocol>
{
@public
IBOutlet NSButton *mSwapHD01;
- (IBAction) onCheckButtonChange: (NSButton*) sender;
- (IBAction) onTextFiedChange: (NSTextField*) sender;
- (IBAction) onForceBootConfigPath: (id) sender;
- (void) setDefaultsValues: (NSMutableDictionary*) dict;
- (void) doSwapHD: (int) val save: (bool) doSave src: (int) isrc dst: (int) idst;
- (IBAction) onForceBootConfigPath: (id) sender;
+ (BootSetupController *)instance;

Archive Download the corresponding diff file

Revision: 51