2013-06-18 01:09:07 -04:00
|
|
|
// +build windows
|
|
|
|
|
2015-10-16 20:32:36 -04:00
|
|
|
package packer
|
2013-06-18 01:09:07 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
"syscall"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
shell = syscall.MustLoadDLL("Shell32.dll")
|
|
|
|
getFolderPath = shell.MustFindProc("SHGetFolderPathW")
|
|
|
|
)
|
|
|
|
|
|
|
|
const CSIDL_APPDATA = 26
|
|
|
|
|
|
|
|
func configFile() (string, error) {
|
2014-09-08 16:44:58 -04:00
|
|
|
dir, err := homeDir()
|
2013-06-18 01:09:07 -04:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return filepath.Join(dir, "packer.config"), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func configDir() (string, error) {
|
2014-09-08 16:44:58 -04:00
|
|
|
dir, err := homeDir()
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return filepath.Join(dir, "packer.d"), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func homeDir() (string, error) {
|
2013-06-18 01:09:07 -04:00
|
|
|
b := make([]uint16, syscall.MAX_PATH)
|
|
|
|
|
|
|
|
// See: http://msdn.microsoft.com/en-us/library/windows/desktop/bb762181(v=vs.85).aspx
|
|
|
|
r, _, err := getFolderPath.Call(0, CSIDL_APPDATA, 0, 0, uintptr(unsafe.Pointer(&b[0])))
|
|
|
|
if uint32(r) != 0 {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return syscall.UTF16ToString(b), nil
|
|
|
|
}
|