Please do not post a support request without first reading and following the advice in https://retropie.org.uk/forum/topic/3/read-this-first

Dirty Little RetroArch.cfg writer



  • Hello fellows,

    this is a small script that may be usefull if you want to set some configs from retroarch.cfg without using nano or any other editor.

    My usecase is, that all autosaves option are activated by default (didn't want that). So I can search every retroarch.cfg for each system and change value manually or I let a small script do this.

    Greetings to @hiulit - this is to 90% his work

    My dedicated runcommand-onstart.sh looks like this nowadays

    # Start/Stop BGM
    pkill -STOP mpg123
    
    # Activate/Deactivate RetroAchievements 
    $HOME/RetroPie/scripts/RetroAchievements.sh "$3" "$1"
    
    # This script writes any parameter to a keyvalue
    # Attention parameter #3 can called as "USETHEFORCE" then Parameter #4 will be written to key without precheck!
    $HOME/RetroPie/scripts/SetRetroArchCfg.sh "$1" "savestate_auto_save" "true" "false"
    
    # Show number of SaveStates for ROM
    $HOME/RetroPie/scripts/SaveStateCheck.sh "$3" all 5
    

    Here is the small code ...

    !/bin/bash
    # This will just check and write some value to RetroArch.cfg
    # Usage of Parameters
    # 1. Parameter is for system
    # 2. Is for key value in RetroArch.cfg
    # 3. Is for key value readout, if this value is in your config setted now
    # 4. Is for key value write
    
    # So we check for for setted and config and write if it was found
    # You can disable this check if you write "USETHEFORCE" as parameter
    
    # Get and check parameters
    system="$1"
    key="$2"
    value_get="$3"
    value_set="$4"
    
    [ -z "$1" ] && echo "SetRetroArchCfg: Wrong parameters setted - set a system" >&2 && exit 1
    [ -z "$2" ] && echo "SetRetroArchCfg: Wrong parameters setted - set a key to search for" >&2 && exit 1
    [ -z "$3" ] && echo "SetRetroArchCfg: Wrong parameters setted - set a key value to check" >&2 && exit 1
    [ -z "$4" ] && echo "SetRetroArchCfg: Wrong parameters setted - set a key value to write" >&2 && exit 1
    
    # Path to RetroArch.cfg
    config_dir="/opt/retropie/configs/$system"
    config_file="$config_dir/retroarch.cfg"
    
    
    # This is part of hiulits Boilder Script!
    # Thank you!
    # USAGE:
    # set_config "[KEY]" "[VALUE]" - Sets the VALUE to the KEY in $SCRIPT_CFG.
    # get_config "[KEY]" - Returns the KEY's VALUE in $SCRIPT_CFG.
    
    function set_config() {
        sed -i "s|^\($1\s*=\s*\).*|\1\"$2\"|" "$config_file"
        echo "\"$1\" set to \"$2\"." && sleep 3
    }
    
    function get_config() {
        config="$(grep -Po "(?<=^$1 = ).*" "$config_file")"
        config="${config%\"}"
        config="${config#\"}"
    }
    
    [ "$value_get" = "USETHEFORCE" ] && force=1
    
    # ReadOut and check
    get_config "$key"
    if [ "$value_get" = "$config" ] || [ $force ]; then
        set_config "$key" "$value_set"
    fi
    

  • administrators

    @cyperghost said in Dirty Little RetroArch.cfg writer:

    So I can search every retroarch.cfg for each system and change value manually or I let a small script do this.

    So long as the user knows the ramifications of editing retroarch.cfg files and the heirarchy of them. Would this not also be simply accomplished through the configuration editor? If you're making the change to all of them you only need to change one retroarch.cfg rather than modifying each system retroarch.cfg



  • @herb_fargus The setup I have for RetroPie is the same since Jessie came out (I think RetroPie 4.0.2??) so some configurations are really old. So in my configuration every retroarch.cfg gots the own entry of input, savestates, display....

    So I can't just modify the system all and have "option" activated - maybe I rebuild the RetroPie once a time :)

    I realized of the .save.auto as I made the SaveStateCheck script here. As I tried some ROMs I saw that on every start a autosavestate was generated. As I tried to switch it off in system all it did not work. As I switched it off in the emulator system megadrive for ex. it works ;)

    That's the reason. But maybe someone can need this to trigger an event at runcommand-onstart.sh and to set it back om runcommand-onend.sh
    Who knows?


  • administrators

    @cyperghost said in Dirty Little RetroArch.cfg writer:

    maybe I rebuild the RetroPie once a time :)

    Sounds like a simpler option ;)



  • @herb_fargus said in Dirty Little RetroArch.cfg writer:

    @cyperghost said in Dirty Little RetroArch.cfg writer:

    maybe I rebuild the RetroPie once a time :)

    Sounds like a simpler option ;)

    Indeed! But does not make so much fun!


Log in to reply
 

Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.

Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.