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]);
93 unlink([[NSString stringWithFormat:@"%@/Library/Caches/com.apple.springboard-imagecache-smallicons", home] UTF8String]);
94 unlink([[NSString stringWithFormat:@"%@/Library/Caches/com.apple.springboard-imagecache-smallicons.plist", home] UTF8String]);
96 unlink([[NSString stringWithFormat:@"%@/Library/Caches/com.apple.SpringBoard.folderSwitcherLinen", home] UTF8String]);
97 unlink([[NSString stringWithFormat:@"%@/Library/Caches/com.apple.SpringBoard.notificationCenterLinen", home] UTF8String]);
99 unlink([[NSString stringWithFormat:@"%@/Library/Caches/com.apple.SpringBoard.folderSwitcherLinen.0", home] UTF8String]);
100 unlink([[NSString stringWithFormat:@"%@/Library/Caches/com.apple.SpringBoard.folderSwitcherLinen.1", home] UTF8String]);
101 unlink([[NSString stringWithFormat:@"%@/Library/Caches/com.apple.SpringBoard.folderSwitcherLinen.2", home] UTF8String]);
102 unlink([[NSString stringWithFormat:@"%@/Library/Caches/com.apple.SpringBoard.folderSwitcherLinen.3", home] UTF8String]);
104 system([[NSString stringWithFormat:@"rm -rf %@/Library/Caches/SpringBoardIconCache", home] UTF8String]);
105 system([[NSString stringWithFormat:@"rm -rf %@/Library/Caches/SpringBoardIconCache-small", home] UTF8String]);
106 system([[NSString stringWithFormat:@"rm -rf %@/Library/Caches/com.apple.IconsCache", home] UTF8String]);
107 system([[NSString stringWithFormat:@"rm -rf %@/Library/Caches/com.apple.newsstand", home] UTF8String]);
108 system([[NSString stringWithFormat:@"rm -rf %@/Library/Caches/com.apple.springboard.sharedimagecache", home] UTF8String]);
111 system("killall installd");
114 system("launchctl stop com.apple.SpringBoard");
116 notify_post("com.apple.mobile.application_installed");