Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted by Anni ( 12 years ago )
-(id) specifiers
{
    if(_specifiers == nil) {
        
        bundle = [NSBundle bundleWithPath:@"/Library/PreferenceBundles/LockerSettings.bundle"];
        
        if(bundle != nil)
        {
            [bundle load];
            plistPath = [bundle pathForResource:@"appList" ofType:@"plist"];
            
            if(plistPath != nil)
            {
                NSMutableDictionary *data = [NSMutableDictionary dictionaryWithContentsOfFile:plistPath];
                
                NSArray *arr = data[@"items"];
                
                if(arr.count > 1)
                {
                    NSLog(@"********** FOUND");
                    _specifiers = [[self loadSpecifiersFromPlistName:@"appList" target:self] retain];
                }
                else
                {
                    NSLog(@"********** NOT FOUND");
                    
                    ALApplicationList *apps = [ALApplicationList sharedApplicationList]; //list all the apps
                    
                    NSDictionary *appData = [apps applications];
                    
                    
                    NSArray *displayIdentifiers = [[appData allKeys] sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
                        return [[apps.applications objectForKey:obj1] caseInsensitiveCompare:[apps.applications objectForKey:obj2]];}]; //sort the apps by display name
                    [displayIdentifiers retain]; //make sure it doesn't disappear when you actually need to use it, if you only use it once, release it
                    
                    NSMutableArray *newArr = [NSMutableArray array];
                    
                    for(int i = 0; i < displayIdentifiers.count; i++)
                    {
                        //create dict with identifier as key, and value is [appname, enabled]
                        
                        NSMutableDictionary *aData = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                        @"PSSwitchCell", @"cell",
                        @NO, @"default",
                        @"com.company.lockersettings", @"defaults",
                        displayIdentifiers[i], @"key",
                        appData[displayIdentifiers[i]], @"label",
                        @"setValueHere:specifier:",@"set",
                        nil];
                        
                        [newArr addObject:aData];
                    }
                    
                    NSLog(@"********** CREATED ARRAY");

                    NSDictionary *dataToWrite = [NSDictionary dictionaryWithObjectsAndKeys:
                    @"Applications List", @"title",
                    [NSArray arrayWithArray:newArr], @"items",
                    nil];
                    [dataToWrite writeToFile:plistPath atomically: YES];
                    
                    NSLog(@"********** WRITTEN TO FILE");

                    _specifiers = [[self loadSpecifiersFromPlistName:@"appList" target:self] retain];
                    

                }
                
            }
            
        }

        
    }
    
    return _specifiers;
}

 

Revise this Paste

Your Name: Code Language: