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