]> git.saurik.com Git - uikittools.git/blob - uicache.mm
UIKit Tools is not part of Telesphoreo.
[uikittools.git] / uicache.mm
1 #import <Foundation/Foundation.h>
2
3 #include <notify.h>
4 #include <sys/types.h>
5 #include <sys/stat.h>
6 #include <unistd.h>
7
8 @interface NSMutableArray (Cydia)
9 - (void) addInfoDictionary:(NSDictionary *)info;
10 @end
11
12 @implementation NSMutableArray (Cydia)
13
14 - (void) addInfoDictionary:(NSDictionary *)info {
15 [self addObject:info];
16 }
17
18 @end
19
20 @interface NSMutableDictionary (Cydia)
21 - (void) addInfoDictionary:(NSDictionary *)info;
22 @end
23
24 @implementation NSMutableDictionary (Cydia)
25
26 - (void) addInfoDictionary:(NSDictionary *)info {
27 NSString *bundle = [info objectForKey:@"CFBundleIdentifier"];
28 [self setObject:info forKey:bundle];
29 }
30
31 @end
32
33 int main() {
34 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
35
36 NSString *path([NSString stringWithFormat:@"%@/Library/Caches/com.apple.mobile.installation.plist", NSHomeDirectory()]);
37
38 if (NSMutableDictionary *cache = [[NSMutableDictionary alloc] initWithContentsOfFile:path]) {
39 [cache autorelease];
40
41 NSFileManager *manager = [NSFileManager defaultManager];
42 NSError *error = nil;
43
44 id system = [cache objectForKey:@"System"];
45 if (system == nil)
46 goto error;
47
48 [system removeAllObjects];
49
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]) {
56 [info autorelease];
57 if ([info objectForKey:@"CFBundleIdentifier"] == nil)
58 fprintf(stderr, "%s missing CFBundleIdentifier", [app UTF8String]);
59 else {
60 [info setObject:path forKey:@"Path"];
61 [info setObject:@"System" forKey:@"ApplicationType"];
62 [system addInfoDictionary:info];
63 }
64 }
65 }
66 } else goto error;
67
68 [cache writeToFile:path atomically:YES];
69
70 if (false) error:
71 fprintf(stderr, "%s\n", error == nil ? strerror(errno) : [[error localizedDescription] UTF8String]);
72 } else fprintf(stderr, "cannot open cache file. incorrect user?\n");
73
74 notify_post("com.apple.mobile.application_installed");
75
76 [pool release];
77
78 return 0;
79 }