From 503e956db9153812af7af765633f44792d84bea6 Mon Sep 17 00:00:00 2001 From: Dale Schultz Date: Tue, 13 May 2014 23:29:00 -0400 Subject: [PATCH] Update to support multiple checksum groups as defined in an ECU definition, i.e.: Checksum Fix 2 --- src/main/java/com/romraider/maps/Rom.java | 74 +++++++++++-------- .../java/com/romraider/maps/TableSwitch.java | 14 ++-- 2 files changed, 53 insertions(+), 35 deletions(-) diff --git a/src/main/java/com/romraider/maps/Rom.java b/src/main/java/com/romraider/maps/Rom.java index 364a3c0e..5092850d 100644 --- a/src/main/java/com/romraider/maps/Rom.java +++ b/src/main/java/com/romraider/maps/Rom.java @@ -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 checksumTables = new ArrayList(); 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; } diff --git a/src/main/java/com/romraider/maps/TableSwitch.java b/src/main/java/com/romraider/maps/TableSwitch.java index 96f8740f..52b9e0c3 100644 --- a/src/main/java/com/romraider/maps/TableSwitch.java +++ b/src/main/java/com/romraider/maps/TableSwitch.java @@ -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(