From b2347f3cff091f3f1c20b631494e803321eb9b13 Mon Sep 17 00:00:00 2001 From: Michael Taboada Date: Thu, 30 Nov 2023 18:44:21 -0800 Subject: [PATCH] Don't allow lgm to try and remove files under lgm's own directory, for games that simply have a launcher script. --- linux-game-manager.sh | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/linux-game-manager.sh b/linux-game-manager.sh index 7fc1220..24a3530 100755 --- a/linux-game-manager.sh +++ b/linux-game-manager.sh @@ -334,9 +334,20 @@ game_removal() { exit 0 fi fi - dialog --backtitle "Linux Game Manager" \ - --yesno "mThis will remove the directory \"${game%/*}\" and all of its contents. Do you want to continue?." -1 -1 --stdout || exit 0 - { rm -rfv "${game%/*}"; + 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" + 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 + else + dialog --backtitle "Linux Game Manager" \ + --yesno "mThis will remove the directory \"${game%/*}\" and all of its contents. Do you want to continue?." -1 -1 --stdout || exit 0 + 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 }