From 81eb291bea93693a3bb7fd89e74801aecf6f5d3c Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Mon, 23 Dec 2024 17:50:48 -0500 Subject: [PATCH] All games updated to the new launch system. Game launcher function updated to totally use the new system. Temporary migration function added to make sure everyone gets updated to the new system without having to do it manually. --- linux-game-manager.sh | 79 ++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 42 deletions(-) diff --git a/linux-game-manager.sh b/linux-game-manager.sh index 4bdde96..81604b9 100755 --- a/linux-game-manager.sh +++ b/linux-game-manager.sh @@ -489,35 +489,17 @@ game_update() { # launch games that are installed game_launcher() { # Initialize array for menu construction - declare -a menuList - # Read both config file and .launch files into lines array - mapfile -t lines < <( - sed '/^$/d' "${configFile}" 2> /dev/null + mapfile -t menuList < <( if [[ -d ".launch" ]]; then - find -L "${0%/*}/.launch" -maxdepth 1 -type f -iname "*.sh" -exec bash -c ' + find -L "${0%/*}/.launch" -maxdepth 1 -type f -iname "*.sh" -print0 | sort -z | xargs -0 bash -c ' for f; do [[ $(head -n1 "$f") =~ ^#$ ]] && continue name="${f##*/}" - echo "${name%.sh}|$f" - done - ' _ {} \; + echo "$f" + echo "${name%.sh}" + done' _ fi ) - # Add all entries to menu - for i in "${lines[@]}"; do - menuList+=("${i#*|}" "${i%|*}") - done - # Sort the menu - mapfile -t sortedList < <( - for ((i=0; i<${#menuList[@]}; i+=2)); do - echo "${menuList[i+1]}|${menuList[i]}" - done | sort -f - ) - # Rebuild menuList from sorted entries - menuList=() - for i in "${sortedList[@]}"; do - menuList+=("${i#*|}" "${i%|*}") - done # Create the menu of all games selectedGame="$(dialog --backtitle "Linux Game Launcher" \ --clear \ @@ -527,29 +509,41 @@ game_launcher() { if [[ $menuCode -eq 1 ]]; then exit 0 fi - # Remove any trailing | from selectedGame variable - selectedGame="${selectedGame%|}" - case "${selectedGame}" in - *.sh) - . "${selectedGame}" - ;; - *) - pushd "${selectedGame%/*}" - if file "${selectedGame##*/}" | grep -q "ELF.*x86-64"; then - if [[ "$(uname -m)" != "x86_64" ]]; then - exec FEXLoader -- ${selectedGame} - else - exec ${selectedGame} - fi - else - exec ${selectedGame} - fi - ;; - esac + pushd "${selectedGame%/*}" + if file "${selectedGame##*/}" | grep -q "ELF.*x86-64"; then + if [[ "$(uname -m)" != "x86_64" ]]; then + exec FEXLoader -- "${selectedGame#./}" + else + . "./${selectedGame##*/}" + fi + else + . "./${selectedGame##*/}" + fi exit 0 } +migrate_launcher() { + # Check if config file exists + [[ -f "${configFile}" ]] || return + # Process each line of the config file + while IFS= read -r line; do + # Skip empty lines + [[ -z "${line}" ]] && continue + # Extract game name and path + gameName="${line%|*}" + # Create launcher script if it doesn't exist + if [[ ! -L "${0%/*}/.launch/${gameName}.sh" ]]; then + ln -srf "${0%/*}/.launch/${gameName}.game" "${0%/*}/.launch/${gameName}.sh" + fi + done < <(sed '/^$/d' "${configFile}") + # Move the old config file and notify user + mv "${configFile}" "${configFile}.bak" + dialog --backtitle "Linux Game manager" --msgbox \ + "Games have been converted to the new launch system.\nThe old game launch information has been moved to ${configFile}.bak\nIf everything works like you expect, feel free to delete ${configFile}" -1 -1 +} + + # If display isn't set assume we are launching from console and an X environment is running using display :0 # Warning, launching games from console is not recommended. if [[ -z "$DISPLAY" ]]; then @@ -574,6 +568,7 @@ export spd_rate="${spd_rate:+ -r ${spd_rate}}" export spd_voice="${spd_voice:+ -y ${spd_voice}}" export spd_volume="${spd_volume:+ -i ${spd_volume}}" mkdir -p "${installPath}" +migrate_launcher # Check for required packages