diff --git a/play.it-2/src/20_dependencies.sh b/play.it-2/src/20_dependencies.sh index 857d96614e13d38bb0a7284a92a518e3ce11d3fb..fb10beaa9469bfe7f470fa147da8cce7bb01856a 100644 --- a/play.it-2/src/20_dependencies.sh +++ b/play.it-2/src/20_dependencies.sh @@ -3,7 +3,6 @@ # NEEDED VARS: (ARCHIVE) (ARCHIVE_TYPE) (OPTION_CHECKSUM) (OPTION_PACKAGE) (SCRIPT_DEPS) # CALLS: check_deps_7z check_deps_error_not_found icons_list_dependencies check_deps() { - icons_list_dependencies if [ "$ARCHIVE" ]; then case "$(get_value "${ARCHIVE}_TYPE")" in ('cabinet') @@ -62,6 +61,22 @@ check_deps() { ;; esac done + + icons_list_dependencies + for dep in $ICONS_DEPS; do + if ! command -v "$dep" >/dev/null 2>&1; then + case "$OPTION_ICONS" in + ('yes') + check_deps_icons_error_not_found "$dep" + ;; + ('auto') + check_deps_icons_warning_not_found "$dep" + export SKIP_ICONS='1' + export ICONS_DEPS='' + ;; + esac + fi + done } # check presence of a software to handle .7z archives @@ -135,3 +150,42 @@ check_deps_error_not_found() { return 1 } +# display an error message if an icon dependency is missing +# USAGE: check_deps_icons_error_not_found $dependency +# NEEDED VARS: (LANG) +# CALLED BY: check_deps +check_deps_icons_error_not_found() { + print_error + case "${LANG%_*}" in + ('fr') + string='%s est introuvable. Installez-le avant de lancer ce script.\n' + string="$string"'Vous pouvez aussi utiliser --icons=no ou --icons=auto\n' + ;; + ('en'|*) + string='%s not found. Install it before running this script.\n' + string="$string"'You can also use --icons=no or --icons=auto\n' + ;; + esac + printf "$string" "$1" + return 1 +} + +# display a warning message if an icon dependency is missing +# USAGE: check_deps_icons_warning_not_found $dependency +# NEEDED VARS: (LANG) +# CALLED BY: check_deps +check_deps_icons_warning_not_found() { + print_warning + case "${LANG%_*}" in + ('fr') + string='%s est introuvable. Installez-le pour inclure les icônes.\n' + string="$string"'Vous pouvez aussi utiliser --icons=no ou --icons=yes\n' + ;; + ('en'|*) + string='%s not found. Install it to include icons.\n' + string="$string"'You can also use --icons=no or --icons=yes\n' + ;; + esac + printf "$string\n" "$1" +} + diff --git a/play.it-2/src/20_help.sh b/play.it-2/src/20_help.sh index c6e7870636ac8f78f29c8815dfb4c74c9d655c5b..85866606ab3354a03abb9f6f86bdb9f212752c2e 100644 --- a/play.it-2/src/20_help.sh +++ b/play.it-2/src/20_help.sh @@ -40,6 +40,8 @@ help() { printf '\n' help_dryrun printf '\n' + help_icons + printf '\n' printf 'ARCHIVE\n\n' archives_get_list @@ -232,3 +234,42 @@ help_dryrun() { printf '\t%s\n\n' "$string" } +# display --icons option usage +# USAGE: help_icons +# NEEDED VARS: (LANG) +# CALLED BY: help +help_icons() { + local string + local string_default + local string_yes + local string_no + local string_auto + case "${LANG%_*}" in + ('fr') + string='Inclure ou non les icônes dans les paquets' + string_default='(option par défaut)' + # shellcheck disable=SC1112 + string_yes='Inclure les icônes et s’arrêter si une dépendance n’a pas pu être trouvée' + string_no='Ne pas inclure les icônes même si toutes les dépendances sont présentes' + string_auto='Inclure les icônes seulement si toutes les dépendances sont présentes' + ;; + ('en'|*) + string='Include icons in packages' + string_default='(default option)' + # shellcheck disable=SC1112 + string_yes='Include icons and stop if a dependency wasn’t found' + # shellcheck disable=SC1112 + string_no='Don’t include icons even if all dependencies are present' + string_auto='Only include icons if all dependencies are present' + ;; + esac + printf -- '--icons=yes|no|auto\n' + printf -- '--icons yes|no|auto\n\n' + printf '\t%s\n\n' "$string" + printf '\tyes\t%s' "$string_yes" + [ "$DEFAULT_OPTION_ICONS" = 'yes' ] && printf ' %s\n' "$string_default" || printf '\n' + printf '\tno\t%s' "$string_no" + [ "$DEFAULT_OPTION_ICONS" = 'no' ] && printf ' %s\n' "$string_default" || printf '\n' + printf '\tauto\t%s' "$string_auto" + [ "$DEFAULT_OPTION_ICONS" = 'auto' ] && printf ' %s\n' "$string_default" || printf '\n' +} diff --git a/play.it-2/src/30_icons.sh b/play.it-2/src/30_icons.sh index e360bf346e770f1abf1a008390b7d8e1c02d456c..cb422bc5613f6fa9dfc5b035f940eee9729b961c 100644 --- a/play.it-2/src/30_icons.sh +++ b/play.it-2/src/30_icons.sh @@ -1,6 +1,7 @@ # update dependencies list with commands needed for icons extraction # USAGE: icons_list_dependencies icons_list_dependencies() { + [ "$SKIP_ICONS" = '1' ] && return 0 local script script="$0" if grep\ @@ -8,7 +9,7 @@ icons_list_dependencies() { --regexp="^APP_[^_]\\+_ICON_.\\+='.\\+'"\ "$script" 1>/dev/null then - SCRIPT_DEPS="$SCRIPT_DEPS identify" + ICONS_DEPS="$ICONS_DEPS identify" if grep\ --regexp="^APP_[^_]\\+_ICON='.\\+\\.bmp'"\ --regexp="^APP_[^_]\\+_ICON_.\\+='.\\+\\.bmp'"\ @@ -16,17 +17,17 @@ icons_list_dependencies() { --regexp="^APP_[^_]\\+_ICON_.\\+='.\\+\\.ico'"\ "$script" 1>/dev/null then - SCRIPT_DEPS="$SCRIPT_DEPS convert" + ICONS_DEPS="$ICONS convert" fi if grep\ --regexp="^APP_[^_]\\+_ICON='.\\+\\.exe'"\ --regexp="^APP_[^_]\\+_ICON_.\\+='.\\+\\.exe'"\ "$script" 1>/dev/null then - SCRIPT_DEPS="$SCRIPT_DEPS convert wrestool" + ICONS_DEPS="$ICONS_DEPS convert wrestool" fi fi - export SCRIPT_DEPS + export ICONS_DEPS } # get .png file(s) from various icon sources in current package @@ -34,6 +35,7 @@ icons_list_dependencies() { # NEEDED VARS: APP_ID|GAME_ID PATH_GAME PATH_ICON_BASE PLAYIT_WORKDIR PKG # CALLS: icons_get_from_path icons_get_from_package() { + [ "$SKIP_ICONS" = '1' ] && return 0 local path local path_pkg path_pkg="$(get_value "${PKG}_PATH")" @@ -49,6 +51,7 @@ extract_and_sort_icons_from() { icons_get_from_package "$@"; } # NEEDED VARS: APP_ID|GAME_ID PATH_ICON_BASE PLAYIT_WORKDIR PKG # CALLS: icons_get_from_path icons_get_from_workdir() { + [ "$SKIP_ICONS" = '1' ] && return 0 local path path="$PLAYIT_WORKDIR/gamedata" icons_get_from_path "$path" "$@" @@ -122,6 +125,7 @@ icon_extract_png_from_file() { } # compatibility alias extract_icon_from() { + [ "$SKIP_ICONS" = '1' ] && return 0 local destination local file destination="$PLAYIT_WORKDIR/icons" @@ -275,6 +279,7 @@ icon_get_resolution_from_file() { # NEEDED VARS: APP_ID|GAME_ID PATH_GAME PATH_ICON_BASE PKG icons_linking_postinst() { [ "$DRY_RUN" = '1' ] && return 0 + [ "$SKIP_ICONS" = '1' ] && return 0 local app local file local icon @@ -342,6 +347,7 @@ postinst_icons_linking() { icons_linking_postinst "$@"; } # USAGE: icons_move_to $pkg # NEEDED VARS: PATH_ICON_BASE PKG icons_move_to() { + [ "$SKIP_ICONS" = '1' ] && return 0 local destination local source destination="$1" @@ -404,3 +410,22 @@ icon_path_empty_error() { printf "$string\\n" "$1" return 1 } + +# print a warning if an icon dependency wasn't found (in auto mode) +# USAGE: icons_dep_missing_warning $dependency +# NEEDED VARS: (LANG) +# CALLED BY: icons_list_dependencies +icons_dep_missing_warning() { + local string + case "${LANG%_*}" in + ('fr') + # shellcheck disable=SC1112 + string='%s est introuvable. Installez-le pour inclure les icônes.' + ;; + ('en'|*) + string='%s not found. Install it to include icons.' + ;; + esac + print_warning + printf "$string\\n" "$1" +} diff --git a/play.it-2/src/99_init.sh b/play.it-2/src/99_init.sh index 05868f4cf5eac77d3f1edf21297d28fd84f99ac5..ceac4e78d599a9c182713fab910e560e89ee328b 100644 --- a/play.it-2/src/99_init.sh +++ b/play.it-2/src/99_init.sh @@ -45,6 +45,8 @@ if [ "${0##*/}" != 'libplayit2.sh' ] && [ -z "$LIB_ONLY" ]; then ALLOWED_VALUES_COMPRESSION='none gzip xz bzip2' # shellcheck disable=SC2034 ALLOWED_VALUES_PACKAGE='arch deb' + # shellcheck disable=SC2034 + ALLOWED_VALUES_ICONS='yes no auto' # Set default values for common options @@ -58,6 +60,8 @@ if [ "${0##*/}" != 'libplayit2.sh' ] && [ -z "$LIB_ONLY" ]; then DEFAULT_OPTION_PREFIX='/usr/local' # shellcheck disable=SC2034 DEFAULT_OPTION_PACKAGE='deb' + # shellcheck disable=SC2034 + DEFAULT_OPTION_ICONS='yes' unset winecfg_desktop unset winecfg_launcher @@ -86,7 +90,9 @@ if [ "${0##*/}" != 'libplayit2.sh' ] && [ -z "$LIB_ONLY" ]; then '--prefix='*|\ '--prefix'|\ '--package='*|\ - '--package') + '--package'|\ + '--icons='*|\ + '--icons') if [ "${1%=*}" != "${1#*=}" ]; then option="$(printf '%s' "${1%=*}" | sed 's/^--//')" value="${1#*=}" @@ -138,7 +144,7 @@ if [ "${0##*/}" != 'libplayit2.sh' ] && [ -z "$LIB_ONLY" ]; then # Set options not already set by script arguments to default values - for option in 'ARCHITECTURE' 'CHECKSUM' 'COMPRESSION' 'PREFIX'; do + for option in 'ARCHITECTURE' 'CHECKSUM' 'COMPRESSION' 'PREFIX' 'ICONS'; do if [ -z "$(get_value "OPTION_$option")" ]\ && [ -n "$(get_value "DEFAULT_OPTION_$option")" ]; then # shellcheck disable=SC2046 @@ -182,10 +188,15 @@ if [ "${0##*/}" != 'libplayit2.sh' ] && [ -z "$LIB_ONLY" ]; then exit 1 } - for option in 'CHECKSUM' 'COMPRESSION' 'PACKAGE'; do + for option in 'CHECKSUM' 'COMPRESSION' 'PACKAGE' 'ICONS'; do check_option_validity "$option" done + if [ "$OPTION_ICONS" = 'no' ]; then + SKIP_ICONS=1 + export SKIP_ICONS + fi + # Do not allow bzip2 compression when building Debian packages if