RetroPie forum home
    • Recent
    • Tags
    • Popular
    • Home
    • Docs
    • Register
    • Login

    SaveStateManager - a script to delete your savestates

    Scheduled Pinned Locked Moved Ideas and Development
    cyperghostsavestatemanager
    11 Posts 4 Posters 2.3k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • cyperghostC
      cyperghost @cyperghost
      last edited by cyperghost

      Updated to version 1.31

      Troubleshooting

      Updated script to v1.22

      28.01.2018

      v1.22 is a bug fixed 1.21, the detection of the rom and srm pathes is improved, due missing response and as I'm using updated RetroPie versions since 4.0.2 some config files got a massiv change! So if the first character of the path_string is / then it's a valid path.

      Hello fellows,

      I'm (a bit) proud to introduce the SaveStateManager script. As I created the SaveStateChecker all requirement were there to write also a Manager script.

      The script is best called with the famous User Menu that was introduced by BuZz. To get the script working we need just to parse system = $1 and rom = $3 to it. Then we have a nice selection of all Savestates (also the autosaves) and the SRM-files (the battery save) and we can delete them.

      To install:

      1. Get the script from the box below and place it to a space were no man has gone before maybe /home/pi/RetroPie/scripts/SaveStateManager.sh
        1.1 You can use command from 1.2 to directly download from github to desired location
        1.2 wget http://raw.githubusercontent.com/crcerror/RetroPie-UserMenu-SaveStateManager/master/SaveStateManager.sh -O /home/pi/RetroPie/scripts/SaveStateManager.sh
      2. We make the script executable with chmod +x /home/pi/RetroPie/scripts/SaveStateManager.sh
      3. We create a small script in /opt/retropie/configs/all/runcommand-menu/SaveStateManager.sh
        3.1 We just make a small one liner /home/pi/RetroPie/scripts/SaveStateManager.sh "$3" all
        3.2 You see $3 is placed first in quotes, after this allrepresents the system. We can also use $1
      4. To use the script run your ROM
      5. Now if the grey box apperas, press a controller button
      6. Access UserMenu and run SaveStateManger
      7. Now delete your SaveStates you are fed off
        IN THIS VERSION THERE IS NO ROM DISPLAYED!!
        The pictures show a recent version (1.2??) but the look is equal to current 1.31

      1. Rewrite of code for better array handling (thx @meleu for his rpi-art)
      2. Dialogs are now working as they should
      3. Dialogs can now launch the ROM or bring you back to runcommand or ES
      4. Deleted savefiles will fade out of list
      5. Better Detection of SRM filestates
      6. Nice countdown if you try to launch a ROM

      Picture Gallery

      1. I want to try to delete an Automatic generated save file

      pic

      2. I am asked if I really want to delete this file

      pic

      3. As you see, the entry is faded away and can't be selected anymore

      pic

      4. Now lets try to delete the SaveState Slot 10

      pic

      5. Here I'm also asked to erase this file

      pic

      6. Voilá the entry for SaveState Slot 10 is past now

      pic


      Now some greetings to people ;)
      to @pjft @mattrixk @madmodder123 @retroprogrammer @Yahmez

      1 Reply Last reply Reply Quote 4
      • madmodder123M
        madmodder123
        last edited by

        @cyperghost
        Looks good, I think that it should automatically filter the ROM files out, if you have a giant set of ROMs, that would be a LOT of scrolling.

        mituM 1 Reply Last reply Reply Quote 0
        • PokeEngineerP
          PokeEngineer
          last edited by

          @cyperghost

          Awesome work!

          Don't sweat it.
          When in doubt, take a BYTE out of life.

          😎

          1 Reply Last reply Reply Quote 0
          • mituM
            mitu Global Moderator @madmodder123
            last edited by

            @madmodder123 I think the script works in the context of launching a ROM, through the Runcommand user menu, so it only shows the save states and ram saves for the ROM you're currently playing, not for all ROMs that have save states.
            @cyperghost Nice work !
            One suggestion though - maybe remove the option to delete the ROM ? Since the script is geared towards managing save states and it doesn't allow the deletion of the ROM anyway, wouldn't be better to just not have this option at all ?

            1 Reply Last reply Reply Quote 1
            • cyperghostC
              cyperghost
              last edited by cyperghost

              @mitu
              You can't delete a ROM. You will need to change the script for doing this. It shows the ROM caused by status_array=("$status_path/$rom_no_ext."*) Then I check how much entries are in. If it's only one (Just ROM-name or empty) it will abort. Otherwise I had to check every entry for file extension.
              I know only one situation it can happen. That would be PSX. Because you have 2 files. An image (BIN, IMG) and a CUE. So you might can delete the IMG or BIN.

              All in all you are right. It shows just states of currently loaded ROM and this is the intention that you can only call it via USER MENU.

              But @madmodder123 is right. It's no problem to extend this and search system-wide for savestates. This script then should be nested into RetroPie-Menu. There is a codepiece here in the forum that I've once written to make a system wide selection possible. :)

              mituM 1 Reply Last reply Reply Quote 0
              • mituM
                mitu Global Moderator @cyperghost
                last edited by mitu

                @cyperghost said in SaveStateManager - a script to delete your savestates:

                ("$status_path/$rom_no_ext."*)

                I don't have the PI right now to test, but would it work if you changed it to

                ("$status_path/$rom_no_ext."{state*,srm,auto})
                

                This should select based on ROM basename and the list of extensions in the accolades.

                cyperghostC 1 Reply Last reply Reply Quote 0
                • cyperghostC
                  cyperghost @mitu
                  last edited by cyperghost

                  @mitu I created v1.21 (this disables the ROM file and shows only SRM and STATES (also Autosaves!)
                  But I prefer the older version....

                  # cyperghosts SavestateManager 1.21 
                  # ROM will not show in list
                  # 24.01.2018
                  # This will let you delete determinated SaveStates of choosen ROMfile
                  # This script is best called into RetroPie's User Menu
                  # Press 'any' key during loading screen and get access to runcommand menu
                  # There choose 'User Menu'
                  #
                  # by cyperghost for retropie.org.uk
                  #
                  # rom=$3, is first parameter
                  # system=$1, is second parameter
                  # So for exp. ./savestate.sh  $1 $3 or ./savestate.sh $1 all
                  
                  [ -z "$2" ] && echo "SaveStateManager Check: Please parse system parameter! Error!" >&2 && exit 1
                  [ -z "$1" ] && echo "SaveStateManager Check: Please parse rompath! Error!" >&2 && exit 1
                  
                      rom="$1"
                      system="$2"
                      rom_name="$(basename "$rom")"
                      rom_path="$(dirname "$rom")"
                      rom_no_ext="${rom_name%.*}"
                  
                      config_dir="/opt/retropie/configs/$system"
                      config_file="$config_dir/retroarch.cfg"
                  
                  # This sniplet is part of hiulits Boilerplate script thank you!
                  # This will determine path of SRM and STATUS directory
                  func_get_config() {
                      config="$(grep -Po "(?<=^$1 = ).*" "$config_file")"
                      config="${config%\"}"
                      config="${config#\"}"
                  }
                  
                  func_get_savepathes() {
                      # GET SRM file location
                      func_get_config "savefile_directory"
                      [ "${config^^}" = "DEFAULT" ] && srm_path="$rom_path" || srm_path="$config"
                  
                      # GET STATE file location
                      func_get_config "savestate_directory"
                      [ "${config^^}" = "DEFAULT" ] && status_path="$rom_path" || status_path="$config"
                  }
                  
                  func_save_del() {
                      # Delete Save games
                      # Is Array value already empty? If Yes then return
                      [ -z "${status_array[$2-1]}" ] && return
                  
                      # Is this entry is a ROM
                      # If yes then display a Info, if no erase file and erase all Arrays with
                      # related entry
                  
                      if [ "$1" = "$rom" ]; then
                          dialog --cancel-label "Launch ROM" \
                                 --pause "This is a ROM file! I don't delete this!" 8 45 5
                              [ $? = 1 ] && exit 2
                        else
                          dialog --yesno "I will delete following SaveState after you choose YES\n\n$1\n" 10 60
                              [ $? = 0 ] && rm -f "$1" && status_array[$2-1]="" && options[$2*2-1]=""
                      fi
                  }
                  
                  func_get_savepathes
                  
                  # Determinine number of Statussavegames!
                  # Is Array valid? (Maybe here some code magic can help me?)
                  
                      z=("$status_path/$rom_no_ext.state"*)
                      [ "${z#*.state}" != "*" ] && status_array+=("${z[@]}")
                      [ -f "$srm_path/$rom_no_ext.srm" ] && status_array+=("$srm_path/$rom_no_ext.srm")    
                      unset z
                  
                  
                      idx=${#status_array[@]}                             #Get Array size
                  
                  # Array validity check!
                      [ $idx = 0 ] && dialog --infobox "No Savestate found!" 0 0 && sleep 3 && exit
                  
                  # Building Choices Array for options
                  # Means "counter Text counter Text"
                      for (( z=0; z<$idx; z++ ))
                          do
                              options+=($(( $z + 1 )))
                              options+=("${status_array[$z]##*/}")
                          done
                  
                  # Create Entry for several Exit options at last positions
                      options+=("L")
                      options+=("Launch ROM")
                      options+=("R")
                      options+=("Exit to RunCommand")
                      options+=("X")
                      options+=("Exit to EmulationStation")
                  
                  # Build Dialog output of SaveState selection
                  while true
                  do
                  
                  cmd=(dialog --backtitle "cyperghosts - SaveStateManager" \
                              --title "ROM: ${rom_no_ext%%(*}" \
                              --cancel-label "Launch ROM" \
                              --menu "Select SaveState to delete:" 18 65 16)
                  choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
                  
                      case $choices in
                          X) exit 1 ;;
                          L) exit 2 ;;
                          R) exit 0 ;;
                          [1-999]) func_save_del "${status_array[$choices-1]}" "$choices" ;;
                          *) exit 2 ;;
                      esac
                  done
                  

                  @mitu said in SaveStateManager - a script to delete your savestates:

                  ("$status_path/$rom_no_ext."*)

                  I don't have the PI right now to test, but would it work if you changed it to
                  ("$status_path/$rom_no_ext."{state*,srm,auto})

                  This should select based on ROM basename and the list of extensions in the accolades.

                  So I'm at home and I can explain a bit more.
                  If you assign state* and srm to the array mask then there are two possibilites. The file is located there and assigned (good!) There is no file and then it will be just located as character into the array! So you have to find ways to prove if the file is valid. I did that with the testcommand -f in v1.21

                  In 1.20 I just ask for ROMName without extension then it's clear what happens! I find the ROMName and all savestates and possible the SRM state within just one loop. If the array contains only 1 entry it's just the rom-name itself. Therefore I check the arrays if the last character is * if yes then it's just an empty entry.

                  I think v1.21 is more specialiced to really find SaveStates and SRM files
                  1.20 is a bit more bare but seems to be better prepared for more usecases.
                  If I get more feedback I can improve this script. But for now both versions work fine!

                  1 Reply Last reply Reply Quote 1
                  • cyperghostC
                    cyperghost
                    last edited by

                    Old version 1.2

                    # cyperghosts SavestateManager 1.2
                    # 23.01.2018
                    # This will let you delete determinated SaveStates of choosen ROMfile
                    # This script is best called into RetroPie's User Menu
                    # Press 'any' key during loading screen and get access to runcommand menu
                    # There choose 'User Menu'
                    #
                    # by cyperghost for retropie.org.uk
                    #
                    # rom=$3, is first parameter
                    # system=$1, is second parameter
                    # So for exp. ./savestate.sh  $1 $3 or ./savestate.sh $1 all
                    
                    [ -z "$2" ] && echo "SaveStateManager Check: Please parse system parameter! Error!" >&2 && exit 1
                    [ -z "$1" ] && echo "SaveStateManager Check: Please parse rompath! Error!" >&2 && exit 1
                    
                        rom="$1"
                        system="$2"
                        rom_name="$(basename "$rom")"
                        rom_path="$(dirname "$rom")"
                        rom_no_ext="${rom_name%.*}"
                    
                        config_dir="/opt/retropie/configs/$system"
                        config_file="$config_dir/retroarch.cfg"
                    
                    # This sniplet is part of hiulits Boilerplate script thank you!
                    # This will determine path of SRM and STATUS directory
                    func_get_config() {
                        config="$(grep -Po "(?<=^$1 = ).*" "$config_file")"
                        config="${config%\"}"
                        config="${config#\"}"
                    }
                    
                    func_get_savepathes() {
                        # GET SRM file location
                        func_get_config "savefile_directory"
                        [ "${config^^}" = "DEFAULT" ] && srm_path="$rom_path" || srm_path="$config"
                    
                        # GET STATE file location
                        func_get_config "savestate_directory"
                        [ "${config^^}" = "DEFAULT" ] && status_path="$rom_path" || status_path="$config"
                    }
                    
                    func_save_del() {
                        # Delete Save games
                        # Is Array value already empty? If Yes then return
                        [ -z "${status_array[$2-1]}" ] && return
                    
                        # Is this entry is a ROM
                        # If yes then display a Info, if no erase file and erase all Arrays with
                        # related entry
                    
                        if [ "$1" = "$rom" ]; then
                            dialog --cancel-label "Launch ROM" \
                                   --pause "This is a ROM file! I don't delete this!" 8 45 5
                                [ $? = 1 ] && exit 2
                          else
                            dialog --yesno "I will delete following SaveState after you choose YES\n\n$1\n" 10 60
                                [ $? = 0 ] && rm -f "$1" && status_array[$2-1]="" && options[$2*2-1]=""
                        fi
                    }
                    
                    func_get_savepathes
                    
                    # Determinine number of Statussavegames!
                    # Is Array valid? (Maybe here some code magic can help me?)
                    
                        status_array=("$status_path/$rom_no_ext."*)        #Build Array
                    
                        if [ "$srm_path" != "$status_path" ]; then         #Build Array SRM only
                            z=("$srm_path/$rom_no_ext."*)
                            [ "${z#*.}" != "*" ] && status_array+=("${z[@]}")
                        fi
                    
                        idx=${#status_array[@]}                             #Get Array size
                    
                    # Array validity check!
                        [ $idx = 1 ] && dialog --infobox "No Savestate found!" 0 0 && sleep 3 && exit
                    
                    # Building Choices Array for options
                    # Means "counter Text counter Text"
                        for (( z=0; z<$idx; z++ ))
                            do
                                options+=($(( $z + 1 )))
                                options+=("${status_array[$z]##*/}")
                            done
                    
                    # Create Entry for several Exit options at last positions
                        options+=("L")
                        options+=("Launch ROM")
                        options+=("R")
                        options+=("Exit to RunCommand")
                        options+=("X")
                        options+=("Exit to EmulationStation")
                    
                    # Build Dialog output of SaveState selection
                    while true
                    do
                    
                    cmd=(dialog --backtitle "cyperghosts - SaveStateManager" \
                                --title "ROM: ${rom_no_ext%%(*}" \
                                --cancel-label "Launch ROM" \
                                --menu "Select SaveState to delete:" 18 65 16)
                    choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
                    
                        case $choices in
                            X) exit 1 ;;
                            L) exit 2 ;;
                            R) exit 0 ;;
                            [1-999]) func_save_del "${status_array[$choices-1]}" "$choices" ;;
                            *) exit 2 ;;
                        esac
                    done
                    
                    
                    cyperghostC 1 Reply Last reply Reply Quote 0
                    • cyperghostC
                      cyperghost @cyperghost
                      last edited by

                      @cyperghost

                      Added newer version to github
                      https://github.com/crcerror/RetroPie-UserMenu-SaveStateManager

                      1 Reply Last reply Reply Quote 3
                      • cyperghostC
                        cyperghost
                        last edited by

                        version 2 in light and extended version available --- see first posting!

                        • Complete rewrite
                        • Select more then one savestate with B-button (selection list)
                        • Extra Menu added
                        • Backup of Savestates added
                        • Mass delete added (for current game)
                        • Rename gamestates to .state.auto (extended version)
                        • Rename gamestate to .state0 (extended version)
                        • Remove all gamesstates except selected one (extended version)
                        1 Reply Last reply Reply Quote 1
                        • First post
                          Last post

                        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.