From 436813798a019db3b784514eef978f13af19aa51 Mon Sep 17 00:00:00 2001 From: Martyn R Date: Wed, 29 Dec 2021 23:19:40 +0000 Subject: [PATCH] Moved the windows stuff to separate file --- user/user.go | 26 +++++++---------------- user/user_nonwindows.go | 42 +++++++++++++++++++++++++++++++++++++ user/user_windows.go | 46 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 18 deletions(-) create mode 100644 user/user_nonwindows.go create mode 100644 user/user_windows.go diff --git a/user/user.go b/user/user.go index 5ae5f14..9df2d0a 100644 --- a/user/user.go +++ b/user/user.go @@ -5,8 +5,6 @@ import ( "os" "runtime" - "golang.org/x/sys/windows" - "git.martyn.berlin/martyn/directories/base" ) @@ -22,8 +20,7 @@ func Audio() (string, error) { return e, nil } case "windows": - path, err := windows.KnownFolderPath(windows.FOLDERID_Music, 0) - return path, err + return windowsAudio() case "darwin": h, err := Home() return h + "/Music", err @@ -39,8 +36,7 @@ func Desktop() (string, error) { return e, nil } case "windows": - path, err := windows.KnownFolderPath(windows.FOLDERID_Desktop, 0) - return path, err + return windowsDesktop() case "darwin": h, err := Home() return h + "/Desktop", err @@ -56,8 +52,7 @@ func Documents() (string, error) { return e, nil } case "windows": - path, err := windows.KnownFolderPath(windows.FOLDERID_Documents, 0) - return path, err + return windowsDocuments() case "darwin": h, err := Home() return h + "/Documents", err @@ -73,8 +68,7 @@ func Downloads() (string, error) { return e, nil } case "windows": - path, err := windows.KnownFolderPath(windows.FOLDERID_Downloads, 0) - return path, err + return windowsDownloads() case "darwin": h, err := Home() return h + "/Downloads", err @@ -109,8 +103,7 @@ func Pictures() (string, error) { return e, nil } case "windows": - path, err := windows.KnownFolderPath(windows.FOLDERID_Pictures, 0) - return path, err + return windowsPictures() case "darwin": h, err := Home() return h + "/Pictures", err @@ -126,8 +119,7 @@ func Public() (string, error) { return e, nil } case "windows": - path, err := windows.KnownFolderPath(windows.FOLDERID_Public, 0) - return path, err + return windowsPublic() case "darwin": h, err := Home() return h + "/Public", err @@ -143,8 +135,7 @@ func Templates() (string, error) { return e, nil } case "windows": - path, err := windows.KnownFolderPath(windows.FOLDERID_Templates, 0) - return path, err + return windowsTemplates() case "darwin": h, err := Home() return h + "/Templates", err @@ -160,8 +151,7 @@ func Videos() (string, error) { return e, nil } case "windows": - path, err := windows.KnownFolderPath(windows.FOLDERID_Videos, 0) - return path, err + return windowsVideos() case "darwin": h, err := Home() return h + "/Videos", err diff --git a/user/user_nonwindows.go b/user/user_nonwindows.go new file mode 100644 index 0000000..3a033e9 --- /dev/null +++ b/user/user_nonwindows.go @@ -0,0 +1,42 @@ +//go:build !windows +// +build !windows + +package user + +import "errors" + +func wrongPlatform() (string, error) { + return "", errors.New("using windows call on non-windows system") +} + +func windowsAudio() (string, error) { + return wrongPlatform() +} + +func windowsDesktop() (string, error) { + return wrongPlatform() +} + +func windowsDocuments() (string, error) { + return wrongPlatform() +} + +func windowsDownloads() (string, error) { + return wrongPlatform() +} + +func windowsPictures() (string, error) { + return wrongPlatform() +} + +func windowsPublic() (string, error) { + return wrongPlatform() +} + +func windowsTemplates() (string, error) { + return wrongPlatform() +} + +func windowsVideos() (string, error) { + return wrongPlatform() +} diff --git a/user/user_windows.go b/user/user_windows.go new file mode 100644 index 0000000..da2547b --- /dev/null +++ b/user/user_windows.go @@ -0,0 +1,46 @@ +//go:build windows +// +build windows + +package user + +import "golang.org/x/sys/windows" + +func windowsAudio() (string, error) { + path, err := windows.KnownFolderPath(windows.FOLDERID_Music, 0) + return path, err +} + +func windowsDesktop() (string, error) { + path, err := windows.KnownFolderPath(windows.FOLDERID_Desktop, 0) + return path, err +} + +func windowsDocuments() (string, error) { + path, err := windows.KnownFolderPath(windows.FOLDERID_Documents, 0) + return path, err +} + +func windowsDownloads() (string, error) { + path, err := windows.KnownFolderPath(windows.FOLDERID_Downloads, 0) + return path, err +} + +func windowsPictures() (string, error) { + path, err := windows.KnownFolderPath(windows.FOLDERID_Pictures, 0) + return path, err +} + +func windowsPublic() (string, error) { + path, err := windows.KnownFolderPath(windows.FOLDERID_Public, 0) + return path, err +} + +func windowsTemplates() (string, error) { + path, err := windows.KnownFolderPath(windows.FOLDERID_Templates, 0) + return path, err +} + +func windowsVideos() (string, error) { + path, err := windows.KnownFolderPath(windows.FOLDERID_Videos, 0) + return path, err +}