]> git.saurik.com Git - uikittools.git/blob - uiinstall.mm
Adding initial version of uiinstall for BigBoss.
[uikittools.git] / uiinstall.mm
1 @interface NSMutableArray (Cydia)
2 - (void) addInfoDictionary:(NSDictionary *)info;
3 @end
4
5 @implementation NSMutableArray (Cydia)
6
7 - (void) addInfoDictionary:(NSDictionary *)info {
8 [self addObject:info];
9 }
10
11 @end
12
13 @interface NSMutableDictionary (Cydia)
14 - (void) addInfoDictionary:(NSDictionary *)info;
15 @end
16
17 @implementation NSMutableDictionary (Cydia)
18
19 - (void) addInfoDictionary:(NSDictionary *)info {
20 NSString *bundle = [info objectForKey:@"CFBundleIdentifier"];
21 [self setObject:info forKey:bundle];
22 }
23
24 @end
25
26 #define Cache_ "/User/Library/Caches/com.apple.mobile.installation.plist"
27
28 int main() {
29 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
30
31 if (NSMutableDictionary *cache = [[NSMutableDictionary alloc] initWithContentsOfFile:@ Cache_]) {
32 [cache autorelease];
33
34 NSFileManager *manager = [NSFileManager defaultManager];
35 NSError *error = nil;
36
37 id system = [cache objectForKey:@"System"];
38 if (system == nil)
39 goto error;
40
41 struct stat info;
42 if (stat(Cache_, &info) == -1)
43 goto error;
44
45 [system removeAllObjects];
46
47 if (NSArray *apps = [manager contentsOfDirectoryAtPath:@"/Applications" error:&error]) {
48 for (NSString *app in apps)
49 if ([app hasSuffix:@".app"]) {
50 NSString *path = [@"/Applications" stringByAppendingPathComponent:app];
51 NSString *plist = [path stringByAppendingPathComponent:@"Info.plist"];
52 if (NSMutableDictionary *info = [[NSMutableDictionary alloc] initWithContentsOfFile:plist]) {
53 [info autorelease];
54 [info setObject:path forKey:@"Path"];
55 [info setObject:@"System" forKey:@"ApplicationType"];
56 [system addInfoDictionary:info];
57 }
58 }
59 } else goto error;
60
61 [cache writeToFile:@Cache_ atomically:YES];
62
63 if (chown(Cache_, info.st_uid, info.st_gid) == -1)
64 goto error;
65 if (chmod(Cache_, info.st_mode) == -1)
66 goto error;
67
68 if (false) error:
69 fprintf(stderr, "%s\n", error == nil ? strerror(errno) : [[error localizedDescription] UTF8String]);
70 }
71
72 notify_post("com.apple.mobile.application_installed");
73
74 [pool release];
75
76 return 0;
77 }