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