mirror of
https://github.com/onyx-dot-app/onyx.git
synced 2026-10-22 03:14:06 -05:00
19 lines
488 B
Go
19 lines
488 B
Go
//go:build windows
|
|
|
|
package resources
|
|
|
|
import "golang.org/x/sys/windows"
|
|
|
|
// DiskAvailableGB returns the free space at path in GB (-1 = unknown).
|
|
func DiskAvailableGB(path string) int {
|
|
p, err := windows.UTF16PtrFromString(path)
|
|
if err != nil {
|
|
return -1
|
|
}
|
|
var freeBytesAvailable, totalBytes, totalFreeBytes uint64
|
|
if err := windows.GetDiskFreeSpaceEx(p, &freeBytesAvailable, &totalBytes, &totalFreeBytes); err != nil {
|
|
return -1
|
|
}
|
|
return int(freeBytesAvailable / (1 << 30))
|
|
}
|