1 #import <Foundation/Foundation.h>
8 #include <objc/runtime.h>
10 #include <MobileCoreServices/LSApplicationWorkspace.h>
12 @interface NSMutableArray (Cydia)
13 - (void) addInfoDictionary:(NSDictionary *)info;
16 @implementation NSMutableArray (Cydia)
18 - (void) addInfoDictionary:(NSDictionary *)info {
19 [self addObject:info];
24 @interface NSMutableDictionary (Cydia)
25 - (void) addInfoDictionary:(NSDictionary *)info;
28 @implementation NSMutableDictionary (Cydia)
30 - (void) addInfoDictionary:(NSDictionary *)info {
31 NSString *bundle = [info objectForKey:@"CFBundleIdentifier"];
32 [self setObject:info forKey:bundle];
38 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
40 NSString *home(NSHomeDirectory());
41 NSString *path([NSString stringWithFormat:@"%@/Library/Caches/com.apple.mobile.installation.plist", home]);
43 Class $LSApplicationWorkspace(objc_getClass("LSApplicationWorkspace"));
44 LSApplicationWorkspace *workspace($LSApplicationWorkspace == nil ? nil : [$LSApplicationWorkspace defaultWorkspace]);
46 if (NSMutableDictionary *cache = [NSMutableDictionary dictionaryWithContentsOfFile:path]) {
47 NSFileManager *manager = [NSFileManager defaultManager];
50 NSMutableArray *bundles([NSMutableArray arrayWithCapacity:16]);
52 id system = [cache objectForKey:@"System"];
56 [system removeAllObjects];
58 if (NSArray *apps = [manager contentsOfDirectoryAtPath:@"/Applications" error:&error]) {
59 for (NSString *app in apps)
60 if ([app hasSuffix:@".app"]) {
61 NSString *path = [@"/Applications" stringByAppendingPathComponent:app];
62 NSString *plist = [path stringByAppendingPathComponent:@"Info.plist"];
64 if (NSMutableDictionary *info = [NSMutableDictionary dictionaryWithContentsOfFile:plist]) {
65 if (NSString *bundle = [info objectForKey:@"CFBundleIdentifier"]) {
66 [bundles addObject:path];
67 [info setObject:path forKey:@"Path"];
68 [info setObject:@"System" forKey:@"ApplicationType"];
69 [system addInfoDictionary:info];
71 fprintf(stderr, "%s missing CFBundleIdentifier", [app UTF8String]);
76 [cache writeToFile:path atomically:YES];
79 for (NSString *bundle in bundles) {
80 [workspace unregisterApplication:[NSURL fileURLWithPath:bundle]];
81 [workspace registerApplication:[NSURL fileURLWithPath:bundle]];
85 fprintf(stderr, "%s\n", error == nil ? strerror(errno) : [[error localizedDescription] UTF8String]);
86 } else fprintf(stderr, "cannot open cache file. incorrect user?\n");
88 unlink([[NSString stringWithFormat:@"%@/Library/Caches/com.apple.springboard-imagecache-icons"] UTF8String]);
89 unlink([[NSString stringWithFormat:@"%@/Library/Caches/com.apple.springboard-imagecache-icons.plist"] UTF8String]);
91 unlink([[NSString stringWithFormat:@"%@/Library/Caches/com.apple.springboard-imagecache-smallicons"] UTF8String]);
92 unlink([[NSString stringWithFormat:@"%@/Library/Caches/com.apple.springboard-imagecache-smallicons.plist"] UTF8String]);
94 system([[NSString stringWithFormat:@"rm -rf %@/Library/Caches/SpringBoardIconCache"] UTF8String]);
95 system([[NSString stringWithFormat:@"rm -rf %@/Library/Caches/SpringBoardIconCache-small"] UTF8String]);
97 system([[NSString stringWithFormat:@"rm -rf %@/Library/Caches/com.apple.IconsCache"] UTF8String]);
99 notify_post("com.apple.mobile.application_installed");