diff options
Diffstat (limited to 'native')
5 files changed, 21 insertions, 60 deletions
diff --git a/native/org.eclipse.cdt.native.serial/META-INF/MANIFEST.MF b/native/org.eclipse.cdt.native.serial/META-INF/MANIFEST.MF index 2c90f7276a3..52b48f6b3df 100644 --- a/native/org.eclipse.cdt.native.serial/META-INF/MANIFEST.MF +++ b/native/org.eclipse.cdt.native.serial/META-INF/MANIFEST.MF @@ -8,3 +8,4 @@ Bundle-RequiredExecutionEnvironment: JavaSE-11 Export-Package: org.eclipse.cdt.serial Automatic-Module-Name: org.eclipse.cdt.native.serial Bundle-Localization: plugin +Require-Bundle: org.eclipse.cdt.core.native;bundle-version="6.0.100" diff --git a/native/org.eclipse.cdt.native.serial/native_src/include/org_eclipse_cdt_serial_SerialPort.h b/native/org.eclipse.cdt.native.serial/native_src/include/org_eclipse_cdt_serial_SerialPort.h index d5da82fce57..44505c12fff 100644 --- a/native/org.eclipse.cdt.native.serial/native_src/include/org_eclipse_cdt_serial_SerialPort.h +++ b/native/org.eclipse.cdt.native.serial/native_src/include/org_eclipse_cdt_serial_SerialPort.h @@ -50,13 +50,6 @@ JNIEXPORT void JNICALL Java_org_eclipse_cdt_serial_SerialPort_write0(JNIEnv *, j */ JNIEXPORT void JNICALL Java_org_eclipse_cdt_serial_SerialPort_write1(JNIEnv *, jobject, jlong, jbyteArray, jint, jint); -/* - * Class: org_eclipse_cdt_serial_SerialPort - * Method: getPortName - * Signature: (I)Ljava/lang/String; - */ -JNIEXPORT jstring JNICALL Java_org_eclipse_cdt_serial_SerialPort_getPortName(JNIEnv *, jclass, jint); - #ifdef __cplusplus } #endif diff --git a/native/org.eclipse.cdt.native.serial/native_src/serial.c b/native/org.eclipse.cdt.native.serial/native_src/serial.c index ec42c9bddc2..91943f5c85a 100644 --- a/native/org.eclipse.cdt.native.serial/native_src/serial.c +++ b/native/org.eclipse.cdt.native.serial/native_src/serial.c @@ -520,38 +520,3 @@ JNIEXPORT void JNICALL FUNC(write1)(JNIEnv *env, jobject jobj, jlong jhandle, jb CloseHandle(olp.hEvent); #endif } - -#ifdef __MINGW32__ -JNIEXPORT jstring FUNC(getPortName)(JNIEnv *env, jclass cls, jint i) { - HKEY key; - - if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"HARDWARE\\DEVICEMAP\\SERIALCOMM", 0, KEY_READ, &key) != ERROR_SUCCESS) { - // There are none - return NULL; - } - - wchar_t name[256]; - DWORD len = sizeof(name); - LONG rc = RegEnumValue(key, (DWORD)i, name, &len, NULL, NULL, NULL, NULL); - if (rc != ERROR_SUCCESS) { - if (rc != ERROR_NO_MORE_ITEMS) { - throwIOException(env, "Can not enum value"); - } - RegCloseKey(key); - return NULL; - } - - wchar_t value[256]; - DWORD type; - len = sizeof(value); - if (RegQueryValueEx(key, name, NULL, &type, (BYTE *)value, &len) != ERROR_SUCCESS) { - throwIOException(env, "Can not query value"); - RegCloseKey(key); - return NULL; - } - - jstring result = (*env)->NewString(env, (jchar *)value, (jsize)wcslen(value)); - RegCloseKey(key); - return result; -} -#endif diff --git a/native/org.eclipse.cdt.native.serial/os/win32/x86_64/serial.dll b/native/org.eclipse.cdt.native.serial/os/win32/x86_64/serial.dll Binary files differindex c4cc3e47a28..a37480b7cc6 100755 --- a/native/org.eclipse.cdt.native.serial/os/win32/x86_64/serial.dll +++ b/native/org.eclipse.cdt.native.serial/os/win32/x86_64/serial.dll diff --git a/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/SerialPort.java b/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/SerialPort.java index ef18b1291d0..80970dafe25 100644 --- a/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/SerialPort.java +++ b/native/org.eclipse.cdt.native.serial/src/org/eclipse/cdt/serial/SerialPort.java @@ -28,6 +28,7 @@ import java.util.Map; import java.util.regex.Pattern; import org.eclipse.cdt.serial.internal.Messages; +import org.eclipse.cdt.utils.WindowsRegistry; /** * @since 5.8 @@ -223,8 +224,6 @@ public class SerialPort { private native void write1(long handle, byte[] b, int off, int len) throws IOException; - private static native String getPortName(int i) throws IOException; - private static String[] listDevs(final Pattern pattern) { File dev = new File("/dev"); //$NON-NLS-1$ File[] files = dev.listFiles(new FilenameFilter() { @@ -257,24 +256,27 @@ public class SerialPort { } else if (osName.equals("Linux")) { //$NON-NLS-1$ return listDevs(Pattern.compile("(ttyUSB|ttyACM|ttyS).*")); //$NON-NLS-1$ } else if (osName.startsWith("Windows")) { //$NON-NLS-1$ - List<String> ports = new ArrayList<>(); - int i = 0; - String name = null; - do { - try { - name = getPortName(i++); - if (name != null) { - ports.add(name); + final WindowsRegistry registry = WindowsRegistry.getRegistry(); + if (registry != null) { + final String subKey = "HARDWARE\\DEVICEMAP\\SERIALCOMM"; //$NON-NLS-1$ + + List<String> ports = new ArrayList<>(); + int i = 0; + String valueName = null; + String value = null; + do { + valueName = registry.getLocalMachineValueName(subKey, i++); + if (valueName != null) { + value = registry.getLocalMachineValue(subKey, valueName); + if (value != null) { + ports.add(value); + } } - } catch (IOException e) { - // TODO log the exception - e.printStackTrace(); - } - } while (name != null); - return ports.toArray(new String[ports.size()]); - } else { - return new String[0]; + } while (valueName != null && value != null); + return ports.toArray(new String[ports.size()]); + } } + return new String[0]; } /** |