1 /* WinterBoard - Theme Manager for the iPhone
2 * Copyright (C) 2008 Jay Freeman (saurik)
6 * Redistribution and use in source and binary
7 * forms, with or without modification, are permitted
8 * provided that the following conditions are met:
10 * 1. Redistributions of source code must retain the
11 * above copyright notice, this list of conditions
12 * and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the
14 * above copyright notice, this list of conditions
15 * and the following disclaimer in the documentation
16 * and/or other materials provided with the
18 * 3. The name of the author may not be used to endorse
19 * or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
24 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
33 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
35 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #define _trace() NSLog(@"WB:_trace(%u)", __LINE__);
41 #include <objc/runtime.h>
42 #include <objc/message.h>
45 #include <mach-o/nlist.h>
48 #import <Foundation/Foundation.h>
49 #import <CoreGraphics/CoreGraphics.h>
51 #import <UIKit/UIColor.h>
52 #import <UIKit/UIFont.h>
53 #import <UIKit/UIImage.h>
54 #import <UIKit/UIImageView.h>
55 #import <UIKit/UINavigationBarBackground.h>
56 #import <UIKit/UIWebDocumentView.h>
58 #import <UIKit/NSString-UIStringDrawing.h>
59 #import <UIKit/NSString-UIStringDrawingDeprecated.h>
61 #import <UIKit/UIImage-UIImageDeprecated.h>
63 #import <UIKit/UIView-Geometry.h>
64 #import <UIKit/UIView-Hierarchy.h>
65 #import <UIKit/UIView-Rendering.h>
67 #import <SpringBoard/SBApplication.h>
68 #import <SpringBoard/SBApplicationIcon.h>
69 #import <SpringBoard/SBAppWindow.h>
70 #import <SpringBoard/SBButtonBar.h>
71 #import <SpringBoard/SBContentLayer.h>
72 #import <SpringBoard/SBIconLabel.h>
73 #import <SpringBoard/SBStatusBarContentsView.h>
74 #import <SpringBoard/SBStatusBarController.h>
75 #import <SpringBoard/SBStatusBarTimeView.h>
76 #import <SpringBoard/SBUIController.h>
78 #import <MediaPlayer/MPVideoView.h>
79 #import <MediaPlayer/MPVideoView-PlaybackControl.h>
81 #import <CoreGraphics/CGGeometry.h>
83 @interface NSDictionary (WinterBoard)
84 - (UIColor *) colorForKey:(NSString *)key;
85 - (BOOL) boolForKey:(NSString *)key;
88 @implementation NSDictionary (WinterBoard)
90 - (UIColor *) colorForKey:(NSString *)key {
91 NSString *value = [self objectForKey:key];
98 - (BOOL) boolForKey:(NSString *)key {
99 if (NSString *value = [self objectForKey:key])
100 return [value boolValue];
107 bool Engineer_ = false;
109 /* WinterBoard Backend {{{ */
110 #define WBPrefix "wb_"
112 void WBInject(const char *classname, const char *oldname, IMP newimp, const char *type) {
113 Class _class = objc_getClass(classname);
116 if (!class_addMethod(_class, sel_registerName(oldname), newimp, type))
117 NSLog(@"WB:Error: failed to inject [%s %s]", classname, oldname);
120 void WBRename(bool instance, const char *classname, const char *oldname, IMP newimp) {
121 Class _class = objc_getClass(classname);
124 NSLog(@"WB:Warning: cannot find class [%s]", classname);
128 _class = object_getClass(_class);
129 Method method = class_getInstanceMethod(_class, sel_getUid(oldname));
132 NSLog(@"WB:Warning: cannot find method [%s %s]", classname, oldname);
135 size_t namelen = strlen(oldname);
136 char newname[sizeof(WBPrefix) + namelen];
137 memcpy(newname, WBPrefix, sizeof(WBPrefix) - 1);
138 memcpy(newname + sizeof(WBPrefix) - 1, oldname, namelen + 1);
139 const char *type = method_getTypeEncoding(method);
140 if (!class_addMethod(_class, sel_registerName(newname), method_getImplementation(method), type))
141 NSLog(@"WB:Error: failed to rename [%s %s]", classname, oldname);
143 Method *methods = class_copyMethodList(_class, &count);
144 for (unsigned int index(0); index != count; ++index)
145 if (methods[index] == method)
148 if (!class_addMethod(_class, sel_getUid(oldname), newimp, type))
149 NSLog(@"WB:Error: failed to rename [%s %s]", classname, oldname);
153 method_setImplementation(method, newimp);
159 @protocol WinterBoard
160 - (NSString *) wb_pathForIcon;
161 - (NSString *) wb_pathForResource:(NSString *)resource ofType:(NSString *)type;
164 - (id) wb_initWithSize:(CGSize)size;
165 - (id) wb_initWithSize:(CGSize)size label:(NSString *)label;
166 - (id) wb_initWithFrame:(CGRect)frame;
167 - (id) wb_initWithCoder:(NSCoder *)coder;
168 - (void) wb_setFrame:(CGRect)frame;
169 - (void) wb_drawRect:(CGRect)rect;
170 - (void) wb_setBackgroundColor:(id)color;
171 - (void) wb_setAlpha:(float)value;
172 - (void) wb_setBarStyle:(int)style;
173 - (id) wb_initWithFrame:(CGRect)frame withBarStyle:(int)style withTintColor:(UIColor *)color;
174 - (void) wb_setOpaque:(BOOL)opaque;
175 - (void) wb_setInDock:(BOOL)docked;
176 - (void) wb_didMoveToSuperview;
177 + (UIImage *) wb_imageNamed:(NSString *)name inBundle:(NSBundle *)bundle;
178 + (UIImage *) wb_applicationImageNamed:(NSString *)name;
179 - (NSDictionary *) wb_infoDictionary;
180 - (UIImage *) wb_icon;
181 - (id) wb_initWithStatusBar:(id)bar mode:(int)mode;
182 - (id) wb_initWithMode:(int)mode orientation:(int)orientation;
183 - (void) wb_setStatusBarMode:(int)mode orientation:(int)orientation duration:(float)duration fenceID:(int)id animation:(int)animation;
186 NSMutableDictionary **ImageMap_;
187 NSMutableSet *UIImages_;
189 NSFileManager *Manager_;
190 NSDictionary *English_;
191 NSMutableDictionary *Info_;
192 NSMutableArray *themes_;
194 NSString *$pathForIcon$(SBApplication<WinterBoard> *self) {
195 for (NSString *theme in themes_) {
196 NSString *identifier = [self bundleIdentifier];
197 NSString *folder = [[self path] lastPathComponent];
198 NSString *dname = [self displayName];
199 NSString *didentifier = [self displayIdentifier];
202 NSLog(@"WB:Debug: [SBApplication(%@:%@:%@:%@) pathForIcon]", identifier, folder, dname, didentifier);
205 #define testForIcon(Name) \
206 if (NSString *name = Name) { \
207 NSString *path = [NSString stringWithFormat:@"%@/Icons/%@.png", theme, name]; \
208 if ([Manager_ fileExistsAtPath:path]) \
212 if (identifier != nil) {
213 NSString *path = [NSString stringWithFormat:@"%@/Bundles/%@/icon.png", theme, identifier];
214 if ([Manager_ fileExistsAtPath:path])
219 NSString *path = [NSString stringWithFormat:@"%@/Folders/%@/icon.png", theme, folder];
220 if ([Manager_ fileExistsAtPath:path])
224 testForIcon(identifier);
227 if (didentifier != nil) {
228 testForIcon([English_ objectForKey:didentifier]);
230 NSArray *parts = [didentifier componentsSeparatedByString:@"-"];
231 if ([parts count] != 1)
232 if (NSDictionary *english = [[[NSDictionary alloc] initWithContentsOfFile:[[self path] stringByAppendingString:@"/English.lproj/UIRoleDisplayNames.strings"]] autorelease])
233 testForIcon([english objectForKey:[parts lastObject]]);
240 static UIImage *SBApplicationIcon$icon(SBApplicationIcon<WinterBoard> *self, SEL sel) {
241 if (![Info_ boolForKey:@"ComposeStoreIcons"])
242 if (NSString *path = $pathForIcon$([self application]))
243 return [UIImage imageWithContentsOfFile:path];
244 return [self wb_icon];
247 static NSString *SBApplication$pathForIcon(SBApplication<WinterBoard> *self, SEL sel) {
248 if (NSString *path = $pathForIcon$(self))
250 return [self wb_pathForIcon];
253 static NSString *$pathForFile$inBundle$(NSString *file, NSBundle *bundle) {
254 for (NSString *theme in themes_) {
255 NSString *identifier = [bundle bundleIdentifier];
257 if (identifier != nil) {
258 NSString *path = [NSString stringWithFormat:@"%@/Bundles/%@/%@", theme, identifier, file];
260 NSLog(@"WB:Debug:%@", path);
261 if ([Manager_ fileExistsAtPath:path])
265 if (NSString *folder = [[bundle bundlePath] lastPathComponent]) {
266 NSString *path = [NSString stringWithFormat:@"%@/Folders/%@/%@", theme, folder, file];
268 NSLog(@"WB:Debug:%@", path);
269 if ([Manager_ fileExistsAtPath:path])
273 #define remapResourceName(oldname, newname) \
274 else if ([file isEqualToString:oldname]) { \
275 NSString *path = [NSString stringWithFormat:@"%@/%@.png", theme, newname]; \
277 NSLog(@"WB:Debug:%@", path); \
278 if ([Manager_ fileExistsAtPath:path]) \
282 if (identifier == nil || ![identifier isEqualToString:@"com.apple.springboard"]);
283 remapResourceName(@"FSO_BG.png", @"StatusBar")
284 remapResourceName(@"SBDockBG.png", @"Dock")
285 remapResourceName(@"SBWeatherCelsius.png", @"Icons/Weather")
291 static UIImage *UIImage$imageNamed$inBundle$(Class<WinterBoard> self, SEL sel, NSString *name, NSBundle *bundle) {
293 NSLog(@"WB:Debug: [UIImage(%@) imageNamed:\"%@\"]", [bundle bundleIdentifier], name);
294 if (NSString *path = $pathForFile$inBundle$(name, bundle))
295 return [UIImage imageWithContentsOfFile:path];
296 return [self wb_imageNamed:name inBundle:bundle];
299 static UIImage *UIImage$imageNamed$(Class<WinterBoard> self, SEL sel, NSString *name) {
300 return UIImage$imageNamed$inBundle$(self, sel, name, [NSBundle mainBundle]);
303 static UIImage *UIImage$applicationImageNamed$(Class<WinterBoard> self, SEL sel, NSString *name) {
304 NSBundle *bundle = [NSBundle mainBundle];
306 NSLog(@"WB:Debug: [UIImage(%@) applicationImageNamed:\"%@\"]", [bundle bundleIdentifier], name);
307 if (NSString *path = $pathForFile$inBundle$(name, bundle))
308 return [UIImage imageWithContentsOfFile:path];
309 return [self wb_applicationImageNamed:name];
312 static NSString *NSBundle$pathForResource$ofType$(NSBundle<WinterBoard> *self, SEL sel, NSString *resource, NSString *type) {
313 NSString *file = type == nil ? resource : [NSString stringWithFormat:@"%@.%@", resource, type];
315 NSLog(@"WB:Debug: [NSBundle(%@) pathForResource:\"%@\"]", [self bundleIdentifier], file);
316 if (NSString *path = $pathForFile$inBundle$(file, self))
318 return [self wb_pathForResource:resource ofType:type];
321 bool UINavigationBar$setBarStyle$_(SBAppWindow<WinterBoard> *self) {
322 if (NSNumber *number = [Info_ objectForKey:@"NavigationBarStyle"]) {
323 [self wb_setBarStyle:[number intValue]];
330 /*id UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$(UINavigationBarBackground<WinterBoard> *self, SEL sel, CGRect frame, int style, UIColor *tint) {
333 if (NSNumber *number = [Info_ objectForKey:@"NavigationBarStyle"])
334 style = [number intValue];
336 if (UIColor *color = [Info_ colorForKey:@"NavigationBarTint"])
339 return [self wb_initWithFrame:frame withBarStyle:style withTintColor:tint];
342 /*id UINavigationBar$initWithCoder$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame, NSCoder *coder) {
343 self = [self wb_initWithCoder:coder];
346 UINavigationBar$setBarStyle$_(self);
350 id UINavigationBar$initWithFrame$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame) {
351 self = [self wb_initWithFrame:frame];
354 UINavigationBar$setBarStyle$_(self);
358 static void UINavigationBar$setBarStyle$(SBAppWindow<WinterBoard> *self, SEL sel, int style) {
359 if (UINavigationBar$setBarStyle$_(self))
361 return [self wb_setBarStyle:style];
364 static void $didMoveToSuperview(SBButtonBar<WinterBoard> *self, SEL sel) {
365 [[self superview] setBackgroundColor:[UIColor clearColor]];
366 [self wb_didMoveToSuperview];
369 static NSString *$getTheme$(NSArray *files) {
370 for (NSString *theme in themes_)
371 for (NSString *file in files) {
372 NSString *path([NSString stringWithFormat:@"%@/%@", theme, file]);
373 if ([Manager_ fileExistsAtPath:path])
380 static id SBContentLayer$initWithSize$(SBContentLayer<WinterBoard> *self, SEL sel, CGSize size) {
381 self = [self wb_initWithSize:size];
385 if (NSString *path = $getTheme$([NSArray arrayWithObject:@"Wallpaper.mp4"])) {
386 MPVideoView *video = [[[MPVideoView alloc] initWithFrame:[self bounds]] autorelease];
387 [video setMovieWithPath:path];
388 [video setRepeatMode:1];
389 [video setRepeatGap:0];
390 [self addSubview:video];
391 [video playFromBeginning];;
394 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"Wallpaper.png", @"Wallpaper.jpg", nil]))
395 if (UIImage *image = [[[UIImage alloc] initWithContentsOfFile:path] autorelease])
396 [self addSubview:[[[UIImageView alloc] initWithImage:image] autorelease]];
398 if (NSString *path = $getTheme$([NSArray arrayWithObject:@"Wallpaper.html"])) {
399 CGRect bounds = [self bounds];
401 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
402 [view setAutoresizes:YES];
404 [view loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:path]]];
406 [[view webView] setDrawsBackground:NO];
407 [view setBackgroundColor:[UIColor clearColor]];
409 [self addSubview:view];
415 #define WBDelegate(delegate) \
416 - (NSMethodSignature*) methodSignatureForSelector:(SEL)sel { \
418 NSLog(@"WB:MS:%s:(%s)", class_getName([self class]), sel_getName(sel)); \
419 if (NSMethodSignature *sig = [delegate methodSignatureForSelector:sel]) \
421 NSLog(@"WB:Error: [%s methodSignatureForSelector:(%s)]", class_getName([self class]), sel_getName(sel)); \
425 - (void) forwardInvocation:(NSInvocation*)inv { \
426 SEL sel = [inv selector]; \
427 if ([delegate respondsToSelector:sel]) \
428 [inv invokeWithTarget:delegate]; \
430 NSLog(@"WB:Error: [%s forwardInvocation:(%s)]", class_getName([self class]), sel_getName(sel)); \
433 static unsigned *ContextCount_;
434 static void ***ContextStack_;
436 extern "C" CGColorRef CGGStateGetSystemColor(void *);
437 extern "C" CGColorRef CGGStateGetFillColor(void *);
438 extern "C" CGColorRef CGGStateGetStrokeColor(void *);
439 extern "C" NSString *UIStyleStringFromColor(CGColorRef);
441 @interface WBTime : NSProxy {
443 _transient SBStatusBarTimeView *view_;
446 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view;
450 @implementation WBTime
457 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view {
458 time_ = [time retain];
465 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
466 if (NSString *custom = [Info_ objectForKey:@"TimeStyle"]) {
468 object_getInstanceVariable(view_, "_mode", (void **) &mode);
470 [time_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
471 "font-family: Helvetica; "
472 "font-weight: bold; "
475 "%@", mode ? @"white" : @"black", custom]];
480 return [time_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
485 @interface WBIconLabel : NSProxy {
490 - (id) initWithString:(NSString *)string;
494 @implementation WBIconLabel
501 - (id) initWithString:(NSString *)string {
502 string_ = [string retain];
508 - (NSString *) _iconLabelStyle {
509 NSString *key = docked_ ? @"DockedIconLabelStyle" : @"UndockedIconLabelStyle";
510 NSString *style = [Info_ objectForKey:key];
514 - (CGSize) drawInRect:(CGRect)rect withFont:(UIFont *)font lineBreakMode:(int)mode alignment:(int)alignment {
515 if (NSString *custom = [self _iconLabelStyle]) {
516 NSString *style = [NSString stringWithFormat:@""
517 "font-family: Helvetica; "
518 "font-weight: bold; "
520 "text-align: center; "
522 "%@", docked_ ? @"white" : @"#b3b3b3", custom];
525 NSLog(@"WB:Debug:style = %@", style);
526 [string_ drawInRect:rect withStyle:style];
530 return [string_ drawInRect:rect withFont:font lineBreakMode:mode alignment:alignment];
533 - (void) drawInRect:(CGRect)rect withStyle:(NSString *)style {
534 if (NSString *custom = [self _iconLabelStyle]) {
535 NSString *combined = [NSString stringWithFormat:@"%@; %@", style, custom];
537 NSLog(@"WB:Debug:combined = %@", combined);
538 return [string_ drawInRect:rect withStyle:combined];
540 return [string_ drawInRect:rect withStyle:style];
543 - (BOOL) respondsToSelector:(SEL)sel {
545 sel == @selector(setInDock:)
546 ? YES : [super respondsToSelector:sel];
549 - (void) setInDock:(BOOL)docked {
555 static void SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$(SBStatusBarController<WinterBoard> *self, SEL sel, int mode, int orientation, float duration, int id, int animation) {
556 if (NSNumber *number = [Info_ objectForKey:@"StatusBarMode"])
557 mode = [number intValue];
558 return [self wb_setStatusBarMode:mode orientation:orientation duration:duration fenceID:id animation:animation];
561 /*static id SBStatusBar$initWithMode$orientation$(SBStatusBar<WinterBoard> *self, SEL sel, int mode, int orientation) {
562 return [self wb_initWithMode:mode orientation:orientation];
565 static id SBStatusBarContentsView$initWithStatusBar$mode$(SBStatusBarContentsView<WinterBoard> *self, SEL sel, id bar, int mode) {
566 if (NSNumber *number = [Info_ objectForKey:@"StatusBarContentsMode"])
567 mode = [number intValue];
568 return [self wb_initWithStatusBar:bar mode:mode];
571 static void SBStatusBarTimeView$drawRect$(SBStatusBarTimeView<WinterBoard> *self, SEL sel, CGRect rect) {
573 object_getInstanceVariable(self, "_time", (void **) &time);
574 if (time != nil && [time class] != [WBTime class])
575 object_setInstanceVariable(self, "_time", (void *) [[WBTime alloc] initWithTime:[time autorelease] view:self]);
576 return [self wb_drawRect:rect];
579 static void SBIconLabel$setInDock$(SBIconLabel<WinterBoard> *self, SEL sel, BOOL docked) {
581 object_getInstanceVariable(self, "_label", (void **) &label);
582 if (![Info_ boolForKey:@"UndockedIconLabels"])
584 if (label != nil && [label respondsToSelector:@selector(setInDock:)])
585 [label setInDock:docked];
586 return [self wb_setInDock:docked];
589 static id SBIconLabel$initWithSize$label$(SBIconLabel<WinterBoard> *self, SEL sel, CGSize size, NSString *label) {
590 // XXX: technically I'm misusing self here
591 return [self wb_initWithSize:size label:[[[WBIconLabel alloc] initWithString:label] autorelease]];
592 //return [self wb_initWithSize:size label:label];
595 extern "C" void FindMappedImages(void);
596 extern "C" NSData *UIImagePNGRepresentation(UIImage *);
598 static void (*__UISharedImageInitialize)(bool);
600 extern "C" void WBInitialize() {
601 NSLog(@"WB:Notice: Installing WinterBoard...");
603 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
606 memset(nl, 0, sizeof(nl));
608 nl[0].n_un.n_name = (char *) "___mappedImages";
609 nl[1].n_un.n_name = (char *) "__UISharedImageInitialize";
610 nl[2].n_un.n_name = (char *) "___currentContextCount";
611 nl[3].n_un.n_name = (char *) "___currentContextStack";
613 nlist("/System/Library/Frameworks/UIKit.framework/UIKit", nl);
615 ImageMap_ = (id *) nl[0].n_value;
616 __UISharedImageInitialize = (void (*)(bool)) nl[1].n_value;
617 ContextCount_ = (unsigned *) nl[2].n_value;
618 ContextStack_ = (void ***) nl[3].n_value;
620 __UISharedImageInitialize(false);
622 English_ = [[NSDictionary alloc] initWithContentsOfFile:@"/System/Library/CoreServices/SpringBoard.app/English.lproj/LocalizedApplicationNames.strings"];
624 English_ = [English_ retain];
626 Manager_ = [[NSFileManager defaultManager] retain];
627 UIImages_ = [[NSMutableSet alloc] initWithCapacity:16];
629 //WBRename("UINavigationBar", "initWithCoder:", (IMP) &UINavigationBar$initWithCoder$);
630 WBRename(true, "UINavigationBar", "setBarStyle:", (IMP) &UINavigationBar$setBarStyle$);
631 //WBRename("UINavigationBarBackground", "initWithFrame:withBarStyle:withTintColor:", (IMP) &UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$);
633 WBRename(false, "UIImage", "imageNamed:inBundle:", (IMP) &UIImage$imageNamed$inBundle$);
634 WBRename(false, "UIImage", "imageNamed:", (IMP) &UIImage$imageNamed$);
635 WBRename(false, "UIImage", "applicationImageNamed:", (IMP) &UIImage$applicationImageNamed$);
636 WBRename(true, "SBApplicationIcon", "icon", (IMP) &SBApplicationIcon$icon);
637 WBRename(true, "SBApplication", "pathForIcon", (IMP) &SBApplication$pathForIcon);
638 WBRename(true, "NSBundle", "pathForResource:ofType:", (IMP) &NSBundle$pathForResource$ofType$);
639 WBRename(true, "SBContentLayer", "initWithSize:", (IMP) &SBContentLayer$initWithSize$);
640 WBRename(true, "SBStatusBarContentsView", "initWithStatusBar:mode:", (IMP) &SBStatusBarContentsView$initWithStatusBar$mode$);
641 //WBRename(true, "SBStatusBar", "initWithMode:orientation:", (IMP) &SBStatusBar$initWithMode$orientation$);
642 WBRename(true, "SBStatusBarContentsView", "didMoveToSuperview", (IMP) &$didMoveToSuperview);
643 WBRename(true, "SBButtonBar", "didMoveToSuperview", (IMP) &$didMoveToSuperview);
644 WBRename(true, "SBIconLabel", "setInDock:", (IMP) &SBIconLabel$setInDock$);
645 WBRename(true, "SBIconLabel", "initWithSize:label:", (IMP) &SBIconLabel$initWithSize$label$);
646 WBRename(true, "SBStatusBarTimeView", "drawRect:", (IMP) &SBStatusBarTimeView$drawRect$);
647 WBRename(true, "SBStatusBarController", "setStatusBarMode:orientation:duration:fenceID:animation:", (IMP) &SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$);
649 themes_ = [[NSMutableArray alloc] initWithCapacity:8];
651 if (NSDictionary *settings = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"/User/Library/Preferences/com.saurik.WinterBoard.plist"]]) {
652 [settings autorelease];
654 NSArray *themes = [settings objectForKey:@"Themes"];
656 if (NSString *theme = [settings objectForKey:@"Theme"])
657 themes = [NSArray arrayWithObject:[NSDictionary dictionaryWithObjectsAndKeys:
659 [NSNumber numberWithBool:YES], @"Active",
662 for (NSDictionary *theme in themes) {
663 NSNumber *active = [theme objectForKey:@"Active"];
664 if (![active boolValue])
667 NSString *name = [theme objectForKey:@"Name"];
671 NSString *theme = nil;
674 NSString *path = [NSString stringWithFormat:@"/Library/Themes/%@.theme", name];
675 if ([Manager_ fileExistsAtPath:path]) {
676 [themes_ addObject:path];
682 NSString *path = [NSString stringWithFormat:@"/Library/Themes/%@", name];
683 if ([Manager_ fileExistsAtPath:path]) {
684 [themes_ addObject:path];
690 NSString *path = [NSString stringWithFormat:@"%@/Library/SummerBoard/Themes/%@", NSHomeDirectory(), name];
691 if ([Manager_ fileExistsAtPath:path]) {
692 [themes_ addObject:path];
699 Info_ = [[NSMutableDictionary dictionaryWithCapacity:16] retain];
701 for (NSString *theme in themes_) {
702 NSString *folder = [NSString stringWithFormat:@"%@/UIImages", theme];
703 if (NSArray *images = [Manager_ contentsOfDirectoryAtPath:folder error:NULL])
704 for (int i(0), e = [images count]; i != e; ++i) {
705 NSString *name = [images objectAtIndex:i];
706 if (![name hasSuffix:@".png"])
708 if ([UIImages_ containsObject:name])
710 NSString *path = [NSString stringWithFormat:@"%@/%@", folder, name];
711 UIImage *image = [UIImage imageWithContentsOfFile:path];
712 [*ImageMap_ setObject:(id)[image imageRef] forKey:name];
713 [UIImages_ addObject:name];
716 if (NSDictionary *info = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/Info.plist", theme]])
717 for (NSString *key in [info allKeys])
718 if ([Info_ objectForKey:key] == nil)
719 [Info_ setObject:[info objectForKey:key] forKey:key];
722 if ([Info_ objectForKey:@"UndockedIconLabels"] == nil)
723 [Info_ setObject:[NSNumber numberWithBool:(
724 [Info_ objectForKey:@"DockedIconLabelStyle"] != nil ||
725 [Info_ objectForKey:@"UndockedIconLabelStyle"] != nil
726 )] forKey:@"UndockedIconLabels"];
728 if (![Info_ boolForKey:@"UndockedIconLabels"])
730 NSLog(@"WB:Debug:Info = %@", [Info_ description]);