From db3ac5aa33a14e11f72683b6db862c804822fc2d Mon Sep 17 00:00:00 2001 From: Jens van de Wiel <85284773+JensvandeWiel@users.noreply.github.com> Date: Fri, 5 Jan 2024 13:24:04 +0100 Subject: [PATCH] Ini files not found (#176) * 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 --- frontend/src/helpers/ini.ts | 18 ++++++++++++++++++ frontend/src/pages/server/General.tsx | 18 ++++++++---------- installer/installer_controller.go | 2 +- server/game.go | 11 +++++++++++ server/gus.go | 10 ++++++++++ 5 files changed, 48 insertions(+), 11 deletions(-) create mode 100644 frontend/src/helpers/ini.ts diff --git a/frontend/src/helpers/ini.ts b/frontend/src/helpers/ini.ts new file mode 100644 index 0000000..71bbc0b --- /dev/null +++ b/frontend/src/helpers/ini.ts @@ -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 } }, 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]; +} \ No newline at end of file diff --git a/frontend/src/pages/server/General.tsx b/frontend/src/pages/server/General.tsx index 6183cf6..da31066 100644 --- a/frontend/src/pages/server/General.tsx +++ b/frontend/src/pages/server/General.tsx @@ -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>; @@ -136,9 +137,7 @@ function GeneralSettings({ setServ, serv, setGus, gus }: Props) { > { setGus((p) => { @@ -161,11 +160,11 @@ function GeneralSettings({ setServ, serv, setGus, gus }: Props) { Message