From 32cdf2e412d4e0ffc0d02e2d8268a5b3d05a0a42 Mon Sep 17 00:00:00 2001 From: chacha <1000chacha0001@gmail.com> Date: Sun, 17 Jul 2022 00:20:55 +0000 Subject: [PATCH] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20'Run.sh'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit implement 'config' command in Run.sh --- Run.sh | 77 +++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 66 insertions(+), 11 deletions(-) diff --git a/Run.sh b/Run.sh index 6004fb6..92eb9b4 100644 --- a/Run.sh +++ b/Run.sh @@ -8,6 +8,9 @@ function add_iniKeyEx() { # Warning: ugly hack with sed to allow multiple key instances + to remove space around '=' sed -i "s/[[:space:]]*__$(echo $3 | sed -e 's/\([[\/.*]\|\]\)/\\&/g')[[:space:]]*=[[:space:]]*/$(echo $3 | sed -e 's/\([[\/.*]\|\]\)/\\&/g')=/g" $OUTPUT_DIR/System/$1 } +function set_iniKeyEx() { + crudini --set $OUTPUT_DIR/System/$1 $2 __$3 $4 +} # !!Warning!! section is not considered function del_iniKeyEx() { sed -i "/[[:space:]]*$(echo $3 | sed -e 's/\([[\/.*]\|\]\)/\\&/g')[[:space:]]*=[[:space:]]*$(echo $4 | sed -e 's/\([[\/.*]\|\]\)/\\&/g')/d" $OUTPUT_DIR/System/$1 @@ -15,6 +18,9 @@ function del_iniKeyEx() { function add_iniKey() { add_iniKeyEx $CFG_FILE $1 $2 $3 } +function set_iniKey() { + set_iniKeyEx $CFG_FILE $1 $2 $3 +} # !!Warning!! section is not considered function del_iniKey() { del_iniKeyEx $CFG_FILE $1 $2 $3 @@ -56,12 +62,56 @@ function disable() { echo disable ok } +function config() { + case $# in + 5) + OptionKey=$4 + OptionValue=$5 + ;; + 4) + OptionKey=$3 + OptionValue=$4 + ;; + *) + echo "Not enough arguments" + show_help + exit 1 + ;; + esac + NIUT_FileName=$(find $OUTPUT_DIR/System -type f -iname "NIUT*.ini" -exec basename {} \;) + NIUT_BaseFileName="${NIUT%.*}" + case "$OptionKey" in + *) + set_iniKeyEx NIUT.ini "$NIUT_BaseFileName.NIUTMutator" $OptionKey $OptionValue + ;; + esac +} function show_help() { echo echo "Usage: $0 { install | enable | disable } []" echo } -function check_cfg_file() { +function check_cfg_file_config() { + if [ $# -eq 4 ] + then + echo "CFG_FILE is unset, setting it to $DEFAULT_CFG_FILE" + CFG_FILE=$DEFAULT_CFG_FILE + elif [ $# -eq 5 ] + then + echo "CFG_FILE is set to '$CFG_FILE'" + else + echo "Wrong number of arguments" + show_help + exit 9999 # die with error code 9999 + fi + if [ ! -f $OUTPUT_DIR/System/$CFG_FILE ] + then + echo "$OUTPUT_DIR/System/$CFG_FILE does not exist" + show_help + exit 9999 # die with error code 9999 + fi +} +function check_cfg_file_gen() { if [ -z ${CFG_FILE} ] then echo "CFG_FILE is unset, setting it to $DEFAULT_CFG_FILE" @@ -87,23 +137,28 @@ function check_game_dir() { } case "$1" in 'install') - check_game_dir - install + check_game_dir "$@" + install "$@" ;; 'enable') - check_game_dir - check_cfg_file - disable - enable + check_game_dir "$@" + check_cfg_file_gen "$@" + disable "$@" + enable "$@" + ;; + 'config') + check_game_dir "$@" + check_cfg_file_config "$@" + config "$@" ;; 'disable') - check_game_dir - check_cfg_file - disable + check_game_dir "$@" + check_cfg_file_gen "$@" + disable "$@" ;; *) show_help exit 1 ;; esac -exit 0 \ No newline at end of file +exit 0