flash: use more precise searches for correct volume/port with default Windows matching

Signed-off-by: Ron Evans <ron@hybridgroup.com>
Этот коммит содержится в:
Ron Evans 2019-12-19 09:28:24 +01:00 коммит произвёл Ayke
родитель 447537aebe
коммит 18e446561d

16
main.go
Просмотреть файл

@ -457,7 +457,7 @@ func flashUF2UsingMSD(volume, tmppath string) error {
case "darwin": case "darwin":
infoPath = "/Volumes/" + volume + "/INFO_UF2.TXT" infoPath = "/Volumes/" + volume + "/INFO_UF2.TXT"
case "windows": case "windows":
path, err := windowsFindUSBDrive() path, err := windowsFindUSBDrive(volume)
if err != nil { if err != nil {
return err return err
} }
@ -484,7 +484,7 @@ func flashHexUsingMSD(volume, tmppath string) error {
case "darwin": case "darwin":
destPath = "/Volumes/" + volume destPath = "/Volumes/" + volume
case "windows": case "windows":
path, err := windowsFindUSBDrive() path, err := windowsFindUSBDrive(volume)
if err != nil { if err != nil {
return err return err
} }
@ -502,10 +502,10 @@ func flashHexUsingMSD(volume, tmppath string) error {
return moveFile(tmppath, d[0]+"/flash.hex") return moveFile(tmppath, d[0]+"/flash.hex")
} }
func windowsFindUSBDrive() (string, error) { func windowsFindUSBDrive(volume string) (string, error) {
cmd := exec.Command("wmic", "PATH", "Win32_LogicalDisk", cmd := exec.Command("wmic",
"get", "DeviceID,", "VolumeName,", "PATH", "Win32_LogicalDisk", "WHERE", "VolumeName = '"+volume+"'",
"FileSystem,", "DriveType") "get", "DeviceID,VolumeName,FileSystem,DriveType")
var out bytes.Buffer var out bytes.Buffer
cmd.Stdout = &out cmd.Stdout = &out
@ -559,8 +559,8 @@ func getDefaultPort() (port string, err error) {
case "linux": case "linux":
portPath = "/dev/ttyACM*" portPath = "/dev/ttyACM*"
case "windows": case "windows":
cmd := exec.Command("wmic", "PATH", "Win32_SerialPort", cmd := exec.Command("wmic",
"get", "DeviceID") "PATH", "Win32_SerialPort", "WHERE", "Caption LIKE 'USB Serial%'", "GET", "DeviceID")
var out bytes.Buffer var out bytes.Buffer
cmd.Stdout = &out cmd.Stdout = &out