コード例 #1
0
ファイル: macos.c プロジェクト: fjrti/subsurface
void subsurface_set_conf_bool(char *name, int value)
{
	CFPreferencesSetAppValue(CFSTR_VAR(name),
		value ? kCFBooleanTrue : kCFBooleanFalse, SUBSURFACE_PREFERENCES);
}
コード例 #2
0
Boolean HIDSaveElementPref(const CFStringRef	inKeyCFStringRef,
                           CFStringRef			inAppCFStringRef,
                           IOHIDDeviceRef		inIOHIDDeviceRef,
                           IOHIDElementRef		inIOHIDElementRef) {
	Boolean success = false;

	if (inKeyCFStringRef &&
	    inAppCFStringRef &&
	    inIOHIDDeviceRef &&
	    inIOHIDElementRef)
	{
		uint32_t vendorID = IOHIDDevice_GetVendorID(inIOHIDDeviceRef);
		require(vendorID,
		        Oops);

		uint32_t productID = IOHIDDevice_GetProductID(inIOHIDDeviceRef);
		require(productID,
		        Oops);

		uint32_t locID = IOHIDDevice_GetLocationID(inIOHIDDeviceRef);
		require(locID,
		        Oops);

		uint32_t usagePage = IOHIDDevice_GetUsagePage(inIOHIDDeviceRef);
		uint32_t usage = IOHIDDevice_GetUsage(inIOHIDDeviceRef);
		if (!usagePage ||
		    !usage)
		{
			usagePage = IOHIDDevice_GetPrimaryUsagePage(inIOHIDDeviceRef);
			usage = IOHIDDevice_GetPrimaryUsage(inIOHIDDeviceRef);
		}

		require(usagePage &&
		        usage,
		        Oops);

		uint32_t usagePageE = IOHIDElementGetUsagePage(inIOHIDElementRef);
		uint32_t usageE = IOHIDElementGetUsage(inIOHIDElementRef);
		IOHIDElementCookie eleCookie = IOHIDElementGetCookie(inIOHIDElementRef);

		CFStringRef prefCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault,
		                                                       NULL,
		                                                       CFSTR("d:{v:%d, p:%d, l:%d, p:%d, u:%d}, e:{p:%d, u:%d, c:%d}"),
		                                                       vendorID,
		                                                       productID,
		                                                       locID,
		                                                       usagePage,
		                                                       usage,
		                                                       usagePageE,
		                                                       usageE,
		                                                       eleCookie);
		if (prefCFStringRef) {
			CFPreferencesSetAppValue(inKeyCFStringRef,
			                         prefCFStringRef,
			                         inAppCFStringRef);
			CFRelease(prefCFStringRef);
			success = true;
		}
	}

