From c28d86b9bc7a51805366e193ef0c97bb57132540 Mon Sep 17 00:00:00 2001 From: VideoTools CI Date: Sat, 17 Jan 2026 20:33:08 -0500 Subject: [PATCH] Add Windows helper to prepend GStreamer bin to PATH --- internal/utils/gstreamer_paths_windows.go | 58 +++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 internal/utils/gstreamer_paths_windows.go diff --git a/internal/utils/gstreamer_paths_windows.go b/internal/utils/gstreamer_paths_windows.go new file mode 100644 index 0000000..5279692 --- /dev/null +++ b/internal/utils/gstreamer_paths_windows.go @@ -0,0 +1,58 @@ +//go:build windows + +package utils + +import ( + "os" + "path/filepath" + "strings" +) + +// EnsureGStreamerOnPath best-effort prepends common GStreamer bin locations to PATH for the +// current process. It does not modify system-wide PATH. This helps avoid missing-DLL issues +// when users install GStreamer but its bin directory is not on PATH. +func EnsureGStreamerOnPath() { + candidates := []string{} + + // If the user set GSTREAMER_1_0_ROOT_X86_64, prefer its bin + if root := os.Getenv("GSTREAMER_1_0_ROOT_X86_64"); root != "" { + candidates = append(candidates, filepath.Join(root, "bin")) + } + + // Common installer locations (64-bit) + candidates = append(candidates, + `C:\\gstreamer\\1.0\\msvc_x86_64\\bin`, + `C:\\Program Files\\GStreamer\\1.0\\msvc_x86_64\\bin`, + ) + + pathVal := os.Getenv("PATH") + parts := []string{} + seen := map[string]bool{} + + // Prepend any found candidates that exist + for _, cand := range candidates { + if cand == "" { + continue + } + if _, err := os.Stat(cand); err == nil { + // Only add if not already present (case-insensitive on Windows) + lower := strings.ToLower(cand) + if !seen[lower] { + parts = append(parts, cand) + seen[lower] = true + } + } + } + + // Append existing PATH entries, preserving order and deduping case-insensitively + for _, p := range filepath.SplitList(pathVal) { + lower := strings.ToLower(p) + if seen[lower] { + continue + } + parts = append(parts, p) + seen[lower] = true + } + + _ = os.Setenv("PATH", strings.Join(parts, string(os.PathListSeparator))) +}