]>
Commit | Line | Data |
---|---|---|
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 |
37 | int main() { |
38 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | |
39 | ||
7e0ec87a JF |
40 | NSString *home(NSHomeDirectory()); |
41 | NSString *path([NSString stringWithFormat:@"%@/Library/Caches/com.apple.mobile.installation.plist", home]); | |
7fb7ce13 | 42 | |
020dfc54 JF |
43 | Class $LSApplicationWorkspace(objc_getClass("LSApplicationWorkspace")); |
44 | LSApplicationWorkspace *workspace($LSApplicationWorkspace == nil ? nil : [$LSApplicationWorkspace defaultWorkspace]); | |
1094bdcb | 45 | |
020dfc54 | 46 | if (NSMutableDictionary *cache = [NSMutableDictionary dictionaryWithContentsOfFile:path]) { |
1094bdcb JF |
47 | NSFileManager *manager = [NSFileManager defaultManager]; |
48 | NSError *error = nil; | |
49 | ||
020dfc54 JF |
50 | NSMutableArray *bundles([NSMutableArray arrayWithCapacity:16]); |
51 | ||
1094bdcb JF |
52 | id system = [cache objectForKey:@"System"]; |
53 | if (system == nil) | |
54 | goto error; | |
55 | ||
1094bdcb JF |
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"]; | |
020dfc54 JF |
63 | |
64 | if (NSMutableDictionary *info = [NSMutableDictionary dictionaryWithContentsOfFile:plist]) { | |
65 | if (NSString *bundle = [info objectForKey:@"CFBundleIdentifier"]) { | |
66 | [bundles addObject:path]; | |
2a72f832 JF |
67 | [info setObject:path forKey:@"Path"]; |
68 | [info setObject:@"System" forKey:@"ApplicationType"]; | |
69 | [system addInfoDictionary:info]; | |
020dfc54 JF |
70 | } else |
71 | fprintf(stderr, "%s missing CFBundleIdentifier", [app UTF8String]); | |
1094bdcb JF |
72 | } |
73 | } | |
74 | } else goto error; | |
75 | ||
7fb7ce13 | 76 | [cache writeToFile:path atomically:YES]; |
1094bdcb | 77 | |
020dfc54 | 78 | if (workspace != nil) |
5ac04f0f JF |
79 | for (NSString *bundle in bundles) { |
80 | [workspace unregisterApplication:[NSURL fileURLWithPath:bundle]]; | |
020dfc54 | 81 | [workspace registerApplication:[NSURL fileURLWithPath:bundle]]; |
5ac04f0f | 82 | } |
020dfc54 | 83 | |
1094bdcb JF |
84 | if (false) error: |
85 | fprintf(stderr, "%s\n", error == nil ? strerror(errno) : [[error localizedDescription] UTF8String]); | |
7fb7ce13 | 86 | } else fprintf(stderr, "cannot open cache file. incorrect user?\n"); |
1094bdcb | 87 | |
91674471 JF |
88 | unlink([[NSString stringWithFormat:@"%@/Library/Caches/com.apple.springboard-imagecache-icons", home] UTF8String]); |
89 | unlink([[NSString stringWithFormat:@"%@/Library/Caches/com.apple.springboard-imagecache-icons.plist", home] UTF8String]); | |
7e0ec87a | 90 | |
91674471 JF |
91 | unlink([[NSString stringWithFormat:@"%@/Library/Caches/com.apple.springboard-imagecache-smallicons", home] UTF8String]); |
92 | unlink([[NSString stringWithFormat:@"%@/Library/Caches/com.apple.springboard-imagecache-smallicons.plist", home] UTF8String]); | |
7e0ec87a | 93 | |
91674471 JF |
94 | system([[NSString stringWithFormat:@"rm -rf %@/Library/Caches/SpringBoardIconCache", home] UTF8String]); |
95 | system([[NSString stringWithFormat:@"rm -rf %@/Library/Caches/SpringBoardIconCache-small", home] UTF8String]); | |
7e0ec87a | 96 | |
91674471 | 97 | system([[NSString stringWithFormat:@"rm -rf %@/Library/Caches/com.apple.IconsCache", home] UTF8String]); |
7e0ec87a | 98 | |
1094bdcb JF |
99 | notify_post("com.apple.mobile.application_installed"); |
100 | ||
101 | [pool release]; | |
102 | ||
103 | return 0; | |
104 | } |