-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_windows.go
48 lines (38 loc) · 1.12 KB
/
main_windows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package trash
import (
"unsafe"
"golang.org/x/sys/windows"
"github.com/hymkor/trash-go/internal/constant"
)
var shell32Dll = windows.NewLazySystemDLL("Shell32.dll")
var shFileOperationWProc = shell32Dll.NewProc("SHFileOperationW")
type _ShFileOpStruct struct {
hwnd uintptr
wFunc uintptr
pFrom uintptr
pTo uintptr
fileOpFlags uintptr
fAnyOperationsAborted uintptr
hNameMappings uintptr
lpszProgressTitle uintptr
}
func throw(filenames ...string) error {
pFromData := make([]uint16, 0, 256)
for _, fn := range filenames {
u, err := windows.UTF16FromString(fn)
if err != nil {
return err
}
pFromData = append(pFromData, u...)
}
pFromData = append(pFromData, 0)
title := []uint16{0, 0}
param := &_ShFileOpStruct{
wFunc: constant.FO_DELETE,
pFrom: uintptr(unsafe.Pointer(&pFromData[0])),
fileOpFlags: (constant.FOF_ALLOWUNDO | constant.FOF_NOCONFIRMATION),
lpszProgressTitle: uintptr(unsafe.Pointer(&title[0])),
}
shFileOperationWProc.Call(uintptr(unsafe.Pointer(param)))
return nil
}