Update to support multiple checksum groups as defined in an ECU definition, i.e.: Checksum Fix 2

This commit is contained in:
Dale Schultz 2014-05-13 23:29:00 -04:00
parent 0b55ac2f52
commit 503e956db9
2 changed files with 53 additions and 35 deletions

View File

@ -1,6 +1,6 @@
/*
* RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2012 RomRaider.com
* Copyright (C) 2006-2014 RomRaider.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -291,36 +291,17 @@ public class Rom extends DefaultMutableTreeNode implements Serializable {
}
public byte[] saveFile() {
Table checksum = null;
final List<TableTreeNode> checksumTables = new ArrayList<TableTreeNode>();
for (TableTreeNode tableNode : tableNodes) {
tableNode.getTable().saveFile(binData);
if (tableNode.getTable().getName().equalsIgnoreCase("Checksum Fix"))
{
checksum = tableNode.getTable();
if (tableNode.getTable().getName().contains("Checksum Fix")) {
checksumTables.add(tableNode);
}
}
if (checksum != null && !checksum.isLocked()) {
calculateRomChecksum(binData, checksum.getStorageAddress(), checksum.getDataSize());
}
else if (checksum != null && checksum.isLocked() && !checksum.isButtonSelected()) {
Object[] options = {"Yes", "No"};
String message = String.format("One or more ROM image Checksums is invalid. " +
"Calculate new Checksums?%n" +
"(NOTE: this will only fix the Checksums it will NOT repair a corrupt ROM image)");
int answer = showOptionDialog(SwingUtilities.windowForComponent(checksum),
message,
"Checksum Fix",
DEFAULT_OPTION,
QUESTION_MESSAGE,
null,
options,
options[0]);
if (answer == 0) {
calculateRomChecksum(binData, checksum.getStorageAddress(), checksum.getDataSize());
}
}
if (checksum != null) {
byte count = binData[checksum.getStorageAddress() + 207];
if (checksumTables.size() == 1) {
final TableTreeNode checksum = checksumTables.get(0);
byte count = binData[checksum.getTable().getStorageAddress() + 207];
if (count == -1) {
count = 1;
}
@ -334,9 +315,44 @@ public class Rom extends DefaultMutableTreeNode implements Serializable {
romStamp,
0,
binData,
checksum.getStorageAddress() + 204,
checksum.getTable().getStorageAddress() + 204,
4);
setEditStamp(binData, checksum.getStorageAddress());
setEditStamp(binData, checksum.getTable().getStorageAddress());
}
for (TableTreeNode checksum : checksumTables) {
if (!checksum.getTable().isLocked()) {
calculateRomChecksum(
binData,
checksum.getTable().getStorageAddress(),
checksum.getTable().getDataSize()
);
}
else if (checksum.getTable().isLocked() &&
!checksum.getTable().isButtonSelected()) {
Object[] options = {"Yes", "No"};
final String message = String.format(
"One or more ROM image Checksums is invalid. " +
"Calculate new Checksums?%n" +
"(NOTE: this will only fix the Checksums it will NOT repair a corrupt ROM image)");
int answer = showOptionDialog(
SwingUtilities.windowForComponent(checksum.getTable()),
message,
"Checksum Fix",
DEFAULT_OPTION,
QUESTION_MESSAGE,
null,
options,
options[0]);
if (answer == 0) {
calculateRomChecksum(
binData,
checksum.getTable().getStorageAddress(),
checksum.getTable().getDataSize()
);
}
}
}
return binData;
}

View File

@ -1,6 +1,6 @@
/*
* RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2012 RomRaider.com
* Copyright (C) 2006-2014 RomRaider.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -87,12 +87,14 @@ public class TableSwitch extends Table {
// if the result is >0: position of failed checksum
// if the result is 0: all the checksums matched
// if the result is -1: all the checksums have been previously disabled
if (super.getName().equalsIgnoreCase("Checksum Fix")) {
if (super.getName().contains("Checksum Fix")) {
int result = validateRomChecksum(input, getStorageAddress(), dataSize);
String message = String.format(
"Checksum No. %d is invalid.%n" +
"The ROM image may be corrupt.%n" +
"Use of this ROM image is not advised!", result);
"Checksum No. %d is invalid in table: %s%n" +
"The ROM image may be corrupt or it has been %n" +
"hex edited manually.%n" +
"The checksum can be corrected when the ROM is saved.",
result, super.getName());
if (result > 0) {
showMessageDialog(this,
message,
@ -182,7 +184,7 @@ public class TableSwitch extends Table {
@Override
public byte[] saveFile(byte[] input) {
if (!super.getName().equalsIgnoreCase("Checksum Fix")) {
if (!super.getName().contains("Checksum Fix")) {
if (!locked) {
JRadioButton selectedButton = getSelectedButton(buttonGroup);
System.arraycopy(