add windows support
This commit is contained in:
72
config.go
72
config.go
@ -4,7 +4,10 @@ import (
|
||||
"fmt"
|
||||
"github.com/BurntSushi/toml"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@ -21,10 +24,11 @@ const (
|
||||
var cfgPath string
|
||||
|
||||
func setupConfig(rerun bool) (*Config, error) {
|
||||
home := os.Getenv("HOME")
|
||||
if home == "" {
|
||||
return nil, fmt.Errorf("$HOME environment variable not set")
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to determine home directory: %v", err)
|
||||
}
|
||||
cfgPath = filepath.Join(home, ".config", configDirName, configName)
|
||||
|
||||
newConfig := Config{
|
||||
WowDir: defaultWowPath,
|
||||
@ -32,36 +36,55 @@ func setupConfig(rerun bool) (*Config, error) {
|
||||
EnableLauncher: false,
|
||||
}
|
||||
|
||||
cfgPath = filepath.Join(home, ".config", configDirName, configName)
|
||||
|
||||
_, statErr := os.Stat(cfgPath)
|
||||
if rerun || os.IsNotExist(statErr) {
|
||||
fmt.Println("Enter the path to your Wow directory below:")
|
||||
_, err := fmt.Scanln(&newConfig.WowDir)
|
||||
var s string
|
||||
_, err = fmt.Scanln(&s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("unable to read input: %v", err)
|
||||
}
|
||||
newConfig.WowDir = strings.TrimSpace(s)
|
||||
|
||||
for {
|
||||
fmt.Printf("Do you want to use epochcli to launch Wow? Select No if you plan on using a launcher tool like Lutris (y/n): ")
|
||||
var s string
|
||||
_, err := fmt.Scanf("%s", &s)
|
||||
_, err = fmt.Scanf("%s", &s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("unable to read input: %v", err)
|
||||
}
|
||||
s = strings.TrimSpace(s)
|
||||
|
||||
if s == "y" || s == "Y" {
|
||||
newConfig.EnableLauncher = true
|
||||
fmt.Println("Enter your launch command to start Wow below. If you would rather configure this later in the configuration file, just press Enter")
|
||||
fmt.Printf("> ")
|
||||
_, err = fmt.Scanf("%s", &s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
if runtime.GOOS == "windows" {
|
||||
newConfig.LaunchCmd = path.Join(newConfig.WowDir, "Project-Epoch.exe")
|
||||
exePath, err := os.Executable()
|
||||
if err != nil {
|
||||
fmt.Println("unable to create desktop shortcut: ", err)
|
||||
break
|
||||
}
|
||||
err = makeLink(exePath, path.Join(home, "Desktop", "Project-Epoch.lnk"))
|
||||
if err != nil {
|
||||
fmt.Println("unable to create desktop shortcut: ", err)
|
||||
}
|
||||
break
|
||||
} else {
|
||||
fmt.Println("Enter your launch command to start Wow below. If you would rather configure this later in the configuration file, just press Enter")
|
||||
fmt.Printf("> ")
|
||||
|
||||
_, err = fmt.Scanf("%s", &s)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to read input: %v", err)
|
||||
}
|
||||
s = strings.TrimSpace(s)
|
||||
|
||||
if s != "" {
|
||||
newConfig.LaunchCmd = s
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
if s != "" {
|
||||
newConfig.LaunchCmd = s
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
if s == "n" || s == "N" {
|
||||
@ -71,23 +94,26 @@ func setupConfig(rerun bool) (*Config, error) {
|
||||
fmt.Println("Please enter a valid value of either 'y' or 'n'")
|
||||
}
|
||||
|
||||
os.MkdirAll(filepath.Join(home, ".config", configDirName), 0755)
|
||||
err = os.MkdirAll(filepath.Join(home, ".config", configDirName), 0755)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to create config directory: %v", err)
|
||||
}
|
||||
|
||||
file, err := os.Create(cfgPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("unable to create config file: %v", err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
encoder := toml.NewEncoder(file)
|
||||
if err = encoder.Encode(newConfig); err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("unable to encode config file: %v", err)
|
||||
}
|
||||
|
||||
fmt.Println("Created new config at ", cfgPath)
|
||||
}
|
||||
|
||||
_, err := toml.DecodeFile(cfgPath, &newConfig)
|
||||
_, err = toml.DecodeFile(cfgPath, &newConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user