forked from nsf/gocode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
os_windows.go
56 lines (47 loc) · 1.3 KB
/
os_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
package main
import (
"flag"
"fmt"
"path/filepath"
"syscall"
"unsafe"
)
var (
shell32 = syscall.NewLazyDLL("shell32.dll")
kernel32 = syscall.NewLazyDLL("kernel32.dll")
)
var (
proc_sh_get_folder_path = shell32.NewProc("SHGetFolderPathW")
proc_get_module_file_name = kernel32.NewProc("GetModuleFileNameW")
)
func create_sock_flag(name, desc string) *string {
return flag.String(name, "tcp", desc)
}
// Full path of the current executable
func get_executable_filename() string {
b := make([]uint16, syscall.MAX_PATH)
ret, _, err := syscall.Syscall(proc_get_module_file_name.Addr(), 3,
0, uintptr(unsafe.Pointer(&b[0])), uintptr(len(b)))
if int(ret) == 0 {
panic(fmt.Sprintf("GetModuleFileNameW : err %d", int(err)))
}
return syscall.UTF16ToString(b)
}
const (
csidl_appdata = 0x1a
)
func get_appdata_folder_path() string {
b := make([]uint16, syscall.MAX_PATH)
ret, _, err := syscall.Syscall6(proc_sh_get_folder_path.Addr(), 5,
0, csidl_appdata, 0, 0, uintptr(unsafe.Pointer(&b[0])), 0)
if int(ret) != 0 {
panic(fmt.Sprintf("SHGetFolderPathW : err %d", int(err)))
}
return syscall.UTF16ToString(b)
}
func config_dir() string {
return filepath.Join(get_appdata_folder_path(), "gocode")
}
func config_file() string {
return filepath.Join(get_appdata_folder_path(), "gocode", "config.json")
}