diff --git a/emu-configs/retroarch.cfg b/emu-configs/retroarch.cfg index db4b873e..752a0596 100644 --- a/emu-configs/retroarch.cfg +++ b/emu-configs/retroarch.cfg @@ -3067,9 +3067,9 @@ show_hidden_files = "false" slowmotion_ratio = "3.000000" soft_filter_enable = "false" soft_filter_index = "0" -sort_savefiles_by_content_enable = "false" +sort_savefiles_by_content_enable = "true" sort_savefiles_enable = "false" -sort_savestates_by_content_enable = "false" +sort_savestates_by_content_enable = "true" sort_savestates_enable = "false" sort_screenshots_by_content_enable = "false" state_slot = "0" diff --git a/global.sh b/global.sh index 29ad7ccb..60635e28 100755 --- a/global.sh +++ b/global.sh @@ -34,6 +34,16 @@ conf_write() { sed -i "s%roms_folder=.*%roms_folder=$roms_folder%" "$rd_conf" fi + if [ ! -z "$saves_folder" ] + then + sed -i "s%saves_folder=.*%saves_folder=$saves_folder%" "$rd_conf" + fi + + if [ ! -z "$states_folder" ] + then + sed -i "s%states_folder=.*%states_folder=$states_folder%" "$rd_conf" + fi + if [ ! -z "$media_folder" ] then sed -i "s%media_folder=.*%media_folder=$media_folder%" "$rd_conf" @@ -65,6 +75,8 @@ then version="$hard_version" # if we are here means that the we are in a new installation, so the version is valorized with the hardcoded one rdhome="$HOME/retrodeck" # the retrodeck home, aka ~/retrodeck roms_folder="$rdhome/roms" # the default roms folder path + saves_folder="$rdhome/saves" # the default saves folder path + states_folder="$rdhome/states" # the default states folder path media_folder="$rdhome/downloaded_media" # the media folder, where all the scraped data is downloaded into themes_folder="$rdhome/themes" # the themes folder sdcard="$default_sd" # Steam Deck SD default path @@ -74,6 +86,8 @@ then echo "version=$version" >> $rd_conf echo "rdhome=$rdhome" >> $rd_conf echo "roms_folder=$roms_folder" >> $rd_conf + echo "saves_folder=$saves_folder" >> $rd_conf + echo "states_folder=$states_folder" >> $rd_conf echo "media_folder=$media_folder" >> $rd_conf echo "themes_folder=$themes_folder" >> $rd_conf echo "sdcard=$sdcard" >> $rd_conf diff --git a/retrodeck.sh b/retrodeck.sh index 71de4556..d7831401 100644 --- a/retrodeck.sh +++ b/retrodeck.sh @@ -186,7 +186,7 @@ standalones_init() { ra_init() { dir_prep "$rdhome/bios" "/var/config/retroarch/system" - dir_prep "$rdhome/.logs/retroarch" "/var/config/retroarch/logs" + dir_prep "$rdhome/.logs/retroarch" "/var/config/retroarch/logs" mkdir -pv /var/config/retroarch/cores/ cp /app/share/libretro/cores/* /var/config/retroarch/cores/ cp -fv $emuconfigs/retroarch.cfg /var/config/retroarch/ @@ -261,19 +261,122 @@ post_update() { # Resetting es_systems, now we need it but in the future I should think a better solution, maybe with sed cp -fv /app/retrodeck/es_settings.xml /var/config/emulationstation/.emulationstation/es_settings.xml + # 0.4 -> 0.5 - # Saves migration - Part 1: Standalones - - #mv -fv OLD_CITRA_SAVES $rdhome/saves/n3ds/citra/nand/ - #mv -fv OLD_CITRA_STATES $rdhome/saves/n3ds/citra/sdmc/ + # Perform save and state migration if needed - mv -fv $rdhome/states/*.ml* $rdhome/states/nds/melonds + versionwheresaveschanged="0.4.5b" # Hardcoded break point between unsorted and sorted saves - mv -fv $rdhome/saves/xemu/* $rdhome/saves/xbox/xemu/ + if [[ $(sed -e "s/\.//g" <<< $hard_version) > $(sed -e "s/\.//g" <<< $versionwheresaveschanged) ]] && [[ ! $(sed -e "s/\.//g" <<< $hard_version) == $(sed -e "s/\.//g" <<< $version) ]]; then # Check if user is upgrading from the version where save organization was changed. Try not to reuse this, it things 0.4.5b is newer than 0.4.5 + migration_logfile=$rdhome/.logs/savemove_"$(date +"%Y_%m_%d_%I_%M_%p").log" + save_backup_file=$rdhome/savebackup_"$(date +"%Y_%m_%d_%I_%M_%p").zip" + state_backup_file=$rdhome/statesbackup_"$(date +"%Y_%m_%d_%I_%M_%p").zip" - mv -fv /var/config/PCSX2/memcards/* $rdhome/saves/ps2/memcards + # NOTE: This Zenity command may need to be one line, it broke when I pasted it into a sandbox file - #ppsspp? + zenity --icon-name=net.retrodeck.retrodeck --info --no-wrap \ + --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \ + --title "RetroDECK" \ + --text="You are updating to a version of RetroDECK where save and state file sorting has changed!\n\nYour existing saves will be backed up to $save_backup_file\n\nYour existing states will be backed up to $state_backup_file\n\nIf a save or state cannot be sorted automatically it will remain in its original directory so you can sort it manually.\n\nIf you encounter any issues, a log of the sorting process is stored at $migration_logfile\n\nPLEASE BE PATIENT! This process can take several minutes if you have a large ROM library." + + allgames=($(find "$roms_folder" -maxdepth 2 -mindepth 2 ! -name "systeminfo.txt" ! -name "systems.txt" ! -name "*^*" | sed -e "s/ /\^/g")) # Build an array of all games and multi-disc-game-containing folders, adding whitespace placeholder + + allsaves=($(find "$saves_folder" -mindepth 1 -maxdepth 1 -name "*.*" | sed -e "s/ /\^/g")) # Build an array of all save files, ignoring standalone emulator sub-folders, adding whitespace placeholder + + allstates=($(find "$states_folder" -mindepth 1 -maxdepth 1 -name "*.*" | sed -e "s/ /\^/g")) # Build an array of all state files, ignoring standalone emulator sub-folders, adding whitespace placeholder + + totalsaves=${#allsaves[@]} + totalstates=${#allstates[@]} + filesleft= + current_dest_folder= + gamestoskip= + + tar -C $rdhome -czf $save_backup_file saves # Backup save directory for safety + echo "Saves backed up to" $save_backup_file >> $migration_logfile + tar -C $rdhome -czf $state_backup_file states # Backup state directory for safety + echo "States backed up to" $state_backup_file >> $migration_logfile + + ( + movefile() { # Take matching save and rom files and sort save into appropriate system folder + echo "# $filesleft $currentlybeingmoved remaining..." # These lines update the Zenity progress bar + progress=$(( 100 - (( 100 / "$totalfiles" ) * "$filesleft" ))) + echo $progress + filesleft=$((filesleft-1)) + if [[ ! " ${gamestoskip[*]} " =~ " ${1} " ]]; then # If the current game name exists multiple times in array ie. /roms/snes/Mortal Kombat 3.zip and /roms/genesis/Mortal Kombat 3.zip, skip and alert user to sort manually + game=$(sed -e "s/\^/ /g" <<< "$1") # Remove whitespace placeholder + gamebasename=$(basename "$game" | sed -e 's/\..*//') # Extract pure file name ie. /roms/snes/game1.zip becomes game1 + systemdir="$(basename "$(dirname "$1")")" # Extract parent directory identifying system ROM belongs to + matches=($(find "$roms_folder" -maxdepth 2 -mindepth 2 -name "$gamebasename"".*" | sed -e 's/ /^/g' | sed -e 's/\..*//')) # Search for multiple instances of pure game name, adding to skip list if found + if [[ ${#matches[@]} -gt 1 ]]; then + echo "ERROR: Multiple ROMS found with name:" $gamebasename "Please sort saves and states for these ROMS manually" >> $migration_logfile + gamestoskip+=("$1") + return + fi + echo "INFO: Examining ROM file:" "$game" >> $migration_logfile + echo "INFO: System detected as" $systemdir >> $migration_logfile + sosfile=$(sed -e "s/\^/ /g" <<< "$2") # Remove whitespace placeholder from s-ave o-r s-tate file + sospurebasename="$(basename "$sosfile")" # Extract pure file name ie. /saves/game1.sav becomes game1 + echo "INFO: Current save or state being examined for match:" $sosfile >> $migration_logfile + echo "INFO: Matching save or state" $sosfile "and game" $game "found." >> $migration_logfile + echo "INFO: Moving save or state to" $current_dest_folder"/"$systemdir"/"$sosbasename >> $migration_logfile + if [[ ! -d $current_dest_folder"/"$systemdir ]]; then # If system directory doesn't exist for save yet, create it + echo "WARNING: Creating missing system directory" $current_dest_folder"/"$systemdir + mkdir $current_dest_folder/$systemdir + fi + mv "$sosfile" -t $current_dest_folder/$systemdir # Move save to appropriate system directory + return + else + echo "WARNING: Game with name" "$(basename "$1" | sed -e "s/\^/ /g")" "already found. Skipping to next game..." >> $migration_logfile # Inform user of game being skipped due to duplicate ROM names + fi + } + + find "$roms_folder" -mindepth 2 -maxdepth 2 -name "*\^*" -exec echo "ERROR: Game named" {} "found, please move save manually" \; >> $migration_logfile # Warn user if any of their files have the whitespace replacement character used by the script + + totalfiles=$totalsaves #set variables for save file migration + filesleft=$totalsaves + currentlybeingmoved="saves" + current_dest_folder=$saves_folder + + for i in "${allsaves[@]}"; do # For each save file, compare to every ROM file name looking for a match + found= + currentsave=($(basename "$i" | sed -e 's/\..*//')) # Extract pure file name ie. /saves/game1.sav becomes game1 + for j in "${allgames[@]}"; do + currentgame=($(basename "$j" | sed -e 's/\..*//')) # Extract pure file name ie. /roms/snes/game1.zip becomes game1 + [[ $currentgame == $currentsave ]] && { found=1; break; } # If names match move to next stage, otherwise skip + done + [[ -n $found ]] && movefile $j $i || echo "ERROR: No ROM match found for save file" $i | sed -e 's/\^/ /g' >> $migration_logfile # If a match is found, run movefile() otherwise warn user of stranded save file + done + + totalfiles=$totalstates #set variables for state file migration + filesleft=$totalstates + currentlybeingmoved="states" + current_dest_folder=$states_folder + + for i in "${allstates[@]}"; do # For each state file, compare to every ROM file name looking for a match + found= + currentstate=($(basename "$i" | sed -e 's/\..*//')) # Extract pure file name ie. /states/game1.sav becomes game1 + for j in "${allgames[@]}"; do + currentgame=($(basename "$j" | sed -e 's/\..*//')) # Extract pure file name ie. /roms/snes/game1.zip becomes game1 + [[ $currentgame == $currentstate ]] && { found=1; break; } # If names match move to next stage, otherwise skip + done + [[ -n $found ]] && movefile $j $i || echo "ERROR: No ROM match found for state file" $i | sed -e 's/\^/ /g' >> $migration_logfile # If a match is found, run movefile() otherwise warn user of stranded state file + done + + ) | + zenity --progress \ + --icon-name=net.retrodeck.retrodeck \ + --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \ + --title="Processing Files" \ + --text="# files remaining..." \ + --percentage=0 \ + --no-cancel \ + --auto-close + + # NOTE: This Zenity command may need to be one line, it broke when I pasted it into a sandbox file + + else + echo "Version" $version "is after the save and state organization was changed, no need to sort again" + fi ra_init standalones_init