From 18e446561dbe8f3d843c2fb8fff4c20d3107c864 Mon Sep 17 00:00:00 2001 From: Ron Evans Date: Thu, 19 Dec 2019 09:28:24 +0100 Subject: [PATCH] flash: use more precise searches for correct volume/port with default Windows matching Signed-off-by: Ron Evans --- main.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index 47aefd9f..c954e974 100644 --- a/main.go +++ b/main.go @@ -457,7 +457,7 @@ func flashUF2UsingMSD(volume, tmppath string) error { case "darwin": infoPath = "/Volumes/" + volume + "/INFO_UF2.TXT" case "windows": - path, err := windowsFindUSBDrive() + path, err := windowsFindUSBDrive(volume) if err != nil { return err } @@ -484,7 +484,7 @@ func flashHexUsingMSD(volume, tmppath string) error { case "darwin": destPath = "/Volumes/" + volume case "windows": - path, err := windowsFindUSBDrive() + path, err := windowsFindUSBDrive(volume) if err != nil { return err } @@ -502,10 +502,10 @@ func flashHexUsingMSD(volume, tmppath string) error { return moveFile(tmppath, d[0]+"/flash.hex") } -func windowsFindUSBDrive() (string, error) { - cmd := exec.Command("wmic", "PATH", "Win32_LogicalDisk", - "get", "DeviceID,", "VolumeName,", - "FileSystem,", "DriveType") +func windowsFindUSBDrive(volume string) (string, error) { + cmd := exec.Command("wmic", + "PATH", "Win32_LogicalDisk", "WHERE", "VolumeName = '"+volume+"'", + "get", "DeviceID,VolumeName,FileSystem,DriveType") var out bytes.Buffer cmd.Stdout = &out @@ -559,8 +559,8 @@ func getDefaultPort() (port string, err error) { case "linux": portPath = "/dev/ttyACM*" case "windows": - cmd := exec.Command("wmic", "PATH", "Win32_SerialPort", - "get", "DeviceID") + cmd := exec.Command("wmic", + "PATH", "Win32_SerialPort", "WHERE", "Caption LIKE 'USB Serial%'", "GET", "DeviceID") var out bytes.Buffer cmd.Stdout = &out