]> git.saurik.com Git - uikittools.git/blame - uicache.mm
Unregister old apps.
[uikittools.git] / uicache.mm
CommitLineData
7fb7ce13
JF
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
020dfc54
JF
8#include <objc/runtime.h>
9
10#include <MobileCoreServices/LSApplicationWorkspace.h>
11
1094bdcb
JF
12@interface NSMutableArray (Cydia)
13- (void) addInfoDictionary:(NSDictionary *)info;
14@end
15
16@implementation NSMutableArray (Cydia)
17
18- (void) addInfoDictionary:(NSDictionary *)info {
19 [self addObject:info];
20}
21
22@end
23
24@interface NSMutableDictionary (Cydia)
25- (void) addInfoDictionary:(NSDictionary *)info;
26@end
27
28@implementation NSMutableDictionary (Cydia)
29
30- (void) addInfoDictionary:(NSDictionary *)info {
31 NSString *bundle = [info objectForKey:@"CFBundleIdentifier"];
32 [self setObject:info forKey:bundle];
33}
34
35@end
36
1094bdcb
JF
37int main() {
38 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
39
7fb7ce13
JF
40 NSString *path([NSString stringWithFormat:@"%@/Library/Caches/com.apple.mobile.installation.plist", NSHomeDirectory()]);
41
020dfc54
JF
42 Class $LSApplicationWorkspace(objc_getClass("LSApplicationWorkspace"));
43 LSApplicationWorkspace *workspace($LSApplicationWorkspace == nil ? nil : [$LSApplicationWorkspace defaultWorkspace]);
1094bdcb 44
020dfc54 45 if (NSMutableDictionary *cache = [NSMutableDictionary dictionaryWithContentsOfFile:path]) {
1094bdcb
JF
46 NSFileManager *manager = [NSFileManager defaultManager];
47 NSError *error = nil;
48
020dfc54
JF
49 NSMutableArray *bundles([NSMutableArray arrayWithCapacity:16]);
50
1094bdcb
JF
51 id system = [cache objectForKey:@"System"];
52 if (system == nil)
53 goto error;
54
1094bdcb
JF
55 [system removeAllObjects];
56
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"];
020dfc54
JF
62
63 if (NSMutableDictionary *info = [NSMutableDictionary dictionaryWithContentsOfFile:plist]) {
64 if (NSString *bundle = [info objectForKey:@"CFBundleIdentifier"]) {
65 [bundles addObject:path];
2a72f832
JF
66 [info setObject:path forKey:@"Path"];
67 [info setObject:@"System" forKey:@"ApplicationType"];
68 [system addInfoDictionary:info];
020dfc54
JF
69 } else
70 fprintf(stderr, "%s missing CFBundleIdentifier", [app UTF8String]);
1094bdcb
JF
71 }
72 }
73 } else goto error;
74
7fb7ce13 75 [cache writeToFile:path atomically:YES];
1094bdcb 76
020dfc54 77 if (workspace != nil)
5ac04f0f
JF
78 for (NSString *bundle in bundles) {
79 [workspace unregisterApplication:[NSURL fileURLWithPath:bundle]];
020dfc54 80 [workspace registerApplication:[NSURL fileURLWithPath:bundle]];
5ac04f0f 81 }
020dfc54 82
1094bdcb
JF
83 if (false) error:
84 fprintf(stderr, "%s\n", error == nil ? strerror(errno) : [[error localizedDescription] UTF8String]);
7fb7ce13 85 } else fprintf(stderr, "cannot open cache file. incorrect user?\n");
1094bdcb
JF
86
87 notify_post("com.apple.mobile.application_installed");
88
89 [pool release];
90
91 return 0;
92}