Oops:;

	return (success);
}                                                                               // HIDSaveElementPref
コード例 #3
0
ファイル: macos.c プロジェクト: fjrti/subsurface
void subsurface_unset_conf(char *name)
{
	CFPreferencesSetAppValue(CFSTR_VAR(name), NULL, SUBSURFACE_PREFERENCES);
}
コード例 #4
0
ファイル: macos.c プロジェクト: fjrti/subsurface
void subsurface_set_conf(char *name, const char *value)
{
	CFPreferencesSetAppValue(CFSTR_VAR(name), CFSTR_VAR(value), SUBSURFACE_PREFERENCES);
}
コード例 #5
0
void PreferencesDialog::shutdownDataBase()
{
	CFStringRef yes = CFSTR("yes");
	CFStringRef no  = CFSTR("no");

	if (m_dataBase->restore(KEY_SAVEPREFS)->getIntValue())
	{
		CFStringRef key = CFSTR(KEY_USEMIDI);		
		CFPreferencesSetAppValue(key, m_dataBase->restore(KEY_USEMIDI)->getBoolValue() ? yes : no, applicationID);

		key = CFSTR(KEY_SAVEPREFS);		
		CFPreferencesSetAppValue(key, m_dataBase->restore(KEY_SAVEPREFS)->getBoolValue() ? yes : no, applicationID);

		key = CFSTR(KEY_MIDIDEVICE);		
		CFStringRef CFStrDevName = CFStringCreateWithCString(NULL, m_dataBase->restore(KEY_MIDIDEVICE)->getStringValue(), kCFStringEncodingASCII);
		CFPreferencesSetAppValue(key, CFStrDevName, applicationID);
		CFRelease(CFStrDevName);

		key = CFSTR(KEY_RECORDVELOCITY);		
		CFPreferencesSetAppValue(key, m_dataBase->restore(KEY_RECORDVELOCITY)->getBoolValue() ? yes : no, applicationID);

		SInt32 number = m_dataBase->restore(KEY_VELOCITYAMPLIFY)->getIntValue();
		CFNumberRef numberRef = CFNumberCreate(NULL, kCFNumberSInt32Type, &number);
		key = CFSTR(KEY_VELOCITYAMPLIFY);		
		CFPreferencesSetAppValue(key,  numberRef, applicationID);
		CFRelease(numberRef);
	}
	else
	{
		// remove keys from preferences (or something like that if it's possible)
		CFStringRef key = CFSTR(KEY_USEMIDI);		
		CFPreferencesSetAppValue(key, NULL, applicationID);

		key = CFSTR(KEY_SAVEPREFS);		
		CFPreferencesSetAppValue(key, NULL, applicationID);

		key = CFSTR(KEY_MIDIDEVICE);		
		CFPreferencesSetAppValue(key, NULL, applicationID);

		key = CFSTR(KEY_RECORDVELOCITY);		
		CFPreferencesSetAppValue(key, NULL, applicationID);

		key = CFSTR(KEY_VELOCITYAMPLIFY);		
		CFPreferencesSetAppValue(key, NULL, applicationID);
	}
	
	SInt32 number = m_dataBase->restore(KEY_INSERTEMULATION)->getIntValue();
	CFNumberRef numberRef = CFNumberCreate(NULL, kCFNumberSInt32Type, &number);
	CFStringRef key = CFSTR(KEY_INSERTEMULATION);		
	CFPreferencesSetAppValue(key,  numberRef, applicationID);
	CFRelease(numberRef);
	
	key = CFSTR(KEY_SIXTEENBITCOLOR);		
	CFPreferencesSetAppValue(key, m_dataBase->restore(KEY_SIXTEENBITCOLOR)->getBoolValue() ? yes : no, applicationID);
	
	CFPreferencesAppSynchronize(applicationID);
}
コード例 #6
0
ファイル: ArchHooks_MacOSX.cpp プロジェクト: Ancaro/stepmania
void ArchHooks_MacOSX::Init()
{
	// First, handle non-fatal termination signals.
	SignalHandler::OnClose( DoCleanShutdown );
	CrashHandler::CrashHandlerHandleArgs( g_argc, g_argv );
	CrashHandler::InitializeCrashHandler();
	SignalHandler::OnClose( DoCrashSignalHandler );
	SignalHandler::OnClose( DoEmergencyShutdown );

	// Now that the crash handler is set up, disable crash reporter.
	// Breaks gdb
	// task_set_exception_ports( mach_task_self(), EXC_MASK_ALL, MACH_PORT_NULL, EXCEPTION_DEFAULT, 0 );

	// CF*Copy* functions' return values need to be released, CF*Get* functions' do not.
	CFStringRef key = CFSTR( "ApplicationBundlePath" );

	CFBundleRef bundle = CFBundleGetMainBundle();
	CFStringRef appID = CFBundleGetIdentifier( bundle );
	if( appID == NULL )
	{
		// We were probably launched through a symlink. Don't bother hunting down the real path.
		return;
	}
	CFStringRef version = CFStringRef( CFBundleGetValueForInfoDictionaryKey(bundle, kCFBundleVersionKey) );
	CFPropertyListRef old = CFPreferencesCopyAppValue( key, appID );
	CFURLRef path = CFBundleCopyBundleURL( bundle );
	CFPropertyListRef value = CFURLCopyFileSystemPath( path, kCFURLPOSIXPathStyle );
	CFMutableDictionaryRef newDict = NULL;

	if( old && CFGetTypeID(old) != CFDictionaryGetTypeID() )
	{
		CFRelease( old );
		old = NULL;
	}

	if( !old )
	{
		newDict = CFDictionaryCreateMutable( kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks,
						     &kCFTypeDictionaryValueCallBacks );
		CFDictionaryAddValue( newDict, version, value );
	}
	else
	{
		CFTypeRef oldValue;
		CFDictionaryRef dict = CFDictionaryRef( old );

		if( !CFDictionaryGetValueIfPresent(dict, version, &oldValue) || !CFEqual(oldValue, value) )
		{
			// The value is either not present or it is but it is different
			newDict = CFDictionaryCreateMutableCopy( kCFAllocatorDefault, 0, dict );
			CFDictionarySetValue( newDict, version, value );
		}
		CFRelease( old );
	}

	if( newDict )
	{
		CFPreferencesSetAppValue( key, newDict, appID );
		if( !CFPreferencesAppSynchronize(appID) )
			LOG->Warn( "Failed to record the run path." );
		CFRelease( newDict );
	}
	CFRelease( value );
	CFRelease( path );
}
コード例 #7
0
int main()
{
	if (geteuid())
	{
		syslog(LOG_ERR,"Error: Daemon must run as root.");
		exit(geteuid());
	}

	encrypt_buffer = CFDataCreateMutable(kCFAllocatorDefault,8);
	
/*********Set up File**********/

	if (!(pathName = (CFStringRef)CFPreferencesCopyAppValue(PATHNAME_PREF_KEY,PREF_DOMAIN)))
	{
		pathName = CFSTR(DEFAULT_PATHNAME);
		CFPreferencesSetAppValue(PATHNAME_PREF_KEY,pathName,PREF_DOMAIN);
	}

	CFURLRef logPathURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,pathName,kCFURLPOSIXPathStyle,false);	
	logStream = CFWriteStreamCreateWithFile(kCFAllocatorDefault,logPathURL);
	CFRelease(logPathURL);

	if (!logStream)
	{
		syslog(LOG_ERR,"Error: Couldn't open file stream at start.");	
		return 1;
	}

