mirror of
https://github.com/packwiz/packwiz.git
synced 2025-10-14 06:54:32 +02:00
Create local store functions
This commit is contained in:
46
core/storeutil.go
Normal file
46
core/storeutil.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
func GetPackwizLocalStore() (string, error) {
|
||||
if //goland:noinspection GoBoolExpressions
|
||||
runtime.GOOS == "linux" {
|
||||
// Prefer $XDG_DATA_HOME over $XDG_CACHE_HOME
|
||||
dataHome := os.Getenv("XDG_DATA_HOME")
|
||||
if dataHome != "" {
|
||||
return filepath.Join(dataHome, "packwiz"), nil
|
||||
}
|
||||
}
|
||||
userConfigDir, err := os.UserConfigDir()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return filepath.Join(userConfigDir, "packwiz"), nil
|
||||
}
|
||||
|
||||
func GetPackwizInstallBinPath() (string, error) {
|
||||
localStore, err := GetPackwizLocalStore()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return filepath.Join(localStore, "bin"), nil
|
||||
}
|
||||
|
||||
func GetPackwizInstallBinFile() (string, error) {
|
||||
binPath, err := GetPackwizInstallBinPath()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
var exeName string
|
||||
if //goland:noinspection GoBoolExpressions
|
||||
runtime.GOOS == "windows" {
|
||||
exeName = "packwiz.exe"
|
||||
} else {
|
||||
exeName = "packwiz"
|
||||
}
|
||||
return filepath.Join(binPath, exeName), nil
|
||||
}
|
Reference in New Issue
Block a user