This commit is contained in:
npc0-hue
2026-08-26 09:56:43 +08:00
parent 2b4974b561
commit 8e02a316fa
93 changed files with 21749 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
//go:build windows
package runtime
import (
"path/filepath"
"syscall"
"unsafe"
)
var getDiskFreeSpaceEx = syscall.NewLazyDLL("kernel32.dll").NewProc("GetDiskFreeSpaceExW")
func workspaceDiskPercent(workspaceRoot string) (float64, error) {
volume := filepath.VolumeName(workspaceRoot)
if volume == "" {
volume = workspaceRoot
} else {
volume += `\`
}
var available, total, free uint64
success, _, callErr := getDiskFreeSpaceEx.Call(uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(volume))), uintptr(unsafe.Pointer(&available)), uintptr(unsafe.Pointer(&total)), uintptr(unsafe.Pointer(&free)))
if success == 0 {
return 0, callErr
}
if total == 0 {
return 0, syscall.EINVAL
}
return 100 * float64(total-free) / float64(total), nil
}