auto-sync

This commit is contained in:
rusEfi 2015-03-10 18:10:39 -05:00
parent 7dacfd06c0
commit 17bcd7c50b
5 changed files with 21 additions and 9 deletions

View File

@ -81,4 +81,10 @@ public class ConfigurationImage {
byte[] copy = content.clone();
return new ConfigurationImage(copy);
}
public byte[] getRange(Integer first, int size) {
byte[] r = new byte[size];
System.arraycopy(content, first, r, 0, size);
return r;
}
}

View File

@ -109,8 +109,15 @@ public class BinaryProtocol {
Pair<Integer, Integer> range = ConfigurationImageDiff.findDifferences(current, newVersion, offset);
if (range == null)
break;
logger.info("Need to patch: " + range);
writeData(newVersion.getContent(), range.first, range.second - range.first, logger);
int size = range.second - range.first;
logger.info("Need to patch: " + range + ", size=" + size);
byte[] oldBytes = current.getRange(range.first, size);
logger.info("old " + Arrays.toString(oldBytes));
byte[] newBytes = newVersion.getRange(range.first, size);
logger.info("new " + Arrays.toString(newBytes));
writeData(newVersion.getContent(), range.first, size, logger);
offset = range.second;
}

View File

@ -390,7 +390,7 @@ public class ECUEditor extends AbstractFrame {
frame.getTable().drawTable();
rightPanel.add(frame);
} catch (IllegalArgumentException ex) {
;// Do nothing.
// Do nothing.
}
frame.pack();
rightPanel.repaint();
@ -464,7 +464,7 @@ public class ECUEditor extends AbstractFrame {
}
public Vector<Rom> getImages() {
Vector<Rom> images = new Vector<Rom>();
Vector<Rom> images = new Vector<>();
for (int i = 0; i < imageRoot.getChildCount(); i++) {
if(imageRoot.getChildAt(i) instanceof Rom) {
Rom rom = (Rom) imageRoot.getChildAt(i);
@ -515,15 +515,12 @@ public class ECUEditor extends AbstractFrame {
public static byte[] readFile(File inputFile) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
FileInputStream fis = new FileInputStream(inputFile);
try {
try (FileInputStream fis = new FileInputStream(inputFile)) {
byte[] buf = new byte[8192];
int bytesRead;
while ((bytesRead = fis.read(buf)) != -1) {
baos.write(buf, 0, bytesRead);
}
} finally {
fis.close();
}
return baos.toByteArray();
}

View File

@ -120,7 +120,7 @@ public class ECUEditorToolBar extends JToolBar {
// refreshImage.setEnabled(true);
// closeImage.setEnabled(true);
// }
// revalidate();
revalidate();
}
private Settings getSettings() {

View File

@ -187,6 +187,8 @@ public final class RomAttributeParser {
ByteBuffer bb = ByteBuffer.wrap(output, 0, 4);
if (endian == Settings.ENDIAN_LITTLE) {
bb.order(ByteOrder.BIG_ENDIAN);
} else {
bb.order(ByteOrder.LITTLE_ENDIAN);
}
bb.putFloat(input);
return bb.array();