summaryrefslogtreecommitdiffstats
path: root/macos.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2014-05-18 14:13:23 +0900
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-05-19 20:12:58 +0900
commitc4899aa8f1ba9ec97818bc138c0dd63f4d02b683 (patch)
tree9bc639fbf5e41051bdd545a50d4f5b07666aa7d9 /macos.c
parent047032ee46ef00d924dea0ee68b0f2726975fcd6 (diff)
downloadsubsurface-c4899aa8f1ba9ec97818bc138c0dd63f4d02b683.tar.gz
Download from dive computer: Fix the broken selection of devices
The old code was completely bogus - it's confused about what the variable 'i' is counting. This also let's us select the Uemis mount point by default if that's the only valid "device" that we found. Compile tested on Windows, untested on Mac. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'macos.c')
-rw-r--r--macos.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/macos.c b/macos.c
index 8b2f122dc..b75ddbf6f 100644
--- a/macos.c
+++ b/macos.c
@@ -47,7 +47,7 @@ const char *system_default_filename(void)
int enumerate_devices(device_callback_t callback, void *userdata, int dc_type)
{
- int index = -1;
+ int index = -1, entries = 0;
DIR *dp = NULL;
struct dirent *ep = NULL;
size_t i;
@@ -75,7 +75,8 @@ int enumerate_devices(device_callback_t callback, void *userdata, int dc_type)
}
callback(filename, userdata);
if (is_default_dive_computer_device(filename))
- index = i;
+ index = entries;
+ entries++;
break;
}
}
@@ -84,6 +85,7 @@ int enumerate_devices(device_callback_t callback, void *userdata, int dc_type)
}
if (dc_type != DC_TYPE_SERIAL) {
const char *dirname = "/Volumes";
+ int num_uemis = 0;
dp = opendir(dirname);
if (dp == NULL) {
return -1;
@@ -99,11 +101,15 @@ int enumerate_devices(device_callback_t callback, void *userdata, int dc_type)
}
callback(filename, userdata);
if (is_default_dive_computer_device(filename))
- index = i;
+ index = entries;
+ entries++;
+ num_uemis++;
break;
}
}
closedir(dp);
+ if (num_uemis == 1 && entries == 1) /* if we find exactly one entry and that's a Uemis, select it */
+ index = 0;
}
return index;
}