diff --git a/config/config.go b/config/config.go index 383c1ac..4ea519d 100644 --- a/config/config.go +++ b/config/config.go @@ -13,6 +13,7 @@ import ( // region Config struct type Config struct { + SteamCMDPath string `json:"steamCMDPath"` } // endregion @@ -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 @@ -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 { @@ -57,12 +62,14 @@ 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()) @@ -70,7 +77,7 @@ func (c *ConfigController) GetConfig() bool { } //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 @@ -84,7 +91,7 @@ func (c *ConfigController) GetConfig() bool { return false } - c.Config = conf + c.Config = &conf return true } diff --git a/installer/installer_controller.go b/installer/installer_controller.go index 861e741..f22b52a 100644 --- a/installer/installer_controller.go +++ b/installer/installer_controller.go @@ -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" @@ -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) { @@ -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 := "" @@ -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 diff --git a/main.go b/main.go index 188c225..205dec0 100644 --- a/main.go +++ b/main.go @@ -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