github.com/jerryclinesmith/packer@v0.3.7/configfile_windows.go (about) 1 // +build windows 2 3 package main 4 5 import ( 6 "path/filepath" 7 "syscall" 8 "unsafe" 9 ) 10 11 var ( 12 shell = syscall.MustLoadDLL("Shell32.dll") 13 getFolderPath = shell.MustFindProc("SHGetFolderPathW") 14 ) 15 16 const CSIDL_APPDATA = 26 17 18 func configFile() (string, error) { 19 dir, err := configDir() 20 if err != nil { 21 return "", err 22 } 23 24 return filepath.Join(dir, "packer.config"), nil 25 } 26 27 func configDir() (string, error) { 28 b := make([]uint16, syscall.MAX_PATH) 29 30 // See: http://msdn.microsoft.com/en-us/library/windows/desktop/bb762181(v=vs.85).aspx 31 r, _, err := getFolderPath.Call(0, CSIDL_APPDATA, 0, 0, uintptr(unsafe.Pointer(&b[0]))) 32 if uint32(r) != 0 { 33 return "", err 34 } 35 36 return syscall.UTF16ToString(b), nil 37 }