#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];␊ |
␉␉␉␊ |
␉␉}␊ |