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 RELEASENOTESFONT = Tahoma
RELEASENOTES = Release Notes RELEASENOTES = Release Notes
STATUSREADY = Ready ... 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: OBSOLETEROM = A newer version of this ECU revision exists. Please visit the following link to download the latest revision:
DISPLAYMSG = Always display this message DISPLAYMSG = Always display this message
ISOBSOLETE = ECU Revision is Obsolete ISOBSOLETE = ECU Revision is Obsolete

View File

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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,6 @@
/* /*
* RomRaider Open-Source Tuning, Logging and Reflashing * 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 * 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 * 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.ERROR_MESSAGE;
import static javax.swing.JOptionPane.showMessageDialog; 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.text.MessageFormat;
import java.util.Map; import java.util.Map;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import org.apache.log4j.Logger;
import com.romraider.maps.Rom;
import com.romraider.util.ResourceUtil; import com.romraider.util.ResourceUtil;
/** /**
* Instantiate a ChecksumManager class. * Instantiate a ChecksumManager class.
*/ */
public final class ChecksumFactory { public final class ChecksumFactory {
private static final Logger LOGGER = Logger.getLogger(ChecksumFactory.class);
private static final ResourceBundle rb = new ResourceUtil().getBundle( private static final ResourceBundle rb = new ResourceUtil().getBundle(
ChecksumFactory.class.getName()); ChecksumFactory.class.getName());
private static final String PATH = "path";
private static final String TYPE = "type"; private static final String TYPE = "type";
private static final String MISSING = rb.getString("MISSING"); private static final String MISSING = rb.getString("MISSING");
private static final String NO_CLASS = rb.getString("NOCLASS"); 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" * @throws ClassNotFoundException if the class based on "type"
* does not exist * does not exist
*/ */
public static ChecksumManager getManager( public static ChecksumManager getManager(Rom rom,
Map<String, String> attrs) { Map<String, String> attrs) {
ChecksumManager cm = null; ChecksumManager cm = null;
Class<?> cls; Class<?> cls;
ClassLoader cl;
final String type = attrs.get(TYPE); final String type = attrs.get(TYPE);
final String pathCustomChecksum = attrs.get(PATH);
try { try {
cls = Class.forName( String path;
ChecksumFactory.class.getPackage().getName() +
".Checksum" + type.toUpperCase()); //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 = (ChecksumManager) cls.newInstance();
cm.configure(attrs); cm.configure(attrs);
} catch (Exception e) { } catch (Exception e) {
@ -69,9 +96,11 @@ public final class ChecksumFactory {
else { else {
message = MessageFormat.format(NO_CLASS, type.toUpperCase()); message = MessageFormat.format(NO_CLASS, type.toUpperCase());
} }
e.printStackTrace();
showMessageDialog(null, showMessageDialog(null,
message, message,
rb.getString("LOADERR"), ERROR_MESSAGE); e.toString(), ERROR_MESSAGE);
} }
return cm; return cm;
} }

View File

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

View File

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

View File

@ -34,7 +34,6 @@ import javax.swing.table.TableColumn;
import com.romraider.Settings; import com.romraider.Settings;
import com.romraider.maps.Scale; import com.romraider.maps.Scale;
import com.romraider.maps.Table; import com.romraider.maps.Table;
import com.romraider.maps.TableSwitch;
import com.romraider.util.ResourceUtil; import com.romraider.util.ResourceUtil;
public class TablePropertyPanel extends javax.swing.JPanel { public class TablePropertyPanel extends javax.swing.JPanel {
@ -325,12 +324,6 @@ public class TablePropertyPanel extends javax.swing.JPanel {
return createScalesTable(scalesModel); 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) { private JTable createScalesTable(DefaultTableModel tableModel) {
final JTable table = new JTable(tableModel); final JTable table = new JTable(tableModel);
table.setAutoCreateRowSorter(false); 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 com.romraider.xml.DOMHelper.unmarshallText;
import static org.w3c.dom.Node.ELEMENT_NODE; import static org.w3c.dom.Node.ELEMENT_NODE;
import java.io.File;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -51,7 +52,7 @@ public final class DOMRomUnmarshaller {
return n; 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 JProgressPane progress) throws
XMLParseException, StackOverflowError, Exception { XMLParseException, StackOverflowError, Exception {
@ -61,6 +62,7 @@ public final class DOMRomUnmarshaller {
tableScaleHandler.unmarshallBaseScales(rootNode); tableScaleHandler.unmarshallBaseScales(rootNode);
Rom rom = new Rom(new RomID()); Rom rom = new Rom(new RomID());
rom.setDefinitionPath(definition);
Rom output = unmarshallRom(romNode, rom); Rom output = unmarshallRom(romNode, rom);
//Set ram offset //Set ram offset
@ -181,7 +183,7 @@ public final class DOMRomUnmarshaller {
} }
} else if (n.getNodeName().equalsIgnoreCase("checksum")) { } else if (n.getNodeName().equalsIgnoreCase("checksum")) {
rom.getRomID().setChecksum(unmarshallAttribute(n, "type", "")); rom.getRomID().setChecksum(unmarshallAttribute(n, "type", ""));
checksumManager = unmarshallChecksum(n); checksumManager = unmarshallChecksum(rom, n);
rom.addChecksumManager(checksumManager); rom.addChecksumManager(checksumManager);
} else { /* unexpected element in Rom (skip) */ } else { /* unexpected element in Rom (skip) */
@ -284,14 +286,14 @@ public final class DOMRomUnmarshaller {
* @param node - the checksum element node to process * @param node - the checksum element node to process
* @return CheckSumManager object * @return CheckSumManager object
*/ */
private ChecksumManager unmarshallChecksum(Node node) { private ChecksumManager unmarshallChecksum(Rom rom, Node node) {
final Map<String, String> attrs = new HashMap<String, String>(); final Map<String, String> attrs = new HashMap<String, String>();
for (int i = 0; i < node.getAttributes().getLength(); i++) { for (int i = 0; i < node.getAttributes().getLength(); i++) {
attrs.put(node.getAttributes().item(i).getNodeName().toLowerCase(), attrs.put(node.getAttributes().item(i).getNodeName().toLowerCase(),
node.getAttributes().item(i).getNodeValue()); node.getAttributes().item(i).getNodeValue());
} }
return ChecksumFactory.getManager(attrs); return ChecksumFactory.getManager(rom, attrs);
} }
} }