Updated checksum feedback and custom checksum loading

This commit is contained in:
Robin K 2021-12-25 20:36:39 +01:00
parent 3183986385
commit 4712e1e366
10 changed files with 101 additions and 44 deletions

View File

@ -11,6 +11,7 @@ CFGEDFSMENU = ECU definition files need to be configured before ROM images can b
RELEASENOTESFONT = Tahoma
RELEASENOTES = Release Notes
STATUSREADY = Ready ...
CHECKSUMSTATE = %d/%d Checksums are correct. Checksums will be updated when file is saved.
OBSOLETEROM = A newer version of this ECU revision exists. Please visit the following link to download the latest revision:
DISPLAYMSG = Always display this message
ISOBSOLETE = ECU Revision is Obsolete

View File

@ -475,7 +475,7 @@ public class ECUEditor extends AbstractFrame {
}
editor.refreshTableCompareMenus();
editor.getStatusPanel().setStatus(ECUEditor.rb.getString("STATUSREADY"));
editor.getStatusPanel().update(ECUEditor.rb.getString("STATUSREADY"), 0);
editor.setCursor(null);
editor.refreshUI();

View File

@ -78,7 +78,16 @@ public class OpenImageWorker extends SwingWorker<Void, Void> {
editor.getStatusPanel().setStatus(
ECUEditor.rb.getString("CHECKSUM"));
rom.validateChecksum();
int validChecksums = rom.validateChecksum();
if(rom.getNumChecksumsManagers() == 0) {
editor.getStatusPanel().setStatus(ECUEditor.rb.getString("STATUSREADY"));
}
else {
editor.getStatusPanel().setStatus(String.format(ECUEditor.rb.getString("CHECKSUMSTATE"),
validChecksums, rom.getNumChecksumsManagers()));
}
setProgress(100);
}
@ -167,13 +176,13 @@ public class OpenImageWorker extends SwingWorker<Void, Void> {
ECUEditor.rb.getString("ERRORFILE"),
inputFile.getName());
try {
Rom rom = null;
Document doc = createDocument(f);
rom = new DOMRomUnmarshaller().unmarshallXMLDefinition(doc.getDocumentElement(), romNode,
Rom rom = new DOMRomUnmarshaller().unmarshallXMLDefinition(f, doc.getDocumentElement(), romNode,
input, editor.getStatusPanel());
rom.setDocument(doc);
loadRom(rom, input);
loadRom(rom, input);
} catch (StackOverflowError ex) {
// handles looped inheritance, which will use up all available memory
showMessageDialog(editor,
@ -309,7 +318,6 @@ public class OpenImageWorker extends SwingWorker<Void, Void> {
public void done() {
ECUEditor editor = ECUEditorManager.getECUEditor();
editor.refreshTableCompareMenus();
editor.getStatusPanel().setStatus(ECUEditor.rb.getString("STATUSREADY"));
setProgress(0);
editor.setCursor(null);
editor.refreshUI();

View File

@ -66,6 +66,7 @@ public class Rom extends DefaultMutableTreeNode implements Serializable {
private static final ResourceBundle rb = new ResourceUtil().getBundle(
Rom.class.getName());
private RomID romID;
private File definitionPath;
private String fileName = "";
private File fullFileName = new File(".");
private byte[] binData;
@ -300,6 +301,14 @@ public class Rom extends DefaultMutableTreeNode implements Serializable {
return this.doc;
}
public void setDefinitionPath(File s) {
definitionPath = s;
}
public File getDefinitionPath() {
return definitionPath;
}
@Override
public String toString() {
String output = "";
@ -494,28 +503,39 @@ public class Rom extends DefaultMutableTreeNode implements Serializable {
public ChecksumManager getChecksumType(int index) {
return checksumManagers.get(index);
}
public void validateChecksum() {
if (!checksumManagers.isEmpty()) {
final String message = rb.getString("INVLAIDCHKSUM");
boolean valid = true;
public int getNumChecksumsManagers() {
return checksumManagers.size();
}
public int validateChecksum() {
int correctChecksums = 0;
boolean valid = true;
if (!checksumManagers.isEmpty()) {
for(ChecksumManager cm: checksumManagers) {
if (!cm.validate(binData)) valid = false;
}
if(!valid)
showMessageDialog(null,
message,
rb.getString("CHKSUMFAIL"),
WARNING_MESSAGE);
if (cm == null || !cm.validate(binData)) {
valid = false;
}
else {
correctChecksums++;
}
}
}
if(!valid) {
showMessageDialog(null,
rb.getString("INVLAIDCHKSUM"),
rb.getString("CHKSUMFAIL"),
WARNING_MESSAGE);
}
return correctChecksums;
}
public void updateChecksum() {
for(ChecksumManager cm: checksumManagers) {
cm.update(binData);
}
for(ChecksumManager cm: checksumManagers) {
cm.update(binData);
}
}
}

View File

@ -129,7 +129,8 @@ public abstract class Table implements Serializable {
}
data = null;
}
}
rom = null;
}
public void setData(DataCell[] data) {

View File

@ -1,6 +1,6 @@
/*
* RomRaider Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006-2020 RomRaider.com
* Copyright (C) 2006-2021 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
@ -22,18 +22,27 @@ package com.romraider.maps.checksum;
import static javax.swing.JOptionPane.ERROR_MESSAGE;
import static javax.swing.JOptionPane.showMessageDialog;
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Paths;
import java.text.MessageFormat;
import java.util.Map;
import java.util.ResourceBundle;
import org.apache.log4j.Logger;
import com.romraider.maps.Rom;
import com.romraider.util.ResourceUtil;
/**
* Instantiate a ChecksumManager class.
*/
public final class ChecksumFactory {
private static final Logger LOGGER = Logger.getLogger(ChecksumFactory.class);
private static final ResourceBundle rb = new ResourceUtil().getBundle(
ChecksumFactory.class.getName());
private static final String PATH = "path";
private static final String TYPE = "type";
private static final String MISSING = rb.getString("MISSING");
private static final String NO_CLASS = rb.getString("NOCLASS");
@ -49,16 +58,34 @@ public final class ChecksumFactory {
* @throws ClassNotFoundException if the class based on "type"
* does not exist
*/
public static ChecksumManager getManager(
public static ChecksumManager getManager(Rom rom,
Map<String, String> attrs) {
ChecksumManager cm = null;
Class<?> cls;
ClassLoader cl;
final String type = attrs.get(TYPE);
final String pathCustomChecksum = attrs.get(PATH);
try {
cls = Class.forName(
ChecksumFactory.class.getPackage().getName() +
".Checksum" + type.toUpperCase());
String path;
//Custom checksum which comes with the definition
//Path is relative to the current definition directory
if(pathCustomChecksum != null && rom.getDefinitionPath() != null) {
path = Paths.get(rom.getDefinitionPath().getParent(), pathCustomChecksum).toString();
cl = new URLClassLoader(new URL[]{new File(path).toURI().toURL()});
cls = cl.loadClass(ChecksumFactory.class.getPackage().getName() + "." + type);
LOGGER.info("Loaded custom checksum type " + type + " from " + path);
}
//Checksum included in RR
else {
path = ChecksumFactory.class.getPackage().getName() + ".Checksum" + type.toUpperCase();
cls = Class.forName(path);
}
cm = (ChecksumManager) cls.newInstance();
cm.configure(attrs);
} catch (Exception e) {
@ -69,9 +96,11 @@ public final class ChecksumFactory {
else {
message = MessageFormat.format(NO_CLASS, type.toUpperCase());
}
e.printStackTrace();
showMessageDialog(null,
message,
rb.getString("LOADERR"), ERROR_MESSAGE);
e.toString(), ERROR_MESSAGE);
}
return cm;
}

View File

@ -375,7 +375,6 @@ public class ECUEditorMenuBar extends JMenuBar implements ActionListener {
}
} else if (e.getSource() == closeImage) {
parent.closeImage();
} else if (e.getSource() == closeAll) {
parent.closeAllImages();
} else if (e.getSource() == exportDef) {

View File

@ -70,7 +70,11 @@ public class JProgressPane extends JPanel implements PropertyChangeListener{
public JProgressBar getProgressBar() {
return this.progressBar;
}
public void updateLabel() {
label.setText(" " + status);
}
@Override
public void propertyChange(PropertyChangeEvent evt) {
if("progress" == evt.getPropertyName()) {

View File

@ -34,7 +34,6 @@ import javax.swing.table.TableColumn;
import com.romraider.Settings;
import com.romraider.maps.Scale;
import com.romraider.maps.Table;
import com.romraider.maps.TableSwitch;
import com.romraider.util.ResourceUtil;
public class TablePropertyPanel extends javax.swing.JPanel {
@ -325,12 +324,6 @@ public class TablePropertyPanel extends javax.swing.JPanel {
return createScalesTable(scalesModel);
}
private JTable populateScalesTable(Map<String, byte[]> switchStates) {
final SwitchStateTableModel scalesModel = new SwitchStateTableModel();
scalesModel.setScalesList(switchStates);
return createScalesTable(scalesModel);
}
private JTable createScalesTable(DefaultTableModel tableModel) {
final JTable table = new JTable(tableModel);
table.setAutoCreateRowSorter(false);

View File

@ -23,6 +23,7 @@ import static com.romraider.xml.DOMHelper.unmarshallAttribute;
import static com.romraider.xml.DOMHelper.unmarshallText;
import static org.w3c.dom.Node.ELEMENT_NODE;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
@ -51,7 +52,7 @@ public final class DOMRomUnmarshaller {
return n;
}
public Rom unmarshallXMLDefinition(Node rootNode, Node romNode, byte[] input,
public Rom unmarshallXMLDefinition(File definition, Node rootNode, Node romNode, byte[] input,
JProgressPane progress) throws
XMLParseException, StackOverflowError, Exception {
@ -61,6 +62,7 @@ public final class DOMRomUnmarshaller {
tableScaleHandler.unmarshallBaseScales(rootNode);
Rom rom = new Rom(new RomID());
rom.setDefinitionPath(definition);
Rom output = unmarshallRom(romNode, rom);
//Set ram offset
@ -181,7 +183,7 @@ public final class DOMRomUnmarshaller {
}
} else if (n.getNodeName().equalsIgnoreCase("checksum")) {
rom.getRomID().setChecksum(unmarshallAttribute(n, "type", ""));
checksumManager = unmarshallChecksum(n);
checksumManager = unmarshallChecksum(rom, n);
rom.addChecksumManager(checksumManager);
} else { /* unexpected element in Rom (skip) */
@ -284,14 +286,14 @@ public final class DOMRomUnmarshaller {
* @param node - the checksum element node to process
* @return CheckSumManager object
*/
private ChecksumManager unmarshallChecksum(Node node) {
private ChecksumManager unmarshallChecksum(Rom rom, Node node) {
final Map<String, String> attrs = new HashMap<String, String>();
for (int i = 0; i < node.getAttributes().getLength(); i++) {
attrs.put(node.getAttributes().item(i).getNodeName().toLowerCase(),
node.getAttributes().item(i).getNodeValue());
}
return ChecksumFactory.getManager(attrs);
return ChecksumFactory.getManager(rom, attrs);
}
}