- window_ = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
- [window_ makeKeyAndVisible];
-
- plist_ = [[NSString stringWithFormat:@"%@/Library/Preferences/com.saurik.WinterBoard.plist",
- NSHomeDirectory()
- ] retain];
-
- settings_ = [[NSMutableDictionary alloc] initWithContentsOfFile:plist_];
- if (settings_ == nil)
- settings_ = [[NSMutableDictionary alloc] initWithCapacity:16];
-
- themesArray_ = [settings_ objectForKey:@"Themes"];
- if (themesArray_ == nil) {
- if (NSString *theme = [settings_ objectForKey:@"Theme"]) {
- themesArray_ = [[NSArray arrayWithObject:[[NSDictionary dictionaryWithObjectsAndKeys:
- theme, @"Name",
- [NSNumber numberWithBool:YES], @"Active",
- nil] mutableCopy]] mutableCopy];
-
- [settings_ removeObjectForKey:@"Theme"];
- }
-
- if (themesArray_ == nil)
- themesArray_ = [NSMutableArray arrayWithCapacity:16];
- [settings_ setObject:themesArray_ forKey:@"Themes"];
- }
-
- themesArray_ = [themesArray_ retain];
-
- NSMutableSet *themesSet = [NSMutableSet setWithCapacity:32];
- for (NSMutableDictionary *theme in themesArray_)
- if (NSString *name = [theme objectForKey:@"Name"])
- [themesSet addObject:name];
-
- NSFileManager *manager = [NSFileManager defaultManager];
-
- NSMutableArray *themes = [NSMutableArray arrayWithCapacity:32];
- [themes addObjectsFromArray:[manager contentsOfDirectoryAtPath:@"/Library/Themes" error:NULL]];
- [themes addObjectsFromArray:[manager contentsOfDirectoryAtPath:[NSString stringWithFormat:@"%@/Library/SummerBoard/Themes", NSHomeDirectory()] error:NULL]];
-
- for (NSUInteger i(0), e([themes count]); i != e; ++i) {
- NSString *theme = [themes objectAtIndex:i];
- if ([theme hasSuffix:@".theme"])
- [themes replaceObjectAtIndex:i withObject:[theme substringWithRange:NSMakeRange(0, [theme length] - 6)]];
- }
-
- for (NSUInteger i(0), e([themesArray_ count]); i != e; ++i) {
- NSMutableDictionary *theme = [themesArray_ objectAtIndex:i];
- NSString *name = [theme objectForKey:@"Name"];
- if (name == nil || ![themes containsObject:name]) {
- [themesArray_ removeObjectAtIndex:i];
- --i; --e;
- }
- }
-
- for (NSString *theme in themes) {
- if ([themesSet containsObject:theme])
- continue;
- [themesSet addObject:theme];
- [themesArray_ insertObject:[[NSDictionary dictionaryWithObjectsAndKeys:
- theme, @"Name",
- [NSNumber numberWithBool:NO], @"Active",
- nil] mutableCopy] atIndex:0];
- }
-
- themesTable_ = [[UITableView alloc] initWithFrame:window_.bounds];
- [window_ addSubview:themesTable_];
-
- [themesTable_ setDataSource:self];
- [themesTable_ setDelegate:self];
-
- [themesTable_ setEditing:YES animated:NO];
- themesTable_.allowsSelectionDuringEditing = YES;
-
- [themesTable_ setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];