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];
37 int main(int argc, const char *argv[]) {
38 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
42 NSString *home(NSHomeDirectory());
43 NSString *path([NSString stringWithFormat:@"%@/Library/Caches/com.apple.mobile.installation.plist", home]);
45 Class $LSApplicationWorkspace(objc_getClass("LSApplicationWorkspace"));
46 LSApplicationWorkspace *workspace($LSApplicationWorkspace == nil ? nil : [$LSApplicationWorkspace defaultWorkspace]);
48 if (NSMutableDictionary *cache = [NSMutableDictionary dictionaryWithContentsOfFile:path]) {
49 NSFileManager *manager = [NSFileManager defaultManager];
52 NSMutableArray *bundles([NSMutableArray arrayWithCapacity:16]);
54 id system = [cache objectForKey:@"System"];
58 [system removeAllObjects];
60 if (NSArray *apps = [manager contentsOfDirectoryAtPath:@"/Applications" error:&error]) {
61 for (NSString *app in apps)
62 if ([app hasSuffix:@".app"]) {
63 NSString *path = [@"/Applications" stringByAppendingPathComponent:app];
64 NSString *plist = [path stringByAppendingPathComponent:@"Info.plist"];
66 if (NSMutableDictionary *info = [NSMutableDictionary dictionaryWithContentsOfFile:plist]) {
67 if ([info objectForKey:@"CFBundleIdentifier"] != nil) {
68 [bundles addObject:path];
69 [info setObject:path forKey:@"Path"];
70 [info setObject:@"System" forKey:@"ApplicationType"];
71 [system addInfoDictionary:info];
73 fprintf(stderr, "%s missing CFBundleIdentifier", [app UTF8String]);
78 [cache writeToFile:path atomically:YES];
81 for (NSString *bundle in bundles) {
82 [workspace unregisterApplication:[NSURL fileURLWithPath:bundle]];
83 [workspace registerApplication:[NSURL fileURLWithPath:bundle]];
87 fprintf(stderr, "%s\n", error == nil ? strerror(errno) : [[error localizedDescription] UTF8String]);
88 } else fprintf(stderr, "cannot open cache file. incorrect user?\n");
90 if (respring || kCFCoreFoundationVersionNumber >= 550.32) {
91 unlink([[NSString stringWithFormat:@"%@/Library/Caches/com.apple.springboard-imagecache-icons", home] UTF8String]);
92 unlink([[NSString stringWithFormat:@"%@/Library/Caches/com.apple.springboard-imagecache-icons.plist", home] UTF8String]);
94 unlink([[NSString stringWithFormat:@"%@/Library/Caches/com.apple.springboard-imagecache-smallicons", home] UTF8String]);
95 unlink([[NSString stringWithFormat:@"%@/Library/Caches/com.apple.springboard-imagecache-smallicons.plist", home] UTF8String]);
97 system([[NSString stringWithFormat:@"rm -rf %@/Library/Caches/SpringBoardIconCache", home] UTF8String]);
98 system([[NSString stringWithFormat:@"rm -rf %@/Library/Caches/SpringBoardIconCache-small", home] UTF8String]);
100 system([[NSString stringWithFormat:@"rm -rf %@/Library/Caches/com.apple.IconsCache", home] UTF8String]);
103 system("killall installd");
106 system("launchctl stop com.apple.SpringBoard");
108 notify_post("com.apple.mobile.application_installed");