-(void)prefs
{
//It is here that we set the defaults
NSString *textValue = [[NSUserDefaults standardUserDefaults] stringForKey:@"SystemMode"];
NSString *commandValue = [[NSUserDefaults standardUserDefaults] stringForKey:@"commandstr"];
//If the first value is nil, then we know that the defaults are not set.
if(textValue == nil)
{
//Get the bundle path
NSLog(@"no prefences found");
NSString *bPath = [[NSBundle mainBundle] bundlePath];
NSString *settingsPath = [bPath stringByAppendingPathComponent:@"Settings.bundle"];
NSString *plistFile = [settingsPath stringByAppendingPathComponent:@"Root.plist"];
//Get the Preferences Array from the dictionary
NSDictionary *settingsDictionary = [NSDictionary dictionaryWithContentsOfFile:plistFile];
NSArray *preferencesArray = [settingsDictionary objectForKey:@"PreferenceSpecifiers"];
//Temporary Variables
NSDictionary *item;
NSString *textEntry_Key;
NSString *readOnly_Key;
NSString *toogle_Key;
NSString *slider_Key;
NSString *colors_Key;
//Loop through the array
for(item in preferencesArray)
{
//Get the key of the item.
NSString *keyValue = [item objectForKey:@"Key"];
//Get the default value specified in the plist file.
id defaultValue = [item objectForKey:@"DefaultValue"];
if([keyValue isEqualToString:@"textEntry_key"])
textEntry_Key = defaultValue;
if([keyValue isEqualToString:@"readOnly_key"])
readOnly_Key = defaultValue;
if([keyValue isEqualToString:@"toogle_key"])
toogle_Key = defaultValue;
if([keyValue isEqualToString:@"slider_key"])
slider_Key = defaultValue;
if([keyValue isEqualToString:@"colors_key"])
colors_Key = defaultValue;
}
//Now that we have all the default values.
//We will create it here.
NSDictionary *appPrerfs = [NSDictionary dictionaryWithObjectsAndKeys:
textEntry_Key, @"textEntry_key",
readOnly_Key, @"readOnly_key",
toogle_Key, @"toogle_key",
slider_Key, @"slider_key",
[NSNumber numberWithInt:1], @"slider_key",
[NSNumber numberWithInt:1], @"colors_key",
nil];
//Register and save the dictionary to the disk
[[NSUserDefaults standardUserDefaults] registerDefaults:appPrerfs];
[[NSUserDefaults standardUserDefaults] synchronize];
}
NSLog(@"Pref Files: %@",textValue);
NSLog(@"Pref file Command: %@",commandValue);
}