]> git.saurik.com Git - uikittools.git/blob - uicache.mm
Delete the icon caches.
[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 #include <objc/runtime.h>
9
10 #include <MobileCoreServices/LSApplicationWorkspace.h>
11
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
37 int main() {
38 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
39
40 NSString *home(NSHomeDirectory());
41 NSString *path([NSString stringWithFormat:@"%@/Library/Caches/com.apple.mobile.installation.plist", home]);
42
43 Class $LSApplicationWorkspace(objc_getClass("LSApplicationWorkspace"));
44 LSApplicationWorkspace *workspace($LSApplicationWorkspace == nil ? nil : [$LSApplicationWorkspace defaultWorkspace]);
45
46 if (NSMutableDictionary *cache = [NSMutableDictionary dictionaryWithContentsOfFile:path]) {
47 NSFileManager *manager = [NSFileManager defaultManager];
48 NSError *error = nil;
49
50 NSMutableArray *bundles([NSMutableArray arrayWithCapacity:16]);
51
52 id system = [cache objectForKey:@"System"];
53 if (system == nil)
54 goto error;
55
56 [system removeAllObjects];
57
58 if (NSArray *apps = [manager contentsOfDirectoryAtPath:@"/Applications" error:&error]) {
59 for (NSString *app in apps)
60 if ([app hasSuffix:@".app"]) {
61 NSString *path = [@"/Applications" stringByAppendingPathComponent:app];
62 NSString *plist = [path stringByAppendingPathComponent:@"Info.plist"];
63
64 if (NSMutableDictionary *info = [NSMutableDictionary dictionaryWithContentsOfFile:plist]) {
65 if (NSString *bundle = [info objectForKey:@"CFBundleIdentifier"]) {
66 [bundles addObject:path];
67 [info setObject:path forKey:@"Path"];
68 [info setObject:@"System" forKey:@"ApplicationType"];
69 [system addInfoDictionary:info];
70 } else
71 fprintf(stderr, "%s missing CFBundleIdentifier", [app UTF8String]);
72 }
73 }
74 } else goto error;
75
76 [cache writeToFile:path atomically:YES];
77
78 if (workspace != nil)
79 for (NSString *bundle in bundles) {
80 [workspace unregisterApplication:[NSURL fileURLWithPath:bundle]];
81 [workspace registerApplication:[NSURL fileURLWithPath:bundle]];
82 }
83
84 if (false) error:
85 fprintf(stderr, "%s\n", error == nil ? strerror(errno) : [[error localizedDescription] UTF8String]);
86 } else fprintf(stderr, "cannot open cache file. incorrect user?\n");
87
88 unlink([[NSString stringWithFormat:@"%@/Library/Caches/com.apple.springboard-imagecache-icons"] UTF8String]);
89 unlink([[NSString stringWithFormat:@"%@/Library/Caches/com.apple.springboard-imagecache-icons.plist"] UTF8String]);
90
91 unlink([[NSString stringWithFormat:@"%@/Library/Caches/com.apple.springboard-imagecache-smallicons"] UTF8String]);
92 unlink([[NSString stringWithFormat:@"%@/Library/Caches/com.apple.springboard-imagecache-smallicons.plist"] UTF8String]);
93
94 system([[NSString stringWithFormat:@"rm -rf %@/Library/Caches/SpringBoardIconCache"] UTF8String]);
95 system([[NSString stringWithFormat:@"rm -rf %@/Library/Caches/SpringBoardIconCache-small"] UTF8String]);
96
97 system([[NSString stringWithFormat:@"rm -rf %@/Library/Caches/com.apple.IconsCache"] UTF8String]);
98
99 notify_post("com.apple.mobile.application_installed");
100
101 [pool release];
102
103 return 0;
104 }