altosui/altosuilib: Shuffle lots more code from altosui into
[fw/altos] / altosui / AltosEepromDelete.java
index c95eda153d5c5edc07eee944b0cd0324a7266d8d..df2ade786ad6e363bc3ba04b29bdadb4536d76c6 100644 (file)
 
 package altosui;
 
-import java.awt.*;
 import java.awt.event.*;
 import javax.swing.*;
-import javax.swing.filechooser.FileNameExtensionFilter;
-import javax.swing.table.*;
 import java.io.*;
-import java.util.*;
-import java.text.*;
-import java.util.prefs.*;
 import java.util.concurrent.*;
-
-import libaltosJNI.*;
+import org.altusmetrum.altosuilib_2.*;
+import org.altusmetrum.altoslib_4.*;
 
 public class AltosEepromDelete implements Runnable {
        AltosEepromList         flights;
@@ -42,18 +36,16 @@ 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
                         */
                        serial_line.flush_input();
                        serial_line.printf("d %d\n", log.flight);
-                       System.out.printf("Attempt to delete flight %d\n", log.flight);
                        for (;;) {
                                /* It can take a while to erase the flash... */
                                String line = serial_line.get_reply(20000);
-                               System.out.printf("got back line %s\n", line);
                                if (line == null)
                                        throw new TimeoutException();
                                if (line.equals("Erased"))
@@ -86,17 +78,16 @@ 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) {
+                               if (log.selected) {
                                        DeleteLog(log);
                                }
                        }
-                       System.out.printf("All flights successfully deleted\n");
                        success = true;
                } catch (IOException ee) {
                        show_error (ee.getLocalizedMessage(),
@@ -106,11 +97,16 @@ public class AltosEepromDelete implements Runnable {
                        show_error (String.format("Connection to \"%s\" failed",
                                                  serial_line.device.toShortString()),
                                    "Connection Failed");
+               } finally {
+                       try {
+                               if (remote)
+                                       serial_line.stop_remote();
+                       } catch (InterruptedException ie) {
+                       } finally {
+                               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() {
@@ -145,4 +141,4 @@ public class AltosEepromDelete implements Runnable {
                flights = given_flights;
                success = false;
        }
-}
\ No newline at end of file
+}