mirror of
https://github.com/dragoonDorise/EmuDeck.git
synced 2024-05-20 13:17:55 -04:00
Compare commits
11 commits
48e07bfc1f
...
73f38af040
Author | SHA1 | Date | |
---|---|---|---|
73f38af040 | |||
b3af3ae4d4 | |||
b027aaafe3 | |||
cc58433b05 | |||
d9d3a826e4 | |||
e78606b819 | |||
3085288717 | |||
e79b1aff03 | |||
7c61546295 | |||
7810440101 | |||
007275f6c7 |
|
@ -1,61 +1,62 @@
|
|||
#!/bin/bash
|
||||
|
||||
generateGameLists(){
|
||||
generateGameLists() {
|
||||
ROMS_DIR="$romsPath/snes"
|
||||
|
||||
ROMS_DIR="$romsPath"
|
||||
# Initialize an empty array in JSON format
|
||||
printf "["
|
||||
|
||||
JSON_OUTPUT="$HOME/emudeck/roms_games.json"
|
||||
echo "[" > "$JSON_OUTPUT"
|
||||
first_system=true
|
||||
|
||||
for system_dir in "$ROMS_DIR"/*; do
|
||||
for system_dir in "$ROMS_DIR"*; do
|
||||
if [[ -d "$system_dir" && -f "$system_dir/metadata.txt" ]]; then
|
||||
|
||||
# Ignore directories named "ps3"
|
||||
if [[ "$system_dir" == *"/ps3" ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
file_count=$(find "$system_dir" -type f | wc -l)
|
||||
if [[ "$file_count" -le 2 ]]; then
|
||||
continue # Skip this system_dir if there are 2 or fewer files
|
||||
fi
|
||||
|
||||
collection=$(grep 'collection:' "$system_dir/metadata.txt" | cut -d ':' -f 2- | awk '{$1=$1};1')
|
||||
shortname=$(grep 'shortname:' "$system_dir/metadata.txt" | cut -d ':' -f 2- | awk '{$1=$1};1')
|
||||
extensions=$(grep 'extensions:' "$system_dir/metadata.txt" | cut -d ':' -f 2- | tr ',' '\n' | awk '{$1=$1};1' | tr '\n' '|')
|
||||
launcher=$(grep 'launch:' "$system_dir/metadata.txt" | cut -d ':' -f 2- | awk '{$1=$1};1')
|
||||
extensions="${extensions%|}" # Eliminar el último '|'
|
||||
extensions=$(grep 'extensions:' "$system_dir/metadata.txt" | cut -d ':' -f 2- | tr ',' ' ' | awk '{$1=$1};1')
|
||||
|
||||
if $first_system; then
|
||||
first_system=false
|
||||
else
|
||||
printf ","
|
||||
fi
|
||||
|
||||
tmp_file="$(mktemp)"
|
||||
# Start system object
|
||||
printf '{ "title": "%s", "id": "%s", "launcher": "%s", "games": [' "$collection" "$shortname" "$launcher"
|
||||
|
||||
|
||||
find "$system_dir" -type f | while read file_path; do
|
||||
# Use jq to create the JSON objects for each game and print them directly
|
||||
first_game=true
|
||||
find "$system_dir" -type f | while read -r file_path; do
|
||||
filename=$(basename "$file_path")
|
||||
extension="${filename##*.}"
|
||||
|
||||
if [[ $extensions =~ (^|[|])${extension,,}([|]|$) ]]; then
|
||||
|
||||
name="${filename%.*}"
|
||||
echo "{\"name\": \"$name\", \"filename\": \"$file_path\"}," >> "$tmp_file"
|
||||
name="${filename%.*}"
|
||||
if [[ "$extensions" =~ "$extension" ]]; then
|
||||
if $first_game; then
|
||||
first_game=false
|
||||
else
|
||||
printf ","
|
||||
fi
|
||||
jq -n --arg name "$name" --arg filename "$file_path" '{"name": $name, "filename": $filename}'
|
||||
fi
|
||||
done
|
||||
|
||||
# End games array and system object
|
||||
printf "] }"
|
||||
|
||||
sort "$tmp_file" | sed '$ s/,$//' > "${tmp_file}_sorted"
|
||||
mv "${tmp_file}_sorted" "$tmp_file"
|
||||
|
||||
|
||||
if [[ -s "$tmp_file" ]]; then
|
||||
echo " {" >> "$JSON_OUTPUT"
|
||||
echo " \"title\": \"$collection\"," >> "$JSON_OUTPUT"
|
||||
echo " \"id\": \"$shortname\"," >> "$JSON_OUTPUT"
|
||||
echo " \"launcher\": \"$launcher\"," >> "$JSON_OUTPUT"
|
||||
echo " \"games\": [" >> "$JSON_OUTPUT"
|
||||
cat "$tmp_file" >> "$JSON_OUTPUT"
|
||||
echo " ]" >> "$JSON_OUTPUT"
|
||||
echo " }," >> "$JSON_OUTPUT"
|
||||
fi
|
||||
|
||||
|
||||
rm "$tmp_file"
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
echo "]" >> "$JSON_OUTPUT"
|
||||
sed -i '$ s/,$//' "$JSON_OUTPUT"
|
||||
|
||||
cat $JSON_OUTPUT
|
||||
|
||||
# End of JSON array
|
||||
printf "]"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue