summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLouie S <louie@example.com>2024-01-01 12:16:45 -0500
committerLouie S <louie@example.com>2024-01-01 12:16:45 -0500
commit211cfdc280b99f00765071945dbc09e1d7a91b0f (patch)
tree25a7b44d2187bbcbe3c646588fb008a8a19f294a
parent2b506fdcf79212f6ea84ae78070bc6b11a401a43 (diff)
Add support for various flags
-rw-r--r--.gitignore1
-rw-r--r--config/romlist.template1
-rw-r--r--icon/n64/Banjo-Kazooie.pngbin386859 -> 0 bytes
-rw-r--r--icon/n64/Beetle Adventure Racing!.pngbin117045 -> 0 bytes
-rw-r--r--icon/n64/Diddy Kong Racing.pngbin351709 -> 0 bytes
-rw-r--r--icon/n64/Donkey Kong 64.pngbin415484 -> 0 bytes
-rw-r--r--icon/n64/F-Zero X.pngbin638220 -> 0 bytes
-rw-r--r--icon/n64/GoldenEye 007.pngbin4201 -> 0 bytes
-rw-r--r--icon/n64/Mario Kart 64.pngbin148520 -> 0 bytes
-rw-r--r--icon/n64/Mario Party 2.pngbin446311 -> 0 bytes
-rw-r--r--icon/n64/Mario Party 3.pngbin155254 -> 0 bytes
-rw-r--r--icon/n64/Paper Mario.pngbin456286 -> 0 bytes
-rw-r--r--icon/n64/Perfect Dark.pngbin124359 -> 0 bytes
-rw-r--r--icon/n64/Pilotwings 64.pngbin470551 -> 0 bytes
-rw-r--r--icon/n64/Star Fox 64.pngbin286702 -> 0 bytes
-rw-r--r--icon/n64/Super Mario 64.pngbin179830 -> 0 bytes
-rw-r--r--icon/n64/Super Smash Bros..pngbin291844 -> 0 bytes
-rw-r--r--icon/n64/The Legend of Zelda: Ocarina of Time (Europe).pngbin79416 -> 0 bytes
-rw-r--r--icon/n64/Wave Race 64.pngbin328616 -> 0 bytes
-rw-r--r--icon/nes/Mario Bros..pngbin222075 -> 0 bytes
-rw-r--r--icon/nes/Super Mario Bros..pngbin2724 -> 0 bytes
-rw-r--r--icon/snes/BioMetal.pngbin20250 -> 0 bytes
-rw-r--r--icon/snes/Donkey Kong Country 2: Diddy's Kong Quest.pngbin440948 -> 0 bytes
-rw-r--r--icon/snes/Donkey Kong Country 3: Dixie Kong's Double Trouble!.pngbin470222 -> 0 bytes
-rw-r--r--icon/snes/Donkey Kong Country.pngbin490470 -> 0 bytes
-rw-r--r--icon/snes/Earthbound.pngbin3364 -> 0 bytes
-rw-r--r--icon/snes/F-Zero.pngbin71134 -> 0 bytes
-rw-r--r--icon/snes/Kirby Super Star.pngbin369409 -> 0 bytes
-rw-r--r--icon/snes/Pilotwings.pngbin5658 -> 0 bytes
-rw-r--r--icon/snes/Secret of Mana.pngbin370984 -> 0 bytes
-rw-r--r--icon/snes/Super Famicom Wars.pngbin21069 -> 0 bytes
-rw-r--r--icon/snes/Super Mario All-Stars.pngbin105211 -> 0 bytes
-rw-r--r--icon/snes/Super Mario Kart.pngbin73418 -> 0 bytes
-rw-r--r--icon/snes/Super Mario World.pngbin10111 -> 0 bytes
-rw-r--r--icon/snes/Super R-Type.pngbin5381 -> 0 bytes
-rw-r--r--icon/snes/The Legend of Zelda: A Link to the Past.pngbin9916 -> 0 bytes
-rwxr-xr-xrom-desktop-entry-generator.sh223
37 files changed, 180 insertions, 45 deletions
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
--- a/icon/n64/Banjo-Kazooie.png
+++ /dev/null
Binary files differ
diff --git a/icon/n64/Beetle Adventure Racing!.png b/icon/n64/Beetle Adventure Racing!.png
deleted file mode 100644
index 8de75c1..0000000
--- a/icon/n64/Beetle Adventure Racing!.png
+++ /dev/null
Binary files differ
diff --git a/icon/n64/Diddy Kong Racing.png b/icon/n64/Diddy Kong Racing.png
deleted file mode 100644
index f8d27d2..0000000
--- a/icon/n64/Diddy Kong Racing.png
+++ /dev/null
Binary files differ
diff --git a/icon/n64/Donkey Kong 64.png b/icon/n64/Donkey Kong 64.png
deleted file mode 100644
index 9e4cab5..0000000
--- a/icon/n64/Donkey Kong 64.png
+++ /dev/null
Binary files differ
diff --git a/icon/n64/F-Zero X.png b/icon/n64/F-Zero X.png
deleted file mode 100644
index 051214f..0000000
--- a/icon/n64/F-Zero X.png
+++ /dev/null
Binary files differ
diff --git a/icon/n64/GoldenEye 007.png b/icon/n64/GoldenEye 007.png
deleted file mode 100644
index b877cd5..0000000
--- a/icon/n64/GoldenEye 007.png
+++ /dev/null
Binary files differ
diff --git a/icon/n64/Mario Kart 64.png b/icon/n64/Mario Kart 64.png
deleted file mode 100644
index 0e12e5e..0000000
--- a/icon/n64/Mario Kart 64.png
+++ /dev/null
Binary files differ
diff --git a/icon/n64/Mario Party 2.png b/icon/n64/Mario Party 2.png
deleted file mode 100644
index 29eacfa..0000000
--- a/icon/n64/Mario Party 2.png
+++ /dev/null
Binary files differ
diff --git a/icon/n64/Mario Party 3.png b/icon/n64/Mario Party 3.png
deleted file mode 100644
index a686c5f..0000000
--- a/icon/n64/Mario Party 3.png
+++ /dev/null
Binary files differ
diff --git a/icon/n64/Paper Mario.png b/icon/n64/Paper Mario.png
deleted file mode 100644
index 58f80f5..0000000
--- a/icon/n64/Paper Mario.png
+++ /dev/null
Binary files differ
diff --git a/icon/n64/Perfect Dark.png b/icon/n64/Perfect Dark.png
deleted file mode 100644
index 851c6cb..0000000
--- a/icon/n64/Perfect Dark.png
+++ /dev/null
Binary files differ
diff --git a/icon/n64/Pilotwings 64.png b/icon/n64/Pilotwings 64.png
deleted file mode 100644
index c636a8f..0000000
--- a/icon/n64/Pilotwings 64.png
+++ /dev/null
Binary files differ
diff --git a/icon/n64/Star Fox 64.png b/icon/n64/Star Fox 64.png
deleted file mode 100644
index e60f43d..0000000
--- a/icon/n64/Star Fox 64.png
+++ /dev/null
Binary files differ
diff --git a/icon/n64/Super Mario 64.png b/icon/n64/Super Mario 64.png
deleted file mode 100644
index f6c63a5..0000000
--- a/icon/n64/Super Mario 64.png
+++ /dev/null
Binary files differ
diff --git a/icon/n64/Super Smash Bros..png b/icon/n64/Super Smash Bros..png
deleted file mode 100644
index 2369445..0000000
--- a/icon/n64/Super Smash Bros..png
+++ /dev/null
Binary files 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
--- a/icon/n64/The Legend of Zelda: Ocarina of Time (Europe).png
+++ /dev/null
Binary files differ
diff --git a/icon/n64/Wave Race 64.png b/icon/n64/Wave Race 64.png
deleted file mode 100644
index 41980dd..0000000
--- a/icon/n64/Wave Race 64.png
+++ /dev/null
Binary files differ
diff --git a/icon/nes/Mario Bros..png b/icon/nes/Mario Bros..png
deleted file mode 100644
index acee373..0000000
--- a/icon/nes/Mario Bros..png
+++ /dev/null
Binary files differ
diff --git a/icon/nes/Super Mario Bros..png b/icon/nes/Super Mario Bros..png
deleted file mode 100644
index 088be11..0000000
--- a/icon/nes/Super Mario Bros..png
+++ /dev/null
Binary files differ
diff --git a/icon/snes/BioMetal.png b/icon/snes/BioMetal.png
deleted file mode 100644
index facd72c..0000000
--- a/icon/snes/BioMetal.png
+++ /dev/null
Binary files 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
--- a/icon/snes/Donkey Kong Country 2: Diddy's Kong Quest.png
+++ /dev/null
Binary files 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
--- a/icon/snes/Donkey Kong Country 3: Dixie Kong's Double Trouble!.png
+++ /dev/null
Binary files differ
diff --git a/icon/snes/Donkey Kong Country.png b/icon/snes/Donkey Kong Country.png
deleted file mode 100644
index f7914a7..0000000
--- a/icon/snes/Donkey Kong Country.png
+++ /dev/null
Binary files differ
diff --git a/icon/snes/Earthbound.png b/icon/snes/Earthbound.png
deleted file mode 100644
index 8ad7af5..0000000
--- a/icon/snes/Earthbound.png
+++ /dev/null
Binary files differ
diff --git a/icon/snes/F-Zero.png b/icon/snes/F-Zero.png
deleted file mode 100644
index 2a2aba7..0000000
--- a/icon/snes/F-Zero.png
+++ /dev/null
Binary files differ
diff --git a/icon/snes/Kirby Super Star.png b/icon/snes/Kirby Super Star.png
deleted file mode 100644
index 02703d8..0000000
--- a/icon/snes/Kirby Super Star.png
+++ /dev/null
Binary files differ
diff --git a/icon/snes/Pilotwings.png b/icon/snes/Pilotwings.png
deleted file mode 100644
index 6b54482..0000000
--- a/icon/snes/Pilotwings.png
+++ /dev/null
Binary files differ
diff --git a/icon/snes/Secret of Mana.png b/icon/snes/Secret of Mana.png
deleted file mode 100644
index 200b5cf..0000000
--- a/icon/snes/Secret of Mana.png
+++ /dev/null
Binary files differ
diff --git a/icon/snes/Super Famicom Wars.png b/icon/snes/Super Famicom Wars.png
deleted file mode 100644
index 6b09d5c..0000000
--- a/icon/snes/Super Famicom Wars.png
+++ /dev/null
Binary files 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
--- a/icon/snes/Super Mario All-Stars.png
+++ /dev/null
Binary files differ
diff --git a/icon/snes/Super Mario Kart.png b/icon/snes/Super Mario Kart.png
deleted file mode 100644
index 8213a6c..0000000
--- a/icon/snes/Super Mario Kart.png
+++ /dev/null
Binary files differ
diff --git a/icon/snes/Super Mario World.png b/icon/snes/Super Mario World.png
deleted file mode 100644
index bd46316..0000000
--- a/icon/snes/Super Mario World.png
+++ /dev/null
Binary files differ
diff --git a/icon/snes/Super R-Type.png b/icon/snes/Super R-Type.png
deleted file mode 100644
index 70afb07..0000000
--- a/icon/snes/Super R-Type.png
+++ /dev/null
Binary files 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
--- a/icon/snes/The Legend of Zelda: A Link to the Past.png
+++ /dev/null
Binary files 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