1 #import "ITLoginItem.h"
2 #import <Carbon/Carbon.h>
3 #import <CoreServices/CoreServices.h>
4 #import <ITFoundation/ITFoundation.h>
6 void ITSetApplicationLaunchOnLogin(NSString *path, BOOL flag) {
7 if ((flag && ITDoesApplicationLaunchOnLogin(path)) || ![[NSFileManager defaultManager] fileExistsAtPath:path]) {
10 NSUserDefaults *df = [NSUserDefaults standardUserDefaults];
11 NSMutableDictionary *loginwindow;
12 NSMutableArray *loginarray;
14 ITDebugLog(@"Set if \"%@\" launches at login to %i.", path, flag);
16 loginwindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy];
17 loginarray = [[loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"] mutableCopy];
23 FSPathMakeRef([path UTF8String], &fileRef, NULL);
24 FSNewAlias(NULL, &fileRef, &alias);
25 aliasData = [NSData dataWithBytes:&alias length:GetHandleSize((Handle)alias)];*/
27 if (!loginarray) { //If there is no loginarray of autolaunch items, create one
28 loginarray = [[[NSMutableArray alloc] init] autorelease];
30 NSDictionary *itemDict = [NSDictionary dictionaryWithObjectsAndKeys:
31 [[NSBundle mainBundle] bundlePath], @"Path",
32 [NSNumber numberWithInt:0], @"Hide",
33 [NSData data], @"AliasData", nil, nil];
34 [loginarray addObject:itemDict];
37 for (i = 0;i < [loginarray count];i++) {
38 NSDictionary *tempDict = [loginarray objectAtIndex:i];
39 if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:[path lastPathComponent]]) {
40 [loginarray removeObjectAtIndex:i];
45 [loginwindow setObject:loginarray forKey:@"AutoLaunchedApplicationDictionary"];
46 [df setPersistentDomain:loginwindow forName:@"loginwindow"];
48 [loginwindow release];
52 BOOL ITDoesApplicationLaunchOnLogin(NSString *path) {
53 NSUserDefaults *df = [NSUserDefaults standardUserDefaults];
54 NSDictionary *loginwindow;
55 NSMutableArray *loginarray;
56 NSEnumerator *loginEnum;
58 ITDebugLog(@"Checking if \"%@\" launches at login.", path);
60 loginwindow = [df persistentDomainForName:@"loginwindow"];
61 loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"];
63 loginEnum = [loginarray objectEnumerator];
64 while ((anItem = [loginEnum nextObject])) {
65 if ([[[anItem objectForKey:@"Path"] lastPathComponent] isEqualToString:[path lastPathComponent]]) {