forked from ttwj/ClutchMod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplist.m
100 lines (85 loc) · 4.25 KB
/
applist.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#import "applist.h"
NSArray * get_application_list(BOOL sort, BOOL updates) {
NSString *basePath = @"/var/mobile/Applications/";
NSMutableArray *returnArray = [[NSMutableArray alloc] init];
NSArray *apps = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:basePath error:NULL];
if ([apps count] == 0) {
return NULL;
}
NSEnumerator *e, *e2;
e = [apps objectEnumerator];
NSString *applicationDirectory;
NSString *applicationSubdirectory;
NSMutableDictionary *cache = [NSMutableDictionary dictionaryWithContentsOfFile:@"/var/cache/clutch.plist"];
BOOL cflush = FALSE;
if ((cache == nil) || (![cache count])) {
cache = [NSMutableDictionary dictionary];
cflush = TRUE;
}
NSMutableDictionary *versions;
if (updates) {
if (![[NSFileManager defaultManager] fileExistsAtPath:@"/etc/clutch_cracked.plist"]) {
versions = [[NSMutableDictionary alloc] init];
}
else {
versions = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/var/cache/clutch_cracked.plist"];
}
}
NSDictionary *applicationDetailObject;
NSString *bundleDisplayName, *applicationRealname, *bundleVersionString;
while (applicationDirectory = [e nextObject]) {
//if ([cache objectForKey:applicationDirectory] != nil) {
//[returnArray addObject:[cache objectForKey:applicationDirectory]];
// } else {
NSArray *sandboxPath = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[basePath stringByAppendingFormat:@"%@/", applicationDirectory] error:NULL];
e2 = [sandboxPath objectEnumerator];
while (applicationSubdirectory = [e2 nextObject]) {
if ([applicationSubdirectory rangeOfString:@".app"].location == NSNotFound)
continue;
else {
bundleDisplayName = [[NSDictionary dictionaryWithContentsOfFile:[basePath stringByAppendingFormat:@"%@/%@/Info.plist", applicationDirectory, applicationSubdirectory]] objectForKey:@"CFBundleDisplayName"];
bundleVersionString = [[[NSDictionary dictionaryWithContentsOfFile:[basePath stringByAppendingFormat:@"%@/%@/Info.plist", applicationDirectory, applicationSubdirectory]] objectForKey:@"CFBundleVersion"] stringByReplacingOccurrencesOfString:@"." withString:@""];
applicationRealname = [applicationSubdirectory stringByReplacingOccurrencesOfString:@".app" withString:@""];
if (bundleDisplayName == nil) {
bundleDisplayName = applicationRealname;
}
if ([[NSFileManager defaultManager] fileExistsAtPath:[basePath stringByAppendingFormat:@"%@/%@/SC_Info/", applicationDirectory, applicationSubdirectory]]) {
applicationDetailObject = [NSDictionary dictionaryWithObjectsAndKeys:
[basePath stringByAppendingFormat:@"%@/", applicationDirectory], @"ApplicationBaseDirectory",
[basePath stringByAppendingFormat:@"%@/%@/", applicationDirectory, applicationSubdirectory], @"ApplicationDirectory",
bundleDisplayName, @"ApplicationDisplayName",
applicationRealname, @"ApplicationName",
applicationSubdirectory, @"ApplicationBasename",
applicationDirectory, @"RealUniqueID",
bundleVersionString, @"ApplicationVersion",
nil];
if (updates) {
if ([versions objectForKey:applicationRealname] != bundleVersionString) {
[returnArray addObject:applicationDetailObject];
}
}
else {
[returnArray addObject:applicationDetailObject];
}
[cache setValue:bundleDisplayName forKey:applicationDirectory];
cflush = TRUE;
}
}
}
}
//}
if (cflush) {
[cache writeToFile:@"/var/cache/clutch.plist" atomically:TRUE];
}
if ([returnArray count] == 0) {
[returnArray release];
return NULL;
}
if (sort) {
return (NSArray *)[returnArray sortedArrayUsingFunction:alphabeticalSort context:NULL];
}
return (NSArray *) returnArray;
}
NSComparisonResult alphabeticalSort(id one, id two, void *context) {
return [[(NSDictionary *)one objectForKey:@"ApplicationName"] localizedCaseInsensitiveCompare:[(NSDictionary *)two objectForKey:@"ApplicationName"]];
}