OSDN Git Service

fixed issue 1199, converting a CFStringRef to a cstring seems to be black magic....
authorbadlogic <contact@badlogicgames.com>
Sun, 27 Jan 2013 17:55:17 +0000 (18:55 +0100)
committerbadlogic <contact@badlogicgames.com>
Sun, 27 Jan 2013 17:55:17 +0000 (18:55 +0100)
extensions/gdx-controllers/gdx-controllers-desktop/jni/ois-v1-4svn/src/mac/MacHIDManager.cpp
extensions/gdx-controllers/gdx-controllers-desktop/src/com/badlogic/gdx/controllers/desktop/DesktopControllersBuild.java

index a0c0537..c6cd96e 100644 (file)
@@ -205,23 +205,56 @@ void MacHIDManager::iterateAndOpenDevices(io_iterator_t iterator)
        IOObjectRelease(iterator);
 }
 
+const char* getCString(CFStringRef cfString) {
+       const char *useUTF8StringPtr = NULL;
+       UInt8 *freeUTF8StringPtr = NULL;
+
+       CFIndex stringLength = CFStringGetLength(cfString), usedBytes = 0L;
+
+       if ((useUTF8StringPtr = CFStringGetCStringPtr(cfString, kCFStringEncodingUTF8)) == NULL) {
+               if ((freeUTF8StringPtr = (UInt8*)malloc(stringLength + 1L)) != NULL) {
+                       CFStringGetBytes(cfString, CFRangeMake(0L, stringLength),
+                                       kCFStringEncodingUTF8, '?', false, freeUTF8StringPtr,
+                                       stringLength, &usedBytes);
+                       freeUTF8StringPtr[usedBytes] = 0;
+                       useUTF8StringPtr = (const char *) freeUTF8StringPtr;
+               }
+       }
+
+       return useUTF8StringPtr;
+}
+
 //------------------------------------------------------------------------------------------------------//
 HidInfo* MacHIDManager::enumerateDeviceProperties(CFMutableDictionaryRef propertyMap)
 {
        HidInfo* info = new HidInfo();
        
        info->type = OISJoyStick;
-       
+
        CFStringRef str = getDictionaryItemAsRef<CFStringRef>(propertyMap, kIOHIDManufacturerKey);
-       if (str)
-               info->vendor = CFStringGetCStringPtr(str, CFStringGetSystemEncoding());
-       
+       if (str) {
+               const char* str_c = getCString(str);
+               if(str_c) {
+                       info->vendor = str_c;
+                       free((char*)str_c);
+               } else {
+                       info->vendor = "Unknown Vendor";
+               }
+       }
+
        str = getDictionaryItemAsRef<CFStringRef>(propertyMap, kIOHIDProductKey);
-       if (str)
-               info->productKey = CFStringGetCStringPtr(str, CFStringGetSystemEncoding());
-       
+       if (str) {
+               const char* str_c = getCString(str);
+               if(str_c) {
+                       info->productKey = str_c;
+                       free((char*)str_c);
+               } else {
+                       info->productKey = "Unknown Product";
+               }
+       }
+
        info->combinedKey = info->vendor + " " + info->productKey;
-       
+
        //Go through all items in this device (i.e. buttons, hats, sticks, axes, etc)
        CFArrayRef array = getDictionaryItemAsRef<CFArrayRef>(propertyMap, kIOHIDElementKey);
        if (array)
index 10e7eaa..9a1888e 100644 (file)
@@ -86,7 +86,7 @@ public class DesktopControllersBuild {
                mac.libraries = "-framework CoreServices -framework Carbon -framework IOKit -framework Cocoa";
                
                new AntScriptGenerator().generate(buildConfig, win32home, win32, win64, lin32, lin64, mac);
-               if(!BuildExecutor.executeAnt("jni/build-macosx32.xml", "-Dhas-compiler=true -v clean postcompile")) {
+               if(!BuildExecutor.executeAnt("jni/build-macosx32.xml", "-Dhas-compiler=true -v postcompile")) {
                        throw new Exception("build failed");
                }
                BuildExecutor.executeAnt("jni/build.xml", "pack-natives");