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/SBImageCache.h>
66 #import <SpringBoard/SBStatusBarContentsView.h>
67 #import <SpringBoard/SBStatusBarController.h>
68 #import <SpringBoard/SBStatusBarOperatorNameView.h>
69 #import <SpringBoard/SBStatusBarTimeView.h>
70 #import <SpringBoard/SBUIController.h>
71 #import <SpringBoard/SBWidgetApplicationIcon.h>
73 #import <MobileSMS/mSMSMessageTranscriptController.h>
75 #import <MediaPlayer/MPMoviePlayerController.h>
76 #import <MediaPlayer/MPVideoView.h>
77 #import <MediaPlayer/MPVideoView-PlaybackControl.h>
79 #import <CoreGraphics/CGGeometry.h>
81 extern "C" void __clear_cache (char *beg, char *end);
87 Class $MPMoviePlayerController;
89 Class $WebCoreFrameBridge;
94 Class $UINavigationBar;
98 Class $SBApplicationIcon;
100 Class $SBBookmarkIcon;
102 Class $SBCalendarIconContentsView;
103 Class $SBContentLayer;
105 Class $SBIconController;
109 //Class $SBImageCache;
110 Class $SBStatusBarContentsView;
111 Class $SBStatusBarController;
112 Class $SBStatusBarOperatorNameView;
113 Class $SBStatusBarTimeView;
114 Class $SBWidgetApplicationIcon;
116 @interface NSDictionary (WinterBoard)
117 - (UIColor *) colorForKey:(NSString *)key;
118 - (BOOL) boolForKey:(NSString *)key;
121 @implementation NSDictionary (WinterBoard)
123 - (UIColor *) colorForKey:(NSString *)key {
124 NSString *value = [self objectForKey:key];
131 - (BOOL) boolForKey:(NSString *)key {
132 if (NSString *value = [self objectForKey:key])
133 return [value boolValue];
140 bool Engineer_ = false;
142 static UIImage *(*_UIApplicationImageWithName)(NSString *name);
143 static UIImage *(*_UIImageAtPath)(NSString *name, NSBundle *path);
144 static CGImageRef (*_UIImageRefAtPath)(NSString *name, bool cache, UIImageOrientation *orientation);
145 static UIImage *(*_UIImageWithNameInDomain)(NSString *name, NSString *domain);
146 static NSBundle *(*_UIKitBundle)();
147 static void (*_UISharedImageInitialize)(bool);
148 static int (*_UISharedImageNameGetIdentifier)(NSString *);
149 static UIImage *(*_UISharedImageWithIdentifier)(int);
151 static NSMutableDictionary *UIImages_;
152 static NSMutableDictionary *PathImages_;
153 static NSMutableDictionary *Cache_;
154 static NSMutableDictionary *Strings_;
155 static NSMutableDictionary *Themed_;
156 static NSMutableDictionary *Bundles_;
158 static NSFileManager *Manager_;
159 static NSDictionary *English_;
160 static NSMutableDictionary *Info_;
161 static NSMutableArray *themes_;
163 static NSString *$getTheme$(NSArray *files, bool parent = false) {
165 if (NSString *path = [Themed_ objectForKey:files])
166 return reinterpret_cast<id>(path) == [NSNull null] ? nil : path;
169 NSLog(@"WB:Debug: %@", [files description]);
173 for (NSString *theme in themes_)
174 for (NSString *file in files) {
175 path = [NSString stringWithFormat:@"%@/%@", theme, file];
176 if ([Manager_ fileExistsAtPath:path]) {
177 path = parent ? theme : path;
185 [Themed_ setObject:(path == nil ? [NSNull null] : reinterpret_cast<id>(path)) forKey:files];
189 static NSString *$pathForFile$inBundle$(NSString *file, NSBundle *bundle, bool ui) {
190 NSString *identifier = [bundle bundleIdentifier];
191 NSMutableArray *names = [NSMutableArray arrayWithCapacity:8];
193 if (identifier != nil)
194 [names addObject:[NSString stringWithFormat:@"Bundles/%@/%@", identifier, file]];
195 if (NSString *folder = [[bundle bundlePath] lastPathComponent])
196 [names addObject:[NSString stringWithFormat:@"Folders/%@/%@", folder, file]];
198 [names addObject:[NSString stringWithFormat:@"UIImages/%@", file]];
200 #define remapResourceName(oldname, newname) \
201 else if ([file isEqualToString:oldname]) \
202 [names addObject:[NSString stringWithFormat:@"%@.png", newname]]; \
204 if (identifier == nil);
205 else if ([identifier isEqualToString:@"com.apple.calculator"])
206 [names addObject:[NSString stringWithFormat:@"Files/Applications/Calculator.app/%@", file]];
207 else if (![identifier isEqualToString:@"com.apple.springboard"]);
208 remapResourceName(@"FSO_BG.png", @"StatusBar")
209 remapResourceName(@"SBDockBG.png", @"Dock")
210 remapResourceName(@"SBWeatherCelsius.png", @"Icons/Weather")
212 if (NSString *path = $getTheme$(names))
217 static NSString *$pathForIcon$(SBApplication *self) {
218 NSString *identifier = [self bundleIdentifier];
219 NSString *path = [self path];
220 NSString *folder = [path lastPathComponent];
221 NSString *dname = [self displayName];
222 NSString *didentifier = [self displayIdentifier];
225 NSLog(@"WB:Debug: [SBApplication(%@:%@:%@:%@) pathForIcon]", identifier, folder, dname, didentifier);
227 NSMutableArray *names = [NSMutableArray arrayWithCapacity:8];
229 if (identifier != nil)
230 [names addObject:[NSString stringWithFormat:@"Bundles/%@/icon.png", identifier]];
232 [names addObject:[NSString stringWithFormat:@"Folders/%@/icon.png", folder]];
234 #define testForIcon(Name) \
235 if (NSString *name = Name) \
236 [names addObject:[NSString stringWithFormat:@"Icons/%@.png", name]];
238 testForIcon(identifier);
241 if (didentifier != nil) {
242 testForIcon([English_ objectForKey:didentifier]);
244 NSArray *parts = [didentifier componentsSeparatedByString:@"-"];
245 if ([parts count] != 1)
246 if (NSDictionary *english = [[[NSDictionary alloc] initWithContentsOfFile:[path stringByAppendingString:@"/English.lproj/UIRoleDisplayNames.strings"]] autorelease])
247 testForIcon([english objectForKey:[parts lastObject]]);
250 if (NSString *path = $getTheme$(names))
255 @interface NSBundle (WinterBoard)
256 + (NSBundle *) wb$bundleWithFile:(NSString *)path;
259 @implementation NSBundle (WinterBoard)
261 + (NSBundle *) wb$bundleWithFile:(NSString *)path {
262 path = [path stringByDeletingLastPathComponent];
263 if (path == nil || [path length] == 0 || [path isEqualToString:@"/"])
266 NSBundle *bundle([Bundles_ objectForKey:path]);
267 if (reinterpret_cast<id>(bundle) == [NSNull null])
269 else if (bundle == nil) {
270 if ([Manager_ fileExistsAtPath:[path stringByAppendingPathComponent:@"Info.plist"]])
271 bundle = [NSBundle bundleWithPath:path];
273 bundle = [NSBundle wb$bundleWithFile:path];
275 NSLog(@"WB:Debug:PathBundle(%@, %@)", path, bundle);
276 [Bundles_ setObject:(bundle == nil ? [NSNull null] : reinterpret_cast<id>(bundle)) forKey:path];
284 @interface NSString (WinterBoard)
285 - (NSString *) wb$themedPath;
288 @implementation NSString (WinterBoard)
290 - (NSString *) wb$themedPath {
292 NSLog(@"WB:Debug:Bypass(\"%@\")", self);
294 if (NSBundle *bundle = [NSBundle wb$bundleWithFile:self]) {
295 NSString *file([self stringByResolvingSymlinksInPath]);
296 NSString *prefix([[bundle bundlePath] stringByResolvingSymlinksInPath]);
297 if ([file hasPrefix:prefix]) {
298 NSUInteger length([prefix length]);
299 if (length != [file length])
300 if (NSString *path = $pathForFile$inBundle$([file substringFromIndex:(length + 1)], bundle, false))
310 UIImage *$cacheForImage$(UIImage *image) {
311 CGColorSpaceRef space(CGColorSpaceCreateDeviceRGB());
312 CGRect rect = {CGPointMake(1, 1), [image size]};
313 CGSize size = {rect.size.width + 2, rect.size.height + 2};
315 CGContextRef context(CGBitmapContextCreate(NULL, size.width, size.height, 8, 4 * size.width, space, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst));
316 CGColorSpaceRelease(space);
318 CGContextDrawImage(context, rect, [image CGImage]);
319 CGImageRef ref(CGBitmapContextCreateImage(context));
320 CGContextRelease(context);
322 UIImage *cache([UIImage imageWithCGImage:ref]);
328 /*MSHook(id, SBImageCache$initWithName$forImageWidth$imageHeight$initialCapacity$, SBImageCache *self, SEL sel, NSString *name, unsigned width, unsigned height, unsigned capacity) {
329 //if ([name isEqualToString:@"icons"]) return nil;
330 return _SBImageCache$initWithName$forImageWidth$imageHeight$initialCapacity$(self, sel, name, width, height, capacity);
333 MSHook(void, SBIconModel$cacheImageForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
334 NSString *key([icon displayIdentifier]);
336 if (UIImage *image = [icon icon]) {
337 CGSize size = [image size];
338 if (size.width > 59 || size.height > 60) {
339 UIImage *cache($cacheForImage$(image));
340 [Cache_ setObject:cache forKey:key];
345 _SBIconModel$cacheImageForIcon$(self, sel, icon);
348 MSHook(UIImage *, SBIconModel$getCachedImagedForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
349 NSString *key([icon displayIdentifier]);
350 if (UIImage *image = [Cache_ objectForKey:key])
353 return _SBIconModel$getCachedImagedForIcon$(self, sel, icon);
356 MSHook(UIImage *, SBApplicationIcon$icon, SBApplicationIcon *self, SEL sel) {
357 if (![Info_ boolForKey:@"ComposeStoreIcons"])
358 if (NSString *path = $pathForIcon$([self application]))
359 return [UIImage imageWithContentsOfFile:path];
360 return _SBApplicationIcon$icon(self, sel);
363 MSHook(UIImage *, SBWidgetApplicationIcon$icon, SBWidgetApplicationIcon *self, SEL sel) {
365 NSLog(@"WB:Debug:Widget(%@:%@)", [self displayIdentifier], [self displayName]);
366 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]]))
367 return [UIImage imageWithContentsOfFile:path];
368 return _SBWidgetApplicationIcon$icon(self, sel);
371 MSHook(UIImage *, SBBookmarkIcon$icon, SBBookmarkIcon *self, SEL sel) {
373 NSLog(@"WB:Debug:Bookmark(%@:%@)", [self displayIdentifier], [self displayName]);
374 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]]))
375 return [UIImage imageWithContentsOfFile:path];
376 return _SBBookmarkIcon$icon(self, sel);
379 MSHook(NSString *, SBApplication$pathForIcon, SBApplication *self, SEL sel) {
380 if (NSString *path = $pathForIcon$(self))
382 return _SBApplication$pathForIcon(self, sel);
385 static UIImage *CachedImageAtPath(NSString *path) {
386 path = [path stringByResolvingSymlinksInPath];
387 UIImage *image = [PathImages_ objectForKey:path];
389 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
390 image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
392 image = [image autorelease];
393 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:path];
397 MSHook(CGImageRef, _UIImageRefAtPath, NSString *name, bool cache, UIImageOrientation *orientation) {
399 NSLog(@"WB:Debug: _UIImageRefAtPath(\"%@\", %s)", name, cache ? "true" : "false");
400 return __UIImageRefAtPath([name wb$themedPath], cache, orientation);
403 /*MSHook(UIImage *, _UIImageAtPath, NSString *name, NSBundle *bundle) {
405 return __UIImageAtPath(name, nil);
407 NSString *key = [NSString stringWithFormat:@"B:%@/%@", [bundle bundleIdentifier], name];
408 UIImage *image = [PathImages_ objectForKey:key];
410 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
412 NSLog(@"WB:Debug: _UIImageAtPath(\"%@\", %@)", name, bundle);
413 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
414 image = CachedImageAtPath(path);
416 image = __UIImageAtPath(name, bundle);
417 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
422 MSHook(UIImage *, _UIApplicationImageWithName, NSString *name) {
423 NSBundle *bundle = [NSBundle mainBundle];
425 NSLog(@"WB:Debug: _UIApplicationImageWithName(\"%@\", %@)", name, bundle);
426 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
427 return CachedImageAtPath(path);
428 return __UIApplicationImageWithName(name);
431 #define WBDelegate(delegate) \
432 - (NSMethodSignature*) methodSignatureForSelector:(SEL)sel { \
434 NSLog(@"WB:MS:%s:(%s)", class_getName([self class]), sel_getName(sel)); \
435 if (NSMethodSignature *sig = [delegate methodSignatureForSelector:sel]) \
437 NSLog(@"WB:Error: [%s methodSignatureForSelector:(%s)]", class_getName([self class]), sel_getName(sel)); \
441 - (void) forwardInvocation:(NSInvocation*)inv { \
442 SEL sel = [inv selector]; \
443 if ([delegate respondsToSelector:sel]) \
444 [inv invokeWithTarget:delegate]; \
446 NSLog(@"WB:Error: [%s forwardInvocation:(%s)]", class_getName([self class]), sel_getName(sel)); \
449 MSHook(NSString *, NSBundle$pathForResource$ofType$, NSBundle *self, SEL sel, NSString *resource, NSString *type) {
450 NSString *file = type == nil ? resource : [NSString stringWithFormat:@"%@.%@", resource, type];
452 NSLog(@"WB:Debug: [NSBundle(%@) pathForResource:\"%@\"]", [self bundleIdentifier], file);
453 if (NSString *path = $pathForFile$inBundle$(file, self, false))
455 return _NSBundle$pathForResource$ofType$(self, sel, resource, type);
458 void $setBarStyle$_(NSString *name, int &style) {
460 NSLog(@"WB:Debug:%@Style:%d", name, style);
461 NSNumber *number = nil;
463 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style-%d", name, style]];
465 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style", name]];
467 style = [number intValue];
469 NSLog(@"WB:Debug:%@Style=%d", name, style);
473 MSHook(void, SBCalendarIconContentsView$drawRect$, SBCalendarIconContentsView *self, SEL sel, CGRect rect) {
474 NSBundle *bundle([NSBundle mainBundle]);
476 CFLocaleRef locale(CFLocaleCopyCurrent());
477 CFDateFormatterRef formatter(CFDateFormatterCreate(NULL, locale, kCFDateFormatterNoStyle, kCFDateFormatterNoStyle));
480 CFDateRef now(CFDateCreate(NULL, CFAbsoluteTimeGetCurrent()));
482 CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NUMBER_FORMAT" value:@"" table:@"SpringBoard"]);
483 CFStringRef date(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
484 CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NAME_FORMAT" value:@"" table:@"SpringBoard"]);
485 CFStringRef day(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
489 CFRelease(formatter);
491 NSString *datestyle(@""
492 "font-family: Helvetica; "
493 "font-weight: bold; "
499 NSString *daystyle(@""
500 "font-family: Helvetica; "
501 "font-weight: bold; "
504 "text-shadow: rgba(0, 0, 0, 0.2) -1px -1px 2px; "
507 if (NSString *style = [Info_ objectForKey:@"CalendarIconDateStyle"])
508 datestyle = [datestyle stringByAppendingString:style];
509 if (NSString *style = [Info_ objectForKey:@"CalendarIconDayStyle"])
510 daystyle = [daystyle stringByAppendingString:style];
512 float width([self bounds].size.width);
514 CGSize datesize = [(NSString *)date sizeWithStyle:datestyle forWidth:(width + leeway)];
515 CGSize daysize = [(NSString *)day sizeWithStyle:daystyle forWidth:(width + leeway)];
517 [(NSString *)date drawAtPoint:CGPointMake(
518 (width + 1 - datesize.width) / 2, (71 - datesize.height) / 2
519 ) withStyle:datestyle];
521 [(NSString *)day drawAtPoint:CGPointMake(
522 (width + 1 - daysize.width) / 2, (16 - daysize.height) / 2
523 ) withStyle:daystyle];
529 /*static id UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$(UINavigationBarBackground<WinterBoard> *self, SEL sel, CGRect frame, int style, UIColor *tint) {
532 if (NSNumber *number = [Info_ objectForKey:@"NavigationBarStyle"])
533 style = [number intValue];
535 if (UIColor *color = [Info_ colorForKey:@"NavigationBarTint"])
538 return [self wb$initWithFrame:frame withBarStyle:style withTintColor:tint];
541 /*static id UINavigationBar$initWithCoder$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame, NSCoder *coder) {
542 self = [self wb$initWithCoder:coder];
545 UINavigationBar$setBarStyle$_(self);
549 static id UINavigationBar$initWithFrame$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame) {
550 self = [self wb$initWithFrame:frame];
553 UINavigationBar$setBarStyle$_(self);
557 MSHook(void, UIToolbar$setBarStyle$, UIToolbar *self, SEL sel, int style) {
558 $setBarStyle$_(@"Toolbar", style);
559 return _UIToolbar$setBarStyle$(self, sel, style);
562 MSHook(void, UINavigationBar$setBarStyle$, UINavigationBar *self, SEL sel, int style) {
563 $setBarStyle$_(@"NavigationBar", style);
564 return _UINavigationBar$setBarStyle$(self, sel, style);
567 MSHook(void, SBButtonBar$didMoveToSuperview, UIView *self, SEL sel) {
568 [[self superview] setBackgroundColor:[UIColor clearColor]];
569 _SBButtonBar$didMoveToSuperview(self, sel);
572 MSHook(void, SBStatusBarContentsView$didMoveToSuperview, UIView *self, SEL sel) {
573 [[self superview] setBackgroundColor:[UIColor clearColor]];
574 _SBStatusBarContentsView$didMoveToSuperview(self, sel);
577 MSHook(UIImage *, UIImage$defaultDesktopImage, UIImage *self, SEL sel) {
579 NSLog(@"WB:Debug:DefaultDesktopImage");
580 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"LockBackground.png", @"LockBackground.jpg", nil]))
581 return [UIImage imageWithContentsOfFile:path];
582 return _UIImage$defaultDesktopImage(self, sel);
585 static NSArray *Wallpapers_;
586 static NSString *WallpaperFile_;
587 static UIImageView *WallpaperImage_;
588 static UIWebDocumentView *WallpaperPage_;
589 static NSURL *WallpaperURL_;
591 #define _release(object) \
592 do if (object != nil) { \
597 MSHook(id, SBContentLayer$initWithSize$, SBContentLayer *self, SEL sel, CGSize size) {
598 self = _SBContentLayer$initWithSize$(self, sel, size);
602 _release(WallpaperFile_);
603 _release(WallpaperImage_);
604 _release(WallpaperPage_);
605 _release(WallpaperURL_);
607 if (NSString *theme = $getTheme$(Wallpapers_, true)) {
608 NSString *mp4 = [theme stringByAppendingPathComponent:@"Wallpaper.mp4"];
609 if ([Manager_ fileExistsAtPath:mp4]) {
613 static AVController *controller_(nil);
614 if (controller_ == nil) {
615 AVQueue *queue([AVQueue avQueue]);
616 controller_ = [[AVController avControllerWithQueue:queue error:&error] retain];
619 AVQueue *queue([controller_ queue]);
621 UIView *video([[[UIView alloc] initWithFrame:[self bounds]] autorelease]);
622 [controller_ setLayer:[video _layer]];
624 AVItem *item([[[AVItem alloc] initWithPath:mp4 error:&error] autorelease]);
625 [queue appendItem:item error:&error];
627 [controller_ play:&error];
628 #elif UseMPMoviePlayerController
629 NSURL *url([NSURL fileURLWithPath:mp4]);
630 MPMoviePlayerController *controller = [[MPMoviePlayerController alloc] initWithContentURL:url];
631 controller.movieControlMode = MPMovieControlModeHidden;
634 MPVideoView *video = [[[$MPVideoView alloc] initWithFrame:[self bounds]] autorelease];
635 [video setMovieWithPath:mp4];
636 [video setRepeatMode:1];
637 [video setRepeatGap:-1];
638 [video playFromBeginning];;
641 [self addSubview:video];
644 NSString *png = [theme stringByAppendingPathComponent:@"Wallpaper.png"];
645 NSString *jpg = [theme stringByAppendingPathComponent:@"Wallpaper.jpg"];
648 if ([Manager_ fileExistsAtPath:png])
650 else if ([Manager_ fileExistsAtPath:jpg])
656 image = [[UIImage alloc] initWithContentsOfFile:path];
658 image = [image autorelease];
662 WallpaperFile_ = [path retain];
663 WallpaperImage_ = [[UIImageView alloc] initWithImage:image];
664 [self addSubview:WallpaperImage_];
667 NSString *html = [theme stringByAppendingPathComponent:@"Wallpaper.html"];
668 if ([Manager_ fileExistsAtPath:html]) {
669 CGRect bounds = [self bounds];
671 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
672 [view setAutoresizes:true];
674 WallpaperPage_ = [view retain];
675 WallpaperURL_ = [[NSURL fileURLWithPath:html] retain];
677 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
679 [[view webView] setDrawsBackground:false];
680 [view setBackgroundColor:[UIColor clearColor]];
682 [self addSubview:view];
686 for (size_t i(0), e([themes_ count]); i != e; ++i) {
687 NSString *theme = [themes_ objectAtIndex:(e - i - 1)];
688 NSString *html = [theme stringByAppendingPathComponent:@"Widget.html"];
689 if ([Manager_ fileExistsAtPath:html]) {
690 CGRect bounds = [self bounds];
692 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
693 [view setAutoresizes:true];
695 NSURL *url = [NSURL fileURLWithPath:html];
696 [view loadRequest:[NSURLRequest requestWithURL:url]];
698 [[view webView] setDrawsBackground:false];
699 [view setBackgroundColor:[UIColor clearColor]];
701 [self addSubview:view];
708 MSHook(void, SBAwayView$updateDesktopImage$, SBAwayView *self, SEL sel, UIImage *image) {
709 NSString *path = $getTheme$([NSArray arrayWithObject:@"LockBackground.html"]);
710 UIView *&_backgroundView(MSHookIvar<UIView *>(self, "_backgroundView"));
712 if (path != nil && _backgroundView != nil)
715 _SBAwayView$updateDesktopImage$(self, sel, image);
718 CGRect bounds = [self bounds];
720 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
721 [view setAutoresizes:true];
723 if (WallpaperPage_ != nil)
724 [WallpaperPage_ release];
725 WallpaperPage_ = [view retain];
727 if (WallpaperURL_ != nil)
728 [WallpaperURL_ release];
729 WallpaperURL_ = [[NSURL fileURLWithPath:path] retain];
731 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
733 [[view webView] setDrawsBackground:false];
734 [view setBackgroundColor:[UIColor clearColor]];
736 [self insertSubview:view aboveSubview:_backgroundView];
740 /*extern "C" CGColorRef CGGStateGetSystemColor(void *);
741 extern "C" CGColorRef CGGStateGetFillColor(void *);
742 extern "C" CGColorRef CGGStateGetStrokeColor(void *);
743 extern "C" NSString *UIStyleStringFromColor(CGColorRef);*/
745 /* WBTimeLabel {{{ */
746 @interface WBTimeLabel : NSProxy {
748 _transient SBStatusBarTimeView *view_;
751 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view;
755 @implementation WBTimeLabel
762 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view {
763 time_ = [time retain];
770 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
771 if (NSString *custom = [Info_ objectForKey:@"TimeStyle"]) {
772 BOOL &_mode(MSHookIvar<BOOL>(view_, "_mode"));;
774 [time_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
775 "font-family: Helvetica; "
776 "font-weight: bold; "
779 "%@", _mode ? @"white" : @"black", custom]];
784 return [time_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
789 /* WBBadgeLabel {{{ */
790 @interface WBBadgeLabel : NSProxy {
794 - (id) initWithBadge:(NSString *)badge;
798 @implementation WBBadgeLabel
805 - (id) initWithBadge:(NSString *)badge {
806 badge_ = [badge retain];
812 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
813 if (NSString *custom = [Info_ objectForKey:@"BadgeStyle"]) {
814 [badge_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
815 "font-family: Helvetica; "
816 "font-weight: bold; "
824 return [badge_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
830 MSHook(id, SBIconBadge$initWithBadge$, SBIconBadge *self, SEL sel, NSString *badge) {
831 if ((self = _SBIconBadge$initWithBadge$(self, sel, badge)) != nil) {
832 id &_badge(MSHookIvar<id>(self, "_badge"));
834 if (id label = [[WBBadgeLabel alloc] initWithBadge:[_badge autorelease]])
839 MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, float duration, int id, int animation) {
841 NSLog(@"WB:Debug:setStatusBarMode:%d", mode);
842 if (mode < 100) // 104:hidden 105:glowing
843 if (NSNumber *number = [Info_ objectForKey:@"StatusBarMode"])
844 mode = [number intValue];
845 return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$(self, sel, mode, orientation, duration, id, animation);
848 MSHook(id, SBStatusBarContentsView$initWithStatusBar$mode$, SBStatusBarContentsView *self, SEL sel, id bar, int mode) {
849 if (NSNumber *number = [Info_ objectForKey:@"StatusBarContentsMode"])
850 mode = [number intValue];
851 return _SBStatusBarContentsView$initWithStatusBar$mode$(self, sel, bar, mode);
854 MSHook(NSString *, SBStatusBarOperatorNameView$operatorNameStyle, SBStatusBarOperatorNameView *self, SEL sel) {
855 NSString *style(_SBStatusBarOperatorNameView$operatorNameStyle(self, sel));
857 NSLog(@"operatorNameStyle= %@", style);
858 if (NSString *custom = [Info_ objectForKey:@"OperatorNameStyle"])
859 style = [NSString stringWithFormat:@"%@; %@", style, custom];
863 MSHook(void, SBStatusBarOperatorNameView$setOperatorName$fullSize$, SBStatusBarOperatorNameView *self, SEL sel, NSString *name, BOOL full) {
865 NSLog(@"setOperatorName:\"%@\" fullSize:%u", name, full);
866 return _SBStatusBarOperatorNameView$setOperatorName$fullSize$(self, sel, name, NO);
869 // XXX: replace this with [SBStatusBarTimeView tile]
870 MSHook(void, SBStatusBarTimeView$drawRect$, SBStatusBarTimeView *self, SEL sel, CGRect rect) {
871 id &_time(MSHookIvar<id>(self, "_time"));
872 if (_time != nil && [_time class] != [WBTimeLabel class])
873 object_setInstanceVariable(self, "_time", reinterpret_cast<void *>([[WBTimeLabel alloc] initWithTime:[_time autorelease] view:self]));
874 return _SBStatusBarTimeView$drawRect$(self, sel, rect);
877 @interface UIView (WinterBoard)
878 - (bool) wb$isWBImageView;
881 @implementation UIView (WinterBoard)
883 - (bool) wb$isWBImageView {
889 @interface WBImageView : UIImageView {
892 - (bool) wb$isWBImageView;
893 - (void) wb$updateFrame;
896 @implementation WBImageView
898 - (bool) wb$isWBImageView {
902 - (void) wb$updateFrame {
903 CGRect frame([self frame]);
906 for (UIView *view(self); ; ) {
907 view = [view superview];
910 frame.origin.y -= [view frame].origin.y;
913 [self setFrame:frame];
918 MSHook(void, SBIconList$setFrame$, SBIconList *self, SEL sel, CGRect frame) {
919 NSArray *subviews([self subviews]);
920 WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
921 if (view != nil && [view wb$isWBImageView])
922 [view wb$updateFrame];
923 _SBIconList$setFrame$(self, sel, frame);
926 MSHook(void, SBIconController$noteNumberOfIconListsChanged, SBIconController *self, SEL sel) {
927 SBIconModel *&_iconModel(MSHookIvar<SBIconModel *>(self, "_iconModel"));
928 NSArray *lists([_iconModel iconLists]);
930 for (unsigned i(0), e([lists count]); i != e; ++i)
931 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Page%u.png", i]])) {
932 SBIconList *list([lists objectAtIndex:i]);
933 NSArray *subviews([list subviews]);
935 WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
936 if (view == nil || ![view wb$isWBImageView]) {
937 view = [[[WBImageView alloc] init] autorelease];
938 [list insertSubview:view atIndex:0];
941 UIImage *image([UIImage imageWithContentsOfFile:path]);
942 [view setImage:image];
943 [view wb$updateFrame];
946 return _SBIconController$noteNumberOfIconListsChanged(self, sel);
949 MSHook(id, SBIconLabel$initWithSize$label$, SBIconLabel *self, SEL sel, CGSize size, NSString *label) {
950 self = _SBIconLabel$initWithSize$label$(self, sel, size, label);
952 [self setClipsToBounds:NO];
956 MSHook(void, SBIconLabel$setInDock$, SBIconLabel *self, SEL sel, BOOL docked) {
957 id &_label(MSHookIvar<id>(self, "_label"));
958 if (![Info_ boolForKey:@"UndockedIconLabels"])
960 if (_label != nil && [_label respondsToSelector:@selector(setInDock:)])
961 [_label setInDock:docked];
962 return _SBIconLabel$setInDock$(self, sel, docked);
965 MSHook(NSString *, NSBundle$localizedStringForKey$value$table$, NSBundle *self, SEL sel, NSString *key, NSString *value, NSString *table) {
966 NSString *identifier = [self bundleIdentifier];
967 NSLocale *locale = [NSLocale currentLocale];
968 NSString *language = [locale objectForKey:NSLocaleLanguageCode];
970 NSLog(@"WB:Debug:[NSBundle(%@) localizedStringForKey:\"%@\" value:\"%@\" table:\"%@\"] (%@)", identifier, key, value, table, language);
971 NSString *file = table == nil ? @"Localizable" : table;
972 NSString *name = [NSString stringWithFormat:@"%@:%@", identifier, file];
973 NSDictionary *strings;
974 if ((strings = [Strings_ objectForKey:name]) != nil) {
975 if (static_cast<id>(strings) != [NSNull null]) strings:
976 if (NSString *value = [strings objectForKey:key])
978 } else if (NSString *path = $pathForFile$inBundle$([NSString stringWithFormat:@"%@.lproj/%@.strings",
981 if ((strings = [[NSDictionary alloc] initWithContentsOfFile:path]) != nil) {
982 [Strings_ setObject:[strings autorelease] forKey:name];
986 [Strings_ setObject:[NSNull null] forKey:name];
987 return _NSBundle$localizedStringForKey$value$table$(self, sel, key, value, table);
990 @class WebCoreFrameBridge;
991 MSHook(CGSize, WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$, WebCoreFrameBridge *self, SEL sel, id node, float width) {
994 void **core(reinterpret_cast<void **>([node _node]));
995 if (core == NULL || core[6] == NULL)
997 return _WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$(self, sel, node, width);
1000 MSHook(void, SBIconLabel$drawRect$, SBIconLabel *self, SEL sel, CGRect rect) {
1001 CGRect bounds = [self bounds];
1003 static Ivar drawMoreLegibly = object_getInstanceVariable(self, "_drawMoreLegibly", NULL);
1006 Ivar ivar = object_getInstanceVariable(self, "_inDock", reinterpret_cast<void **>(&docked));
1007 docked = (docked & (ivar_getOffset(ivar) == ivar_getOffset(drawMoreLegibly) ? 0x2 : 0x1)) != 0;
1009 NSString *label(MSHookIvar<NSString *>(self, "_label"));
1011 NSString *style = [NSString stringWithFormat:@""
1012 "font-family: Helvetica; "
1013 "font-weight: bold; "
1016 "", docked ? @"white" : @"#b3b3b3"];
1019 style = [style stringByAppendingString:@"text-shadow: rgba(0, 0, 0, 0.5) 0px -1px 0px; "];
1021 bool ellipsis(false);
1022 float max = 75, width;
1024 width = [(ellipsis ? [label stringByAppendingString:@"..."] : label) sizeWithStyle:style forWidth:320].width;
1027 size_t length([label length]);
1028 float spacing((width - max) / (length - 1));
1030 if (spacing > 1.25) {
1032 label = [label substringToIndex:(length - 1)];
1036 style = [style stringByAppendingString:[NSString stringWithFormat:@"letter-spacing: -%f; ", spacing]];
1040 label = [label stringByAppendingString:@"..."];
1042 if (NSString *custom = [Info_ objectForKey:(docked ? @"DockedIconLabelStyle" : @"UndockedIconLabelStyle")])
1043 style = [style stringByAppendingString:custom];
1045 CGSize size = [label sizeWithStyle:style forWidth:bounds.size.width];
1046 [label drawAtPoint:CGPointMake((bounds.size.width - size.width) / 2, 0) withStyle:style];
1049 MSHook(void, mSMSMessageTranscriptController$loadView, mSMSMessageTranscriptController *self, SEL sel) {
1050 _mSMSMessageTranscriptController$loadView(self, sel);
1052 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"SMSBackground.png", @"SMSBackground.jpg", nil]))
1053 if (UIImage *image = [[UIImage alloc] initWithContentsOfFile:path]) {
1054 [image autorelease];
1055 UIView *&_transcriptLayer(MSHookIvar<UIView *>(self, "_transcriptLayer"));
1056 UIView *parent([_transcriptLayer superview]);
1057 UIImageView *background([[[UIImageView alloc] initWithImage:image] autorelease]);
1058 [parent insertSubview:background belowSubview:_transcriptLayer];
1059 [_transcriptLayer setBackgroundColor:[UIColor clearColor]];
1063 MSHook(UIImage *, _UIImageWithName, NSString *name) {
1064 int id(_UISharedImageNameGetIdentifier(name));
1066 NSLog(@"WB:Debug: _UIImageWithName(\"%@\", %d)", name, id);
1069 return _UIImageAtPath(name, _UIKitBundle());
1071 NSNumber *key([NSNumber numberWithInt:id]);
1072 UIImage *image = [UIImages_ objectForKey:key];
1074 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
1075 if (NSString *path = $pathForFile$inBundle$(name, _UIKitBundle(), true)) {
1076 image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
1078 [image autorelease];
1081 image = _UISharedImageWithIdentifier(id);
1082 [UIImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
1087 MSHook(UIImage *, _UIImageWithNameInDomain, NSString *name, NSString *domain) {
1088 NSString *key = [NSString stringWithFormat:@"D:%zu%@%@", [domain length], domain, name];
1089 UIImage *image = [PathImages_ objectForKey:key];
1091 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
1093 NSLog(@"WB:Debug: UIImageWithNameInDomain(\"%@\", \"%@\")", name, domain);
1094 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Domains/%@/%@", domain, name]])) {
1095 image = [[UIImage alloc] initWithContentsOfFile:path];
1097 [image autorelease];
1100 image = __UIImageWithNameInDomain(name, domain);
1101 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
1105 MSHook(GSFontRef, GSFontCreateWithName, const char *name, GSFontSymbolicTraits traits, float size) {
1106 if (NSString *font = [Info_ objectForKey:[NSString stringWithFormat:@"FontName-%s", name]])
1107 name = [font UTF8String];
1108 return _GSFontCreateWithName(name, traits, size);
1111 #define AudioToolbox "/System/Library/Frameworks/AudioToolbox.framework/AudioToolbox"
1112 #define UIKit "/System/Library/Frameworks/UIKit.framework/UIKit"
1114 bool (*_Z24GetFileNameForThisActionmPcRb)(unsigned long a0, char *a1, bool &a2);
1116 MSHook(bool, _Z24GetFileNameForThisActionmPcRb, unsigned long a0, char *a1, bool &a2) {
1117 bool value = __Z24GetFileNameForThisActionmPcRb(a0, a1, a2);
1119 NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %s, %u) = %u", a0, value ? a1 : NULL, a2, value);
1122 NSString *path = [NSString stringWithUTF8String:a1];
1123 if ([path hasPrefix:@"/System/Library/Audio/UISounds/"]) {
1124 NSString *file = [path substringFromIndex:31];
1125 for (NSString *theme in themes_) {
1126 NSString *path([NSString stringWithFormat:@"%@/UISounds/%@", theme, file]);
1127 if ([Manager_ fileExistsAtPath:path]) {
1128 strcpy(a1, [path UTF8String]);
1137 static void ChangeWallpaper(
1138 CFNotificationCenterRef center,
1142 CFDictionaryRef info
1145 NSLog(@"WB:Debug:ChangeWallpaper!");
1148 if (WallpaperFile_ != nil) {
1149 image = [[UIImage alloc] initWithContentsOfFile:WallpaperFile_];
1151 image = [image autorelease];
1154 if (WallpaperImage_ != nil)
1155 [WallpaperImage_ setImage:image];
1156 if (WallpaperPage_ != nil)
1157 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
1161 #define WBRename(name, sel, imp) \
1162 _ ## name ## $ ## imp = MSHookMessage($ ## name, @selector(sel), &$ ## name ## $ ## imp)
1164 extern "C" void WBInitialize() {
1165 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
1167 NSString *identifier([[NSBundle mainBundle] bundleIdentifier]);
1169 NSLog(@"WB:Notice: WinterBoard");
1172 memset(nl, 0, sizeof(nl));
1174 nl[0].n_un.n_name = (char *) "__UIApplicationImageWithName";
1175 nl[1].n_un.n_name = (char *) "__UIImageAtPath";
1176 nl[2].n_un.n_name = (char *) "__UIImageRefAtPath";
1177 nl[3].n_un.n_name = (char *) "__UIImageWithNameInDomain";
1178 nl[4].n_un.n_name = (char *) "__UIKitBundle";
1179 nl[5].n_un.n_name = (char *) "__UISharedImageInitialize";
1180 nl[6].n_un.n_name = (char *) "__UISharedImageNameGetIdentifier";
1181 nl[7].n_un.n_name = (char *) "__UISharedImageWithIdentifier";
1185 _UIApplicationImageWithName = (UIImage *(*)(NSString *)) nl[0].n_value;
1186 _UIImageAtPath = (UIImage *(*)(NSString *, NSBundle *)) nl[1].n_value;
1187 _UIImageRefAtPath = (CGImageRef (*)(NSString *, bool, UIImageOrientation *)) nl[2].n_value;
1188 _UIImageWithNameInDomain = (UIImage *(*)(NSString *, NSString *)) nl[3].n_value;
1189 _UIKitBundle = (NSBundle *(*)()) nl[4].n_value;
1190 _UISharedImageInitialize = (void (*)(bool)) nl[5].n_value;
1191 _UISharedImageNameGetIdentifier = (int (*)(NSString *)) nl[6].n_value;
1192 _UISharedImageWithIdentifier = (UIImage *(*)(int)) nl[7].n_value;
1194 MSHookFunction(_UIApplicationImageWithName, &$_UIApplicationImageWithName, &__UIApplicationImageWithName);
1195 MSHookFunction(_UIImageRefAtPath, &$_UIImageRefAtPath, &__UIImageRefAtPath);
1196 MSHookFunction(_UIImageWithName, &$_UIImageWithName, &__UIImageWithName);
1197 MSHookFunction(_UIImageWithNameInDomain, &$_UIImageWithNameInDomain, &__UIImageWithNameInDomain);
1199 MSHookFunction(&GSFontCreateWithName, &$GSFontCreateWithName, &_GSFontCreateWithName);
1201 if (dlopen(AudioToolbox, RTLD_LAZY | RTLD_NOLOAD) != NULL) {
1203 memset(nl, 0, sizeof(nl));
1204 nl[0].n_un.n_name = (char *) "__Z24GetFileNameForThisActionmPcRb";
1205 nlist(AudioToolbox, nl);
1206 _Z24GetFileNameForThisActionmPcRb = (bool (*)(unsigned long, char *, bool &)) nl[0].n_value;
1207 MSHookFunction(_Z24GetFileNameForThisActionmPcRb, &$_Z24GetFileNameForThisActionmPcRb, &__Z24GetFileNameForThisActionmPcRb);
1210 $NSBundle = objc_getClass("NSBundle");
1212 _NSBundle$localizedStringForKey$value$table$ = MSHookMessage($NSBundle, @selector(localizedStringForKey:value:table:), &$NSBundle$localizedStringForKey$value$table$);
1213 _NSBundle$pathForResource$ofType$ = MSHookMessage($NSBundle, @selector(pathForResource:ofType:), &$NSBundle$pathForResource$ofType$);
1215 $UIImage = objc_getClass("UIImage");
1216 $UINavigationBar = objc_getClass("UINavigationBar");
1217 $UIToolbar = objc_getClass("UIToolbar");
1219 _UIImage$defaultDesktopImage = MSHookMessage(object_getClass($UIImage), @selector(defaultDesktopImage), &$UIImage$defaultDesktopImage);
1221 //WBRename("UINavigationBar", @selector(initWithCoder:", (IMP) &UINavigationBar$initWithCoder$);
1222 //WBRename("UINavigationBarBackground", @selector(initWithFrame:withBarStyle:withTintColor:", (IMP) &UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$);
1224 _UINavigationBar$setBarStyle$ = MSHookMessage($UINavigationBar, @selector(setBarStyle:), &$UINavigationBar$setBarStyle$);
1225 _UIToolbar$setBarStyle$ = MSHookMessage($UIToolbar, @selector(setBarStyle:), &$UIToolbar$setBarStyle$);
1227 _UISharedImageInitialize(false);
1229 Manager_ = [[NSFileManager defaultManager] retain];
1230 UIImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1231 PathImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1232 Strings_ = [[NSMutableDictionary alloc] initWithCapacity:0];
1233 Bundles_ = [[NSMutableDictionary alloc] initWithCapacity:2];
1234 Themed_ = [[NSMutableDictionary alloc] initWithCapacity:128];
1236 themes_ = [[NSMutableArray alloc] initWithCapacity:8];
1238 if (NSDictionary *settings = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"/User/Library/Preferences/com.saurik.WinterBoard.plist"]]) {
1239 [settings autorelease];
1241 if (NSNumber *debug = [settings objectForKey:@"Debug"])
1242 Debug_ = [debug boolValue];
1244 NSArray *themes = [settings objectForKey:@"Themes"];
1246 if (NSString *theme = [settings objectForKey:@"Theme"])
1247 themes = [NSArray arrayWithObject:[NSDictionary dictionaryWithObjectsAndKeys:
1249 [NSNumber numberWithBool:true], @"Active",
1252 for (NSDictionary *theme in themes) {
1253 NSNumber *active = [theme objectForKey:@"Active"];
1254 if (![active boolValue])
1257 NSString *name = [theme objectForKey:@"Name"];
1261 NSString *theme = nil;
1263 #define testForTheme(format...) \
1264 if (theme == nil) { \
1265 NSString *path = [NSString stringWithFormat:format]; \
1266 if ([Manager_ fileExistsAtPath:path]) { \
1267 [themes_ addObject:path]; \
1272 testForTheme(@"/Library/Themes/%@.theme", name)
1273 testForTheme(@"/Library/Themes/%@", name)
1274 testForTheme(@"%@/Library/SummerBoard/Themes/%@", NSHomeDirectory(), name)
1278 Info_ = [[NSMutableDictionary dictionaryWithCapacity:16] retain];
1280 for (NSString *theme in themes_)
1281 if (NSDictionary *info = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/Info.plist", theme]]) {
1283 for (NSString *key in [info allKeys])
1284 if ([Info_ objectForKey:key] == nil)
1285 [Info_ setObject:[info objectForKey:key] forKey:key];
1288 if ([identifier isEqualToString:@"com.apple.MobileSMS"]) {
1289 Class mSMSMessageTranscriptController = objc_getClass("mSMSMessageTranscriptController");
1290 _mSMSMessageTranscriptController$loadView = MSHookMessage(mSMSMessageTranscriptController, @selector(loadView), &$mSMSMessageTranscriptController$loadView);
1291 } else if ([identifier isEqualToString:@"com.apple.springboard"]) {
1292 CFNotificationCenterAddObserver(
1293 CFNotificationCenterGetDarwinNotifyCenter(),
1294 NULL, &ChangeWallpaper, (CFStringRef) @"com.saurik.winterboard.lockbackground", NULL, 0
1297 NSBundle *MediaPlayer = [NSBundle bundleWithPath:@"/System/Library/Frameworks/MediaPlayer.framework"];
1298 if (MediaPlayer != nil)
1301 $MPMoviePlayerController = objc_getClass("MPMoviePlayerController");
1302 $MPVideoView = objc_getClass("MPVideoView");
1303 $WebCoreFrameBridge = objc_getClass("WebCoreFrameBridge");
1305 $SBApplication = objc_getClass("SBApplication");
1306 $SBApplicationIcon = objc_getClass("SBApplicationIcon");
1307 $SBAwayView = objc_getClass("SBAwayView");
1308 $SBBookmarkIcon = objc_getClass("SBBookmarkIcon");
1309 $SBButtonBar = objc_getClass("SBButtonBar");
1310 $SBCalendarIconContentsView = objc_getClass("SBCalendarIconContentsView");
1311 $SBContentLayer = objc_getClass("SBContentLayer");
1312 $SBIconBadge = objc_getClass("SBIconBadge");
1313 $SBIconController = objc_getClass("SBIconController");
1314 $SBIconLabel = objc_getClass("SBIconLabel");
1315 $SBIconList = objc_getClass("SBIconList");
1316 $SBIconModel = objc_getClass("SBIconModel");
1317 //$SBImageCache = objc_getClass("SBImageCache");
1318 $SBStatusBarContentsView = objc_getClass("SBStatusBarContentsView");
1319 $SBStatusBarController = objc_getClass("SBStatusBarController");
1320 $SBStatusBarOperatorNameView = objc_getClass("SBStatusBarOperatorNameView");
1321 $SBStatusBarTimeView = objc_getClass("SBStatusBarTimeView");
1322 $SBWidgetApplicationIcon = objc_getClass("SBWidgetApplicationIcon");
1324 WBRename(WebCoreFrameBridge, renderedSizeOfNode:constrainedToWidth:, renderedSizeOfNode$constrainedToWidth$);
1326 WBRename(SBApplication, pathForIcon, pathForIcon);
1327 WBRename(SBApplicationIcon, icon, icon);
1328 WBRename(SBBookmarkIcon, icon, icon);
1329 WBRename(SBButtonBar, didMoveToSuperview, didMoveToSuperview);
1330 WBRename(SBCalendarIconContentsView, drawRect:, drawRect$);
1331 WBRename(SBContentLayer, initWithSize:, initWithSize$);
1332 WBRename(SBIconBadge, initWithBadge:, initWithBadge$);
1333 WBRename(SBIconController, noteNumberOfIconListsChanged, noteNumberOfIconListsChanged);
1334 WBRename(SBWidgetApplicationIcon, icon, icon);
1336 WBRename(SBIconLabel, drawRect:, drawRect$);
1337 WBRename(SBIconLabel, initWithSize:label:, initWithSize$label$);
1338 WBRename(SBIconLabel, setInDock:, setInDock$);
1340 WBRename(SBIconList, setFrame:, setFrame$);
1342 WBRename(SBIconModel, cacheImageForIcon:, cacheImageForIcon$);
1343 WBRename(SBIconModel, getCachedImagedForIcon:, getCachedImagedForIcon$);
1345 //WBRename(SBImageCache, initWithName:forImageWidth:imageHeight:initialCapacity:, initWithName$forImageWidth$imageHeight$initialCapacity$);
1347 WBRename(SBAwayView, updateDesktopImage:, updateDesktopImage$);
1348 WBRename(SBStatusBarContentsView, didMoveToSuperview, didMoveToSuperview);
1349 WBRename(SBStatusBarContentsView, initWithStatusBar:mode:, initWithStatusBar$mode$);
1350 WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:, setStatusBarMode$orientation$duration$fenceID$animation$);
1351 WBRename(SBStatusBarOperatorNameView, operatorNameStyle, operatorNameStyle);
1352 WBRename(SBStatusBarOperatorNameView, setOperatorName:fullSize:, setOperatorName$fullSize$);
1353 WBRename(SBStatusBarTimeView, drawRect:, drawRect$);
1355 English_ = [[NSDictionary alloc] initWithContentsOfFile:@"/System/Library/CoreServices/SpringBoard.app/English.lproj/LocalizedApplicationNames.strings"];
1356 Cache_ = [[NSMutableDictionary alloc] initWithCapacity:64];
1359 Wallpapers_ = [[NSArray arrayWithObjects:@"Wallpaper.mp4", @"Wallpaper.png", @"Wallpaper.jpg", @"Wallpaper.html", nil] retain];
1361 if ([Info_ objectForKey:@"UndockedIconLabels"] == nil)
1362 [Info_ setObject:[NSNumber numberWithBool:(
1363 $getTheme$(Wallpapers_) == nil ||
1364 [Info_ objectForKey:@"DockedIconLabelStyle"] != nil ||
1365 [Info_ objectForKey:@"UndockedIconLabelStyle"] != nil
1366 )] forKey:@"UndockedIconLabels"];
1369 NSLog(@"WB:Debug:Info = %@", [Info_ description]);