Beispiel #1
0
void AppearanceAlert (AlertType type, int stringID1, int stringID2)
{
	OSStatus		err;
	DialogRef		dialog;
	DialogItemIndex	outItemHit;
	CFStringRef		key1, key2, mes1, mes2;
	char			label1[32], label2[32];

	sprintf(label1, "AlertMes_%02d", stringID1);
	sprintf(label2, "AlertMes_%02d", stringID2);

	key1 = CFStringCreateWithCString(kCFAllocatorDefault, label1, CFStringGetSystemEncoding());
	key2 = CFStringCreateWithCString(kCFAllocatorDefault, label2, CFStringGetSystemEncoding());

	if (key1) mes1 = CFCopyLocalizedString(key1, "mes1");	else mes1 = NULL;
	if (key2) mes2 = CFCopyLocalizedString(key2, "mes2");	else mes2 = NULL;

	PlayAlertSound();

	err = CreateStandardAlert(type, mes1, mes2, NULL, &dialog);
	err = RunStandardAlert(dialog, NULL, &outItemHit);

	if (key1) CFRelease(key1);
	if (key2) CFRelease(key2);
	if (mes1) CFRelease(mes1);
	if (mes2) CFRelease(mes2);
}
Beispiel #2
0
void GetStrPreference (const char *name, char *out, const char *defaut, const int bufferSize)
{
    if ((out==NULL) || (name==NULL)) return;

    if (defaut != NULL)
    {
        strncpy(out,defaut,bufferSize-1);
        out[bufferSize-1]=0;
    }
    else out[0]=0;

    CFStringRef nom = CFStringCreateWithCString (NULL,name,CFStringGetSystemEncoding());

    if (nom != NULL)
    {
        CFStringRef value = (CFStringRef)CFPreferencesCopyAppValue(nom,kCFPreferencesCurrentApplication);

        if (value != NULL)
        {
            if (CFGetTypeID(value) == CFStringGetTypeID ())
            {
                if ((!CFStringGetCString (value, out, bufferSize, CFStringGetSystemEncoding())) && (defaut != NULL))
                    strcpy(out,defaut);
            }
            CFRelease(value);
        }
        CFRelease(nom);
    }
}
Beispiel #3
0
QueryData genUsb() {
  QueryData results;

    CFMutableDictionaryRef matchingDict;
    io_iterator_t iter;
    kern_return_t kr;
    io_service_t device;
    char vendor[256];
    char product[256];

    matchingDict = IOServiceMatching(kIOUSBDeviceClassName);
    if (matchingDict == NULL)
    { return results; }

    kr = IOServiceGetMatchingServices(kIOMasterPortDefault, matchingDict, &iter);
    if (kr != KERN_SUCCESS)
    {  return results; }

    while ((device = IOIteratorNext(iter)))
    {
        Row r

        //Get the vendor of the device;
        CFMutableDictionaryRef vendor_dict = NULL;
        IORegistryEntryCreateCFProperties(device, &vendor_dict, kCFAllocatorDefault, kNilOptions);
        CFTypeRef vendor_obj = CFDictionaryGetValue(vendor_dict, CFSTR("USB Vendor Name"));
        if(vendor_obj) {
           CFStringRef cf_vendor  =  CFStringCreateCopy(kCFAllocatorDefault, (CFStringRef)vendor_obj);
           CFStringGetCString(cf_vendor, vendor, 256, CFStringGetSystemEncoding());
           r["manufacturer"] = vendor;
        }

        //Get the product name of the device
        CFMutableDictionaryRef product_dict = NULL;
        IORegistryEntryCreateCFProperties(device, &product_dict, kCFAllocatorDefault, kNilOptions);
        CFTypeRef product_obj = CFDictionaryGetValue(product_dict, CFSTR("USB Product Name"));
        if(product_obj) {
           CFStringRef cf_product  =  CFStringCreateCopy(kCFAllocatorDefault, (CFStringRef)product_obj);
           CFStringGetCString(cf_product, product, 256, CFStringGetSystemEncoding());
           r["product"] = product;
        }

         //Lets make sure we don't have an empty product & manufacturer
        if(r["product"] != "" || r["manufacturer"] != "") {
          results.push_back(r);
        }

        IOObjectRelease(device);
    }

  IOObjectRelease(iter);
  return results;
}
Beispiel #4
0
void SetStrPreference (const char *name, const char *value)
{
    CFStringRef nom = CFStringCreateWithCString (NULL,name,CFStringGetSystemEncoding());
    if (nom != NULL)
    {
        CFStringRef val = CFStringCreateWithCString (NULL,value,CFStringGetSystemEncoding());
        if (val != NULL)
        {
            CFPreferencesSetAppValue (nom,val,kCFPreferencesCurrentApplication);
            (void)CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication);
            CFRelease(val);
        }
        CFRelease(nom);
    }
}
static void printCFString(CFStringRef string)
{
    CFIndex	len;
    char *	buffer;

    len = CFStringGetMaximumSizeForEncoding(CFStringGetLength(string),
	    CFStringGetSystemEncoding()) + sizeof('\0');
    buffer = malloc(len);
    if (buffer && CFStringGetCString(string, buffer, len,
                                  CFStringGetSystemEncoding()) )
	printf(buffer);

    if (buffer)
	free(buffer);
}
Beispiel #6
0
/* lifted from portmidi */
static char *get_ep_name(MIDIEndpointRef ep)
{
	MIDIEntityRef entity;
	MIDIDeviceRef device;
	CFStringRef endpointName = NULL, deviceName = NULL, fullName = NULL;
	CFStringEncoding defaultEncoding;
	char* newName;

	/* get the default string encoding */
	defaultEncoding = CFStringGetSystemEncoding();

	/* get the entity and device info */
	MIDIEndpointGetEntity(ep, &entity);
	MIDIEntityGetDevice(entity, &device);

	/* create the nicely formated name */
	MIDIObjectGetStringProperty(ep, kMIDIPropertyName, &endpointName);
	MIDIObjectGetStringProperty(device, kMIDIPropertyName, &deviceName);
	if (deviceName != NULL) {
		fullName = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@: %@"),
						deviceName, endpointName);
	} else {
		fullName = endpointName;
	}

	/* copy the string into our buffer */
	newName = (char*)mem_alloc(CFStringGetLength(fullName) + 1);
	CFStringGetCString(fullName, newName, CFStringGetLength(fullName) + 1,
			defaultEncoding);

	/* clean up */
	if (fullName && !deviceName) CFRelease(fullName);

	return newName;
}
int
main(void)
{
    kern_return_t          kr;
    io_iterator_t          io_hw_sensors;
    io_service_t           io_hw_sensor;
    CFMutableDictionaryRef sensor_properties;
    CFStringEncoding       systemEncoding = CFStringGetSystemEncoding();
   
    kr = IOServiceGetMatchingServices(kIOMasterPortDefault,
             IOServiceNameMatching("IOHWSensor"), &io_hw_sensors);
   
    while ((io_hw_sensor = IOIteratorNext(io_hw_sensors))) {
        kr = IORegistryEntryCreateCFProperties(io_hw_sensor, &sensor_properties,
                 kCFAllocatorDefault, kNilOptions);
        if (kr == KERN_SUCCESS)
            printTemperatureSensor(sensor_properties, systemEncoding);
   
        CFRelease(sensor_properties);
        IOObjectRelease(io_hw_sensor);
    }
   
    IOObjectRelease(io_hw_sensors);
   
    exit(kr);
}
CFIndex
CFStringGetMaximumSizeOfFileSystemRepresentation (CFStringRef string)
{
  CFIndex length = CFStringGetLength (string);
  return
    CFStringGetMaximumSizeForEncoding (length, CFStringGetSystemEncoding ());
}
Beispiel #9
0
const CHXString& CHXString::operator =(CFStringRef ref)
{
#ifdef _MAC_CFM
    CFStringEncoding encoding = CFStringGetSystemEncoding();
#else
    CFStringEncoding encoding = kCFStringEncodingUTF8;
#endif

    // we need the string to be canonically decomposed Unicode in case it'll be used as a path on
    // an HFS disk, so we'll make a mutable copy of the string, normalize it, and then encode that as UTF-8

    const CFIndex kNoMaxLength = 0;

    CFMutableStringRef mutableRef = CFStringCreateMutableCopy(kCFAllocatorDefault, kNoMaxLength, ref);

#ifndef __MWERKS__
    // our version of CodeWarrior doesn't have CFStringNormalize in the headers since they are pre-10.2 headers, alas
    CFStringNormalize(mutableRef, kCFStringNormalizationFormD);
#endif

    (void) SetFromCFString(mutableRef, encoding);

    CFRelease(mutableRef);

    return *this;
}
void bluetoothDiscoverySDPCompleteCallback(void *userRefCon, IOBluetoothDeviceRef foundDevRef, IOReturn status)
{
	ConnectivityBluetooth *conn = (ConnectivityBluetooth *) userRefCon;
	IOBluetoothSDPUUIDRef uuid;
	unsigned char uuid_bytes[] = HAGGLE_BLUETOOTH_SDP_UUID;
	
	uuid = IOBluetoothSDPUUIDCreateWithBytes(uuid_bytes, sizeof(uuid_bytes));

	if (uuid == NULL) {
		CM_DBG("Failed to create UUID (%ld)\n", sizeof(uuid_bytes));
	}
	
	CFStringRef nameRef = IOBluetoothDeviceGetName(foundDevRef);

	const char *name = nameRef ? CFStringGetCStringPtr(nameRef, CFStringGetSystemEncoding()) : "PeerBluetoothInterface";
	//IOBluetoothObjectRetain(foundDevRef);
	//memcpy(macaddr, btAddr, BT_ALEN);
	
	const BluetoothDeviceAddress *btAddr = IOBluetoothDeviceGetAddress(foundDevRef);
	BluetoothAddress addr((unsigned char *)btAddr);
	
	BluetoothInterface iface((unsigned char *)btAddr, name, &addr, IFFLAG_UP);
	
	if (IOBluetoothDeviceGetServiceRecordForUUID(foundDevRef, uuid) != NULL) {
		CM_DBG("%s: Found Haggle device %s\n", conn->getName(), addr.getStr());
		
		conn->report_interface(&iface, conn->rootInterface, new ConnectivityInterfacePolicyTTL(2));
	} else {
		CM_DBG("%s: Found non-Haggle device [%s]\n", conn->getName(), addr.getStr());
	}

	IOBluetoothDeviceCloseConnection(foundDevRef);
	IOBluetoothObjectRelease(foundDevRef);
	IOBluetoothObjectRelease(uuid);
}
Beispiel #11
0
static FILE* ios_open_from_bundle(const char path[], const char* perm) {
    // Get a reference to the main bundle
    CFBundleRef mainBundle = CFBundleGetMainBundle();

    // Get a reference to the file's URL
    CFStringRef pathRef = CFStringCreateWithCString(NULL, path, kCFStringEncodingUTF8);
    CFURLRef imageURL = CFBundleCopyResourceURL(mainBundle, pathRef, NULL, NULL);
    CFRelease(pathRef);
    if (!imageURL) {
        return nullptr;
    }

    // Convert the URL reference into a string reference
    CFStringRef imagePath = CFURLCopyFileSystemPath(imageURL, kCFURLPOSIXPathStyle);
    CFRelease(imageURL);

    // Get the system encoding method
    CFStringEncoding encodingMethod = CFStringGetSystemEncoding();

    // Convert the string reference into a C string
    const char *finalPath = CFStringGetCStringPtr(imagePath, encodingMethod);
    FILE* fileHandle = fopen(finalPath, perm);
    CFRelease(imagePath);
    return fileHandle;
}
Beispiel #12
0
void qt_mac_to_pascal_string(const QString &s, Str255 str, TextEncoding encoding, int len)
{
    if(len == -1)
        len = s.length();
#if 0
    UnicodeMapping mapping;
    mapping.unicodeEncoding = CreateTextEncoding(kTextEncodingUnicodeDefault,
                                                 kTextEncodingDefaultVariant,
                                                 kUnicode16BitFormat);
    mapping.otherEncoding = (encoding ? encoding : );
    mapping.mappingVersion = kUnicodeUseLatestMapping;

    UnicodeToTextInfo info;
    OSStatus err = CreateUnicodeToTextInfo(&mapping, &info);
    if(err != noErr) {
        qDebug("Qt: internal: Unable to create pascal string '%s'::%d [%ld]",
               s.left(len).latin1(), (int)encoding, err);
        return;
    }
    const int unilen = len * 2;
    const UniChar *unibuf = (UniChar *)s.unicode();
    ConvertFromUnicodeToPString(info, unilen, unibuf, str);
    DisposeUnicodeToTextInfo(&info);
#else
    Q_UNUSED(encoding);
    CFStringGetPascalString(QCFString(s), str, 256, CFStringGetSystemEncoding());
#endif
}
Beispiel #13
0
int main (int argc, const char * argv[]) {
    
	if (argv[1] != NULL)
	{
		CFDataRef data;
		CFStringRef searchterm = CFStringCreateWithCString(NULL, argv[1],
														   kCFStringEncodingMacRoman);
		CFRange searchRange = CFRangeMake(0, CFStringGetLength(searchterm));
		CFStringRef dictResult = DCSCopyTextDefinition(NULL, searchterm, searchRange);
		CFRelease(searchterm);

		if (dictResult != NULL) {
			data = CFStringCreateExternalRepresentation(NULL, dictResult, CFStringGetSystemEncoding(), '?');
			CFRelease(dictResult);

		}
		if (data != NULL) {
			printf ("%.*s\n\n", (int)CFDataGetLength(data), CFDataGetBytePtr(data));
			CFRelease(data);
		}
		else {
			printf("Could not find word in Dictionary.app.\n");
		}

		return 0;
	}
	else {
		printf("Usage: dictlookup \"word\"\n");
		return 1;
	}

}
static void listClients()
{
    IOHIDEventSystemClientRef eventSystem = IOHIDEventSystemClientCreateWithType(kCFAllocatorDefault, kIOHIDEventSystemClientTypeAdmin, NULL);
    CFIndex     types;
    
    require(eventSystem, exit);
    
    for ( types=kIOHIDEventSystemClientTypeAdmin; types<=kIOHIDEventSystemClientTypeRateControlled; types++ ) {
        CFArrayRef  clients = _IOHIDEventSystemClientCopyClientDescriptions(eventSystem, (IOHIDEventSystemClientType)types);
        CFIndex     index;
        
        if ( !clients )
            continue;
        
        for ( index=0; index<CFArrayGetCount(clients); index++ ) {
            CFStringRef clientDebugDesc = (CFStringRef)CFArrayGetValueAtIndex(clients, index);
            printf("%s\n", CFStringGetCStringPtr(clientDebugDesc, CFStringGetSystemEncoding()));
        }
        
        CFRelease(clients);
    }
    
exit:
    if (eventSystem)
        CFRelease(eventSystem);
}
Beispiel #15
0
char *Bgethomedir(void)
{
#ifdef _WIN32
	TCHAR appdata[MAX_PATH];

	if (SUCCEEDED(SHGetSpecialFolderPathA(NULL, appdata, CSIDL_APPDATA, FALSE)))
		return strdup(appdata);
	return NULL;
#elif defined __APPLE__
	FSRef ref;
	CFStringRef str;
	CFURLRef base;
	char *s;

	if (FSFindFolder(kUserDomain, kVolumeRootFolderType, kDontCreateFolder, &ref) < 0) return NULL;
	base = CFURLCreateFromFSRef(NULL, &ref);
	if (!base) return NULL;
	str = CFURLCopyFileSystemPath(base, kCFURLPOSIXPathStyle);
	CFRelease(base);
	if (!str) return NULL;
	s = (char*)CFStringGetCStringPtr(str,CFStringGetSystemEncoding());
	if (s) s = strdup(s);
	CFRelease(str);
	return s;
#else
	char *e = getenv("HOME");
	if (!e) return NULL;
	return strdup(e);
#endif
}
Beispiel #16
0
void DeinitMultiCart (void)
{
	CFStringRef	keyRef;
	char		key[32];

	for (int i = 0; i < 2; i++)
	{
		sprintf(key, "MultiCartPath_%02d", i);
		keyRef = CFStringCreateWithCString(kCFAllocatorDefault, key, CFStringGetSystemEncoding());
		if (keyRef)
		{
			if (multiCartPath[i])
			{
				CFPreferencesSetAppValue(keyRef, multiCartPath[i], kCFPreferencesCurrentApplication);
				CFRelease(multiCartPath[i]);
			}
			else
				CFPreferencesSetAppValue(keyRef, NULL, kCFPreferencesCurrentApplication);

			CFRelease(keyRef);
		}
	}

	CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication);
}
Beispiel #17
0
static void getDeviceInfo(io_object_t hidDevice, CFMutableDictionaryRef hidProperties, struct deviceRecord *deviceRec)
{
	CFMutableDictionaryRef	usbProperties = 0;
	io_registry_entry_t		parent1, parent2;
	CFTypeRef					refCF = 0;

	if ((!IORegistryEntryGetParentEntry(hidDevice, kIOServicePlane, &parent1)) &&
		(!IORegistryEntryGetParentEntry(parent1, kIOServicePlane, &parent2)) &&
		(!IORegistryEntryCreateCFProperties(parent2, &usbProperties, kCFAllocatorDefault, kNilOptions)))
	{
		if (usbProperties)
		{
			refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDSerialNumberKey));

			if (refCF)
			{
				if (CFStringGetCString((const __CFString *) refCF,
					(char *) deviceRec->serial, 256, CFStringGetSystemEncoding()))
				{
					strcpy(PK2UnitIDString, (const char *) deviceRec->serial);
					PK2UnitIDString[14] = 0; // ensure termination
				}
				else if (verbose)
					printf("Cannot get UnitID from descriptor.\n");
			}
		}
		else if (verbose)
			printf("Cannot get usb properties.\n");

		CFRelease(usbProperties);
		IOObjectRelease(parent2);
		IOObjectRelease(parent1);
	}
}
Beispiel #18
0
char *Bgetsupportdir(int global)
{
#ifndef __APPLE__
	return Bgethomedir();
#else
#if LOWANG_IOS
    return Bgethomedir();
#else
	FSRef ref;
	CFStringRef str;
	CFURLRef base;
	char *s;
	
	if (FSFindFolder(global ? kLocalDomain : kUserDomain,
					 kApplicationSupportFolderType,
					 kDontCreateFolder, &ref) < 0) return NULL;
	base = CFURLCreateFromFSRef(NULL, &ref);
	if (!base) return NULL;
	str = CFURLCopyFileSystemPath(base, kCFURLPOSIXPathStyle);
	CFRelease(base);
	if (!str) return NULL;
	s = (char*)CFStringGetCStringPtr(str,CFStringGetSystemEncoding());
	if (s) s = strdup(s);
	CFRelease(str);
	return s;
#endif
#endif
}
Beispiel #19
0
QString WebService::installPrefix() const {
#ifndef Q_OS_WIN32DOWS
  QDir binaryPath(QCoreApplication::applicationDirPath());
  if (binaryPath.cdUp()) {
    return QDir::toNativeSeparators(binaryPath.canonicalPath());
  }
#endif

#ifdef Q_OS_LINUX
  QString basePath(qgetenv("PLEXYDESK_DIR"));
  if (basePath.isEmpty() || basePath.isNull()) {
    return PLEXYPREFIX;
  }

  return basePath;
#endif

#ifdef Q_OS_MAC
  CFURLRef appUrlRef = CFBundleCopyBundleURL(CFBundleGetMainBundle());
  CFStringRef macPath =
      CFURLCopyFileSystemPath(appUrlRef, kCFURLPOSIXPathStyle);
  const char *pathPtr =
      CFStringGetCStringPtr(macPath, CFStringGetSystemEncoding());
  CFRelease(appUrlRef);
  CFRelease(macPath);
  return QLatin1String(pathPtr) + QString("/Contents/");
#endif

  return QString();
}
QStringList findResourceFiles(const QString& dirName, const QString& filter, QStringList additionalPreferredPaths) {
	QStringList searchFiles;
	QString dn = dirName;
	if (dn.endsWith('/')||dn.endsWith(QDir::separator())) dn=dn.left(dn.length()-1); //remove / at the end
	if (!dn.startsWith('/')&&!dn.startsWith(QDir::separator())) dn="/"+dn; //add / at beginning
	searchFiles<<":"+dn; //resource fall back
	searchFiles.append(additionalPreferredPaths);
	searchFiles<<QCoreApplication::applicationDirPath() + dn; //windows new
	// searchFiles<<QCoreApplication::applicationDirPath() + "/data/"+fileName; //windows new

#if !defined(PREFIX)
#define PREFIX ""
#endif

#if defined( Q_WS_X11 )
	searchFiles<<PREFIX"/share/texstudio"+dn; //X_11
	searchFiles<<PREFIX"/share/texmakerx"+dn; //X_11
#endif
#ifdef Q_WS_MAC
	CFURLRef appUrlRef = CFBundleCopyBundleURL(CFBundleGetMainBundle());
	CFStringRef macPath = CFURLCopyFileSystemPath(appUrlRef,
												  kCFURLPOSIXPathStyle);
	const char *pathPtr = CFStringGetCStringPtr(macPath,
												CFStringGetSystemEncoding());
	searchFiles<<QString(pathPtr)+"/Contents/Resources"+dn; //Mac
	CFRelease(appUrlRef);
	CFRelease(macPath);
#endif

	QStringList result;
	foreach(const QString& fn, searchFiles) {
		QDir fic(fn);
		if (fic.exists() && fic.isReadable())
			result<< fic.entryList(QStringList(filter),QDir::Files,QDir::Name);
	}
Beispiel #21
0
char const* path_to_file(CFStringRef file, CFStringRef extension)
{
    // Get a reference to the main bundle
    CFBundleRef mainBundle = CFBundleGetMainBundle();
    
    if (mainBundle == NULL) {
        return NULL;
    }
    
    // Get a reference to the file's URL
    CFURLRef imageURL = CFBundleCopyResourceURL(mainBundle,
                                                file,
                                                extension,
                                                NULL);
    
    if (imageURL == NULL) {
        return NULL;
    }
    
    // Convert the URL reference into a string reference
    CFStringRef imagePath = CFURLCopyFileSystemPath(imageURL,
                                                    kCFURLPOSIXPathStyle);
    
    // Get the system encoding method
    CFStringEncoding encodingMethod = CFStringGetSystemEncoding();
    
    // Convert the string reference into a C string
    const char *path = CFStringGetCStringPtr(imagePath, encodingMethod);
    return path;
}
Beispiel #22
0
static OSStatus FindSNESFolder (FSRef *folderRef, char *folderPath, const char *folderName)
{
	OSStatus	err;
	CFURLRef	burl, purl;
	CFStringRef	fstr;
	FSRef		pref;
	UniChar		buffer[PATH_MAX + 1];
	Boolean		r;

	fstr = CFStringCreateWithCString(kCFAllocatorDefault, folderName, CFStringGetSystemEncoding());
	CFStringGetCharacters(fstr, CFRangeMake(0, CFStringGetLength(fstr)), buffer);

	burl = CFBundleCopyBundleURL(CFBundleGetMainBundle());
	purl = CFURLCreateCopyDeletingLastPathComponent(kCFAllocatorDefault, burl);
	r    = CFURLGetFSRef(purl, &pref);

	err = FSMakeFSRefUnicode(&pref, CFStringGetLength(fstr), buffer, kTextEncodingUnicodeDefault, folderRef);
	if (err == dirNFErr || err == fnfErr)
	{
		err = FSCreateDirectoryUnicode(&pref, CFStringGetLength(fstr), buffer, kFSCatInfoNone, NULL, folderRef, NULL, NULL);
		if (err == noErr)
			AddFolderIcon(folderRef, folderName);
	}

	if (err == noErr)
		err = FSRefMakePath(folderRef, (unsigned char *) folderPath, PATH_MAX);

	CFRelease(purl);
	CFRelease(burl);
	CFRelease(fstr);

	return (err);
}
static CFStringRef BIMCreatePortName( const ProcessSerialNumber *inProcessSerialNumber )
{
    CFMutableStringRef	portName;
    CFStringRef		processSerialNumberStringRef;
    Str255		processSerialNumberString;
    Str255		processSerialNumberLowString;

    //  Convert the high and low parts of the process serial number into a string.

    NumToString( inProcessSerialNumber->highLongOfPSN, processSerialNumberString );
    NumToString( inProcessSerialNumber->lowLongOfPSN, processSerialNumberLowString );
    BlockMoveData( processSerialNumberLowString + 1,
                   processSerialNumberString + processSerialNumberString [0] + 1,
                   processSerialNumberLowString [0] );
    processSerialNumberString [0] += processSerialNumberLowString [0];

    //  Create a CFString and append the process serial number string onto the end.

    portName = CFStringCreateMutableCopy( NULL, 255, CFSTR( kBasicServerPortName ) );
    processSerialNumberStringRef = CFStringCreateWithPascalString( NULL,
                                                                   processSerialNumberString,
                                                                   CFStringGetSystemEncoding() );
    CFStringAppend( portName, processSerialNumberStringRef );
    CFRelease( processSerialNumberStringRef );
    return portName;
}
void writePropertyListToFile (CFDataRef data) {
    CFStringRef errorString;

    CFPropertyListRef propertyList = CFPropertyListCreateFromXMLData (NULL, data, kCFPropertyListMutableContainersAndLeaves, &errorString);

    if (errorString == NULL) {
        CFStringRef urlString = CFStringCreateWithCString (NULL, kFilename, CFStringGetSystemEncoding ());

        CFURLRef fileURL = CFURLCreateWithFileSystemPath (NULL, urlString, kCFURLPOSIXPathStyle, FALSE);

        CFWriteStreamRef stream = CFWriteStreamCreateWithFile (NULL, fileURL);

        Boolean isOpen = CFWriteStreamOpen (stream);

        CFShow (CFSTR ("Property list (as written to file):"));
        CFShow (propertyList);
  
        CFIndex bytesWritten = CFPropertyListWriteToStream (propertyList, stream, kCFPropertyListXMLFormat_v1_0, NULL);

        CFWriteStreamClose (stream);
    }
    else {
        CFShow (errorString);
        CFRelease (errorString);
    }

    CFRelease (propertyList);
}
Beispiel #25
0
int main(int argc, char *argv[])
{
#ifdef WIN32
    qInstallMsgHandler(myMessageOutput);
#endif
#if defined(Q_OS_MACX)
    // On Mac, switch working directory to resources folder
    CFURLRef pluginRef = CFBundleCopyBundleURL(CFBundleGetMainBundle());
    CFStringRef macPath = CFURLCopyFileSystemPath(pluginRef, kCFURLPOSIXPathStyle);
    QString path( CFStringGetCStringPtr(macPath, CFStringGetSystemEncoding()) );
    path += "/Contents/Resources";
    QDir::setCurrent( path );
    CFRelease(pluginRef);
    CFRelease(macPath);
#elif defined(PO_DATA_REPO)
    QDir::setCurrent(PO_DATA_REPO);
#endif

    srand(time(NULL));
    try
    {
        //HotKeyClass HotKeyEvent;
	QApplication a(argc, argv);
        //a.installEventFilter(&HotKeyEvent);

	/* Names to use later for QSettings */
        QCoreApplication::setApplicationName("Pokeymon-Online");
	QCoreApplication::setOrganizationName("Dreambelievers");

        QSettings settings;
        if (settings.value("language").isNull()) {
            settings.setValue("language", QLocale::system().name().section('_', 0, 0));
        }

        QString locale = settings.value("language").toString();

        QTranslator translator;
        translator.load(QString("trans/translation_") + locale);
        a.installTranslator(&translator);

        /* icon ;) */
#if not defined(Q_OS_MACX)
	a.setWindowIcon(QIcon("db/icon.png"));
#endif

        MainEngine w;

        return a.exec();
    }  /*catch (const std::exception &e) {
        qDebug() << "Caught runtime " << e.what();
    } catch (const QString &s) {
        qDebug() << "Caught string " << s;
    } */catch (const char* s) {
        qDebug() << "Caught const char*  " << s;
    } /*catch (...) {
        qDebug() << "Caught Exception.";
    }*/
    return 0;
}
Beispiel #26
0
static void char2str(char *dst, int size, const UniChar *uni, int unicnt) {

	CFStringRef	cfsr;

	cfsr = CFStringCreateWithCharacters(NULL, uni, unicnt);
	CFStringGetCString(cfsr, dst, size, CFStringGetSystemEncoding());
	CFRelease(cfsr);
}
Beispiel #27
0
CHXCFString::CHXCFString(ConstStr255Param pPString)
{
	mCFStringRef = CFStringCreateWithPascalString(kCFAllocatorDefault, pPString, CFStringGetSystemEncoding());

	check_nonnull(mCFStringRef);
	
	UpdateDebugOnlyString();
}
Beispiel #28
0
CHXCFString::CHXCFString(const char *pCString)
{
	mCFStringRef = CFStringCreateWithCString(kCFAllocatorDefault, pCString, CFStringGetSystemEncoding());

	check_nonnull(mCFStringRef);
	
	UpdateDebugOnlyString();
}
OSStatus DoWriteDataToFile(COMMAND_PROC_ARGUMENTS) {
#pragma unused (auth)
#pragma unused (userData)
	OSStatus retval = noErr;
	
	// Pre-conditions
    
    // userData may be NULL
	assert(request != NULL);
	assert(response != NULL);
    // asl may be NULL
    // aslMsg may be NULL
	
	// Get data to write and assert that it's a CFDataRef
	CFDataRef data = CFDictionaryGetValue(request, CFSTR(kData)) ;
	assert(data != NULL) ;
	assert(CFGetTypeID(data) == CFDataGetTypeID()) ;
	
	// Get path and assert that it's a CFStringRef
	CFStringRef filePath = CFDictionaryGetValue(request, CFSTR(kPath)) ;
	assert(filePath != NULL) ;
	assert(CFGetTypeID(filePath) == CFStringGetTypeID()) ;
	
	CFURLRef url = CFURLCreateWithFileSystemPath (
												  kCFAllocatorDefault,
												  filePath,
												  kCFURLPOSIXPathStyle,
												  false
												  ) ;
	
	SInt32 errorCode ;
	Boolean ok = CFURLWriteDataAndPropertiesToResource (
														url,
														data,
														NULL,
														&errorCode
														) ;
	if (!ok) {
		retval = errorCode ;
	}
	
	asl_log(asl,
			aslMsg,
			ASL_LEVEL_DEBUG,
			"DoWriteDataToFile result ok=%d for %s",
			ok,
			CFStringGetCStringPtr(
								  filePath,
								  CFStringGetSystemEncoding()
								  )
			) ;
	
	// Clean up
	CFQRelease(url) ;
	
	return retval ;
}	
void
AddServiceToPopupMenu(char * serviceType, UInt16 serviceLen, UInt16 * serviceMenuItem)
{
    ControlID 		controlID = { kNSLSample, kServicesTypePopup };
    ControlRef		control;
    CFStringRef		tempService = NULL;
    CFStringRef    	menuText = NULL;
    char		tempServiceString[kMaxTypeNameLength];
    CFComparisonResult	result = -1;
    MenuRef		menu;
    OSStatus		err = noErr;
    short		itemCount, i;
    
    if (serviceType)
    {
        err = GetControlByID(gMainWindow, &controlID, &control);
        if (err == noErr)
        {
            strncpy(tempServiceString, serviceType, serviceLen);
            tempServiceString[serviceLen] = '\0';
            
            for (i = 0; i < serviceLen; i++) tempServiceString[i] = toupper(tempServiceString[i]);
            
            tempService = CFStringCreateWithCString(NULL, tempServiceString, CFStringGetSystemEncoding());
            if (tempService)
            {
                menu = GetControlPopupMenuHandle(control);
                itemCount = CountMenuItems(menu);
                
                for (i = 1; i <= itemCount; i ++)
                {
                    CopyMenuItemTextAsCFString(menu, i , &menuText);
                    if (menuText)
                    {                        
                        result = CFStringCompare(menuText, tempService, kCFCompareCaseInsensitive);
                        if (result == kCFCompareEqualTo)
                        {
                            if (serviceMenuItem) *serviceMenuItem = i;
                            break;
                        }
                    }
                }
                
                if (result != kCFCompareEqualTo)
                {
                    err = AppendMenuItemTextWithCFString(menu, tempService, 0, 0, serviceMenuItem);
                    if (err == noErr)
                    {
                        SetControlMaximum(control, itemCount + 1);
                        if (serviceMenuItem) *serviceMenuItem = itemCount + 1;
                    }
                    CFRelease(tempService);
                }
            }
        }
    }
}