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