File: os_windows.go

package info (click to toggle)
gocode 0~git20140530-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 760 kB
  • ctags: 492
  • sloc: lisp: 212; tcl: 60; python: 55; sh: 50; ruby: 46; makefile: 9
file content (56 lines) | stat: -rw-r--r-- 1,331 bytes parent folder | download | duplicates (2)
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")
}