Add CHD compression functions

This commit is contained in:
icenine451 2023-03-07 10:06:08 -05:00
parent be7a6afbbd
commit b870ff92f9
3 changed files with 123 additions and 20 deletions

View file

@ -8,16 +8,16 @@
# FUNCTION SECTION
#=================
browse() {
directory_browse() {
# This function browses for a directory and returns the path chosen
# USAGE: path_to_be_browsed_for=$(browse $action_text)
# USAGE: path_to_be_browsed_for=$(directory_browse $action_text)
path_selected=false
local path_selected=false
while [ $path_selected == false ]
do
target="$(zenity --file-selection --title="Choose $1" --directory)"
if [ $? == 0 ] #yes
local target="$(zenity --file-selection --title="Choose $1" --directory)"
if [ ! -z $target ] #yes
then
zenity --question --no-wrap --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" --title "RetroDECK" --cancel-label="No" --ok-label "Yes" \
--text="Directory $target chosen, is this correct?"
@ -29,7 +29,37 @@ browse() {
fi
else
zenity --question --no-wrap --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" --title "RetroDECK" --cancel-label="No" --ok-label "Yes" \
--text="No directory selected. Do you want to exit?"
--text="No directory selected. Do you want to exit the selection process?"
if [ $? == 0 ]
then
break
fi
fi
done
}
file_browse() {
# This function browses for a file and returns the path chosen
# USAGE: file_to_be_browsed_for=$(file_browse $action_text)
local file_selected=false
while [ $file_selected == false ]
do
local target="$(zenity --file-selection --title="Choose $1")"
if [ ! -z $target ] #yes
then
zenity --question --no-wrap --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" --title "RetroDECK" --cancel-label="No" --ok-label "Yes" \
--text="File $target chosen, is this correct?"
if [ $? == 0 ]
then
file_selected=true
echo $target
break
fi
else
zenity --question --no-wrap --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" --title "RetroDECK" --cancel-label="No" --ok-label "Yes" \
--text="No file selected. Do you want to exit the selection process?"
if [ $? == 0 ]
then
break
@ -892,17 +922,17 @@ finit_browse() {
path_selected=false
while [ $path_selected == false ]
do
sdcard="$(zenity --file-selection --title="Choose RetroDECK data directory location" --directory)"
if [[ $? == 0 ]]; then
if [[ -w $sdcard ]]; then
local target="$(zenity --file-selection --title="Choose RetroDECK data directory location" --directory)"
if [[ ! -z $target ]]; then
if [[ -w $target ]]; then
zenity --question --no-wrap --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" --title "RetroDECK" \
--cancel-label="No" \
--ok-label "Yes" \
--text="Your RetroDECK data folder will be:\n\n$sdcard/retrodeck\n\nis that ok?"
--text="Your RetroDECK data folder will be:\n\n$target/retrodeck\n\nis that ok?"
if [ $? == 0 ] #yes
then
path_selected=true
echo "$sdcard/retrodeck"
echo "$target/retrodeck"
break
else
zenity --question --no-wrap --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" --title "RetroDECK" --cancel-label="No" --ok-label "Yes" --text="Do you want to quit?"

View file

@ -72,7 +72,7 @@ then
# Check if SD card path has changed from SteamOS update
if [[ ! -d $default_sd && "$(ls -A /run/media/deck/)" ]]; then
configurator_generic_dialog "The SD card was not found in the expected location.\nThis may happen when SteamOS is updated.\n\nPlease browse to the current location of the SD card.\n\nIf you are not using an SD card, please click \"Cancel\"."
default_sd=$(browse "SD Card Location")
default_sd=$(directory_browse "SD Card Location")
fi
rdhome="$HOME/retrodeck" # the retrodeck home, aka ~/retrodeck
@ -111,7 +111,7 @@ else
if [[ ! -d $rdhome ]]; then
prev_home_path=$rdhome
configurator_generic_dialog "The RetroDECK data folder was not found in the expected location.\nThis may happen when SteamOS is updated.\n\nPlease browse to the current location of the \"retrodeck\" folder."
new_home_path=$(browse "RetroDECK folder location")
new_home_path=$(directory_browse "RetroDECK folder location")
sed -i 's#'$prev_home_path'#'$new_home_path'#g' $rd_conf
source "$rd_conf"
emulators_post_move

View file

@ -13,14 +13,18 @@ source /app/libexec/functions.sh # uncomment for flatpak testing
# Configurator Option Tree
# Welcome
# - Move RetroDECK data directory
# - Migrate everything
# - Change Emulator Options
# - Move Files
# - Migrate Everything
# - Change Options
# - RetroArch
# - Change Rewind Setting
# - RetroAchivement login
# - RetroAchivement Login
# - Login prompt
# - Reset RetroDECK
# - Compress Games
# - Manual selection
# - Troubleshooting Tools
# - Multi-file game check
# - Reset
# - Reset RetroArch
# - Reset Specific Standalone Emulator
# - Reset Citra
@ -344,6 +348,67 @@ configurator_options_dialog() {
esac
}
configurator_compress_single_game_dialog() {
file_to_compress=$(file_browse "Game to compress")
if [[ ! -z $file_to_compress ]]; then
if [[ "$file_to_compress" == *".cue" ]] || [[ "$file_to_compress" == *".gdi" ]] || [[ "$file_to_compress" == *".iso" ]]; then
local file_path=$(dirname $(realpath $file_to_compress))
local file_base_name=$(basename $file_to_compress)
local file_name=${file_base_name%.*}
if [[ "$file_to_compress" == *".cue" ]]; then # Validate .cue file correctly maps existing .bin file(s)
local cue_bin_files=$(grep -o -P "(?<=FILE \").*(?=\".*$)" $file_to_compress)
local cue_validated="false"
for line in $cue_bin_files
do
if [[ -f "$file_path/$line" ]]; then
cue_validated="true"
else
echo ".bin file NOT found at $file_path/$line"
echo ".cue file could not be validated. Please verify your .cue file contains the correct corresponding .bin file information and retry."
cue_validated="false"
break
fi
done
if [[ $cue_validated == "true" ]]; then
(
compress_to_chd "$file_path/$file_base_name" "$file_path/$file_name"
) |
zenity --icon-name=net.retrodeck.retrodeck --progress --no-cancel --pulsate --auto-close \
--window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \
--title "RetroDECK Configurator Utility - Compression in Progress" \
--text="Compressing game $file_base_name, please wait."
fi
else
(
compress_to_chd "$file_path/$file_base_name" "$file_path/$file_name"
) |
zenity --icon-name=net.retrodeck.retrodeck --progress --no-cancel --pulsate --auto-close \
--window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \
--title "RetroDECK Configurator Utility - Compression in Progress" \
--text="Compressing game $file_base_name, please wait."
fi
else
configurator_generic_dialog "File type not recognized. Supported file types are .cue, .gdi and .iso"
configurator_compress_single_game_dialog
fi
else
configurator_generic_dialog "No file selected, returning to main menu"
configurator_welcome_dialog
fi
}
configurator_compress_games_dialog() {
# This is currently a placeholder for a dialog where you can compress a single game or multiple at once. Currently only the single game option is available, so is launched by default.
configurator_generic_dialog "This utility will compress a single game into .CHD format.\n\nPlease select the game to be compressed in the next dialog: supported file types are .cue, .iso and .gdi"
configurator_compress_single_game_dialog
}
configurator_troubleshooting_tools_dialog() {
}
configurator_move_dialog() {
if [[ -d $rdhome ]]; then
destination=$(configurator_destination_choice_dialog "RetroDECK Data" "Please choose a destination for the RetroDECK data folder.")
@ -433,7 +498,7 @@ configurator_move_dialog() {
"Custom Location" )
configurator_generic_dialog "Select the root folder you would like to store the RetroDECK data folder in.\n\nA new folder \"retrodeck\" will be created in the destination chosen."
custom_dest=$(browse "RetroDECK directory location")
custom_dest=$(directory_browse "RetroDECK directory location")
if [[ ! -w $custom_dest ]]; then
configurator_generic_dialog "The destination was found but is not writable\n\nThis can happen if RetroDECK does not have permission to write to this location.\n\nThis can typically be solved through the utility Flatseal, please make the needed changes and try the moving process again."
configurator_welcome_dialog
@ -484,7 +549,7 @@ configurator_move_dialog() {
esac
else
configurator_generic_dialog "The RetroDECK data folder was not found at the expected location.\n\nThis may have happened if the folder was moved manually.\n\nPlease select the current location of the RetroDECK data folder."
rdhome=$(browse "RetroDECK directory location")
rdhome=$(directory_browse "RetroDECK directory location")
roms_folder="$rdhome/roms"
saves_folder="$rdhome/saves"
states_folder="$rdhome/states"
@ -529,6 +594,14 @@ configurator_welcome_dialog() {
configurator_retroachivement_dialog
;;
"Compress Games" )
configurator_compress_games_dialog
;;
"Troubleshooting Tools" )
configurator_troubleshooting_tools_dialog
;;
"Reset" )
configurator_reset_dialog
;;