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 }