- Add command groups (Getting Started, Search, Downloads, Daemon, System) - Add shell completion command (bash, zsh, fish, powershell) - Add flag completions for --type, --quality, --sort, --lang, --genre, --country, --method, --player - Improve Long descriptions and Examples for all commands - Split doctor disk check into platform-specific files (Unix/Windows) - Validate infoHash length before truncating (prevent panic) - Fix references to non-existent 'unarr daemon start' command - Move stats command to System & Diagnostics group - Rewrite README with complete documentation, correct config format (toml not yaml), all commands, shell completion section
33 lines
793 B
Go
33 lines
793 B
Go
//go:build windows
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"syscall"
|
|
"unsafe"
|
|
)
|
|
|
|
func checkDiskSpace(dir string) (string, error) {
|
|
kernel32 := syscall.NewLazyDLL("kernel32.dll")
|
|
getDiskFreeSpaceEx := kernel32.NewProc("GetDiskFreeSpaceExW")
|
|
|
|
var freeBytesAvailable, totalBytes, totalFreeBytes int64
|
|
dirPtr, _ := syscall.UTF16PtrFromString(dir)
|
|
ret, _, err := getDiskFreeSpaceEx.Call(
|
|
uintptr(unsafe.Pointer(dirPtr)),
|
|
uintptr(unsafe.Pointer(&freeBytesAvailable)),
|
|
uintptr(unsafe.Pointer(&totalBytes)),
|
|
uintptr(unsafe.Pointer(&totalFreeBytes)),
|
|
)
|
|
if ret == 0 {
|
|
return "", fmt.Errorf("GetDiskFreeSpaceEx: %w", err)
|
|
}
|
|
|
|
gb := float64(freeBytesAvailable) / (1024 * 1024 * 1024)
|
|
msg := fmt.Sprintf("%.1f GB free", gb)
|
|
if gb < 10 {
|
|
return "!" + msg + " (low)", nil
|
|
}
|
|
return msg, nil
|
|
}
|