diff options
Diffstat (limited to 'windows.c')
-rw-r--r-- | windows.c | 53 |
1 files changed, 53 insertions, 0 deletions
@@ -333,3 +333,56 @@ gboolean subsurface_os_feature_available(os_feature_t f) return TRUE; } } + +int enumerate_devices (device_callback_t callback, void *userdata) +{ + // Open the registry key. + HKEY hKey; + int index = -1; + LONG rc = RegOpenKeyEx (HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\SERIALCOMM", 0, KEY_QUERY_VALUE, &hKey); + if (rc != ERROR_SUCCESS) { + return -1; + } + + // Get the number of values. + DWORD count = 0; + rc = RegQueryInfoKey (hKey, NULL, NULL, NULL, NULL, NULL, NULL, &count, NULL, NULL, NULL, NULL); + if (rc != ERROR_SUCCESS) { + RegCloseKey(hKey); + return -1; + } + + for (DWORD i = 0; i < count; ++i) { + // Get the value name, data and type. + char name[512], data[512]; + DWORD name_len = sizeof (name); + DWORD data_len = sizeof (data); + DWORD type = 0; + rc = RegEnumValue (hKey, i, name, &name_len, NULL, &type, (LPBYTE) data, &data_len); + if (rc != ERROR_SUCCESS) { + RegCloseKey(hKey); + return -1; + } + + // Ignore non-string values. + if (type != REG_SZ) + continue; + + // Prevent a possible buffer overflow. + if (data_len >= sizeof (data)) { + RegCloseKey(hKey); + return -1; + } + + // Null terminate the string. + data[data_len] = 0; + + callback (data, userdata); + index++; + if (is_default_dive_computer_device(filename)) + index = i; + } + + RegCloseKey(hKey); + return index; +} |