From: Keith Packard Date: Wed, 22 Aug 2018 07:56:25 +0000 (-0700) Subject: altosuilib: Show a more useful message when the flash target device is unknown X-Git-Tag: 1.8.7~3^2~56 X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=commitdiff_plain;h=75420fecbc76ab718661718ada249673e139a29d;ds=sidebyside altosuilib: Show a more useful message when the flash target device is unknown The flashing code uses the new symbol table to find information in the existing device; if they don't match at all, there won't be anything about the target device known. Tell the user this, rather than displaying mystic information (or crashing). Signed-off-by: Keith Packard --- diff --git a/altosuilib/AltosFlashUI.java b/altosuilib/AltosFlashUI.java index d6c7a16f..6dc80272 100644 --- a/altosuilib/AltosFlashUI.java +++ b/altosuilib/AltosFlashUI.java @@ -278,6 +278,12 @@ public class AltosFlashUI } boolean rom_config_matches (AltosRomconfig a, AltosRomconfig b) { + if (a == null || b == null) + return (a == null && b == null); + + if (!a.valid || !b.valid) + return false; + if (a.usb_id != null && b.usb_id != null && (a.usb_id.vid != b.usb_id.vid || a.usb_id.pid != b.usb_id.pid)) @@ -294,16 +300,27 @@ public class AltosFlashUI AltosRomconfig new_config; if (!rom_config_matches(existing_config, image_config)) { - int ret = JOptionPane.showConfirmDialog(this, - String.format("Device is %04x:%04x %s\nImage is %04x:%04x %s\nFlash anyways?", - existing_config.usb_id.vid, - existing_config.usb_id.pid, - existing_config.usb_product, - image_config.usb_id.vid, - image_config.usb_id.pid, - image_config.usb_product), - "Image doesn't match Device", - JOptionPane.YES_NO_OPTION); + int ret; + if (existing_config == null || !existing_config.valid) { + ret = JOptionPane.showConfirmDialog(this, + String.format("Cannot determine target device type\nImage is %04x:%04x %s\nFlash anyways?", + image_config.usb_id.vid, + image_config.usb_id.pid, + image_config.usb_product), + "Unknown Target Device", + JOptionPane.YES_NO_OPTION); + } else { + ret = JOptionPane.showConfirmDialog(this, + String.format("Device is %04x:%04x %s\nImage is %04x:%04x %s\nFlash anyways?", + existing_config.usb_id.vid, + existing_config.usb_id.pid, + existing_config.usb_product, + image_config.usb_id.vid, + image_config.usb_id.pid, + image_config.usb_product), + "Image doesn't match Device", + JOptionPane.YES_NO_OPTION); + } if (ret != JOptionPane.YES_OPTION) return false; }