diff --git a/linux-game-manager.sh b/linux-game-manager.sh index 81604b9..03eaa0f 100755 --- a/linux-game-manager.sh +++ b/linux-game-manager.sh @@ -407,47 +407,55 @@ game_installer() { # remove games game_removal() { - mapfile -t lines < <(sed '/^$/d' "${configFile}" 2> /dev/null) - if [[ ${#lines} -eq 0 ]]; then - echo "No games found." + # Initialize array for menu construction + mapfile -t menuList < <( + if [[ -d ".launch" ]]; then + find -L "${0%/*}/.launch" -maxdepth 1 -type f -iname "*.sh" -print0 | sort -z | xargs -0 bash -c ' + for f; do + name="${f##*/}" + echo "$f" + echo "${name%.sh}" + done' _ + fi + ) + if [[ ${#menuList} -eq 0 ]]; then + dialog --backtitle "Linux Game Manager" \ + --msgbox "No games found." -1 -1 exit 0 fi # Create the menu of installed games - declare -a menuList - for i in "${lines[@]}" ; do - menuList+=("${i#*|}" "${i%|*}") - done - menuList+=("Donate" "Donate") - menuList+=("Become a Patron" "Become a Patron") - local game="$(dialog --backtitle "Audio Game Removal" \ + local selectedGame="$(dialog --backtitle "Linux Game Manager" \ --clear \ --no-tags \ --menu "Please select a game to delete" 0 0 0 "${menuList[@]}" --stdout)" - if [[ ${#game} -gt 0 ]]; then - if [[ "$game" == "Donate" ]]; then - open_url "https://ko-fi.com/stormux" - exit 0 - fi - if [[ "$game" == "Become a Patron" ]]; then - open_url "https://2mb.games/product/2mb-patron/" - exit 0 - fi - fi - local launcherPath="$(readlink -f "$0")" - launcherPath="${launcherPath%/*}" - local noRemove="no" - if [[ "${game%/*}" =~ ^$launcherPath ]] ; then - # The launcher is actually a script under lgm, do not remove. - noRemove="yes" + [[ $? -ne 0 ]] && exit 0 + # Get the actual game file paths + local gameName="${selectedGame##*/}" + gameName="${gameName%.sh}" + local gameFile="$(readlink -f "${0%/*}/.launch/${gameName}.sh")" + # Get the actual installation path from the .game file + local gameInstallPath + gameInstallPath="$(grep -F "installPath" "$gameFile" | grep -v 'pushd' | head -n1)" + gameInstallPath="${gameInstallPath#*${installPath}/}" + gameInstallPath="${gameInstallPath%/*}" + if [[ -z "$gameInstallPath" ]]; then + # No install path found, just remove from list dialog --backtitle "Linux Game Manager" \ - --yesno "This will remove the game from your game list, but will not remove any files. Do you want to continue?." -1 -1 --stdout || exit 0 + --yesno "This will remove the game from your game list, but will not remove any files. Do you want to continue?" -1 -1 || exit 0 + # Remove only the .sh symlink + rm -f "${0%/*}/.launch/${gameName}.sh" | \ + dialog --backtitle "Linux Game Manager" \ + --progressbox "Removing game from list..." -1 -1 else + # Found install path, can remove game files dialog --backtitle "Linux Game Manager" \ - --yesno "This will remove the directory \"${game%/*}\" and all of its contents. Do you want to continue?." -1 -1 --stdout || exit 0 + --yesno "This will remove the directory \"${installPath}/${gameInstallPath}\" and all of its contents. Do you want to continue?" -1 -1 || exit 0 + # Remove the game directory and symlink + { rm -rfv "${installPath}/${gameInstallPath}" + rm -fv "${0%/*}/.launch/${gameName}.sh"; + } | dialog --backtitle "Linux Game Manager" \ + --progressbox "Removing game..." -1 -1 fi - export noRemove - { [[ "$noRemove" == "no" ]] && rm -rfv "${game%/*}"; - sed -i "/${game//\//\\/}/d" "$configFile"; } | dialog --backtitle "Linux Game Manager" --progressbox "Removing game..." -1 -1 exit 0 } @@ -500,6 +508,11 @@ game_launcher() { done' _ fi ) + if [[ ${#menuList} -eq 0 ]]; then + dialog --backtitle "Linux Game Manager" \ + --msgbox "No games found." 5 20 + exit 0 + fi # Create the menu of all games selectedGame="$(dialog --backtitle "Linux Game Launcher" \ --clear \