]> git.saurik.com Git - fiveicondock.git/blob - prerm.mm
A quick fid fix for eric, added thumb support to MS, and got fmil working.
[fiveicondock.git] / prerm.mm
1 #import <Foundation/Foundation.h>
2
3 #include <sys/types.h>
4 #include <pwd.h>
5 #include <unistd.h>
6
7 int main(int argc, const char *argv[]) {
8 if (argc < 2 || strcmp(argv[1], "remove") != 0)
9 return 0;
10
11 struct passwd *passwd = getpwnam("mobile");
12 if (passwd == NULL) {
13 perror("getpwnam");
14 return 0;
15 }
16
17 if (setregid(passwd->pw_gid, passwd->pw_gid) == -1) {
18 perror("setregid");
19 return 1;
20 }
21
22 if (setreuid(passwd->pw_uid, passwd->pw_uid) == -1) {
23 perror("setreuid");
24 return 1;
25 }
26
27 NSAutoreleasePool *pool([[NSAutoreleasePool alloc] init]);
28
29 NSString *path([NSString stringWithFormat:@"%@/Library/Preferences/com.apple.springboard.plist", NSHomeDirectory()]);
30
31 NSMutableDictionary *settings([[NSMutableDictionary alloc] initWithContentsOfFile:path]);
32 if (settings == nil)
33 return 0;
34
35 NSMutableDictionary *iconState([settings objectForKey:@"iconState"]);
36 if (iconState == nil)
37 return 0;
38
39 NSMutableDictionary *buttonBar([iconState objectForKey:@"buttonBar"]);
40 if (buttonBar == nil)
41 return 0;
42
43 NSMutableArray *buttonBarIconMatrix([buttonBar objectForKey:@"iconMatrix"]);
44 if (buttonBarIconMatrix == nil || [buttonBarIconMatrix count] == 0)
45 return 0;
46
47 NSMutableArray *buttonBarRow([buttonBarIconMatrix objectAtIndex:0]);
48 if (buttonBarRow == nil || [buttonBarRow count] < 5)
49 return 0;
50
51 NSMutableDictionary *fifth([buttonBarRow objectAtIndex:4]);
52
53 if (![fifth isEqual:[NSNumber numberWithInt:0]]) {
54 NSMutableArray *iconLists([iconState objectForKey:@"iconLists"]);
55 if (iconLists == nil)
56 iconLists = [NSMutableArray arrayWithCapacity:1];
57 else for (NSUInteger i(0), e([iconLists count]); i != e; ++i) {
58 NSMutableDictionary *iconList([iconLists objectAtIndex:i]);
59 NSMutableArray *iconMatrix([iconList objectForKey:@"iconMatrix"]);
60 if (iconMatrix == nil)
61 continue;
62
63 for (NSUInteger i(0), e([iconMatrix count]); i != e; ++i) {
64 NSMutableArray *row([iconMatrix objectAtIndex:i]);
65 NSUInteger spot([row indexOfObject:[NSNumber numberWithInteger:0]]);
66 if (spot != NSNotFound) {
67 [row replaceObjectAtIndex:i withObject:fifth];
68 goto save;
69 }
70 }
71 }
72
73 [iconLists addObject:[NSDictionary dictionaryWithObjectsAndKeys:
74 [NSArray arrayWithObjects:[NSArray arrayWithObject:fifth], nil], @"iconMatrix",
75 nil]];
76 }
77
78 save:
79 [buttonBarRow removeLastObject];
80 bool saved([settings writeToFile:path atomically:YES]);
81
82 [pool release];
83
84 return saved ? 0 : 1;
85 }