+#define Cache_ "/User/Library/Caches/com.apple.mobile.installation.plist"
+
+ if (NSMutableDictionary *cache = [[NSDictionary alloc] initWithContentsOfFile:@ Cache_]) {
+ [cache autorelease];
+
+ NSFileManager *manager = [NSFileManager defaultManager];
+ id error = nil;
+
+ NSMutableDictionary *system = [cache objectForKey:@"System"];
+ if (system == nil)
+ goto error;
+
+ struct stat info;
+ if (stat(Cache_, &info) == -1)
+ goto error;
+
+ [system removeAllObjects];
+
+ if (NSArray *apps = [manager contentsOfDirectoryAtPath:@"/Applications" error:&error])
+ for (NSString *app in apps)
+ if ([app hasSuffix:@".app"]) {
+ NSString *path = [@"/Applications" stringByAppendingPathComponent:app];
+ NSString *plist = [path stringByAppendingPathComponent:@"Info.plist"];
+ if (NSMutableDictionary *info = [[NSMutableDictionary alloc] initWithContentsOfFile:plist]) {
+ [info autorelease];
+ [info setObject:path forKey:@"Path"];
+ [info setObject:@"System" forKey:@"ApplicationType"];
+ NSString *bundle = [info objectForKey:@"CFBundleIdentifier"];
+ [system setObject:info forKey:bundle];
+ }
+ }
+ else goto error;
+
+ [cache writeToFile:@Cache_ atomically:YES];
+
+ if (chown(Cache_, info.st_uid, info.st_gid) == -1)
+ goto error;
+ if (chmod(Cache_, info.st_mode) == -1)
+ goto error;
+
+ if (false) error:
+ fprintf(stderr, "%s\n", error == nil ? strerror(errno) : [[error localizedDescription] UTF8String]);
+ }
+