From 84029bd008e87c6a5d77a027c068f4057771577a Mon Sep 17 00:00:00 2001 From: ChienNM3 Date: Wed, 7 Feb 2024 21:29:04 +0700 Subject: [PATCH] Fix not open vlc x86 on windown --- vlc/open_windows.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/vlc/open_windows.go b/vlc/open_windows.go index 2c1ec2a..002f440 100644 --- a/vlc/open_windows.go +++ b/vlc/open_windows.go @@ -3,10 +3,30 @@ package vlc import ( + "os" "os/exec" ) func open(url string) error { - cmd := exec.Command(`C:\Program Files\VideoLAN\VLC\vlc.exe`, url) + vlcPath, err := getVlcPath() + if err != nil { + return err + } + cmd := exec.Command(vlcPath, url) return cmd.Run() } + +const ( + vlcPath64 = `C:\Program Files\VideoLAN\VLC\vlc.exe` + vlcPath32 = `C:\Program Files (x86)\VideoLAN\VLC\vlc.exe` +) + +func getVlcPath() (string, error) { + if _, err := os.Stat(vlcPath64); err == nil { + return vlcPath64, nil + } + if _, err := os.Stat(vlcPath32); err == nil { + return vlcPath32, nil + } + return "", os.ErrNotExist +}