From: Keith Packard Date: Wed, 30 Sep 2020 05:02:56 +0000 (-0700) Subject: altosui: Work around lack of actual USB product names on Windows X-Git-Tag: 1.9.5~1^2~1 X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=commitdiff_plain;h=67e8e9b5b51e259eda4a669de527111851bab78f altosui: Work around lack of actual USB product names on Windows Windows doesn't provide an API to get the USB product name for attached devices, it only provides the name listed in the .inf file for each vid/pid. This means that you get 'TeleMega', or 'TeleMega can't isolate the list to the correct version. With this fix, at least the '#2' is stripped off, and the matching code restricts itself to showing only TeleMega files instead of all filenames starting with 'tele'. Signed-off-by: Keith Packard --- diff --git a/altosuilib/AltosFlashUI.java b/altosuilib/AltosFlashUI.java index 33fdb688..6b78aea7 100644 --- a/altosuilib/AltosFlashUI.java +++ b/altosuilib/AltosFlashUI.java @@ -208,9 +208,18 @@ public class AltosFlashUI public AltosHexfileFilter(String usb_product) { int l; + int dash; /* Trim off any trailing variants (1.0a vs 1.0) */ - for (l = usb_product.length(); l > 0; l--) { + for (dash = usb_product.length(); dash > 0; dash--) { + char c = usb_product.charAt(dash-1); + if (c == '-') + break; + } + if (dash == 0) + dash = usb_product.length(); + + for (l = usb_product.length(); l > dash; l--) { char c = usb_product.charAt(l-1); if (c < 'a' || 'z' < c) break; diff --git a/libaltos/libaltos_windows.c b/libaltos/libaltos_windows.c index 0c1f6782..162c85ba 100644 --- a/libaltos/libaltos_windows.c +++ b/libaltos/libaltos_windows.c @@ -246,6 +246,10 @@ altos_list_next(struct altos_list *list, struct altos_device *device) break; } + char *space = strchr(friendlyname, ' '); + if (space) + *space = '\0'; + device->vendor = vid; device->product = pid; device->serial = serial;