Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Add steamcmdpath config variable (#41)
Browse files Browse the repository at this point in the history
* added steamCMDPath config var for install

* enhanced return val check

steamCMD can return non null return value without failing
  • Loading branch information
JensvandeWiel authored Oct 31, 2023
1 parent f6c9e81 commit 08093d6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
17 changes: 12 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
// region Config struct

type Config struct {
SteamCMDPath string `json:"steamCMDPath"`
}

// endregion
Expand All @@ -21,7 +22,7 @@ type Config struct {
type ConfigController struct {
ctx context.Context
configFileDir string
Config Config
Config *Config
}

// NewConfigController creates a new ConfigController application struct
Expand All @@ -43,6 +44,10 @@ func NewConfigController() *ConfigController {
func (c *ConfigController) Startup(ctx context.Context) {
c.ctx = ctx

//get and set config
c.GetConfig()
c.SaveConfig()

}

func (c *ConfigController) GetConfig() bool {
Expand All @@ -57,20 +62,22 @@ func (c *ConfigController) GetConfig() bool {
}

// Check if the config file exists
_, err := os.Stat(path.Join(c.configFileDir, "config.json"))
_, err := os.Stat(path.Join(c.configFileDir))
if err != nil {
if os.IsNotExist(err) {
runtime.LogDebug(c.ctx, "Config file does not exist, returning new configuration")
//TODO set new config
c.Config = Config{}
c.Config = &Config{}
//save so that the file exists
c.SaveConfig()
return true
}
runtime.LogError(c.ctx, "Error reading config file: "+err.Error())
return false
}

//It exists so read the file
cf, err := os.ReadFile(path.Join(c.configFileDir, "config.json"))
cf, err := os.ReadFile(path.Join(c.configFileDir))
if err != nil {
runtime.LogError(c.ctx, "Error reading config file: "+err.Error())
return false
Expand All @@ -84,7 +91,7 @@ func (c *ConfigController) GetConfig() bool {
return false
}

c.Config = conf
c.Config = &conf
return true
}

Expand Down
18 changes: 13 additions & 5 deletions installer/installer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package installer
import (
"context"
"fmt"
"github.com/JensvandeWiel/ArkAscendedServerManager/config"
"github.com/jensvandewiel/gosteamcmd"
"github.com/jensvandewiel/gosteamcmd/console"
"github.com/wailsapp/wails/v2/pkg/runtime"
Expand All @@ -12,11 +13,14 @@ import (
)

type InstallerController struct {
ctx context.Context
ctx context.Context
config *config.ConfigController
}

func NewInstallerController() *InstallerController {
return &InstallerController{}
func NewInstallerController(c *config.ConfigController) *InstallerController {
return &InstallerController{
config: c,
}
}

func (c *InstallerController) Startup(ctx context.Context) {
Expand All @@ -34,13 +38,17 @@ Events:
// Install installs the server and returns true is successful and error and false if failed
func (c *InstallerController) Install(installPath string) error {

//get steamcmd path
c.config.GetConfig()
steamCMDPath := c.config.Config.SteamCMDPath

prompts := []*gosteamcmd.Prompt{
gosteamcmd.ForceInstallDir(installPath),
gosteamcmd.Login("", "", ""),
gosteamcmd.AppUpdate(2430930, "", true),
}

cmd := gosteamcmd.New(io.Discard, prompts, "")
cmd := gosteamcmd.New(io.Discard, prompts, steamCMDPath)

cmd.Console.Parser.OnInformationReceived = func(action console.Action, progress float64, currentWritten, total uint64) {
actionString := ""
Expand Down Expand Up @@ -80,7 +88,7 @@ func (c *InstallerController) Install(installPath string) error {

}

if i != 0 {
if i != 0 && i != 7 {
return fmt.Errorf("failed to install: returned non 0 return code: " + strconv.Itoa(int(i)))
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func main() {
app := NewApp()
c := config.NewConfigController()
s := server.NewServerController()
i := installer.NewInstallerController()
i := installer.NewInstallerController(c)
h := helpers.NewHelpersController()

// Create application with options
Expand Down

0 comments on commit 08093d6

Please sign in to comment.