altoslib: Make sure .eeprom download file is flushed on exception
[fw/altos] / altoslib / AltosEepromDownload.java
index 9598bd93e88456cc5f946ad6a3496f2a0103f424..c4ddb0e7472c851d8d9e54673c383a98f33dcc4e 100644 (file)
@@ -15,7 +15,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_6;
+package org.altusmetrum.altoslib_8;
 
 import java.io.*;
 import java.util.*;
@@ -111,12 +111,12 @@ public class AltosEepromDownload implements Runnable {
                                monitor.set_flight(state.flight);
 
                        /* Monitor state transitions to update display */
-                       if (state.state != AltosLib.ao_flight_invalid &&
-                           state.state <= AltosLib.ao_flight_landed)
+                       if (state.state() != AltosLib.ao_flight_invalid &&
+                           state.state() <= AltosLib.ao_flight_landed)
                        {
-                               if (state.state > AltosLib.ao_flight_pad)
+                               if (state.state() > AltosLib.ao_flight_pad)
                                        want_file = true;
-                               if (state.state == AltosLib.ao_flight_landed)
+                               if (state.state() == AltosLib.ao_flight_landed)
                                        done = true;
                        }
 
@@ -147,7 +147,6 @@ public class AltosEepromDownload implements Runnable {
 
                /* Reset per-capture variables */
                want_file = false;
-               eeprom_file = null;
                eeprom_pending = new LinkedList<String>();
 
                /* Set serial number in the monitor dialog window */
@@ -174,21 +173,17 @@ public class AltosEepromDownload implements Runnable {
 
                        CaptureEeprom (eechunk, log_format);
 
-                       if (state.state != prev_state && state.state != AltosLib.ao_flight_invalid) {
+                       if (state.state() != prev_state && state.state() != AltosLib.ao_flight_invalid) {
                                state_block = block;
-                               prev_state = state.state;
+                               prev_state = state.state();
                        }
 
                        monitor.set_value(state.state_name(),
-                                         state.state,
+                                         state.state(),
                                          block - state_block,
                                          block - log.start_block);
                }
                CheckFile(true);
-               if (eeprom_file != null) {
-                       eeprom_file.flush();
-                       eeprom_file.close();
-               }
        }
 
        public void run () {
@@ -201,11 +196,16 @@ public class AltosEepromDownload implements Runnable {
                                parse_exception = null;
                                if (log.selected) {
                                        monitor.reset();
+                                       eeprom_file = null;
                                        try {
                                                CaptureLog(log);
                                        } catch (ParseException e) {
                                                parse_exception = e;
                                        }
+                                       if (eeprom_file != null) {
+                                               eeprom_file.flush();
+                                               eeprom_file.close();
+                                       }
                                }
                                if (parse_exception != null) {
                                        failed = true;