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 #import <CoreFoundation/CoreFoundation.h>
42 #import <Foundation/Foundation.h>
43 #import <CoreGraphics/CoreGraphics.h>
45 #import <Celestial/AVController.h>
46 #import <Celestial/AVItem.h>
47 #import <Celestial/AVQueue.h>
49 #include <substrate.h>
51 #import <UIKit/UIKit.h>
53 #import <SpringBoard/SBApplication.h>
54 #import <SpringBoard/SBApplicationIcon.h>
55 #import <SpringBoard/SBAppWindow.h>
56 #import <SpringBoard/SBAwayView.h>
57 #import <SpringBoard/SBBookmarkIcon.h>
58 #import <SpringBoard/SBButtonBar.h>
59 #import <SpringBoard/SBCalendarIconContentsView.h>
60 #import <SpringBoard/SBContentLayer.h>
61 #import <SpringBoard/SBIconController.h>
62 #import <SpringBoard/SBIconLabel.h>
63 #import <SpringBoard/SBIconList.h>
64 #import <SpringBoard/SBIconModel.h>
65 #import <SpringBoard/SBStatusBarContentsView.h>
66 #import <SpringBoard/SBStatusBarController.h>
67 #import <SpringBoard/SBStatusBarOperatorNameView.h>
68 #import <SpringBoard/SBStatusBarTimeView.h>
69 #import <SpringBoard/SBUIController.h>
70 #import <SpringBoard/SBWidgetApplicationIcon.h>
72 #import <MobileSMS/mSMSMessageTranscriptController.h>
74 #import <MediaPlayer/MPMoviePlayerController.h>
75 #import <MediaPlayer/MPVideoView.h>
76 #import <MediaPlayer/MPVideoView-PlaybackControl.h>
78 #import <CoreGraphics/CGGeometry.h>
80 extern "C" void __clear_cache (char *beg, char *end);
86 Class $MPMoviePlayerController;
88 Class $WebCoreFrameBridge;
93 Class $UINavigationBar;
97 Class $SBApplicationIcon;
99 Class $SBBookmarkIcon;
101 Class $SBCalendarIconContentsView;
102 Class $SBContentLayer;
104 Class $SBIconController;
108 Class $SBStatusBarContentsView;
109 Class $SBStatusBarController;
110 Class $SBStatusBarOperatorNameView;
111 Class $SBStatusBarTimeView;
112 Class $SBWidgetApplicationIcon;
114 @interface NSDictionary (WinterBoard)
115 - (UIColor *) colorForKey:(NSString *)key;
116 - (BOOL) boolForKey:(NSString *)key;
119 @implementation NSDictionary (WinterBoard)
121 - (UIColor *) colorForKey:(NSString *)key {
122 NSString *value = [self objectForKey:key];
129 - (BOOL) boolForKey:(NSString *)key {
130 if (NSString *value = [self objectForKey:key])
131 return [value boolValue];
138 bool Engineer_ = false;
140 static UIImage *(*_UIApplicationImageWithName)(NSString *name);
141 static UIImage *(*_UIImageAtPath)(NSString *name, NSBundle *path);
142 static CGImageRef (*_UIImageRefAtPath)(NSString *name, bool cache, UIImageOrientation *orientation);
143 static UIImage *(*_UIImageWithNameInDomain)(NSString *name, NSString *domain);
144 static NSBundle *(*_UIKitBundle)();
145 static void (*_UISharedImageInitialize)(bool);
146 static int (*_UISharedImageNameGetIdentifier)(NSString *);
147 static UIImage *(*_UISharedImageWithIdentifier)(int);
149 static NSMutableDictionary *UIImages_;
150 static NSMutableDictionary *PathImages_;
151 static NSMutableDictionary *Cache_;
152 static NSMutableDictionary *Strings_;
153 static NSMutableDictionary *Themed_;
154 static NSMutableDictionary *Bundles_;
156 static NSFileManager *Manager_;
157 static NSDictionary *English_;
158 static NSMutableDictionary *Info_;
159 static NSMutableArray *themes_;
161 static NSString *$getTheme$(NSArray *files, bool parent = false) {
163 if (NSString *path = [Themed_ objectForKey:files])
164 return reinterpret_cast<id>(path) == [NSNull null] ? nil : path;
167 NSLog(@"WB:Debug: %@", [files description]);
171 for (NSString *theme in themes_)
172 for (NSString *file in files) {
173 path = [NSString stringWithFormat:@"%@/%@", theme, file];
174 if ([Manager_ fileExistsAtPath:path]) {
175 path = parent ? theme : path;
183 [Themed_ setObject:(path == nil ? [NSNull null] : reinterpret_cast<id>(path)) forKey:files];
187 static NSString *$pathForFile$inBundle$(NSString *file, NSBundle *bundle, bool ui) {
188 NSString *identifier = [bundle bundleIdentifier];
189 NSMutableArray *names = [NSMutableArray arrayWithCapacity:8];
191 if (identifier != nil)
192 [names addObject:[NSString stringWithFormat:@"Bundles/%@/%@", identifier, file]];
193 if (NSString *folder = [[bundle bundlePath] lastPathComponent])
194 [names addObject:[NSString stringWithFormat:@"Folders/%@/%@", folder, file]];
196 [names addObject:[NSString stringWithFormat:@"UIImages/%@", file]];
198 #define remapResourceName(oldname, newname) \
199 else if ([file isEqualToString:oldname]) \
200 [names addObject:[NSString stringWithFormat:@"%@.png", newname]]; \
202 if (identifier == nil);
203 else if ([identifier isEqualToString:@"com.apple.calculator"])
204 [names addObject:[NSString stringWithFormat:@"Files/Applications/Calculator.app/%@", file]];
205 else if (![identifier isEqualToString:@"com.apple.springboard"]);
206 remapResourceName(@"FSO_BG.png", @"StatusBar")
207 remapResourceName(@"SBDockBG.png", @"Dock")
208 remapResourceName(@"SBWeatherCelsius.png", @"Icons/Weather")
210 if (NSString *path = $getTheme$(names))
215 static NSString *$pathForIcon$(SBApplication *self) {
216 NSString *identifier = [self bundleIdentifier];
217 NSString *path = [self path];
218 NSString *folder = [path lastPathComponent];
219 NSString *dname = [self displayName];
220 NSString *didentifier = [self displayIdentifier];
223 NSLog(@"WB:Debug: [SBApplication(%@:%@:%@:%@) pathForIcon]", identifier, folder, dname, didentifier);
225 NSMutableArray *names = [NSMutableArray arrayWithCapacity:8];
227 if (identifier != nil)
228 [names addObject:[NSString stringWithFormat:@"Bundles/%@/icon.png", identifier]];
230 [names addObject:[NSString stringWithFormat:@"Folders/%@/icon.png", folder]];
232 #define testForIcon(Name) \
233 if (NSString *name = Name) \
234 [names addObject:[NSString stringWithFormat:@"Icons/%@.png", name]];
236 testForIcon(identifier);
239 if (didentifier != nil) {
240 testForIcon([English_ objectForKey:didentifier]);
242 NSArray *parts = [didentifier componentsSeparatedByString:@"-"];
243 if ([parts count] != 1)
244 if (NSDictionary *english = [[[NSDictionary alloc] initWithContentsOfFile:[path stringByAppendingString:@"/English.lproj/UIRoleDisplayNames.strings"]] autorelease])
245 testForIcon([english objectForKey:[parts lastObject]]);
248 if (NSString *path = $getTheme$(names))
253 @interface NSBundle (WinterBoard)
254 + (NSBundle *) wb$bundleWithFile:(NSString *)path;
257 @implementation NSBundle (WinterBoard)
259 + (NSBundle *) wb$bundleWithFile:(NSString *)path {
260 path = [path stringByDeletingLastPathComponent];
261 if (path == nil || [path length] == 0 || [path isEqualToString:@"/"])
264 NSBundle *bundle([Bundles_ objectForKey:path]);
265 if (reinterpret_cast<id>(bundle) == [NSNull null])
267 else if (bundle == nil) {
268 if ([Manager_ fileExistsAtPath:[path stringByAppendingPathComponent:@"Info.plist"]])
269 bundle = [NSBundle bundleWithPath:path];
271 bundle = [NSBundle wb$bundleWithFile:path];
273 NSLog(@"WB:Debug:PathBundle(%@, %@)", path, bundle);
274 [Bundles_ setObject:(bundle == nil ? [NSNull null] : reinterpret_cast<id>(bundle)) forKey:path];
282 @interface NSString (WinterBoard)
283 - (NSString *) wb$themedPath;
286 @implementation NSString (WinterBoard)
288 - (NSString *) wb$themedPath {
290 NSLog(@"WB:Debug:Bypass(\"%@\")", self);
292 if (NSBundle *bundle = [NSBundle wb$bundleWithFile:self]) {
293 NSString *file([self stringByResolvingSymlinksInPath]);
294 NSString *prefix([[bundle bundlePath] stringByResolvingSymlinksInPath]);
295 if ([file hasPrefix:prefix]) {
296 NSUInteger length([prefix length]);
297 if (length != [file length])
298 if (NSString *path = $pathForFile$inBundle$([file substringFromIndex:(length + 1)], bundle, false))
308 MSHook(void, SBIconModel$cacheImageForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
309 _SBIconModel$cacheImageForIcon$(self, sel, icon);
310 NSString *key([icon displayIdentifier]);
312 if (UIImage *image = [icon icon]) {
313 CGColorSpaceRef space(CGColorSpaceCreateDeviceRGB());
314 CGRect rect = {CGPointMake(1, 1), [image size]};
315 CGSize size = {rect.size.width + 2, rect.size.height + 2};
317 CGContextRef context(CGBitmapContextCreate(NULL, size.width, size.height, 8, 4 * size.width, space, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst));
318 CGColorSpaceRelease(space);
320 CGContextDrawImage(context, rect, [image CGImage]);
321 CGImageRef ref(CGBitmapContextCreateImage(context));
322 CGContextRelease(context);
324 UIImage *image([UIImage imageWithCGImage:ref]);
327 [Cache_ setObject:image forKey:key];
331 MSHook(UIImage *, SBIconModel$getCachedImagedForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
332 NSString *key([icon displayIdentifier]);
333 if (UIImage *image = [Cache_ objectForKey:key])
336 return _SBIconModel$getCachedImagedForIcon$(self, sel, icon);
339 MSHook(UIImage *, SBApplicationIcon$icon, SBApplicationIcon *self, SEL sel) {
340 if (![Info_ boolForKey:@"ComposeStoreIcons"])
341 if (NSString *path = $pathForIcon$([self application]))
342 return [UIImage imageWithContentsOfFile:path];
343 return _SBApplicationIcon$icon(self, sel);
346 MSHook(UIImage *, SBWidgetApplicationIcon$icon, SBWidgetApplicationIcon *self, SEL sel) {
348 NSLog(@"WB:Debug:Widget(%@:%@)", [self displayIdentifier], [self displayName]);
349 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]]))
350 return [UIImage imageWithContentsOfFile:path];
351 return _SBWidgetApplicationIcon$icon(self, sel);
354 MSHook(UIImage *, SBBookmarkIcon$icon, SBBookmarkIcon *self, SEL sel) {
356 NSLog(@"WB:Debug:Bookmark(%@:%@)", [self displayIdentifier], [self displayName]);
357 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]]))
358 return [UIImage imageWithContentsOfFile:path];
359 return _SBBookmarkIcon$icon(self, sel);
362 MSHook(NSString *, SBApplication$pathForIcon, SBApplication *self, SEL sel) {
363 if (NSString *path = $pathForIcon$(self))
365 return _SBApplication$pathForIcon(self, sel);
368 static UIImage *CachedImageAtPath(NSString *path) {
369 path = [path stringByResolvingSymlinksInPath];
370 UIImage *image = [PathImages_ objectForKey:path];
372 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
373 image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
375 image = [image autorelease];
376 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:path];
380 MSHook(CGImageRef, _UIImageRefAtPath, NSString *name, bool cache, UIImageOrientation *orientation) {
382 NSLog(@"WB:Debug: _UIImageRefAtPath(\"%@\", %s)", name, cache ? "true" : "false");
383 return __UIImageRefAtPath([name wb$themedPath], cache, orientation);
386 /*MSHook(UIImage *, _UIImageAtPath, NSString *name, NSBundle *bundle) {
388 return __UIImageAtPath(name, nil);
390 NSString *key = [NSString stringWithFormat:@"B:%@/%@", [bundle bundleIdentifier], name];
391 UIImage *image = [PathImages_ objectForKey:key];
393 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
395 NSLog(@"WB:Debug: _UIImageAtPath(\"%@\", %@)", name, bundle);
396 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
397 image = CachedImageAtPath(path);
399 image = __UIImageAtPath(name, bundle);
400 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
405 MSHook(UIImage *, _UIApplicationImageWithName, NSString *name) {
406 NSBundle *bundle = [NSBundle mainBundle];
408 NSLog(@"WB:Debug: _UIApplicationImageWithName(\"%@\", %@)", name, bundle);
409 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
410 return CachedImageAtPath(path);
411 return __UIApplicationImageWithName(name);
414 #define WBDelegate(delegate) \
415 - (NSMethodSignature*) methodSignatureForSelector:(SEL)sel { \
417 NSLog(@"WB:MS:%s:(%s)", class_getName([self class]), sel_getName(sel)); \
418 if (NSMethodSignature *sig = [delegate methodSignatureForSelector:sel]) \
420 NSLog(@"WB:Error: [%s methodSignatureForSelector:(%s)]", class_getName([self class]), sel_getName(sel)); \
424 - (void) forwardInvocation:(NSInvocation*)inv { \
425 SEL sel = [inv selector]; \
426 if ([delegate respondsToSelector:sel]) \
427 [inv invokeWithTarget:delegate]; \
429 NSLog(@"WB:Error: [%s forwardInvocation:(%s)]", class_getName([self class]), sel_getName(sel)); \
432 MSHook(NSString *, NSBundle$pathForResource$ofType$, NSBundle *self, SEL sel, NSString *resource, NSString *type) {
433 NSString *file = type == nil ? resource : [NSString stringWithFormat:@"%@.%@", resource, type];
435 NSLog(@"WB:Debug: [NSBundle(%@) pathForResource:\"%@\"]", [self bundleIdentifier], file);
436 if (NSString *path = $pathForFile$inBundle$(file, self, false))
438 return _NSBundle$pathForResource$ofType$(self, sel, resource, type);
441 void $setBarStyle$_(NSString *name, int &style) {
443 NSLog(@"WB:Debug:%@Style:%d", name, style);
444 NSNumber *number = nil;
446 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style-%d", name, style]];
448 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style", name]];
450 style = [number intValue];
452 NSLog(@"WB:Debug:%@Style=%d", name, style);
456 MSHook(void, SBCalendarIconContentsView$drawRect$, SBCalendarIconContentsView *self, SEL sel, CGRect rect) {
457 NSBundle *bundle([NSBundle mainBundle]);
459 CFLocaleRef locale(CFLocaleCopyCurrent());
460 CFDateFormatterRef formatter(CFDateFormatterCreate(NULL, locale, kCFDateFormatterNoStyle, kCFDateFormatterNoStyle));
463 CFDateRef now(CFDateCreate(NULL, CFAbsoluteTimeGetCurrent()));
465 CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NUMBER_FORMAT" value:@"" table:@"SpringBoard"]);
466 CFStringRef date(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
467 CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NAME_FORMAT" value:@"" table:@"SpringBoard"]);
468 CFStringRef day(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
472 CFRelease(formatter);
474 NSString *datestyle(@""
475 "font-family: Helvetica; "
476 "font-weight: bold; "
482 NSString *daystyle(@""
483 "font-family: Helvetica; "
484 "font-weight: bold; "
487 "text-shadow: rgba(0, 0, 0, 0.2) -1px -1px 2px; "
490 if (NSString *style = [Info_ objectForKey:@"CalendarIconDateStyle"])
491 datestyle = [datestyle stringByAppendingString:style];
492 if (NSString *style = [Info_ objectForKey:@"CalendarIconDayStyle"])
493 daystyle = [daystyle stringByAppendingString:style];
495 float width([self bounds].size.width);
497 CGSize datesize = [(NSString *)date sizeWithStyle:datestyle forWidth:(width + leeway)];
498 CGSize daysize = [(NSString *)day sizeWithStyle:daystyle forWidth:(width + leeway)];
500 [(NSString *)date drawAtPoint:CGPointMake(
501 (width + 1 - datesize.width) / 2, (71 - datesize.height) / 2
502 ) withStyle:datestyle];
504 [(NSString *)day drawAtPoint:CGPointMake(
505 (width + 1 - daysize.width) / 2, (16 - daysize.height) / 2
506 ) withStyle:daystyle];
512 /*static id UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$(UINavigationBarBackground<WinterBoard> *self, SEL sel, CGRect frame, int style, UIColor *tint) {
515 if (NSNumber *number = [Info_ objectForKey:@"NavigationBarStyle"])
516 style = [number intValue];
518 if (UIColor *color = [Info_ colorForKey:@"NavigationBarTint"])
521 return [self wb$initWithFrame:frame withBarStyle:style withTintColor:tint];
524 /*static id UINavigationBar$initWithCoder$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame, NSCoder *coder) {
525 self = [self wb$initWithCoder:coder];
528 UINavigationBar$setBarStyle$_(self);
532 static id UINavigationBar$initWithFrame$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame) {
533 self = [self wb$initWithFrame:frame];
536 UINavigationBar$setBarStyle$_(self);
540 MSHook(void, UIToolbar$setBarStyle$, UIToolbar *self, SEL sel, int style) {
541 $setBarStyle$_(@"Toolbar", style);
542 return _UIToolbar$setBarStyle$(self, sel, style);
545 MSHook(void, UINavigationBar$setBarStyle$, UINavigationBar *self, SEL sel, int style) {
546 $setBarStyle$_(@"NavigationBar", style);
547 return _UINavigationBar$setBarStyle$(self, sel, style);
550 MSHook(void, SBButtonBar$didMoveToSuperview, UIView *self, SEL sel) {
551 [[self superview] setBackgroundColor:[UIColor clearColor]];
552 _SBButtonBar$didMoveToSuperview(self, sel);
555 MSHook(void, SBStatusBarContentsView$didMoveToSuperview, UIView *self, SEL sel) {
556 [[self superview] setBackgroundColor:[UIColor clearColor]];
557 _SBStatusBarContentsView$didMoveToSuperview(self, sel);
560 MSHook(UIImage *, UIImage$defaultDesktopImage, UIImage *self, SEL sel) {
562 NSLog(@"WB:Debug:DefaultDesktopImage");
563 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"LockBackground.png", @"LockBackground.jpg", nil]))
564 return [UIImage imageWithContentsOfFile:path];
565 return _UIImage$defaultDesktopImage(self, sel);
568 static NSArray *Wallpapers_;
569 static NSString *WallpaperFile_;
570 static UIImageView *WallpaperImage_;
571 static UIWebDocumentView *WallpaperPage_;
572 static NSURL *WallpaperURL_;
574 #define _release(object) \
575 do if (object != nil) { \
580 MSHook(id, SBContentLayer$initWithSize$, SBContentLayer *self, SEL sel, CGSize size) {
581 self = _SBContentLayer$initWithSize$(self, sel, size);
585 _release(WallpaperFile_);
586 _release(WallpaperImage_);
587 _release(WallpaperPage_);
588 _release(WallpaperURL_);
590 if (NSString *theme = $getTheme$(Wallpapers_, true)) {
591 NSString *mp4 = [theme stringByAppendingPathComponent:@"Wallpaper.mp4"];
592 if ([Manager_ fileExistsAtPath:mp4]) {
596 static AVController *controller_(nil);
597 if (controller_ == nil) {
598 AVQueue *queue([AVQueue avQueue]);
599 controller_ = [[AVController avControllerWithQueue:queue error:&error] retain];
602 AVQueue *queue([controller_ queue]);
604 UIView *video([[[UIView alloc] initWithFrame:[self bounds]] autorelease]);
605 [controller_ setLayer:[video _layer]];
607 AVItem *item([[[AVItem alloc] initWithPath:mp4 error:&error] autorelease]);
608 [queue appendItem:item error:&error];
610 [controller_ play:&error];
611 #elif UseMPMoviePlayerController
612 NSURL *url([NSURL fileURLWithPath:mp4]);
613 MPMoviePlayerController *controller = [[MPMoviePlayerController alloc] initWithContentURL:url];
614 controller.movieControlMode = MPMovieControlModeHidden;
617 MPVideoView *video = [[[$MPVideoView alloc] initWithFrame:[self bounds]] autorelease];
618 [video setMovieWithPath:mp4];
619 [video setRepeatMode:1];
620 [video setRepeatGap:-1];
621 [video playFromBeginning];;
624 [self addSubview:video];
627 NSString *png = [theme stringByAppendingPathComponent:@"Wallpaper.png"];
628 NSString *jpg = [theme stringByAppendingPathComponent:@"Wallpaper.jpg"];
631 if ([Manager_ fileExistsAtPath:png])
633 else if ([Manager_ fileExistsAtPath:jpg])
639 image = [[UIImage alloc] initWithContentsOfFile:path];
641 image = [image autorelease];
645 WallpaperFile_ = [path retain];
646 WallpaperImage_ = [[UIImageView alloc] initWithImage:image];
647 [self addSubview:WallpaperImage_];
650 NSString *html = [theme stringByAppendingPathComponent:@"Wallpaper.html"];
651 if ([Manager_ fileExistsAtPath:html]) {
652 CGRect bounds = [self bounds];
654 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
655 [view setAutoresizes:true];
657 WallpaperPage_ = [view retain];
658 WallpaperURL_ = [[NSURL fileURLWithPath:html] retain];
660 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
662 [[view webView] setDrawsBackground:false];
663 [view setBackgroundColor:[UIColor clearColor]];
665 [self addSubview:view];
669 for (size_t i(0), e([themes_ count]); i != e; ++i) {
670 NSString *theme = [themes_ objectAtIndex:(e - i - 1)];
671 NSString *html = [theme stringByAppendingPathComponent:@"Widget.html"];
672 if ([Manager_ fileExistsAtPath:html]) {
673 CGRect bounds = [self bounds];
675 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
676 [view setAutoresizes:true];
678 NSURL *url = [NSURL fileURLWithPath:html];
679 [view loadRequest:[NSURLRequest requestWithURL:url]];
681 [[view webView] setDrawsBackground:false];
682 [view setBackgroundColor:[UIColor clearColor]];
684 [self addSubview:view];
691 MSHook(void, SBAwayView$updateDesktopImage$, SBAwayView *self, SEL sel, UIImage *image) {
692 NSString *path = $getTheme$([NSArray arrayWithObject:@"LockBackground.html"]);
693 UIView *&_backgroundView(MSHookIvar<UIView *>(self, "_backgroundView"));
695 if (path != nil && _backgroundView != nil)
698 _SBAwayView$updateDesktopImage$(self, sel, image);
701 CGRect bounds = [self bounds];
703 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
704 [view setAutoresizes:true];
706 if (WallpaperPage_ != nil)
707 [WallpaperPage_ release];
708 WallpaperPage_ = [view retain];
710 if (WallpaperURL_ != nil)
711 [WallpaperURL_ release];
712 WallpaperURL_ = [[NSURL fileURLWithPath:path] retain];
714 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
716 [[view webView] setDrawsBackground:false];
717 [view setBackgroundColor:[UIColor clearColor]];
719 [self insertSubview:view aboveSubview:_backgroundView];
723 /*extern "C" CGColorRef CGGStateGetSystemColor(void *);
724 extern "C" CGColorRef CGGStateGetFillColor(void *);
725 extern "C" CGColorRef CGGStateGetStrokeColor(void *);
726 extern "C" NSString *UIStyleStringFromColor(CGColorRef);*/
728 /* WBTimeLabel {{{ */
729 @interface WBTimeLabel : NSProxy {
731 _transient SBStatusBarTimeView *view_;
734 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view;
738 @implementation WBTimeLabel
745 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view {
746 time_ = [time retain];
753 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
754 if (NSString *custom = [Info_ objectForKey:@"TimeStyle"]) {
755 BOOL &_mode(MSHookIvar<BOOL>(view_, "_mode"));;
757 [time_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
758 "font-family: Helvetica; "
759 "font-weight: bold; "
762 "%@", _mode ? @"white" : @"black", custom]];
767 return [time_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
772 /* WBBadgeLabel {{{ */
773 @interface WBBadgeLabel : NSProxy {
777 - (id) initWithBadge:(NSString *)badge;
781 @implementation WBBadgeLabel
788 - (id) initWithBadge:(NSString *)badge {
789 badge_ = [badge retain];
795 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
796 if (NSString *custom = [Info_ objectForKey:@"BadgeStyle"]) {
797 [badge_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
798 "font-family: Helvetica; "
799 "font-weight: bold; "
807 return [badge_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
813 MSHook(id, SBIconBadge$initWithBadge$, SBIconBadge *self, SEL sel, NSString *badge) {
814 if ((self = _SBIconBadge$initWithBadge$(self, sel, badge)) != nil) {
815 id &_badge(MSHookIvar<id>(self, "_badge"));
817 if (id label = [[WBBadgeLabel alloc] initWithBadge:[_badge autorelease]])
822 MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, float duration, int id, int animation) {
824 NSLog(@"WB:Debug:setStatusBarMode:%d", mode);
825 if (mode < 100) // 104:hidden 105:glowing
826 if (NSNumber *number = [Info_ objectForKey:@"StatusBarMode"])
827 mode = [number intValue];
828 return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$(self, sel, mode, orientation, duration, id, animation);
831 MSHook(id, SBStatusBarContentsView$initWithStatusBar$mode$, SBStatusBarContentsView *self, SEL sel, id bar, int mode) {
832 if (NSNumber *number = [Info_ objectForKey:@"StatusBarContentsMode"])
833 mode = [number intValue];
834 return _SBStatusBarContentsView$initWithStatusBar$mode$(self, sel, bar, mode);
837 MSHook(NSString *, SBStatusBarOperatorNameView$operatorNameStyle, SBStatusBarOperatorNameView *self, SEL sel) {
838 NSString *style(_SBStatusBarOperatorNameView$operatorNameStyle(self, sel));
840 NSLog(@"operatorNameStyle= %@", style);
841 if (NSString *custom = [Info_ objectForKey:@"OperatorNameStyle"])
842 style = [NSString stringWithFormat:@"%@; %@", style, custom];
846 MSHook(void, SBStatusBarOperatorNameView$setOperatorName$fullSize$, SBStatusBarOperatorNameView *self, SEL sel, NSString *name, BOOL full) {
848 NSLog(@"setOperatorName:\"%@\" fullSize:%u", name, full);
849 return _SBStatusBarOperatorNameView$setOperatorName$fullSize$(self, sel, name, NO);
852 // XXX: replace this with [SBStatusBarTimeView tile]
853 MSHook(void, SBStatusBarTimeView$drawRect$, SBStatusBarTimeView *self, SEL sel, CGRect rect) {
854 id &_time(MSHookIvar<id>(self, "_time"));
855 if (_time != nil && [_time class] != [WBTimeLabel class])
856 object_setInstanceVariable(self, "_time", reinterpret_cast<void *>([[WBTimeLabel alloc] initWithTime:[_time autorelease] view:self]));
857 return _SBStatusBarTimeView$drawRect$(self, sel, rect);
860 @interface UIView (WinterBoard)
861 - (bool) wb$isWBImageView;
864 @implementation UIView (WinterBoard)
866 - (bool) wb$isWBImageView {
872 @interface WBImageView : UIImageView {
875 - (bool) wb$isWBImageView;
876 - (void) wb$updateFrame;
879 @implementation WBImageView
881 - (bool) wb$isWBImageView {
885 - (void) wb$updateFrame {
886 CGRect frame([self frame]);
889 for (UIView *view(self); ; ) {
890 view = [view superview];
893 frame.origin.y -= [view frame].origin.y;
896 [self setFrame:frame];
901 MSHook(void, SBIconList$setFrame$, SBIconList *self, SEL sel, CGRect frame) {
902 NSArray *subviews([self subviews]);
903 WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
904 if (view != nil && [view wb$isWBImageView])
905 [view wb$updateFrame];
906 _SBIconList$setFrame$(self, sel, frame);
909 MSHook(void, SBIconController$noteNumberOfIconListsChanged, SBIconController *self, SEL sel) {
910 SBIconModel *&_iconModel(MSHookIvar<SBIconModel *>(self, "_iconModel"));
911 NSArray *lists([_iconModel iconLists]);
913 for (unsigned i(0), e([lists count]); i != e; ++i)
914 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Page%u.png", i]])) {
915 SBIconList *list([lists objectAtIndex:i]);
916 NSArray *subviews([list subviews]);
918 WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
919 if (view == nil || ![view wb$isWBImageView]) {
920 view = [[[WBImageView alloc] init] autorelease];
921 [list insertSubview:view atIndex:0];
924 UIImage *image([UIImage imageWithContentsOfFile:path]);
925 [view setImage:image];
926 [view wb$updateFrame];
929 return _SBIconController$noteNumberOfIconListsChanged(self, sel);
932 MSHook(id, SBIconLabel$initWithSize$label$, SBIconLabel *self, SEL sel, CGSize size, NSString *label) {
933 self = _SBIconLabel$initWithSize$label$(self, sel, size, label);
935 [self setClipsToBounds:NO];
939 MSHook(void, SBIconLabel$setInDock$, SBIconLabel *self, SEL sel, BOOL docked) {
940 id &_label(MSHookIvar<id>(self, "_label"));
941 if (![Info_ boolForKey:@"UndockedIconLabels"])
943 if (_label != nil && [_label respondsToSelector:@selector(setInDock:)])
944 [_label setInDock:docked];
945 return _SBIconLabel$setInDock$(self, sel, docked);
948 MSHook(NSString *, NSBundle$localizedStringForKey$value$table$, NSBundle *self, SEL sel, NSString *key, NSString *value, NSString *table) {
949 NSString *identifier = [self bundleIdentifier];
950 NSLocale *locale = [NSLocale currentLocale];
951 NSString *language = [locale objectForKey:NSLocaleLanguageCode];
953 NSLog(@"WB:Debug:[NSBundle(%@) localizedStringForKey:\"%@\" value:\"%@\" table:\"%@\"] (%@)", identifier, key, value, table, language);
954 NSString *file = table == nil ? @"Localizable" : table;
955 NSString *name = [NSString stringWithFormat:@"%@:%@", identifier, file];
956 NSDictionary *strings;
957 if ((strings = [Strings_ objectForKey:name]) != nil) {
958 if (static_cast<id>(strings) != [NSNull null]) strings:
959 if (NSString *value = [strings objectForKey:key])
961 } else if (NSString *path = $pathForFile$inBundle$([NSString stringWithFormat:@"%@.lproj/%@.strings",
964 if ((strings = [[NSDictionary alloc] initWithContentsOfFile:path]) != nil) {
965 [Strings_ setObject:[strings autorelease] forKey:name];
969 [Strings_ setObject:[NSNull null] forKey:name];
970 return _NSBundle$localizedStringForKey$value$table$(self, sel, key, value, table);
973 @class WebCoreFrameBridge;
974 MSHook(CGSize, WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$, WebCoreFrameBridge *self, SEL sel, id node, float width) {
977 void **core(reinterpret_cast<void **>([node _node]));
978 if (core == NULL || core[6] == NULL)
980 return _WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$(self, sel, node, width);
983 MSHook(void, SBIconLabel$drawRect$, SBIconLabel *self, SEL sel, CGRect rect) {
984 CGRect bounds = [self bounds];
986 static Ivar drawMoreLegibly = object_getInstanceVariable(self, "_drawMoreLegibly", NULL);
989 Ivar ivar = object_getInstanceVariable(self, "_inDock", reinterpret_cast<void **>(&docked));
990 docked = (docked & (ivar_getOffset(ivar) == ivar_getOffset(drawMoreLegibly) ? 0x2 : 0x1)) != 0;
992 NSString *label(MSHookIvar<NSString *>(self, "_label"));
994 NSString *style = [NSString stringWithFormat:@""
995 "font-family: Helvetica; "
996 "font-weight: bold; "
999 "", docked ? @"white" : @"#b3b3b3"];
1002 style = [style stringByAppendingString:@"text-shadow: rgba(0, 0, 0, 0.5) 0px -1px 0px; "];
1004 bool ellipsis(false);
1005 float max = 75, width;
1007 width = [(ellipsis ? [label stringByAppendingString:@"..."] : label) sizeWithStyle:style forWidth:320].width;
1010 size_t length([label length]);
1011 float spacing((width - max) / (length - 1));
1013 if (spacing > 1.25) {
1015 label = [label substringToIndex:(length - 1)];
1019 style = [style stringByAppendingString:[NSString stringWithFormat:@"letter-spacing: -%f; ", spacing]];
1023 label = [label stringByAppendingString:@"..."];
1025 if (NSString *custom = [Info_ objectForKey:(docked ? @"DockedIconLabelStyle" : @"UndockedIconLabelStyle")])
1026 style = [style stringByAppendingString:custom];
1028 CGSize size = [label sizeWithStyle:style forWidth:bounds.size.width];
1029 [label drawAtPoint:CGPointMake((bounds.size.width - size.width) / 2, 0) withStyle:style];
1032 MSHook(void, mSMSMessageTranscriptController$loadView, mSMSMessageTranscriptController *self, SEL sel) {
1033 _mSMSMessageTranscriptController$loadView(self, sel);
1035 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"SMSBackground.png", @"SMSBackground.jpg", nil]))
1036 if (UIImage *image = [[UIImage alloc] initWithContentsOfFile:path]) {
1037 [image autorelease];
1038 UIView *&_transcriptLayer(MSHookIvar<UIView *>(self, "_transcriptLayer"));
1039 UIView *parent([_transcriptLayer superview]);
1040 UIImageView *background([[[UIImageView alloc] initWithImage:image] autorelease]);
1041 [parent insertSubview:background belowSubview:_transcriptLayer];
1042 [_transcriptLayer setBackgroundColor:[UIColor clearColor]];
1046 MSHook(UIImage *, _UIImageWithName, NSString *name) {
1047 int id(_UISharedImageNameGetIdentifier(name));
1049 NSLog(@"WB:Debug: _UIImageWithName(\"%@\", %d)", name, id);
1052 return _UIImageAtPath(name, _UIKitBundle());
1054 NSNumber *key([NSNumber numberWithInt:id]);
1055 UIImage *image = [UIImages_ objectForKey:key];
1057 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
1058 if (NSString *path = $pathForFile$inBundle$(name, _UIKitBundle(), true)) {
1059 image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
1061 [image autorelease];
1064 image = _UISharedImageWithIdentifier(id);
1065 [UIImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
1070 MSHook(UIImage *, _UIImageWithNameInDomain, NSString *name, NSString *domain) {
1071 NSString *key = [NSString stringWithFormat:@"D:%zu%@%@", [domain length], domain, name];
1072 UIImage *image = [PathImages_ objectForKey:key];
1074 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
1076 NSLog(@"WB:Debug: UIImageWithNameInDomain(\"%@\", \"%@\")", name, domain);
1077 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Domains/%@/%@", domain, name]])) {
1078 image = [[UIImage alloc] initWithContentsOfFile:path];
1080 [image autorelease];
1083 image = __UIImageWithNameInDomain(name, domain);
1084 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
1088 MSHook(GSFontRef, GSFontCreateWithName, const char *name, GSFontSymbolicTraits traits, float size) {
1089 if (NSString *font = [Info_ objectForKey:[NSString stringWithFormat:@"FontName-%s", name]])
1090 name = [font UTF8String];
1091 return _GSFontCreateWithName(name, traits, size);
1094 #define AudioToolbox "/System/Library/Frameworks/AudioToolbox.framework/AudioToolbox"
1095 #define UIKit "/System/Library/Frameworks/UIKit.framework/UIKit"
1097 bool (*_Z24GetFileNameForThisActionmPcRb)(unsigned long a0, char *a1, bool &a2);
1099 MSHook(bool, _Z24GetFileNameForThisActionmPcRb, unsigned long a0, char *a1, bool &a2) {
1100 bool value = __Z24GetFileNameForThisActionmPcRb(a0, a1, a2);
1102 NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %s, %u) = %u", a0, value ? a1 : NULL, a2, value);
1105 NSString *path = [NSString stringWithUTF8String:a1];
1106 if ([path hasPrefix:@"/System/Library/Audio/UISounds/"]) {
1107 NSString *file = [path substringFromIndex:31];
1109 for (NSString *theme in themes_) {
1110 NSString *path([NSString stringWithFormat:@"%@/UISounds/%@", theme, file]);
1111 if ([Manager_ fileExistsAtPath:path]) {
1112 strcpy(a1, [path UTF8String]);
1121 static void ChangeWallpaper(
1122 CFNotificationCenterRef center,
1126 CFDictionaryRef info
1129 NSLog(@"WB:Debug:ChangeWallpaper!");
1132 if (WallpaperFile_ != nil) {
1133 image = [[UIImage alloc] initWithContentsOfFile:WallpaperFile_];
1135 image = [image autorelease];
1138 if (WallpaperImage_ != nil)
1139 [WallpaperImage_ setImage:image];
1140 if (WallpaperPage_ != nil)
1141 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
1145 #define WBRename(name, sel, imp) \
1146 _ ## name ## $ ## imp = MSHookMessage($ ## name, @selector(sel), &$ ## name ## $ ## imp)
1148 extern "C" void WBInitialize() {
1149 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
1151 NSString *identifier([[NSBundle mainBundle] bundleIdentifier]);
1153 NSLog(@"WB:Notice: WinterBoard");
1156 memset(nl, 0, sizeof(nl));
1158 nl[0].n_un.n_name = (char *) "__UIApplicationImageWithName";
1159 nl[1].n_un.n_name = (char *) "__UIImageAtPath";
1160 nl[2].n_un.n_name = (char *) "__UIImageRefAtPath";
1161 nl[3].n_un.n_name = (char *) "__UIImageWithNameInDomain";
1162 nl[4].n_un.n_name = (char *) "__UIKitBundle";
1163 nl[5].n_un.n_name = (char *) "__UISharedImageInitialize";
1164 nl[6].n_un.n_name = (char *) "__UISharedImageNameGetIdentifier";
1165 nl[7].n_un.n_name = (char *) "__UISharedImageWithIdentifier";
1169 _UIApplicationImageWithName = (UIImage *(*)(NSString *)) nl[0].n_value;
1170 _UIImageAtPath = (UIImage *(*)(NSString *, NSBundle *)) nl[1].n_value;
1171 _UIImageRefAtPath = (CGImageRef (*)(NSString *, bool, UIImageOrientation *)) nl[2].n_value;
1172 _UIImageWithNameInDomain = (UIImage *(*)(NSString *, NSString *)) nl[3].n_value;
1173 _UIKitBundle = (NSBundle *(*)()) nl[4].n_value;
1174 _UISharedImageInitialize = (void (*)(bool)) nl[5].n_value;
1175 _UISharedImageNameGetIdentifier = (int (*)(NSString *)) nl[6].n_value;
1176 _UISharedImageWithIdentifier = (UIImage *(*)(int)) nl[7].n_value;
1178 MSHookFunction(_UIApplicationImageWithName, &$_UIApplicationImageWithName, &__UIApplicationImageWithName);
1179 MSHookFunction(_UIImageRefAtPath, &$_UIImageRefAtPath, &__UIImageRefAtPath);
1180 MSHookFunction(_UIImageWithName, &$_UIImageWithName, &__UIImageWithName);
1181 MSHookFunction(_UIImageWithNameInDomain, &$_UIImageWithNameInDomain, &__UIImageWithNameInDomain);
1183 MSHookFunction(&GSFontCreateWithName, &$GSFontCreateWithName, &_GSFontCreateWithName);
1185 if (dlopen(AudioToolbox, RTLD_LAZY | RTLD_NOLOAD) != NULL) {
1187 memset(nl, 0, sizeof(nl));
1188 nl[0].n_un.n_name = (char *) "__Z24GetFileNameForThisActionmPcRb";
1189 nlist(AudioToolbox, nl);
1190 _Z24GetFileNameForThisActionmPcRb = (bool (*)(unsigned long, char *, bool &)) nl[0].n_value;
1191 MSHookFunction(_Z24GetFileNameForThisActionmPcRb, &$_Z24GetFileNameForThisActionmPcRb, &__Z24GetFileNameForThisActionmPcRb);
1194 $NSBundle = objc_getClass("NSBundle");
1196 _NSBundle$localizedStringForKey$value$table$ = MSHookMessage($NSBundle, @selector(localizedStringForKey:value:table:), &$NSBundle$localizedStringForKey$value$table$);
1197 _NSBundle$pathForResource$ofType$ = MSHookMessage($NSBundle, @selector(pathForResource:ofType:), &$NSBundle$pathForResource$ofType$);
1199 $UIImage = objc_getClass("UIImage");
1200 $UINavigationBar = objc_getClass("UINavigationBar");
1201 $UIToolbar = objc_getClass("UIToolbar");
1203 _UIImage$defaultDesktopImage = MSHookMessage(object_getClass($UIImage), @selector(defaultDesktopImage), &$UIImage$defaultDesktopImage);
1205 //WBRename("UINavigationBar", @selector(initWithCoder:", (IMP) &UINavigationBar$initWithCoder$);
1206 //WBRename("UINavigationBarBackground", @selector(initWithFrame:withBarStyle:withTintColor:", (IMP) &UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$);
1208 _UINavigationBar$setBarStyle$ = MSHookMessage($UINavigationBar, @selector(setBarStyle:), &$UINavigationBar$setBarStyle$);
1209 _UIToolbar$setBarStyle$ = MSHookMessage($UIToolbar, @selector(setBarStyle:), &$UIToolbar$setBarStyle$);
1211 _UISharedImageInitialize(false);
1213 Manager_ = [[NSFileManager defaultManager] retain];
1214 UIImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1215 PathImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1216 Strings_ = [[NSMutableDictionary alloc] initWithCapacity:0];
1217 Bundles_ = [[NSMutableDictionary alloc] initWithCapacity:2];
1218 Themed_ = [[NSMutableDictionary alloc] initWithCapacity:128];
1220 themes_ = [[NSMutableArray alloc] initWithCapacity:8];
1222 if (NSDictionary *settings = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"/User/Library/Preferences/com.saurik.WinterBoard.plist"]]) {
1223 [settings autorelease];
1225 if (NSNumber *debug = [settings objectForKey:@"Debug"])
1226 Debug_ = [debug boolValue];
1228 NSArray *themes = [settings objectForKey:@"Themes"];
1230 if (NSString *theme = [settings objectForKey:@"Theme"])
1231 themes = [NSArray arrayWithObject:[NSDictionary dictionaryWithObjectsAndKeys:
1233 [NSNumber numberWithBool:true], @"Active",
1236 for (NSDictionary *theme in themes) {
1237 NSNumber *active = [theme objectForKey:@"Active"];
1238 if (![active boolValue])
1241 NSString *name = [theme objectForKey:@"Name"];
1245 NSString *theme = nil;
1247 #define testForTheme(format...) \
1248 if (theme == nil) { \
1249 NSString *path = [NSString stringWithFormat:format]; \
1250 if ([Manager_ fileExistsAtPath:path]) { \
1251 [themes_ addObject:path]; \
1256 testForTheme(@"/Library/Themes/%@.theme", name)
1257 testForTheme(@"/Library/Themes/%@", name)
1258 testForTheme(@"%@/Library/SummerBoard/Themes/%@", NSHomeDirectory(), name)
1262 Info_ = [[NSMutableDictionary dictionaryWithCapacity:16] retain];
1264 for (NSString *theme in themes_)
1265 if (NSDictionary *info = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/Info.plist", theme]])
1266 for (NSString *key in [info allKeys])
1267 if ([Info_ objectForKey:key] == nil)
1268 [Info_ setObject:[info objectForKey:key] forKey:key];
1270 if ([identifier isEqualToString:@"com.apple.MobileSMS"]) {
1271 Class mSMSMessageTranscriptController = objc_getClass("mSMSMessageTranscriptController");
1272 _mSMSMessageTranscriptController$loadView = MSHookMessage(mSMSMessageTranscriptController, @selector(loadView), &$mSMSMessageTranscriptController$loadView);
1273 } else if ([identifier isEqualToString:@"com.apple.springboard"]) {
1274 CFNotificationCenterAddObserver(
1275 CFNotificationCenterGetDarwinNotifyCenter(),
1276 NULL, &ChangeWallpaper, (CFStringRef) @"com.saurik.winterboard.lockbackground", NULL, 0
1279 NSBundle *MediaPlayer = [NSBundle bundleWithPath:@"/System/Library/Frameworks/MediaPlayer.framework"];
1280 if (MediaPlayer != nil)
1283 $MPMoviePlayerController = objc_getClass("MPMoviePlayerController");
1284 $MPVideoView = objc_getClass("MPVideoView");
1285 $WebCoreFrameBridge = objc_getClass("WebCoreFrameBridge");
1287 $SBApplication = objc_getClass("SBApplication");
1288 $SBApplicationIcon = objc_getClass("SBApplicationIcon");
1289 $SBAwayView = objc_getClass("SBAwayView");
1290 $SBBookmarkIcon = objc_getClass("SBBookmarkIcon");
1291 $SBButtonBar = objc_getClass("SBButtonBar");
1292 $SBCalendarIconContentsView = objc_getClass("SBCalendarIconContentsView");
1293 $SBContentLayer = objc_getClass("SBContentLayer");
1294 $SBIconBadge = objc_getClass("SBIconBadge");
1295 $SBIconController = objc_getClass("SBIconController");
1296 $SBIconLabel = objc_getClass("SBIconLabel");
1297 $SBIconList = objc_getClass("SBIconList");
1298 $SBIconModel = objc_getClass("SBIconModel");
1299 $SBStatusBarContentsView = objc_getClass("SBStatusBarContentsView");
1300 $SBStatusBarController = objc_getClass("SBStatusBarController");
1301 $SBStatusBarOperatorNameView = objc_getClass("SBStatusBarOperatorNameView");
1302 $SBStatusBarTimeView = objc_getClass("SBStatusBarTimeView");
1303 $SBWidgetApplicationIcon = objc_getClass("SBWidgetApplicationIcon");
1305 WBRename(WebCoreFrameBridge, renderedSizeOfNode:constrainedToWidth:, renderedSizeOfNode$constrainedToWidth$);
1307 WBRename(SBApplication, pathForIcon, pathForIcon);
1308 WBRename(SBApplicationIcon, icon, icon);
1309 WBRename(SBBookmarkIcon, icon, icon);
1310 WBRename(SBButtonBar, didMoveToSuperview, didMoveToSuperview);
1311 WBRename(SBCalendarIconContentsView, drawRect:, drawRect$);
1312 WBRename(SBContentLayer, initWithSize:, initWithSize$);
1313 WBRename(SBIconBadge, initWithBadge:, initWithBadge$);
1314 WBRename(SBIconController, noteNumberOfIconListsChanged, noteNumberOfIconListsChanged);
1315 WBRename(SBWidgetApplicationIcon, icon, icon);
1317 WBRename(SBIconLabel, drawRect:, drawRect$);
1318 WBRename(SBIconLabel, initWithSize:label:, initWithSize$label$);
1319 WBRename(SBIconLabel, setInDock:, setInDock$);
1321 WBRename(SBIconList, setFrame:, setFrame$);
1323 WBRename(SBIconModel, cacheImageForIcon:, cacheImageForIcon$);
1324 WBRename(SBIconModel, getCachedImagedForIcon:, getCachedImagedForIcon$);
1326 WBRename(SBAwayView, updateDesktopImage:, updateDesktopImage$);
1327 WBRename(SBStatusBarContentsView, didMoveToSuperview, didMoveToSuperview);
1328 WBRename(SBStatusBarContentsView, initWithStatusBar:mode:, initWithStatusBar$mode$);
1329 WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:, setStatusBarMode$orientation$duration$fenceID$animation$);
1330 WBRename(SBStatusBarOperatorNameView, operatorNameStyle, operatorNameStyle);
1331 WBRename(SBStatusBarOperatorNameView, setOperatorName:fullSize:, setOperatorName$fullSize$);
1332 WBRename(SBStatusBarTimeView, drawRect:, drawRect$);
1334 English_ = [[NSDictionary alloc] initWithContentsOfFile:@"/System/Library/CoreServices/SpringBoard.app/English.lproj/LocalizedApplicationNames.strings"];
1335 if (English_ != nil)
1336 English_ = [English_ retain];
1338 Cache_ = [[NSMutableDictionary alloc] initWithCapacity:64];
1341 Wallpapers_ = [[NSArray arrayWithObjects:@"Wallpaper.mp4", @"Wallpaper.png", @"Wallpaper.jpg", @"Wallpaper.html", nil] retain];
1343 if ([Info_ objectForKey:@"UndockedIconLabels"] == nil)
1344 [Info_ setObject:[NSNumber numberWithBool:(
1345 $getTheme$(Wallpapers_) == nil ||
1346 [Info_ objectForKey:@"DockedIconLabelStyle"] != nil ||
1347 [Info_ objectForKey:@"UndockedIconLabelStyle"] != nil
1348 )] forKey:@"UndockedIconLabels"];
1351 NSLog(@"WB:Debug:Info = %@", [Info_ description]);