📄 library.mm
字号:
/* WinterBoard - Theme Manager for the iPhone * Copyright (C) 2008 Jay Freeman (saurik)*//* * Redistribution and use in source and binary * forms, with or without modification, are permitted * provided that the following conditions are met: * * 1. Redistributions of source code must retain the * above copyright notice, this list of conditions * and the following disclaimer. * 2. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions * and the following disclaimer in the documentation * and/or other materials provided with the * distribution. * 3. The name of the author may not be used to endorse * or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/#define _trace() NSLog(@"WB:_trace(%u)", __LINE__);#define _transient#import <CoreFoundation/CoreFoundation.h>#import <Foundation/Foundation.h>#import <CoreGraphics/CoreGraphics.h>#include <substrate.h>#import <UIKit/UIKit.h>#import <SpringBoard/SBApplication.h>#import <SpringBoard/SBApplicationIcon.h>#import <SpringBoard/SBAppWindow.h>#import <SpringBoard/SBBookmarkIcon.h>#import <SpringBoard/SBButtonBar.h>#import <SpringBoard/SBCalendarIconContentsView.h>#import <SpringBoard/SBContentLayer.h>#import <SpringBoard/SBIconController.h>#import <SpringBoard/SBIconLabel.h>#import <SpringBoard/SBSlidingAlertDisplay.h>#import <SpringBoard/SBStatusBarContentsView.h>#import <SpringBoard/SBStatusBarController.h>#import <SpringBoard/SBStatusBarOperatorNameView.h>#import <SpringBoard/SBStatusBarTimeView.h>#import <SpringBoard/SBUIController.h>#import <MobileSMS/mSMSMessageTranscriptController.h>#import <MediaPlayer/MPVideoView.h>#import <MediaPlayer/MPVideoView-PlaybackControl.h>#import <CoreGraphics/CGGeometry.h>extern "C" void __clear_cache (char *beg, char *end);Class $MPVideoView;@interface NSDictionary (WinterBoard)- (UIColor *) colorForKey:(NSString *)key;- (BOOL) boolForKey:(NSString *)key;@end@implementation NSDictionary (WinterBoard)- (UIColor *) colorForKey:(NSString *)key { NSString *value = [self objectForKey:key]; if (value == nil) return nil; /* XXX: incorrect */ return nil;}- (BOOL) boolForKey:(NSString *)key { if (NSString *value = [self objectForKey:key]) return [value boolValue]; return false;}@endbool Debug_ = false;bool Engineer_ = false;@protocol WinterBoard- (void) wb$setOperatorName:(NSString *)name fullSize:(BOOL)full;- (NSString *) wb$operatorNameStyle;- (void) wb$loadView;- (NSString *) wb$localizedStringForKey:(NSString *)key value:(NSString *)value table:(NSString *)table;- (id) wb$initWithBadge:(id)badge;- (void) wb$cacheImageForIcon:(SBIcon *)icon;- (UIImage *) wb$getCachedImagedForIcon:(SBIcon *)icon;- (CGSize) wb$renderedSizeOfNode:(id)node constrainedToWidth:(float)width;- (void *) _node;- (void) wb$updateDesktopImage:(UIImage *)image;- (UIImage *) wb$defaultDesktopImage;- (NSString *) wb$pathForIcon;- (NSString *) wb$pathForResource:(NSString *)resource ofType:(NSString *)type;- (id) wb$init;- (id) wb$layer;- (id) wb$initWithSize:(CGSize)size;- (id) wb$initWithSize:(CGSize)size label:(NSString *)label;- (id) wb$initWithFrame:(CGRect)frame;- (id) wb$initWithCoder:(NSCoder *)coder;- (void) wb$setFrame:(CGRect)frame;- (void) wb$drawRect:(CGRect)rect;- (void) wb$setBackgroundColor:(id)color;- (void) wb$setAlpha:(float)value;- (void) wb$setBarStyle:(int)style;- (id) wb$initWithFrame:(CGRect)frame withBarStyle:(int)style withTintColor:(UIColor *)color;- (void) wb$setOpaque:(BOOL)opaque;- (void) wb$setInDock:(BOOL)docked;- (void) wb$didMoveToSuperview;+ (UIImage *) wb$imageNamed:(NSString *)name inBundle:(NSBundle *)bundle;+ (UIImage *) wb$applicationImageNamed:(NSString *)name;- (NSDictionary *) wb$infoDictionary;- (UIImage *) wb$icon;- (void) wb$appendIconList:(SBIconList *)list;- (id) wb$initWithStatusBar:(id)bar mode:(int)mode;- (id) wb$initWithMode:(int)mode orientation:(int)orientation;- (id) wb$imageAtPath:(NSString *)path;- (id) wb$initWithContentsOfFile:(NSString *)file;- (id) wb$initWithContentsOfFile:(NSString *)file cache:(BOOL)cache;- (void) wb$setStatusBarMode:(int)mode orientation:(int)orientation duration:(float)duration fenceID:(int)id animation:(int)animation;@endstatic NSMutableDictionary *UIImages_;static NSMutableDictionary *PathImages_;static NSMutableDictionary *Cache_;static NSMutableDictionary *Strings_;static NSFileManager *Manager_;static NSDictionary *English_;static NSMutableDictionary *Info_;static NSMutableArray *themes_;static NSString *$getTheme$(NSArray *files, bool parent = false) { if (Debug_) NSLog(@"WB:Debug: %@", [files description]); for (NSString *theme in themes_) for (NSString *file in files) { NSString *path([NSString stringWithFormat:@"%@/%@", theme, file]); if ([Manager_ fileExistsAtPath:path]) return parent ? theme : path; } return nil;}static NSString *$pathForIcon$(SBApplication<WinterBoard> *self) { NSString *identifier = [self bundleIdentifier]; NSString *path = [self path]; NSString *folder = [path lastPathComponent]; NSString *dname = [self displayName]; NSString *didentifier = [self displayIdentifier]; if (Debug_) NSLog(@"WB:Debug: [SBApplication(%@:%@:%@:%@) pathForIcon]", identifier, folder, dname, didentifier); NSMutableArray *names = [NSMutableArray arrayWithCapacity:8]; if (identifier != nil) [names addObject:[NSString stringWithFormat:@"Bundles/%@/icon.png", identifier]]; if (folder != nil) [names addObject:[NSString stringWithFormat:@"Folders/%@/icon.png", folder]]; #define testForIcon(Name) \ if (NSString *name = Name) \ [names addObject:[NSString stringWithFormat:@"Icons/%@.png", name]]; testForIcon(identifier); testForIcon(dname); if (didentifier != nil) { testForIcon([English_ objectForKey:didentifier]); NSArray *parts = [didentifier componentsSeparatedByString:@"-"]; if ([parts count] != 1) if (NSDictionary *english = [[[NSDictionary alloc] initWithContentsOfFile:[path stringByAppendingString:@"/English.lproj/UIRoleDisplayNames.strings"]] autorelease]) testForIcon([english objectForKey:[parts lastObject]]); } if (NSString *path = $getTheme$(names)) return path; return nil;}static void SBIconModel$cacheImageForIcon$(SBIconModel<WinterBoard> *self, SEL sel, SBIcon *icon) { [self wb$cacheImageForIcon:icon]; NSString *key([icon displayIdentifier]); if (UIImage *image = [icon icon]) { CGColorSpaceRef space(CGColorSpaceCreateDeviceRGB()); CGRect rect = {CGPointMake(1, 1), [image size]}; CGSize size = {rect.size.width + 2, rect.size.height + 2}; CGContextRef context(CGBitmapContextCreate(NULL, size.width, size.height, 8, 4 * size.width, space, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst)); CGColorSpaceRelease(space); CGContextDrawImage(context, rect, [image CGImage]); CGImageRef ref(CGBitmapContextCreateImage(context)); CGContextRelease(context); UIImage *image([UIImage imageWithCGImage:ref]); CGImageRelease(ref); [Cache_ setObject:image forKey:key]; }}static UIImage *SBIconModel$getCachedImagedForIcon$(SBIconModel<WinterBoard> *self, SEL sel, SBIcon *icon) { NSString *key([icon displayIdentifier]); if (UIImage *image = [Cache_ objectForKey:key]) return image; else return [self wb$getCachedImagedForIcon:icon];}static UIImage *SBApplicationIcon$icon(SBApplicationIcon<WinterBoard> *self, SEL sel) { if (![Info_ boolForKey:@"ComposeStoreIcons"]) if (NSString *path = $pathForIcon$([self application])) return [UIImage imageWithContentsOfFile:path]; return [self wb$icon];}static UIImage *SBBookmarkIcon$icon(SBBookmarkIcon<WinterBoard> *self, SEL sel) { if (Debug_) NSLog(@"WB:Debug:Bookmark(%@:%@)", [self displayIdentifier], [self displayName]); if (NSString *path = $getTheme$([NSArray arrayWithObject:[NSString stringWithFormat:@"Icons/%@.png", [self displayName]]])) return [UIImage imageWithContentsOfFile:path]; return [self wb$icon];}static NSString *SBApplication$pathForIcon(SBApplication<WinterBoard> *self, SEL sel) { if (NSString *path = $pathForIcon$(self)) return path; return [self wb$pathForIcon];}static NSString *$pathForFile$inBundle$(NSString *file, NSBundle<WinterBoard> *bundle, bool ui) { NSString *identifier = [bundle bundleIdentifier]; NSMutableArray *names = [NSMutableArray arrayWithCapacity:8]; if (identifier != nil) [names addObject:[NSString stringWithFormat:@"Bundles/%@/%@", identifier, file]]; if (NSString *folder = [[bundle bundlePath] lastPathComponent]) [names addObject:[NSString stringWithFormat:@"Folders/%@/%@", folder, file]]; if (ui) [names addObject:[NSString stringWithFormat:@"UIImages/%@", file]]; #define remapResourceName(oldname, newname) \ else if ([file isEqualToString:oldname]) \ [names addObject:[NSString stringWithFormat:@"%@.png", newname]]; \ if (identifier == nil); else if ([identifier isEqualToString:@"com.apple.calculator"]) [names addObject:[NSString stringWithFormat:@"Files/Applications/Calculator.app/%@", file]]; else if (![identifier isEqualToString:@"com.apple.springboard"]); remapResourceName(@"FSO_BG.png", @"StatusBar") remapResourceName(@"SBDockBG.png", @"Dock") remapResourceName(@"SBWeatherCelsius.png", @"Icons/Weather") if (NSString *path = $getTheme$(names)) return path; return nil;}static UIImage *CachedImageAtPath(NSString *path) { UIImage *image = [PathImages_ objectForKey:path]; if (image != nil) return reinterpret_cast<id>(image) == [NSNull null] ? nil : image; image = [[UIImage alloc] wb$initWithContentsOfFile:path cache:true]; if (image != nil) image = [image autorelease]; [PathImages_ setObject:(image == nil ? [NSNull null] : reinterpret_cast<id>(image)) forKey:path]; return image;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -