fix launching
This commit is contained in:
36
main.go
36
main.go
@ -28,7 +28,7 @@ func main() {
|
||||
}
|
||||
|
||||
if outOfDate {
|
||||
fmt.Println("There is a new version of epochcli, please update before running")
|
||||
fmt.Println("There is a new version of epochcli, you must update before running")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
@ -65,9 +65,9 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Printf("%d files updated\n", stats.updated)
|
||||
fmt.Printf("%d files updated\n\n", stats.updated)
|
||||
if stats.current > 0 {
|
||||
fmt.Printf("%d files are already up to date\n", stats.current)
|
||||
fmt.Printf("%d files are already up to date\n\n", stats.current)
|
||||
}
|
||||
|
||||
if updateOnlyFlag {
|
||||
@ -80,10 +80,22 @@ func main() {
|
||||
}
|
||||
|
||||
fmt.Println("Starting Epoch...")
|
||||
var cmd = strings.Split(config.LaunchCmd, " ")
|
||||
if runtime.GOOS == "darwin" {
|
||||
exec.Command("open", config.LaunchCmd).Run()
|
||||
} else {
|
||||
exec.Command(config.LaunchCmd).Run()
|
||||
cmd = append([]string{"open"}, cmd...)
|
||||
}
|
||||
ex := exec.Command(cmd[0], cmd[1:]...)
|
||||
cmdStr := strings.Join(cmd, " ")
|
||||
if config.WinePrefix != "" {
|
||||
prefix := fmt.Sprintf("WINEPREFIX=%s", config.WinePrefix)
|
||||
newEnv := append(os.Environ(), prefix)
|
||||
ex.Env = newEnv
|
||||
cmdStr = prefix + " " + cmdStr
|
||||
}
|
||||
fmt.Println("Running command:", cmdStr)
|
||||
err = ex.Run()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -108,7 +120,10 @@ func downloadUpdate(config *Config, force bool) (DownloadStats, error) {
|
||||
localPath := filepath.Join(config.WowDir, path)
|
||||
localDir := filepath.Dir(localPath)
|
||||
if _, err = os.Stat(localDir); os.IsNotExist(err) {
|
||||
os.MkdirAll(localDir, 0755)
|
||||
err = os.MkdirAll(localDir, 0755)
|
||||
if err != nil {
|
||||
return stats, fmt.Errorf("failed to create directory %s: %v", localDir, err)
|
||||
}
|
||||
}
|
||||
|
||||
if !force {
|
||||
@ -127,32 +142,35 @@ func downloadUpdate(config *Config, force bool) (DownloadStats, error) {
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf(" %s...\n", localPath)
|
||||
fmt.Printf("Updating %s...\n", localPath)
|
||||
|
||||
outFile, err := os.Create(localPath)
|
||||
if err != nil {
|
||||
return stats, err
|
||||
}
|
||||
defer outFile.Close()
|
||||
|
||||
for _, url := range []string{file.Urls.Cloudflare, file.Urls.Digitalocean, file.Urls.None} {
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
outFile.Close()
|
||||
return stats, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
outFile.Close()
|
||||
return stats, fmt.Errorf("failed to download update from %s, status code: %d", url, resp.StatusCode)
|
||||
}
|
||||
|
||||
_, err = io.Copy(outFile, resp.Body)
|
||||
if err != nil {
|
||||
outFile.Close()
|
||||
return stats, err
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
outFile.Close()
|
||||
stats.updated += 1
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user