From d527e86c84f03a3ad847330c8513e4626882fef7 Mon Sep 17 00:00:00 2001
From: Bob Mottram <bob@robotics.uk.to>
Date: Mon, 24 Oct 2016 09:47:17 +0100
Subject: [PATCH] Restore using radiolist

---
 src/freedombone-controlpanel | 112 +++++++++++++++--------------------
 1 file changed, 48 insertions(+), 64 deletions(-)

diff --git a/src/freedombone-controlpanel b/src/freedombone-controlpanel
index 8253cf5da..35b42259e 100755
--- a/src/freedombone-controlpanel
+++ b/src/freedombone-controlpanel
@@ -937,80 +937,64 @@ function restore_data_from_storage {
 
     choices=$(dialog --stdout --backtitle $"Freedombone" \
                      --title $"Restore apps" \
-                     --checklist $'Choose:' \
+                     --radiolist $'Choose:' \
                      30 40 20 $applist)
 
-    if [ $? -eq 0 ]; then
-        clear
+    sel=$?
+    case $sel in
+        1) return;;
+        255) return;;
+    esac
+    app_name=$(cat $data)
 
-        # Test for exit
-        for choice in $choices
-        do
-            app_index=$[choice-1]
-            app_name=${app_list[app_index]}
-            if [[ $app_name == "$ExitStr" ]]; then
-                return
-            fi
-        done
-
-        # Test for restoring all apps
-        for choice in $choices
-        do
-            app_index=$[choice-2]
-            app_name=${app_list[app_index]}
-            if [[ $app_name == "$AllStr" ]]; then
-                $restore_command
-                retcode="$?"
-                if [[ "$retcode" != "0" ]]; then
-                    if [[ "$1" == "local" ]]; then
-                        dialog --title $"Restore all apps from USB" \
-                               --msgbox $"Restore failed with code $retcode" 6 60
-                    else
-                        dialog --title $"Restore all apps from $1" \
-                               --msgbox $"Restore failed with code $retcode" 6 60
-                    fi
-                    return
-                fi
+    # exit
+    if [[ $app_name == "$ExitStr" ]]; then
+        return
+    fi
 
-                if [[ "$1" == "local" ]]; then
-                    dialog --title $"Restore all apps from USB" \
-                           --msgbox $"Restore complete" 6 40
-                else
-                    dialog --title $"Restore all apps from $1" \
-                           --msgbox $"Restore complete" 6 40
-                fi
-                return
-            fi
-        done
-
-        ctr=0
-        for choice in $choices
-        do
-            app_index=$[choice-2]
-            app_name=${app_list[app_index]}
-            if [ ${#app_name} -gt 0 ]; then
-                $restore_command "${app_name}"
-                retcode="$?"
-                if [[ "$retcode" != "0" ]]; then
-                    dialog --title $"Restore apps from USB" \
-                           --msgbox $"Restore of ${app_name} failed with code $retcode" 6 60
-                    return
-                fi
-            fi
-            ctr=$((ctr + 1))
-        done
-        if [ $ctr -gt 0 ]; then
+    # Restore all
+    if [[ $app_name == "$AllStr" ]]; then
+        clear
+        $restore_command
+        retcode="$?"
+        if [[ "$retcode" != "0" ]]; then
             if [[ "$1" == "local" ]]; then
-                dialog --title $"Restore apps from USB" \
-                       --msgbox $"Restore complete" 6 40
+                dialog --title $"Restore all apps from USB" \
+                       --msgbox $"Restore failed with code $retcode" 6 60
             else
-                dialog --title $"Restore apps from $1" \
-                       --msgbox $"Restore complete" 6 40
+                dialog --title $"Restore all apps from $1" \
+                       --msgbox $"Restore failed with code $retcode" 6 60
             fi
             return
         fi
+
+        if [[ "$1" == "local" ]]; then
+            dialog --title $"Restore all apps from USB" \
+                   --msgbox $"Restore complete" 6 40
+        else
+            dialog --title $"Restore all apps from $1" \
+                   --msgbox $"Restore complete" 6 40
+        fi
+        return
+    fi
+
+    # Restore an app
+    $restore_command "${app_name}"
+    retcode="$?"
+    if [[ "$retcode" != "0" ]]; then
+        dialog --title $"Restore apps from USB" \
+               --msgbox $"Restore of ${app_name} failed with code $retcode" 6 60
+        return
+    fi
+
+    # finished
+    if [[ "$1" == "local" ]]; then
+        dialog --title $"Restore apps from USB" \
+               --msgbox $"Restore complete" 6 40
+    else
+        dialog --title $"Restore apps from $1" \
+               --msgbox $"Restore complete" 6 40
     fi
-    any_key
 }
 
 function restore_data {
-- 
GitLab