summaryrefslogtreecommitdiffstats
path: root/windows.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2014-05-18 13:29:40 +0900
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-05-19 20:12:55 +0900
commit047032ee46ef00d924dea0ee68b0f2726975fcd6 (patch)
treeb3a8c1120e2bc873e6996842fba7a820a7a0c282 /windows.c
parent6d42a99e7f6d3ea3a9c977604c7cc980a4215f18 (diff)
downloadsubsurface-047032ee46ef00d924dea0ee68b0f2726975fcd6.tar.gz
Divecomputer download: try to offer only those devices that make sense
If the user selects a Uemis divecomputer, don't show serial devices. If the user selects a serial divecomputer, don't show the Uemis filesystem. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'windows.c')
-rw-r--r--windows.c104
1 files changed, 68 insertions, 36 deletions
diff --git a/windows.c b/windows.c
index d2ba119ed..da7e9005b 100644
--- a/windows.c
+++ b/windows.c
@@ -36,56 +36,88 @@ const char *system_default_filename(void)
return buffer;
}
-int enumerate_devices(device_callback_t callback, void *userdata)
+int enumerate_devices(device_callback_t callback, void *userdata, int dc_type)
{
- // 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;
- }
DWORD i;
- for (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 (dc_type != DC_TYPE_UEMIS) {
+ // Open the registry key.
+ HKEY hKey;
+ LONG rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\SERIALCOMM", 0, KEY_QUERY_VALUE, &hKey);
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)) {
+ // 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 (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;
+ }
- // Null terminate the string.
- data[data_len] = 0;
+ // Ignore non-string values.
+ if (type != REG_SZ)
+ continue;
- callback(data, userdata);
- index++;
- if (is_default_dive_computer_device(name))
- index = i;
+ // 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(name))
+ index = i;
+ }
+
+ RegCloseKey(hKey);
}
+ if (dc_type != DC_TYPE_SERIAL) {
+ int i;
+ const int bufdef = 512;
+ const char *dlabels[] = {"UEMISSDA", NULL};
+ char bufname[bufdef], bufval[bufdef], *p;
+ DWORD bufname_len;
+
+ /* add drive letters that match labels */
+ memset(bufname, 0, bufdef);
+ bufname_len = bufdef;
+ if (GetLogicalDriveStringsA(bufname_len, bufname)) {
+ p = bufname;
- RegCloseKey(hKey);
+ while (*p) {
+ memset(bufval, 0, bufdef);
+ if (GetVolumeInformationA(p, bufval, bufdef, NULL, NULL, NULL, NULL, 0)) {
+ for (i = 0; dlabels[i] != NULL; i++)
+ if (!strcmp(bufval, dlabels[i])) {
+ char data[512];
+ snprintf(data, sizeof(data), "%s (%s)", p, dlabels[i]);
+ callback(data, userdata);
+ if (is_default_dive_computer_device(p))
+ index = i;
+ i++;
+ }
+ }
+ p = &p[strlen(p) + 1];
+ }
+ }
+ }
return index;
}