static const NSString* const keySwapHD02 = @"swapHD02";␊ |
static const NSString* const keyUseFrozenParts = @"useFrozenParts";␊ |
static const NSString* const keyPartitionsList = @"partitionsList";␊ |
static const char cPartDescSep = ';'; // partition descriptor separator␊ |
static const char* sPartDescSep = ";"; // cstring version␊ |
//--------------------------------------------------------------------------␊ |
// Static file variables␊ |
//--------------------------------------------------------------------------␊ |
|
␉PropertyList::chmodFile(sPath.c_str(), "0644", auth);␊ |
␉return true;␊ |
}␊ |
␊ |
//--------------------------------------------------------------------------␊ |
- (void) loadFrozenParts␊ |
{␊ |
␉std::vector<PartitionInfo>& partList = partExtractor->editPartList(); //rw␊ |
␉// iterate for all entries to add␊ |
␉char keyPartN[32] = "";␊ |
␉char buffer[256]="";␊ |
␉int k=0;␊ |
␉partList.clear();␊ |
␉for (int i=0; i<[mPartitionsDict count]; i++)␊ |
␉{␊ |
␉␉// get the key␊ |
␉␉snprintf(keyPartN, sizeof(keyPartN)-1, "partition%02d",i);␊ |
␉␉NSString* obj = [mPartitionsDict objectForKey: [[NSString alloc] initWithUTF8String: keyPartN] ];␊ |
␉␉// assign this key if valid␊ |
␉␉if (obj!=nil && [obj length]>0)␊ |
␉␉{␊ |
␉␉␉PartitionInfo p;␊ |
␉␉␉// parse string␊ |
␉␉␉strncpy(buffer, [obj UTF8String], sizeof(buffer)-1);␊ |
␉␉␉k=0;␊ |
␉␉␉for(const char* word = strtok(buffer,";"); word; word=strtok(NULL,sPartDescSep),k++)␊ |
␉␉␉{␊ |
␉␉␉␉switch (k) {␊ |
␉␉␉␉␉case 0: // parse disk number␊ |
␉␉␉␉␉␉if (isdigit(*word)) p.disk(*word-'0');␊ |
␉␉␉␉␉␉break;␊ |
␉␉␉␉␉case 1: // parse partition number␊ |
␉␉␉␉␉␉if (isdigit(*word)) p.partition(*word-'0');␊ |
␉␉␉␉␉␉break;␊ |
␉␉␉␉␉case 2: // parse volume label␊ |
␉␉␉␉␉␉p.label(word);␊ |
␉␉␉␉␉case 3:␊ |
␉␉␉␉␉␉p.fsType(word);␊ |
␉␉␉␉␉␉break;␊ |
␉␉␉␉␉default:␊ |
␉␉␉␉␉␉break;␊ |
␉␉␉␉}␊ |
␉␉␉}␊ |
␉␉␉partList.push_back(p);␊ |
␉␉}␊ |
␉}␊ |
}␊ |
//--------------------------------------------------------------------------␊ |
- (void) loadPreferences␊ |
␊ |
{␊ |
␉id oldGlobalPreferences = [ [NSDictionary dictionaryWithContentsOfFile: ␊ |
␉␉␉␉␉␉␉␉kPreferencesFilePath ] retain];␊ |
␊ |
␉mPartitionsDict = [[NSMutableDictionary alloc] init];␊ |
␉[mPartitionsDict retain];␊ |
␊ |
if (oldGlobalPreferences!=nil)␊ |
␉{␊ |
␉␉mPreferenceFileVersion= [[oldGlobalPreferences objectForKey: keyPreferencesFileVersion] intValue ];␊ |
␉␉[mSwapHD01 setIntValue: [[oldGlobalPreferences objectForKey:␉keySwapHD01] intValue]];␊ |
␉␉[mSwapHD02 setIntValue: [[oldGlobalPreferences objectForKey:␉keySwapHD02] intValue]];␊ |
␉␉[mFreezeParts setIntValue: [[oldGlobalPreferences objectForKey: keyUseFrozenParts] intValue] ];␊ |
␉␉mPartitionsList = [oldGlobalPreferences objectForKey: keyUseFrozenParts];␊ |
␉␉[mPartitionsDict addEntriesFromDictionary: [oldGlobalPreferences objectForKey: keyPartitionsList] ];␊ |
␉}␊ |
␉else ␊ |
␉{ // Create a preference plist file with Defaults values␊ |
|
␉␉[oldGlobalPreferences setObject: [[NSNumber alloc] initWithBool: false] forKey: keySwapHD01];␊ |
␉␉[oldGlobalPreferences setObject: [[NSNumber alloc] initWithBool: false] forKey: keySwapHD02];␊ |
␉␉[oldGlobalPreferences setObject:[[NSNumber alloc] initWithBool: false] forKey: keyUseFrozenParts];␊ |
␉␉[oldGlobalPreferences setObject: [[NSMutableDictionary alloc] initWithCapacity:64] forKey: keyPartitionsList];␊ |
␉␉[oldGlobalPreferences setObject: mPartitionsDict forKey: keyPartitionsList];␊ |
␉␉␊ |
␉␉// Save the preferences file␊ |
␉␉[ self savePreferences:oldGlobalPreferences ];␊ |
|
␊ |
␉mOptionsDict = [[NSMutableDictionary alloc] init];␊ |
[mOptionsDict addEntriesFromDictionary:oldGlobalPreferences];␊ |
␉[mOptionsDict retain];␊ |
␉if (mPartitionsList!=nil) [mPartitionsList retain];␊ |
␉if (mPartitionsDict!=nil) [mPartitionsDict retain];␊ |
[oldGlobalPreferences release];␊ |
␉␊ |
}␊ |
␊ |
//--------------------------------------------------------------------------␊ |
|
␉{␊ |
␉␉partExtractor->swapHD(iSrc, iDst);␉␊ |
␉}␊ |
␉partExtractor->extractPartitions();␊ |
␉␊ |
␉if ([mFreezeParts intValue]==0) ␊ |
␉␉partExtractor->extractPartitions();␊ |
␉else ␊ |
␉␉[self loadFrozenParts ];␊ |
␉␊ |
␉[ self selectDefaultPartition];␊ |
␊ |
}␊ |
|
- (void) doSwapHD: (int) val save: (bool) doSave src: (int) isrc dst: (int) idst␊ |
{␊ |
␉␊ |
␉if( val>0) //on␊ |
␉if( val>0 && ![mFreezeParts intValue]) //on␊ |
␉{␊ |
␉␉[self swapDisks: true src:isrc dst:idst ];␊ |
␉}␊ |
|
{␊ |
␉bool val = !![sender intValue];␊ |
␉[mOptionsDict setObject: [NSNumber numberWithBool: val] forKey: keyUseFrozenParts];␊ |
␉[self savePreferences :mOptionsDict];␊ |
␉[self savePreferences: mOptionsDict];␊ |
␉[self onSwapHD: nil];␊ |
}␊ |
␊ |
//--------------------------------------------------------------------------␊ |
- (IBAction)onInjectPartsToFreeze: (id)sender␊ |
{␊ |
␉// TODO generate the parts list in preferences proplist␊ |
␉int size = partExtractor ? partExtractor->partList().size() : 0;␊ |
␉if (!size) ␊ |
␉{ // nothing to inject␊ |
␉␉NSRunAlertPanel(@"Inject Partitions to Freeze Configuration", ␊ |
␉␉␉␉␉␉@"No current partitions to inject, did you check boot config file ?",@"OK", nil,nil);␊ |
␉␉return;␊ |
␉}␊ |
␉// generate the parts list in preferences proplist␊ |
␉NSInteger n = NSRunAlertPanel(@"Inject Partitions to Freeze Configuration", ␊ |
␉␉␉␉␉␉␉␉ @"Are you sure you want to overwrite your Freeze settings with current partition list ?",␊ |
␉␉␉␉␉␉␉␉ @"OK", @"Cancel",nil);␊ |
␉if (n==1)␊ |
␉{␊ |
␉␉// populate the dictionary with the current partitions␊ |
␉␉␊ |
␉␉// empty dictionary and update key in parent:␊ |
␉␉[mOptionsDict removeObjectForKey: keyPartitionsList];␊ |
␉␉[mPartitionsDict removeAllObjects ];␊ |
␉␉␊ |
␉␉// iterate for all entries to add␊ |
␉␉char partDesc[256]="";␊ |
␉␉char keyPartN[32] = "";␊ |
␉␉for (int i=0; i< size; i++)␊ |
␉␉{␊ |
␉␉␉␊ |
␉␉␉const PartitionInfo& p =partExtractor->partList()[i];␊ |
␉␉␉␊ |
␉␉␉// format the partition key and descriptor string␊ |
␉␉␉snprintf(keyPartN, sizeof(keyPartN)-1, "partition%02d",i);␊ |
␉␉␉␊ |
␉␉␉snprintf(partDesc, sizeof(partDesc)-1, "%d%c%d%c%s%c%s",␊ |
␉␉␉␉␉ p.disk(), cPartDescSep,␊ |
␉␉␉␉␉ p.partition(), cPartDescSep,␊ |
␉␉␉␉␉ p.label().c_str(), cPartDescSep,␊ |
␉␉␉␉␉ p.fsType().c_str());␊ |
␉␉␉␊ |
␉␉␉// write it to the dictionary␊ |
␉␉␉NSString * key = [[NSString alloc] initWithUTF8String: keyPartN];␊ |
␉␉␉NSString * desc = [[NSString alloc] initWithUTF8String: partDesc]; ␊ |
␉␉␉[mPartitionsDict setObject: desc forKey: key];␊ |
␉␉}␊ |
␉␉[mOptionsDict setObject: mPartitionsDict forKey: keyPartitionsList];␊ |
␉␉[self savePreferences: mOptionsDict];␊ |
␉}␊ |
}␊ |
//--------------------------------------------------------------------------␊ |
|
␉}␊ |
␉␊ |
}␊ |
//--------------------------------------------------------------------------␊ |
- (IBAction)onShutdown: (id)sender␊ |
{␊ |
␉NSInteger n = NSRunAlertPanel(@"Shutting Down OS X", ␊ |