RetroDECK/functions/game_downloader.sh

58 lines
1.9 KiB
Bash
Raw Normal View History

#!/bin/bash
hacks_db_setup() {
crc32_cmd="python3 /app/libexec/crc32.py"
# "hacks" is the general name which includes ROM Hacks, Homebrew and Ports
hacks_db_path="$HOME/.var/app/net.retrodeck.retrodeck/data/hacks_metadata.db"
2024-01-27 14:32:42 +00:00
# Set up hacks database
declare -g hacks_db_cmd="sqlite3 $hacks_db_path"
2024-01-27 14:32:42 +00:00
$hacks_db_cmd < <(curl -sL "https://raw.githubusercontent.com/Libretto7/best-romhacks/main/db_setup.sql")
$hacks_db_cmd "ALTER TABLE bases ADD COLUMN local_path;"
}
2024-01-26 23:37:01 +00:00
db_sanitize() {
echo "$(echo "$1" | sed -e "s/'/''/g")"
}
check_romhacks_compatibility() {
2024-01-26 23:37:01 +00:00
# Add paths of locally available base roms to db
for rom_path in ${roms_folder}/*/*; do
if [[ "$(basename "$rom_path")" != "systeminfo.txt" ]]; then
crc32="$($crc32_cmd "$rom_path")"
2024-01-26 23:37:01 +00:00
$hacks_db_cmd < <(echo "UPDATE bases SET local_path = '""$(db_sanitize "$rom_path")""' WHERE crc32 = '""$crc32""'")
fi
done
}
2024-01-26 23:37:01 +00:00
install_romhack() {
# $1: name of romhack
hack_name="$1"
infos=$($hacks_db_cmd "SELECT bases.system,bases.name,bases.local_path \
FROM bases JOIN rhacks ON bases.crc32 = rhacks.base_crc32 \
WHERE rhacks.name = '""$(db_sanitize "$1")""'")
IFS='|' read -r system base_name base_local_path <<< $infos
2024-01-27 14:32:42 +00:00
# Download patchfile
wget -q "https://github.com/Libretto7/best-romhacks/raw/main/rhacks/$system/$base_name/$hack_name/patch.tar.xz" \
-O "/tmp/patch.tar.xz"
2024-01-26 23:37:01 +00:00
2024-01-27 14:32:42 +00:00
# Extract patchfile
2024-01-26 23:37:01 +00:00
patchfile_name=$(tar -xvf "/tmp/patch.tar.xz" --directory="$roms_folder/$system")
2024-01-27 14:32:42 +00:00
# Create the hack
base_name="$(basename "$base_local_path")"
ext="$(echo "${base_name##*.}")"
flatpak-spawn --host flatpak run com.github.Alcaro.Flips \
--apply "$roms_folder/$system/$patchfile_name" "$base_local_path" "$roms_folder/$system/$hack_name.$ext" >/dev/null
# Cleanup
rm "$roms_folder/$system/$patchfile_name"
2024-01-26 23:37:01 +00:00
}