X-Git-Url: https://git.saurik.com/winterboard.git/blobdiff_plain/198eb03bb454659a44a9626ca4ad23caeace299b..cc46954c2946323eda2e776ea0fdda2d953c065d:/Library.mm diff --git a/Library.mm b/Library.mm index b7fb754..b9399a1 100644 --- a/Library.mm +++ b/Library.mm @@ -1,5 +1,5 @@ /* WinterBoard - Theme Manager for the iPhone - * Copyright (C) 2008 Jay Freeman (saurik) + * Copyright (C) 2008-2010 Jay Freeman (saurik) */ /* @@ -172,6 +172,7 @@ static BOOL (*_GSFontGetUseLegacyFontMetrics)(); bool Debug_ = false; bool Engineer_ = false; +bool SummerBoard_ = true; static UIImage *(*_UIApplicationImageWithName)(NSString *name); static UIImage *(*_UIImageAtPath)(NSString *name, NSBundle *path); @@ -239,7 +240,7 @@ static NSString *$pathForFile$inBundle$(NSString *file, NSBundle *bundle, bool u [names addObject:[NSString stringWithFormat:@"Bundles/com.apple.MobileSMS/%@", file]]; else if ([identifier isEqualToString:@"com.apple.calculator"]) [names addObject:[NSString stringWithFormat:@"Files/Applications/Calculator.app/%@", file]]; - else if (![identifier isEqualToString:@"com.apple.springboard"]); + else if (![identifier isEqualToString:@"com.apple.springboard"] || !SummerBoard_); remapResourceName(@"FSO_BG.png", @"StatusBar") remapResourceName(@"SBDockBG.png", @"Dock") remapResourceName(@"SBWeatherCelsius.png", @"Icons/Weather") @@ -261,18 +262,25 @@ static NSString *$pathForIcon$(SBApplication *self) { NSMutableArray *names = [NSMutableArray arrayWithCapacity:8]; + /* XXX: I might need to keep this for backwards compatibility if (identifier != nil) [names addObject:[NSString stringWithFormat:@"Bundles/%@/icon.png", identifier]]; if (folder != nil) - [names addObject:[NSString stringWithFormat:@"Folders/%@/icon.png", folder]]; + [names addObject:[NSString stringWithFormat:@"Folders/%@/icon.png", folder]]; */ #define testForIcon(Name) \ if (NSString *name = Name) \ [names addObject:[NSString stringWithFormat:@"Icons/%@.png", name]]; + if (![didentifier isEqualToString:identifier]) + testForIcon(didentifier); + testForIcon(identifier); testForIcon(dname); + if ([identifier isEqualToString:@"com.apple.MobileSMS"]) + testForIcon(@"SMS"); + if (didentifier != nil) { testForIcon([English_ objectForKey:didentifier]); @@ -284,6 +292,7 @@ static NSString *$pathForIcon$(SBApplication *self) { if (NSString *path = $getTheme$(names)) return path; + return nil; } @@ -742,7 +751,7 @@ MSHook(id, SBUIController$init, SBUIController *self, SEL sel) { [controller_ play:&error]; #elif UseMPMoviePlayerController NSURL *url([NSURL fileURLWithPath:mp4]); - MPMoviePlayerController *controller = [[MPMoviePlayerController alloc] initWithContentURL:url]; + MPMoviePlayerController *controller = [[$MPMoviePlayerController alloc] initWithContentURL:url]; controller.movieControlMode = MPMovieControlModeHidden; [controller play]; #else @@ -824,7 +833,6 @@ MSHook(id, SBUIController$init, SBUIController *self, SEL sel) { } [content addSubview:layer]; - WBLogHierarchy(_window); return self; } @@ -920,6 +928,7 @@ WBDelegate(time_) } - (id) initWithBadge:(NSString *)badge; +- (NSString *) description; @end @@ -935,6 +944,10 @@ WBDelegate(time_) return self; } +- (NSString *) description { + return [badge_ description]; +} + WBDelegate(badge_) - (CGSize) drawAtPoint:(CGPoint)point forWidth:(float)width withFont:(UIFont *)font lineBreakMode:(int)mode { @@ -1263,10 +1276,6 @@ MSHook(void, TranscriptController$loadView, mSMSMessageTranscriptController *sel [table setBackgroundColor:[UIColor clearColor]]; [placard insertSubview:background belowSubview:table]; } - - WBLogHierarchy(placard); - - [placard performSelector:@selector(wb$logHierarchy) withObject:nil afterDelay:10]; } } @@ -1281,24 +1290,22 @@ MSHook(UIImage *, _UIImageWithName, NSString *name) { NSNumber *key([NSNumber numberWithInt:id]); UIImage *image = [UIImages_ objectForKey:key]; if (image != nil) - return reinterpret_cast(image) == [NSNull null] ? nil : image; + return reinterpret_cast(image) == [NSNull null] ? _UISharedImageWithIdentifier(id) : image; if (NSString *path = $pathForFile$inBundle$(name, _UIKitBundle(), true)) { image = [[UIImage alloc] initWithContentsOfFile:path cache:true]; if (image != nil) [image autorelease]; } - if (image == nil) - image = _UISharedImageWithIdentifier(id); [UIImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast(image)) forKey:key]; - return image; + return image == nil ? _UISharedImageWithIdentifier(id) : image; } } MSHook(UIImage *, _UIImageWithNameInDomain, NSString *name, NSString *domain) { - NSString *key = [NSString stringWithFormat:@"D:%zu%@%@", [domain length], domain, name]; - UIImage *image = [PathImages_ objectForKey:key]; + NSString *key([NSString stringWithFormat:@"D:%zu%@%@", [domain length], domain, name]); + UIImage *image([PathImages_ objectForKey:key]); if (image != nil) - return reinterpret_cast(image) == [NSNull null] ? nil : image; + return reinterpret_cast(image) == [NSNull null] ? __UIImageWithNameInDomain(name, domain) : image; if (Debug_) NSLog(@"WB:Debug: UIImageWithNameInDomain(\"%@\", \"%@\")", name, domain); if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Domains/%@/%@", domain, name]])) { @@ -1306,10 +1313,8 @@ MSHook(UIImage *, _UIImageWithNameInDomain, NSString *name, NSString *domain) { if (image != nil) [image autorelease]; } - if (image == nil) - image = __UIImageWithNameInDomain(name, domain); [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast(image)) forKey:key]; - return image; + return image == nil ? __UIImageWithNameInDomain(name, domain) : image; } MSHook(GSFontRef, GSFontCreateWithName, const char *name, GSFontSymbolicTraits traits, float size) { @@ -1390,7 +1395,7 @@ static void dlset(Type_ &function, const char *name) { } extern "C" void WBInitialize() { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]); NSString *identifier([[NSBundle mainBundle] bundleIdentifier]); @@ -1445,8 +1450,8 @@ extern "C" void WBInitialize() { _UIImage$defaultDesktopImage = MSHookMessage(object_getClass($UIImage), @selector(defaultDesktopImage), &$UIImage$defaultDesktopImage); - //WBRename("UINavigationBar", @selector(initWithCoder:", (IMP) &UINavigationBar$initWithCoder$); - //WBRename("UINavigationBarBackground", @selector(initWithFrame:withBarStyle:withTintColor:", (IMP) &UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$); + //WBRename("UINavigationBar", @selector(initWithCoder:), (IMP) &UINavigationBar$initWithCoder$); + //WBRename("UINavigationBarBackground", @selector(initWithFrame:withBarStyle:withTintColor:), (IMP) &UINavigationBarBackground$initWithFrame$withBarStyle$withTintColor$); _UINavigationBar$setBarStyle$ = MSHookMessage($UINavigationBar, @selector(setBarStyle:), &$UINavigationBar$setBarStyle$); _UIToolbar$setBarStyle$ = MSHookMessage($UIToolbar, @selector(setBarStyle:), &$UIToolbar$setBarStyle$); @@ -1460,30 +1465,31 @@ extern "C" void WBInitialize() { themes_ = [[NSMutableArray alloc] initWithCapacity:8]; - if (NSDictionary *settings = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"/User/Library/Preferences/com.saurik.WinterBoard.plist"]]) { - [settings autorelease]; - - if (NSNumber *debug = [settings objectForKey:@"Debug"]) - Debug_ = [debug boolValue]; + if (NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"/User/Library/Preferences/com.saurik.WinterBoard.plist"]]) { + if (NSNumber *value = [settings objectForKey:@"SummerBoard"]) + SummerBoard_ = [value boolValue]; + if (NSNumber *value = [settings objectForKey:@"Debug"]) + Debug_ = [value boolValue]; - NSArray *themes = [settings objectForKey:@"Themes"]; + NSArray *themes([settings objectForKey:@"Themes"]); if (themes == nil) if (NSString *theme = [settings objectForKey:@"Theme"]) themes = [NSArray arrayWithObject:[NSDictionary dictionaryWithObjectsAndKeys: theme, @"Name", [NSNumber numberWithBool:true], @"Active", nil]]; + if (themes != nil) for (NSDictionary *theme in themes) { - NSNumber *active = [theme objectForKey:@"Active"]; + NSNumber *active([theme objectForKey:@"Active"]); if (![active boolValue]) continue; - NSString *name = [theme objectForKey:@"Name"]; + NSString *name([theme objectForKey:@"Name"]); if (name == nil) continue; - NSString *theme = nil; + NSString *theme(nil); #define testForTheme(format...) \ if (theme == nil) { \ @@ -1497,18 +1503,17 @@ extern "C" void WBInitialize() { testForTheme(@"/Library/Themes/%@.theme", name) testForTheme(@"/Library/Themes/%@", name) testForTheme(@"%@/Library/SummerBoard/Themes/%@", NSHomeDirectory(), name) + } } Info_ = [[NSMutableDictionary dictionaryWithCapacity:16] retain]; for (NSString *theme in themes_) - if (NSDictionary *info = [[NSDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/Info.plist", theme]]) { - [info autorelease]; + if (NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"%@/Info.plist", theme]]) for (NSString *key in [info allKeys]) if ([Info_ objectForKey:key] == nil) [Info_ setObject:[info objectForKey:key] forKey:key]; - } bool sms($getTheme$([NSArray arrayWithObjects:@"SMSBackground.png", @"SMSBackground.jpg", nil]) != nil); @@ -1542,12 +1547,15 @@ extern "C" void WBInitialize() { NULL, &ChangeWallpaper, (CFStringRef) @"com.saurik.winterboard.lockbackground", NULL, 0 ); - NSBundle *MediaPlayer = [NSBundle bundleWithPath:@"/System/Library/Frameworks/MediaPlayer.framework"]; - if (MediaPlayer != nil) - [MediaPlayer load]; + if ($getTheme$([NSArray arrayWithObject:@"Wallpaper.mp4"]) != nil) { + NSBundle *MediaPlayer([NSBundle bundleWithPath:@"/System/Library/Frameworks/MediaPlayer.framework"]); + if (MediaPlayer != nil) + [MediaPlayer load]; + + $MPMoviePlayerController = objc_getClass("MPMoviePlayerController"); + $MPVideoView = objc_getClass("MPVideoView"); + } - $MPMoviePlayerController = objc_getClass("MPMoviePlayerController"); - $MPVideoView = objc_getClass("MPVideoView"); $WebCoreFrameBridge = objc_getClass("WebCoreFrameBridge"); $SBApplication = objc_getClass("SBApplication"); @@ -1574,8 +1582,11 @@ extern "C" void WBInitialize() { WBRename(WebCoreFrameBridge, renderedSizeOfNode:constrainedToWidth:, renderedSizeOfNode$constrainedToWidth$); - WBRename(SBApplication, pathForIcon, pathForIcon); - WBRename(SBApplicationIcon, icon, icon); + if (SummerBoard_) { + WBRename(SBApplication, pathForIcon, pathForIcon); + WBRename(SBApplicationIcon, icon, icon); + } + WBRename(SBBookmarkIcon, icon, icon); WBRename(SBButtonBar, didMoveToSuperview, didMoveToSuperview); WBRename(SBCalendarIconContentsView, drawRect:, drawRect$); @@ -1612,7 +1623,9 @@ extern "C" void WBInitialize() { WBRename(SBStatusBarOperatorNameView, setOperatorName:fullSize:, setOperatorName$fullSize$); WBRename(SBStatusBarTimeView, drawRect:, drawRect$); - English_ = [[NSDictionary alloc] initWithContentsOfFile:@"/System/Library/CoreServices/SpringBoard.app/English.lproj/LocalizedApplicationNames.strings"]; + if (SummerBoard_) + English_ = [[NSDictionary alloc] initWithContentsOfFile:@"/System/Library/CoreServices/SpringBoard.app/English.lproj/LocalizedApplicationNames.strings"]; + Cache_ = [[NSMutableDictionary alloc] initWithCapacity:64]; }