]> git.saurik.com Git - winterboard.git/blob - Library.mm
665f765046e8c3d040a725aa28ca1ba7d1d01dff
[winterboard.git] / Library.mm
1 /* WinterBoard - Theme Manager for the iPhone
2 * Copyright (C) 2008-2010 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 #include <sys/time.h>
39
40 struct timeval _ltv;
41 bool _itv;
42
43 #define _trace() do { \
44 struct timeval _ctv; \
45 gettimeofday(&_ctv, NULL); \
46 if (!_itv) { \
47 _itv = true; \
48 _ltv = _ctv; \
49 } \
50 fprintf(stderr, "%lu.%.6u[%f]:_trace()@%s:%u[%s]\n", \
51 _ctv.tv_sec, _ctv.tv_usec, \
52 (_ctv.tv_sec - _ltv.tv_sec) + (_ctv.tv_usec - _ltv.tv_usec) / 1000000.0, \
53 __FILE__, __LINE__, __FUNCTION__\
54 ); \
55 _ltv = _ctv; \
56 } while (false)
57
58 #define _transient
59
60 #import <CoreFoundation/CoreFoundation.h>
61 #import <Foundation/Foundation.h>
62 #import <CoreGraphics/CoreGraphics.h>
63 #import <ImageIO/CGImageSource.h>
64
65 #import <Celestial/AVController.h>
66 #import <Celestial/AVItem.h>
67 #import <Celestial/AVQueue.h>
68
69 #include <substrate.h>
70
71 #import <UIKit/UIKit.h>
72
73 #import <SpringBoard/SBApplication.h>
74 #import <SpringBoard/SBApplicationIcon.h>
75 #import <SpringBoard/SBAppWindow.h>
76 #import <SpringBoard/SBAwayView.h>
77 #import <SpringBoard/SBBookmarkIcon.h>
78 #import <SpringBoard/SBButtonBar.h>
79 #import <SpringBoard/SBCalendarIconContentsView.h>
80 #import <SpringBoard/SBIconController.h>
81 #import <SpringBoard/SBIconLabel.h>
82 #import <SpringBoard/SBIconList.h>
83 #import <SpringBoard/SBIconModel.h>
84 #import <SpringBoard/SBImageCache.h>
85 // XXX: #import <SpringBoard/SBSearchView.h>
86 #import <SpringBoard/SBSearchTableViewCell.h>
87 #import <SpringBoard/SBStatusBarContentsView.h>
88 #import <SpringBoard/SBStatusBarController.h>
89 #import <SpringBoard/SBStatusBarOperatorNameView.h>
90 #import <SpringBoard/SBStatusBarTimeView.h>
91 #import <SpringBoard/SBUIController.h>
92 #import <SpringBoard/SBWidgetApplicationIcon.h>
93
94 #import <MobileSMS/mSMSMessageTranscriptController.h>
95
96 #import <MediaPlayer/MPMoviePlayerController.h>
97 #import <MediaPlayer/MPVideoView.h>
98 #import <MediaPlayer/MPVideoView-PlaybackControl.h>
99
100 #import <CoreGraphics/CGGeometry.h>
101
102 #import <ChatKit/CKMessageCell.h>
103
104 extern "C" void __clear_cache (char *beg, char *end);
105
106 @protocol WinterBoard
107 - (void *) _node;
108 @end
109
110 Class $MPMoviePlayerController;
111 Class $MPVideoView;
112 Class $WebCoreFrameBridge;
113
114 Class $NSBundle;
115
116 Class $UIImage;
117 Class $UINavigationBar;
118 Class $UIToolbar;
119
120 Class $CKMessageCell;
121 Class $CKTimestampView;
122 Class $CKTranscriptController;
123 Class $CKTranscriptTableView;
124
125 Class $SBApplication;
126 Class $SBApplicationIcon;
127 Class $SBAwayView;
128 Class $SBBookmarkIcon;
129 Class $SBButtonBar;
130 Class $SBCalendarIconContentsView;
131 Class $SBIcon;
132 Class $SBIconBadge;
133 Class $SBIconController;
134 Class $SBIconLabel;
135 Class $SBIconList;
136 Class $SBIconModel;
137 //Class $SBImageCache;
138 Class $SBSearchView;
139 Class $SBSearchTableViewCell;
140 Class $SBStatusBarContentsView;
141 Class $SBStatusBarController;
142 Class $SBStatusBarOperatorNameView;
143 Class $SBStatusBarTimeView;
144 Class $SBUIController;
145 Class $SBWidgetApplicationIcon;
146
147 static bool IsWild_;
148
149 @interface NSDictionary (WinterBoard)
150 - (UIColor *) wb$colorForKey:(NSString *)key;
151 - (BOOL) wb$boolForKey:(NSString *)key;
152 @end
153
154 @implementation NSDictionary (WinterBoard)
155
156 - (UIColor *) wb$colorForKey:(NSString *)key {
157 NSString *value = [self objectForKey:key];
158 if (value == nil)
159 return nil;
160 /* XXX: incorrect */
161 return nil;
162 }
163
164 - (BOOL) wb$boolForKey:(NSString *)key {
165 if (NSString *value = [self objectForKey:key])
166 return [value boolValue];
167 return false;
168 }
169
170 @end
171
172 static BOOL (*_GSFontGetUseLegacyFontMetrics)();
173 #define $GSFontGetUseLegacyFontMetrics() \
174 (_GSFontGetUseLegacyFontMetrics == NULL ? YES : _GSFontGetUseLegacyFontMetrics())
175
176 static bool Debug_ = false;
177 static bool Engineer_ = false;
178 static bool SummerBoard_ = true;
179 static bool SpringBoard_;
180
181 static UIImage *(*_UIApplicationImageWithName)(NSString *name);
182 static UIImage *(*_UIImageAtPath)(NSString *name, NSBundle *path);
183 static CGImageRef (*_UIImageRefAtPath)(NSString *name, bool cache, UIImageOrientation *orientation);
184 static UIImage *(*_UIImageWithNameInDomain)(NSString *name, NSString *domain);
185 static NSBundle *(*_UIKitBundle)();
186 static int (*_UISharedImageNameGetIdentifier)(NSString *);
187 static UIImage *(*_UISharedImageWithIdentifier)(int);
188
189 static NSMutableDictionary *UIImages_;
190 static NSMutableDictionary *PathImages_;
191 static NSMutableDictionary *Cache_;
192 static NSMutableDictionary *Strings_;
193 static NSMutableDictionary *Themed_;
194 static NSMutableDictionary *Bundles_;
195
196 static NSFileManager *Manager_;
197 static NSDictionary *English_;
198 static NSMutableDictionary *Info_;
199 static NSMutableArray *themes_;
200
201 static NSString *$getTheme$(NSArray *files, bool parent = false) {
202 if (!parent)
203 if (NSString *path = [Themed_ objectForKey:files])
204 return reinterpret_cast<id>(path) == [NSNull null] ? nil : path;
205
206 if (Debug_)
207 NSLog(@"WB:Debug: %@", [files description]);
208
209 NSString *path;
210
211 for (NSString *theme in themes_)
212 for (NSString *file in files) {
213 path = [NSString stringWithFormat:@"%@/%@", theme, file];
214 if ([Manager_ fileExistsAtPath:path]) {
215 path = parent ? theme : path;
216 goto set;
217 }
218 }
219
220 path = nil;
221 set:
222 if (!parent)
223 [Themed_ setObject:(path == nil ? [NSNull null] : reinterpret_cast<id>(path)) forKey:files];
224 return path;
225 }
226
227 static NSString *$pathForFile$inBundle$(NSString *file, NSBundle *bundle, bool ui) {
228 NSString *identifier = [bundle bundleIdentifier];
229 NSMutableArray *names = [NSMutableArray arrayWithCapacity:8];
230
231 if (identifier != nil)
232 [names addObject:[NSString stringWithFormat:@"Bundles/%@/%@", identifier, file]];
233 if (NSString *folder = [[bundle bundlePath] lastPathComponent])
234 [names addObject:[NSString stringWithFormat:@"Folders/%@/%@", folder, file]];
235 if (ui)
236 [names addObject:[NSString stringWithFormat:@"UIImages/%@", file]];
237
238 #define remapResourceName(oldname, newname) \
239 else if ([file isEqualToString:oldname]) \
240 [names addObject:[NSString stringWithFormat:@"%@.png", newname]]; \
241
242 bool summer(SpringBoard_ && SummerBoard_);
243
244 if (identifier == nil);
245 else if ([identifier isEqualToString:@"com.apple.chatkit"])
246 [names addObject:[NSString stringWithFormat:@"Bundles/com.apple.MobileSMS/%@", file]];
247 else if ([identifier isEqualToString:@"com.apple.calculator"])
248 [names addObject:[NSString stringWithFormat:@"Files/Applications/Calculator.app/%@", file]];
249 else if (!summer);
250 remapResourceName(@"FSO_BG.png", @"StatusBar")
251 remapResourceName(@"SBDockBG.png", @"Dock")
252 remapResourceName(@"SBWeatherCelsius.png", @"Icons/Weather")
253
254 if (NSString *path = $getTheme$(names))
255 return path;
256
257 return nil;
258 }
259
260 static NSString *$pathForIcon$(SBApplication *self, NSString *suffix = @"") {
261 NSString *identifier = [self bundleIdentifier];
262 NSString *path = [self path];
263 NSString *folder = [path lastPathComponent];
264 NSString *dname = [self displayName];
265 NSString *didentifier = [self displayIdentifier];
266
267 if (Debug_)
268 NSLog(@"WB:Debug: [SBApplication(%@:%@:%@:%@) pathForIcon]", identifier, folder, dname, didentifier);
269
270 NSMutableArray *names = [NSMutableArray arrayWithCapacity:8];
271
272 /* XXX: I might need to keep this for backwards compatibility
273 if (identifier != nil)
274 [names addObject:[NSString stringWithFormat:@"Bundles/%@/icon.png", identifier]];
275 if (folder != nil)
276 [names addObject:[NSString stringWithFormat:@"Folders/%@/icon.png", folder]]; */
277
278 #define testForIcon(Name) \
279 if (NSString *name = Name) \
280 [names addObject:[NSString stringWithFormat:@"Icons%@/%@.png", suffix, name]];
281
282 if (![didentifier isEqualToString:identifier])
283 testForIcon(didentifier);
284
285 testForIcon(identifier);
286 testForIcon(dname);
287
288 if ([identifier isEqualToString:@"com.apple.MobileSMS"])
289 testForIcon(@"SMS");
290
291 if (didentifier != nil) {
292 testForIcon([English_ objectForKey:didentifier]);
293
294 NSArray *parts = [didentifier componentsSeparatedByString:@"-"];
295 if ([parts count] != 1)
296 if (NSDictionary *english = [[[NSDictionary alloc] initWithContentsOfFile:[path stringByAppendingString:@"/English.lproj/UIRoleDisplayNames.strings"]] autorelease])
297 testForIcon([english objectForKey:[parts lastObject]]);
298 }
299
300 if (NSString *path = $getTheme$(names))
301 return path;
302
303 return nil;
304 }
305
306 @interface NSBundle (WinterBoard)
307 + (NSBundle *) wb$bundleWithFile:(NSString *)path;
308 @end
309
310 @implementation NSBundle (WinterBoard)
311
312 + (NSBundle *) wb$bundleWithFile:(NSString *)path {
313 path = [path stringByDeletingLastPathComponent];
314 if (path == nil || [path length] == 0 || [path isEqualToString:@"/"])
315 return nil;
316
317 NSBundle *bundle([Bundles_ objectForKey:path]);
318 if (reinterpret_cast<id>(bundle) == [NSNull null])
319 return nil;
320 else if (bundle == nil) {
321 if ([Manager_ fileExistsAtPath:[path stringByAppendingPathComponent:@"Info.plist"]])
322 bundle = [NSBundle bundleWithPath:path];
323 if (bundle == nil)
324 bundle = [NSBundle wb$bundleWithFile:path];
325 if (Debug_)
326 NSLog(@"WB:Debug:PathBundle(%@, %@)", path, bundle);
327 [Bundles_ setObject:(bundle == nil ? [NSNull null] : reinterpret_cast<id>(bundle)) forKey:path];
328 }
329
330 return bundle;
331 }
332
333 @end
334
335 @interface NSString (WinterBoard)
336 - (NSString *) wb$themedPath;
337 @end
338
339 @implementation NSString (WinterBoard)
340
341 - (NSString *) wb$themedPath {
342 if (Debug_)
343 NSLog(@"WB:Debug:Bypass(\"%@\")", self);
344
345 if (NSBundle *bundle = [NSBundle wb$bundleWithFile:self]) {
346 NSString *file([self stringByResolvingSymlinksInPath]);
347 NSString *prefix([[bundle bundlePath] stringByResolvingSymlinksInPath]);
348 if ([file hasPrefix:prefix]) {
349 NSUInteger length([prefix length]);
350 if (length != [file length])
351 if (NSString *path = $pathForFile$inBundle$([file substringFromIndex:(length + 1)], bundle, false))
352 return path;
353 }
354 }
355
356 return self;
357 }
358
359 @end
360
361 void WBLogRect(const char *tag, struct CGRect rect) {
362 NSLog(@"%s:{%f,%f+%f,%f}", tag, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
363 }
364
365 void WBLogHierarchy(UIView *view, unsigned index = 0, unsigned indent = 0) {
366 CGRect frame([view frame]);
367 NSLog(@"%*s|%2d:%p:%s : {%f,%f+%f,%f} (%@)", indent * 3, "", index, view, class_getName([view class]), frame.origin.x, frame.origin.y, frame.size.width, frame.size.height, [view backgroundColor]);
368 index = 0;
369 for (UIView *child in [view subviews])
370 WBLogHierarchy(child, index++, indent + 1);
371 }
372
373 UIImage *$cacheForImage$(UIImage *image) {
374 CGColorSpaceRef space(CGColorSpaceCreateDeviceRGB());
375 CGRect rect = {CGPointMake(1, 1), [image size]};
376 CGSize size = {rect.size.width + 2, rect.size.height + 2};
377
378 CGContextRef context(CGBitmapContextCreate(NULL, size.width, size.height, 8, 4 * size.width, space, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst));
379 CGColorSpaceRelease(space);
380
381 CGContextDrawImage(context, rect, [image CGImage]);
382 CGImageRef ref(CGBitmapContextCreateImage(context));
383 CGContextRelease(context);
384
385 UIImage *cache([UIImage imageWithCGImage:ref]);
386 CGImageRelease(ref);
387
388 return cache;
389 }
390
391 /*MSHook(id, SBImageCache$initWithName$forImageWidth$imageHeight$initialCapacity$, SBImageCache *self, SEL sel, NSString *name, unsigned width, unsigned height, unsigned capacity) {
392 //if ([name isEqualToString:@"icons"]) return nil;
393 return _SBImageCache$initWithName$forImageWidth$imageHeight$initialCapacity$(self, sel, name, width, height, capacity);
394 }*/
395
396 MSHook(void, SBIconModel$cacheImageForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
397 NSString *key([icon displayIdentifier]);
398
399 if (UIImage *image = [icon icon]) {
400 CGSize size = [image size];
401 if (size.width != 59 || size.height != 60) {
402 UIImage *cache($cacheForImage$(image));
403 [Cache_ setObject:cache forKey:key];
404 return;
405 }
406 }
407
408 _SBIconModel$cacheImageForIcon$(self, sel, icon);
409 }
410
411 MSHook(void, SBIconModel$cacheImagesForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
412 /* XXX: do I /really/ have to do this? figure out how to cache the small icon! */
413 _SBIconModel$cacheImagesForIcon$(self, sel, icon);
414
415 NSString *key([icon displayIdentifier]);
416
417 if (UIImage *image = [icon icon]) {
418 CGSize size = [image size];
419 if (size.width != 59 || size.height != 60) {
420 UIImage *cache($cacheForImage$(image));
421 [Cache_ setObject:cache forKey:key];
422 return;
423 }
424 }
425 }
426
427 MSHook(UIImage *, SBIconModel$getCachedImagedForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {
428 NSString *key([icon displayIdentifier]);
429 if (UIImage *image = [Cache_ objectForKey:key])
430 return image;
431 else
432 return _SBIconModel$getCachedImagedForIcon$(self, sel, icon);
433 }
434
435 MSHook(UIImage *, SBIconModel$getCachedImagedForIcon$smallIcon$, SBIconModel *self, SEL sel, SBIcon *icon, BOOL small) {
436 if (small)
437 return _SBIconModel$getCachedImagedForIcon$smallIcon$(self, sel, icon, small);
438 NSString *key([icon displayIdentifier]);
439 if (UIImage *image = [Cache_ objectForKey:key])
440 return image;
441 else
442 return _SBIconModel$getCachedImagedForIcon$smallIcon$(self, sel, icon, small);
443 }
444
445 MSHook(id, SBSearchView$initWithFrame$, id /* XXX: SBSearchView */ self, SEL sel, struct CGRect frame) {
446 if ((self = _SBSearchView$initWithFrame$(self, sel, frame)) != nil) {
447 [self setBackgroundColor:[UIColor clearColor]];
448 for (UIView *child in [self subviews])
449 [child setBackgroundColor:[UIColor clearColor]];
450 } return self;
451 }
452
453 MSHook(id, SBSearchTableViewCell$initWithStyle$reuseIdentifier$, SBSearchTableViewCell *self, SEL sel, int style, NSString *reuse) {
454 if ((self = _SBSearchTableViewCell$initWithStyle$reuseIdentifier$(self, sel, style, reuse)) != nil) {
455 [self setBackgroundColor:[UIColor clearColor]];
456 } return self;
457 }
458
459 MSHook(void, SBSearchTableViewCell$drawRect$, SBSearchTableViewCell *self, SEL sel, struct CGRect rect, BOOL selected) {
460 _SBSearchTableViewCell$drawRect$(self, sel, rect, selected);
461 float inset([self edgeInset]);
462 [[UIColor clearColor] set];
463 UIRectFill(CGRectMake(0, 0, inset, rect.size.height));
464 UIRectFill(CGRectMake(rect.size.width - inset, 0, inset, rect.size.height));
465 }
466
467 MSHook(UIImage *, SBApplicationIcon$icon, SBApplicationIcon *self, SEL sel) {
468 if (![Info_ wb$boolForKey:@"ComposeStoreIcons"])
469 if (NSString *path = $pathForIcon$([self application]))
470 return [UIImage imageWithContentsOfFile:path];
471 return _SBApplicationIcon$icon(self, sel);
472 }
473
474 MSHook(UIImage *, SBApplicationIcon$generateIconImage$, SBApplicationIcon *self, SEL sel, int type) {
475 if (type == 2)
476 if (![Info_ wb$boolForKey:@"ComposeStoreIcons"]) {
477 if (NSString *path72 = $pathForIcon$([self application], @"-72"))
478 return [UIImage imageWithContentsOfFile:path72];
479 else if (NSString *path = $pathForIcon$([self application]))
480 if (UIImage *image = [UIImage imageWithContentsOfFile:path])
481 return [image _imageScaledToProportion:1.2 interpolationQuality:5];
482 }
483 return _SBApplicationIcon$generateIconImage$(self, sel, type);
484 }
485
486 MSHook(UIImage *, SBWidgetApplicationIcon$icon, SBWidgetApplicationIcon *self, SEL sel) {
487 if (Debug_)
488 NSLog(@"WB:Debug:Widget(%@:%@)", [self displayIdentifier], [self displayName]);
489 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]]))
490 return [UIImage imageWithContentsOfFile:path];
491 return _SBWidgetApplicationIcon$icon(self, sel);
492 }
493
494 MSHook(UIImage *, SBBookmarkIcon$icon, SBBookmarkIcon *self, SEL sel) {
495 if (Debug_)
496 NSLog(@"WB:Debug:Bookmark(%@:%@)", [self displayIdentifier], [self displayName]);
497 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]]))
498 return [UIImage imageWithContentsOfFile:path];
499 return _SBBookmarkIcon$icon(self, sel);
500 }
501
502 MSHook(NSString *, SBApplication$pathForIcon, SBApplication *self, SEL sel) {
503 if (NSString *path = $pathForIcon$(self))
504 return path;
505 return _SBApplication$pathForIcon(self, sel);
506 }
507
508 static UIImage *CachedImageAtPath(NSString *path) {
509 path = [path stringByResolvingSymlinksInPath];
510 UIImage *image = [PathImages_ objectForKey:path];
511 if (image != nil)
512 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
513 image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
514 if (image != nil)
515 image = [image autorelease];
516 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:path];
517 return image;
518 }
519
520 MSHook(CGImageSourceRef, CGImageSourceCreateWithURL, CFURLRef url, CFDictionaryRef options) {
521 if (Debug_)
522 NSLog(@"WB:Debug: CGImageSourceCreateWithURL(\"%@\", %s)", url, options);
523 NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
524 if (NSString *path = (NSString *) CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle))
525 if (NSString *themed = [path wb$themedPath])
526 if (themed != path)
527 url = (CFURLRef) [NSURL fileURLWithPath:themed];
528 CGImageSourceRef source(_CGImageSourceCreateWithURL(url, options));
529 [pool release];
530 return source;
531 }
532
533 MSHook(CGImageRef, _UIImageRefAtPath, NSString *name, bool cache, UIImageOrientation *orientation) {
534 if (Debug_)
535 NSLog(@"WB:Debug: _UIImageRefAtPath(\"%@\", %s)", name, cache ? "true" : "false");
536
537 NSString *themed([name wb$themedPath]);
538
539 if (false && SpringBoard_ && SummerBoard_ && themed == name) {
540 if ([name isEqualToString:@"/System/Library/CoreServices/SpringBoard.app/SBDockBGT-Portrait.png"])
541 if (NSString *path = $getTheme$([NSArray arrayWithObject:@"Dock.png"])) {
542 UIImage *image([UIImage imageWithContentsOfFile:path]);
543 CGImageRef ref([[image _imageScaledToProportion:2.4 interpolationQuality:5] imageRef]);
544 CGImageRetain(ref);
545 return ref;
546 }
547 }
548
549 return __UIImageRefAtPath(themed, cache, orientation);
550 }
551
552 /*MSHook(UIImage *, _UIImageAtPath, NSString *name, NSBundle *bundle) {
553 if (bundle == nil)
554 return __UIImageAtPath(name, nil);
555 else {
556 NSString *key = [NSString stringWithFormat:@"B:%@/%@", [bundle bundleIdentifier], name];
557 UIImage *image = [PathImages_ objectForKey:key];
558 if (image != nil)
559 return reinterpret_cast<id>(image) == [NSNull null] ? nil : image;
560 if (Debug_)
561 NSLog(@"WB:Debug: _UIImageAtPath(\"%@\", %@)", name, bundle);
562 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
563 image = CachedImageAtPath(path);
564 if (image == nil)
565 image = __UIImageAtPath(name, bundle);
566 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
567 return image;
568 }
569 }*/
570
571 MSHook(UIImage *, _UIApplicationImageWithName, NSString *name) {
572 NSBundle *bundle = [NSBundle mainBundle];
573 if (Debug_)
574 NSLog(@"WB:Debug: _UIApplicationImageWithName(\"%@\", %@)", name, bundle);
575 if (NSString *path = $pathForFile$inBundle$(name, bundle, false))
576 return CachedImageAtPath(path);
577 return __UIApplicationImageWithName(name);
578 }
579
580 #define WBDelegate(delegate) \
581 - (NSMethodSignature*) methodSignatureForSelector:(SEL)sel { \
582 if (Engineer_) \
583 NSLog(@"WB:MS:%s:(%s)", class_getName([self class]), sel_getName(sel)); \
584 if (NSMethodSignature *sig = [delegate methodSignatureForSelector:sel]) \
585 return sig; \
586 NSLog(@"WB:Error: [%s methodSignatureForSelector:(%s)]", class_getName([self class]), sel_getName(sel)); \
587 return nil; \
588 } \
589 \
590 - (void) forwardInvocation:(NSInvocation*)inv { \
591 SEL sel = [inv selector]; \
592 if ([delegate respondsToSelector:sel]) \
593 [inv invokeWithTarget:delegate]; \
594 else \
595 NSLog(@"WB:Error: [%s forwardInvocation:(%s)]", class_getName([self class]), sel_getName(sel)); \
596 }
597
598 MSHook(NSString *, NSBundle$pathForResource$ofType$, NSBundle *self, SEL sel, NSString *resource, NSString *type) {
599 NSString *file = type == nil ? resource : [NSString stringWithFormat:@"%@.%@", resource, type];
600 if (Debug_)
601 NSLog(@"WB:Debug: [NSBundle(%@) pathForResource:\"%@\"]", [self bundleIdentifier], file);
602 if (NSString *path = $pathForFile$inBundle$(file, self, false))
603 return path;
604 return _NSBundle$pathForResource$ofType$(self, sel, resource, type);
605 }
606
607 void $setBarStyle$_(NSString *name, int &style) {
608 if (Debug_)
609 NSLog(@"WB:Debug:%@Style:%d", name, style);
610 NSNumber *number = nil;
611 if (number == nil)
612 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style-%d", name, style]];
613 if (number == nil)
614 number = [Info_ objectForKey:[NSString stringWithFormat:@"%@Style", name]];
615 if (number != nil) {
616 style = [number intValue];
617 if (Debug_)
618 NSLog(@"WB:Debug:%@Style=%d", name, style);
619 }
620 }
621
622 MSHook(void, SBCalendarIconContentsView$drawRect$, SBCalendarIconContentsView *self, SEL sel, CGRect rect) {
623 NSBundle *bundle([NSBundle mainBundle]);
624
625 CFLocaleRef locale(CFLocaleCopyCurrent());
626 CFDateFormatterRef formatter(CFDateFormatterCreate(NULL, locale, kCFDateFormatterNoStyle, kCFDateFormatterNoStyle));
627 CFRelease(locale);
628
629 CFDateRef now(CFDateCreate(NULL, CFAbsoluteTimeGetCurrent()));
630
631 CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NUMBER_FORMAT" value:@"" table:@"SpringBoard"]);
632 CFStringRef date(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
633 CFDateFormatterSetFormat(formatter, (CFStringRef) [bundle localizedStringForKey:@"CALENDAR_ICON_DAY_NAME_FORMAT" value:@"cccc" table:@"SpringBoard"]);
634 CFStringRef day(CFDateFormatterCreateStringWithDate(NULL, formatter, now));
635
636 CFRelease(now);
637
638 CFRelease(formatter);
639
640 NSString *datestyle([@""
641 "font-family: Helvetica; "
642 "font-weight: bold; "
643 "color: #333333; "
644 "alpha: 1.0; "
645 "" stringByAppendingString:(IsWild_
646 ? @"font-size: 54px; "
647 : @"font-size: 39px; "
648 )]);
649
650 NSString *daystyle([@""
651 "font-family: Helvetica; "
652 "font-weight: bold; "
653 "color: white; "
654 "text-shadow: rgba(0, 0, 0, 0.2) -1px -1px 2px; "
655 "" stringByAppendingString:(IsWild_
656 ? @"font-size: 11px; "
657 : @"font-size: 9px; "
658 )]);
659
660 if (NSString *style = [Info_ objectForKey:@"CalendarIconDateStyle"])
661 datestyle = [datestyle stringByAppendingString:style];
662 if (NSString *style = [Info_ objectForKey:@"CalendarIconDayStyle"])
663 daystyle = [daystyle stringByAppendingString:style];
664
665 float width([self bounds].size.width);
666 float leeway(10);
667 CGSize datesize = [(NSString *)date sizeWithStyle:datestyle forWidth:(width + leeway)];
668 CGSize daysize = [(NSString *)day sizeWithStyle:daystyle forWidth:(width + leeway)];
669
670 unsigned base(IsWild_ ? 89 : 70);
671 if ($GSFontGetUseLegacyFontMetrics())
672 base = base + 1;
673
674 [(NSString *)date drawAtPoint:CGPointMake(
675 (width + 1 - datesize.width) / 2, (base - datesize.height) / 2
676 ) withStyle:datestyle];
677
678 [(NSString *)day drawAtPoint:CGPointMake(
679 (width + 1 - daysize.width) / 2, ((IsWild_ ? 18 : 16) - daysize.height) / 2
680 ) withStyle:daystyle];
681
682 CFRelease(date);
683 CFRelease(day);
684 }
685
686 /*static id UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$(UINavigationBarBackground<WinterBoard> *self, SEL sel, CGRect frame, int style, UIColor *tint) {
687 _trace();
688
689 if (NSNumber *number = [Info_ objectForKey:@"NavigationBarStyle"])
690 style = [number intValue];
691
692 if (UIColor *color = [Info_ wb$colorForKey:@"NavigationBarTint"])
693 tint = color;
694
695 return [self wb$initWithFrame:frame withBarStyle:style withTintColor:tint];
696 }*/
697
698 /*static id UINavigationBar$initWithCoder$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame, NSCoder *coder) {
699 self = [self wb$initWithCoder:coder];
700 if (self == nil)
701 return nil;
702 UINavigationBar$setBarStyle$_(self);
703 return self;
704 }
705
706 static id UINavigationBar$initWithFrame$(SBAppWindow<WinterBoard> *self, SEL sel, CGRect frame) {
707 self = [self wb$initWithFrame:frame];
708 if (self == nil)
709 return nil;
710 UINavigationBar$setBarStyle$_(self);
711 return self;
712 }*/
713
714 MSHook(void, UIToolbar$setBarStyle$, UIToolbar *self, SEL sel, int style) {
715 $setBarStyle$_(@"Toolbar", style);
716 return _UIToolbar$setBarStyle$(self, sel, style);
717 }
718
719 MSHook(void, UINavigationBar$setBarStyle$, UINavigationBar *self, SEL sel, int style) {
720 $setBarStyle$_(@"NavigationBar", style);
721 return _UINavigationBar$setBarStyle$(self, sel, style);
722 }
723
724 MSHook(void, SBButtonBar$didMoveToSuperview, UIView *self, SEL sel) {
725 [[self superview] setBackgroundColor:[UIColor clearColor]];
726 _SBButtonBar$didMoveToSuperview(self, sel);
727 }
728
729 MSHook(void, SBStatusBarContentsView$didMoveToSuperview, UIView *self, SEL sel) {
730 [[self superview] setBackgroundColor:[UIColor clearColor]];
731 _SBStatusBarContentsView$didMoveToSuperview(self, sel);
732 }
733
734 MSHook(UIImage *, UIImage$defaultDesktopImage, UIImage *self, SEL sel) {
735 if (Debug_)
736 NSLog(@"WB:Debug:DefaultDesktopImage");
737 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"LockBackground.png", @"LockBackground.jpg", nil]))
738 return [UIImage imageWithContentsOfFile:path];
739 return _UIImage$defaultDesktopImage(self, sel);
740 }
741
742 static NSArray *Wallpapers_;
743 static bool Papered_;
744 static NSString *WallpaperFile_;
745 static UIImageView *WallpaperImage_;
746 static UIWebDocumentView *WallpaperPage_;
747 static NSURL *WallpaperURL_;
748
749 #define _release(object) \
750 do if (object != nil) { \
751 [object release]; \
752 object = nil; \
753 } while (false)
754
755 MSHook(id, SBUIController$init, SBUIController *self, SEL sel) {
756 self = _SBUIController$init(self, sel);
757 if (self == nil)
758 return nil;
759
760 UIDevice *device([UIDevice currentDevice]);
761 IsWild_ = [device respondsToSelector:@selector(isWildcat)] && [device isWildcat];
762
763 if (Papered_) {
764 UIWindow *&_wallpaperView(MSHookIvar<UIWindow *>(self, "_wallpaperView"));
765 if (&_wallpaperView != NULL) {
766 [_wallpaperView removeFromSuperview];
767 [_wallpaperView release];
768 _wallpaperView = nil;
769 }
770 }
771
772 UIWindow *&_window(MSHookIvar<UIWindow *>(self, "_window"));
773 UIView *&_contentLayer(MSHookIvar<UIView *>(self, "_contentLayer"));
774 UIView *&_contentView(MSHookIvar<UIView *>(self, "_contentView"));
775
776 UIView *layer;
777 if (&_contentLayer != NULL)
778 layer = _contentLayer;
779 else if (&_contentView != NULL)
780 layer = _contentView;
781 else
782 layer = nil;
783
784 UIView *content([[[UIView alloc] initWithFrame:[layer frame]] autorelease]);
785
786 [content setBackgroundColor:[layer backgroundColor]];
787 [layer setBackgroundColor:[UIColor clearColor]];
788 [layer setFrame:[content bounds]];
789 [_window setContentView:content];
790
791 UIView *indirect;
792 if (!SummerBoard_ || !IsWild_)
793 indirect = content;
794 else {
795 CGRect bounds([content bounds]);
796 bounds.origin.y = -30;
797 indirect = [[[UIView alloc] initWithFrame:bounds] autorelease];
798 [content addSubview:indirect];
799 [indirect zoomToScale:2.4];
800 }
801
802 _release(WallpaperFile_);
803 _release(WallpaperImage_);
804 _release(WallpaperPage_);
805 _release(WallpaperURL_);
806
807 if (NSString *theme = $getTheme$(Wallpapers_, true)) {
808 NSString *mp4 = [theme stringByAppendingPathComponent:@"Wallpaper.mp4"];
809 if ([Manager_ fileExistsAtPath:mp4]) {
810 #if UseAVController
811 NSError *error;
812
813 static AVController *controller_(nil);
814 if (controller_ == nil) {
815 AVQueue *queue([AVQueue avQueue]);
816 controller_ = [[AVController avControllerWithQueue:queue error:&error] retain];
817 }
818
819 AVQueue *queue([controller_ queue]);
820
821 UIView *video([[[UIView alloc] initWithFrame:[indirect bounds]] autorelease]);
822 [controller_ setLayer:[video _layer]];
823
824 AVItem *item([[[AVItem alloc] initWithPath:mp4 error:&error] autorelease]);
825 [queue appendItem:item error:&error];
826
827 [controller_ play:&error];
828 #elif UseMPMoviePlayerController
829 NSURL *url([NSURL fileURLWithPath:mp4]);
830 MPMoviePlayerController *controller = [[$MPMoviePlayerController alloc] initWithContentURL:url];
831 controller.movieControlMode = MPMovieControlModeHidden;
832 [controller play];
833 #else
834 MPVideoView *video = [[[$MPVideoView alloc] initWithFrame:[indirect bounds]] autorelease];
835 [video setMovieWithPath:mp4];
836 [video setRepeatMode:1];
837 [video setRepeatGap:-1];
838 [video playFromBeginning];;
839 #endif
840
841 [indirect addSubview:video];
842 }
843
844 NSString *png = [theme stringByAppendingPathComponent:@"Wallpaper.png"];
845 NSString *jpg = [theme stringByAppendingPathComponent:@"Wallpaper.jpg"];
846
847 NSString *path;
848 if ([Manager_ fileExistsAtPath:png])
849 path = png;
850 else if ([Manager_ fileExistsAtPath:jpg])
851 path = jpg;
852 else path = nil;
853
854 UIImage *image;
855 if (path != nil) {
856 image = [[UIImage alloc] initWithContentsOfFile:path];
857 if (image != nil)
858 image = [image autorelease];
859 } else image = nil;
860
861 if (image != nil) {
862 WallpaperFile_ = [path retain];
863 WallpaperImage_ = [[UIImageView alloc] initWithImage:image];
864 if (NSNumber *number = [Info_ objectForKey:@"WallpaperAlpha"])
865 [WallpaperImage_ setAlpha:[number floatValue]];
866 [indirect addSubview:WallpaperImage_];
867 }
868
869 NSString *html = [theme stringByAppendingPathComponent:@"Wallpaper.html"];
870 if ([Manager_ fileExistsAtPath:html]) {
871 CGRect bounds = [indirect bounds];
872
873 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
874 [view setAutoresizes:true];
875
876 WallpaperPage_ = [view retain];
877 WallpaperURL_ = [[NSURL fileURLWithPath:html] retain];
878
879 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
880
881 [view setBackgroundColor:[UIColor clearColor]];
882 if ([view respondsToSelector:@selector(setDrawsBackground:)])
883 [view setDrawsBackground:NO];
884 [[view webView] setDrawsBackground:NO];
885
886 [indirect addSubview:view];
887 }
888 }
889
890 for (size_t i(0), e([themes_ count]); i != e; ++i) {
891 NSString *theme = [themes_ objectAtIndex:(e - i - 1)];
892 NSString *html = [theme stringByAppendingPathComponent:@"Widget.html"];
893 if ([Manager_ fileExistsAtPath:html]) {
894 CGRect bounds = [indirect bounds];
895
896 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
897 [view setAutoresizes:true];
898
899 NSURL *url = [NSURL fileURLWithPath:html];
900 [view loadRequest:[NSURLRequest requestWithURL:url]];
901
902 [view setBackgroundColor:[UIColor clearColor]];
903 if ([view respondsToSelector:@selector(setDrawsBackground:)])
904 [view setDrawsBackground:NO];
905 [[view webView] setDrawsBackground:NO];
906
907 [indirect addSubview:view];
908 }
909 }
910
911 [content addSubview:layer];
912
913 return self;
914 }
915
916 MSHook(void, SBAwayView$updateDesktopImage$, SBAwayView *self, SEL sel, UIImage *image) {
917 NSString *path = $getTheme$([NSArray arrayWithObject:@"LockBackground.html"]);
918 UIView *&_backgroundView(MSHookIvar<UIView *>(self, "_backgroundView"));
919
920 if (path != nil && _backgroundView != nil)
921 path = nil;
922
923 _SBAwayView$updateDesktopImage$(self, sel, image);
924
925 if (path != nil) {
926 CGRect bounds = [self bounds];
927
928 UIWebDocumentView *view([[[UIWebDocumentView alloc] initWithFrame:bounds] autorelease]);
929 [view setAutoresizes:true];
930
931 if (WallpaperPage_ != nil)
932 [WallpaperPage_ release];
933 WallpaperPage_ = [view retain];
934
935 if (WallpaperURL_ != nil)
936 [WallpaperURL_ release];
937 WallpaperURL_ = [[NSURL fileURLWithPath:path] retain];
938
939 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
940
941 [[view webView] setDrawsBackground:false];
942 [view setBackgroundColor:[UIColor clearColor]];
943
944 [self insertSubview:view aboveSubview:_backgroundView];
945 }
946 }
947
948 /*extern "C" CGColorRef CGGStateGetSystemColor(void *);
949 extern "C" CGColorRef CGGStateGetFillColor(void *);
950 extern "C" CGColorRef CGGStateGetStrokeColor(void *);
951 extern "C" NSString *UIStyleStringFromColor(CGColorRef);*/
952
953 /* WBTimeLabel {{{ */
954 @interface WBTimeLabel : NSProxy {
955 NSString *time_;
956 _transient SBStatusBarTimeView *view_;
957 }
958
959 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view;
960
961 @end
962
963 @implementation WBTimeLabel
964
965 - (void) dealloc {
966 [time_ release];
967 [super dealloc];
968 }
969
970 - (id) initWithTime:(NSString *)time view:(SBStatusBarTimeView *)view {
971 time_ = [time retain];
972 view_ = view;
973 return self;
974 }
975
976 - (NSString *) description {
977 return time_;
978 }
979
980 WBDelegate(time_)
981
982 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
983 if (NSString *custom = [Info_ objectForKey:@"TimeStyle"]) {
984 BOOL &_mode(MSHookIvar<BOOL>(view_, "_mode"));;
985
986 [time_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
987 "font-family: Helvetica; "
988 "font-weight: bold; "
989 "font-size: 14px; "
990 "color: %@; "
991 "%@", _mode ? @"white" : @"black", custom]];
992
993 return CGSizeZero;
994 }
995
996 return [time_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
997 }
998
999 @end
1000 /* }}} */
1001 /* WBBadgeLabel {{{ */
1002 @interface WBBadgeLabel : NSProxy {
1003 NSString *badge_;
1004 }
1005
1006 - (id) initWithBadge:(NSString *)badge;
1007 - (NSString *) description;
1008
1009 @end
1010
1011 @implementation WBBadgeLabel
1012
1013 - (void) dealloc {
1014 [badge_ release];
1015 [super dealloc];
1016 }
1017
1018 - (id) initWithBadge:(NSString *)badge {
1019 badge_ = [badge retain];
1020 return self;
1021 }
1022
1023 - (NSString *) description {
1024 return [badge_ description];
1025 }
1026
1027 WBDelegate(badge_)
1028
1029 - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode {
1030 if (NSString *custom = [Info_ objectForKey:@"BadgeStyle"]) {
1031 [badge_ drawAtPoint:point withStyle:[NSString stringWithFormat:@""
1032 "font-family: Helvetica; "
1033 "font-weight: bold; "
1034 "font-size: 17px; "
1035 "color: white; "
1036 "%@", custom]];
1037
1038 return CGSizeZero;
1039 }
1040
1041 return [badge_ drawAtPoint:point forWidth:width withFont:font lineBreakMode:mode];
1042 }
1043
1044 @end
1045 /* }}} */
1046
1047 MSHook(void, SBIcon$setAlpha$, SBIcon *self, SEL sel, float alpha) {
1048 if (NSNumber *number = [Info_ objectForKey:@"IconAlpha"])
1049 alpha = [number floatValue];
1050 return _SBIcon$setAlpha$(self, sel, alpha);
1051 }
1052
1053 MSHook(id, SBIconBadge$initWithBadge$, SBIconBadge *self, SEL sel, NSString *badge) {
1054 if ((self = _SBIconBadge$initWithBadge$(self, sel, badge)) != nil) {
1055 id &_badge(MSHookIvar<id>(self, "_badge"));
1056 if (_badge != nil)
1057 if (id label = [[WBBadgeLabel alloc] initWithBadge:[_badge autorelease]])
1058 _badge = label;
1059 } return self;
1060 }
1061
1062 void SBStatusBarController$setStatusBarMode(int &mode) {
1063 if (Debug_)
1064 NSLog(@"WB:Debug:setStatusBarMode:%d", mode);
1065 if (mode < 100) // 104:hidden 105:glowing
1066 if (NSNumber *number = [Info_ objectForKey:@"StatusBarMode"])
1067 mode = [number intValue];
1068 }
1069
1070 /*MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, double duration, int animation) {
1071 NSLog(@"mode:%d orientation:%d duration:%f animation:%d", mode, orientation, duration, animation);
1072 SBStatusBarController$setStatusBarMode(mode);
1073 return _SBStatusBarController$setStatusBarMode$orientation$duration$animation$(self, sel, mode, orientation, duration, animation);
1074 }*/
1075
1076 MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$, SBStatusBarController *self, SEL sel, int mode, int orientation, float duration, int fenceID, int animation) {
1077 //NSLog(@"mode:%d orientation:%d duration:%f fenceID:%d animation:%d", mode, orientation, duration, fenceID, animation);
1078 SBStatusBarController$setStatusBarMode(mode);
1079 return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$(self, sel, mode, orientation, duration, fenceID, animation);
1080 }
1081
1082 MSHook(void, SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$startTime$, SBStatusBarController *self, SEL sel, int mode, int orientation, double duration, int fenceID, int animation, double startTime) {
1083 //NSLog(@"mode:%d orientation:%d duration:%f fenceID:%d animation:%d startTime:%f", mode, orientation, duration, fenceID, animation, startTime);
1084 SBStatusBarController$setStatusBarMode(mode);
1085 //NSLog(@"mode=%u", mode);
1086 return _SBStatusBarController$setStatusBarMode$orientation$duration$fenceID$animation$startTime$(self, sel, mode, orientation, duration, fenceID, animation, startTime);
1087 }
1088
1089 /*MSHook(id, SBStatusBarContentsView$initWithStatusBar$mode$, SBStatusBarContentsView *self, SEL sel, id bar, int mode) {
1090 if (NSNumber *number = [Info_ objectForKey:@"StatusBarContentsMode"])
1091 mode = [number intValue];
1092 return _SBStatusBarContentsView$initWithStatusBar$mode$(self, sel, bar, mode);
1093 }*/
1094
1095 MSHook(NSString *, SBStatusBarOperatorNameView$operatorNameStyle, SBStatusBarOperatorNameView *self, SEL sel) {
1096 NSString *style(_SBStatusBarOperatorNameView$operatorNameStyle(self, sel));
1097 if (Debug_)
1098 NSLog(@"operatorNameStyle= %@", style);
1099 if (NSString *custom = [Info_ objectForKey:@"OperatorNameStyle"])
1100 style = [NSString stringWithFormat:@"%@; %@", style, custom];
1101 return style;
1102 }
1103
1104 MSHook(void, SBStatusBarOperatorNameView$setOperatorName$fullSize$, SBStatusBarOperatorNameView *self, SEL sel, NSString *name, BOOL full) {
1105 if (Debug_)
1106 NSLog(@"setOperatorName:\"%@\" fullSize:%u", name, full);
1107 return _SBStatusBarOperatorNameView$setOperatorName$fullSize$(self, sel, name, NO);
1108 }
1109
1110 // XXX: replace this with [SBStatusBarTimeView tile]
1111 MSHook(void, SBStatusBarTimeView$drawRect$, SBStatusBarTimeView *self, SEL sel, CGRect rect) {
1112 id &_time(MSHookIvar<id>(self, "_time"));
1113 if (_time != nil && [_time class] != [WBTimeLabel class])
1114 object_setInstanceVariable(self, "_time", reinterpret_cast<void *>([[WBTimeLabel alloc] initWithTime:[_time autorelease] view:self]));
1115 return _SBStatusBarTimeView$drawRect$(self, sel, rect);
1116 }
1117
1118 @interface UIView (WinterBoard)
1119 - (bool) wb$isWBImageView;
1120 - (void) wb$logHierarchy;
1121 @end
1122
1123 @implementation UIView (WinterBoard)
1124
1125 - (bool) wb$isWBImageView {
1126 return false;
1127 }
1128
1129 - (void) wb$logHierarchy {
1130 WBLogHierarchy(self);
1131 }
1132
1133 @end
1134
1135 @interface WBImageView : UIImageView {
1136 }
1137
1138 - (bool) wb$isWBImageView;
1139 - (void) wb$updateFrame;
1140 @end
1141
1142 @implementation WBImageView
1143
1144 - (bool) wb$isWBImageView {
1145 return true;
1146 }
1147
1148 - (void) wb$updateFrame {
1149 CGRect frame([self frame]);
1150 frame.origin.y = 0;
1151
1152 for (UIView *view(self); ; ) {
1153 view = [view superview];
1154 if (view == nil)
1155 break;
1156 frame.origin.y -= [view frame].origin.y;
1157 }
1158
1159 [self setFrame:frame];
1160 }
1161
1162 @end
1163
1164 MSHook(void, SBIconList$setFrame$, SBIconList *self, SEL sel, CGRect frame) {
1165 NSArray *subviews([self subviews]);
1166 WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
1167 if (view != nil && [view wb$isWBImageView])
1168 [view wb$updateFrame];
1169 _SBIconList$setFrame$(self, sel, frame);
1170 }
1171
1172 MSHook(void, SBIconController$noteNumberOfIconListsChanged, SBIconController *self, SEL sel) {
1173 SBIconModel *&_iconModel(MSHookIvar<SBIconModel *>(self, "_iconModel"));
1174 NSArray *lists([_iconModel iconLists]);
1175
1176 for (unsigned i(0), e([lists count]); i != e; ++i)
1177 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Page%u.png", i]])) {
1178 SBIconList *list([lists objectAtIndex:i]);
1179 NSArray *subviews([list subviews]);
1180
1181 WBImageView *view([subviews count] == 0 ? nil : [subviews objectAtIndex:0]);
1182 if (view == nil || ![view wb$isWBImageView]) {
1183 view = [[[WBImageView alloc] init] autorelease];
1184 [list insertSubview:view atIndex:0];
1185 }
1186
1187 UIImage *image([UIImage imageWithContentsOfFile:path]);
1188
1189 CGRect frame([view frame]);
1190 frame.size = [image size];
1191 [view setFrame:frame];
1192
1193 [view setImage:image];
1194 [view wb$updateFrame];
1195 }
1196
1197 return _SBIconController$noteNumberOfIconListsChanged(self, sel);
1198 }
1199
1200 MSHook(id, SBIconLabel$initWithSize$label$, SBIconLabel *self, SEL sel, CGSize size, NSString *label) {
1201 self = _SBIconLabel$initWithSize$label$(self, sel, size, label);
1202 if (self != nil)
1203 [self setClipsToBounds:NO];
1204 return self;
1205 }
1206
1207 MSHook(void, SBIconLabel$setInDock$, SBIconLabel *self, SEL sel, BOOL docked) {
1208 id &_label(MSHookIvar<id>(self, "_label"));
1209 if (![Info_ wb$boolForKey:@"UndockedIconLabels"])
1210 docked = true;
1211 if (_label != nil && [_label respondsToSelector:@selector(setInDock:)])
1212 [_label setInDock:docked];
1213 return _SBIconLabel$setInDock$(self, sel, docked);
1214 }
1215
1216 MSHook(NSString *, NSBundle$localizedStringForKey$value$table$, NSBundle *self, SEL sel, NSString *key, NSString *value, NSString *table) {
1217 NSString *identifier = [self bundleIdentifier];
1218 NSLocale *locale = [NSLocale currentLocale];
1219 NSString *language = [locale objectForKey:NSLocaleLanguageCode];
1220 if (Debug_)
1221 NSLog(@"WB:Debug:[NSBundle(%@) localizedStringForKey:\"%@\" value:\"%@\" table:\"%@\"] (%@)", identifier, key, value, table, language);
1222 NSString *file = table == nil ? @"Localizable" : table;
1223 NSString *name = [NSString stringWithFormat:@"%@:%@", identifier, file];
1224 NSDictionary *strings;
1225 if ((strings = [Strings_ objectForKey:name]) != nil) {
1226 if (static_cast<id>(strings) != [NSNull null]) strings:
1227 if (NSString *value = [strings objectForKey:key])
1228 return value;
1229 } else if (NSString *path = $pathForFile$inBundle$([NSString stringWithFormat:@"%@.lproj/%@.strings",
1230 language, file
1231 ], self, false)) {
1232 if ((strings = [[NSDictionary alloc] initWithContentsOfFile:path]) != nil) {
1233 [Strings_ setObject:[strings autorelease] forKey:name];
1234 goto strings;
1235 } else goto null;
1236 } else null:
1237 [Strings_ setObject:[NSNull null] forKey:name];
1238 return _NSBundle$localizedStringForKey$value$table$(self, sel, key, value, table);
1239 }
1240
1241 @class WebCoreFrameBridge;
1242 MSHook(CGSize, WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$, WebCoreFrameBridge *self, SEL sel, id node, float width) {
1243 if (node == nil)
1244 return CGSizeZero;
1245 void **core(reinterpret_cast<void **>([node _node]));
1246 if (core == NULL || core[6] == NULL)
1247 return CGSizeZero;
1248 return _WebCoreFrameBridge$renderedSizeOfNode$constrainedToWidth$(self, sel, node, width);
1249 }
1250
1251 MSHook(void, SBIconLabel$drawRect$, SBIconLabel *self, SEL sel, CGRect rect) {
1252 CGRect bounds = [self bounds];
1253
1254 static Ivar drawMoreLegibly = object_getInstanceVariable(self, "_drawMoreLegibly", NULL);
1255
1256 int docked;
1257 Ivar ivar = object_getInstanceVariable(self, "_inDock", reinterpret_cast<void **>(&docked));
1258 docked = (docked & (ivar_getOffset(ivar) == ivar_getOffset(drawMoreLegibly) ? 0x2 : 0x1)) != 0;
1259
1260 NSString *label(MSHookIvar<NSString *>(self, "_label"));
1261
1262 NSString *style = [NSString stringWithFormat:@""
1263 "font-family: Helvetica; "
1264 "font-weight: bold; "
1265 "color: %@; %@"
1266 "", (docked || !SummerBoard_ ? @"white" : @"#b3b3b3"), (IsWild_
1267 ? @"font-size: 12px; "
1268 : @"font-size: 11px; "
1269 )];
1270
1271 if (IsWild_)
1272 style = [style stringByAppendingString:@"text-shadow: rgba(0, 0, 0, 0.5) 0px 1px 0px; "];
1273 else if (docked)
1274 style = [style stringByAppendingString:@"text-shadow: rgba(0, 0, 0, 0.5) 0px -1px 0px; "];
1275
1276 bool ellipsis(false);
1277 float max = 75, width;
1278 width:
1279 width = [(ellipsis ? [label stringByAppendingString:@"..."] : label) sizeWithStyle:style forWidth:320].width;
1280
1281 if (width > max) {
1282 size_t length([label length]);
1283 float spacing((width - max) / (length - 1));
1284
1285 if (spacing > 1.25) {
1286 ellipsis = true;
1287 label = [label substringToIndex:(length - 1)];
1288 goto width;
1289 }
1290
1291 style = [style stringByAppendingString:[NSString stringWithFormat:@"letter-spacing: -%f; ", spacing]];
1292 }
1293
1294 if (ellipsis)
1295 label = [label stringByAppendingString:@"..."];
1296
1297 if (NSString *custom = [Info_ objectForKey:(docked ? @"DockedIconLabelStyle" : @"UndockedIconLabelStyle")])
1298 style = [style stringByAppendingString:custom];
1299
1300 CGSize size = [label sizeWithStyle:style forWidth:bounds.size.width];
1301 [label drawAtPoint:CGPointMake((bounds.size.width - size.width) / 2, 0) withStyle:style];
1302 }
1303
1304 MSHook(void, CKMessageCell$addBalloonView$, id self, SEL sel, CKBalloonView *balloon) {
1305 _CKMessageCell$addBalloonView$(self, sel, balloon);
1306 [balloon setBackgroundColor:[UIColor clearColor]];
1307 }
1308
1309 MSHook(id, CKMessageCell$initWithStyle$reuseIdentifier$, id self, SEL sel, int style, NSString *reuse) {
1310 if ((self = _CKMessageCell$initWithStyle$reuseIdentifier$(self, sel, style, reuse)) != nil) {
1311 [[self contentView] setBackgroundColor:[UIColor clearColor]];
1312 } return self;
1313 }
1314
1315 MSHook(id, CKTimestampView$initWithStyle$reuseIdentifier$, id self, SEL sel, int style, NSString *reuse) {
1316 if ((self = _CKTimestampView$initWithStyle$reuseIdentifier$(self, sel, style, reuse)) != nil) {
1317 UILabel *&_label(MSHookIvar<UILabel *>(self, "_label"));
1318 [_label setBackgroundColor:[UIColor clearColor]];
1319 } return self;
1320 }
1321
1322 MSHook(void, CKTranscriptTableView$setSeparatorStyle$, id self, SEL sel, int style) {
1323 _CKTranscriptTableView$setSeparatorStyle$(self, sel, UITableViewCellSeparatorStyleNone);
1324 }
1325
1326 MSHook(id, CKTranscriptTableView$initWithFrame$style$, id self, SEL sel, CGRect frame, int style) {
1327 _trace();
1328 if ((self = _CKTranscriptTableView$initWithFrame$style$(self, sel, frame, style)) != nil) {
1329 [self setSeparatorStyle:UITableViewCellSeparatorStyleNone];
1330 } return self;
1331 }
1332
1333 MSHook(void, TranscriptController$loadView, mSMSMessageTranscriptController *self, SEL sel) {
1334 _TranscriptController$loadView(self, sel);
1335
1336 if (NSString *path = $getTheme$([NSArray arrayWithObjects:@"SMSBackground.png", @"SMSBackground.jpg", nil]))
1337 if (UIImage *image = [[UIImage alloc] initWithContentsOfFile:path]) {
1338 [image autorelease];
1339
1340 UIView *&_transcriptTable(MSHookIvar<UIView *>(self, "_transcriptTable"));
1341 UIView *&_transcriptLayer(MSHookIvar<UIView *>(self, "_transcriptLayer"));
1342 UIView *table;
1343 if (&_transcriptTable != NULL)
1344 table = _transcriptTable;
1345 else if (&_transcriptLayer != NULL)
1346 table = _transcriptLayer;
1347 else
1348 table = nil;
1349
1350 UIView *placard(table != nil ? [table superview] : MSHookIvar<UIView *>(self, "_backPlacard"));
1351 UIImageView *background([[[UIImageView alloc] initWithImage:image] autorelease]);
1352
1353 if (table == nil)
1354 [placard insertSubview:background atIndex:0];
1355 else {
1356 [table setBackgroundColor:[UIColor clearColor]];
1357 [placard insertSubview:background belowSubview:table];
1358 }
1359 }
1360 }
1361
1362 MSHook(UIImage *, _UIImageWithName, NSString *name) {
1363 int id(_UISharedImageNameGetIdentifier(name));
1364 if (Debug_)
1365 NSLog(@"WB:Debug: _UIImageWithName(\"%@\": %d)", name, id);
1366
1367 if (id == -1)
1368 return _UIImageAtPath(name, _UIKitBundle());
1369 else {
1370 NSNumber *key([NSNumber numberWithInt:id]);
1371 UIImage *image = [UIImages_ objectForKey:key];
1372 if (image != nil)
1373 return reinterpret_cast<id>(image) == [NSNull null] ? _UISharedImageWithIdentifier(id) : image;
1374 if (NSString *path = $pathForFile$inBundle$(name, _UIKitBundle(), true)) {
1375 image = [[UIImage alloc] initWithContentsOfFile:path cache:true];
1376 if (image != nil)
1377 [image autorelease];
1378 }
1379 [UIImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
1380 return image == nil ? _UISharedImageWithIdentifier(id) : image;
1381 }
1382 }
1383
1384 MSHook(UIImage *, _UIImageWithNameInDomain, NSString *name, NSString *domain) {
1385 NSString *key([NSString stringWithFormat:@"D:%zu%@%@", [domain length], domain, name]);
1386 UIImage *image([PathImages_ objectForKey:key]);
1387 if (image != nil)
1388 return reinterpret_cast<id>(image) == [NSNull null] ? __UIImageWithNameInDomain(name, domain) : image;
1389 if (Debug_)
1390 NSLog(@"WB:Debug: UIImageWithNameInDomain(\"%@\", \"%@\")", name, domain);
1391 if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Domains/%@/%@", domain, name]])) {
1392 image = [[UIImage alloc] initWithContentsOfFile:path];
1393 if (image != nil)
1394 [image autorelease];
1395 }
1396 [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:key];
1397 return image == nil ? __UIImageWithNameInDomain(name, domain) : image;
1398 }
1399
1400 MSHook(GSFontRef, GSFontCreateWithName, const char *name, GSFontSymbolicTraits traits, float size) {
1401 if (Debug_)
1402 NSLog(@"WB:Debug: GSFontCreateWithName(\"%s\", %f)", name, size);
1403 if (NSString *font = [Info_ objectForKey:[NSString stringWithFormat:@"FontName-%s", name]])
1404 name = [font UTF8String];
1405 //if (NSString *scale = [Info_ objectForKey:[NSString stringWithFormat:@"FontScale-%s", name]])
1406 // size *= [scale floatValue];
1407 return _GSFontCreateWithName(name, traits, size);
1408 }
1409
1410 #define AudioToolbox "/System/Library/Frameworks/AudioToolbox.framework/AudioToolbox"
1411 #define UIKit "/System/Library/Frameworks/UIKit.framework/UIKit"
1412
1413 bool (*_Z24GetFileNameForThisActionmPcRb)(unsigned long a0, char *a1, bool &a2);
1414
1415 MSHook(bool, _Z24GetFileNameForThisActionmPcRb, unsigned long a0, char *a1, bool &a2) {
1416 if (Debug_)
1417 NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %p, %u)", a0, a1, a2);
1418 bool value = __Z24GetFileNameForThisActionmPcRb(a0, a1, a2);
1419 if (Debug_)
1420 NSLog(@"WB:Debug:GetFileNameForThisAction(%u, %s, %u) = %u", a0, value ? a1 : NULL, a2, value);
1421
1422 if (value) {
1423 NSString *path = [NSString stringWithUTF8String:a1];
1424 if ([path hasPrefix:@"/System/Library/Audio/UISounds/"]) {
1425 NSString *file = [path substringFromIndex:31];
1426 for (NSString *theme in themes_) {
1427 NSString *path([NSString stringWithFormat:@"%@/UISounds/%@", theme, file]);
1428 if ([Manager_ fileExistsAtPath:path]) {
1429 strcpy(a1, [path UTF8String]);
1430 continue;
1431 }
1432 }
1433 }
1434 }
1435 return value;
1436 }
1437
1438 static void ChangeWallpaper(
1439 CFNotificationCenterRef center,
1440 void *observer,
1441 CFStringRef name,
1442 const void *object,
1443 CFDictionaryRef info
1444 ) {
1445 if (Debug_)
1446 NSLog(@"WB:Debug:ChangeWallpaper!");
1447
1448 UIImage *image;
1449 if (WallpaperFile_ != nil) {
1450 image = [[UIImage alloc] initWithContentsOfFile:WallpaperFile_];
1451 if (image != nil)
1452 image = [image autorelease];
1453 } else image = nil;
1454
1455 if (WallpaperImage_ != nil)
1456 [WallpaperImage_ setImage:image];
1457 if (WallpaperPage_ != nil)
1458 [WallpaperPage_ loadRequest:[NSURLRequest requestWithURL:WallpaperURL_]];
1459
1460 }
1461
1462 #define WBRename(name, sel, imp) \
1463 _ ## name ## $ ## imp = MSHookMessage($ ## name, @selector(sel), &$ ## name ## $ ## imp)
1464
1465 template <typename Type_>
1466 static void nlset(Type_ &function, struct nlist *nl, size_t index) {
1467 struct nlist &name(nl[index]);
1468 uintptr_t value(name.n_value);
1469 if ((name.n_desc & N_ARM_THUMB_DEF) != 0)
1470 value |= 0x00000001;
1471 function = reinterpret_cast<Type_>(value);
1472 }
1473
1474 template <typename Type_>
1475 static void dlset(Type_ &function, const char *name) {
1476 function = reinterpret_cast<Type_>(dlsym(RTLD_DEFAULT, name));
1477 }
1478
1479 /*static void WBImage(const struct mach_header* mh, intptr_t vmaddr_slide) {
1480 uint32_t count(_dyld_image_count());
1481 for (uint32_t index(0); index != count; ++index)
1482 if (_dyld_get_image_header(index) == mh) {
1483 CGImageSourceRef (*CGImageSourceCreateWithURL)(CFURLRef url, CFDictionaryRef options);
1484 dlset(CGImageSourceCreateWithURL, "CGImageSourceCreateWithURL");
1485 MSHookFunction(&CGImageSourceCreateWithURL, &$CGImageSourceCreateWithURL, &_CGImageSourceCreateWithURL);
1486 }
1487 }*/
1488
1489 extern "C" void WBInitialize() {
1490 NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
1491
1492 NSString *identifier([[NSBundle mainBundle] bundleIdentifier]);
1493
1494 NSLog(@"WB:Notice: WinterBoard");
1495
1496 dlset(_GSFontGetUseLegacyFontMetrics, "GSFontGetUseLegacyFontMetrics");
1497
1498 //if ([NSBundle bundleWithIdentifier:@"com.apple.ImageIO.framework"] != nil)
1499 MSHookFunction(&CGImageSourceCreateWithURL, &$CGImageSourceCreateWithURL, &_CGImageSourceCreateWithURL);
1500 //else
1501 // _dyld_register_func_for_add_image(&WBImage);
1502
1503 struct nlist nl[8];
1504
1505 if ([NSBundle bundleWithIdentifier:@"com.apple.UIKit"] != nil) {
1506 // UIKit {{{
1507 memset(nl, 0, sizeof(nl));
1508 nl[0].n_un.n_name = (char *) "__UIApplicationImageWithName";
1509 nl[1].n_un.n_name = (char *) "__UIImageAtPath";
1510 nl[2].n_un.n_name = (char *) "__UIImageRefAtPath";
1511 nl[3].n_un.n_name = (char *) "__UIImageWithNameInDomain";
1512 nl[4].n_un.n_name = (char *) "__UIKitBundle";
1513 nl[5].n_un.n_name = (char *) "__UISharedImageNameGetIdentifier";
1514 nl[6].n_un.n_name = (char *) "__UISharedImageWithIdentifier";
1515 nlist(UIKit, nl);
1516
1517 nlset(_UIApplicationImageWithName, nl, 0);
1518 nlset(_UIImageAtPath, nl, 1);
1519 nlset(_UIImageRefAtPath, nl, 2);
1520 nlset(_UIImageWithNameInDomain, nl, 3);
1521 nlset(_UIKitBundle, nl, 4);
1522 nlset(_UISharedImageNameGetIdentifier, nl, 5);
1523 nlset(_UISharedImageWithIdentifier, nl, 6);
1524
1525 MSHookFunction(_UIApplicationImageWithName, &$_UIApplicationImageWithName, &__UIApplicationImageWithName);
1526 MSHookFunction(_UIImageRefAtPath, &$_UIImageRefAtPath, &__UIImageRefAtPath);
1527 MSHookFunction(_UIImageWithName, &$_UIImageWithName, &__UIImageWithName);
1528 MSHookFunction(_UIImageWithNameInDomain, &$_UIImageWithNameInDomain, &__UIImageWithNameInDomain);
1529 // }}}
1530 }
1531
1532 MSHookFunction(&GSFontCreateWithName, &$GSFontCreateWithName, &_GSFontCreateWithName);
1533
1534 if (dlopen(AudioToolbox, RTLD_LAZY | RTLD_NOLOAD) != NULL) {
1535 // AudioToolbox {{{
1536 struct nlist nl[2];
1537 memset(nl, 0, sizeof(nl));
1538 nl[0].n_un.n_name = (char *) "__Z24GetFileNameForThisActionmPcRb";
1539 nlist(AudioToolbox, nl);
1540 nlset(_Z24GetFileNameForThisActionmPcRb, nl, 0);
1541 MSHookFunction(_Z24GetFileNameForThisActionmPcRb, &$_Z24GetFileNameForThisActionmPcRb, &__Z24GetFileNameForThisActionmPcRb);
1542 // }}}
1543 }
1544
1545 $NSBundle = objc_getClass("NSBundle");
1546
1547 _NSBundle$localizedStringForKey$value$table$ = MSHookMessage($NSBundle, @selector(localizedStringForKey:value:table:), &$NSBundle$localizedStringForKey$value$table$);
1548 _NSBundle$pathForResource$ofType$ = MSHookMessage($NSBundle, @selector(pathForResource:ofType:), &$NSBundle$pathForResource$ofType$);
1549
1550 $UIImage = objc_getClass("UIImage");
1551 $UINavigationBar = objc_getClass("UINavigationBar");
1552 $UIToolbar = objc_getClass("UIToolbar");
1553
1554 _UIImage$defaultDesktopImage = MSHookMessage(object_getClass($UIImage), @selector(defaultDesktopImage), &$UIImage$defaultDesktopImage);
1555
1556 //WBRename("UINavigationBar", @selector(initWithCoder:), (IMP) &UINavigationBar$initWithCoder$);
1557 //WBRename("UINavigationBarBackground", @selector(initWithFrame:withBarStyle:withTintColor:), (IMP) &UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$);
1558
1559 _UINavigationBar$setBarStyle$ = MSHookMessage($UINavigationBar, @selector(setBarStyle:), &$UINavigationBar$setBarStyle$);
1560 _UIToolbar$setBarStyle$ = MSHookMessage($UIToolbar, @selector(setBarStyle:), &$UIToolbar$setBarStyle$);
1561
1562 Manager_ = [[NSFileManager defaultManager] retain];
1563 UIImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1564 PathImages_ = [[NSMutableDictionary alloc] initWithCapacity:16];
1565 Strings_ = [[NSMutableDictionary alloc] initWithCapacity:0];
1566 Bundles_ = [[NSMutableDictionary alloc] initWithCapacity:2];
1567 Themed_ = [[NSMutableDictionary alloc] initWithCapacity:128];
1568
1569 themes_ = [[NSMutableArray alloc] initWithCapacity:8];
1570
1571 if (NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"/User/Library/Preferences/com.saurik.WinterBoard.plist"]]) {
1572 // Load Settings {{{
1573 if (NSNumber *value = [settings objectForKey:@"SummerBoard"])
1574 SummerBoard_ = [value boolValue];
1575 if (NSNumber *value = [settings objectForKey:@"Debug"])
1576 Debug_ = [value boolValue];
1577
1578 NSArray *themes([settings objectForKey:@"Themes"]);
1579 if (themes == nil)
1580 if (NSString *theme = [settings objectForKey:@"Theme"])
1581 themes = [NSArray arrayWithObject:[NSDictionary dictionaryWithObjectsAndKeys:
1582 theme, @"Name",
1583 [NSNumber numberWithBool:true], @"Active",
1584 nil]];
1585
1586 if (themes != nil)
1587 for (NSDictionary *theme in themes) {
1588 NSNumber *active([theme objectForKey:@"Active"]);
1589 if (![active boolValue])
1590 continue;
1591
1592 NSString *name([theme objectForKey:@"Name"]);
1593 if (name == nil)
1594 continue;
1595
1596 NSString *theme(nil);
1597
1598 #define testForTheme(format...) \
1599 if (theme == nil) { \
1600 NSString *path = [NSString stringWithFormat:format]; \
1601 if ([Manager_ fileExistsAtPath:path]) { \
1602 [themes_ addObject:path]; \
1603 continue; \
1604 } \
1605 }
1606
1607 testForTheme(@"/Library/Themes/%@.theme", name)
1608 testForTheme(@"/Library/Themes/%@", name)
1609 testForTheme(@"%@/Library/SummerBoard/Themes/%@", NSHomeDirectory(), name)
1610
1611 }
1612 // }}}
1613 }
1614
1615 Info_ = [[NSMutableDictionary dictionaryWithCapacity:16] retain];
1616
1617 for (NSString *theme in themes_)
1618 if (NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"%@/Info.plist", theme]])
1619 for (NSString *key in [info allKeys])
1620 if ([Info_ objectForKey:key] == nil)
1621 [Info_ setObject:[info objectForKey:key] forKey:key];
1622
1623 bool sms($getTheme$([NSArray arrayWithObjects:@"SMSBackground.png", @"SMSBackground.jpg", nil]) != nil);
1624
1625 SpringBoard_ = [identifier isEqualToString:@"com.apple.springboard"];
1626
1627 if ([NSBundle bundleWithIdentifier:@"com.apple.chatkit"] != nil)
1628 // ChatKit {{{
1629 if (sms) {
1630 $CKMessageCell = objc_getClass("CKMessageCell");
1631 _CKMessageCell$addBalloonView$ = MSHookMessage($CKMessageCell, @selector(addBalloonView:), &$CKMessageCell$addBalloonView$);
1632 _CKMessageCell$initWithStyle$reuseIdentifier$ = MSHookMessage($CKMessageCell, @selector(initWithStyle:reuseIdentifier:), &$CKMessageCell$initWithStyle$reuseIdentifier$);
1633
1634 $CKTranscriptTableView = objc_getClass("CKTranscriptTableView");
1635 _CKTranscriptTableView$setSeparatorStyle$ = MSHookMessage($CKTranscriptTableView, @selector(setSeparatorStyle:), &$CKTranscriptTableView$setSeparatorStyle$);
1636 _CKTranscriptTableView$initWithFrame$style$ = MSHookMessage($CKTranscriptTableView, @selector(initWithFrame:style:), &$CKTranscriptTableView$initWithFrame$style$);
1637
1638 $CKTimestampView = objc_getClass("CKTimestampView");
1639 _CKTimestampView$initWithStyle$reuseIdentifier$ = MSHookMessage($CKTimestampView, @selector(initWithStyle:reuseIdentifier:), &$CKTimestampView$initWithStyle$reuseIdentifier$);
1640
1641 $CKTranscriptController = objc_getClass("CKTranscriptController");
1642 _TranscriptController$loadView = MSHookMessage($CKTranscriptController, @selector(loadView), &$TranscriptController$loadView);
1643 }
1644 // }}}
1645
1646 if ([identifier isEqualToString:@"com.apple.MobileSMS"]) {
1647 // MobileSMS {{{
1648 if (sms) {
1649 if (_TranscriptController$loadView == NULL) {
1650 Class mSMSMessageTranscriptController = objc_getClass("mSMSMessageTranscriptController");
1651 _TranscriptController$loadView = MSHookMessage(mSMSMessageTranscriptController, @selector(loadView), &$TranscriptController$loadView);
1652 }
1653 }
1654 // }}}
1655 } else if (SpringBoard_) {
1656 // SpringBoard {{{
1657 CFNotificationCenterAddObserver(
1658 CFNotificationCenterGetDarwinNotifyCenter(),
1659 NULL, &ChangeWallpaper, (CFStringRef) @"com.saurik.winterboard.lockbackground", NULL, 0
1660 );
1661
1662 if ($getTheme$([NSArray arrayWithObject:@"Wallpaper.mp4"]) != nil) {
1663 NSBundle *MediaPlayer([NSBundle bundleWithPath:@"/System/Library/Frameworks/MediaPlayer.framework"]);
1664 if (MediaPlayer != nil)
1665 [MediaPlayer load];
1666
1667 $MPMoviePlayerController = objc_getClass("MPMoviePlayerController");
1668 $MPVideoView = objc_getClass("MPVideoView");
1669 }
1670
1671 $WebCoreFrameBridge = objc_getClass("WebCoreFrameBridge");
1672
1673 $SBApplication = objc_getClass("SBApplication");
1674 $SBApplicationIcon = objc_getClass("SBApplicationIcon");
1675 $SBAwayView = objc_getClass("SBAwayView");
1676 $SBBookmarkIcon = objc_getClass("SBBookmarkIcon");
1677 $SBButtonBar = objc_getClass("SBButtonBar");
1678 $SBCalendarIconContentsView = objc_getClass("SBCalendarIconContentsView");
1679 $SBIcon = objc_getClass("SBIcon");
1680 $SBIconBadge = objc_getClass("SBIconBadge");
1681 $SBIconController = objc_getClass("SBIconController");
1682 $SBIconLabel = objc_getClass("SBIconLabel");
1683 $SBIconList = objc_getClass("SBIconList");
1684 $SBIconModel = objc_getClass("SBIconModel");
1685 //$SBImageCache = objc_getClass("SBImageCache");
1686 $SBSearchView = objc_getClass("SBSearchView");
1687 $SBSearchTableViewCell = objc_getClass("SBSearchTableViewCell");
1688 $SBStatusBarContentsView = objc_getClass("SBStatusBarContentsView");
1689 $SBStatusBarController = objc_getClass("SBStatusBarController");
1690 $SBStatusBarOperatorNameView = objc_getClass("SBStatusBarOperatorNameView");
1691 $SBStatusBarTimeView = objc_getClass("SBStatusBarTimeView");
1692 $SBUIController = objc_getClass("SBUIController");
1693 $SBWidgetApplicationIcon = objc_getClass("SBWidgetApplicationIcon");
1694
1695 WBRename(WebCoreFrameBridge, renderedSizeOfNode:constrainedToWidth:, renderedSizeOfNode$constrainedToWidth$);
1696
1697 if (SummerBoard_) {
1698 WBRename(SBApplication, pathForIcon, pathForIcon);
1699 WBRename(SBApplicationIcon, icon, icon);
1700 WBRename(SBApplicationIcon, generateIconImage:, generateIconImage$);
1701 }
1702
1703 WBRename(SBBookmarkIcon, icon, icon);
1704 WBRename(SBButtonBar, didMoveToSuperview, didMoveToSuperview);
1705 WBRename(SBCalendarIconContentsView, drawRect:, drawRect$);
1706 WBRename(SBIcon, setAlpha:, setAlpha$);
1707 WBRename(SBIconBadge, initWithBadge:, initWithBadge$);
1708 WBRename(SBIconController, noteNumberOfIconListsChanged, noteNumberOfIconListsChanged);
1709 WBRename(SBUIController, init, init);
1710 WBRename(SBWidgetApplicationIcon, icon, icon);
1711
1712 WBRename(SBIconLabel, drawRect:, drawRect$);
1713 WBRename(SBIconLabel, initWithSize:label:, initWithSize$label$);
1714 WBRename(SBIconLabel, setInDock:, setInDock$);
1715
1716 WBRename(SBIconList, setFrame:, setFrame$);
1717
1718 WBRename(SBIconModel, cacheImageForIcon:, cacheImageForIcon$);
1719 WBRename(SBIconModel, cacheImagesForIcon:, cacheImagesForIcon$);
1720 WBRename(SBIconModel, getCachedImagedForIcon:, getCachedImagedForIcon$);
1721 WBRename(SBIconModel, getCachedImagedForIcon:smallIcon:, getCachedImagedForIcon$smallIcon$);
1722
1723 WBRename(SBSearchView, initWithFrame:, initWithFrame$);
1724 WBRename(SBSearchTableViewCell, drawRect:, drawRect$);
1725 WBRename(SBSearchTableViewCell, initWithStyle:reuseIdentifier:, initWithStyle$reuseIdentifier$);
1726
1727 //WBRename(SBImageCache, initWithName:forImageWidth:imageHeight:initialCapacity:, initWithName$forImageWidth$imageHeight$initialCapacity$);
1728
1729 WBRename(SBAwayView, updateDesktopImage:, updateDesktopImage$);
1730 WBRename(SBStatusBarContentsView, didMoveToSuperview, didMoveToSuperview);
1731 //WBRename(SBStatusBarContentsView, initWithStatusBar:mode:, initWithStatusBar$mode$);
1732 //WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:animation:, setStatusBarMode$orientation$duration$animation$);
1733 WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:, setStatusBarMode$orientation$duration$fenceID$animation$);
1734 WBRename(SBStatusBarController, setStatusBarMode:orientation:duration:fenceID:animation:startTime:, setStatusBarMode$orientation$duration$fenceID$animation$startTime$);
1735 WBRename(SBStatusBarOperatorNameView, operatorNameStyle, operatorNameStyle);
1736 WBRename(SBStatusBarOperatorNameView, setOperatorName:fullSize:, setOperatorName$fullSize$);
1737 WBRename(SBStatusBarTimeView, drawRect:, drawRect$);
1738
1739 if (SummerBoard_)
1740 English_ = [[NSDictionary alloc] initWithContentsOfFile:@"/System/Library/CoreServices/SpringBoard.app/English.lproj/LocalizedApplicationNames.strings"];
1741
1742 Cache_ = [[NSMutableDictionary alloc] initWithCapacity:64];
1743 // }}}
1744 }
1745
1746 Wallpapers_ = [[NSArray arrayWithObjects:@"Wallpaper.mp4", @"Wallpaper.png", @"Wallpaper.jpg", @"Wallpaper.html", nil] retain];
1747 Papered_ = $getTheme$(Wallpapers_) != nil;
1748
1749 if ([Info_ objectForKey:@"UndockedIconLabels"] == nil)
1750 [Info_ setObject:[NSNumber numberWithBool:(
1751 !Papered_ ||
1752 [Info_ objectForKey:@"DockedIconLabelStyle"] != nil ||
1753 [Info_ objectForKey:@"UndockedIconLabelStyle"] != nil
1754 )] forKey:@"UndockedIconLabels"];
1755
1756 if (Debug_)
1757 NSLog(@"WB:Debug:Info = %@", [Info_ description]);
1758
1759 [pool release];
1760 }