5 * Created by Kent Sutherland on Mon May 17 2004.
6 * Copyright (c) 2004 __MyCompanyName__. All rights reserved.
10 #import "ITLoginItem.h"
13 void ITSetApplicationLaunchOnLogin(NSString *path, BOOL flag)
15 if ( (flag && ITDoesApplicationLaunchOnLogin(path)) || ![[NSFileManager defaultManager] fileExistsAtPath:path] ) {
18 NSUserDefaults *df = [NSUserDefaults standardUserDefaults];
19 NSMutableDictionary *loginwindow;
20 NSMutableArray *loginarray;
22 ITDebugLog(@"Set if \"%@\" launches at login to %i.", path, flag);
24 loginwindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy];
25 loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"];
31 FSPathMakeRef([path UTF8String], &fileRef, NULL);
32 FSNewAlias(NULL, &fileRef, &alias);
33 aliasData = [NSData dataWithBytes:&alias length:GetHandleSize((Handle)alias)];
35 if (!loginarray) { //If there is no loginarray of autolaunch items, create one
36 loginarray = [[[NSMutableArray alloc] init] autorelease];
37 [loginwindow setObject:loginarray forKey:@"AutoLaunchedApplicationDictionary"];
40 NSDictionary *itemDict = [NSDictionary dictionaryWithObjectsAndKeys:
41 [[NSBundle mainBundle] bundlePath], @"Path",
42 [NSNumber numberWithInt:0], @"Hide",
43 aliasData, @"AliasData", nil, nil];
44 [loginarray addObject:itemDict];
47 for (i = 0; i < [loginarray count]; i++) {
48 NSDictionary *tempDict = [loginarray objectAtIndex:i];
49 if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:[path lastPathComponent]]) {
50 [loginarray removeObjectAtIndex:i];
55 [df setPersistentDomain:loginwindow forName:@"loginwindow"];
57 [loginwindow release];
60 BOOL ITDoesApplicationLaunchOnLogin(NSString *path)
62 NSUserDefaults *df = [NSUserDefaults standardUserDefaults];
63 NSDictionary *loginwindow;
64 NSMutableArray *loginarray;
65 NSEnumerator *loginEnum;
67 ITDebugLog(@"Checking if \"%@\" launches at login.", path);
69 loginwindow = [df persistentDomainForName:@"loginwindow"];
70 loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"];
72 loginEnum = [loginarray objectEnumerator];
73 while ( (anItem = [loginEnum nextObject]) ) {
74 if ( [[[anItem objectForKey:@"Path"] lastPathComponent] isEqualToString:[path lastPathComponent]] ) {