Add standalone desktop workflow
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
//go:build windows
|
||||
|
||||
package disk
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
func IsMountPoint(path string) bool {
|
||||
clean := filepath.Clean(path)
|
||||
volume := filepath.VolumeName(clean)
|
||||
if volume == "" {
|
||||
return false
|
||||
}
|
||||
root := volume + `\`
|
||||
return strings.EqualFold(clean, root)
|
||||
}
|
||||
|
||||
func DiskUsage(mountPath string) (total, free int64, err error) {
|
||||
root := filepath.Clean(mountPath)
|
||||
if volume := filepath.VolumeName(root); volume != "" {
|
||||
root = volume + `\`
|
||||
}
|
||||
|
||||
pathPtr, err := windows.UTF16PtrFromString(root)
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
|
||||
var freeBytesAvailable uint64
|
||||
var totalNumberOfBytes uint64
|
||||
var totalNumberOfFreeBytes uint64
|
||||
if err := windows.GetDiskFreeSpaceEx(pathPtr, &freeBytesAvailable, &totalNumberOfBytes, &totalNumberOfFreeBytes); err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
return int64(totalNumberOfBytes), int64(freeBytesAvailable), nil
|
||||
}
|
||||
Reference in New Issue
Block a user