1 /* UIKit Tools - command-line utilities for UIKit
2 * Copyright (C) 2008-2012 Jay Freeman (saurik)
5 /* Modified BSD License {{{ */
7 * Redistribution and use in source and binary
8 * forms, with or without modification, are permitted
9 * provided that the following conditions are met:
11 * 1. Redistributions of source code must retain the
12 * above copyright notice, this list of conditions
13 * and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the
15 * above copyright notice, this list of conditions
16 * and the following disclaimer in the documentation
17 * and/or other materials provided with the
19 * 3. The name of the author may not be used to endorse
20 * or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
25 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
34 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
36 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 #import <Foundation/Foundation.h>
43 #include <sys/types.h>
47 #include <objc/runtime.h>
49 #include <MobileCoreServices/LSApplicationWorkspace.h>
51 #include "csstore.hpp"
53 @interface NSMutableArray (Cydia)
54 - (void) addInfoDictionary:(NSDictionary *)info;
57 @implementation NSMutableArray (Cydia)
59 - (void) addInfoDictionary:(NSDictionary *)info {
60 [self addObject:info];
63 - (NSArray *) allInfoDictionaries {
69 @interface NSMutableDictionary (Cydia)
70 - (void) addInfoDictionary:(NSDictionary *)info;
73 @implementation NSMutableDictionary (Cydia)
75 - (void) addInfoDictionary:(NSDictionary *)info {
76 NSString *bundle = [info objectForKey:@"CFBundleIdentifier"];
77 [self setObject:info forKey:bundle];
80 - (NSArray *) allInfoDictionaries {
81 return [self allValues];
86 int main(int argc, const char *argv[]) {
87 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
91 NSString *home(NSHomeDirectory());
92 NSString *path([NSString stringWithFormat:@"%@/Library/Caches/com.apple.mobile.installation.plist", home]);
94 system("killall -SIGSTOP SpringBoard");
99 DeleteCSStores([home UTF8String]);
101 system("killall lsd");
103 Class $LSApplicationWorkspace(objc_getClass("LSApplicationWorkspace"));
104 LSApplicationWorkspace *workspace($LSApplicationWorkspace == nil ? nil : [$LSApplicationWorkspace defaultWorkspace]);
106 if ([workspace respondsToSelector:@selector(invalidateIconCache:)])
107 while (![workspace invalidateIconCache:nil])
110 if (NSMutableDictionary *cache = [NSMutableDictionary dictionaryWithContentsOfFile:path]) {
111 NSFileManager *manager = [NSFileManager defaultManager];
112 NSError *error = nil;
114 NSMutableDictionary *bundles([NSMutableDictionary dictionaryWithCapacity:16]);
116 id after = [cache objectForKey:@"System"];
117 if (after == nil) { error:
118 fprintf(stderr, "%s\n", error == nil ? strerror(errno) : [[error localizedDescription] UTF8String]);
122 id before([[after copy] autorelease]);
123 [after removeAllObjects];
125 NSArray *cached([cache objectForKey:@"InfoPlistCachedKeys"]);
127 NSMutableSet *removed([NSMutableSet set]);
128 for (NSDictionary *info in [before allInfoDictionaries])
129 if (NSString *path = [info objectForKey:@"Path"])
130 [removed addObject:path];
132 if (NSArray *apps = [manager contentsOfDirectoryAtPath:@"/Applications" error:&error]) {
133 for (NSString *app in apps)
134 if ([app hasSuffix:@".app"]) {
135 NSString *path = [@"/Applications" stringByAppendingPathComponent:app];
136 NSString *plist = [path stringByAppendingPathComponent:@"Info.plist"];
138 if (NSMutableDictionary *info = [NSMutableDictionary dictionaryWithContentsOfFile:plist]) {
139 if (NSString *identifier = [info objectForKey:@"CFBundleIdentifier"]) {
140 [bundles setObject:path forKey:identifier];
141 [removed removeObject:path];
144 NSMutableDictionary *merged([before objectForKey:identifier]);
146 merged = [NSMutableDictionary dictionary];
148 merged = [[merged mutableCopy] autorelease];
150 for (NSString *key in cached)
151 if (NSObject *value = [info objectForKey:key])
152 [merged setObject:value forKey:key];
154 [merged removeObjectForKey:key];
159 [info setObject:path forKey:@"Path"];
160 [info setObject:@"System" forKey:@"ApplicationType"];
161 [after addInfoDictionary:info];
163 fprintf(stderr, "%s missing CFBundleIdentifier", [app UTF8String]);
168 [cache writeToFile:path atomically:YES];
170 if (workspace != nil) {
171 if ([workspace respondsToSelector:@selector(invalidateIconCache:)]) {
172 for (NSString *identifier in bundles)
173 [workspace invalidateIconCache:identifier];
175 for (NSString *identifier in bundles) {
176 NSString *path([bundles objectForKey:identifier]);
177 [workspace unregisterApplication:[NSURL fileURLWithPath:path]];
181 for (NSString *identifier in bundles) {
182 NSString *path([bundles objectForKey:identifier]);
183 [workspace registerApplication:[NSURL fileURLWithPath:path]];
186 for (NSString *path in removed)
187 [workspace unregisterApplication:[NSURL fileURLWithPath:path]];
189 } else fprintf(stderr, "cannot open cache file. incorrect user?\n");
192 if (respring || kCFCoreFoundationVersionNumber >= 550.32) {
193 unlink([[NSString stringWithFormat:@"%@/Library/Caches/com.apple.springboard-imagecache-icons", home] UTF8String]);
194 unlink([[NSString stringWithFormat:@"%@/Library/Caches/com.apple.springboard-imagecache-icons.plist", home] UTF8String]);
196 unlink([[NSString stringWithFormat:@"%@/Library/Caches/com.apple.springboard-imagecache-smallicons", home] UTF8String]);
197 unlink([[NSString stringWithFormat:@"%@/Library/Caches/com.apple.springboard-imagecache-smallicons.plist", home] UTF8String]);
199 system([[NSString stringWithFormat:@"rm -rf %@/Library/Caches/SpringBoardIconCache", home] UTF8String]);
200 system([[NSString stringWithFormat:@"rm -rf %@/Library/Caches/SpringBoardIconCache-small", home] UTF8String]);
202 system([[NSString stringWithFormat:@"rm -rf %@/Library/Caches/com.apple.IconsCache", home] UTF8String]);
205 system("killall installd");
208 system("killall -SIGCONT SpringBoard");
212 system("launchctl stop com.apple.SpringBoard");
214 notify_post("com.apple.mobile.application_installed");