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