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

Commit

Permalink
Ini files not found (#176)
Browse files Browse the repository at this point in the history
* bug: Allow paths with spaces

Before this path's with spaces in them did not work, now to path is escaped between "" to make it work.

* bug: Make ini files if they don't exist

* bug: Made so that values are always defined

* bug: Made so that values are always defined
  • Loading branch information
JensvandeWiel committed Jan 5, 2024
1 parent 374d636 commit db3ac5a
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 11 deletions.
18 changes: 18 additions & 0 deletions frontend/src/helpers/ini.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// getVal is a function that takes a gus object, a section, a key, and an index, and returns a string. This function is used to handle when anything is undefined, if so it creates it.
export function getVal(gus: { [key: string]: { [key: string]: Array<string> } }, section: string, key: string, index: number = 0): string {

if (!gus[section]) {
gus[section] = {};
}

if (!gus[section][key]) {
gus[section][key] = [];
}

if (!gus[section][key][index]) {
gus[section][key][index] = '';
return gus[section][key][index];
}

return gus[section][key][index];
}
18 changes: 8 additions & 10 deletions frontend/src/pages/server/General.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { PasswordInput } from "../../components/PasswordInput";
import { Slider } from "../../components/Slider";
import { useAlert } from "../../components/AlertProvider";
import { EventsOn } from "../../../wailsjs/runtime";
import {getVal} from "../../helpers/ini";

type Props = {
setServ: React.Dispatch<React.SetStateAction<server.Server>>;
Expand Down Expand Up @@ -136,9 +137,7 @@ function GeneralSettings({ setServ, serv, setGus, gus }: Props) {
>
<Slider
value={parseFloat(
gus["ServerSettings"][
"AutoSavePeriodMinutes"
][0] ?? "0",
getVal(gus, "ServerSettings", "AutoSavePeriodMinutes") ?? "0",
)}
onChange={(v) => {
setGus((p) => {
Expand All @@ -161,11 +160,11 @@ function GeneralSettings({ setServ, serv, setGus, gus }: Props) {
<FormLabel>Message</FormLabel>
<Textarea
minRows={5}
value={gus["MessageOfTheDay"].Message[0]}
value={getVal(gus, "MessageOfTheDay", "Message")}
onChange={(e) => {
setGus((p) => {
const newState = { ...p };
newState["MessageOfTheDay"].Message[0] =
newState["MessageOfTheDay"]["Message"][0] =
e.target.value;
return newState;
});
Expand All @@ -184,7 +183,7 @@ function GeneralSettings({ setServ, serv, setGus, gus }: Props) {
sliderMax={240}
value={
parseFloat(
gus["MessageOfTheDay"].Duration[0],
getVal(gus, "MessageOfTheDay", "Duration"),
) ?? 0
}
onChange={(v) => {
Expand Down Expand Up @@ -253,8 +252,7 @@ function GeneralSettings({ setServ, serv, setGus, gus }: Props) {
sliderMax={3600}
value={
parseFloat(
gus["ServerSettings"]
.KickIdlePlayersPeriod[0],
getVal(gus, "ServerSettings", "KickIdlePlayersPeriod"),
) ?? 0
}
onChange={(v) => {
Expand All @@ -275,7 +273,7 @@ function GeneralSettings({ setServ, serv, setGus, gus }: Props) {
<div className={"space-y-2"}>
<FormLabel>Ban list url:</FormLabel>
<Input
value={gus["ServerSettings"]["BanListURL"]}
value={getVal(gus, "ServerSettings", "BanListURL")}
onChange={(e) => {
setGus((p) => {
const newState = { ...p };
Expand All @@ -290,7 +288,7 @@ function GeneralSettings({ setServ, serv, setGus, gus }: Props) {
<div className={"space-y-2"}>
<FormLabel>Allowed Cheaters URL:</FormLabel>
<Input
value={gus["ServerSettings"]["AllowedCheatersURL"]}
value={getVal(gus, "ServerSettings", "AllowedCheatersURL")}
onChange={(e) => {
setGus((p) => {
const newState = { ...p };
Expand Down
2 changes: 1 addition & 1 deletion installer/installer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (c *InstallerController) InstallUpdateVerify(installPath string) error {
}

c.config.GetConfig()
steamCMDPath = c.config.Config.SteamCMDPath
steamCMDPath = "\"" + c.config.Config.SteamCMDPath + "\""

prompts := []*gosteamcmd.Prompt{
gosteamcmd.ForceInstallDir("\"" + installPath + "\""),
Expand Down
11 changes: 11 additions & 0 deletions server/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ import (
func (s *Server) getGame() (*ini.IniFile, error) {
gamePath := filepath.Join(s.ServerPath, "ShooterGame", "Saved", "Config", "WindowsServer", "Game.ini")

if _, err := os.Stat(gamePath); os.IsNotExist(err) {
err = os.MkdirAll(filepath.Dir(gamePath), 0644)
if err != nil {
return nil, err
}
err = os.WriteFile(gamePath, []byte(""), 0644)
if err != nil {
return nil, err
}
}

gameContent, err := os.ReadFile(gamePath)
if err != nil {
return nil, errors.New("error reading Game.ini: " + err.Error())
Expand Down
10 changes: 10 additions & 0 deletions server/gus.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ var duplicateKeys = []string{}
// getGus returns the GameUserSettings.ini file as an ini.IniFile struct
func (s *Server) getGus() (*ini.IniFile, error) {
gusPath := filepath.Join(s.ServerPath, "ShooterGame", "Saved", "Config", "WindowsServer", "GameUserSettings.ini")
if _, err := os.Stat(gusPath); os.IsNotExist(err) {
err = os.MkdirAll(filepath.Dir(gusPath), 0644)
if err != nil {
return nil, err
}
err = os.WriteFile(gusPath, []byte(""), 0644)
if err != nil {
return nil, err
}
}

gusContent, err := os.ReadFile(gusPath)
if err != nil {
Expand Down

0 comments on commit db3ac5a

Please sign in to comment.