feat: auto-install libusb on Windows from bundled DLL
- installLibusb now extracts libusb-1.0.dll from payload to install dir - Falls back to winget, then shows Zadig download link - checkLibusbInstalled also checks install directory - CI workflow copies libusb-1.0.dll into payload during staging Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
8ac02b3b35
commit
522800cc7d
@ -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: |
|
||||
|
||||
1
.github/workflows/build-installer.yaml
vendored
1
.github/workflows/build-installer.yaml
vendored
@ -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: |
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user