You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

171 lines
3.8 KiB
Go

package user
import (
"errors"
"os"
"runtime"
"golang.org/x/sys/windows"
"git.martyn.berlin/martyn/directories/base"
)
func Home() (string, error) {
return base.Home()
}
func Audio() (string, error) {
switch runtime.GOOS {
case "linux":
e, ok := os.LookupEnv("XDG_MUSIC_DIR")
if ok {
return e, nil
}
case "windows":
path, err := windows.KnownFolderPath(windows.FOLDERID_Music, 0)
return path, err
case "darwin":
h, err := Home()
return h + "/Music", err
}
return "", errors.New("could not determine location for Audio()")
}
func Desktop() (string, error) {
switch runtime.GOOS {
case "linux":
e, ok := os.LookupEnv("XDG_DESKTOP_DIR")
if ok {
return e, nil
}
case "windows":
path, err := windows.KnownFolderPath(windows.FOLDERID_Desktop, 0)
return path, err
case "darwin":
h, err := Home()
return h + "/Desktop", err
}
return "", errors.New("could not determine location for Desktop()")
}
func Documents() (string, error) {
switch runtime.GOOS {
case "linux":
e, ok := os.LookupEnv("XDG_DOCUMENTS_DIR")
if ok {
return e, nil
}
case "windows":
path, err := windows.KnownFolderPath(windows.FOLDERID_Documents, 0)
return path, err
case "darwin":
h, err := Home()
return h + "/Documents", err
}
return "", errors.New("could not determine location for Documents()")
}
func Downloads() (string, error) {
switch runtime.GOOS {
case "linux":
e, ok := os.LookupEnv("XDG_DOWNLOAD_DIR")
if ok {
return e, nil
}
case "windows":
path, err := windows.KnownFolderPath(windows.FOLDERID_Downloads, 0)
return path, err
case "darwin":
h, err := Home()
return h + "/Downloads", err
}
return "", errors.New("could not determine location for Downloads()")
}
func Fonts() (string, error) {
switch runtime.GOOS {
case "linux":
e, ok := os.LookupEnv("XDG_DATA_HOME" + "/fonts")
if ok {
return e, nil
} else {
h, err := Home()
return h + "/.local/share/fonts", err
}
case "windows":
return "", errors.New("windows has no per-user fonts dir")
case "darwin":
h, err := Home()
return h + "/Library/Fonts", err
}
return "", errors.New("could not determine location for Fonts()")
}
func Pictures() (string, error) {
switch runtime.GOOS {
case "linux":
e, ok := os.LookupEnv("XDG_PICTURES_DIR")
if ok {
return e, nil
}
case "windows":
path, err := windows.KnownFolderPath(windows.FOLDERID_Pictures, 0)
return path, err
case "darwin":
h, err := Home()
return h + "/Pictures", err
}
return "", errors.New("could not determine location for Pictures()")
}
func Public() (string, error) {
switch runtime.GOOS {
case "linux":
e, ok := os.LookupEnv("XDG_PUBLICSHARE_DIR")
if ok {
return e, nil
}
case "windows":
path, err := windows.KnownFolderPath(windows.FOLDERID_Public, 0)
return path, err
case "darwin":
h, err := Home()
return h + "/Public", err
}
return "", errors.New("could not determine location for Public()")
}
func Templates() (string, error) {
switch runtime.GOOS {
case "linux":
e, ok := os.LookupEnv("XDG_TEMPLATES_DIR")
if ok {
return e, nil
}
case "windows":
path, err := windows.KnownFolderPath(windows.FOLDERID_Templates, 0)
return path, err
case "darwin":
h, err := Home()
return h + "/Templates", err
}
return "", errors.New("could not determine location for Templates()")
}
func Videos() (string, error) {
switch runtime.GOOS {
case "linux":
e, ok := os.LookupEnv("XDG_VIDEOS_DIR")
if ok {
return e, nil
}
case "windows":
path, err := windows.KnownFolderPath(windows.FOLDERID_Videos, 0)
return path, err
case "darwin":
h, err := Home()
return h + "/Videos", err
}
return "", errors.New("could not determine location for Videos()")
}