diff --git a/.gitea/workflows/build-installer.yaml b/.gitea/workflows/build-installer.yaml index 3377a15..e252b38 100644 --- a/.gitea/workflows/build-installer.yaml +++ b/.gitea/workflows/build-installer.yaml @@ -114,6 +114,7 @@ jobs: Copy-Item "$base\scripts\kneron_detect.py" "$base\installer\payload\scripts\" Copy-Item "$base\server\scripts\firmware\KL520\*.bin" "$base\installer\payload\scripts\firmware\KL520\" Copy-Item "$base\server\scripts\firmware\KL720\*.bin" "$base\installer\payload\scripts\firmware\KL720\" + Copy-Item "local_service_win\third_party\Kneron_DFUT\bin\libusb-1.0.dll" "$base\installer\payload\scripts\" - name: Build Windows installer run: | diff --git a/.github/workflows/build-installer.yaml b/.github/workflows/build-installer.yaml index 3377a15..e252b38 100644 --- a/.github/workflows/build-installer.yaml +++ b/.github/workflows/build-installer.yaml @@ -114,6 +114,7 @@ jobs: Copy-Item "$base\scripts\kneron_detect.py" "$base\installer\payload\scripts\" Copy-Item "$base\server\scripts\firmware\KL520\*.bin" "$base\installer\payload\scripts\firmware\KL520\" Copy-Item "$base\server\scripts\firmware\KL720\*.bin" "$base\installer\payload\scripts\firmware\KL720\" + Copy-Item "local_service_win\third_party\Kneron_DFUT\bin\libusb-1.0.dll" "$base\installer\payload\scripts\" - name: Build Windows installer run: | diff --git a/edge-ai-platform/installer/platform_windows.go b/edge-ai-platform/installer/platform_windows.go index 387ec1c..5bc9875 100644 --- a/edge-ai-platform/installer/platform_windows.go +++ b/edge-ai-platform/installer/platform_windows.go @@ -71,24 +71,50 @@ func removeSystemLink() { } func installLibusb(installDir string) error { - // Check known system DLL locations - dllPaths := []string{ + // Check if already present in system or install directory + checkPaths := []string{ filepath.Join(os.Getenv("SystemRoot"), "System32", "libusb-1.0.dll"), filepath.Join(os.Getenv("SystemRoot"), "SysWOW64", "libusb-1.0.dll"), + filepath.Join(installDir, "libusb-1.0.dll"), } - for _, p := range dllPaths { + for _, p := range checkPaths { if _, err := os.Stat(p); err == nil { return nil // already installed } } - return fmt.Errorf("libusb not found. Please install the WinUSB driver via Zadig: https://zadig.akeo.ie") + // Try to extract libusb-1.0.dll from payload to install directory + // The DLL is bundled at payload/scripts/libusb-1.0.dll + dllDest := filepath.Join(installDir, "libusb-1.0.dll") + data, err := payloadFS.ReadFile("payload/scripts/libusb-1.0.dll") + if err == nil { + if writeErr := os.WriteFile(dllDest, data, 0644); writeErr == nil { + return nil // successfully extracted + } + } + + // Fallback: try winget + if wingetPath, err := exec.LookPath("winget"); err == nil { + cmd := exec.Command(wingetPath, "install", "libusb", + "--accept-source-agreements", "--accept-package-agreements", "--silent") + cmd.Run() // best effort + + // Re-check + for _, p := range checkPaths { + if _, err := os.Stat(p); err == nil { + return nil + } + } + } + + return fmt.Errorf("libusb not found. For Kneron USB device support, install the WinUSB driver via Zadig: https://zadig.akeo.ie") } func checkLibusbInstalled() bool { dllPaths := []string{ filepath.Join(os.Getenv("SystemRoot"), "System32", "libusb-1.0.dll"), filepath.Join(os.Getenv("SystemRoot"), "SysWOW64", "libusb-1.0.dll"), + filepath.Join(platformDefaultDir(), "libusb-1.0.dll"), } for _, p := range dllPaths { if _, err := os.Stat(p); err == nil {