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