+ public static void set_logfile(int serial, File new_logfile) {
+ synchronized(backend) {
+ logfiles.put(serial, new_logfile);
+ backend.putString(String.format(logfilePreferenceFormat, serial), new_logfile.getPath());
+ flush_preferences();
+ }
+ }
+
+ public static File logfile(int serial) {
+ synchronized(backend) {
+ if (logfiles.containsKey(serial))
+ return logfiles.get(serial);
+ String logfile_string = backend.getString(String.format(logfilePreferenceFormat, serial), null);
+ if (logfile_string == null)
+ return null;
+ File logfile = new File(logfile_string);
+ logfiles.put(serial, logfile);
+ return logfile;
+ }
+ }
+
+ public static void set_state(AltosState state, int serial) {
+
+ synchronized(backend) {
+ backend.putJson(String.format(statePreferenceFormat, serial), new AltosJson(state));
+ backend.putInt(statePreferenceLatest, serial);
+ flush_preferences();
+ }
+ }
+
+ public static ArrayList<Integer> list_states() {
+ String[] keys = backend.keys();
+ ArrayList<Integer> states = new ArrayList<Integer>();
+
+ for (String key : keys) {
+ if (key.startsWith(statePreferenceHead)) {
+ try {
+ int serial = AltosParse.parse_int(key.substring(statePreferenceHead.length()));
+ states.add(serial);
+ } catch (ParseException pe) {
+ }
+ }
+ }
+ return states;
+ }
+
+ public static void remove_state(int serial) {
+ synchronized(backend) {
+ backend.remove(String.format(statePreferenceFormat, serial));
+ flush_preferences();
+ }
+ }
+
+ public static int latest_state() {
+ int latest = 0;
+ synchronized (backend) {
+ latest = backend.getInt(statePreferenceLatest, 0);
+ }
+ return latest;
+ }
+
+ public static AltosState state(int serial) {
+ synchronized(backend) {
+ try {
+ AltosJson json = backend.getJson(String.format(statePreferenceFormat, serial));
+ if (json != null)
+ return (AltosState) (json.make(AltosState.class));
+ } catch (Exception e) {
+ }
+ return null;
+ }
+ }
+