From 013b8c479f165ca78e3a8029c76af9c91ec192b9 Mon Sep 17 00:00:00 2001 From: Evan Burkey Date: Thu, 5 Jun 2025 16:45:03 -0700 Subject: [PATCH] add ability to launch epoch client --- README.md | 2 +- config.go | 59 +++++++++++++++++++++++++++++++++ main.go | 96 +++++++++++++++++++++++------------------------------- release.sh | 2 +- 4 files changed, 102 insertions(+), 57 deletions(-) create mode 100644 config.go diff --git a/README.md b/README.md index f7dde67..97816ec 100644 --- a/README.md +++ b/README.md @@ -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 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. 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 5. Use your launcher or tool of choice to startup Epoch in `wine` diff --git a/config.go b/config.go new file mode 100644 index 0000000..36b39db --- /dev/null +++ b/config.go @@ -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 +} diff --git a/main.go b/main.go index dfef8a6..59756a6 100644 --- a/main.go +++ b/main.go @@ -3,88 +3,74 @@ package main import ( "crypto/md5" "encoding/hex" + "flag" "fmt" - "github.com/BurntSushi/toml" "io" "log" "net/http" "os" + "os/exec" "path/filepath" + "runtime" "strings" ) const ( - manifestUrl = "https://updater.project-epoch.net/api/manifest" - defaultWowPath = "/path/to/wow" - configDirName = "epochcli" - configName = "config.toml" + manifestUrl = "https://updater.project-epoch.net/api/manifest" + defaultWowPath = "/path/to/wow" + defaultLaunchCmd = "not configured" ) -type Config struct { - WowDir string -} +func main() { + var ( + 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() -var ( - config Config -) - -func setupConfig() error { - home := os.Getenv("HOME") - if home == "" { - 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) + if helpFlag { + flag.CommandLine.SetOutput(os.Stdout) + flag.PrintDefaults() os.Exit(0) } - _, err := toml.DecodeFile(cfgPath, &config) - 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() + config, err := setupConfig() if err != nil { 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 { log.Fatal(err) } fmt.Printf("Updated %d files\n", count) + + if updateOnlyFlag { + os.Exit(0) + } + + 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() (int, error) { +func downloadUpdate(config *Config) (int, error) { var c int manifest, err := getManifest() diff --git a/release.sh b/release.sh index 9e96234..4dbc496 100755 --- a/release.sh +++ b/release.sh @@ -2,7 +2,7 @@ set -e -rm ./*.tar.gz +rm -f ./*.tar.gz mkdir bin