# THIS IS A CENTRALIZED LOCATION FOR FUNCTIONS, WHICH CAN BE SOURCED WITHOUT RUNNING EXTRA CODE. EXISTING USE OF THESE FUNCTIONS CAN BE REFACTORED TO HERE.
--text="The destination directory you have selected does not have enough free space for the files you are trying to move.\n\nPlease select a new destination or free up some space."
--title "RetroDECK Configurator Utility - Process Complete"\
--text="The process of $1 is now complete.\n\nYou may need to quit and restart RetroDECK for your changes to take effect\n\nClick OK to return to the Main Menu or Quit to return to RetroDECK."
if[ ! $?==0]# OK button clicked
then
configurator_welcome_dialog
fi
}
configurator_generic_dialog(){
# This dialog is for showing temporary messages before another process happens.
# This dialog is for making things easy for new users to move files to common locations. Gives the options for "Internal", "SD Card" and "Custom" locations.
versionwheresaveschanged="0.4.5b"# Hardcoded break point between unsorted and sorted saves
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
--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."
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
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
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
--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"
--text="Welcome to the first configuration of RetroDECK.\nThe setup will be quick but please READ CAREFULLY each message in order to avoid misconfigurations.\n\nWhere do you want your roms folder to be located?")
--text="SD Card was not find in the default location.\nPlease choose the SD Card root.\nA retrodeck/roms folder will be created starting from the directory that you selected."
browse # Calling the browse function
else
roms_folder="$sdcard/retrodeck/roms"# sdcard variable is correct as its given by browse function
echo"ROMs folder = $roms_folder"
fi
;;
#"Advanced" ) # Browse + not found fallback
# echo "Advanced"
# advanced
#;;
esac
mkdir -pv $roms_folder
# TODO: after the next update of ES-DE this will not be needed
#zenity --icon-name=net.retrodeck.retrodeck --info --no-wrap --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" --title "RetroDECK" --text="EmulationStation will now initialize the system.\nPlease DON'T EDIT THE ROMS LOCATION, just select:\n\nCREATE DIRECTORIES\nYES\nOK\nQUIT\n\nRetroDECK will manage the rest."
zenity --icon-name=net.retrodeck.retrodeck --info --no-wrap --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" --title "RetroDECK" --text="RetroDECK will now install the needed files.\nPlease wait up to one minute,\nanother message will notify when the process will be finished.\n\nPress OK to continue."
#zenity --icon-name=net.retrodeck.retrodeck --info --no-wrap --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" --title "RetroDECK" --text="RetroDECK will now install the needed files.\nPlease wait up to one minute,\nanother message will notify when the process will be finished.\n\nPress OK to continue."
# Initializing ROMs folder - Original in retrodeck home (or SD Card)
--text="Installation completed.\nPlease put your roms in:\n\n$roms_folder\n\nand your bioses in\n\n$rdhome/bios\n\nThen start the program again.\nIf you wish to change the roms location, you may use the tool located the tools section of RetroDECK.\n\nIMPORTANT NOTES:\n- RetroDECK must be manually added and launched from your Steam Library in order to work correctly.\n- It's recommended to use the 'RetroDECK Offical Controller Config' from Steam (under community layouts).\n- It's suggested to use BoilR to automatically add the SteamGridDB images to Steam (this will be automated soon).\nhttps://github.com/PhilipK/BoilR"
# TODO: Replace the stuff above with BoilR code when ready
}
conf_write(){
# writes the variables in the retrodeck config file
echo"DEBUG: printing the config file content before writing it:"
cat "$rd_conf"
echo""
echo"Writing the config file: $rd_conf"
# TODO: this can be optimized with a while and a list of variables to check
if[ ! -z "$version"]#if the variable is not null then I update it
then
sed -i "s%version=.*%version=$version%""$rd_conf"
fi
if[ ! -z "$rdhome"]
then
sed -i "s%rdhome=.*%rdhome=$rdhome%""$rd_conf"
fi
if[ ! -z "$roms_folder"]
then
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"