Skip to content

Commit bb07176

Browse files
author
Matthias Clausen
committed
Bugfix time configuration option
1 parent 15445bd commit bb07176

File tree

2 files changed

+13
-27
lines changed

2 files changed

+13
-27
lines changed

src/hotpants/Configuration.java

+10-24
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import java.nio.ByteBuffer;
77
import javax.microedition.rms.*;
88
import java.util.Hashtable;
9-
import util.IntToBytes;
109

1110
public class Configuration {
1211
private RecordStore recordStore;
@@ -15,7 +14,7 @@ public class Configuration {
1514
public static final byte TOTP = 1;
1615
public static final byte HOTP = 2;
1716
public static final byte TimeConfig = 3;
18-
private int timeOffset = 0;
17+
private byte timeOffset = 0;
1918
private int offsetRecordId = -1;
2019

2120
public Configuration() {
@@ -25,9 +24,7 @@ public Configuration() {
2524
recordStore.setMode(RecordStore.AUTHMODE_PRIVATE, false);
2625
RecordEnumeration re = recordStore.enumerateRecords(null, null, false);
2726
while (re.hasNextElement()) {
28-
int recId = re.nextRecordId();
29-
byte[] record = recordStore.getRecord(recId);
30-
record[record.length-1] = (byte)recId;
27+
byte[] record = re.nextRecord();
3128
int type = getEntryTypeFromRecordBytes(record);
3229
if (Configuration.TOTP == type) {
3330
TotpEntry e = TotpEntry.fromBytes(record);
@@ -46,23 +43,13 @@ public Configuration() {
4643
}
4744

4845
private void setTimeOffset(byte[] record) {
49-
ByteArrayOutputStream b_id_baos = new ByteArrayOutputStream();
50-
DataOutputStream b_id = new DataOutputStream(b_id_baos);
51-
ByteArrayOutputStream b_sec_baos = new ByteArrayOutputStream();
52-
DataOutputStream b_sec = new DataOutputStream(b_sec_baos);
53-
int section = 0;
54-
for (int i = 0; i < record.length; i++) {
55-
if (Configuration.DELIM == record[i]) {
56-
section++;
57-
}
58-
switch (section) {
59-
case 3:
60-
timeOffset = record[i] - 120;
61-
break;
62-
case 4:
63-
offsetRecordId = record[i];
64-
}
46+
if (record.length != 9) {
47+
System.err.println("Corrupt time offset configuration entry.");
48+
return;
6549
}
50+
timeOffset = record[6];
51+
offsetRecordId = record[8];
52+
System.out.println("Time offset from config: " + timeOffset);
6653
}
6754

6855
private int getEntryTypeFromRecordBytes(byte[] record) {
@@ -114,7 +101,6 @@ public void updateOffsetSeconds(byte seconds) {
114101
try {
115102
timeOffset = seconds;
116103
byte[] record = new byte[9];
117-
118104
recordStore = RecordStore.openRecordStore("Hotpants",true);
119105
recordStore.setMode(RecordStore.AUTHMODE_PRIVATE, true);
120106
boolean isNew = offsetRecordId == -1;
@@ -127,7 +113,7 @@ public void updateOffsetSeconds(byte seconds) {
127113
record[3] = DELIM;
128114
record[4] = TimeConfig;
129115
record[5] = DELIM;
130-
record[6] = (byte)(seconds + 120);
116+
record[6] = seconds;
131117
record[7] = DELIM;
132118
record[8] = (byte)offsetRecordId;
133119

@@ -141,7 +127,7 @@ public void updateOffsetSeconds(byte seconds) {
141127
}
142128
}
143129

144-
public int getOffsetSeconds() {
130+
public byte getOffsetSeconds() {
145131
return timeOffset;
146132
}
147133

src/hotpants/TimeConfigForm.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class TimeConfigForm extends Form implements CommandListener, ItemStateL
1717
private final Midlet midlet;
1818
private final Command cancel, save;
1919
private final Gauge secondsInput;
20-
private int offset;
20+
private byte offset;
2121
private final Calendar displayedTime;
2222
private final StringItem helpText;
2323

@@ -64,14 +64,14 @@ public void updateTimeLabel() {
6464

6565
public void commandAction(Command c, Displayable d) {
6666
if (c == save) {
67-
midlet.getConfiguration().updateOffsetSeconds((byte)offset);
67+
midlet.getConfiguration().updateOffsetSeconds(offset);
6868
}
6969
midlet.showMainForm();
7070
}
7171

7272
public void itemStateChanged(Item item) {
7373
if (item == secondsInput) {
74-
offset = secondsInput.getValue() - 120;
74+
offset = (byte)(secondsInput.getValue() - 120);
7575
updateTimeLabel();
7676
}
7777
}

0 commit comments

Comments
 (0)