Index: trunk/ChameleonPrefPane/Sources/property_list.cpp =================================================================== --- trunk/ChameleonPrefPane/Sources/property_list.cpp (revision 16) +++ trunk/ChameleonPrefPane/Sources/property_list.cpp (revision 17) @@ -214,6 +214,22 @@ 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; + +} /****************************************************************************/ /** @@ -225,12 +241,8 @@ if (!path || !*path) return false; - if (auth) - { // give write temporary write rights to the file - std::string args = " 0777 "+ _propFilePath; - if(!executePrivilegedCmd(auth, "/bin/chmod", args.c_str(), flags)) - return false; - } + // give write temporary write rights to the file + if (!chmodFile(path,"0777", auth, flags)) return false; _propFilePath = path; @@ -250,12 +262,8 @@ if (_proplistRef) ret= true; } - if (auth) - { // give write temporary write rights to the file - std::string args = " 0644 "+ _propFilePath; - if(!executePrivilegedCmd(auth, "/bin/chmod", args.c_str(), flags)) - ret= false; - } + // restore rights + ret= chmodFile(path,"0644", auth, flags); return ret; } Index: trunk/ChameleonPrefPane/Sources/ChameleonPrefPane.h =================================================================== --- trunk/ChameleonPrefPane/Sources/ChameleonPrefPane.h (revision 16) +++ trunk/ChameleonPrefPane/Sources/ChameleonPrefPane.h (revision 17) @@ -23,11 +23,11 @@ IBOutlet NSButton * mRestartButton; IBOutlet NSButton * mSwapHD01; IBOutlet NSButton * mSwapHD02; + IBOutlet NSButton * mFreezeParts; + IBOutlet NSButton * mInjectFrozenParts; IBOutlet NSTextField* mStatusText; IBOutlet NSBox* mOptions; - IBOutlet SFAuthorizationView *authView; - IBOutlet NSButton *touchButton; NSImage * mMacOSXImage; NSImage * mWindowsImage; @@ -42,6 +42,8 @@ - (void)awakeFromNib; - (void)initBootConfig; - (id) getImageResource: (NSString *) str ofType: (NSString*) sType; +- (void) loadPreferences; +-(bool) savePreferences: (NSDictionary*) dict; //- (void) mainViewDidLoad; - (void)tableViewSelectionDidChange:(NSNotification *)notification; @@ -51,8 +53,10 @@ - (IBAction)onShutdown: (id)sender; - (IBAction)onSleep: (id)sender; - (IBAction)onSwapHD: (id)sender; +- (IBAction)onUseFrozenParts: (id)sender; +- (IBAction)onInjectPartsToFreeze: (id)sender; -- (BOOL)isUnlocked; +- (bool)isUnlocked; - (void) refreshLockStates; - (void) doSwapHD: (int) val save: (bool) doSave src: (int)isrc dst: (int) idst; - (void)tableViewSelectionDidChange:(NSNotification *)notification; Index: trunk/ChameleonPrefPane/Sources/ChameleonPrefPane.mm =================================================================== --- trunk/ChameleonPrefPane/Sources/ChameleonPrefPane.mm (revision 16) +++ trunk/ChameleonPrefPane/Sources/ChameleonPrefPane.mm (revision 17) @@ -28,6 +28,12 @@ static const char* const kDefaultPartition = "Default Partition"; static const char* const kHidePartition = "Hide Partition"; static const char* const kRenamePartition = "Rename Partition"; + +static const NSString* const kPreferencesFilePath = @"/Library/Preferences/com.chameleon.prefPane.plist"; +static const NSString* const keyForceBootConfigPath = @"forceBootConfigPath"; +static const NSString* const keySwapHD01 = @"swapHD01"; +static const NSString* const keySwapHD02 = @"swapHD02"; +static const NSString* const keyUseFrozenParts = @"useFrozenParts"; //-------------------------------------------------------------------------- // Static file variables //-------------------------------------------------------------------------- @@ -62,10 +68,13 @@ [mSwapHD01 setEnabled:[self isUnlocked]]; [mSwapHD02 setEnabled:[self isUnlocked]]; [mStatusText setEnabled:[self isUnlocked]]; + [mFreezeParts setEnabled:[self isUnlocked]]; + [mInjectFrozenParts setEnabled:[self isUnlocked]]; } + //-------------------------------------------------------------------------- -- (BOOL)isUnlocked +- (bool)isUnlocked { return [authView authorizationState] == SFAuthorizationViewUnlockedState; } @@ -80,21 +89,57 @@ img = [[NSImage alloc] initWithContentsOfFile: sRes]; return img; } -- (bool) loadOptionsDict + +//-------------------------------------------------------------------------- +-(bool) savePreferences: (NSDictionary*) dict { + std::string sPath = [kPreferencesFilePath UTF8String]; - NSBundle * b = [NSBundle bundleForClass:[self class]]; - if(mOptionsPlistPath !=nil) [mOptionsDict dealloc]; - mOptionsPlistPath = [[NSString alloc] initWithString: [b pathForResource: @"Data" ofType:@"plist"]]; - NSMutableDictionary * d = [NSMutableDictionary dictionaryWithContentsOfFile: mOptionsPlistPath]; - if(mOptionsDict !=nil) [mOptionsDict dealloc]; - mOptionsDict = [[NSMutableDictionary alloc] initWithCapacity:64 ]; - [mOptionsDict addEntriesFromDictionary: d]; + if(dict==nil || sPath.length()==0) return false; - //if (d != nil) [d dealloc]; + AuthorizationRef auth = [self isUnlocked] ? [[authView authorization] authorizationRef] : NULL; + + PropertyList::chmodFile(sPath.c_str(), "0777", auth); + [dict writeToFile:kPreferencesFilePath atomically:YES]; + PropertyList::chmodFile(sPath.c_str(), "0644", auth); + return true; +} - return (mOptionsDict != nil) ? true : false; +//-------------------------------------------------------------------------- +- (void) loadPreferences + +{ + id oldGlobalPreferences = [ [NSDictionary dictionaryWithContentsOfFile: + kPreferencesFilePath ] retain]; + if (oldGlobalPreferences!=nil) + { + [mSwapHD01 setIntValue: [[oldGlobalPreferences objectForKey: keySwapHD01] intValue]]; + [mSwapHD02 setIntValue: [[oldGlobalPreferences objectForKey: keySwapHD02] intValue]]; + [mFreezeParts setIntValue: [[oldGlobalPreferences objectForKey: keyUseFrozenParts] intValue] ]; + } + else + { // Create a preference plist file with Defaults values + [mSwapHD01 setIntValue: 0]; + [mSwapHD02 setIntValue: 0]; + [mFreezeParts setIntValue: 0]; + + // Initialize defaults + oldGlobalPreferences = [[NSMutableDictionary alloc] init]; + [oldGlobalPreferences setObject: [[NSNumber alloc] initWithBool: false] forKey: keySwapHD01]; + [oldGlobalPreferences setObject: [[NSNumber alloc] initWithBool: false] forKey: keySwapHD02]; + [oldGlobalPreferences setObject:[[NSNumber alloc] initWithBool: false] forKey: keyUseFrozenParts]; + + // Save the preferences file + [ self savePreferences:oldGlobalPreferences ]; + } + + mOptionsDict = [[NSMutableDictionary alloc] init]; + [mOptionsDict addEntriesFromDictionary:oldGlobalPreferences]; + [mOptionsDict retain]; + [oldGlobalPreferences release]; + } + //-------------------------------------------------------------------------- - (id) init { @@ -108,8 +153,7 @@ mUnknownImage = [self getImageResource: @"Chameleon" ofType: @"tiff"]; - // Retrieve the Data.plist config - if (![self loadOptionsDict]) NSLog(@"Error reading plist: %@", mOptionsPlistPath); + // Retrieve the com.chameleon.prefPane.plist config return self; } @@ -121,6 +165,7 @@ if(ft) { ft=false; + [self loadPreferences]; [self initBootConfig]; } } @@ -152,7 +197,7 @@ CFStringRef errorString=NULL; bool cont =true; - id sForcedPath = [mOptionsDict valueForKey: @"forceBootConfigPath"]; + id sForcedPath = [mOptionsDict valueForKey: keyForceBootConfigPath]; const char * szForcedPath = sForcedPath!=nil ? [sForcedPath UTF8String] : NULL; if (szForcedPath && *szForcedPath) { @@ -192,11 +237,11 @@ partExtractor->renamedPartitions(prop->getStringForKey(kRenamePartition)); // partExtractor->resetSwapping(); - id val = [mOptionsDict valueForKey:@"swapHD01"]; + id val = [mOptionsDict valueForKey: keySwapHD01]; [mSwapHD01 setIntValue: [val intValue] ]; [self doSwapHD: [val boolValue] save: false src:0 dst:1]; - val = [mOptionsDict valueForKey:@"swapHD02"]; + val = [mOptionsDict valueForKey: keySwapHD02]; [mSwapHD02 setIntValue: [val intValue] ]; [self doSwapHD: [val boolValue] save: false src:0 dst:2]; @@ -259,14 +304,11 @@ if(doSave) { - if ( [self loadOptionsDict] ) - { - if (isrc==0 && idst==1) - [mOptionsDict setObject: [NSNumber numberWithBool: val ? true : false] forKey:@"swapHD01"]; - if (isrc==0 && idst==2) - [mOptionsDict setObject: [NSNumber numberWithBool: val ? true : false] forKey:@"swapHD02"]; - [mOptionsDict writeToFile:mOptionsPlistPath atomically:YES]; - } + if (isrc==0 && idst==1) + [mOptionsDict setObject: [NSNumber numberWithBool: val ? true : false] forKey: keySwapHD01]; + if (isrc==0 && idst==2) + [mOptionsDict setObject: [NSNumber numberWithBool: val ? true : false] forKey: keySwapHD02]; + [ self savePreferences:mOptionsDict ]; } [mPartitionsTable reloadData]; @@ -278,11 +320,23 @@ - (IBAction)onSwapHD: (id)sender { partExtractor->resetSwapping(); - [self doSwapHD: !![mSwapHD01 intValue] save:true src:0 dst:1]; - [self doSwapHD: !![mSwapHD02 intValue] save:true src:0 dst:2]; + [self doSwapHD: [mSwapHD01 intValue] save:true src:0 dst:1]; + [self doSwapHD: [mSwapHD02 intValue] save:true src:0 dst:2]; } +//-------------------------------------------------------------------------- +- (IBAction)onUseFrozenParts: (id)sender +{ + bool val = !![sender intValue]; + [mOptionsDict setObject: [NSNumber numberWithBool: val] forKey: keyUseFrozenParts]; + [self savePreferences :mOptionsDict]; +} //-------------------------------------------------------------------------- +- (IBAction)onInjectPartsToFreeze: (id)sender +{ + // TODO generate the parts list in preferences proplist +} +//-------------------------------------------------------------------------- // following DieBuch recommendation : using applescript and system events (thanks!): - (IBAction)onRestart: (id)sender { Index: trunk/ChameleonPrefPane/Sources/property_list.h =================================================================== --- trunk/ChameleonPrefPane/Sources/property_list.h (revision 16) +++ trunk/ChameleonPrefPane/Sources/property_list.h (revision 17) @@ -43,6 +43,8 @@ return _propFilePath.c_str(); } + static bool chmodFile(const char * path, const char * chmodMask, + AuthorizationRef auth, AuthorizationFlags flags=kAuthorizationFlagDefaults); private: CFPropertyListRef _proplistRef; CFURLRef _CFURLRef; Index: trunk/ChameleonPrefPane/README =================================================================== --- trunk/ChameleonPrefPane/README (revision 16) +++ trunk/ChameleonPrefPane/README (revision 17) @@ -7,10 +7,13 @@ Double click on the panel file to install the resource Configuration: + The persistent configuration file is a all users level preferences property list + located in In /Library/Preferences/com.chameleon.prefPane.plist. + The swap diskk fix option might be use if your disk order from chameleon is different from what diskutil list returns Idealy we should not need this fix, but as for now, I don't know another way to do it - In the bundle resources folder, in Data.plist + In /Library/Preferences/com.chameleon.prefPane.plist: you can insert a 'forceBootConfigPath' key with your com.apple.Boot,plist file path: So if automatic detection does not work, then force your com.apple.Boot.plist path here. @@ -18,6 +21,4 @@ If the panel sees your com.apple.boot.plist in the status box, but the boot selection seem to have no effect, it might be that you have more than one bootConfig file and that the chameleon booter does not load the one that the panel selected, - see upper to force the bootConfig to match the one loaded by the chameleon booter. - - \ No newline at end of file + see upper to force the bootConfig to match the one loaded by the chameleon booter. \ No newline at end of file Index: trunk/ChameleonPrefPane/English.lproj/Chameleon.xib =================================================================== --- trunk/ChameleonPrefPane/English.lproj/Chameleon.xib (revision 16) +++ trunk/ChameleonPrefPane/English.lproj/Chameleon.xib (revision 17) @@ -1,14 +1,18 @@ - + 1050 - 9L30 - 677 - 949.54 - 353.00 + 10C540 + 740 + 1038.25 + 458.00 + + com.apple.InterfaceBuilder.CocoaPlugin + 740 + YES - + YES @@ -16,7 +20,7 @@ YES - + YES @@ -39,12 +43,12 @@ 2 {{176, 715}, {668, 368}} 1081606144 - PDwgZG8gbm90IGxvY2FsaXplID4+A + << do not localize >> NSWindow View - {3.40282e+38, 3.40282e+38} + {1.79769e+308, 1.79769e+308} {224.664, 10} @@ -61,21 +65,21 @@ 36 - {{-3.5, 53}, {674, 309}} + {{-7, 53}, {683, 309}} YES 1 - + 256 YES 268 - {{498, 224}, {147, 19}} + {{498, 231}, {147, 19}} YES @@ -84,7 +88,7 @@ V1.0 b8, by Rekursor LucidaGrande - 1.100000e+01 + 11 3100 @@ -95,19 +99,19 @@ controlColor 3 - MC42NjY2NjY2OQA + MC42NjY2NjY2NjY3AA 1 - MC4zODc1NDY5NiAwLjM5MDQ2NjI3IDAuNDEzMDQzNDcAA + MC4zODc1NDY5NjczIDAuMzkwNDY2Mjc0MyAwLjQxMzA0MzQ3ODMAA 268 - {{561, 34}, {91, 32}} + {{560, 35}, {91, 32}} YES @@ -116,7 +120,7 @@ Shutdown LucidaGrande - 1.300000e+01 + 13 1044 @@ -131,7 +135,7 @@ 268 - {{498, 76}, {147, 140}} + {{498, 83}, {147, 140}} YES @@ -161,7 +165,7 @@ 8448 - {471, 215} + {471, 221} YES @@ -174,15 +178,15 @@ -2147483392 - {{-26, 0}, {16, 17}} + {{446, 0}, {16, 17}} YES - 3.600000e+01 - 1.000000e+01 - 3.402823e+38 + 36 + 10 + 3.4028234663852886e+38 75628096 2048 @@ -222,9 +226,9 @@ - 1.980000e+02 - 4.000000e+01 - 1.000000e+03 + 198 + 40 + 1000 75628096 67110912 @@ -547,9 +551,9 @@ - 8.400000e+01 - 1.000000e+01 - 3.402823e+38 + 84 + 10 + 3.4028229999999999e+38 75628096 134219776 @@ -575,9 +579,9 @@ Name Displayed on the bootable partion during Chameleon boot - 1.410000e+02 - 4.000000e+01 - 1.000000e+03 + 141 + 40 + 1000 75628096 2048 @@ -602,8 +606,8 @@ - 3.000000e+00 - 2.000000e+00 + 3 + 2 6 @@ -614,15 +618,18 @@ MC41AA - 3.200000e+01 + 32 -692060160 + + 4 15 0 YES + 0 - {{1, 17}, {471, 215}} + {{1, 17}, {471, 221}} @@ -636,7 +643,7 @@ _doScroller: - 9.242424e-01 + 0.9242424242424242 @@ -646,7 +653,7 @@ 1 _doScroller: - 9.957716e-01 + 0.99577167019027479 @@ -664,7 +671,7 @@ - {{17, 10}, {473, 233}} + {{17, 11}, {473, 239}} 562 @@ -678,7 +685,7 @@ 268 - {{493, 2}, {158, 32}} + {{493, 3}, {158, 32}} YES @@ -698,7 +705,7 @@ 268 - {{492, 34}, {67, 32}} + {{493, 35}, {67, 32}} YES @@ -716,8 +723,7 @@ - {{10, 33}, {654, 263}} - + {{10, 33}, {663, 263}} Select Boot Partition @@ -726,7 +732,7 @@ 2 - + 256 YES @@ -745,11 +751,12 @@ 268 {{12, 41}, {123, 18}} + 2 YES 67239424 131072 - U3dhcCBkaXNrcyAwPC0+MQ + Swap disks 0<->1 1211912703 @@ -770,13 +777,14 @@ 268 - {{12, 21}, {123, 18}} + {{138, 41}, {123, 18}} + 2 YES 67239424 131072 - U3dhcCBkaXNrcyAwPC0+Mg + Swap disks 0<->2 1211912703 @@ -789,14 +797,60 @@ 25 + + + 268 + {{321, 41}, {139, 18}} + + 2 + YES + + 67239424 + 131072 + Use Freezed Parts List + + + 1211912703 + 2 + + + + + 200 + 25 + + + + + 268 + {{461, 35}, {159, 28}} + + 2 + YES + + 67239424 + 134348800 + Inject Parts in Freeze File + + + -2038284033 + 129 + + + 200 + 25 + + - {{1, 1}, {151, 75}} + {{1, 1}, {636, 75}} + 2 - {{14, 160}, {153, 91}} + {{19, 166}, {638, 91}} YES + 2 {0, 0} 67239424 @@ -821,21 +875,22 @@ NO - {{10, 33}, {654, 263}} + {{10, 33}, {663, 263}} + Settings - + 0 YES YES YES - + @@ -844,7 +899,7 @@ {{0, 0}, {1920, 1178}} {224.664, 32} - {3.40282e+38, 3.40282e+38} + {1.79769e+308, 1.79769e+308} ChameleonPrefPane @@ -1013,28 +1068,58 @@ 199 + + + mFreezeParts + + + + 217 + + + + mInjectFrozenParts + + + + 218 + + + + onUseFrozenParts: + + + + 219 + + + + onInjectPartsToFreeze: + + + + 220 + YES 0 - - YES - + -2 - - RmlsZSdzIE93bmVyA + + File's Owner -1 - + First Responder @@ -1044,7 +1129,7 @@ YES - + PrefPane @@ -1060,13 +1145,13 @@ -3 - + Application 112 - + ChameleonPrefPane @@ -1102,8 +1187,8 @@ + - @@ -1269,6 +1354,8 @@ YES + + @@ -1328,14 +1415,40 @@ + + 200 + + + YES + + + + + + 201 + + + + + 203 + + + YES + + + + + + 204 + + + YES - + YES - -1.IBPluginDependency - -2.IBPluginDependency -3.IBPluginDependency 100.IBPluginDependency 101.IBPluginDependency @@ -1348,8 +1461,8 @@ 110.IBAttributePlaceholdersKey 110.IBPluginDependency 111.IBPluginDependency - 112.IBPluginDependency 12.IBEditorWindowLastContentRect + 12.IBPluginDependency 12.IBViewEditorWindowController.showingLayoutRectangles 12.IBWindowTemplateEditedContentRect 12.ImportedFromIB2 @@ -1382,6 +1495,11 @@ 189.IBAttributePlaceholdersKey 189.IBPluginDependency 190.IBPluginDependency + 200.IBAttributePlaceholdersKey + 200.IBPluginDependency + 201.IBPluginDependency + 203.IBPluginDependency + 204.IBPluginDependency 6.IBPluginDependency 6.ImportedFromIB2 99.IBAttributePlaceholdersKey @@ -1398,8 +1516,6 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin ToolTip @@ -1410,12 +1526,12 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + {{134, 127}, {668, 368}} com.apple.InterfaceBuilder.CocoaPlugin - {{75, 109}, {668, 368}} - {{75, 109}, {668, 368}} - - + {{134, 127}, {668, 368}} + + {224.664, 10} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -1437,8 +1553,7 @@ ToolTip - U3dhcCBkaXNrcyBpbmRleGVzIDA8LT4yLCB1c2UgdGhpcyBvcHRpb24gaWYgeW91ciBkaXNrIHNlcXVl -bmNlIGluIG9zeCBkb2VzIG5vdCBtYXRjaCB0aGUgY2hhbWVsZW9uIGJvb3QgZGlzayBzZXF1ZW5jZQ + Swap disks indexes 0<->2, use this option if your disk sequence in osx does not match the chameleon boot disk sequence com.apple.InterfaceBuilder.CocoaPlugin @@ -1447,8 +1562,7 @@ ToolTip - U3dhcCBkaXNrcyBpbmRleGVzIDA8LT4xLCB1c2UgdGhpcyBvcHRpb24gaWYgeW91ciBkaXNrIHNlcXVl -bmNlIGluIG9zeCBkb2VzIG5vdCBtYXRjaCB0aGUgY2hhbWVsZW9uIGJvb3QgZGlzayBzZXF1ZW5jZQ + Swap disks indexes 0<->1, use this option if your disk sequence in osx does not match the chameleon boot disk sequence com.apple.InterfaceBuilder.CocoaPlugin @@ -1474,8 +1588,20 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + + ToolTip + + ToolTip + + Swap disks indexes 0<->2, use this option if your disk sequence in osx does not match the chameleon boot disk sequence + + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + ToolTip @@ -1489,9 +1615,7 @@ YES - - YES - + YES @@ -1499,30 +1623,49 @@ YES - - YES - + YES - 199 + 220 YES + FirstResponder + NSObject + + IBUserSource + + + + + NSPreferencePane + NSObject + + IBUserSource + + + + + + YES + ChameleonPrefPane NSPreferencePane YES - + YES + onInjectPartsToFreeze: onRestart: onShutdown: onSleep: onSwapHD: + onUseFrozenParts: YES @@ -1530,14 +1673,18 @@ id id id + id + id YES - + YES authView mFileSystemColumn + mFreezeParts + mInjectFrozenParts mOptions mPartitionIDColumn mPartitionImgColumn @@ -1549,12 +1696,13 @@ mStatusText mSwapHD01 mSwapHD02 - touchButton YES SFAuthorizationView NSTableColumn + NSButton + NSButton NSBox NSTableColumn NSTableColumn @@ -1566,33 +1714,29 @@ NSTextField NSButton NSButton - NSButton - IBProjectSource - Sources/ChameleonPrefPane.h + IBDocumentRelativeSource + ../Sources/ChameleonPrefPane.h - - FirstResponder - NSObject - - IBUserSource - - - - - NSPreferencePane - NSObject - - IBUserSource - - - 0 + + com.apple.InterfaceBuilder.CocoaPlugin.macosx + + + + com.apple.InterfaceBuilder.CocoaPlugin.macosx + + + + com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3 + + + YES ../ChameleonPrefPane.xcodeproj 3