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 *path([NSString stringWithFormat:@"%@/Library/Caches/com.apple.mobile.installation.plist", NSHomeDirectory()]);
42 Class $LSApplicationWorkspace(objc_getClass("LSApplicationWorkspace"));
43 LSApplicationWorkspace *workspace($LSApplicationWorkspace == nil ? nil : [$LSApplicationWorkspace defaultWorkspace]);
45 if (NSMutableDictionary *cache = [NSMutableDictionary dictionaryWithContentsOfFile:path]) {
46 NSFileManager *manager = [NSFileManager defaultManager];
49 NSMutableArray *bundles([NSMutableArray arrayWithCapacity:16]);
51 id system = [cache objectForKey:@"System"];
55 [system removeAllObjects];
57 if (NSArray *apps = [manager contentsOfDirectoryAtPath:@"/Applications" error:&error]) {
58 for (NSString *app in apps)
59 if ([app hasSuffix:@".app"]) {
60 NSString *path = [@"/Applications" stringByAppendingPathComponent:app];
61 NSString *plist = [path stringByAppendingPathComponent:@"Info.plist"];
63 if (NSMutableDictionary *info = [NSMutableDictionary dictionaryWithContentsOfFile:plist]) {
64 if (NSString *bundle = [info objectForKey:@"CFBundleIdentifier"]) {
65 [bundles addObject:path];
66 [info setObject:path forKey:@"Path"];
67 [info setObject:@"System" forKey:@"ApplicationType"];
68 [system addInfoDictionary:info];
70 fprintf(stderr, "%s missing CFBundleIdentifier", [app UTF8String]);
75 [cache writeToFile:path atomically:YES];
78 for (NSString *bundle in bundles) {
79 [workspace unregisterApplication:[NSURL fileURLWithPath:bundle]];
80 [workspace registerApplication:[NSURL fileURLWithPath:bundle]];
84 fprintf(stderr, "%s\n", error == nil ? strerror(errno) : [[error localizedDescription] UTF8String]);
85 } else fprintf(stderr, "cannot open cache file. incorrect user?\n");
87 notify_post("com.apple.mobile.application_installed");