Moved the windows stuff to separate file

This commit is contained in:
Martyn 2021-12-29 23:19:40 +00:00
parent eed78633aa
commit 436813798a
3 changed files with 96 additions and 18 deletions

View File

@ -5,8 +5,6 @@ import (
"os" "os"
"runtime" "runtime"
"golang.org/x/sys/windows"
"git.martyn.berlin/martyn/directories/base" "git.martyn.berlin/martyn/directories/base"
) )
@ -22,8 +20,7 @@ func Audio() (string, error) {
return e, nil return e, nil
} }
case "windows": case "windows":
path, err := windows.KnownFolderPath(windows.FOLDERID_Music, 0) return windowsAudio()
return path, err
case "darwin": case "darwin":
h, err := Home() h, err := Home()
return h + "/Music", err return h + "/Music", err
@ -39,8 +36,7 @@ func Desktop() (string, error) {
return e, nil return e, nil
} }
case "windows": case "windows":
path, err := windows.KnownFolderPath(windows.FOLDERID_Desktop, 0) return windowsDesktop()
return path, err
case "darwin": case "darwin":
h, err := Home() h, err := Home()
return h + "/Desktop", err return h + "/Desktop", err
@ -56,8 +52,7 @@ func Documents() (string, error) {
return e, nil return e, nil
} }
case "windows": case "windows":
path, err := windows.KnownFolderPath(windows.FOLDERID_Documents, 0) return windowsDocuments()
return path, err
case "darwin": case "darwin":
h, err := Home() h, err := Home()
return h + "/Documents", err return h + "/Documents", err
@ -73,8 +68,7 @@ func Downloads() (string, error) {
return e, nil return e, nil
} }
case "windows": case "windows":
path, err := windows.KnownFolderPath(windows.FOLDERID_Downloads, 0) return windowsDownloads()
return path, err
case "darwin": case "darwin":
h, err := Home() h, err := Home()
return h + "/Downloads", err return h + "/Downloads", err
@ -109,8 +103,7 @@ func Pictures() (string, error) {
return e, nil return e, nil
} }
case "windows": case "windows":
path, err := windows.KnownFolderPath(windows.FOLDERID_Pictures, 0) return windowsPictures()
return path, err
case "darwin": case "darwin":
h, err := Home() h, err := Home()
return h + "/Pictures", err return h + "/Pictures", err
@ -126,8 +119,7 @@ func Public() (string, error) {
return e, nil return e, nil
} }
case "windows": case "windows":
path, err := windows.KnownFolderPath(windows.FOLDERID_Public, 0) return windowsPublic()
return path, err
case "darwin": case "darwin":
h, err := Home() h, err := Home()
return h + "/Public", err return h + "/Public", err
@ -143,8 +135,7 @@ func Templates() (string, error) {
return e, nil return e, nil
} }
case "windows": case "windows":
path, err := windows.KnownFolderPath(windows.FOLDERID_Templates, 0) return windowsTemplates()
return path, err
case "darwin": case "darwin":
h, err := Home() h, err := Home()
return h + "/Templates", err return h + "/Templates", err
@ -160,8 +151,7 @@ func Videos() (string, error) {
return e, nil return e, nil
} }
case "windows": case "windows":
path, err := windows.KnownFolderPath(windows.FOLDERID_Videos, 0) return windowsVideos()
return path, err
case "darwin": case "darwin":
h, err := Home() h, err := Home()
return h + "/Videos", err return h + "/Videos", err

42
user/user_nonwindows.go Normal file
View File

@ -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()
}

46
user/user_windows.go Normal file
View File

@ -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
}