The silly thing compiles now
[ITFoundation.git] / ITLoginItem.m
1 /*
2  *  ITLoginItem.m
3  *  ITFoundation
4  *
5  *  Created by Kent Sutherland on Mon May 17 2004.
6  *  Copyright (c) 2004 __MyCompanyName__. All rights reserved.
7  *
8  */
9
10 #import "ITLoginItem.h"
11 #import "ITDebug.h"
12
13 BOOL ITSetLaunchApplicationOnLogin(NSString *path, BOOL flag)
14 {
15     NSUserDefaults *df = [NSUserDefaults standardUserDefaults];
16     NSMutableDictionary *loginwindow;
17     NSMutableArray *loginarray;
18     FSRef fileRef;
19     AliasHandle alias;
20     NSData *aliasData;
21     
22     ITDebugLog(@"Set if MenuPrefs launches at login to %i.", flag);
23     [df synchronize];
24     loginwindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy];
25     loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"];
26     
27     //Create the alias data
28     FSPathMakeRef([path UTF8String], &fileRef, NULL);
29     FSNewAlias(NULL, &fileRef, &alias);
30     aliasData = [NSData dataWithBytes:&alias length:sizeof(alias)];
31     
32     if (flag) {
33         NSDictionary *itemDict = [NSDictionary dictionaryWithObjectsAndKeys:
34         [[NSBundle mainBundle] bundlePath], @"Path",
35         [NSNumber numberWithInt:0], @"Hide",
36         aliasData, @"AliasData", nil, nil];
37         [loginarray addObject:itemDict];
38     } else {
39         int i;
40         for (i = 0; i < [loginarray count]; i++) {
41             NSDictionary *tempDict = [loginarray objectAtIndex:i];
42             if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]]) {
43                 [loginarray removeObjectAtIndex:i];
44                 break;
45             }
46         }
47     }
48     [df setPersistentDomain:loginwindow forName:@"loginwindow"];
49     [df synchronize];
50     [loginwindow release];
51     return YES;
52 }