mirror of
https://github.com/RetroDECK/RetroDECK.git
synced 2024-11-29 09:05:42 +00:00
Use db for data sharing between configurator and game_downloader.sh
This commit is contained in:
parent
6d1437e500
commit
60fa87c16b
|
@ -1,57 +1,31 @@
|
|||
#!/bin/bash
|
||||
|
||||
game_downloader_setup() {
|
||||
hacks_db_setup() {
|
||||
crc32_cmd="python3 /app/libexec/crc32.py"
|
||||
|
||||
# "hacks" is the general name which includes ROM Hacks, Homebrew and Ports
|
||||
hacks_repo_url="https://raw.githubusercontent.com/Libretto7/best-romhacks/b6e2163e9707a23b209f2e3dd082fff29fb6e8c5"
|
||||
hacks_repo_url="https://raw.githubusercontent.com/Libretto7/best-romhacks/main"
|
||||
hacks_db_path="$HOME/.var/app/net.retrodeck.retrodeck/data/hacks_metadata.db"
|
||||
|
||||
# set up hacks database
|
||||
rm $hacks_db_path
|
||||
sqlite3 $hacks_db_path < <(curl -sL "$hacks_repo_url"/db_setup.sql)
|
||||
sqlite3 $hacks_db_path < <(echo "ALTER TABLE bases ADD COLUMN local_path;")
|
||||
|
||||
declare -g hacks_db_cmd="sqlite3 $hacks_db_path"
|
||||
}
|
||||
|
||||
collect_base_rom_crc32s() {
|
||||
check_romhacks_compatibility() {
|
||||
# Register all crc32 checksums of potential base ROMs and their paths into the dictionary "base_roms"
|
||||
|
||||
declare -gA base_roms
|
||||
for rom_path in ${roms_folder}/*/*; do
|
||||
if [[ "$(basename "$rom_path")" != "systeminfo.txt" ]]; then
|
||||
|
||||
for rom in ${roms_folder}/*/*; do
|
||||
if [[ "$(basename "$rom")" != "systeminfo.txt" ]]; then
|
||||
crc32="$($crc32_cmd "$rom")"
|
||||
base_roms["$crc32"]="$rom"
|
||||
crc32="$($crc32_cmd "$rom_path")"
|
||||
sanitized_path="$(echo "$rom_path" | sed -e "s/'/''/g")"
|
||||
|
||||
$hacks_db_cmd < <(echo "UPDATE bases SET local_path = '""$sanitized_path""' WHERE crc32 = '""$crc32""'")
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
build_patches_array() {
|
||||
# Set up array that contains the names of patches compatible with available base ROMs
|
||||
|
||||
declare -ga compatible_romhack_patches=()
|
||||
|
||||
for base_crc32 in "${!base_roms[@]}"; do
|
||||
|
||||
current_base_compatible_patches="$($hacks_db_cmd "SELECT name FROM main WHERE base_crc32 = '""$base_crc32""'")"
|
||||
|
||||
if [[ ! -z "$(printf "$current_base_compatible_patches")" ]]; then # if there are compatible patches for this base
|
||||
# Add available patches to array
|
||||
|
||||
# TODO: Remove redundancy within this line. Puts the patches names separated by newlines into an array
|
||||
IFS='|' read -r -a array_of_compatible_patches <<< $(echo "$current_base_compatible_patches" | tr '\n' '|')
|
||||
|
||||
for patch in "${array_of_compatible_patches[@]}"; do
|
||||
compatible_romhack_patches+=("$patch")
|
||||
done
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
get_compatible_romhacks() {
|
||||
# Provide global array "compatible_romhack_patches" which contains names of available, compatible romhack patches
|
||||
|
||||
game_downloader_setup
|
||||
collect_base_rom_crc32s
|
||||
build_patches_array
|
||||
}
|
||||
|
|
|
@ -91,6 +91,7 @@ source /app/libexec/global.sh
|
|||
# - Version-specific changelogs
|
||||
# - RetroDECK Credits
|
||||
# - Add to Steam
|
||||
# - ROM Hack Downloader
|
||||
# - Developer Options (Hidden)
|
||||
# - Change Multi-user mode
|
||||
# - Change Update channel
|
||||
|
@ -109,6 +110,7 @@ configurator_welcome_dialog() {
|
|||
"RetroDECK: Troubleshooting" "Backup data, perform BIOS / multi-disc file checks checks and emulator resets" \
|
||||
"RetroDECK: About" "Show additional information about RetroDECK" \
|
||||
"Sync with Steam" "Sync with Steam all the favorites games" \
|
||||
"ROM Hack Downloader" "Install ROM Hacks which are compatible with your ROMs" \
|
||||
"Developer Options" "Welcome to the DANGER ZONE")
|
||||
else
|
||||
welcome_menu_options=("Presets & Settings" "Here you find various presets, tweaks and settings to customize your RetroDECK experience" \
|
||||
|
@ -150,6 +152,10 @@ configurator_welcome_dialog() {
|
|||
configurator_add_steam
|
||||
;;
|
||||
|
||||
"ROM Hack Downloader" )
|
||||
configurator_romhack_downloader_dialog
|
||||
;;
|
||||
|
||||
"Developer Options" )
|
||||
configurator_generic_dialog "RetroDECK Configurator - Developer Options" "The following features and options are potentially VERY DANGEROUS for your RetroDECK install!\n\nThey should be considered the bleeding-edge of upcoming RetroDECK features, and never used when you have important saves/states/roms that are not backed up!\n\nYOU HAVE BEEN WARNED!"
|
||||
configurator_developer_dialog
|
||||
|
@ -1392,26 +1398,35 @@ configurator_game_downloader_dialog() {
|
|||
|
||||
configurator_romhack_downloader_dialog() {
|
||||
|
||||
get_compatible_romhacks # creates compatible_romhack_patches array
|
||||
hacks_db_setup
|
||||
check_romhacks_compatibility # add paths of available base roms to db
|
||||
|
||||
available_bases_crc32s="$($hacks_db_cmd "SELECT crc32 FROM bases WHERE local_path NOT NULL;")"
|
||||
|
||||
zenity_columns=()
|
||||
for hack_name in "${compatible_romhack_patches[@]}"; do
|
||||
|
||||
# Get romhack info
|
||||
sanitized_name="$(echo "$hack_name" | sed -e "s/'/''/g")"
|
||||
hack_info="$($hacks_db_cmd "SELECT released,retro_achievements,description FROM main WHERE name = '""$sanitized_name""'")"
|
||||
IFS='|' read -r -a hack_info_array <<< "$hack_info"
|
||||
while IFS= read -r base_crc32; do
|
||||
|
||||
# Add row of hack info
|
||||
zenity_columns+=("$hack_name")
|
||||
for info in "${hack_info_array[@]}"; do
|
||||
zenity_columns+=("$info")
|
||||
done
|
||||
done
|
||||
# Get info of the available hacks for this base crc32
|
||||
info_of_hacks_compatible_with_base="$($hacks_db_cmd "SELECT name,released,retro_achievements,description FROM rhacks WHERE base_crc32 = '""$base_crc32""'")"
|
||||
|
||||
while IFS= read -r single_hack_info; do
|
||||
|
||||
# Turn db output into array
|
||||
IFS='|' read -r -a single_hack_info_array <<< "$single_hack_info"
|
||||
|
||||
# Add row of hack info to zenity choices
|
||||
for info in "${single_hack_info_array[@]}"; do
|
||||
zenity_columns+=("$info")
|
||||
done
|
||||
|
||||
done <<< "$info_of_hacks_compatible_with_base"
|
||||
|
||||
done <<< "$available_bases_crc32s"
|
||||
|
||||
choice=$(zenity --list --title="RetroDECK Configurator Utility - Game Downloader: ROM Hacks" --cancel-label="Back" \
|
||||
--window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" --width=1200 --height=720 \
|
||||
--column="ROM Hack Name" --column="Released" --column="Retro Achievements" --column="Description" \
|
||||
--column="ROM Hack Name" --column="Released" --column="RetroAchievements" --column="Description" \
|
||||
"${zenity_columns[@]}" )
|
||||
|
||||
echo "$choice"
|
||||
|
|
Loading…
Reference in a new issue