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>
This commit is contained in:
Dirk Hohndel 2014-05-18 13:29:40 +09:00
parent 6d42a99e7f
commit 047032ee46
7 changed files with 178 additions and 111 deletions

106
windows.c
View file

@ -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) {
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 (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;
// Ignore non-string values.
if (type != REG_SZ)
continue;
// Prevent a possible buffer overflow.
if (data_len >= sizeof(data)) {
RegCloseKey(hKey);
return -1;
// 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;
}
// 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;
RegCloseKey(hKey);
/* 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])) {
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;
}