+// -[NSBundle wb$bundleWithFile] {{{
+@interface NSBundle (WinterBoard)
++ (NSBundle *) wb$bundleWithFile:(NSString *)path;
+@end
+
+@implementation NSBundle (WinterBoard)
+
++ (NSBundle *) wb$bundleWithFile:(NSString *)path {
+ path = [path stringByDeletingLastPathComponent];
+ if (path == nil || [path length] == 0 || [path isEqualToString:@"/"])
+ return nil;
+
+ NSBundle *bundle([Bundles_ objectForKey:path]);
+ if (reinterpret_cast<id>(bundle) == [NSNull null])
+ return nil;
+ else if (bundle == nil) {
+ if ([Manager_ fileExistsAtPath:[path stringByAppendingPathComponent:@"Info.plist"]])
+ bundle = [NSBundle bundleWithPath:path];
+ if (bundle == nil)
+ bundle = [NSBundle wb$bundleWithFile:path];
+ if (Debug_)
+ NSLog(@"WB:Debug:PathBundle(%@, %@)", path, bundle);
+ [Bundles_ setObject:(bundle == nil ? [NSNull null] : reinterpret_cast<id>(bundle)) forKey:path];
+ }
+
+ return bundle;
+}
+
+@end
+// }}}
+// -[NSString wb$themedPath] {{{
+@interface NSString (WinterBoard)
+- (NSString *) wb$themedPath;
+@end
+
+@implementation NSString (WinterBoard)
+
+- (NSString *) wb$themedPath {
+ if (Debug_)
+ NSLog(@"WB:Debug:Bypass(\"%@\")", self);
+
+ if (NSBundle *bundle = [NSBundle wb$bundleWithFile:self]) {
+ NSString *file([self stringByResolvingSymlinksInPath]);
+ NSString *prefix([[bundle bundlePath] stringByResolvingSymlinksInPath]);
+ if ([file hasPrefix:prefix]) {
+ NSUInteger length([prefix length]);
+ if (length != [file length])
+ if (NSString *path = $pathForFile$inBundle$([file substringFromIndex:(length + 1)], bundle, false))
+ return path;
+ }
+ }
+
+ return self;
+}
+
+@end
+// }}}
+
+void WBLogRect(const char *tag, struct CGRect rect) {
+ NSLog(@"%s:{%f,%f+%f,%f}", tag, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
+}
+
+void WBLogHierarchy(UIView *view, unsigned index = 0, unsigned indent = 0) {
+ CGRect frame([view frame]);
+ NSLog(@"%*s|%2d:%p:%s : {%f,%f+%f,%f} (%@)", indent * 3, "", index, view, class_getName([view class]), frame.origin.x, frame.origin.y, frame.size.width, frame.size.height, [view backgroundColor]);
+ index = 0;
+ for (UIView *child in [view subviews])
+ WBLogHierarchy(child, index++, indent + 1);
+}
+
+UIImage *$cacheForImage$(UIImage *image) {
+ 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 *cache([UIImage imageWithCGImage:ref]);
+ CGImageRelease(ref);
+
+ return cache;
+}
+
+/*MSHook(id, SBImageCache$initWithName$forImageWidth$imageHeight$initialCapacity$, SBImageCache *self, SEL sel, NSString *name, unsigned width, unsigned height, unsigned capacity) {
+ //if ([name isEqualToString:@"icons"]) return nil;
+ return _SBImageCache$initWithName$forImageWidth$imageHeight$initialCapacity$(self, sel, name, width, height, capacity);
+}*/
+
+MSHook(void, SBIconModel$cacheImageForIcon$, SBIconModel *self, SEL sel, SBIcon *icon) {