From 211cfdc280b99f00765071945dbc09e1d7a91b0f Mon Sep 17 00:00:00 2001 From: Louie S Date: Mon, 1 Jan 2024 12:16:45 -0500 Subject: Add support for various flags --- .gitignore | 1 + config/romlist.template | 1 + icon/n64/Banjo-Kazooie.png | Bin 386859 -> 0 bytes icon/n64/Beetle Adventure Racing!.png | Bin 117045 -> 0 bytes icon/n64/Diddy Kong Racing.png | Bin 351709 -> 0 bytes icon/n64/Donkey Kong 64.png | Bin 415484 -> 0 bytes icon/n64/F-Zero X.png | Bin 638220 -> 0 bytes icon/n64/GoldenEye 007.png | Bin 4201 -> 0 bytes icon/n64/Mario Kart 64.png | Bin 148520 -> 0 bytes icon/n64/Mario Party 2.png | Bin 446311 -> 0 bytes icon/n64/Mario Party 3.png | Bin 155254 -> 0 bytes icon/n64/Paper Mario.png | Bin 456286 -> 0 bytes icon/n64/Perfect Dark.png | Bin 124359 -> 0 bytes icon/n64/Pilotwings 64.png | Bin 470551 -> 0 bytes icon/n64/Star Fox 64.png | Bin 286702 -> 0 bytes icon/n64/Super Mario 64.png | Bin 179830 -> 0 bytes icon/n64/Super Smash Bros..png | Bin 291844 -> 0 bytes ...e Legend of Zelda: Ocarina of Time (Europe).png | Bin 79416 -> 0 bytes icon/n64/Wave Race 64.png | Bin 328616 -> 0 bytes icon/nes/Mario Bros..png | Bin 222075 -> 0 bytes icon/nes/Super Mario Bros..png | Bin 2724 -> 0 bytes icon/snes/BioMetal.png | Bin 20250 -> 0 bytes .../Donkey Kong Country 2: Diddy's Kong Quest.png | Bin 440948 -> 0 bytes ...ong Country 3: Dixie Kong's Double Trouble!.png | Bin 470222 -> 0 bytes icon/snes/Donkey Kong Country.png | Bin 490470 -> 0 bytes icon/snes/Earthbound.png | Bin 3364 -> 0 bytes icon/snes/F-Zero.png | Bin 71134 -> 0 bytes icon/snes/Kirby Super Star.png | Bin 369409 -> 0 bytes icon/snes/Pilotwings.png | Bin 5658 -> 0 bytes icon/snes/Secret of Mana.png | Bin 370984 -> 0 bytes icon/snes/Super Famicom Wars.png | Bin 21069 -> 0 bytes icon/snes/Super Mario All-Stars.png | Bin 105211 -> 0 bytes icon/snes/Super Mario Kart.png | Bin 73418 -> 0 bytes icon/snes/Super Mario World.png | Bin 10111 -> 0 bytes icon/snes/Super R-Type.png | Bin 5381 -> 0 bytes .../The Legend of Zelda: A Link to the Past.png | Bin 9916 -> 0 bytes rom-desktop-entry-generator.sh | 223 ++++++++++++++++----- 37 files changed, 180 insertions(+), 45 deletions(-) delete mode 100644 icon/n64/Banjo-Kazooie.png delete mode 100644 icon/n64/Beetle Adventure Racing!.png delete mode 100644 icon/n64/Diddy Kong Racing.png delete mode 100644 icon/n64/Donkey Kong 64.png delete mode 100644 icon/n64/F-Zero X.png delete mode 100644 icon/n64/GoldenEye 007.png delete mode 100644 icon/n64/Mario Kart 64.png delete mode 100644 icon/n64/Mario Party 2.png delete mode 100644 icon/n64/Mario Party 3.png delete mode 100644 icon/n64/Paper Mario.png delete mode 100644 icon/n64/Perfect Dark.png delete mode 100644 icon/n64/Pilotwings 64.png delete mode 100644 icon/n64/Star Fox 64.png delete mode 100644 icon/n64/Super Mario 64.png delete mode 100644 icon/n64/Super Smash Bros..png delete mode 100644 icon/n64/The Legend of Zelda: Ocarina of Time (Europe).png delete mode 100644 icon/n64/Wave Race 64.png delete mode 100644 icon/nes/Mario Bros..png delete mode 100644 icon/nes/Super Mario Bros..png delete mode 100644 icon/snes/BioMetal.png delete mode 100644 icon/snes/Donkey Kong Country 2: Diddy's Kong Quest.png delete mode 100644 icon/snes/Donkey Kong Country 3: Dixie Kong's Double Trouble!.png delete mode 100644 icon/snes/Donkey Kong Country.png delete mode 100644 icon/snes/Earthbound.png delete mode 100644 icon/snes/F-Zero.png delete mode 100644 icon/snes/Kirby Super Star.png delete mode 100644 icon/snes/Pilotwings.png delete mode 100644 icon/snes/Secret of Mana.png delete mode 100644 icon/snes/Super Famicom Wars.png delete mode 100644 icon/snes/Super Mario All-Stars.png delete mode 100644 icon/snes/Super Mario Kart.png delete mode 100644 icon/snes/Super Mario World.png delete mode 100644 icon/snes/Super R-Type.png delete mode 100644 icon/snes/The Legend of Zelda: A Link to the Past.png diff --git a/.gitignore b/.gitignore index 77320b3..1df2082 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ output/* +icon/* diff --git a/config/romlist.template b/config/romlist.template index 14737c4..15c5ee1 100644 --- a/config/romlist.template +++ b/config/romlist.template @@ -1 +1,2 @@ +# Name of file should be romlist_[SYSTEM NAME] (i.e., romlist_nes) for each system # "NAME" "PATH" "SYSTEM NAME" diff --git a/icon/n64/Banjo-Kazooie.png b/icon/n64/Banjo-Kazooie.png deleted file mode 100644 index d2dd705..0000000 Binary files a/icon/n64/Banjo-Kazooie.png and /dev/null differ diff --git a/icon/n64/Beetle Adventure Racing!.png b/icon/n64/Beetle Adventure Racing!.png deleted file mode 100644 index 8de75c1..0000000 Binary files a/icon/n64/Beetle Adventure Racing!.png and /dev/null differ diff --git a/icon/n64/Diddy Kong Racing.png b/icon/n64/Diddy Kong Racing.png deleted file mode 100644 index f8d27d2..0000000 Binary files a/icon/n64/Diddy Kong Racing.png and /dev/null differ diff --git a/icon/n64/Donkey Kong 64.png b/icon/n64/Donkey Kong 64.png deleted file mode 100644 index 9e4cab5..0000000 Binary files a/icon/n64/Donkey Kong 64.png and /dev/null differ diff --git a/icon/n64/F-Zero X.png b/icon/n64/F-Zero X.png deleted file mode 100644 index 051214f..0000000 Binary files a/icon/n64/F-Zero X.png and /dev/null differ diff --git a/icon/n64/GoldenEye 007.png b/icon/n64/GoldenEye 007.png deleted file mode 100644 index b877cd5..0000000 Binary files a/icon/n64/GoldenEye 007.png and /dev/null differ diff --git a/icon/n64/Mario Kart 64.png b/icon/n64/Mario Kart 64.png deleted file mode 100644 index 0e12e5e..0000000 Binary files a/icon/n64/Mario Kart 64.png and /dev/null differ diff --git a/icon/n64/Mario Party 2.png b/icon/n64/Mario Party 2.png deleted file mode 100644 index 29eacfa..0000000 Binary files a/icon/n64/Mario Party 2.png and /dev/null differ diff --git a/icon/n64/Mario Party 3.png b/icon/n64/Mario Party 3.png deleted file mode 100644 index a686c5f..0000000 Binary files a/icon/n64/Mario Party 3.png and /dev/null differ diff --git a/icon/n64/Paper Mario.png b/icon/n64/Paper Mario.png deleted file mode 100644 index 58f80f5..0000000 Binary files a/icon/n64/Paper Mario.png and /dev/null differ diff --git a/icon/n64/Perfect Dark.png b/icon/n64/Perfect Dark.png deleted file mode 100644 index 851c6cb..0000000 Binary files a/icon/n64/Perfect Dark.png and /dev/null differ diff --git a/icon/n64/Pilotwings 64.png b/icon/n64/Pilotwings 64.png deleted file mode 100644 index c636a8f..0000000 Binary files a/icon/n64/Pilotwings 64.png and /dev/null differ diff --git a/icon/n64/Star Fox 64.png b/icon/n64/Star Fox 64.png deleted file mode 100644 index e60f43d..0000000 Binary files a/icon/n64/Star Fox 64.png and /dev/null differ diff --git a/icon/n64/Super Mario 64.png b/icon/n64/Super Mario 64.png deleted file mode 100644 index f6c63a5..0000000 Binary files a/icon/n64/Super Mario 64.png and /dev/null differ diff --git a/icon/n64/Super Smash Bros..png b/icon/n64/Super Smash Bros..png deleted file mode 100644 index 2369445..0000000 Binary files a/icon/n64/Super Smash Bros..png and /dev/null differ diff --git a/icon/n64/The Legend of Zelda: Ocarina of Time (Europe).png b/icon/n64/The Legend of Zelda: Ocarina of Time (Europe).png deleted file mode 100644 index 5dc81e0..0000000 Binary files a/icon/n64/The Legend of Zelda: Ocarina of Time (Europe).png and /dev/null differ diff --git a/icon/n64/Wave Race 64.png b/icon/n64/Wave Race 64.png deleted file mode 100644 index 41980dd..0000000 Binary files a/icon/n64/Wave Race 64.png and /dev/null differ diff --git a/icon/nes/Mario Bros..png b/icon/nes/Mario Bros..png deleted file mode 100644 index acee373..0000000 Binary files a/icon/nes/Mario Bros..png and /dev/null differ diff --git a/icon/nes/Super Mario Bros..png b/icon/nes/Super Mario Bros..png deleted file mode 100644 index 088be11..0000000 Binary files a/icon/nes/Super Mario Bros..png and /dev/null differ diff --git a/icon/snes/BioMetal.png b/icon/snes/BioMetal.png deleted file mode 100644 index facd72c..0000000 Binary files a/icon/snes/BioMetal.png and /dev/null differ diff --git a/icon/snes/Donkey Kong Country 2: Diddy's Kong Quest.png b/icon/snes/Donkey Kong Country 2: Diddy's Kong Quest.png deleted file mode 100644 index f62d1a4..0000000 Binary files a/icon/snes/Donkey Kong Country 2: Diddy's Kong Quest.png and /dev/null differ diff --git a/icon/snes/Donkey Kong Country 3: Dixie Kong's Double Trouble!.png b/icon/snes/Donkey Kong Country 3: Dixie Kong's Double Trouble!.png deleted file mode 100644 index 556be9b..0000000 Binary files a/icon/snes/Donkey Kong Country 3: Dixie Kong's Double Trouble!.png and /dev/null differ diff --git a/icon/snes/Donkey Kong Country.png b/icon/snes/Donkey Kong Country.png deleted file mode 100644 index f7914a7..0000000 Binary files a/icon/snes/Donkey Kong Country.png and /dev/null differ diff --git a/icon/snes/Earthbound.png b/icon/snes/Earthbound.png deleted file mode 100644 index 8ad7af5..0000000 Binary files a/icon/snes/Earthbound.png and /dev/null differ diff --git a/icon/snes/F-Zero.png b/icon/snes/F-Zero.png deleted file mode 100644 index 2a2aba7..0000000 Binary files a/icon/snes/F-Zero.png and /dev/null differ diff --git a/icon/snes/Kirby Super Star.png b/icon/snes/Kirby Super Star.png deleted file mode 100644 index 02703d8..0000000 Binary files a/icon/snes/Kirby Super Star.png and /dev/null differ diff --git a/icon/snes/Pilotwings.png b/icon/snes/Pilotwings.png deleted file mode 100644 index 6b54482..0000000 Binary files a/icon/snes/Pilotwings.png and /dev/null differ diff --git a/icon/snes/Secret of Mana.png b/icon/snes/Secret of Mana.png deleted file mode 100644 index 200b5cf..0000000 Binary files a/icon/snes/Secret of Mana.png and /dev/null differ diff --git a/icon/snes/Super Famicom Wars.png b/icon/snes/Super Famicom Wars.png deleted file mode 100644 index 6b09d5c..0000000 Binary files a/icon/snes/Super Famicom Wars.png and /dev/null differ diff --git a/icon/snes/Super Mario All-Stars.png b/icon/snes/Super Mario All-Stars.png deleted file mode 100644 index 8b26c72..0000000 Binary files a/icon/snes/Super Mario All-Stars.png and /dev/null differ diff --git a/icon/snes/Super Mario Kart.png b/icon/snes/Super Mario Kart.png deleted file mode 100644 index 8213a6c..0000000 Binary files a/icon/snes/Super Mario Kart.png and /dev/null differ diff --git a/icon/snes/Super Mario World.png b/icon/snes/Super Mario World.png deleted file mode 100644 index bd46316..0000000 Binary files a/icon/snes/Super Mario World.png and /dev/null differ diff --git a/icon/snes/Super R-Type.png b/icon/snes/Super R-Type.png deleted file mode 100644 index 70afb07..0000000 Binary files a/icon/snes/Super R-Type.png and /dev/null differ diff --git a/icon/snes/The Legend of Zelda: A Link to the Past.png b/icon/snes/The Legend of Zelda: A Link to the Past.png deleted file mode 100644 index d817945..0000000 Binary files a/icon/snes/The Legend of Zelda: A Link to the Past.png and /dev/null differ diff --git a/rom-desktop-entry-generator.sh b/rom-desktop-entry-generator.sh index d4eea49..6f53064 100755 --- a/rom-desktop-entry-generator.sh +++ b/rom-desktop-entry-generator.sh @@ -5,14 +5,16 @@ BASEDIR="$(dirname "$0")" SCRIPTNAME="$(basename "$0" .sh)" DESKTOP_ENTRY_OUTPUT_DIR="$BASEDIR/output" DESKTOP_ENTRY_INSTALL_DIR="$HOME/.local/share/applications" +ICON_SOURCE_DIR="$BASEDIR/icon" ICON_INSTALL_DIR="$HOME/.local/share/icons/hicolor" # Build an individual .desktop entry given a name, rompath, and system +# Usage: build_desktop_file NAME ROMPATH SYSTEM build_desktop_file() { NAME="$1" ROMPATH="$2" SYSTEM="$3" - OUTPUT="$DESKTOP_ENTRY_OUTPUT_DIR/${SCRIPTNAME}_${SYSTEM}_${NAME}.desktop" + OUTPUT="$DESKTOP_ENTRY_OUTPUT_DIR/$SYSTEM/${SCRIPTNAME}_${SYSTEM}_${NAME}.desktop" echo "Building $NAME" @@ -43,7 +45,7 @@ build_desktop_file() { # shellcheck source=/dev/null . "$BASEDIR/config/systems/$SYSTEM" - mkdir -p "$DESKTOP_ENTRY_OUTPUT_DIR" + mkdir -p "$DESKTOP_ENTRY_OUTPUT_DIR/$SYSTEM" echo "[Desktop Entry]" > "$OUTPUT" echo "Type=Application" >> "$OUTPUT" echo "Name=$NAME" >> "$OUTPUT" @@ -51,31 +53,67 @@ build_desktop_file() { echo "Exec=$launcher $flags $ROMPATH" >> "$OUTPUT" echo "Categories=Game" >> "$OUTPUT" - echo "Installing $NAME" - install_icon "$NAME" "$SYSTEM" - install_desktop_file "$OUTPUT" + #echo "Installing $NAME" + #install_icon "$NAME" "$SYSTEM" + #install_desktop_file "$OUTPUT" } -# empty the output directory -clean() { - rm -rf "$BASEDIR/output" +# Wrapper for a call to build +# Usage: build_wrapper [TARGET_SYSTEMS]... +build_wrapper() { + # find all romlist files in config if --system is not specified + if [ -z "$1" ]; then + find "$BASEDIR/config/" -name 'romlist_*' | while read -r file; do + parse_config "$file" + done + else + while [ -n "$1" ]; do + if [ -r "$BASEDIR/config/romlist_$1" ]; then + parse_config "$BASEDIR/config/romlist_$1" + fi + shift + done + fi } -install_desktop_file() { - OUTPUT="$1" +# empty the output directory +# Usage: clean_wrapper [TARGET_SYSTEMS] +clean_wrapper() { + while [ -n "$1" ]; do + rm -rf "$DESKTOP_ENTRY_OUTPUT_DIR/$1" + shift + done + + rmdir --ignore-fail-on-non-empty "$DESKTOP_ENTRY_OUTPUT_DIR" +} - # TODO look into using xdg-desktop-menu for install and uninstall - install "$OUTPUT" "$DESKTOP_ENTRY_INSTALL_DIR" +# help message +# Usage: help +help() { + echo "Usage: $0 [OPTION]... [TARGET]..." + echo "Generate desktop entries for video game roms" + echo + echo "Targets:" + echo " build build desktop entries into $DESKTOP_ENTRY_OUTPUT_DIR" + echo " clean remove $DESKTOP_ENTRY_OUTPUT_DIR and its contents (also calls uninstall target)" + echo " install install desktop entries into $DESKTOP_ENTRY_INSTALL_DIR" + echo " uninstall uninstall desktop entries from $DESKTOP_ENTRY_INSTALL_DIR" + echo + echo "Options" + echo " -h, --help print this help message and exit" + echo " --icon-dir [DIR] Specify an icon source directory (default is $ICON_SOURCE_DIR)" + echo " -s, --system [SYSTEM] Specify a system, or comma-separated list of systems. Default is all systems" } +# Usage: install_icon NAME SYSTEM install_icon() { NAME="$1" SYSTEM="$2" - ICON_SOURCE="$BASEDIR/icon/$SYSTEM/$NAME" + ICON_SOURCE="$ICON_SOURCE_DIR/$SYSTEM/$NAME" ICON_EXTENSION="" # Try a number of file extensions for the icon source - for extension in ".png"; do + for extension in ".png" ".svg" ".svgz" ".xpm"; do if [ -r "${ICON_SOURCE}${extension}" ]; then ICON_EXTENSION="$extension" break @@ -95,6 +133,27 @@ install_icon() { done } +# Wrapper for a call to install +# Usage: install_wrapper [TARGET_SYSTEMS]... +install_wrapper() { + while [ -n "$1" ]; do + find "$DESKTOP_ENTRY_OUTPUT_DIR/$1" -type f | while read -r file; do + echo "Installing $file" + + # Install desktop entry + # TODO look into using xdg-desktop-menu for install and uninstall + install "$file" "$DESKTOP_ENTRY_INSTALL_DIR" + + # Install icon + NAME="$(grep "^Name=" "$file" | cut -d "=" -f 2)" + SYSTEM="$(basename "$(dirname "$file")")" + install_icon "$NAME" "$SYSTEM" + done + + shift + done +} + parse_config() { CONFIG_PATH="$1" @@ -109,42 +168,116 @@ parse_config() { eval "build_desktop_file $line" done < "$CONFIG_PATH" - - # Workaround to refresh icons - touch "$ICON_INSTALL_DIR" } -uninstall() { - #NAME="$1" - #ROMPATH="$2" - #SYSTEM="$3" +# Usage: uninstall_wrapper [TARGET_SYSTEMS]... +uninstall_wrapper() { + while [ -n "$1" ]; do + find "$DESKTOP_ENTRY_OUTPUT_DIR/$1" -type f | while read -r file; do + echo "Uninstalling $(basename "$file")" - find "$BASEDIR/output/" -type f | while read -r file; do - echo "Removing $(basename "$file")" + # Remove icons + ICON="$(grep "^Icon=" "$file" | cut -d "=" -f 2)" + for size in "16" "24" "32" "48" "64" "96" "128" "256"; do + rm -f "$ICON_INSTALL_DIR/${size}x${size}/apps/$ICON"* + done - # Remove icons - ICON="$(grep "^Icon=" "$file" | cut -d "=" -f 2)" - for size in "16" "24" "32" "48" "64" "96" "128" "256"; do - rm -f "$ICON_INSTALL_DIR/${size}x${size}/apps/$ICON"* + # Remove the desktop entry + rm -f "$DESKTOP_ENTRY_INSTALL_DIR/$(basename "$file")" done - - # Remove the desktop entry - rm -f "$DESKTOP_ENTRY_INSTALL_DIR/$(basename "$file")" + + shift done } -# TODO allow for building without also installing -MODE="build" -case "$1" in - clean) - MODE="clean" - eval $MODE - ;; - uninstall) - MODE="uninstall" - eval $MODE - ;; - *) - parse_config "$BASEDIR/config/romlist" - ;; -esac +# Read arguments +GETOPT=$(getopt -o 'hs:' --long 'help,icon-dir:,system:' -n "$(basename "$0")" -- "$@") + +# Terminate if getopt goes wrong +if [ $? -ne 0 ]; then + echo "Terminating..." >&2 + exit 1 +fi + +eval set -- "$GETOPT" +unset GETOPT + +while true; do + echo "$1" + case "$1" in + '-h'|'--help') + help + exit + ;; + '--icon-dir') + shift + ICON_SOURCE_DIR="$1" + shift + continue + ;; + '-s'|'--system') + shift + TARGET_SYSTEMS="$1" + shift + continue + ;; + '--') + shift + break + ;; + *) + echo "Internal error!" >&2 + exit 1 + ;; + esac +done + +# By default, build, but do not install +if [ -z "$1" ]; then + build_wrapper +fi + +while [ -n "$1" ]; do + case "$1" in + build) + if [ -z "$TARGET_SYSTEMS" ]; then + build_wrapper + else + build_wrapper $(echo "$TARGET_SYSTEMS" | tr ',' ' ') + fi + shift + continue + ;; + clean) + if [ -z "$TARGET_SYSTEMS" ]; then + uninstall_wrapper $(ls -1 "$DESKTOP_ENTRY_OUTPUT_DIR") + clean_wrapper $(ls -1 "$DESKTOP_ENTRY_OUTPUT_DIR") + else + uninstall_wrapper $(echo "$TARGET_SYSTEMS" | tr ',' ' ') + clean_wrapper $(echo "$TARGET_SYSTEMS" | tr ',' ' ') + fi + shift + continue + ;; + install) + if [ -z "$TARGET_SYSTEMS" ]; then + install_wrapper $(ls -1 "$DESKTOP_ENTRY_OUTPUT_DIR") + else + install_wrapper $(echo "$TARGET_SYSTEMS" | tr ',' ' ') + fi + # Workaround to refresh icons + touch "$ICON_INSTALL_DIR" + shift + continue + ;; + uninstall) + if [ -z "$TARGET_SYSTEMS" ]; then + uninstall_wrapper $(ls -1 "$DESKTOP_ENTRY_OUTPUT_DIR") + else + uninstall_wrapper $(echo "$TARGET_SYSTEMS" | tr ',' ' ') + fi + shift + continue + ;; + esac +done -- cgit