Skip to content

Commit

Permalink
EmuCleaner improvements
Browse files Browse the repository at this point in the history
Use extlist to detect games.
Credits Schmurtzm : schmurtzm/TrimUI-Smart-Pro@54bcfa4
  • Loading branch information
cizia64 committed Jun 5, 2024
1 parent 05c9909 commit 17df9fb
Showing 1 changed file with 77 additions and 56 deletions.
133 changes: 77 additions & 56 deletions Apps/EmuCleaner/launch.sh
Original file line number Diff line number Diff line change
@@ -1,89 +1,110 @@
#!/bin/bash
PATH="/mnt/SDCARD/System/bin:$PATH"

silent=false
for arg in "$@"; do
if [ "$arg" = "-s" ]; then
silent=true
break
fi
if [ "$arg" = "-s" ]; then
silent=true
break
fi
done

RomsFolder="/mnt/SDCARD/Roms"
EmuFolder="/mnt/SDCARD/Emus"

json_file="/mnt/SDCARD/Emus/show.json"

NumRemoved=0
NumAdded=0

if [ "$silent" = false ]; then
/mnt/SDCARD/System/bin/sdl2imgshow \
-i "./background.jpg" \
-f "/mnt/SDCARD/System/resources/DejaVuSans.ttf" \
-s 100 \
-c "220,0,0" \
-t " " &
/mnt/SDCARD/System/bin/sdl2imgshow \
-i "./background.jpg" \
-f "/mnt/SDCARD/System/resources/DejaVuSans.ttf" \
-s 100 \
-c "220,0,0" \
-t " " &
fi

write_entry() {
label="$1"
show="$2"
echo "{"
echo -e "\t\"label\": \"$label\","
echo -e "\t\"show\": $show"
echo "},"
label="$1"
show="$2"
echo "{"
echo -e "\t\"label\": \"$label\","
echo -e "\t\"show\": $show"
echo "},"
}
echo "[" > $json_file

echo "[" >$json_file


# we check if some emulators must be hidden from /mnt/SDCARD/Emus
# We check if some emulators must be hidden from /mnt/SDCARD/Emus
for subfolder in $EmuFolder/*/; do
# Check if the config.json file exists
if [ -f "$subfolder/config.json" ]; then
# Extract the rompath, label, and extlist from the config.json using jq
RomPath=$(jq -r '.rompath' "$subfolder/config.json")
RomFolderName=$(basename "$RomPath")

Label=$(jq -r '.label' "$subfolder/config.json")
ExtList=$(jq -r '.extlist' "$subfolder/config.json")

echo "--$Label--"

# Build the find command with extensions from extlist
if [ -z "$ExtList" ] || [ "$ExtList" = "null" ]; then
find_cmd="find \"$RomsFolder/$RomFolderName\" '!' -name '*.db' '!' -name '.gitkeep' -mindepth 1 -maxdepth 1"
else
set -- $(echo $ExtList | tr '|' ' ')
find_cmd="find \"$RomsFolder/$RomFolderName\""
first=1
for ext in "$@"; do
if [ $first -eq 1 ]; then
find_cmd="$find_cmd -iname '*.$ext'"
first=0
else
find_cmd="$find_cmd -o -iname '*.$ext'"
fi
done
find_cmd="$find_cmd -mindepth 1 -maxdepth 1"
fi

if [ -f "$subfolder/config.json" ]; then
# RomPath=$(grep '"rompath":*' $subfolder/config.json |sed 's|.*"rompath":"\([^"]*\)".*|\1|')
RomPath=$(/mnt/SDCARD/System/bin/jq -r '.rompath' "$subfolder/config.json")
RomFolderName=$(basename "$RomPath")

# Label=$(grep '"label":*' $subfolder/config.json | sed 's|.*"label":"\([^"]*\)".*|\1|')
Label=$(/mnt/SDCARD/System/bin/jq -r '.label' "$subfolder/config.json")
echo "--$Label--"

if ! find "$RomsFolder/$RomFolderName" '!' -name '*.db' '!' -name '.gitkeep' -mindepth 1 -maxdepth 1 | read; then
echo "Removing $Label emulator (no roms in $RomFolderName folder)."
write_entry "$Label" 0 >> $json_file
let NumRemoved++;
else
echo "Adding $Label emulator (no roms in $RomFolderName folder)."
write_entry "$Label" 1 >> $json_file
let NumAdded++;

fi
fi

# Check if the ROM folder contains any files with the specified extensions
if ! eval "$find_cmd | read"; then
echo "Removing $Label emulator (no roms in $RomFolderName folder)."
write_entry "$Label" 0 >>$json_file
NumRemoved=$((NumRemoved + 1))
else
echo "Adding $Label emulator (roms found in $RomFolderName folder)."
write_entry "$Label" 1 >>$json_file
NumAdded=$((NumAdded + 1))
fi
fi
done


sed -i '$ s/,$//' $json_file
echo "]" >> $json_file
echo "]" >>$json_file
sync

# Refresh Emus list
jq '(.list[].tabstate[] | select(has("pagestart"))).pagestart = 0 | (.list[].tabstate[] | select(has("pageend"))).pageend = 7' /tmp/state.json >/tmp/state.tmp && mv /tmp/state.tmp /tmp/state.json

sync

echo -ne "\n=============================\n"
echo -ne "${NumRemoved} hidden emulator(s)\n${NumAdded} displayed emulator(s)\n"
echo -ne "=============================\n\n"

if [ "$silent" = false ]; then
sleep 0.5
pkill -f sdl2imgshow
sleep 1

/mnt/SDCARD/System/bin/sdl2imgshow \
-i "./background-info.jpg" \
-f "/mnt/SDCARD/System/resources/DejaVuSans.ttf" \
-s 40 \
-c "255,255,255" \
-t "${NumAdded} displayed emulator(s). ${NumRemoved} hidden emulator(s)." &
pkill -f sdl2imgshow
sleep 0.3

sleep 4
/mnt/SDCARD/System/bin/sdl2imgshow \
-i "./background-info.jpg" \
-f "/mnt/SDCARD/System/resources/DejaVuSans.ttf" \
-s 40 \
-c "255,255,255" \
-t "${NumAdded} displayed emulator(s). ${NumRemoved} hidden emulator(s)." &

pkill -f sdl2imgshow

fi
sleep 3.5
pkill -f sdl2imgshow
fi

0 comments on commit 17df9fb

Please sign in to comment.