1 #import <Foundation/Foundation.h>
8 @interface NSMutableArray (Cydia)
9 - (void) addInfoDictionary:(NSDictionary *)info;
12 @implementation NSMutableArray (Cydia)
14 - (void) addInfoDictionary:(NSDictionary *)info {
15 [self addObject:info];
20 @interface NSMutableDictionary (Cydia)
21 - (void) addInfoDictionary:(NSDictionary *)info;
24 @implementation NSMutableDictionary (Cydia)
26 - (void) addInfoDictionary:(NSDictionary *)info {
27 NSString *bundle = [info objectForKey:@"CFBundleIdentifier"];
28 [self setObject:info forKey:bundle];
34 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
36 NSString *path([NSString stringWithFormat:@"%@/Library/Caches/com.apple.mobile.installation.plist", NSHomeDirectory()]);
38 if (NSMutableDictionary *cache = [[NSMutableDictionary alloc] initWithContentsOfFile:path]) {
41 NSFileManager *manager = [NSFileManager defaultManager];
44 id system = [cache objectForKey:@"System"];
48 [system removeAllObjects];
50 if (NSArray *apps = [manager contentsOfDirectoryAtPath:@"/Applications" error:&error]) {
51 for (NSString *app in apps)
52 if ([app hasSuffix:@".app"]) {
53 NSString *path = [@"/Applications" stringByAppendingPathComponent:app];
54 NSString *plist = [path stringByAppendingPathComponent:@"Info.plist"];
55 if (NSMutableDictionary *info = [[NSMutableDictionary alloc] initWithContentsOfFile:plist]) {
57 if ([info objectForKey:@"CFBundleIdentifier"] == nil)
58 fprintf(stderr, "%s missing CFBundleIdentifier", [app UTF8String]);
60 [info setObject:path forKey:@"Path"];
61 [info setObject:@"System" forKey:@"ApplicationType"];
62 [system addInfoDictionary:info];
68 [cache writeToFile:path atomically:YES];
71 fprintf(stderr, "%s\n", error == nil ? strerror(errno) : [[error localizedDescription] UTF8String]);
72 } else fprintf(stderr, "cannot open cache file. incorrect user?\n");
74 notify_post("com.apple.mobile.application_installed");