Updated the game removal function.

This commit is contained in:
Storm Dragon 2024-12-23 20:41:51 -05:00
parent 81eb291bea
commit 30f36491f7

View File

@ -407,47 +407,55 @@ game_installer() {
# remove games # remove games
game_removal() { game_removal() {
mapfile -t lines < <(sed '/^$/d' "${configFile}" 2> /dev/null) # Initialize array for menu construction
if [[ ${#lines} -eq 0 ]]; then mapfile -t menuList < <(
echo "No games found." 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 exit 0
fi fi
# Create the menu of installed games # Create the menu of installed games
declare -a menuList local selectedGame="$(dialog --backtitle "Linux Game Manager" \
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" \
--clear \ --clear \
--no-tags \ --no-tags \
--menu "Please select a game to delete" 0 0 0 "${menuList[@]}" --stdout)" --menu "Please select a game to delete" 0 0 0 "${menuList[@]}" --stdout)"
if [[ ${#game} -gt 0 ]]; then [[ $? -ne 0 ]] && exit 0
if [[ "$game" == "Donate" ]]; then # Get the actual game file paths
open_url "https://ko-fi.com/stormux" local gameName="${selectedGame##*/}"
exit 0 gameName="${gameName%.sh}"
fi local gameFile="$(readlink -f "${0%/*}/.launch/${gameName}.sh")"
if [[ "$game" == "Become a Patron" ]]; then # Get the actual installation path from the .game file
open_url "https://2mb.games/product/2mb-patron/" local gameInstallPath
exit 0 gameInstallPath="$(grep -F "installPath" "$gameFile" | grep -v 'pushd' | head -n1)"
fi gameInstallPath="${gameInstallPath#*${installPath}/}"
fi gameInstallPath="${gameInstallPath%/*}"
local launcherPath="$(readlink -f "$0")" if [[ -z "$gameInstallPath" ]]; then
launcherPath="${launcherPath%/*}" # No install path found, just remove from list
local noRemove="no"
if [[ "${game%/*}" =~ ^$launcherPath ]] ; then
# The launcher is actually a script under lgm, do not remove.
noRemove="yes"
dialog --backtitle "Linux Game Manager" \ 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 else
# Found install path, can remove game files
dialog --backtitle "Linux Game Manager" \ 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 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 exit 0
} }
@ -500,6 +508,11 @@ game_launcher() {
done' _ done' _
fi 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 # Create the menu of all games
selectedGame="$(dialog --backtitle "Linux Game Launcher" \ selectedGame="$(dialog --backtitle "Linux Game Launcher" \
--clear \ --clear \