altosui: Work around lack of actual USB product names on Windows
authorKeith Packard <keithp@keithp.com>
Wed, 30 Sep 2020 05:02:56 +0000 (22:02 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 30 Sep 2020 05:07:22 +0000 (22:07 -0700)
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 <keithp@keithp.com>
altosuilib/AltosFlashUI.java
libaltos/libaltos_windows.c

index 33fdb6887238f8e530a71f7954a7d6b068fb54ba..6b78aea7f69a2706a3e2d439159ec2ecfe42a6f5 100644 (file)
@@ -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;
index 0c1f6782fd58f167be01d53a112dede4d04a426f..162c85bab8fa6aa658479017bb920395fb678e8a 100644 (file)
@@ -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;