added SPM
This commit is contained in:
parent
17bb547c74
commit
9e5457c2ec
8 changed files with 779 additions and 18 deletions
64
spm/utils.go
Normal file
64
spm/utils.go
Normal file
|
@ -0,0 +1,64 @@
|
|||
package spm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
func GetTempDownloadDir() string {
|
||||
dir, err := os.MkdirTemp("", "spm_downloads")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return dir
|
||||
}
|
||||
|
||||
func SetDownloadFolder(customDir string) (string, error) {
|
||||
if err := os.MkdirAll(customDir, os.ModePerm); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return customDir, nil
|
||||
}
|
||||
|
||||
// GetDefaultInstallDir generates the default installation directory based on the OS and environment.
|
||||
func GetDefaultInstallDir() (string, error) {
|
||||
var installDir string
|
||||
|
||||
switch runtime.GOOS {
|
||||
case "windows":
|
||||
// Use %APPDATA% or Program Files on Windows
|
||||
appData := os.Getenv("APPDATA")
|
||||
if appData != "" {
|
||||
installDir = filepath.Join(appData, "Spitfire")
|
||||
} else {
|
||||
programFiles := os.Getenv("ProgramFiles")
|
||||
if programFiles == "" {
|
||||
return "", fmt.Errorf("unable to determine default install directory on Windows")
|
||||
}
|
||||
installDir = filepath.Join(programFiles, "Spitfire")
|
||||
}
|
||||
|
||||
case "darwin":
|
||||
// Use ~/Library/Application Support on macOS
|
||||
homeDir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("unable to determine home directory on macOS: %w", err)
|
||||
}
|
||||
installDir = filepath.Join(homeDir, "Library", "Application Support", "Spitfire")
|
||||
|
||||
case "linux":
|
||||
// Use ~/.local/share or /opt on Linux
|
||||
homeDir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("unable to determine home directory on Linux: %w", err)
|
||||
}
|
||||
installDir = filepath.Join(homeDir, ".local", "share", "Spitfire")
|
||||
|
||||
default:
|
||||
return "", fmt.Errorf("unsupported operating system: %s", runtime.GOOS)
|
||||
}
|
||||
|
||||
return installDir, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue