From 67e8e9b5b51e259eda4a669de527111851bab78f Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 29 Sep 2020 22:02:56 -0700 Subject: [PATCH] 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 --- altosuilib/AltosFlashUI.java | 11 ++++++++++- libaltos/libaltos_windows.c | 4 ++++ 2 files changed, 14 insertions(+), 1 deletion(-) 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; -- 2.30.2