altosui: Devices with log-format can also delete flights
[fw/altos] / altosui / AltosEepromDelete.java
index ecd82c187bd2328126cd882706b6c09e39282afa..cd9abfabc02fcf3b00e25f8324cb9f35ca6bd67c 100644 (file)
@@ -42,7 +42,7 @@ public class AltosEepromDelete implements Runnable {
        private void DeleteLog (AltosEepromLog log)
                throws IOException, InterruptedException, TimeoutException {
 
-               if (flights.config_data.flight_log_max != 0) {
+               if (flights.config_data.flight_log_max != 0 || flights.config_data.log_format != 0) {
 
                        /* Devices with newer firmware can erase the
                         * flash blocks containing each flight
@@ -84,11 +84,11 @@ public class AltosEepromDelete implements Runnable {
        }
 
        public void run () {
-               if (remote)
-                       serial_line.start_remote();
-
                success = false;
                try {
+                       if (remote)
+                               serial_line.start_remote();
+
                        for (AltosEepromLog log : flights) {
                                if (log.delete) {
                                        DeleteLog(log);
@@ -103,11 +103,12 @@ public class AltosEepromDelete implements Runnable {
                        show_error (String.format("Connection to \"%s\" failed",
                                                  serial_line.device.toShortString()),
                                    "Connection Failed");
+               } finally {
+                       if (remote)
+                               serial_line.stop_remote();
+                       serial_line.flush_output();
+                       serial_line.close();
                }
-               if (remote)
-                       serial_line.stop_remote();
-               serial_line.flush_output();
-               serial_line.close();
                if (listener != null) {
                        Runnable r = new Runnable() {
                                        public void run() {