SHARE
TWEET

Edited jsfuncs.sh

a guest Mar 30th, 2019 94 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env bash
  2. # jsfuncs.sh
  3. ############
  4. #
  5. # These functions were originally part of joystick_selection.sh but as
  6. # they became useful for runcommand-on{start,end}.sh, then I decided to
  7. # put them in a separate file.
  8. #
  9. # Most of the functions have comments about what it does.
  10. #
  11. # Has been edited by a monster to achieve monstrous things.
  12. #
  13.  
  14. user="$SUDO_USER"
  15. [[ -z "$user" ]] && user=$(id -un)
  16.  
  17. readonly rootdir="/opt/retropie"
  18. readonly configdir="$rootdir/configs"
  19. readonly global_jscfg="$configdir/all/joystick-selection.cfg"
  20. readonly jslist_exe="$rootdir/supplementary/joystick-selection/jslist"
  21. readonly jslist_file=$(mktemp /tmp/jslist.XXXX)
  22. readonly temp_file=$(mktemp /tmp/deleteme.XXXX)
  23.  
  24. # getting some usefull functions from RetroPie
  25. source "$rootdir/lib/inifuncs.sh"
  26.  
  27. # BYNAME is a flag to indicate the using of "joystick selection by name" method.
  28. # The "ON" string means that the selection by name method is on, any string
  29. # different from "ON" means "off"
  30. BYNAME="OFF"
  31. byname_msg=
  32.  
  33.  
  34. # borrowed code from runcommand.sh
  35. function start_joy2key() {
  36.     local __joy2key_dev
  37.  
  38.     # get the first joystick device (if not already set)
  39.     [[ -z "$__joy2key_dev" ]] && __joy2key_dev="$(ls -1 /dev/input/js* 2>/dev/null | head -n1)"
  40.  
  41.     # if joy2key.py is installed run it with cursor keys for axis, and enter + tab for buttons 0 and 1
  42.     if [[ -f "$rootdir/supplementary/runcommand/joy2key.py" && -n "$__joy2key_dev" ]] && ! pgrep -f joy2key.py >/dev/null; then
  43.         "$rootdir/supplementary/runcommand/joy2key.py" "$__joy2key_dev" 1b5b44 1b5b43 1b5b41 1b5b42 0a 09 &
  44.         __joy2key_pid=$!
  45.     fi
  46. }
  47.  
  48.  
  49. # borrowed code from runcommand.sh
  50. function stop_joy2key() {
  51.     if [[ -n "$__joy2key_pid" ]]; then
  52.         kill -INT "$__joy2key_pid" 2> /dev/null
  53.     fi
  54. }
  55.  
  56.  
  57. # use this instead of exit to stop_joy2key
  58. function safe_exit() {
  59.     stop_joy2key
  60.     rm -f "$jslist_file" "$temp_file"
  61.     exit $1
  62. }
  63.  
  64.  
  65. function fatalError() {
  66.     echo "Error: $1" 1>&2
  67.     safe_exit 1
  68. }
  69.  
  70.  
  71. # check if we are able to use the joystick selection by name method.
  72. function check_byname_is_ok() {
  73.     local okcount=0
  74.  
  75.     # checking if we have runcommand-onstart.sh feature...
  76.     grep 'runcommand-onstart\.sh' "$rootdir/supplementary/runcommand/runcommand.sh" \
  77.     | grep -qv '#.*runcommand-onstart\.sh'
  78.     if [[ $? -ne 0 ]]; then
  79.         dialog \
  80.           --title "Joystick selection by name error!" \
  81.           --yesno \
  82. "It seems that your runcommand is outdated!
  83.  
  84. The joystick selection by name method depends on an updated version of RetroPie's runcommand.
  85.  
  86. You must update it via retropie_setup.sh to use joystick selection by name method.
  87.  
  88. Short way: execute retropie_setup.sh and choose \"Update RetroPie-Setup script\". And then go to
  89. \"Manage Packages\" -> \"Manage core packages\" -> \"runcommand\" -> \"Update from binary\"
  90.  
  91. Detailed instructions can be found here:
  92. https://github.com/RetroPie/RetroPie-Setup/wiki/Updating-RetroPie
  93.  
  94. Choose \"Yes\" to exit or \"No\" to continue using the joystick selection by index method." \
  95.           0 0 >/dev/tty || return $?
  96.  
  97.         safe_exit 0
  98.     fi
  99.     okcount=$((okcount + 1)) # runcommand is updated - CHECKED!
  100.  
  101.     local jsonstart="$rootdir/supplementary/joystick-selection/js-onstart.sh"
  102.     local rconstart="$configdir/all/runcommand-onstart.sh"
  103.  
  104.     # checking runcommand-onstart.sh
  105.     if ! grep -q "^bash \"$jsonstart\" \"\$@\"" "$rconstart" 2> /dev/null; then
  106.         sudo cat >> "$rconstart" << _EoF_
  107. # the line below is needed to use the joystick selection by name method
  108. bash "$jsonstart" "\$@"
  109. _EoF_
  110.         check_byname_is_ok
  111.         return $?
  112.     fi
  113.     okcount=$((okcount + 1)) # runcommand-onstart calls js-onstart.sh - CHECKED!
  114.  
  115.     # checking if js-onstart.sh exists
  116.     if ! [[ -f "$jsonstart" ]]; then
  117.         cat > "/tmp/jsonstart.tmp" << _EoF_
  118. #!/bin/bash
  119. # this file is needed to use the joystick selection by name method.
  120. # Do NOT edit it unless you are absolutely right of what you are doing.
  121.  
  122. [[ "\$4" != *retroarch* ]] && exit 0
  123.  
  124. source "$rootdir/supplementary/joystick-selection/jsfuncs.sh"
  125.  
  126. system="\$1"
  127.  
  128. get_configs
  129. # if not using joystick selection by name method, there's nothing to do.
  130. if [[ "\$BYNAME" != "ON" ]]; then
  131.     exit 0
  132. fi
  133.  
  134. echo "--- start of joystick-selection log" >&2
  135. echo "joystick selection by name is ON!" >&2
  136. js_to_retroarchcfg "\$system" && echo "joystick indexes for \"\$system\" was configured" >&2
  137. js_to_retroarchcfg all && echo "joystick indexes for \"all\" was configured" >&2
  138. echo "--- end of joystick-selection log" >&2
  139. _EoF_
  140.         sudo mv "/tmp/jsonstart.tmp" "$jsonstart"
  141.         sudo chown "$user"."$user"   "$jsonstart"
  142.         check_byname_is_ok
  143.         return $?
  144.     fi
  145.     okcount=$((okcount + 1)) # js-onstart is OK - CHECKED!
  146.  
  147.     if [[ $okcount -lt 3 ]]; then
  148.         return 1
  149.     fi
  150.  
  151.     return 0
  152. }
  153.  
  154.  
  155. # get the initial configs
  156. # [improvement]: maybe I'll add a way to define __joy2key_dev
  157. function get_configs() {
  158.     iniConfig ' = ' '"' '' 1
  159.  
  160.     iniGet joystick_selection_by_name "$global_jscfg"
  161.  
  162.     if [[ "$ini_value" =~ ^[Tt][Rr][Uu][Ee]$ ]]; then
  163.         if check_byname_is_ok; then
  164.             BYNAME="ON"
  165.         else
  166.             iniSet "joystick_selection_by_name" "false" "$global_jscfg"
  167.             BYNAME="OFF"
  168.         fi
  169.     else
  170.         BYNAME="OFF"
  171.     fi
  172.  
  173.     byname_msg="Selection by name is: [$BYNAME]\n\n"
  174. }
  175.  
  176.  
  177.  
  178. ###############################################################################
  179. # Fills the jslist_file with the available joysticks and their indexes.
  180. #
  181. # Globals:
  182. #   jslist_exe
  183. #   jslist_file
  184. #
  185. # Arguments:
  186. #   None
  187. #
  188. # Returns:
  189. #   1  if no joystick found.
  190. #   0  otherwise
  191. function fill_jslist_file() {
  192.     # the jslist returns a non-zero value if it doesn't find any joystick
  193.     "$jslist_exe" > "$temp_file" 2>/dev/null || return 1
  194.  
  195.     # This obscure command searches for duplicated joystick names and puts
  196.     # a sequential number at the end of the repeated ones
  197.     # credit goes to fedorqui (http://stackoverflow.com/users/1983854/fedorqui)
  198.     awk -F: 'FNR==NR {count[$2]++; next}
  199.             count[$2]>0 {$0=$0 OFS "#"++times[$2]}
  200.             1' "$temp_file" "$temp_file" > "$jslist_file"
  201. }
  202.  
  203.  
  204.  
  205. ###############################################################################
  206. # Get a joystick name and print its index. If the name is an integer, print
  207. # this integer.
  208. # OBS.: jslist_file MUST be filled.
  209. #
  210. # Globals:
  211. #   jslist_file
  212. #
  213. # Arguments:
  214. #   $1  Joystick name.
  215. #
  216. # Returns:
  217. #   0       on success
  218. # non-zero  otherwise
  219. function js_name2index() {
  220.     [[ "$1" ]] || return -1
  221.  
  222.     if [[ "$1" =~ ^[0-9]+$ ]]; then
  223.         echo "$1"
  224.         return 0
  225.     fi
  226.  
  227.     local js_name
  228.     local js_index
  229.     js_name="$1"
  230.     js_index=$(grep "^[0-9]\+:$js_name" "$jslist_file" | cut -d: -f1)
  231.  
  232.     [[ -z "$js_index" ]] && return 1
  233.  
  234.     echo "$js_index"
  235. }
  236.  
  237.  
  238.  
  239.  
  240. ###############################################################################
  241. # Get a joystick index and print its name. If there is no joystick with the
  242. # given index, print "(NOT CONNECTED)" and return a non-zero value.
  243. #
  244. # Globals:
  245. #   jslist_file
  246. #
  247. # Arguments:
  248. #   $1 : Joystick index (must be an integer).
  249. #
  250. # Returns:
  251. #   0       on success
  252. # non-zero  otherwise
  253. function js_index2name() {
  254.     if ! [[ "$1" =~ ^[0-9]+$ ]]; then
  255.         echo "*** erro: js_index2name: argument must be an integer" >&2
  256.         return -1
  257.     fi
  258.  
  259.     local js_index="$1"
  260.     local js_name
  261.     local return_val=0
  262.  
  263.     js_name=$(grep "^$js_index:" "$jslist_file" | cut -d: -f2)
  264.  
  265.     if [[ -z "$js_name" ]]; then
  266.         js_name="(NOT CONNECTED)"
  267.         return_val=1
  268.     fi
  269.  
  270.     echo "$js_name"
  271.     return $return_val
  272. }
  273.  
  274.  
  275.  
  276. ###############################################################################
  277. # Get a joystick index or name and check if it is connected. If the argument
  278. # is an integer, it is considered an index, otherwise it is considered a
  279. # joystick name.
  280. # If the joystick is connected, return 0.
  281. # If the joystick isn't connected, print "(NOT CONNECTED)" and return non-zero.
  282. #
  283. # Globals:
  284. #   jslist_file
  285. #
  286. # Arguments:
  287. #   $1 : Joystick index or name
  288. #
  289. # Returns:
  290. #   0       if the joystick is connected
  291. # non-zero  otherwise
  292. function js_is_connected() {
  293.     [[ "$1" ]] || fatalError "js_is_connected: missing arguments!"
  294.  
  295.     # if it's an integer, than it's an index
  296.     if [[ "$1" =~ ^[0-9]+$ ]]; then
  297.         if grep -q "^$1:" "$jslist_file"; then
  298.             return 0
  299.         else
  300.             echo "(NOT CONNECTED)"
  301.             return 1
  302.         fi
  303.     else
  304.         if grep -q "^[0-9]\+:$1" "$jslist_file"; then
  305.             return 0
  306.         else
  307.             echo "(NOT CONNECTED)"
  308.             return 1
  309.         fi
  310.     fi
  311. }
  312.  
  313. function elementIn () {
  314.   local e match="$1"
  315.   shift
  316.   for e; do [[ "$e" == "$match" ]] && return 0; done
  317.   return 1
  318. }
  319.  
  320. ###############################################################################
  321. # Make the retroarch.cfg configs match the joystick-selection.cfg. Only works
  322. # if the BYNAME is on. Makes sure Retroarch won't default to a joystick already in use.
  323. # Assigns controllers to UNSET spots based on port order and availability.
  324. # Needs the system as an argument.
  325. #
  326. # Globals:
  327. #   None
  328. #
  329. # Arguments:
  330. #   $1  the system to configure
  331. #
  332. # Returns:
  333. #   1   if BYNAME is off
  334. #   0   otherwise
  335. function js_to_retroarchcfg() {
  336.     [[ "$BYNAME" != "ON" ]] && return 1
  337.     [[ "$1" ]] && [[ -d "$configdir/$1" ]] || fatalError "js_to_retroarchcfg: the argument must be a valid system!"
  338.  
  339.     local jscfg="$configdir/$1/joystick-selection.cfg"
  340.     local retroarchcfg="$configdir/$1/retroarch.cfg"
  341.  
  342.     [[ -f "$jscfg" ]] || return 1
  343.  
  344.     fill_jslist_file
  345.  
  346.     local js_index
  347.     declare -a used_controller_indices
  348.     declare -a unset_player_indices
  349.    
  350.     for i in 1 2 3 4; do
  351.         iniGet "input_player${i}_joypad_index" "$jscfg"
  352.         js_index=$(js_name2index "$ini_value")
  353.  
  354.         if [[ -z "$js_index" ]]; then            
  355.             unset_player_indices+=("$i")
  356.         else
  357.             iniSet "input_player${i}_joypad_index" "$js_index" "$retroarchcfg"
  358.             used_controller_indices+=("$js_index")
  359.         fi
  360.     done
  361.    
  362.     #all of the below is a pretty ugly solution, but I'm garbage at shell scripts so...
  363.     for unset_player_index in ${unset_player_indices[@]}; do
  364.         for i in 0 1 2 3; do       
  365.             if ! elementIn $i "${used_controller_indices[@]}" ; then
  366.                 iniSet "input_player${unset_player_index}_joypad_index" "$i" "$retroarchcfg"
  367.                 used_controller_indices+=("$i")
  368.                 break
  369.             elif [[ "$i" -eq 3 ]] ; then
  370.                     iniSet "input_player${unset_player_index}_joypad_index" "16" "$retroarchcfg" #disable the player if there are no remaining controllers, this is probably not actually needed
  371.             fi
  372.         done       
  373.     done
  374. }
  375.  
  376.  
  377.  
  378. ###############################################################################
  379. # Create a joystick-selection.cfg for the system given as argument.
  380. # The created file will be filled with the input_player[1-4]_joypad_index
  381. # values from the respective retroarch.cfg.
  382. #
  383. # Globals:
  384. #   None
  385. #
  386. # Arguments:
  387. #   $1 : The joystick-selection.cfg file.
  388. #
  389. # Returns:
  390. #   0
  391. function retroarch_to_jscfg() {
  392.     [[ "$1" ]] && [[ -d "$configdir/$1" ]] || fatalError "retroarch_to_jscfg: the argument must be a valid system!"
  393.  
  394.     local temp=$(mktemp /tmp/temp.XXX)
  395.     local jscfg="$configdir/$1/joystick-selection.cfg"
  396.     local retroarchcfg="$configdir/$1/retroarch.cfg"
  397.     local jsname=
  398.  
  399.     [[ -f "$retroarchcfg" ]] || fatalError "retroarch_to_jscfg: \"$retroarchcfg\" not found!"
  400.  
  401.     fill_jslist_file
  402.  
  403.     cat > "$temp" << _EoF_
  404. # This file was created by the joystick-selection tool.
  405. # It's recommended to NOT edit it manually.
  406. # The format is pretty simmilar to a retroarch.cfg file, but it contains only
  407. # input_player[1-4]_joypad_index, and accepts "strings" as a value.
  408. # Example:
  409. # input_playerN_joypad_index = "joystick name"
  410. # If "joystick name" is an integer, then the real joystick index is used.
  411. _EoF_
  412.     sudo mv "$temp" "$jscfg"
  413.     sudo chown "$user"."$user" "$jscfg"
  414.  
  415.     if [[ "$jscfg" = "$global_jscfg" ]]; then
  416.         if [[ "$BYNAME" = "ON" ]]; then
  417.             iniSet "joystick_selection_by_name" "true" "$jscfg"
  418.         else
  419.             iniSet "joystick_selection_by_name" "false" "$jscfg"
  420.         fi
  421.     fi
  422.  
  423.     for i in 1 2 3 4; do
  424.         iniGet "input_player${i}_joypad_index" "$retroarchcfg"
  425.         if [[ -z "$ini_value" ]]; then
  426.             iniUnset "input_player${i}_joypad_index" "$((i-1))" "$jscfg"
  427.         else
  428.             jsname=$(js_index2name "$ini_value")
  429.             if [[ "$jsname" = "(NOT CONNECTED)" ]]; then
  430.                 iniUnset "input_player${i}_joypad_index" "$((i-1))" "$jscfg"
  431.             else
  432.                 iniSet "input_player${i}_joypad_index" "$jsname" "$jscfg"
  433.             fi
  434.         fi
  435.     done
  436. } # end of retroarch_to_jscfg()
  437.  
  438.  
  439.  
  440. ###############################################################################
  441. # Toggle the joystick selection method (by name or by index).
  442. #
  443. # If toggle from "by name" to "by index", just set the
  444. # "joystick_selection_by_name" to "false" in global joystick-selection.cfg.
  445. #
  446. # If toggle from "by index" to "by name", make all existent system's
  447. # joystick-selection.cfg match the current config from the
  448. # respective retroarch.cfg.
  449. #
  450. # Globals:
  451. #   BYNAME
  452. #   byname_msg
  453. #
  454. # Arguments:
  455. #   None
  456. #
  457. # Returns:
  458. #   0
  459. function toggle_byname() {
  460.     if [[ "$BYNAME" = "ON" ]]; then
  461.         dialog \
  462.           --title "Toggle \"selection by name\" capability" \
  463.           --yesno "Are you sure you want to turn OFF the joystick selection by name method?" \
  464.           0 0 >/dev/tty || return 1
  465.  
  466.         iniSet "joystick_selection_by_name" "false" "$global_jscfg"
  467.         BYNAME="OFF"
  468.     else
  469.         check_byname_is_ok || return 1
  470.  
  471.         dialog \
  472.           --title "Toggle \"selection by name\" capability" \
  473.           --yesno "If you turn ON the joystick selection by name method, probably your current joystick selection will be lost (but you can easily reconfigure it using this tool).\n\nAre you sure you want to turn ON the joystick selection by name method?" \
  474.           0 0 >/dev/tty || return 1
  475.  
  476.         dialog --title "Joystick Selection" --infobox "Please wait..." 0 0
  477.  
  478.         BYNAME="ON"
  479.         local file
  480.         local system
  481.         # get all the systems *joypad_index configs and convert to an
  482.         # equivalent joystick-selection.cfg
  483.         for file in $(find "$configdir" -name retroarch.cfg 2>/dev/null); do
  484.             if grep -q "^[[:space:]#]*input_player[1-4]_joypad_index[[:space:]]*=" "$file"; then
  485.                 system=${file%/*}
  486.                 system=${system//$configdir\//}
  487.                 retroarch_to_jscfg "$system"
  488.             fi
  489.         done
  490.     fi
  491.     byname_msg="Selection by name is: [$BYNAME]\n\n"
  492. } # end of toggle_byname()
  493.  
  494.  
  495.  
  496. # Choose between global config, system specific config, toggle byname
  497. function main_menu() {
  498.     while true; do
  499.         cmd=(dialog \
  500.              --title " Joystick Selection Main Menu " \
  501.              --menu "${byname_msg}This is a tool to let you choose which controller to use for RetroArch players 1-4" 19 80 12)
  502.         options=(
  503.             1 "Global joystick selection."
  504.             2 "System specific joystick selection."
  505.             3 "Toggle the joystick selection \"by-name\" method."
  506.         )
  507.         choice=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
  508.    
  509.         if [[ -n "$choice" ]]; then
  510.             case $choice in
  511.                 1)  system_js_select_menu "all"
  512.                 ;;
  513.  
  514.                 2)  systems_menu
  515.                 ;;
  516.  
  517.                 3)  toggle_byname
  518.                 ;;
  519.             esac
  520.         else
  521.             break
  522.         fi
  523.     done
  524. } # end of main_menu()
  525.  
  526.  
  527.  
  528. ###############################################################################
  529. # Show a menu to let the user configure the input for a given system.
  530. # At the end of this function, if the BYNAME flag is ON, the retroarch.cfg
  531. # system file will match the configs in joystick-selection.cfg system file.
  532. #
  533. # Globals:
  534. #   js_list_file
  535. #
  536. # Arguments:
  537. #   $1 : The system to be configured
  538. #
  539. # Returns:
  540. #   0
  541. function system_js_select_menu() {
  542.     [[ "$1" ]] || fatalError "js_select: missing argument: \"system\""
  543.  
  544.     fill_jslist_file
  545.  
  546.     local system="$1"
  547.     local js_name_p=()
  548.  
  549.     local retroarchcfg="$configdir/$system/retroarch.cfg"
  550.     local jscfg="$configdir/$system/joystick-selection.cfg"
  551.  
  552.     while true; do
  553.         # the 'if' outside the 'for' is for a performance reason
  554.         if [[ "$BYNAME" = "ON" ]]; then
  555.             for i in 1 2 3 4; do
  556.                 iniGet "input_player${i}_joypad_index" "$jscfg"
  557.                 if [[ -z "$ini_value" ]]; then
  558.                     js_name_p[$i]="** UNSET **"
  559.                 elif [[ "$ini_value" == "16" ]]; then # 16 means disabled
  560.                     js_name_p[$i]="** DISABLED **"
  561.                 else
  562.                     js_name_p[$i]="$ini_value $(js_is_connected "$ini_value")"
  563.                 fi
  564.             done
  565.         else
  566.             for i in 1 2 3 4; do
  567.                 iniGet "input_player${i}_joypad_index" "$retroarchcfg"
  568.                 if [[ -z "$ini_value" ]]; then
  569.                     js_name_p[$i]="** UNSET **"
  570.                 elif [[ "$ini_value" == "16" ]]; then # 16 means disabled
  571.                     js_name_p[$i]="** DISABLED **"
  572.                 else
  573.                     js_name_p[$i]="$ini_value:$(js_index2name "$ini_value")"
  574.                 fi
  575.             done
  576.         fi
  577.  
  578.         cmd=(dialog \
  579.              --title " Joystick Selection for \"$system\" " \
  580.              --menu "${byname_msg}OBS: UNSET/NOT CONNECTED joysticks are set to RetroArch defaults when launching a game.\n\nChoose the player you want to configure:" \
  581.              19 80 12
  582.         )
  583.         options=(
  584.             1 "${js_name_p[1]}"
  585.             2 "${js_name_p[2]}"
  586.             3 "${js_name_p[3]}"
  587.             4 "${js_name_p[4]}"
  588.         )
  589.         choice=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
  590.    
  591.         if [[ -n "$choice" ]]; then
  592.             player_js_select_menu "$choice" "$system"
  593.         else
  594.             break
  595.         fi
  596.     done
  597.  
  598.     # making retroarch.cfg match the configs in joystick-selection.cfg
  599.     # to avoid user confusion when looking at the files.
  600.     js_to_retroarchcfg "$system"
  601.  
  602.     # if this function was invoked by "runcommand-onmenu"...
  603.     [[ "$ON_MENU" -eq 1 ]] && return 0
  604.  
  605.     # if the system is not "all", go back to the systems_menu
  606.     [[ "$system" != "all" ]] && systems_menu
  607. } # end of system_js_select_menu()
  608.  
  609.  
  610.  
  611. ###############################################################################
  612. # Show the available joysticks and let the user choose which one to use
  613. # for the player given as a parameter.
  614. #
  615. # Globals:
  616. #   None
  617. #
  618. # Arguments:
  619. #   $1  an integer [1-4] that represents the player.
  620. #   $2  the system to configure
  621. #
  622. # Returns:
  623. #   0
  624. function player_js_select_menu() {
  625.     [[ "$1" =~ ^[1-4]$ ]] || fatalError "player_js_select_menu: invalid argument!"
  626.     [[ "$2" ]] && [[ -d "$configdir/$2" ]] || fatalError "player_js_select_menu: arg2 must be a valid system!"
  627.  
  628.     local i="$1"
  629.     local jscfg="$configdir/$2/joystick-selection.cfg"
  630.     local retroarchcfg="$configdir/$2/retroarch.cfg"
  631.    
  632.     fill_jslist_file
  633.  
  634.     options="U \"Unset\""
  635.     # The sed below obtain the joystick list with the format
  636.     # index "Joystick Name"
  637.     # to use as dialog menu options
  638.     options+=" $(sed 's/:\(.*\)/ "\1"/' "$jslist_file")"
  639.  
  640.     # do not give the option to disable input for player1
  641.     [[ "$i" -ne 1 ]] && options+=" D \"Disable input for player$i\""
  642.  
  643.     choice=$(
  644.         echo "$options" \
  645.         | xargs dialog \
  646.             --title " Joystick Selection for \"$system\" " \
  647.             --menu "${byname_msg}Choose the joystick for player$i" \
  648.             19 80 12 2>&1 >/dev/tty
  649.     )
  650.  
  651.     if [[ -n "$choice" ]]; then
  652.         case $choice in
  653.             U)
  654.                 iniUnset "input_player${i}_joypad_index" "$((i-1))" "$jscfg"
  655.                 iniUnset "input_player${i}_joypad_index" "$((i-1))" "$retroarchcfg"
  656.             ;;
  657.  
  658.             D)
  659.                 # index 16 is an ugly workaround to disable joypad input
  660.                 if [[ "$BYNAME" = "ON" ]]; then
  661.                     iniSet "input_player${i}_joypad_index" "16" "$jscfg"
  662.                 else
  663.                     iniSet "input_player${i}_joypad_index" "16" "$retroarchcfg"
  664.                 fi
  665.             ;;
  666.  
  667.             *)
  668.                 if [[ "$BYNAME" = "ON" ]]; then
  669.                     iniSet "input_player${i}_joypad_index" "$(js_index2name "$choice")" "$jscfg"
  670.                 else
  671.                     iniSet "input_player${i}_joypad_index" "$choice" "$retroarchcfg"
  672.                 fi
  673.             ;;
  674.         esac
  675.     fi
  676. } # end of player_js_select_menu()
  677.  
  678.  
  679.  
  680. ###############################################################################
  681. # Show the available systems to configure.
  682. #
  683. # Globals:
  684. #   None
  685. #
  686. # Arguments:
  687. #   None
  688. #
  689. # Returns:
  690. #   0
  691. function systems_menu() {
  692.     local file
  693.     local system_list
  694.     local system
  695.  
  696.     for file in $(find "$configdir" -name retroarch.cfg 2>/dev/null); do
  697.         system=${file%/*}
  698.         system=${system//$configdir\//}
  699.         system_list+="$system\n"
  700.     done
  701.     system_list=$(echo -e "$system_list" | grep -v "^all$" | sort | nl )
  702.  
  703.     cmd=(dialog \
  704.          --title "Joystick Selection" \
  705.          --menu "What system do you want to configure?" 25 80 20)
  706.     options=( $system_list )
  707.     choice=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty) || return 1
  708.  
  709.     system=$(echo -e "$system_list" | grep "^[[:blank:]]*$choice[[:blank:]]\+" | cut -f2)
  710.  
  711.     system_js_select_menu "$system"
  712. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top