Skip to content

Commit

Permalink
Recursively walk into /System/Library and extract all png
Browse files Browse the repository at this point in the history
  • Loading branch information
0xced committed Aug 4, 2010
1 parent d0eccba commit 67e3566
Showing 1 changed file with 30 additions and 23 deletions.
53 changes: 30 additions & 23 deletions Classes/ArtworkViewController.m
Expand Up @@ -27,6 +27,23 @@ CGFloat UIScreen_scale(id self, SEL _cmd)
return 1.0;
}

static NSString *systemLibraryPath()
{
NSString *systemFrameworksPath = @"/System/Library/Frameworks";
for (NSBundle *framework in [NSBundle allFrameworks])
{
// So that it works on both simulator and device
NSString *frameworkName = [[framework bundlePath] lastPathComponent];
if ([frameworkName isEqualToString:@"Foundation.framework"])
{
systemFrameworksPath = [[framework bundlePath] stringByDeletingLastPathComponent];
break;
}
}
return [systemFrameworksPath stringByDeletingLastPathComponent];
}


@implementation ArtworkViewController

@synthesize progressView;
Expand Down Expand Up @@ -120,8 +137,12 @@ - (NSDictionary*) images
return images;
}

- (void) addImage:(UIImage *)image fileName:(NSString *)fileName framework:(NSString *)frameworkName
- (void) addImage:(UIImage *)image fileName:(NSString *)fileName bundleName:(NSString *)bundleName
{
for (UITableViewCell *cell in self.cells)
if ([cell.textLabel.text isEqualToString:fileName])
fileName = [bundleName stringByAppendingFormat:@"_%@", fileName];

UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ImageCell"] autorelease];
cell.textLabel.text = fileName;
cell.textLabel.font = [UIFont systemFontOfSize:12];
Expand All @@ -148,34 +169,20 @@ - (void) viewDidLoad
self.cells = [NSMutableArray array];

for (NSString *imageName in [[self.images allKeys] sortedArrayUsingSelector:@selector(compare:)])
[self addImage:[self.images objectForKey:imageName] fileName:imageName framework:@"UIKit"];
[self addImage:[self.images objectForKey:imageName] fileName:imageName bundleName:@"UIKit"];

if ([self isEmoji])
return;

NSString *frameworksPath = @"/System/Library/Frameworks";
for (NSBundle *framework in [NSBundle allFrameworks])
for (NSString *relativePath in [[NSFileManager defaultManager] enumeratorAtPath:systemLibraryPath()])
{
// So that it works on both simulator and device
NSString *frameworkName = [[framework bundlePath] lastPathComponent];
if ([frameworkName isEqualToString:@"Foundation.framework"])
if ([relativePath hasSuffix:@"png"] && [relativePath rangeOfString:@"@2x"].location == NSNotFound)
{
frameworksPath = [[framework bundlePath] stringByDeletingLastPathComponent];
break;
}
}

for (NSString *frameworkName in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:frameworksPath error:nil])
{
NSString *frameworkPath = [frameworksPath stringByAppendingPathComponent:frameworkName];
for (NSString *fileName in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:frameworkPath error:nil])
{
if ([fileName hasSuffix:@"png"] && [fileName rangeOfString:@"@2x"].location == NSNotFound)
{
NSString *filePath = [frameworkPath stringByAppendingPathComponent:fileName];
// TODO: workaround http://www.openradar.me/8225750
[self addImage:[UIImage imageWithContentsOfFile:filePath] fileName:fileName framework:[frameworkName stringByDeletingPathExtension]];
}
NSString *filePath = [systemLibraryPath() stringByAppendingPathComponent:relativePath];
NSString *bundlePath = [filePath stringByDeletingLastPathComponent];
NSString *bundleName = [[bundlePath lastPathComponent] stringByDeletingPathExtension];
// TODO: workaround http://www.openradar.me/8225750
[self addImage:[UIImage imageWithContentsOfFile:filePath] fileName:[filePath lastPathComponent] bundleName:bundleName];
}
}
}
Expand Down

0 comments on commit 67e3566

Please sign in to comment.