void SetLoginPreferences(Boolean
newSetting)
{
CFArrayRef src_array; /* オリジナル */
CFMutableArrayRef dst_array; /*
変更を加えたもの */
Boolean currentSetting;
CFIndex index;
currentSetting = ((index = GetLoginPreferences()) > 0);
if (newSetting == currentSetting)
return;
/* まず、初期設定ファイル(loginwindow.plist)から情報を得る
*/
src_array = CFPreferencesCopyValue(
CFSTR("AutoLaunchedApplicationDictionary"),
CFSTR("loginwindow"),
kCFPreferencesCurrentUser,
kCFPreferencesAnyHost);
if (src_array)
{
Boolean changed;
/* 変更できるようにコピーする */
dst_array = CFArrayCreateMutableCopy(NULL,0,src_array);
if (dst_array) /*
コピー成功 */
{
if (newSetting) /*
add entry to preferences */
{
CFMutableDictionaryRef dict;
CFStringRef path;
dict = CFDictionaryCreateMutable(
kCFAllocatorDefault,0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
/* Hide : false */
CFDictionarySetValue(dict,
CFSTR("Hide"),kCFBooleanFalse);
/* Path : */
path = GetApplicationPath();
CFDictionarySetValue(dict,CFSTR("Path"),path);
CFRelease(path);
/* add value to array */
CFArrayAppendValue(dst_array,dict);
CFRelease(dict);
}
else /*
remove entry from preferences */
{
CFArrayRemoveValueAtIndex(dst_array,index);
}
/* save to preferences */
CFPreferencesSetValue(
CFSTR("AutoLaunchedApplicationDictionary"),
dst_array,
CFSTR("loginwindow"),
kCFPreferencesCurrentUser,
kCFPreferencesAnyHost);
changed = CFPreferencesSynchronize(
CFSTR("loginwindow"),
kCFPreferencesCurrentUser,
kCFPreferencesAnyHost);
}
CFRelease(src_array);
CFRelease(dst_array);
}
}
|