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