From 2de6f796354ad029e9e786027210fcf1b02868e2 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Fri, 26 Oct 2012 15:52:39 -0700 Subject: Improve the dive computer device selection We try to identify devices that are connected and their matching device names (and mount paths in the case of the Uemis Zurich). Those are presented as a drop down menu to choose from. The user can still override this by simply entering a different device / path name. On Windows this is not functional. How do I find out which drive letter corresponds to the USB device named "UEMISSDA"? Similarly we need code that finds serial ports that are present. For now we once again default to COM3 (so this isn't a step back, but of course it's far from what we want). Signed-off-by: Dirk Hohndel --- windows.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'windows.c') diff --git a/windows.c b/windows.c index 2127614bd..df136085f 100644 --- a/windows.c +++ b/windows.c @@ -119,9 +119,18 @@ void subsurface_close_conf(void) RegCloseKey(hkey); } -const char *subsurface_USB_name() +int subsurface_fill_device_list(GtkListStore *store) { - return "COM3"; + GtkTreeIter iter; + int index = -1; + + /* if we can't find anything, use the default */ + gtk_list_store_append(store, &iter); + gtk_list_store_set(store, &iter, + 0, "COM3", -1); + if (is_default_dive_computer_device("COM3")) + index = 0; + return index; } const char *subsurface_icon_name() -- cgit v1.2.3-70-g09d2 From ab8af0bdeb09f35f0d40b455601995f833811b12 Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" Date: Mon, 29 Oct 2012 21:48:43 +0200 Subject: windows.c: added device retrieval from subsurface_fill_device_list() subsurface_fill_device_list() now goes trough the list of registry entries in the SERIALCOMM key and adds all present values (such as COM1, COM2) to a GtkListStore. Once done the function compares all logic drive label to a static list of known DC labels, such a 'UEMISSDA', which is the only present one at the moment and adds any matching drive letters (e.g. C:\, H:\) to the list store as well. If no serial ports were added or no matching logical drives were found the function simply adds a default entry named "COM1". Signed-off-by: Lubomir I. Ivanov --- windows.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 57 insertions(+), 6 deletions(-) (limited to 'windows.c') diff --git a/windows.c b/windows.c index df136085f..1189fae5a 100644 --- a/windows.c +++ b/windows.c @@ -121,15 +121,66 @@ void subsurface_close_conf(void) int subsurface_fill_device_list(GtkListStore *store) { + const int bufdef = 512; + const char *dlabels[] = {"UEMISSDA", NULL}; + const char *devdef = "COM1"; GtkTreeIter iter; - int index = -1; + int index = -1, nentries = 0, ret, i; + char bufname[bufdef], bufval[bufdef], *p; + DWORD nvalues, bufval_len, bufname_len; + HKEY key; + /* add serial ports */ + ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\SERIALCOMM", + 0, KEY_READ, &key); + if (ret == ERROR_SUCCESS) { + ret = RegQueryInfoKeyA(key, NULL, NULL, NULL, NULL, NULL, NULL, &nvalues, + NULL, NULL, NULL, NULL); + if (ret == ERROR_SUCCESS) + for (i = 0; i < nvalues; i++) { + memset(bufval, 0, bufdef); + memset(bufname, 0, bufdef); + bufname_len = bufdef; + bufval_len = bufdef; + ret = RegEnumValueA(key, i, bufname, &bufname_len, NULL, NULL, bufval, + &bufval_len); + if (ret == ERROR_SUCCESS) { + gtk_list_store_append(store, &iter); + gtk_list_store_set(store, &iter, 0, bufval, -1); + if (is_default_dive_computer_device(bufval)) + index = nentries; + nentries++; + } + } + } + /* add drive letters that match labels */ + memset(bufname, 0, bufdef); + bufname_len = bufdef; + if (GetLogicalDriveStringsA(bufname_len, bufname)) { + p = bufname; + 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])) { + gtk_list_store_append(store, &iter); + gtk_list_store_set(store, &iter, 0, p, -1); + if (is_default_dive_computer_device(p)) + index = nentries; + nentries++; + } + } + p = &p[strlen(p) + 1]; + } + } /* if we can't find anything, use the default */ - gtk_list_store_append(store, &iter); - gtk_list_store_set(store, &iter, - 0, "COM3", -1); - if (is_default_dive_computer_device("COM3")) - index = 0; + if (!nentries) { + gtk_list_store_append(store, &iter); + gtk_list_store_set(store, &iter, + 0, devdef, -1); + if (is_default_dive_computer_device(devdef)) + index = 0; + } return index; } -- cgit v1.2.3-70-g09d2 From ee5c31d2921c0b8970303a1230586391dd06df4a Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Wed, 31 Oct 2012 16:51:04 -0700 Subject: Show drive name after the drive letter on Windows In the device selector when downloading from a divecomputer add the drive name that we have been looking for (so far that's only "UEMISSDA") to the drive letter - this should make it easier for people to figure out why there is a drive letter offered as an option. Signed-off-by: Dirk Hohndel --- windows.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'windows.c') diff --git a/windows.c b/windows.c index 1189fae5a..372e03b14 100644 --- a/windows.c +++ b/windows.c @@ -163,8 +163,10 @@ int subsurface_fill_device_list(GtkListStore *store) if (GetVolumeInformationA(p, bufval, bufdef, NULL, NULL, NULL, NULL, 0)) { for (i = 0; dlabels[i] != NULL; i++) if (!strcmp(bufval, dlabels[i])) { + char name[80]; + snprintf(name, sizeof(name), "%s (%s)", p, dlabels[i]); gtk_list_store_append(store, &iter); - gtk_list_store_set(store, &iter, 0, p, -1); + gtk_list_store_set(store, &iter, 0, name, -1); if (is_default_dive_computer_device(p)) index = nentries; nentries++; -- cgit v1.2.3-70-g09d2