-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
file_windows.go
96 lines (79 loc) · 1.99 KB
/
file_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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package dialog
import (
"os"
"path/filepath"
"syscall"
"fyne.io/fyne"
"fyne.io/fyne/theme"
)
func driveMask() uint32 {
dll, err := syscall.LoadLibrary("kernel32.dll")
if err != nil {
fyne.LogError("Error loading kernel32.dll", err)
return 0
}
handle, err := syscall.GetProcAddress(dll, "GetLogicalDrives")
if err != nil {
fyne.LogError("Could not find GetLogicalDrives call", err)
return 0
}
ret, _, err := syscall.Syscall(uintptr(handle), 0, 0, 0, 0)
if err != syscall.Errno(0) { // for some reason Syscall returns something not nil on success
fyne.LogError("Error calling GetLogicalDrives", err)
return 0
}
return uint32(ret)
}
func listDrives() []string {
var drives []string
mask := driveMask()
for i := 0; i < 24; i++ {
if mask&1 == 1 {
letter := string('A' + rune(i))
drives = append(drives, letter+":")
}
mask >>= 1
}
return drives
}
func (f *fileDialog) loadPlaces() []fyne.CanvasObject {
var places []fyne.CanvasObject
for _, drive := range listDrives() {
driveRoot := drive + string(os.PathSeparator) // capture loop var
places = append(places, makeFavoriteButton(drive, theme.StorageIcon(), func() {
f.setDirectory(driveRoot)
}))
}
return places
}
func isHidden(file, dir string) bool {
path := filepath.Join(dir, file)
point, err := syscall.UTF16PtrFromString(path)
if err != nil {
fyne.LogError("Error making string pointer", err)
return false
}
attr, err := syscall.GetFileAttributes(point)
if err != nil {
fyne.LogError("Error getting file attributes", err)
return false
}
return attr&syscall.FILE_ATTRIBUTE_HIDDEN != 0
}
func fileOpenOSOverride(*FileDialog) bool {
return false
}
func fileSaveOSOverride(*FileDialog) bool {
return false
}
func getFavoriteLocations() (map[string]string, error) {
homeDir, err := os.UserHomeDir()
if err != nil {
return nil, err
}
return map[string]string{
"Home": homeDir,
"Documents": filepath.Join(homeDir, "Documents"),
"Downloads": filepath.Join(homeDir, "Downloads"),
}, nil
}