updated spm package
This commit is contained in:
parent
b403befe74
commit
48473f98c5
16 changed files with 1454 additions and 505 deletions
97
spm/utils.go
97
spm/utils.go
|
@ -1,71 +1,26 @@
|
|||
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
|
||||
}
|
||||
|
||||
// DecompressPackage determines the appropriate package format and decompresses it.
|
||||
func DecompressPackage(downloadDir string) (string, error) {
|
||||
osName := runtime.GOOS
|
||||
packagePath := filepath.Join(downloadDir, fmt.Sprintf("browser-amd64-nightly-%s.tar.gz", osName)) // If file naming changes this will break!!
|
||||
return DecompressToTemp(packagePath)
|
||||
}
|
||||
package spm
|
||||
|
||||
import (
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
// persistSystemEnvVar sets a persistent environment variable on Windows using the `setx` command.
|
||||
// Perhaps support for other systems would be needed, but all of this "Launcher" thingy is probably going to end up
|
||||
// being Windows-specific, as other superior systems have their own package managers.
|
||||
func persistSystemEnvVar(key, value string) error {
|
||||
cmd := exec.Command("cmd", "/C", "setx", key, value)
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsMatchingEntry checks if a package entry matches the requested specs
|
||||
func IsMatchingEntry(e AppIndexEntry, name, release, arch, osName, pkgType string) bool {
|
||||
return e.Name == name &&
|
||||
e.Release == release &&
|
||||
e.Arch == arch &&
|
||||
e.OS == osName &&
|
||||
e.Type == pkgType
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue