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