STEAM_SYNC: cleaning up the folder to ensure that removed launchers are removed + usinr run_game function to start the games

This commit is contained in:
XargonWan 2025-01-29 15:23:02 +09:00
parent ea4b88a9b8
commit ea048f3625

View file

@ -21,6 +21,10 @@ add_to_steam() {
# Iterate through all gamelist.xml files in the folder structure # Iterate through all gamelist.xml files in the folder structure
for system_path in "$rdhome/ES-DE/gamelists/"*/; do for system_path in "$rdhome/ES-DE/gamelists/"*/; do
# Skip the CLEANUP folder
if [[ "$system_path" == *"/CLEANUP/"* ]]; then
continue
fi
system=$(basename "$system_path") # Extract the folder name as the system name system=$(basename "$system_path") # Extract the folder name as the system name
gamelist="${system_path}gamelist.xml" gamelist="${system_path}gamelist.xml"
@ -59,21 +63,15 @@ add_to_steam() {
local launcher_tmp="$steamsync_folder_tmp/${name}.sh" local launcher_tmp="$steamsync_folder_tmp/${name}.sh"
# Create the launcher file # Create the launcher file
# Check if the launcher file does not already exist
if [ ! -e "$launcher_tmp" ]; then if [ ! -e "$launcher_tmp" ]; then
log d "Creating launcher file: $launcher" log d "Creating launcher file: $launcher"
command="flatpak run net.retrodeck.retrodeck '$roms_folder/$system/$path'" command="flatpak run net.retrodeck.retrodeck -s $system '$roms_folder/$system/$path'"
cat <<EOF > "$launcher" echo '#!/bin/bash' > "$launcher_tmp"
#!/bin/bash echo "$command" >> "$launcher_tmp"
if [ test "\$(whereis flatpak)" = "flatpak:" ]; then chmod +x "$launcher_tmp"
flatpak-spawn --host $command
else else
$command log d "$(basename $launcher) desktop file already exists"
fi
EOF
chmod +x "$launcher"
else
log d "$launcher desktop file already exists"
mv "$launcher_tmp" "$launcher"
fi fi
fi fi
@ -84,13 +82,20 @@ EOF
fi fi
done < "$gamelist" done < "$gamelist"
else else
log "e" "Gamelist file not found: $gamelist" log "e" "Gamelist file not found for system: $system"
fi fi
done done
rm -r $steamsync_folder_tmp # Remove the old Steam sync folder
rm -rf "$steamsync_folder"
# Move the temporary Steam sync folder to the final location
log d "Moving the temporary Steam sync folder to the final location"
mv "$steamsync_folder_tmp" "$steamsync_folder" && log d "\"$steamsync_folder_tmp\" -> \"$steamsync_folder\""
# Check if the Steam sync folder is empty
if [ -z "$(ls -A $steamsync_folder)" ]; then if [ -z "$(ls -A $steamsync_folder)" ]; then
# if empty, add the remove_from_steam function
log d "No games found, cleaning shortcut" log d "No games found, cleaning shortcut"
remove_from_steam remove_from_steam
else else
@ -99,11 +104,13 @@ EOF
fi fi
} }
# Function to remove the games from Steam, this is a workaround to make SRM remove the games as it cannot remove the games based on a empty folder
# So a dummy file must be in place to make SRM remove the other games
remove_from_steam() { remove_from_steam() {
log d "Creating fake game" log d "Creating dummy game"
cat "" > "$steamsync_folder/CUL0.sh" cat "" > "$steamsync_folder/CUL0.sh"
log d "Cleaning the shortcut" log d "Cleaning the shortcut"
steam-rom-manager remove steam-rom-manager remove
log d "Removing fake game" log d "Removing dummy game"
rm "$steamsync_folder/CUL0.sh" rm "$steamsync_folder/CUL0.sh"
} }