]> git.saurik.com Git - winterboard.git/blob - Library.mm
Improved many-theme performance.
[winterboard.git] / Library.mm
1 /* WinterBoard - Theme Manager for the iPhone
2 * Copyright (C) 2008 Jay Freeman (saurik)
3 */
4
5 /*
6 * Redistribution and use in source and binary
7 * forms, with or without modification, are permitted
8 * provided that the following conditions are met:
9 *
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
17 * distribution.
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.
21 *
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.
36 */
37
38 #define _trace() NSLog(@"WB:_trace(%u)", __LINE__);
39 #define _transient
40
41 #import <CoreFoundation/CoreFoundation.h>
42 #import <Foundation/Foundation.h>
43 #import <CoreGraphics/CoreGraphics.h>
44
45 #include <substrate.h>
46
47 #import <UIKit/UIKit.h>
48
49 #import <SpringBoard/SBApplication.h>
50 #import <SpringBoard/SBApplicationIcon.h>
51 #import <SpringBoard/SBAppWindow.h>
52 #import <SpringBoard/SBBookmarkIcon.h>
53 #import <SpringBoard/SBButtonBar.h>
54 #import <SpringBoard/SBCalendarIconContentsView.h>
55 #import <SpringBoard/SBContentLayer.h>
56 #import <SpringBoard/SBIconController.h>
57 #import <SpringBoard/SBIconLabel.h>
58 #import <SpringBoard/SBSlidingAlertDisplay.h>
59 #import <SpringBoard/SBStatusBarContentsView.h>
60 #import <SpringBoard/SBStatusBarController.h>
61 #import <SpringBoard/SBStatusBarOperatorNameView.h>
62 #import <SpringBoard/SBStatusBarTimeView.h>
63 #import <SpringBoard/SBUIController.h>
64
65 #import <MobileSMS/mSMSMessageTranscriptController.h>
66
67 #import <MediaPlayer/MPVideoView.h>
68 #import <MediaPlayer/MPVideoView-PlaybackControl.h>
69
70 #import <CoreGraphics/CGGeometry.h>
71
72 extern "C" void __clear_cache (char *beg, char *end);
73
74 @protocol WinterBoard
75 - (void *) _node;
76 @end
77
78 Class $MPVideoView;
79 Class $WebCoreFrameBridge;
80
81 Class $NSBundle;
82
83 Class $UIImage;
84 Class $UINavigationBar;
85 Class $UIToolbar;
86
87 Class $SBApplication;
88 Class $SBApplicationIcon;
89 Class $SBBookmarkIcon;
90 Class $SBButtonBar;
91 Class $SBCalendarIconContentsView;
92 Class $SBContentLayer;
93 Class $SBIconBadge;
94 Class $SBIconController;
95 Class $SBIconLabel;
96 Class $SBIconModel;
97 Class $SBSlidingAlertDisplay;
98 Class $SBStatusBarContentsView;
99 Class $SBStatusBarController;
100 Class $SBStatusBarOperatorNameView;
101 Class $SBStatusBarTimeView;
102
103 @interface NSDictionary (WinterBoard)
104 - (UIColor *) colorForKey:(NSString *)key;
105 - (BOOL) boolForKey:(NSString *)key;
106 @end
107
108 @implementation NSDictionary (WinterBoard)
109
110 - (UIColor *) colorForKey:(NSString *)key {
111 NSString *value = [self objectForKey:key];
112 if (value == nil)
113 return nil;
114 /* XXX: incorrect */
115 return nil;
116 }
117
118 - (BOOL) boolForKey:(NSString *)key {
119 if (NSString *value = [self objectForKey:key])
120 return [value boolValue];
121 return false;
122 }
123
124 @end
125
126 bool Debug_ = false;
127 bool Engineer_ = false;
128
129 static UIImage *(*_UIApplicationImageWithName)(NSString *name);
130 static UIImage *(*_UIImageAtPath)(NSString *name, NSBundle *path);
131 static CGImageRef (*_UIImageRefAtPath)(NSString *name, bool cache, UIImageOrientation *orientation);
132 static UIImage *(*_UIImageWithNameInDomain)(NSString *name, NSString *domain);
133 static NSBundle *(*_UIKitBundle)();
134 static void (*_UISharedImageInitialize)(bool);
135 static int (*_UISharedImageNameGetIdentifier)(NSString *);
136 static UIImage *(*_UISharedImageWithIdentifier)(int);
137
138 static NSMutableDictionary *UIImages_;
139 static NSMutableDictionary *PathImages_;
140 static NSMutableDictionary *Cache_;
141 static NSMutableDictionary *Strings_;
142 static NSMutableDictionary *Themed_;
143 static NSMutableDictionary *Bundles_;
144
145 static NSFileManager *Manager_;
146 static NSDictionary *English_;
147 static NSMutableDictionary *Info_;
148 static NSMutableArray *themes_;
149
150 static NSString *$getTheme$(NSArray *files, bool parent = false) {
151 if (!parent)
152 if (NSString *path = [Themed_ objectForKey:files])
153 return reinterpret_cast<id>(path) == [NSNull null] ? nil : path;
154
155 if (Debug_)
156 NSLog(@"WB:Debug: %@", [files description]);
157
158 NSString *path;
159
160 for (NSString *theme in themes_)
161 for (NSString *file in files) {
162 path = [NSString stringWithFormat:@"%@/%@", theme, file];
163 if ([Manager_ fileExistsAtPath:path]) {
164 path = parent ? theme : path;
165 goto set;
166 }
167 }
168
169 path = nil;
170 set:
171 if (!parent)
172 [Themed_ setObject:(path == nil ? [NSNull null] : reinterpret_cast<id>(path)) forKey:files];
173 return path;
174 }
175
176 static NSString *$pathForFile$inBundle$(NSString *file, NSBundle *bundle, bool ui) {
177 NSString *identifier = [bundle bundleIdentifier];
178 NSMutableArray *names = [NSMutableArray arrayWithCapacity:8];
179
180 if (identifier != nil)
181 [names addObject:[NSString stringWithFormat:@"Bundles/%@/%@", identifier, file]];
182 if (NSString *folder = [[bundle bundlePath] lastPathComponent])
183 [names addObject:[NSString stringWithFormat:@"Folders/%@/%@", folder, file]];
184 if (ui)
185 [names addObject:[NSString stringWithFormat:@"UIImages/%@", file]];
186
187 #define remapResourceName(oldname, newname) \
188 else if ([file isEqualToString:oldname]) \
189 [names addObject:[NSString stringWithFormat:@"%@.png", newname]]; \
190
191 if (identifier == nil);
192 else if ([identifier isEqualToString:@"com.apple.calculator"])
193 [names addObject:[NSString stringWithFormat:@"Files/Applications/Calculator.app/%@", file]];
194 else if (![identifier isEqualToString:@"com.apple.springboard"]);
195 remapResourceName(@"FSO_BG.png", @"StatusBar")
196 remapResourceName(@"SBDockBG.png", @"Dock")
197 remapResourceName(@"SBWeatherCelsius.png", @"Icons/Weather")
198
199 if (NSString *path = $getTheme$(names))
200 return path;
201 return nil;
202 }
203
204 static NSString *$pathForIcon$(SBApplication *self) {
205 NSString *identifier = [self bundleIdentifier];
206 NSString *path = [self path];
207 NSString *folder = [path lastPathComponent];
208 NSString *dname = [self displayName];
209 NSString *didentifier = [self displayIdentifier];
210
211 if (Debug_)
212 NSLog(@"WB:Debug: [SBApplication(%@:%@:%@:%@) pathForIcon]", identifier, folder, dname, didentifier);
213
214 NSMutableArray *names = [NSMutableArray arrayWithCapacity:8];
215
216 if (identifier != nil)
217 [names addObject:[NSString stringWithFormat:@"Bundles/%@/icon.png", identifier]];
218 if (folder != nil)
219 [names addObject:[NSString stringWithFormat:@"Folders/%@/icon.png", folder]];
220
221 #define testForIcon(Name) \
222 if (NSString *name = Name) \
223 [names addObject:[NSString stringWithFormat:@"Icons/%@.png", name]];
224
225 testForIcon(identifier);
226 testForIcon(dname);
227
228 if (didentifier != nil) {
229 testForIcon([English_ objectForKey:didentifier]);
230
231 NSArray *parts = [didentifier componentsSeparatedByString:@"-"];
232 if ([parts count] != 1)
233 if (NSDictionary *english = [[[NSDictionary alloc] initWithContentsOfFile:[path stringByAppendingString:@"/English.lproj/UIRoleDisplayNames.strings"]] autorelease])
234 testForIcon([english objectForKey:[parts lastObject]]);
235 }
236
237 if (NSString *path = $getTheme$(names))
238 return path;
239 return nil;
240 }
241
242 @interface NSBundle (WinterBoard)
243 + (NSBundle *) wb$bundleWithFile:(NSString *)path;
244 @end
245
246 @implementation NSBundle (WinterBoard)
247
248 + (NSBundle *) wb$bundleWithFile:(NSString *)path {
249 path = [path stringByDeletingLastPathComponent];
250 if (path == nil || [path length] == 0 || [path isEqualToString:@"/"])
251 return nil;
252
253 NSBundle *bundle([Bundles_ objectForKey:path]);
254 if (reinterpret_cast<id>(bundle) == [NSNull null])
255 return nil;
256 else if (bundle == nil) {
257 if ([Manager_ fileExistsAtPath:[path stringByAppendingPathComponent:@"Info.plist"]])
258 bundle = [NSBundle bundleWithPath:path];
259 if (bundle == nil)
260 bundle = [NSBundle wb$bundleWithFile:path];
261 if (Debug_)
262 NSLog(@"WB:Debug:PathBundle(%@, %@)", path, bundle);
263 [Bundles_ setObject:(bundle == nil ? [NSNull null] : reinterpret_cast<id>(bundle)) forKey:path];
264 }
265
266 return bundle;
267 }
268
269 @end
270
271 @interface NSString (WinterBoard)
272 - (NSString *) wb$themedPath;
273 @end
274
275 @implementation NSString (WinterBoard)
276
277 - (NSString *) wb$themedPath {
278 if (Debug_)
279 NSLog(@"WB:Debug:Bypass(\"%@\")", self);
280
281 if (NSBundle *bundle = [NSBundle wb$bundleWithFile:self]) {
282 NSString *file([self stringByResolvingSymlinksInPath]);
283 NSString *prefix([[bundle bundlePath] stringByResolvingSymlinksInPath]);
284 if ([file hasPrefix:prefix]) {
285 NSUInteger length([prefix length]);
286 if (length != [file length])
287 if (NSString *path = $pathForFile$inBundle$([file substringFromIndex:(length + 1)], bundle, false))
288 return path;
289 }
290 }
291
292 return self;
293 }
294
295 @end
296
297 MSHook(void, SBIconModel$cacheImageForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
298 _SBIconModel$cacheImageForIcon$(self, sel, icon);
299 NSString *key([icon displayIdentifier]);
300
301 if (UIImage *image = [icon icon]) {
302 CGColorSpaceRef space(CGColorSpaceCreateDeviceRGB());
303 CGRect rect = {CGPointMake(1, 1), [image size]};
304 CGSize size = {rect.size.width + 2, rect.size.height + 2};
305
306 CGContextRef context(CGBitmapContextCreate(NULL, size.width, size.height, 8, 4 * size.width, space, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst));
307 CGColorSpaceRelease(space);
308
309 CGContextDrawImage(context, rect, [image CGImage]);
310 CGImageRef ref(CGBitmapContextCreateImage(context));
311 CGContextRelease(context);
312
313 UIImage *image([UIImage imageWithCGImage:ref]);
314 CGImageRelease(ref);
315
316 [Cache_ setObject:image forKey:key];
317 }
318 }
319
320 MSHook(UIImage *, SBIconModel$getCachedImagedForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
321 NSString *key([icon displayIdentifier]);
322 if (UIImage *image = [Cache_ objectForKey:key])
323 return image;
324 else
325 return _SBIconModel$getCachedImagedForIcon$(self, sel, icon);
326 }
327
328 MSHook(UIImage *, SBApplicationIcon$icon, SBApplicationIcon *self, SEL sel) {
329 if (![Info_ boolForKey:@"ComposeStoreIcons"])
330 if (NSString *path = $pathForIcon$([self application]))
331 return [UIImage imageWithContentsOfFile:path];
332 return _SBApplicationIcon$icon(self, sel);
333 }
334
335 MSHook(UIImage *, SBBookmarkIcon$icon, SBBookmarkIcon *self, SEL sel) {
336 if (Debug_)
337 NSLog(@"WB:Debug:Bookmark(%@:%@)", [self displayIdentifier], [self displayName]);
338 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]]))
339 return [UIImage imageWithContentsOfFile:path];
340 return _SBBookmarkIcon$icon(self, sel);
341 }
342
343 MSHook(NSString *, SBApplication$pathForIcon, SBApplication *self, SEL sel) {
344 if (NSString *path = $pathForIcon$(self))
345 return path;
346 return _SBApplication$pathForIcon(self, sel);
347 }
348
349 static UIImage *CachedImageAtPath(NSString *path) {
350 path = [path stringByResolvingSymlinksInPath];
351 UIImage *image = [PathImages_ objectForKey:path];
352 if (image != nil)
353 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
354 image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
355 if (image != nil)
356 image = [image autorelease];
357 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:path];
358 return image;
359 }
360
361 MSHook(CGImageRef, _UIImageRefAtPath, NSString *name, bool cache, UIImageOrientation *orientation) {
362 if (Debug_)
363 NSLog(@"WB:Debug: _UIImageRefAtPath(\"%@\", %s)", name, cache ? "true" : "false");
364 return __UIImageRefAtPath([name wb$themedPath], cache, orientation);
365 }
366
367 /*MSHook(UIImage *, _UIImageAtPath, NSString *name, NSBundle *bundle) {
368 if (bundle == nil)
369 return __UIImageAtPath(name, nil);
370 else {
371 NSString *key = [NSString stringWithFormat:@"B:%@/%@", [bundle bundleIdentifier], name];
372 UIImage *image = [PathImages_ objectForKey:key];
373 if (image != nil)
374 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
375 if (Debug_)
376 NSLog(@"WB:Debug: _UIImageAtPath(\"%@\", %@)", name, bundle);
377 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
378 image = CachedImageAtPath(path);
379 if (image == nil)
380 image = __UIImageAtPath(name, bundle);
381 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
382 return image;
383 }
384 }*/
385
386 MSHook(UIImage *, _UIApplicationImageWithName, NSString *name) {
387 NSBundle *bundle = [NSBundle mainBundle];
388 if (Debug_)
389 NSLog(@"WB:Debug: _UIApplicationImageWithName(\"%@\", %@)", name, bundle);
390 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
391 return CachedImageAtPath(path);
392 return __UIApplicationImageWithName(name);
393 }
394
395 #define WBDelegate(delegate) \
396 - (NSMethodSignature*) methodSignatureForSelector:(SEL)sel { \
397 if (Engineer_) \
398 NSLog(@"WB:MS:%s:(%s)", class_getName([self class]), sel_getName(sel)); \
399 if (NSMethodSignature *sig = [delegate methodSignatureForSelector:sel]) \
400 return sig; \
401 NSLog(@"WB:Error: [%s methodSignatureForSelector:(%s)]", class_getName([self class]), sel_getName(sel)); \
402 return nil; \
403 } \
404 \
405 - (void) forwardInvocation:(NSInvocation*)inv { \
406 SEL sel = [inv selector]; \
407 if ([delegate respondsToSelector:sel]) \
408 [inv invokeWithTarget:delegate]; \
409 else \
410 NSLog(@"WB:Error: [%s forwardInvocation:(%s)]", class_getName([self class]), sel_getName(sel)); \
411 }
412
413 MSHook(NSString *, NSBundle$pathForResource$ofType$, NSBundle *self, SEL sel, NSString *resource, NSString *type) {
414 NSString *file = type == nil ? resource : [NSString stringWithFormat:@"%@.%@", resource, type];
415 if (Debug_)
416 NSLog(@"WB:Debug: [NSBundle(%@) pathForResource:\"%@\"]", [self bundleIdentifier], file);
417 if (NSString *path = $pathForFile$inBundle$(file, self, false))
418 return path;
419 return _NSBundle$pathForResource$ofType$(self, sel, resource, type);
420 }
421
422 void $setBarStyle$_(NSString *name, int &style) {
423 if (Debug_)
424 NSLog(@"WB:Debug:%@Style:%d", name, style);
425 NSNumber *number = nil;
426 if (number == nil)
427 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style-%d", name, style]];
428 if (number == nil)
429 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style", name]];
430 if (number != nil) {
431 style = [number intValue];
432 if (Debug_)
433 NSLog(@"WB:Debug:%@Style=%d", name, style);
434 }
435 }
436
437 MSHook(void, SBCalendarIconContentsView$drawRect$, SBCalendarIconContentsView *self, SEL sel, CGRect rect) {
438 NSBundle *bundle([NSBundle mainBundle]);
439
440 CFLocaleRef locale(CFLocaleCopyCurrent());
441 CFDateFormatterRef formatter(CFDateFormatterCreate(NULL, locale, kCFDateFormatterNoStyle, kCFDateFormatterNoStyle));
442 CFRelease(locale);
443
444 CFDateRef now(CFDateCreate(NULL, CFAbsoluteTimeGetCurrent()));
445
446 CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NUMBER_FORMAT" value:@"" table:@"SpringBoard"]);
447 CFStringRef date(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
448 CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NAME_FORMAT" value:@"" table:@"SpringBoard"]);
449 CFStringRef day(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
450
451 CFRelease(now);
452
453 CFRelease(formatter);
454
455 NSString *datestyle(@""
456 "font-family: Helvetica; "
457 "font-weight: bold; "
458 "font-size: 39px; "
459 "color: #333333; "
460 "alpha: 1.0; "
461 "");
462
463 NSString *daystyle(@""
464 "font-family: Helvetica; "
465 "font-weight: bold; "
466 "font-size: 9px; "
467 "color: white; "
468 "text-shadow: rgba(0, 0, 0, 0.2) -1px -1px 2px; "
469 "");
470
471 if (NSString *style = [Info_ objectForKey:@"CalendarIconDateStyle"])
472 datestyle = [datestyle stringByAppendingString:style];
473 if (NSString *style = [Info_ objectForKey:@"CalendarIconDayStyle"])
474 daystyle = [daystyle stringByAppendingString:style];
475
476 float width([self bounds].size.width);
477 float leeway(10);
478 CGSize datesize = [(NSString *)date sizeWithStyle:datestyle forWidth:(width + leeway)];
479 CGSize daysize = [(NSString *)day sizeWithStyle:daystyle forWidth:(width + leeway)];
480
481 [(NSString *)date drawAtPoint:CGPointMake(
482 (width + 1 - datesize.width) / 2, (71 - datesize.height) / 2
483 ) withStyle:datestyle];
484
485 [(NSString *)day drawAtPoint:CGPointMake(
486 (width + 1 - daysize.width) / 2, (16 - daysize.height) / 2
487 ) withStyle:daystyle];
488
489 CFRelease(date);
490 CFRelease(day);
491 }
492
493 /*static id UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$(UINavigationBarBackground<WinterBoard> *self, SEL sel, CGRect frame, int style, UIColor *tint) {
494 _trace();
495
496 if (NSNumber *number = [Info_ objectForKey:@"NavigationBarStyle"])
497 style = [number intValue];
498
499 if (UIColor *color = [Info_ colorForKey:@"NavigationBarTint"])
500 tint = color;
501
502 return [self wb$initWithFrame:frame withBarStyle:style withTintColor:tint];
503 }*/
504
505 /*static id UINavigationBar$initWithCoder$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame, NSCoder *coder) {
506 self = [self wb$initWithCoder:coder];
507 if (self == nil)
508 return nil;
509 UINavigationBar$setBarStyle$_(self);
510 return self;
511 }
512
513 static id UINavigationBar$initWithFrame$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame) {
514 self = [self wb$initWithFrame:frame];
515 if (self == nil)
516 return nil;
517 UINavigationBar$setBarStyle$_(self);
518 return self;
519 }*/
520
521 MSHook(void, UIToolbar$setBarStyle$, UIToolbar *self, SEL sel, int style) {
522 $setBarStyle$_(@"Toolbar", style);
523 return _UIToolbar$setBarStyle$(self, sel, style);
524 }
525
526 MSHook(void, UINavigationBar$setBarStyle$, UINavigationBar *self, SEL sel, int style) {
527 $setBarStyle$_(@"NavigationBar", style);
528 return _UINavigationBar$setBarStyle$(self, sel, style);
529 }
530
531 MSHook(void, SBButtonBar$didMoveToSuperview, UIView *self, SEL sel) {
532 [[self superview] setBackgroundColor:[UIColor clearColor]];
533 _SBButtonBar$didMoveToSuperview(self, sel);
534 }
535
536 MSHook(void, SBStatusBarContentsView$didMoveToSuperview, UIView *self, SEL sel) {
537 [[self superview] setBackgroundColor:[UIColor clearColor]];
538 _SBStatusBarContentsView$didMoveToSuperview(self, sel);
539 }
540
541 MSHook(UIImage *, UIImage$defaultDesktopImage, UIImage *self, SEL sel) {
542 if (Debug_)
543 NSLog(@"WB:Debug:DefaultDesktopImage");
544 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"LockBackground.png", @"LockBackground.jpg", nil]))
545 return [UIImage imageWithContentsOfFile:path];
546 return _UIImage$defaultDesktopImage(self, sel);
547 }
548
549 static NSArray *Wallpapers_;
550 static NSString *WallpaperFile_;
551 static UIImageView *WallpaperImage_;
552 static UIWebDocumentView *WallpaperPage_;
553 static NSURL *WallpaperURL_;
554
555 #define _release(object) \
556 do if (object != nil) { \
557 [object release]; \
558 object = nil; \
559 } while (false)
560
561 MSHook(id, SBContentLayer$initWithSize$, SBContentLayer *self, SEL sel, CGSize size) {
562 self = _SBContentLayer$initWithSize$(self, sel, size);
563 if (self == nil)
564 return nil;
565
566 _release(WallpaperFile_);
567 _release(WallpaperImage_);
568 _release(WallpaperPage_);
569 _release(WallpaperURL_);
570
571 if (NSString *theme = $getTheme$(Wallpapers_, true)) {
572 NSString *mp4 = [theme stringByAppendingPathComponent:@"Wallpaper.mp4"];
573 if ([Manager_ fileExistsAtPath:mp4]) {
574 MPVideoView *video = [[[$MPVideoView alloc] initWithFrame:[self bounds]] autorelease];
575 [video setMovieWithPath:mp4];
576 [video setRepeatMode:1];
577 [video setRepeatGap:0];
578 [self addSubview:video];
579 [video playFromBeginning];;
580 }
581
582 NSString *png = [theme stringByAppendingPathComponent:@"Wallpaper.png"];
583 NSString *jpg = [theme stringByAppendingPathComponent:@"Wallpaper.jpg"];
584
585 NSString *path;
586 if ([Manager_ fileExistsAtPath:png])
587 path = png;
588 else if ([Manager_ fileExistsAtPath:jpg])
589 path = jpg;
590 else path = nil;
591
592 UIImage *image;
593 if (path != nil) {
594 image = [[UIImage alloc] initWithContentsOfFile:path];
595 if (image != nil)
596 image = [image autorelease];
597 } else image = nil;
598
599 if (image != nil) {
600 WallpaperFile_ = [path retain];
601 WallpaperImage_ = [[UIImageView alloc] initWithImage:image];
602 [self addSubview:WallpaperImage_];
603 }
604
605 NSString *html = [theme stringByAppendingPathComponent:@"Wallpaper.html"];
606 if ([Manager_ fileExistsAtPath:html]) {
607 CGRect bounds = [self bounds];
608
609 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
610 [view setAutoresizes:true];
611
612 WallpaperPage_ = [view retain];
613 WallpaperURL_ = [[NSURL fileURLWithPath:html] retain];
614
615 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
616
617 [[view webView] setDrawsBackground:false];
618 [view setBackgroundColor:[UIColor clearColor]];
619
620 [self addSubview:view];
621 }
622 }
623
624 for (size_t i(0), e([themes_ count]); i != e; ++i) {
625 NSString *theme = [themes_ objectAtIndex:(e - i - 1)];
626 NSString *html = [theme stringByAppendingPathComponent:@"Widget.html"];
627 if ([Manager_ fileExistsAtPath:html]) {
628 CGRect bounds = [self bounds];
629
630 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
631 [view setAutoresizes:true];
632
633 NSURL *url = [NSURL fileURLWithPath:html];
634 [view loadRequest:[NSURLRequest requestWithURL:url]];
635
636 [[view webView] setDrawsBackground:false];
637 [view setBackgroundColor:[UIColor clearColor]];
638
639 [self addSubview:view];
640 }
641 }
642
643 return self;
644 }
645
646 MSHook(void, SBSlidingAlertDisplay$updateDesktopImage$, SBSlidingAlertDisplay *self, SEL sel, UIImage *image) {
647 NSString *path = $getTheme$([NSArray arrayWithObject:@"LockBackground.html"]);
648 UIView *&_backgroundView(MSHookIvar<UIView *>(self, "_backgroundView"));
649
650 if (path != nil && _backgroundView != nil)
651 path = nil;
652
653 _SBSlidingAlertDisplay$updateDesktopImage$(self, sel, image);
654
655 if (path != nil) {
656 CGRect bounds = [self bounds];
657
658 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
659 [view setAutoresizes:true];
660
661 if (WallpaperPage_ != nil)
662 [WallpaperPage_ release];
663 WallpaperPage_ = [view retain];
664
665 if (WallpaperURL_ != nil)
666 [WallpaperURL_ release];
667 WallpaperURL_ = [[NSURL fileURLWithPath:path] retain];
668
669 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
670
671 [[view webView] setDrawsBackground:false];
672 [view setBackgroundColor:[UIColor clearColor]];
673
674 [self insertSubview:view aboveSubview:_backgroundView];
675 }
676 }
677
678 /*extern "C" CGColorRef CGGStateGetSystemColor(void *);
679 extern "C" CGColorRef CGGStateGetFillColor(void *);
680 extern "C" CGColorRef CGGStateGetStrokeColor(void *);
681 extern "C" NSString *UIStyleStringFromColor(CGColorRef);*/
682
683 /* WBTimeLabel {{{ */
684 @interface WBTimeLabel : NSProxy {
685 NSString *time_;
686 _transient SBStatusBarTimeView *view_;
687 }
688
689 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view;
690
691 @end
692
693 @implementation WBTimeLabel
694
695 - (void) dealloc {
696 [time_ release];
697 [super dealloc];
698 }
699
700 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view {
701 time_ = [time retain];
702 view_ = view;
703 return self;
704 }
705
706 WBDelegate(time_)
707
708 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
709 if (NSString *custom = [Info_ objectForKey:@"TimeStyle"]) {
710 BOOL &_mode(MSHookIvar<BOOL>(view_, "_mode"));;
711
712 [time_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
713 "font-family: Helvetica; "
714 "font-weight: bold; "
715 "font-size: 14px; "
716 "color: %@; "
717 "%@", _mode ? @"white" : @"black", custom]];
718
719 return CGSizeZero;
720 }
721
722 return [time_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
723 }
724
725 @end
726 /* }}} */
727 /* WBBadgeLabel {{{ */
728 @interface WBBadgeLabel : NSProxy {
729 NSString *badge_;
730 }
731
732 - (id) initWithBadge:(NSString *)badge;
733
734 @end
735
736 @implementation WBBadgeLabel
737
738 - (void) dealloc {
739 [badge_ release];
740 [super dealloc];
741 }
742
743 - (id) initWithBadge:(NSString *)badge {
744 badge_ = [badge retain];
745 return self;
746 }
747
748 WBDelegate(badge_)
749
750 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
751 if (NSString *custom = [Info_ objectForKey:@"BadgeStyle"]) {
752 [badge_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
753 "font-family: Helvetica; "
754 "font-weight: bold; "
755 "font-size: 17px; "
756 "color: white; "
757 "%@", custom]];
758
759 return CGSizeZero;
760 }
761
762 return [badge_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
763 }
764
765 @end
766 /* }}} */
767
768 MSHook(id, SBIconBadge$initWithBadge$, SBIconBadge *self, SEL sel, NSString *badge) {
769 if ((self = _SBIconBadge$initWithBadge$(self, sel, badge)) != nil) {
770 id &_badge(MSHookIvar<id>(self, "_badge"));
771 if (_badge != nil)
772 if (id label = [[WBBadgeLabel alloc] initWithBadge:[_badge autorelease]])
773 _badge = label;
774 } return self;
775 }
776
777 MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, float duration, int id, int animation) {
778 if (Debug_)
779 NSLog(@"WB:Debug:setStatusBarMode:%d", mode);
780 if (mode < 100) // 104:hidden 105:glowing
781 if (NSNumber *number = [Info_ objectForKey:@"StatusBarMode"])
782 mode = [number intValue];
783 return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$(self, sel, mode, orientation, duration, id, animation);
784 }
785
786 MSHook(id, SBStatusBarContentsView$initWithStatusBar$mode$, SBStatusBarContentsView *self, SEL sel, id bar, int mode) {
787 if (NSNumber *number = [Info_ objectForKey:@"StatusBarContentsMode"])
788 mode = [number intValue];
789 return _SBStatusBarContentsView$initWithStatusBar$mode$(self, sel, bar, mode);
790 }
791
792 MSHook(NSString *, SBStatusBarOperatorNameView$operatorNameStyle, SBStatusBarOperatorNameView *self, SEL sel) {
793 NSString *style(_SBStatusBarOperatorNameView$operatorNameStyle(self, sel));
794 if (Debug_)
795 NSLog(@"operatorNameStyle= %@", style);
796 if (NSString *custom = [Info_ objectForKey:@"OperatorNameStyle"])
797 style = [NSString stringWithFormat:@"%@; %@", style, custom];
798 return style;
799 }
800
801 MSHook(void, SBStatusBarOperatorNameView$setOperatorName$fullSize$, SBStatusBarOperatorNameView *self, SEL sel, NSString *name, BOOL full) {
802 if (Debug_)
803 NSLog(@"setOperatorName:\"%@\" fullSize:%u", name, full);
804 return _SBStatusBarOperatorNameView$setOperatorName$fullSize$(self, sel, name, NO);
805 }
806
807 // XXX: replace this with [SBStatusBarTimeView tile]
808 MSHook(void, SBStatusBarTimeView$drawRect$, SBStatusBarTimeView *self, SEL sel, CGRect rect) {
809 id &_time(MSHookIvar<id>(self, "_time"));
810 if (_time != nil && [_time class] != [WBTimeLabel class])
811 object_setInstanceVariable(self, "_time", reinterpret_cast<void *>([[WBTimeLabel alloc] initWithTime:[_time autorelease] view:self]));
812 return _SBStatusBarTimeView$drawRect$(self, sel, rect);
813 }
814
815 MSHook(void, SBIconController$appendIconList$, SBIconController *self, SEL sel, SBIconList *list) {
816 if (Debug_)
817 NSLog(@"appendIconList:%@", list);
818 return _SBIconController$appendIconList$(self, sel, list);
819 }
820
821 MSHook(id, SBIconLabel$initWithSize$label$, SBIconLabel *self, SEL sel, CGSize size, NSString *label) {
822 self = _SBIconLabel$initWithSize$label$(self, sel, size, label);
823 if (self != nil)
824 [self setClipsToBounds:NO];
825 return self;
826 }
827
828 MSHook(void, SBIconLabel$setInDock$, SBIconLabel *self, SEL sel, BOOL docked) {
829 id &_label(MSHookIvar<id>(self, "_label"));
830 if (![Info_ boolForKey:@"UndockedIconLabels"])
831 docked = true;
832 if (_label != nil && [_label respondsToSelector:@selector(setInDock:)])
833 [_label setInDock:docked];
834 return _SBIconLabel$setInDock$(self, sel, docked);
835 }
836
837 MSHook(NSString *, NSBundle$localizedStringForKey$value$table$, NSBundle *self, SEL sel, NSString *key, NSString *value, NSString *table) {
838 NSString *identifier = [self bundleIdentifier];
839 NSLocale *locale = [NSLocale currentLocale];
840 NSString *language = [locale objectForKey:NSLocaleLanguageCode];
841 if (Debug_)
842 NSLog(@"WB:Debug:[NSBundle(%@) localizedStringForKey:\"%@\" value:\"%@\" table:\"%@\"] (%@)", identifier, key, value, table, language);
843 NSString *file = table == nil ? @"Localizable" : table;
844 NSString *name = [NSString stringWithFormat:@"%@:%@", identifier, file];
845 NSDictionary *strings;
846 if ((strings = [Strings_ objectForKey:name]) != nil) {
847 if (static_cast<id>(strings) != [NSNull null]) strings:
848 if (NSString *value = [strings objectForKey:key])
849 return value;
850 } else if (NSString *path = $pathForFile$inBundle$([NSString stringWithFormat:@"%@.lproj/%@.strings",
851 language, file
852 ], self, false)) {
853 if ((strings = [[NSDictionary alloc] initWithContentsOfFile:path]) != nil) {
854 [Strings_ setObject:[strings autorelease] forKey:name];
855 goto strings;
856 } else goto null;
857 } else null:
858 [Strings_ setObject:[NSNull null] forKey:name];
859 return _NSBundle$localizedStringForKey$value$table$(self, sel, key, value, table);
860 }
861
862 @class WebCoreFrameBridge;
863 MSHook(CGSize, WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$, WebCoreFrameBridge *self, SEL sel, id node, float width) {
864 if (node == nil)
865 return CGSizeZero;
866 void **core(reinterpret_cast<void **>([node _node]));
867 if (core == NULL || core[6] == NULL)
868 return CGSizeZero;
869 return _WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$(self, sel, node, width);
870 }
871
872 MSHook(void, SBIconLabel$drawRect$, SBIconLabel *self, SEL sel, CGRect rect) {
873 CGRect bounds = [self bounds];
874
875 static Ivar drawMoreLegibly = object_getInstanceVariable(self, "_drawMoreLegibly", NULL);
876
877 BOOL docked;
878 Ivar ivar = object_getInstanceVariable(self, "_inDock", reinterpret_cast<void **>(&docked));
879 docked = (docked & (ivar_getOffset(ivar) == ivar_getOffset(drawMoreLegibly) ? 0x2 : 0x1)) != 0;
880
881 NSString *&label(MSHookIvar<NSString *>(self, "_label"));
882
883 NSString *style = [NSString stringWithFormat:@""
884 "font-family: Helvetica; "
885 "font-weight: bold; "
886 "font-size: 11px; "
887 "color: %@; "
888 "", docked ? @"white" : @"#b3b3b3"];
889
890 if (docked)
891 style = [style stringByAppendingString:@"text-shadow: rgba(0, 0, 0, 0.5) 0px -1px 0px; "];
892 float max = 75, width = [label sizeWithStyle:style forWidth:320].width;
893 if (width > max)
894 style = [style stringByAppendingString:[NSString stringWithFormat:@"letter-spacing: -%f; ", ((width - max) / ([label length] - 1))]];
895 if (NSString *custom = [Info_ objectForKey:(docked ? @"DockedIconLabelStyle" : @"UndockedIconLabelStyle")])
896 style = [style stringByAppendingString:custom];
897
898 CGSize size = [label sizeWithStyle:style forWidth:bounds.size.width];
899 [label drawAtPoint:CGPointMake((bounds.size.width - size.width) / 2, 0) withStyle:style];
900 }
901
902 MSHook(void, mSMSMessageTranscriptController$loadView, mSMSMessageTranscriptController *self, SEL sel) {
903 _mSMSMessageTranscriptController$loadView(self, sel);
904
905 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"SMSBackground.png", @"SMSBackground.jpg", nil]))
906 if (UIImage *image = [[UIImage alloc] initWithContentsOfFile:path]) {
907 [image autorelease];
908 UIView *&_transcriptLayer(MSHookIvar<UIView *>(self, "_transcriptLayer"));
909 UIView *parent([_transcriptLayer superview]);
910 UIImageView *background([[[UIImageView alloc] initWithImage:image] autorelease]);
911 [parent insertSubview:background belowSubview:_transcriptLayer];
912 [_transcriptLayer setBackgroundColor:[UIColor clearColor]];
913 }
914 }
915
916 MSHook(UIImage *, _UIImageWithName, NSString *name) {
917 int id(_UISharedImageNameGetIdentifier(name));
918 if (Debug_)
919 NSLog(@"WB:Debug: _UIImageWithName(\"%@\", %d)", name, id);
920
921 if (id == -1)
922 return _UIImageAtPath(name, _UIKitBundle());
923 else {
924 NSNumber *key([NSNumber numberWithInt:id]);
925 UIImage *image = [UIImages_ objectForKey:key];
926 if (image != nil)
927 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
928 if (NSString *path = $pathForFile$inBundle$(name, _UIKitBundle(), true)) {
929 image = [[UIImage alloc] initWithContentsOfFile:path];
930 if (image != nil)
931 [image autorelease];
932 }
933 if (image == nil)
934 image = _UISharedImageWithIdentifier(id);
935 [UIImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
936 return image;
937 }
938 }
939
940 MSHook(UIImage *, _UIImageWithNameInDomain, NSString *name, NSString *domain) {
941 NSString *key = [NSString stringWithFormat:@"D:%zu%@%@", [domain length], domain, name];
942 UIImage *image = [PathImages_ objectForKey:key];
943 if (image != nil)
944 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
945 if (Debug_)
946 NSLog(@"WB:Debug: UIImageWithNameInDomain(\"%@\", \"%@\")", name, domain);
947 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Domains/%@/%@", domain, name]])) {
948 image = [[UIImage alloc] initWithContentsOfFile:path];
949 if (image != nil)
950 [image autorelease];
951 }
952 if (image == nil)
953 image = __UIImageWithNameInDomain(name, domain);
954 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
955 return image;
956 }
957
958 #define AudioToolbox "/System/Library/Frameworks/AudioToolbox.framework/AudioToolbox"
959 #define UIKit "/System/Library/Frameworks/UIKit.framework/UIKit"
960
961 bool (*_Z24GetFileNameForThisActionmPcRb)(unsigned long a0, char *a1, bool &a2);
962
963 MSHook(bool, _Z24GetFileNameForThisActionmPcRb, unsigned long a0, char *a1, bool &a2) {
964 bool value = __Z24GetFileNameForThisActionmPcRb(a0, a1, a2);
965 if (Debug_)
966 NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %s, %u) = %u", a0, value ? a1 : NULL, a2, value);
967
968 if (value) {
969 NSString *path = [NSString stringWithUTF8String:a1];
970 if ([path hasPrefix:@"/System/Library/Audio/UISounds/"]) {
971 NSString *file = [path substringFromIndex:31];
972 NSLog(@"%@", file);
973 for (NSString *theme in themes_) {
974 NSString *path([NSString stringWithFormat:@"%@/UISounds/%@", theme, file]);
975 if ([Manager_ fileExistsAtPath:path]) {
976 strcpy(a1, [path UTF8String]);
977 continue;
978 }
979 }
980 }
981 }
982 return value;
983 }
984
985 static void ChangeWallpaper(
986 CFNotificationCenterRef center,
987 void *observer,
988 CFStringRef name,
989 const void *object,
990 CFDictionaryRef info
991 ) {
992 if (Debug_)
993 NSLog(@"WB:Debug:ChangeWallpaper!");
994
995 UIImage *image;
996 if (WallpaperFile_ != nil) {
997 image = [[UIImage alloc] initWithContentsOfFile:WallpaperFile_];
998 if (image != nil)
999 image = [image autorelease];
1000 } else image = nil;
1001
1002 if (WallpaperImage_ != nil)
1003 [WallpaperImage_ setImage:image];
1004 if (WallpaperPage_ != nil)
1005 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
1006
1007 }
1008
1009 #define WBRename(name, sel, imp) \
1010 _ ## name ## $ ## imp = MSHookMessage($ ## name, @selector(sel), &$ ## name ## $ ## imp)
1011
1012 extern "C" void WBInitialize() {
1013 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
1014
1015 NSString *identifier([[NSBundle mainBundle] bundleIdentifier]);
1016
1017 NSLog(@"WB:Notice: WinterBoard");
1018
1019 struct nlist nl[9];
1020 memset(nl, 0, sizeof(nl));
1021
1022 nl[0].n_un.n_name = (char *) "__UIApplicationImageWithName";
1023 nl[1].n_un.n_name = (char *) "__UIImageAtPath";
1024 nl[2].n_un.n_name = (char *) "__UIImageRefAtPath";
1025 nl[3].n_un.n_name = (char *) "__UIImageWithNameInDomain";
1026 nl[4].n_un.n_name = (char *) "__UIKitBundle";
1027 nl[5].n_un.n_name = (char *) "__UISharedImageInitialize";
1028 nl[6].n_un.n_name = (char *) "__UISharedImageNameGetIdentifier";
1029 nl[7].n_un.n_name = (char *) "__UISharedImageWithIdentifier";
1030
1031 nlist(UIKit, nl);
1032
1033 _UIApplicationImageWithName = (UIImage *(*)(NSString *)) nl[0].n_value;
1034 _UIImageAtPath = (UIImage *(*)(NSString *, NSBundle *)) nl[1].n_value;
1035 _UIImageRefAtPath = (CGImageRef (*)(NSString *, bool, UIImageOrientation *)) nl[2].n_value;
1036 _UIImageWithNameInDomain = (UIImage *(*)(NSString *, NSString *)) nl[3].n_value;
1037 _UIKitBundle = (NSBundle *(*)()) nl[4].n_value;
1038 _UISharedImageInitialize = (void (*)(bool)) nl[5].n_value;
1039 _UISharedImageNameGetIdentifier = (int (*)(NSString *)) nl[6].n_value;
1040 _UISharedImageWithIdentifier = (UIImage *(*)(int)) nl[7].n_value;
1041
1042 MSHookFunction(_UIApplicationImageWithName, &$_UIApplicationImageWithName, &__UIApplicationImageWithName);
1043 MSHookFunction(_UIImageRefAtPath, &$_UIImageRefAtPath, &__UIImageRefAtPath);
1044 MSHookFunction(_UIImageWithName, &$_UIImageWithName, &__UIImageWithName);
1045 MSHookFunction(_UIImageWithNameInDomain, &$_UIImageWithNameInDomain, &__UIImageWithNameInDomain);
1046
1047 if (dlopen(AudioToolbox, RTLD_LAZY | RTLD_NOLOAD) != NULL) {
1048 struct nlist nl[2];
1049 memset(nl, 0, sizeof(nl));
1050 nl[0].n_un.n_name = (char *) "__Z24GetFileNameForThisActionmPcRb";
1051 nlist(AudioToolbox, nl);
1052 _Z24GetFileNameForThisActionmPcRb = (bool (*)(unsigned long, char *, bool &)) nl[0].n_value;
1053 MSHookFunction(_Z24GetFileNameForThisActionmPcRb, &$_Z24GetFileNameForThisActionmPcRb, &__Z24GetFileNameForThisActionmPcRb);
1054 }
1055
1056 $NSBundle = objc_getClass("NSBundle");
1057
1058 _NSBundle$localizedStringForKey$value$table$ = MSHookMessage($NSBundle, @selector(localizedStringForKey:value:table:), &$NSBundle$localizedStringForKey$value$table$);
1059 _NSBundle$pathForResource$ofType$ = MSHookMessage($NSBundle, @selector(pathForResource:ofType:), &$NSBundle$pathForResource$ofType$);
1060
1061 $UIImage = objc_getClass("UIImage");
1062 $UINavigationBar = objc_getClass("UINavigationBar");
1063 $UIToolbar = objc_getClass("UIToolbar");
1064
1065 _UIImage$defaultDesktopImage = MSHookMessage(object_getClass($UIImage), @selector(defaultDesktopImage), &$UIImage$defaultDesktopImage);
1066
1067 //WBRename("UINavigationBar", @selector(initWithCoder:", (IMP) &UINavigationBar$initWithCoder$);
1068 //WBRename("UINavigationBarBackground", @selector(initWithFrame:withBarStyle:withTintColor:", (IMP) &UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$);
1069
1070 _UINavigationBar$setBarStyle$ = MSHookMessage($UINavigationBar, @selector(setBarStyle:), &$UINavigationBar$setBarStyle$);
1071 _UIToolbar$setBarStyle$ = MSHookMessage($UIToolbar, @selector(setBarStyle:), &$UIToolbar$setBarStyle$);
1072
1073 _UISharedImageInitialize(false);
1074
1075 Manager_ = [[NSFileManager defaultManager] retain];
1076 UIImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1077 PathImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1078 Strings_ = [[NSMutableDictionary alloc] initWithCapacity:0];
1079 Bundles_ = [[NSMutableDictionary alloc] initWithCapacity:2];
1080 Themed_ = [[NSMutableDictionary alloc] initWithCapacity:128];
1081
1082 themes_ = [[NSMutableArray alloc] initWithCapacity:8];
1083
1084 if (NSDictionary *settings = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"/User/Library/Preferences/com.saurik.WinterBoard.plist"]]) {
1085 [settings autorelease];
1086
1087 if (NSNumber *debug = [settings objectForKey:@"Debug"])
1088 Debug_ = [debug boolValue];
1089
1090 NSArray *themes = [settings objectForKey:@"Themes"];
1091 if (themes == nil)
1092 if (NSString *theme = [settings objectForKey:@"Theme"])
1093 themes = [NSArray arrayWithObject:[NSDictionary dictionaryWithObjectsAndKeys:
1094 theme, @"Name",
1095 [NSNumber numberWithBool:true], @"Active",
1096 nil]];
1097 if (themes != nil)
1098 for (NSDictionary *theme in themes) {
1099 NSNumber *active = [theme objectForKey:@"Active"];
1100 if (![active boolValue])
1101 continue;
1102
1103 NSString *name = [theme objectForKey:@"Name"];
1104 if (name == nil)
1105 continue;
1106
1107 NSString *theme = nil;
1108
1109 #define testForTheme(format...) \
1110 if (theme == nil) { \
1111 NSString *path = [NSString stringWithFormat:format]; \
1112 if ([Manager_ fileExistsAtPath:path]) { \
1113 [themes_ addObject:path]; \
1114 continue; \
1115 } \
1116 }
1117
1118 testForTheme(@"/Library/Themes/%@.theme", name)
1119 testForTheme(@"/Library/Themes/%@", name)
1120 testForTheme(@"%@/Library/SummerBoard/Themes/%@", NSHomeDirectory(), name)
1121 }
1122 }
1123
1124 Info_ = [[NSMutableDictionary dictionaryWithCapacity:16] retain];
1125
1126 for (NSString *theme in themes_)
1127 if (NSDictionary *info = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/Info.plist", theme]])
1128 for (NSString *key in [info allKeys])
1129 if ([Info_ objectForKey:key] == nil)
1130 [Info_ setObject:[info objectForKey:key] forKey:key];
1131
1132 if ([identifier isEqualToString:@"com.apple.MobileSMS"]) {
1133 Class mSMSMessageTranscriptController = objc_getClass("mSMSMessageTranscriptController");
1134 _mSMSMessageTranscriptController$loadView = MSHookMessage(mSMSMessageTranscriptController, @selector(loadView), &$mSMSMessageTranscriptController$loadView);
1135 } else if ([identifier isEqualToString:@"com.apple.springboard"]) {
1136 CFNotificationCenterAddObserver(
1137 CFNotificationCenterGetDarwinNotifyCenter(),
1138 NULL, &ChangeWallpaper, (CFStringRef) @"com.saurik.winterboard.lockbackground", NULL, 0
1139 );
1140
1141 NSBundle *MediaPlayer = [NSBundle bundleWithPath:@"/System/Library/Frameworks/MediaPlayer.framework"];
1142 if (MediaPlayer != nil)
1143 [MediaPlayer load];
1144
1145 $MPVideoView = objc_getClass("MPVideoView");
1146 $WebCoreFrameBridge = objc_getClass("WebCoreFrameBridge");
1147
1148 $SBApplication = objc_getClass("SBApplication");
1149 $SBApplicationIcon = objc_getClass("SBApplicationIcon");
1150 $SBBookmarkIcon = objc_getClass("SBBookmarkIcon");
1151 $SBButtonBar = objc_getClass("SBButtonBar");
1152 $SBCalendarIconContentsView = objc_getClass("SBCalendarIconContentsView");
1153 $SBContentLayer = objc_getClass("SBContentLayer");
1154 $SBIconBadge = objc_getClass("SBIconBadge");
1155 $SBIconController = objc_getClass("SBIconController");
1156 $SBIconLabel = objc_getClass("SBIconLabel");
1157 $SBIconModel = objc_getClass("SBIconModel");
1158 $SBSlidingAlertDisplay = objc_getClass("SBSlidingAlertDisplay");
1159 $SBStatusBarContentsView = objc_getClass("SBStatusBarContentsView");
1160 $SBStatusBarController = objc_getClass("SBStatusBarController");
1161 $SBStatusBarOperatorNameView = objc_getClass("SBStatusBarOperatorNameView");
1162 $SBStatusBarTimeView = objc_getClass("SBStatusBarTimeView");
1163
1164 WBRename(WebCoreFrameBridge, renderedSizeOfNode:constrainedToWidth:, renderedSizeOfNode$constrainedToWidth$);
1165
1166 WBRename(SBApplication, pathForIcon, pathForIcon);
1167 WBRename(SBApplicationIcon, icon, icon);
1168 WBRename(SBBookmarkIcon, icon, icon);
1169 WBRename(SBButtonBar, didMoveToSuperview, didMoveToSuperview);
1170 WBRename(SBCalendarIconContentsView, drawRect:, drawRect$);
1171 WBRename(SBContentLayer, initWithSize:, initWithSize$);
1172 WBRename(SBIconBadge, initWithBadge:, initWithBadge$);
1173 WBRename(SBIconController, appendIconList:, appendIconList$);
1174
1175 WBRename(SBIconLabel, drawRect:, drawRect$);
1176 WBRename(SBIconLabel, initWithSize:label:, initWithSize$label$);
1177 WBRename(SBIconLabel, setInDock:, setInDock$);
1178
1179 WBRename(SBIconModel, cacheImageForIcon:, cacheImageForIcon$);
1180 WBRename(SBIconModel, getCachedImagedForIcon:, getCachedImagedForIcon$);
1181
1182 WBRename(SBSlidingAlertDisplay, updateDesktopImage:, updateDesktopImage$);
1183 WBRename(SBStatusBarContentsView, didMoveToSuperview, didMoveToSuperview);
1184 WBRename(SBStatusBarContentsView, initWithStatusBar:mode:, initWithStatusBar$mode$);
1185 WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:, setStatusBarMode$orientation$duration$fenceID$animation$);
1186 WBRename(SBStatusBarOperatorNameView, operatorNameStyle, operatorNameStyle);
1187 WBRename(SBStatusBarOperatorNameView, setOperatorName:fullSize:, setOperatorName$fullSize$);
1188 WBRename(SBStatusBarTimeView, drawRect:, drawRect$);
1189
1190 English_ = [[NSDictionary alloc] initWithContentsOfFile:@"/System/Library/CoreServices/SpringBoard.app/English.lproj/LocalizedApplicationNames.strings"];
1191 if (English_ != nil)
1192 English_ = [English_ retain];
1193
1194 Cache_ = [[NSMutableDictionary alloc] initWithCapacity:64];
1195 }
1196
1197 Wallpapers_ = [[NSArray arrayWithObjects:@"Wallpaper.mp4", @"Wallpaper.png", @"Wallpaper.jpg", @"Wallpaper.html", nil] retain];
1198
1199 if ([Info_ objectForKey:@"UndockedIconLabels"] == nil)
1200 [Info_ setObject:[NSNumber numberWithBool:(
1201 $getTheme$(Wallpapers_) == nil ||
1202 [Info_ objectForKey:@"DockedIconLabelStyle"] != nil ||
1203 [Info_ objectForKey:@"UndockedIconLabelStyle"] != nil
1204 )] forKey:@"UndockedIconLabels"];
1205
1206 if (Debug_)
1207 NSLog(@"WB:Debug:Info = %@", [Info_ description]);
1208
1209 [pool release];
1210 }