error handling, release builds
This commit is contained in:
30
main.go
30
main.go
@ -14,9 +14,10 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
manifestUrl = "https://updater.project-epoch.net/api/manifest"
|
||||
configDirName = "epoch-linux"
|
||||
configName = "config.toml"
|
||||
manifestUrl = "https://updater.project-epoch.net/api/manifest"
|
||||
defaultWowPath = "/path/to/wow"
|
||||
configDirName = "epoch-linux"
|
||||
configName = "config.toml"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@ -27,10 +28,10 @@ var (
|
||||
config Config
|
||||
)
|
||||
|
||||
func setupConfig() {
|
||||
func setupConfig() error {
|
||||
home := os.Getenv("HOME")
|
||||
if home == "" {
|
||||
log.Fatal("$HOME environment variable not set")
|
||||
return fmt.Errorf("$HOME environment variable not set")
|
||||
}
|
||||
|
||||
cfgPath := filepath.Join(home, ".config", configDirName, configName)
|
||||
@ -39,18 +40,18 @@ func setupConfig() {
|
||||
os.MkdirAll(filepath.Join(home, ".config", configDirName), 0755)
|
||||
|
||||
newConfig := &Config{
|
||||
WowDir: "/path/to/wow",
|
||||
WowDir: defaultWowPath,
|
||||
}
|
||||
|
||||
file, err := os.Create(cfgPath)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
encoder := toml.NewEncoder(file)
|
||||
if err = encoder.Encode(newConfig); err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("Created new config at %s, edit it before running the launcher again\n", cfgPath)
|
||||
@ -59,12 +60,21 @@ func setupConfig() {
|
||||
|
||||
_, err := toml.DecodeFile(cfgPath, &config)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
|
||||
if config.WowDir == defaultWowPath {
|
||||
return fmt.Errorf("WowDir in %s is still the default setting", cfgPath)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
setupConfig()
|
||||
err := setupConfig()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
count, err := downloadUpdate()
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user