]> git.saurik.com Git - uikittools.git/commitdiff
Added UICache.
authorJay Freeman (saurik) <saurik@saurik.com>
Sun, 14 Sep 2008 21:08:55 +0000 (21:08 +0000)
committerJay Freeman (saurik) <saurik@saurik.com>
Sun, 14 Sep 2008 21:08:55 +0000 (21:08 +0000)
makefile
uicache.mm [new file with mode: 0644]
uiinstall.mm [deleted file]

index cf9cbd010e3f0307b415d7dd50df9b067b597637..60cb272183ef0046138451447433d119c7df12a9 100644 (file)
--- a/makefile
+++ b/makefile
@@ -1,4 +1,4 @@
-all: uiduid uishoot
+all: uiduid uishoot uicache
 
 %: %.mm
        $${PKG_TARG}-g++ -o $@ $< -framework CoreFoundation -framework Foundation -framework UIKit -lobjc
diff --git a/uicache.mm b/uicache.mm
new file mode 100644 (file)
index 0000000..71f67d8
--- /dev/null
@@ -0,0 +1,75 @@
+#import <Foundation/Foundation.h>
+
+#include <notify.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+@interface NSMutableArray (Cydia)
+- (void) addInfoDictionary:(NSDictionary *)info;
+@end
+
+@implementation NSMutableArray (Cydia)
+
+- (void) addInfoDictionary:(NSDictionary *)info {
+    [self addObject:info];
+}
+
+@end
+
+@interface NSMutableDictionary (Cydia)
+- (void) addInfoDictionary:(NSDictionary *)info;
+@end
+
+@implementation NSMutableDictionary (Cydia)
+
+- (void) addInfoDictionary:(NSDictionary *)info {
+    NSString *bundle = [info objectForKey:@"CFBundleIdentifier"];
+    [self setObject:info forKey:bundle];
+}
+
+@end
+
+int main() {
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+    NSString *path([NSString stringWithFormat:@"%@/Library/Caches/com.apple.mobile.installation.plist", NSHomeDirectory()]);
+
+    if (NSMutableDictionary *cache = [[NSMutableDictionary alloc] initWithContentsOfFile:path]) {
+        [cache autorelease];
+
+        NSFileManager *manager = [NSFileManager defaultManager];
+        NSError *error = nil;
+
+        id system = [cache objectForKey:@"System"];
+        if (system == nil)
+            goto error;
+
+        [system removeAllObjects];
+
+        if (NSArray *apps = [manager contentsOfDirectoryAtPath:@"/Applications" error:&error]) {
+            for (NSString *app in apps)
+                if ([app hasSuffix:@".app"]) {
+                    NSString *path = [@"/Applications" stringByAppendingPathComponent:app];
+                    NSString *plist = [path stringByAppendingPathComponent:@"Info.plist"];
+                    if (NSMutableDictionary *info = [[NSMutableDictionary alloc] initWithContentsOfFile:plist]) {
+                        [info autorelease];
+                        [info setObject:path forKey:@"Path"];
+                        [info setObject:@"System" forKey:@"ApplicationType"];
+                        [system addInfoDictionary:info];
+                    }
+                }
+        } else goto error;
+
+        [cache writeToFile:path atomically:YES];
+
+        if (false) error:
+            fprintf(stderr, "%s\n", error == nil ? strerror(errno) : [[error localizedDescription] UTF8String]);
+    } else fprintf(stderr, "cannot open cache file. incorrect user?\n");
+
+    notify_post("com.apple.mobile.application_installed");
+
+    [pool release];
+
+    return 0;
+}
diff --git a/uiinstall.mm b/uiinstall.mm
deleted file mode 100644 (file)
index 1473ca5..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-@interface NSMutableArray (Cydia)
-- (void) addInfoDictionary:(NSDictionary *)info;
-@end
-
-@implementation NSMutableArray (Cydia)
-
-- (void) addInfoDictionary:(NSDictionary *)info {
-    [self addObject:info];
-}
-
-@end
-
-@interface NSMutableDictionary (Cydia)
-- (void) addInfoDictionary:(NSDictionary *)info;
-@end
-
-@implementation NSMutableDictionary (Cydia)
-
-- (void) addInfoDictionary:(NSDictionary *)info {
-    NSString *bundle = [info objectForKey:@"CFBundleIdentifier"];
-    [self setObject:info forKey:bundle];
-}
-
-@end
-
-#define Cache_ "/User/Library/Caches/com.apple.mobile.installation.plist"
-
-int main() {
-    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-
-    if (NSMutableDictionary *cache = [[NSMutableDictionary alloc] initWithContentsOfFile:@ Cache_]) {
-        [cache autorelease];
-
-        NSFileManager *manager = [NSFileManager defaultManager];
-        NSError *error = nil;
-
-        id system = [cache objectForKey:@"System"];
-        if (system == nil)
-            goto error;
-
-        struct stat info;
-        if (stat(Cache_, &info) == -1)
-            goto error;
-
-        [system removeAllObjects];
-
-        if (NSArray *apps = [manager contentsOfDirectoryAtPath:@"/Applications" error:&error]) {
-            for (NSString *app in apps)
-                if ([app hasSuffix:@".app"]) {
-                    NSString *path = [@"/Applications" stringByAppendingPathComponent:app];
-                    NSString *plist = [path stringByAppendingPathComponent:@"Info.plist"];
-                    if (NSMutableDictionary *info = [[NSMutableDictionary alloc] initWithContentsOfFile:plist]) {
-                        [info autorelease];
-                        [info setObject:path forKey:@"Path"];
-                        [info setObject:@"System" forKey:@"ApplicationType"];
-                        [system addInfoDictionary:info];
-                    }
-                }
-        } else goto error;
-
-        [cache writeToFile:@Cache_ atomically:YES];
-
-        if (chown(Cache_, info.st_uid, info.st_gid) == -1)
-            goto error;
-        if (chmod(Cache_, info.st_mode) == -1)
-            goto error;
-
-        if (false) error:
-            fprintf(stderr, "%s\n", error == nil ? strerror(errno) : [[error localizedDescription] UTF8String]);
-    }
-
-    notify_post("com.apple.mobile.application_installed");
-
-    [pool release];
-
-    return 0;
-}