Skip to content

Commit

Permalink
windows: add winox.FolderTypeStartMenu
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime committed Oct 31, 2019
1 parent 643554b commit df30735
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions syscallex/shell32_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const (
CSIDL_APPDATA = 0x001a
CSIDL_PROFILE = 0x0028
CSIDL_LOCAL_APPDATA = 0x001c
CSIDL_STARTMENU = 0x000b
)

const MAX_PATH = 260
Expand Down
3 changes: 3 additions & 0 deletions winox/users_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const (
FolderTypeProfile FolderType = iota
FolderTypeAppData
FolderTypeLocalAppData
FolderTypeStartMenu
)

func GetFolderPath(folderType FolderType) (string, error) {
Expand All @@ -27,6 +28,8 @@ func GetFolderPath(folderType FolderType) (string, error) {
csidl = syscallex.CSIDL_APPDATA
case FolderTypeLocalAppData:
csidl = syscallex.CSIDL_LOCAL_APPDATA
case FolderTypeStartMenu:
csidl = syscallex.CSIDL_STARTMENU
default:
return "", errors.Errorf("Unknown folder type: %d", folderType)
}
Expand Down
22 changes: 18 additions & 4 deletions winox/users_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,24 @@ import (
)

func Test_GetFolderPath(t *testing.T) {
{
s, err := winox.GetFolderPath(winox.FolderTypeProfile)
assert.NoError(t, err)
assert.NotEmpty(t, s)
type tcase struct {
name string
typ winox.FolderType
}

cases := []tcase{
tcase{name: "appData", typ: winox.FolderTypeAppData},
tcase{name: "localAppData", typ: winox.FolderTypeLocalAppData},
tcase{name: "profile", typ: winox.FolderTypeProfile},
tcase{name: "startMenu", typ: winox.FolderTypeStartMenu},
}

for _, cas := range cases {
t.Run(cas.name, func(t *testing.T) {
s, err := winox.GetFolderPath(cas.typ)
assert.NoError(t, err)
assert.NotEmpty(t, s)
})
}

{
Expand Down

0 comments on commit df30735

Please sign in to comment.