Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

use SHGetKnownFolderPath, local instead of roaming #126

Merged
merged 3 commits into from
Dec 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 58 additions & 3 deletions keybase/platform_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,71 @@ package keybase

import (
"encoding/json"
"errors"
"fmt"
"os"
"path/filepath"
"strings"
"syscall"
"time"
"unsafe"

"github.com/kardianos/osext"
"github.com/keybase/go-updater"
"github.com/keybase/go-updater/command"
"github.com/keybase/go-updater/util"
"golang.org/x/sys/windows"
"golang.org/x/sys/windows/registry"
)

type guid struct {
Data1 uint32
Data2 uint16
Data3 uint16
Data4 [8]byte
}

// FOLDERID_LocalAppData
// F1B32785-6FBA-4FCF-9D55-7B8E7F157091
var (
folderIDLocalAppData = guid{0xF1B32785, 0x6FBA, 0x4FCF, [8]byte{0x9D, 0x55, 0x7B, 0x8E, 0x7F, 0x15, 0x70, 0x91}}
)

var (
modShell32 = windows.NewLazySystemDLL("Shell32.dll")
modOle32 = windows.NewLazySystemDLL("Ole32.dll")
procSHGetKnownFolderPath = modShell32.NewProc("SHGetKnownFolderPath")
procCoTaskMemFree = modOle32.NewProc("CoTaskMemFree")
)

func coTaskMemFree(pv uintptr) {
syscall.Syscall(procCoTaskMemFree.Addr(), 1, uintptr(pv), 0, 0)
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need this return?

}

func getDataDir(id guid) (string, error) {

var pszPath uintptr
r0, _, _ := procSHGetKnownFolderPath.Call(uintptr(unsafe.Pointer(&id)), uintptr(0), uintptr(0), uintptr(unsafe.Pointer(&pszPath)))
if r0 != 0 {
return "", errors.New("can't get FOLDERID_RoamingAppData")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think most of our errors are title cased... "Can't...

}

defer coTaskMemFree(pszPath)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to check pszPath is invalid?


// go vet: "possible misuse of unsafe.Pointer"
folder := syscall.UTF16ToString((*[1 << 16]uint16)(unsafe.Pointer(pszPath))[:])

if len(folder) == 0 {
return "", errors.New("can't get AppData directory")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think most of our errors are title cased... "Can't...

}

return folder, nil
}

func localDataDir() (string, error) {
return getDataDir(folderIDLocalAppData)
}

func (c config) destinationPath() string {
pathName, err := osext.Executable()
if err != nil {
Expand All @@ -30,9 +82,12 @@ func (c config) destinationPath() string {

// Dir returns where to store config and log files
func Dir(appName string) (string, error) {
dir := os.Getenv("APPDATA")
dir, err := localDataDir()
if err != nil {
return "", err
}
if dir == "" {
return "", fmt.Errorf("No APPDATA env set")
return "", fmt.Errorf("No LocalDataDir")
}
if appName == "" {
return "", fmt.Errorf("No app name for dir")
Expand Down
13 changes: 13 additions & 0 deletions vendor/golang.org/x/sys/windows/asm_windows_386.s

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions vendor/golang.org/x/sys/windows/asm_windows_amd64.s

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading