add ability to launch epoch client

This commit is contained in:
2025-06-05 16:45:03 -07:00
parent 1a6af606ff
commit 013b8c479f
4 changed files with 102 additions and 57 deletions

View File

@ -17,7 +17,7 @@ For macOS, the [Kegworks Wineskin port](https://github.com/Kegworks-App/Kegworks
1. Download the latest binary from the [releases](https://git.burkey.co/eburk/epochcli/releases) page 1. Download the latest binary from the [releases](https://git.burkey.co/eburk/epochcli/releases) page
2. If you have the `go` toolchain installed, you can run `go install git.burkey.co/eburk/epochcli` to install to your `$GOROOT` 2. If you have the `go` toolchain installed, you can run `go install git.burkey.co/eburk/epochcli` to install to your `$GOROOT`
3. Compile the source yourself 3. Compile the source yourself
3. Run `epochcli` once. This will create a config file at `$HOME/.config/epochcli/config.toml`. Change the `WowDir` variable to your Wow game directory 3. Run `epochcli` once. This will create a config file at `$HOME/.config/epochcli/config.toml`. Update the variables with the appropriate information
4. Run `epochcli` again. It will download the patch files from Epoch's servers to your Wow directory 4. Run `epochcli` again. It will download the patch files from Epoch's servers to your Wow directory
5. Use your launcher or tool of choice to startup Epoch in `wine` 5. Use your launcher or tool of choice to startup Epoch in `wine`

59
config.go Normal file
View File

@ -0,0 +1,59 @@
package main
import (
"fmt"
"github.com/BurntSushi/toml"
"os"
"path/filepath"
)
type Config struct {
WowDir string
LaunchCmd string
}
const (
configDirName = "epochcli"
configName = "config.toml"
)
var cfgPath string
func setupConfig() (*Config, error) {
home := os.Getenv("HOME")
if home == "" {
return nil, fmt.Errorf("$HOME environment variable not set")
}
newConfig := Config{
WowDir: defaultWowPath,
LaunchCmd: defaultLaunchCmd,
}
cfgPath = filepath.Join(home, ".config", configDirName, configName)
if _, statErr := os.Stat(cfgPath); os.IsNotExist(statErr) {
os.MkdirAll(filepath.Join(home, ".config", configDirName), 0755)
file, err := os.Create(cfgPath)
if err != nil {
return nil, err
}
defer file.Close()
encoder := toml.NewEncoder(file)
if err = encoder.Encode(newConfig); err != nil {
return nil, err
}
fmt.Printf("Created new config at %s, edit it before running the launcher again\n", cfgPath)
os.Exit(0)
}
_, err := toml.DecodeFile(cfgPath, &newConfig)
if err != nil {
return nil, err
}
return &newConfig, nil
}

88
main.go
View File

@ -3,88 +3,74 @@ package main
import ( import (
"crypto/md5" "crypto/md5"
"encoding/hex" "encoding/hex"
"flag"
"fmt" "fmt"
"github.com/BurntSushi/toml"
"io" "io"
"log" "log"
"net/http" "net/http"
"os" "os"
"os/exec"
"path/filepath" "path/filepath"
"runtime"
"strings" "strings"
) )
const ( const (
manifestUrl = "https://updater.project-epoch.net/api/manifest" manifestUrl = "https://updater.project-epoch.net/api/manifest"
defaultWowPath = "/path/to/wow" defaultWowPath = "/path/to/wow"
configDirName = "epochcli" defaultLaunchCmd = "not configured"
configName = "config.toml"
) )
type Config struct { func main() {
WowDir string
}
var ( var (
config Config helpFlag bool
updateOnlyFlag bool
) )
flag.BoolVar(&helpFlag, "h", false, "Print help")
flag.BoolVar(&updateOnlyFlag, "u", false, "Only update the client, do not launch")
flag.Parse()
func setupConfig() error { if helpFlag {
home := os.Getenv("HOME") flag.CommandLine.SetOutput(os.Stdout)
if home == "" { flag.PrintDefaults()
return fmt.Errorf("$HOME environment variable not set")
}
cfgPath := filepath.Join(home, ".config", configDirName, configName)
if _, statErr := os.Stat(cfgPath); os.IsNotExist(statErr) {
os.MkdirAll(filepath.Join(home, ".config", configDirName), 0755)
newConfig := &Config{
WowDir: defaultWowPath,
}
file, err := os.Create(cfgPath)
if err != nil {
return err
}
defer file.Close()
encoder := toml.NewEncoder(file)
if err = encoder.Encode(newConfig); err != nil {
return err
}
fmt.Printf("Created new config at %s, edit it before running the launcher again\n", cfgPath)
os.Exit(0) os.Exit(0)
} }
_, err := toml.DecodeFile(cfgPath, &config) config, err := setupConfig()
if err != nil {
return err
}
if config.WowDir == defaultWowPath {
return fmt.Errorf("WowDir in %s is still the default setting", cfgPath)
}
return nil
}
func main() {
err := setupConfig()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
count, err := downloadUpdate() if config.WowDir == defaultWowPath {
log.Fatalf("WowDir in %s is still the default setting, exiting", cfgPath)
}
if !updateOnlyFlag && config.LaunchCmd == defaultLaunchCmd {
log.Fatalf("LaunchCmd in %s is still the default setting, exiting\n", cfgPath)
}
count, err := downloadUpdate(config)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
fmt.Printf("Updated %d files\n", count) fmt.Printf("Updated %d files\n", count)
if updateOnlyFlag {
os.Exit(0)
} }
func downloadUpdate() (int, error) { fmt.Printf("Starting Epoch....\n", count)
switch runtime.GOOS {
case "darwin":
exec.Command("open", config.LaunchCmd).Run()
case "linux":
exec.Command(config.LaunchCmd).Run()
}
}
func downloadUpdate(config *Config) (int, error) {
var c int var c int
manifest, err := getManifest() manifest, err := getManifest()

View File

@ -2,7 +2,7 @@
set -e set -e
rm ./*.tar.gz rm -f ./*.tar.gz
mkdir bin mkdir bin