From d62218c6e4f4659255fac95e770c471148063b7c Mon Sep 17 00:00:00 2001 From: XargonWan Date: Thu, 5 Dec 2024 10:32:36 +0900 Subject: [PATCH] MIME: added a tool to automatically generate the mime files based on es_systems and updated the actual mime file. --- .../net.retrodeck.retrodeck.mime.xml | 478 ++++++++++++------ developer_toolbox/mime-populator.sh | 56 ++ 2 files changed, 392 insertions(+), 142 deletions(-) create mode 100755 developer_toolbox/mime-populator.sh diff --git a/config/retrodeck/net.retrodeck.retrodeck.mime.xml b/config/retrodeck/net.retrodeck.retrodeck.mime.xml index 9c6b7a9e..2b4266bf 100644 --- a/config/retrodeck/net.retrodeck.retrodeck.mime.xml +++ b/config/retrodeck/net.retrodeck.retrodeck.mime.xml @@ -1,145 +1,339 @@ - - Retro Game - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - c - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + Retro Game + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/developer_toolbox/mime-populator.sh b/developer_toolbox/mime-populator.sh new file mode 100755 index 00000000..04a14ed8 --- /dev/null +++ b/developer_toolbox/mime-populator.sh @@ -0,0 +1,56 @@ +#!/bin/bash +# Input files +ES_SYSTEMS_FILE="../ES-DE/resources/systems/linux/es_systems.xml" +MIME_FILE="config/retrodeck/net.retrodeck.retrodeck.mime.xml" + +# List of extensions to ignore +IGNORED_EXTENSIONS=". .appimage cue" + +# Check if xmlstarlet is installed +if ! command -v xmlstarlet &> /dev/null; then + echo "Error: xmlstarlet is not installed." + echo "Please install it using your package manager (e.g., sudo apt install xmlstarlet)." + exit 1 +fi + +# Temporary files +EXTENSIONS_FILE=$(mktemp) + +# Extract extensions from the field in es_systems.xml +grep -oP '\K.*?(?=)' "$ES_SYSTEMS_FILE" | \ +tr ' ' '\n' | \ +awk '{print tolower($0)}' | \ +sort -u > "$EXTENSIONS_FILE" + +# Create a new MIME file with the correct base structure +cat > "$MIME_FILE" << EOF + + + + Retro Game +EOF + +# Add new elements to the MIME file +while IFS= read -r ext; do + # Skip ignored extensions + if [[ "$IGNORED_EXTENSIONS" =~ (^|[[:space:]])"$ext"($|[[:space:]]) ]]; then + echo "Skipping ignored extension: $ext" + continue + fi + + # Add the element for the extension + echo "Adding glob pattern for extension: $ext" + echo " " >> "$MIME_FILE" +done < "$EXTENSIONS_FILE" + +# Close the XML tags +echo " +" >> "$MIME_FILE" + +# Ensure proper formatting using xmlstarlet +xmlstarlet fo --indent-tab "$MIME_FILE" > "$MIME_FILE.tmp" && mv "$MIME_FILE.tmp" "$MIME_FILE" + +# Clean up temporary files +rm -f "$EXTENSIONS_FILE" + +echo "MIME file updated successfully at $MIME_FILE" \ No newline at end of file