mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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 <neolit123@gmail.com>
This commit is contained in:
parent
2de6f79635
commit
ab8af0bdeb
1 changed files with 57 additions and 6 deletions
57
windows.c
57
windows.c
|
@ -121,15 +121,66 @@ void subsurface_close_conf(void)
|
||||||
|
|
||||||
int subsurface_fill_device_list(GtkListStore *store)
|
int subsurface_fill_device_list(GtkListStore *store)
|
||||||
{
|
{
|
||||||
|
const int bufdef = 512;
|
||||||
|
const char *dlabels[] = {"UEMISSDA", NULL};
|
||||||
|
const char *devdef = "COM1";
|
||||||
GtkTreeIter iter;
|
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 */
|
/* if we can't find anything, use the default */
|
||||||
|
if (!nentries) {
|
||||||
gtk_list_store_append(store, &iter);
|
gtk_list_store_append(store, &iter);
|
||||||
gtk_list_store_set(store, &iter,
|
gtk_list_store_set(store, &iter,
|
||||||
0, "COM3", -1);
|
0, devdef, -1);
|
||||||
if (is_default_dive_computer_device("COM3"))
|
if (is_default_dive_computer_device(devdef))
|
||||||
index = 0;
|
index = 0;
|
||||||
|
}
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue