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