if[[ ! -L "$rdhome"&& ! -L "$rdhome/roms"]];then# Add a roms folder symlink back to ~/retrodeck if missing, to fix things like PS2 autosaves until user migrates whole ~retrodeck directory
if[[$(sed -e "s/\.//g"<<<"$hard_version") > $(sed -e "s/\.//g"<<<"$versionwheresaveschanged")]]&&[[ ! $(sed -e "s/\.//g"<<<"$version") > $(sed -e "s/\.//g"<<<"$versionwheresaveschanged")]];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
--text="You are updating to a version of RetroDECK where save file locations have changed!\n\nYour existing files will be backed up for safety and then sorted automatically.\n\nIf a file cannot be sorted automatically it will remain where it is for manual sorting.\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 "gc" ! -name "n3ds" ! -name "nds" ! -name "wii" ! -name "xbox" ! -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 "*.*" ! -name "gc" ! -name "n3ds" ! -name "nds" ! -name "wii" ! -name "xbox"| 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 "*.*" ! -name "gc" ! -name "n3ds" ! -name "nds" ! -name "wii" ! -name "xbox"| sed -e "s/ /\^/g"))# Build an array of all state files, ignoring standalone emulator sub-folders, adding whitespace placeholder
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
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
log w "Game with name \"$name\" already found. Skipping to next game...""$migration_logfile"# Inform user of game being skipped due to duplicate ROM names
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
[[ -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
[[ -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
--text="The migration process has sorted all of your files automatically.\n\nEverything should be working normally, if you experience any issues please check the RetroDECK wiki or contact us directly on the Discord."
--text="The migration process was unable to sort $(cat "$migration_logfile"| grep "ERROR"| wc -l) files automatically.\n\nThese files will need to be moved manually to their new locations, find more detail on the RetroDECK wiki.\n\nA log of the files that need manual sorting can be found at $rdhome/manual_sort_needed.log"