/*********Check encryption & keymap**********/

	updateEncryption();
	updateKeymap();

/*********Check space**********/

	if (outOfSpace(pathName))
	{
		stamp_file(CFSTR("Not enough disk space remaining!"));
		CFRunLoopStop(CFRunLoopGetCurrent());
	}

/*********Connect to kernel extension**********/
	
	if (!connectToKext())
	{
		if (load_kext())
		{
			stamp_file(CFSTR("Could not load KEXT"));
			return 1;
		}
		if (!connectToKext())
		{
			stamp_file(CFSTR("Could not connect with KEXT"));
			return 1;
		}
	}
	sleep(1);		// just a little time to let the kernel notification handlers finish
	
	stamp_file(CFSTR("LogKext Daemon starting up"));
	// stamp login file with initial user
	LoginLogoutCallBackFunction(NULL, NULL, NULL);
	
	CFPreferencesAppSynchronize(PREF_DOMAIN);
	
/*********Create Daemon Timer source**********/

	CFRunLoopTimerContext timerContext = { 0 };
	CFRunLoopSourceRef loginLogoutSource;	
    if (InstallLoginLogoutNotifiers(&loginLogoutSource))
		syslog(LOG_ERR,"Error: could not install login notifier");
	else
		CFRunLoopAddSource(CFRunLoopGetCurrent(),loginLogoutSource, kCFRunLoopDefaultMode);

	CFRunLoopTimerRef daemonTimer = CFRunLoopTimerCreate(NULL, 0, TIME_TO_SLEEP, 0, 0, DaemonTimerCallback, &timerContext);
	CFRunLoopAddTimer(CFRunLoopGetCurrent(), daemonTimer, kCFRunLoopCommonModes);

	
	CFRunLoopRun();
	
	stamp_file(CFSTR("Server error: closing Daemon"));	
	CFWriteStreamClose(logStream);
}
コード例 #8
0
void DaemonTimerCallback( CFRunLoopTimerRef timer, void *info )
{
/*********Wait if not logging**********/

	Boolean validKey;
	CFPreferencesAppSynchronize(PREF_DOMAIN);
	CFBooleanRef isLogging = (CFPreferencesGetAppBooleanValue(CFSTR("Logging"),PREF_DOMAIN,&validKey))?kCFBooleanTrue:kCFBooleanFalse;
	if (!validKey)
	{
		isLogging = kCFBooleanTrue;
		CFPreferencesSetAppValue(CFSTR("Logging"),isLogging,PREF_DOMAIN);
	}
	
	if (!CFBooleanGetValue(isLogging))
		return;
	
/********* Check the buffer **********/

	int buffsize=0;
	int keys=0;
	getBufferSizeAndKeys(&buffsize,&keys);

	#ifdef LK_DEBUG
		syslog(LOG_ERR,"Buffsize %d, Keys %d.",buffsize,keys);	
	#endif

	if (!keys)			// no keyboards logged
		return;

	if (buffsize < MAX_BUFF_SIZE/10)
		return;

/********* Get the buffer **********/

	CFStringRef the_buffer = getBuffer();
	
/********* Check defaults/file **********/		

	CFStringRef curPathName = (CFStringRef)CFPreferencesCopyAppValue(PATHNAME_PREF_KEY,PREF_DOMAIN);
	if (!curPathName)		// path has been deleted
	{
		pathName = CFSTR(DEFAULT_PATHNAME);
		CFPreferencesSetAppValue(PATHNAME_PREF_KEY,pathName,PREF_DOMAIN);

		logStream = CFWriteStreamCreateWithFile(kCFAllocatorDefault,CFURLCreateWithFileSystemPath(kCFAllocatorDefault,pathName,kCFURLPOSIXPathStyle,false));

		if (!logStream)
		{
			syslog(LOG_ERR,"Error: Couldn't open file stream while running.");	
			return;
		}
	}
	else if (CFStringCompare(curPathName,pathName,0)!=kCFCompareEqualTo)	// path has changed
	{
		pathName = curPathName;			
		logStream = CFWriteStreamCreateWithFile(kCFAllocatorDefault,CFURLCreateWithFileSystemPath(kCFAllocatorDefault,pathName,kCFURLPOSIXPathStyle,false));

		if (!logStream)
		{
			syslog(LOG_ERR,"Error: Couldn't open file stream while running.");	
			return;
		}
		
		CFDataDeleteBytes(encrypt_buffer,CFRangeMake(0,CFDataGetLength(encrypt_buffer)));
	}

	if (!fileExists(pathName))		// when file is deleted, we resync the encryption & keymap preferences
	{
		CFPreferencesAppSynchronize(PREF_DOMAIN);
		updateEncryption();
		updateKeymap();

		logStream = CFWriteStreamCreateWithFile(kCFAllocatorDefault,CFURLCreateWithFileSystemPath(kCFAllocatorDefault,pathName,kCFURLPOSIXPathStyle,false));
		if (!logStream)
		{
			syslog(LOG_ERR,"Error: Couldn't open file stream while running.");	
			return;
		}

		stamp_file(CFSTR("LogKext Daemon created new logfile"));
	}

	if (outOfSpace(pathName))
	{
		stamp_file(CFSTR("Not enough disk space remaining!"));
		return;
	}

/********* Finally, write the buffer **********/

	write_buffer(the_buffer);
	CFRelease(the_buffer);		
	
	return;
}
コード例 #9
0
ファイル: mac-quicktime.cpp プロジェクト: alesegdia/snes-sdk
void MacQTVideoConfig(WindowRef parent)
{
	OSStatus			err;
	ComponentInstance	ci;
	
	if (running)
		return;

	MacQTOpenVideoComponent(&ci);
	
	long	flag;

	flag = scListEveryCodec | scAllowZeroKeyFrameRate | scDisableFrameRateItem;
	err = SCSetInfo(ci, scPreferenceFlagsType, &flag);
	
	PicHandle   pict;
	Rect		rct;
	int			width, height;

	width  = IPPU.RenderedScreenWidth;
	height = IPPU.RenderedScreenHeight;
	pict = GetScreenAsPicHandle(width, height, width, height);
	HNoPurge((Handle) pict);
	rct.left   = (width  - scTestImageWidth)  >> 1;
	rct.top    = (height - scTestImageHeight) >> 1;
	rct.right  = rct.left + scTestImageWidth;
	rct.bottom = rct.top  + scTestImageHeight;
	err = SCSetTestImagePictHandle(ci, pict, &rct, scPreferCropping);
	
	SCWindowSettings	ws;
	
	ws.size          = sizeof(SCWindowSettings);
	ws.windowRefKind = scWindowRefKindCarbon;
	ws.parentWindow  = parent;
	
	err = SCSetInfo(ci, scWindowOptionsType, &ws);

	err = SCRequestSequenceSettings(ci);
	if (err == noErr)
	{
		CFDataRef	data;
		Handle		hdl;

		err = SCGetInfo(ci, scSettingsStateType, &hdl);
		if (err == noErr)
		{
			HLock(hdl);
			data = CFDataCreate(kCFAllocatorDefault, (unsigned char *) *hdl, GetHandleSize(hdl));
			if (data)
			{
				CFPreferencesSetAppValue(CFSTR("QTVideoSetting"), data, kCFPreferencesCurrentApplication);
				CFRelease(data);
			}
			
			DisposeHandle(hdl);
		}
	}
	
	MacQTCloseVideoComponent(ci);
	
	KillPicture(pict);
}